extensions: libxt_mark: Add translation to nft
PATCH v3 1/1 extensions: libxt_mark: Add translation to nft
Add translation for metainformation mark to nftables.
Examples:
$ sudo iptables-translate -I INPUT -m mark --mark 12 nft insert rule ip filter INPUT mark & xc counter
$ sudo iptables-translate -A FORWARD -m mark --mark 22 -j ACCEPT nft add rule ip filter FORWARD mark & x16 counter accept
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 46000 -m mark --mark 0x40 nft add rule ip mangle PREROUTING tcp dport 46000 mark & x40 counter
$ sudo iptables-translate -A FORWARD -m mark -k 0x400/0x400 -j ACCEPT nft add rule ip filter FORWARD mark & x400 == x400 counter accept
Signed-off-by Shivani Bhardwaj <[email protected]>
---
Changes in v3:
Fix indentation errors as shown by checkpatch Make commit message clearer by adding examples
extensions/libxt_mark.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-)
extensions/libxt_mark.c +60 -2
@@ -75,7 +75,7 @@ mark_print(const void *ip, const struct xt_entry_match *match, int numeric)if (info->invert)printf (" !" ); - +print_mark (info->mark, info->mask); }
@@ -97,11 +97,67 @@ mark_save(const void *ip, const struct xt_entry_match *match)if (info->invert)printf (" !" ); - +printf (" --mark" );print_mark (info->mark, info->mask); } +static void +print_mark_xlate (struct xt_buf *buf, +unsigned int mark,unsigned int mask) +{ +if (mask !=0xffffffffU ) +xt_buf_add (buf," & x%x == x%x" , mark, mask); +else +xt_buf_add (buf," & x%x" , mark); +} + +static void +mark_mt_print_xlate (const struct xt_entry_match *match, +struct xt_buf *buf,int numeric) +{ +const struct xt_mark_mtinfo1 *info = (const void *)match->data; + +xt_buf_add (buf,"%s" , info->invert ?" !=" :"" ); +print_mark_xlate (buf, info->mark, info->mask); +} + +static int +mark_mt_xlate (const struct xt_entry_match *match, +struct xt_buf *buf,int numeric) +{ +const struct xt_mark_mtinfo1 *info = (const void *)match->data; + +xt_buf_add (buf,"mark %s" , info->invert ?" !=" :"" ); +print_mark_xlate (buf, info->mark, info->mask); +xt_buf_add (buf," " ); + +return 1 ; +} + +static void +mark_print_xlate (const struct xt_entry_match *match, +struct xt_buf *buf,int numeric) +{ +const struct xt_mark_info *info = (const void *)match->data; + +xt_buf_add (buf,"%s" , info->invert ?" !=" :"" ); +print_mark_xlate (buf, info->mark, info->mask); +} + +static int +mark_xlate (const struct xt_entry_match *match, +struct xt_buf *buf,int numeric) +{ +const struct xt_mark_info *info = (const void *)match->data; + +xt_buf_add (buf,"mark %s" , info->invert ?" !=" :"" ); +print_mark_xlate (buf, info->mark, info->mask); +xt_buf_add (buf," " ); + +return 1 ; +} +static struct xtables_match mark_mt_reg[] = { { .family =NFPROTO_UNSPEC ,
@@ -115,6 +171,7 @@ static struct xtables_match mark_mt_reg[] = { .save = mark_save, .x6_parse = mark_parse, .x6_options = mark_mt_opts, + .xlate = mark_xlate, }, { .version = XTABLES_VERSION,
@@ -128,6 +185,7 @@ static struct xtables_match mark_mt_reg[] = { .save = mark_mt_save, .x6_parse = mark_mt_parse, .x6_options = mark_mt_opts, + .xlate = mark_mt_xlate, }, };
Signature · 1 line
1.9.1
Pablo Neira Ayuso
maintainerQuoted 7 lines · Shivani Bhardwaj
Add translation for metainformation mark to nftables.
Examples:
$ sudo iptables-translate -I INPUT -m mark --mark 12 nft insert rule ip filter INPUT mark & xc counter
Quoted 8 lines
$ sudo iptables-translate -A FORWARD -m mark --mark 22 -j ACCEPT nft add rule ip filter FORWARD mark & x16 counter accept$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 46000 -m mark --mark 0x40 nft add rule ip mangle PREROUTING tcp dport 46000 mark & x40 counter$ sudo iptables-translate -A FORWARD -m mark -k 0x400/0x400 -j ACCEPT nft add rule ip filter FORWARD mark & x400 == x400 counter accept
Much better, getting closer, but still these translations are not correct, please fix them and respin, thanks.