iptables: extensions: libxt_ecn: Add translation to nft
PATCH 1/1 iptables: extensions: libxt_ecn: Add translation to nft
From: Roberto García <[email protected]>
Add translation of the ecn match to nftables.
Examples:
# iptables-translate -A INPUT -m ecn --ecn-ip-ect 0 nft add rule ip filter INPUT ip ecn not-ect counter
# iptables-translate -A INPUT -m ecn --ecn-ip-ect 1 nft add rule ip filter INPUT ip ecn ect1 counter
# iptables-translate -A INPUT -m ecn --ecn-ip-ect 2 nft add rule ip filter INPUT ip ecn ect0 counter
# iptables-translate -A INPUT -m ecn --ecn-ip-ect 3 nft add rule ip filter INPUT ip ecn ce counter
# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 0 nft add rule ip filter INPUT ip ecn != not-ect counter
# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 1 nft add rule ip filter INPUT ip ecn != ect1 counter
# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 2 nft add rule ip filter INPUT ip ecn != ect0 counter
# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 3 nft add rule ip filter INPUT ip ecn != ce counter
--- extensions/libxt_ecn.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
extensions/libxt_ecn.c +45 -0
@@ -118,6 +118,50 @@ static void ecn_save(const void *ip, const struct xt_entry_match *match) } } +static int ecn_xlate (const void *ip,const struct xt_entry_match *match, +struct xt_xlate *xl,int numeric) +{ +const struct xt_ecn_info *einfo = + (const struct xt_ecn_info *)match->data; + +if (einfo->operation &XT_ECN_OP_MATCH_IP ) { +xt_xlate_add (xl,"ip ecn " ); +if (einfo->invert) { +switch (einfo->ip_ect) { +case 0 : +xt_xlate_add (xl,"!= not-ect " ); +break ; +case 1 : +xt_xlate_add (xl,"!= ect1 " ); +break ; +case 2 : +xt_xlate_add (xl,"!= ect0 " ); +break ; +case 3 : +xt_xlate_add (xl,"!= ce " ); +break ; + } + }else { +switch (einfo->ip_ect) { +case 0 : +xt_xlate_add (xl,"not-ect " ); +break ; +case 1 : +xt_xlate_add (xl,"ect1 " ); +break ; +case 2 : +xt_xlate_add (xl,"ect0 " ); +break ; +case 3 : +xt_xlate_add (xl,"ce " ); +break ; + } + } +return 1 ; + }else +return 0 ; +} +static struct xtables_match ecn_mt_reg = { .name ="ecn" , .version =XTABLES_VERSION ,
@@ -130,6 +174,7 @@ static struct xtables_match ecn_mt_reg = { .x6_parse = ecn_parse, .x6_fcheck = ecn_check, .x6_options = ecn_opts, + .xlate = ecn_xlate, };void _init (void )
Signature · 6 lines
2.8.0 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 69 lines · On 28 June 2016 at 21:58, <[email protected]> wrote:
From: Roberto García <[email protected]>
Add translation of the ecn match to nftables.
Examples:
# iptables-translate -A INPUT -m ecn --ecn-ip-ect 0 nft add rule ip filter INPUT ip ecn not-ect counter# iptables-translate -A INPUT -m ecn --ecn-ip-ect 1 nft add rule ip filter INPUT ip ecn ect1 counter# iptables-translate -A INPUT -m ecn --ecn-ip-ect 2 nft add rule ip filter INPUT ip ecn ect0 counter# iptables-translate -A INPUT -m ecn --ecn-ip-ect 3 nft add rule ip filter INPUT ip ecn ce counter# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 0 nft add rule ip filter INPUT ip ecn != not-ect counter# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 1 nft add rule ip filter INPUT ip ecn != ect1 counter# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 2 nft add rule ip filter INPUT ip ecn != ect0 counter# iptables-translate -A INPUT -m ecn ! --ecn-ip-ect 3 nft add rule ip filter INPUT ip ecn != ce counterSigned-off-by Roberto García <[email protected]>--- extensions/libxt_ecn.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)extensions/libxt_ecn.c +27
-0@@ -118,6 +118,50 @@ static void ecn_save(const void *ip, const struct xt_entry_match *match) } } +static int ecn_xlate (const void *ip,const struct xt_entry_match *match, +struct xt_xlate *xl,int numeric) +{ +const struct xt_ecn_info *einfo = + (const struct xt_ecn_info *)match->data; + +if (einfo->operation &XT_ECN_OP_MATCH_IP ) { +xt_xlate_add (xl,"ip ecn " ); +if (einfo->invert) { +switch (einfo->ip_ect) { +case 0 : +xt_xlate_add (xl,"!= not-ect " ); +break ; +case 1 : +xt_xlate_add (xl,"!= ect1 " ); +break ; +case 2 : +xt_xlate_add (xl,"!= ect0 " ); +break ; +case 3 : +xt_xlate_add (xl,"!= ce " ); +break ; + } + }else { +switch (einfo->ip_ect) { +case 0 : +xt_xlate_add (xl,"not-ect " );
extensions/libxt_ecn.c static void ecn_save(const void *ip, const struct xt_entry_match *match) · line 157
Quoted 10 lines
extensions/libxt_ecn.c +10
-0+break ; +case 1 : +xt_xlate_add (xl,"ect1 " ); +break ; +case 2 : +xt_xlate_add (xl,"ect0 " ); +break ; +case 3 : +xt_xlate_add (xl,"ce " ); +break ;
I would try to compact a bit the code, ie:
[...]xt_xlate_add(xl, "ip ecn ");
if (einfo->invert)
xt_xlate_add(xl, "!= ");
switch (einfo->ip_ect) {
case 0:
xt_xlate_add(xl, "not-ect");
break;
[...]
Signature · 5 lines
Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 5 lines · On 28 June 2016 at 21:58, <[email protected]> wrote:
extensions/libxt_ecn.c +0
-0
extensions/libxt_ecn.c static void ecn_save(const void *ip, const struct xt_entry_match *match) · line 127
Quoted 10 lines
extensions/libxt_ecn.c +7
-0@@ -118,6 +118,50 @@ static void ecn_save(const void *ip, const struct xt_entry_match *match) } } +static int ecn_xlate (const void *ip,const struct xt_entry_match *match, +struct xt_xlate *xl,int numeric) +{ +const struct xt_ecn_info *einfo = + (const struct xt_ecn_info *)match->data; + +if (einfo->operation &XT_ECN_OP_MATCH_IP ) {
You could also do an early return here, given the case of this if () failing we have nothing to translate.
Signature · 5 lines
Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Ok, gonna fix that ASAP.
Quoted 20 lines · Arturo Borrero Gonzalez
Quoted 5 lines · On 28 June 2016 at 21:58, <[email protected]> wrote:
extensions/libxt_ecn.c +0
-0extensions/libxt_ecn.c static void ecn_save(const void *ip, const struct xt_entry_match *match) · line 127
Quoted 10 lines
extensions/libxt_ecn.c +7
-0@@ -118,6 +118,50 @@ static void ecn_save(const void *ip, const struct xt_entry_match *match) } } +static int ecn_xlate (const void *ip,const struct xt_entry_match *match, +struct xt_xlate *xl,int numeric) +{ +const struct xt_ecn_info *einfo = + (const struct xt_ecn_info *)match->data; + +if (einfo->operation &XT_ECN_OP_MATCH_IP ) {You could also do an early return here, given the case of this if () failing we have nothing to translate.