* Writing own match module for modern ebtables.
@ 2024-06-14 7:01 Pawel Kraszewski
2024-06-14 15:26 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Pawel Kraszewski @ 2024-06-14 7:01 UTC (permalink / raw)
To: netfilter
Hello!
I'm trying to write a simple match module for ebtables. Nothing fancy,
just check ethertype and first 2 bytes of payload. I need to make
ebtables' dnat, based on a custom in-packet tag:
> ebtables -t nat -A PREROUTING -i eth0 --MYMATCH-tag 10 -j dnat --to-destination SO:ME:MA:CA:DD:RS
Kernel module ebt_MYMATCH.ko is almost ready (it just accepts
everything now, just a PoC for now), based mostly on ebt_vlan.
What I am absolutely stuck on is xtables/libebt_MYMATCH.so library. I
mean, it is written, compiled properly, and objdump reports the same
structure as existing ones (say, libebt_vlan.so). The only slight
problem is that ebtables doesn't detect or recognize it.
When running the above ebtables example under strace, it does iterate
over "standard" libebt_* libraries (with newfstatat() and openat() )
but doesn't even try to touch mine with a long stick. It doesn't even
check if it is there.
When I do a match with existing libebt_* (say vlan), it still does
iterate over all standard libraries (for iteration's sake) and then
(apparently, there's no dload() or sth) just ignores libebt_vlan.so
and pulls NFT gun.
That's Arch system:
* ebtables 1.8.10 (nf_tables)
* iptables v1.8.10 (tried both legacy and nf_tables, no change in behaviour)
* kernel 6.9.3-hardened1-1-hardened
I even tried with manually compiled ebtables v2.0.11 (legacy), which
is, um, dated 2011.
What are my options now? Any guides on writing both nft kernel modules
and matching userspace libraries?
Or just forget all that and use raw @base,offset,length matches?
Best regards,
--
Paweł Kraszewski
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Writing own match module for modern ebtables.
2024-06-14 7:01 Writing own match module for modern ebtables Pawel Kraszewski
@ 2024-06-14 15:26 ` Pablo Neira Ayuso
2024-06-14 19:33 ` Pawel Kraszewski
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2024-06-14 15:26 UTC (permalink / raw)
To: Pawel Kraszewski; +Cc: netfilter
On Fri, Jun 14, 2024 at 09:01:22AM +0200, Pawel Kraszewski wrote:
> Hello!
>
> I'm trying to write a simple match module for ebtables. Nothing fancy,
> just check ethertype and first 2 bytes of payload. I need to make
> ebtables' dnat, based on a custom in-packet tag:
>
> > ebtables -t nat -A PREROUTING -i eth0 --MYMATCH-tag 10 -j dnat --to-destination SO:ME:MA:CA:DD:RS
>
> Kernel module ebt_MYMATCH.ko is almost ready (it just accepts
> everything now, just a PoC for now), based mostly on ebt_vlan.
>
> What I am absolutely stuck on is xtables/libebt_MYMATCH.so library. I
> mean, it is written, compiled properly, and objdump reports the same
> structure as existing ones (say, libebt_vlan.so). The only slight
> problem is that ebtables doesn't detect or recognize it.
>
> When running the above ebtables example under strace, it does iterate
> over "standard" libebt_* libraries (with newfstatat() and openat() )
> but doesn't even try to touch mine with a long stick. It doesn't even
> check if it is there.
>
> When I do a match with existing libebt_* (say vlan), it still does
> iterate over all standard libraries (for iteration's sake) and then
> (apparently, there's no dload() or sth) just ignores libebt_vlan.so
> and pulls NFT gun.
>
> That's Arch system:
> * ebtables 1.8.10 (nf_tables)
> * iptables v1.8.10 (tried both legacy and nf_tables, no change in behaviour)
> * kernel 6.9.3-hardened1-1-hardened
>
> I even tried with manually compiled ebtables v2.0.11 (legacy), which
> is, um, dated 2011.
>
> What are my options now? Any guides on writing both nft kernel modules
> and matching userspace libraries?
> Or just forget all that and use raw @base,offset,length matches?
That is an option, if you provide more info what --MYMATCH-tag 10 does.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Writing own match module for modern ebtables.
2024-06-14 15:26 ` Pablo Neira Ayuso
@ 2024-06-14 19:33 ` Pawel Kraszewski
0 siblings, 0 replies; 3+ messages in thread
From: Pawel Kraszewski @ 2024-06-14 19:33 UTC (permalink / raw)
Cc: netfilter
For starters - verify that ether-type is XXX, lowest bit of byte 0 of
payload is 0 and second byte is YY. I managed to do that with raw
matches, along with "set" to rewrite the destination MAC address. I
assume that putting that in bridge/nat/prerouting chain will do the
trick and the bridge will forward the packet to the new destination.
--
Paweł Kraszewski
pt., 14 cze 2024 o 17:26 Pablo Neira Ayuso <pablo@netfilter.org> napisał(a):
>
> On Fri, Jun 14, 2024 at 09:01:22AM +0200, Pawel Kraszewski wrote:
> > Hello!
> >
> > I'm trying to write a simple match module for ebtables. Nothing fancy,
> > just check ethertype and first 2 bytes of payload. I need to make
> > ebtables' dnat, based on a custom in-packet tag:
> >
> > > ebtables -t nat -A PREROUTING -i eth0 --MYMATCH-tag 10 -j dnat --to-destination SO:ME:MA:CA:DD:RS
> >
> > Kernel module ebt_MYMATCH.ko is almost ready (it just accepts
> > everything now, just a PoC for now), based mostly on ebt_vlan.
> >
> > What I am absolutely stuck on is xtables/libebt_MYMATCH.so library. I
> > mean, it is written, compiled properly, and objdump reports the same
> > structure as existing ones (say, libebt_vlan.so). The only slight
> > problem is that ebtables doesn't detect or recognize it.
> >
> > When running the above ebtables example under strace, it does iterate
> > over "standard" libebt_* libraries (with newfstatat() and openat() )
> > but doesn't even try to touch mine with a long stick. It doesn't even
> > check if it is there.
> >
> > When I do a match with existing libebt_* (say vlan), it still does
> > iterate over all standard libraries (for iteration's sake) and then
> > (apparently, there's no dload() or sth) just ignores libebt_vlan.so
> > and pulls NFT gun.
> >
> > That's Arch system:
> > * ebtables 1.8.10 (nf_tables)
> > * iptables v1.8.10 (tried both legacy and nf_tables, no change in behaviour)
> > * kernel 6.9.3-hardened1-1-hardened
> >
> > I even tried with manually compiled ebtables v2.0.11 (legacy), which
> > is, um, dated 2011.
> >
> > What are my options now? Any guides on writing both nft kernel modules
> > and matching userspace libraries?
> > Or just forget all that and use raw @base,offset,length matches?
>
> That is an option, if you provide more info what --MYMATCH-tag 10 does.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-14 19:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-14 7:01 Writing own match module for modern ebtables Pawel Kraszewski
2024-06-14 15:26 ` Pablo Neira Ayuso
2024-06-14 19:33 ` Pawel Kraszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox