extensions: libebt_redirect: Fix target translation
Phil Sutter
reviewerPATCH 1/6 extensions: libebt_redirect: Fix target translation
While EBT_ACCEPT is the default verdict for ebtables targets, omitting it from translation implicitly converts it into 'continue'. Omit the non-default EBT_CONTINUE instead.
--- extensions/libebt_redirect.c | 2 +- extensions/libebt_redirect.txlate | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 extensions/libebt_redirect.txlate
extensions/libebt_redirect.c +1 -1
@@ -84,7 +84,7 @@ static int brredir_xlate(struct xt_xlate *xl,const struct ebt_redirect_info *red = (const void *)params->target->data;xt_xlate_add (xl,"meta set pkttype host" ); -if (red->target !=EBT_ACCEPT ) +if (red->target !=EBT_CONTINUE )xt_xlate_add (xl," %s " ,brredir_verdict (red->target));return 1 ; }
extensions/libebt_redirect.txlate new file +8 -0
@@ -0,0 +1,8 @@ +ebtables-translate -t nat -A PREROUTING -d de:ad:00:00:be:ef -j redirect +nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta set pkttype host accept' + +ebtables-translate -t nat -A PREROUTING -d de:ad:00:00:be:ef -j redirect --redirect-target RETURN +nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta set pkttype host return' + +ebtables-translate -t nat -A PREROUTING -d de:ad:00:00:be:ef -j redirect --redirect-target CONTINUE +nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta set pkttype host'
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 2/6 extensions: libebt_redirect: Fix for wrong syntax in translation
Meta key comes before 'set' in meta statement.
--- extensions/libebt_redirect.c | 2 +- extensions/libebt_redirect.txlate | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
extensions/libebt_redirect.c +1 -1
@@ -83,7 +83,7 @@ static int brredir_xlate(struct xt_xlate *xl, {const struct ebt_redirect_info *red = (const void *)params->target->data; -xt_xlate_add (xl,"meta set pkttype host" ); +xt_xlate_add (xl,"meta pkttype set host" );if (red->target !=EBT_CONTINUE )xt_xlate_add (xl," %s " ,brredir_verdict (red->target));return 1 ;
extensions/libebt_redirect.txlate +3 -3
@@ -1,8 +1,8 @@ ebtables-translate -t nat -A PREROUTING -d de:ad:00:00:be:ef -j redirect -nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta set pkttype host accept' +nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta pkttype set host accept' ebtables-translate -t nat -A PREROUTING -d de:ad:00:00:be:ef -j redirect --redirect-target RETURN -nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta set pkttype host return' +nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta pkttype set host return' ebtables-translate -t nat -A PREROUTING -d de:ad:00:00:be:ef -j redirect --redirect-target CONTINUE -nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta set pkttype host' +nft 'add rule bridge nat PREROUTING ether daddr de:ad:00:00:be:ef counter meta pkttype set host'
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 3/6 extensions: libebt_ip: Do not use 'ip dscp' for translation
In reply to Phil SutterConverting from TOS field match to DSCP one is irreversible, so replay testing is not possible. Use a raw payload expression to produce something that translates 1:1 back into an 'ip' match.
--- extensions/libebt_ip.c | 4 ++-- extensions/libebt_ip.txlate | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
extensions/libebt_ip.c +2 -2
@@ -442,10 +442,10 @@ static int brip_xlate(struct xt_xlate *xl,brip_xlate_nh (xl, info,EBT_IP_DEST );if (info->bitmask &EBT_IP_TOS ) { -xt_xlate_add (xl,"ip dscp " ); +xt_xlate_add (xl,"@nh,8,8 " );if (info->invflags &EBT_IP_TOS )xt_xlate_add (xl,"!= " ); -xt_xlate_add (xl,"0x%02x " , info->tos &0x3f );/* remove ECN bits */ +xt_xlate_add (xl,"0x%02x " , info->tos); }if (info->bitmask &EBT_IP_PROTO ) {struct protoent *pe;
extensions/libebt_ip.txlate +1 -1
@@ -5,7 +5,7 @@ ebtables-translate -I FORWARD -p ip --ip-dst 10.0.0.1 nft 'insert rule bridge filter FORWARD ip daddr 10.0.0.1 counter' ebtables-translate -I OUTPUT 3 -p ip -o eth0 --ip-tos 0xff -nft 'insert rule bridge filter OUTPUT oifname "eth0" ip dscp 0x3f counter' +nft 'insert rule bridge filter OUTPUT oifname "eth0" @nh,8,8 0xff counter' ebtables-translate -A FORWARD -p ip --ip-proto tcp --ip-dport 22 nft 'add rule bridge filter FORWARD tcp dport 22 counter'
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 4/6 extensions: libebt_ip: Translation has to match on ether type
In reply to Phil SutterOn one hand, nft refuses th expression in bridge family if layer3 protocol has not been assured by a previous match. On the other, ebt_ip kernel module will only match on IPv4 packets, so there might be a functional change in the translation versus the original.
Instead of just always emitting an 'ether type' match, decide whether it's actually needed - explicit "ip <something>" payload matches (or icmp ones) cause implicit creation of a match on IPv4 by nft.
--- extensions/libebt_ip.c | 21 +++++++++++++++++++++ extensions/libebt_ip.txlate | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-)
extensions/libebt_ip.c +21 -0
@@ -432,6 +432,24 @@ static void brip_xlate_nh(struct xt_xlate *xl, xtables_ipmask_to_numeric(maskp)); } +static bool may_skip_ether_type_dep (uint8_t flags) +{ +/* these convert to "ip (s|d)addr" matches */ +if (flags & (EBT_IP_SOURCE |EBT_IP_DEST )) +return true; + +/* icmp match triggers implicit ether type dependency in nft */ +if (flags &EBT_IP_ICMP ) +return true; + +/* allow if "ip protocol" match is created by brip_xlate() */ +if (flags &EBT_IP_PROTO && + !(flags & (EBT_IP_SPORT |EBT_IP_DPORT |EBT_IP_ICMP ))) +return true; + +return false; +} +static int brip_xlate (struct xt_xlate *xl,const struct xt_xlate_mt_params *params) {
@@ -441,6 +459,9 @@ static int brip_xlate(struct xt_xlate *xl,brip_xlate_nh (xl, info,EBT_IP_SOURCE );brip_xlate_nh (xl, info,EBT_IP_DEST ); +if (!may_skip_ether_type_dep (info->bitmask)) +xt_xlate_add (xl,"ether type ip " ); +if (info->bitmask &EBT_IP_TOS ) {xt_xlate_add (xl,"@nh,8,8 " );if (info->invflags &EBT_IP_TOS )
extensions/libebt_ip.txlate +3 -3
@@ -5,13 +5,13 @@ ebtables-translate -I FORWARD -p ip --ip-dst 10.0.0.1 nft 'insert rule bridge filter FORWARD ip daddr 10.0.0.1 counter' ebtables-translate -I OUTPUT 3 -p ip -o eth0 --ip-tos 0xff -nft 'insert rule bridge filter OUTPUT oifname "eth0" @nh,8,8 0xff counter' +nft 'insert rule bridge filter OUTPUT oifname "eth0" ether type ip @nh,8,8 0xff counter' ebtables-translate -A FORWARD -p ip --ip-proto tcp --ip-dport 22 -nft 'add rule bridge filter FORWARD tcp dport 22 counter' +nft 'add rule bridge filter FORWARD ether type ip tcp dport 22 counter' ebtables-translate -A FORWARD -p ip --ip-proto udp --ip-sport 1024:65535 -nft 'add rule bridge filter FORWARD udp sport 1024-65535 counter' +nft 'add rule bridge filter FORWARD ether type ip udp sport 1024-65535 counter' ebtables-translate -A FORWARD -p ip --ip-proto 253 nft 'add rule bridge filter FORWARD ip protocol 253 counter'
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 5/6 ebtables: ip and ip6 matches depend on protocol match
In reply to Phil SutterThis is consistent with legacy ebtables, also avoids invalid combinations like '-p IPv6 --ip-source 1.2.3.4'.
--- iptables/nft-bridge.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
iptables/nft-bridge.c +9 -2
@@ -104,11 +104,18 @@ static int nft_bridge_add_match(struct nft_handle *h, const struct ebt_entry *fw, struct nftnl_rule *r, struct xt_entry_match *m) { - if (!strcmp(m->u.user.name, "802_3") && - !(fw->bitmask & EBT_802_3)) + if (!strcmp(m->u.user.name, "802_3") && !(fw->bitmask & EBT_802_3)) xtables_error(PARAMETER_PROBLEM, "For 802.3 DSAP/SSAP filtering the protocol must be LENGTH"); +if (!strcmp (m->u.user.name,"ip" ) && fw->ethproto !=htons (ETH_P_IP )) +xtables_error (PARAMETER_PROBLEM , +"For IP filtering the protocol must be specified as IPv4." ); + +if (!strcmp (m->u.user.name,"ip6" ) && fw->ethproto !=htons (ETH_P_IPV6 )) +xtables_error (PARAMETER_PROBLEM , +"For IPv6 filtering the protocol must be specified as IPv6." ); +return add_match (h, r, m); }
Signature · 1 line
2.38.0
Phil Sutter
reviewerPATCH 6/6 xtables-translate: Support insert with index
In reply to Phil SutterTranslation is pretty simple due to nft's 'insert rule ... index' support. Testing the translation is sadly not: index 1 vanishes (as it should), higher indexes are rejected in replay mode since no rules previously exist.
--- extensions/libebt_ip.txlate | 2 +- iptables/xtables-translate.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
extensions/libebt_ip.txlate +1 -1
@@ -4,7 +4,7 @@ nft 'add rule bridge filter FORWARD ip saddr != 192.168.0.0/24 counter accept' ebtables-translate -I FORWARD -p ip --ip-dst 10.0.0.1 nft 'insert rule bridge filter FORWARD ip daddr 10.0.0.1 counter' -ebtables-translate -I OUTPUT 3 -p ip -o eth0 --ip-tos 0xff +ebtables-translate -I OUTPUT -p ip -o eth0 --ip-tos 0xff nft 'insert rule bridge filter OUTPUT oifname "eth0" ether type ip @nh,8,8 0xff counter' ebtables-translate -A FORWARD -p ip --ip-proto tcp --ip-dport 22
iptables/xtables-translate.c +2 -0
@@ -173,6 +173,8 @@ static int nft_rule_xlate_add(struct nft_handle *h, tick, append ?"add" :"insert" , family2str[h->family], p->table, p->chain); +if (!append && p->rulenum >1 ) +printf ("index %d " , p->rulenum);printf ("%s%s\n" ,xt_xlate_rule_get (xl), tick);
Signature · 1 line
2.38.0
Phil Sutter
reviewerQuoted 6 lines · Phil Sutter
While
EBT_ACCEPTis the default verdict for ebtables targets, omitting it from translation implicitly converts it into 'continue'. Omit the non-defaultEBT_CONTINUEinstead.Fixes 24ce7465056ae ("ebtables-compat: add redirect match extension")Signed-off-by Phil Sutter <[email protected]>
And this series also applied. ;)