diff mbox series

[iptables,04/23] libxtables: xtoptions: Treat NFPROTO_BRIDGE as IPv4

Message ID 20231220160636.11778-5-phil@nwl.cc
State Accepted
Headers show
Series Guided option parser for ebtables | expand

Commit Message

Phil Sutter Dec. 20, 2023, 4:06 p.m. UTC
When parsing for XTTYPE_HOST(MASK), the return value of afinfo_family()
is used to indicate the expected address family.

Make guided option parser expect IPv4 by default for ebtables as this is
the more common case. The exception is libebt_ip6, which will
temporarily adjust afinfo->family while parsing.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 libxtables/xtoptions.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jan Engelhardt Dec. 20, 2023, 7:20 p.m. UTC | #1
On Wednesday 2023-12-20 17:06, Phil Sutter wrote:

>When parsing for XTTYPE_HOST(MASK), the return value of afinfo_family()
>is used to indicate the expected address family.
>
>Make guided option parser expect IPv4 by default for ebtables as this is
>the more common case.

ebtables is about Ethernet addresses mostly,
and ebt_ip6 and ebt_ip have the same priority really.
Phil Sutter Dec. 20, 2023, 9:35 p.m. UTC | #2
On Wed, Dec 20, 2023 at 08:20:10PM +0100, Jan Engelhardt wrote:
> 
> On Wednesday 2023-12-20 17:06, Phil Sutter wrote:
> 
> >When parsing for XTTYPE_HOST(MASK), the return value of afinfo_family()
> >is used to indicate the expected address family.
> >
> >Make guided option parser expect IPv4 by default for ebtables as this is
> >the more common case.
> 
> ebtables is about Ethernet addresses mostly,
> and ebt_ip6 and ebt_ip have the same priority really.

That's right, but there's also libebt_arp which expects IPv4 address
in --arp-ip-src and --arp-ip-dst options.

I was a bit undecided about this solution because libebt_ip6's
workaround is fugly:

| xtables_set_nfproto(NFPROTO_IPV6);
| xtables_option_parse(cb);
| xtables_set_nfproto(NFPROTO_BRIDGE);

OTOH introducing XTTYPE_HOST{,MASK}{4,6} to force the expected address
family despite afinfo->family value seemed over-engineering given the
single user I had to cover after treating NFPROTO_BRIDGE as IPv4 by
default.

Cheers, Phil
diff mbox series

Patch

diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c
index 9377e1641f28c..5b693a9b00e3f 100644
--- a/libxtables/xtoptions.c
+++ b/libxtables/xtoptions.c
@@ -71,6 +71,7 @@  static uint8_t afinfo_family(void)
 {
 	switch (afinfo->family) {
 	case NFPROTO_ARP:
+	case NFPROTO_BRIDGE:
 		return NFPROTO_IPV4;
 	default:
 		return afinfo->family;