extensions: libxt_CONNMARK.c: Add translation to nft
PATCH 1/1 extensions: libxt_CONNMARK.c: Add translation to nft
Add translation for target CONNMARK to nftables.
Examples:
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffff
--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
extensions/libxt_CONNMARK.c +28 -0
@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate (const struct xt_entry_target *target, +struct xt_xlate *xl,int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) { +case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE : +xt_xlate_add (xl,"mark save nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : +xt_xlate_add (xl,"mark restore nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +default : +/* Should not happen */ +break ; + } + +return 1 ; +} +static struct xtables_target connmark_tg_reg[] = { { .family =NFPROTO_UNSPEC ,
@@ -362,6 +388,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = CONNMARK_parse, .x6_fcheck = connmark_tg_check, .x6_options = CONNMARK_opts, + .xlate = connmark_tg_xlate, }, { .version = XTABLES_VERSION,
@@ -377,6 +404,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = connmark_tg_parse, .x6_fcheck = connmark_tg_check, .x6_options = connmark_tg_opts, + .xlate = connmark_tg_xlate, }, };
Signature · 1 line
1.9.1
Quoted 33 lines · Bhumika Goyal
Add translation for target CONNMARK to nftables.
Examples:
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffffSigned-off-by Bhumika Goyal <[email protected]>--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)extensions/libxt_CONNMARK.c +7
-0@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate (const struct xt_entry_target *target, +struct xt_xlate *xl,int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) {
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 366
Quoted 10 lines
extensions/libxt_CONNMARK.c +10
-0+case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE : +xt_xlate_add (xl,"mark save nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : +xt_xlate_add (xl,"mark restore nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask);
This translation is not correct.
Quoted 38 lines · Pablo Neira Ayuso
Quoted 37 lines · Bhumika Goyal
Add translation for target CONNMARK to nftables.
Examples:
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffffSigned-off-by Bhumika Goyal <[email protected]>--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)extensions/libxt_CONNMARK.c +11
-0@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate (const struct xt_entry_target *target, +struct xt_xlate *xl,int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) { +case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE :
Quoted 9 lines
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 366
Quoted 6 lines
extensions/libxt_CONNMARK.c +6
-0+xt_xlate_add (xl,"mark save nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : +xt_xlate_add (xl,"mark restore nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask);This translation is not correct.
Thanks for the feedback. Could you please tell me the mistake as I am not able to figure out my mistake?
Thanks,
Bhumika
Quoted 49 lines · Bhumika Goyal
Quoted 38 lines · Pablo Neira Ayuso
Quoted 37 lines · Bhumika Goyal
Add translation for target CONNMARK to nftables.
Examples:
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffffSigned-off-by Bhumika Goyal <[email protected]>--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)extensions/libxt_CONNMARK.c +11
-0@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate (const struct xt_entry_target *target, +struct xt_xlate *xl,int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) { +case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE :Quoted 9 lines
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 366
Quoted 6 lines
extensions/libxt_CONNMARK.c +6
-0+xt_xlate_add (xl,"mark save nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : +xt_xlate_add (xl,"mark restore nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask);This translation is not correct.
Quoted 2 lines
Thanks for the feedback. Could you please tell me the mistake as I am not able to figure out my mistake?
You have to test your translations, to make sure they work fine with nft:
# nft add rule filter PREROUTING nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc
<cmdline>:1:32-34: Error: syntax error, unexpected add
add rule filter PREROUTING nft add rule ip mangle PREROUTING tcp dport
80 counter mark restore nfmask 0xc ctmask 0xc
^^^This syntax is not correct. Please, have a look at the wiki and investigate how to translate this. Thanks.
Quoted 56 lines · Pablo Neira Ayuso
Quoted 49 lines · Bhumika Goyal
Quoted 38 lines · Pablo Neira Ayuso
Quoted 37 lines · Bhumika Goyal
Add translation for target CONNMARK to nftables.
Examples:
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffffSigned-off-by Bhumika Goyal <[email protected]>--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)extensions/libxt_CONNMARK.c +11
-0@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate (const struct xt_entry_target *target, +struct xt_xlate *xl,int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) { +case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE :Quoted 9 lines
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 366
Quoted 6 lines
extensions/libxt_CONNMARK.c +6
-0+xt_xlate_add (xl,"mark save nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : +xt_xlate_add (xl,"mark restore nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask);This translation is not correct.
Quoted 2 lines
Thanks for the feedback. Could you please tell me the mistake as I am not able to figure out my mistake?
You have to test your translations, to make sure they work fine with nft:
Quoted 8 lines
# nft add rule filter PREROUTING nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc <cmdline>:1:32-34: Error: syntax error, unexpected add add rule filter PREROUTING nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc ^^^This syntax is not correct. Please, have a look at the wiki and investigate how to translate this. Thanks.
Ok. I will read more on the wiki and then try to correct it.
Thanks,
Bhumika
Hello Bhumika,
Quoted 4 lines · Bhumika Goyal
Add translation for target CONNMARK to nftables.
Examples:
Quoted 8 lines
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffff
^^^^^^^^^^^^^^ this does not work
Quoted 15 lines
Signed-off-by Bhumika Goyal <[email protected]>--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)extensions/libxt_CONNMARK.c +2
-0@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate(const struct xt_entry_target *target,
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 361
Quoted 10 lines
extensions/libxt_CONNMARK.c +10
-0+ struct xt_xlate *xl, int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) { +case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE : + xt_xlate_add(xl,"mark save nfmask 0x%x ctmask 0x%x",
^ missing space here
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 365
Quoted 4 lines
extensions/libxt_CONNMARK.c +4
-0+ info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : + xt_xlate_add(xl,"mark restore nfmask 0x%x ctmask 0x%x",
^ missing space here
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 369
Quoted 4 lines
extensions/libxt_CONNMARK.c +4
-0+ info->nfmask, info->ctmask); +break ; +default : +/* Should not happen */
^^^^^^^^^^^^^^^^^^^^^^^ this comment is not meaningfull
Quoted 26 lines
extensions/libxt_CONNMARK.c +8
-0+break ; + } + +return 1 ; +} +static struct xtables_target connmark_tg_reg[] = { { .family =NFPROTO_UNSPEC ,@@ -362,6 +388,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = CONNMARK_parse, .x6_fcheck = connmark_tg_check, .x6_options = CONNMARK_opts, + .xlate = connmark_tg_xlate, }, { .version = XTABLES_VERSION,@@ -377,6 +404,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = connmark_tg_parse, .x6_fcheck = connmark_tg_check, .x6_options = connmark_tg_opts, + .xlate = connmark_tg_xlate, }, };
Quoted 10 lines · Piyush Pangtey
Hello Bhumika,
Quoted 7 lines · Bhumika Goyal
Add translation for target CONNMARK to nftables.
Examples:
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff
Quoted 7 lines
Quoted 5 lines
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffff^^^^^^^^^^^^^^ this does not work
Thanks for the feedback.
Does the other two translations for --save-mark and --restore-mark look ok? Please suggest me the improvement for the --set-mark translation.
Quoted 35 lines
Quoted 15 lines
Signed-off-by Bhumika Goyal <[email protected]>--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)extensions/libxt_CONNMARK.c +2
-0@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate(const struct xt_entry_target *target,extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 361
Quoted 10 lines
extensions/libxt_CONNMARK.c +10
-0+ struct xt_xlate *xl, int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) { +case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE : + xt_xlate_add(xl,"mark save nfmask 0x%x ctmask 0x%x",^
missing space hereextensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 365
Quoted 4 lines
extensions/libxt_CONNMARK.c +4
-0+ info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : + xt_xlate_add(xl,"mark restore nfmask 0x%x ctmask 0x%x",^
missing space here
Quoted 7 lines
extensions/libxt_CONNMARK.c connmark_tg_save(const void *ip, const struct xt_entry_target *target) · line 369
Quoted 4 lines
extensions/libxt_CONNMARK.c +4
-0+ info->nfmask, info->ctmask); +break ; +default : +/* Should not happen */ ^^^^^^^^^^^^^^^^^^^^^^^
this comment is not meaningfull
Ok I will remove the comment.
Thanks,
Bhumika
Quoted 29 lines
Quoted 26 lines
extensions/libxt_CONNMARK.c +8
-0+break ; + } + +return 1 ; +} +static struct xtables_target connmark_tg_reg[] = { { .family =NFPROTO_UNSPEC ,@@ -362,6 +388,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = CONNMARK_parse, .x6_fcheck = connmark_tg_check, .x6_options = CONNMARK_opts, + .xlate = connmark_tg_xlate, }, { .version = XTABLES_VERSION,@@ -377,6 +404,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = connmark_tg_parse, .x6_fcheck = connmark_tg_check, .x6_options = connmark_tg_opts, + .xlate = connmark_tg_xlate, }, };
Quoted 2 lines · Bhumika Goyal
Add translation for target CONNMARK to nftables.
Hi Bhumika,
Quoted 11 lines
Examples:
$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --save-mark nft add rule ip mangle PREROUTING tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 80 -j CONNMARK --restore-mark --mask 12 nft add rule ip mangle PREROUTING tcp dport 80 counter mark restore nfmask 0xc ctmask 0xc$ sudo iptables-translate -t mangle -A PREROUTING -p tcp --dport 22 -j CONNMARK --set-mark 2 nft add rule ip mangle PREROUTING tcp dport 22 counter mark set 0x2/0xffffffff
In nftables, I'm seeing mangle supporting only chains with hook output, let Pablo comment about this.
I'm giving you an example using output chain only. For the rules that you've written above, say rule 1
nft add rule ip mangle OUTPUT tcp dport 80 counter mark save nfmask 0xffffffff ctmask 0xffffffff
You should carry out the testing as follows:
$ sudo nft add table mangle
$ sudo nft add chain mangle OUTPUT { type route hook output priority 0\;}
$ sudo <your rule goes here>Now, if nftables does not throw any errors, may be your translation is correct then, this however throws errors. Look out for correct translation code.
Hint: http://wiki.nftables.org/wiki-nftables/index.php/Setting_packet_metainformation
Thanks.
Quoted 61 lines
Signed-off-by Bhumika Goyal <[email protected]>--- extensions/libxt_CONNMARK.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)extensions/libxt_CONNMARK.c +28
-1@@ -347,6 +347,32 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target) } } +static int +connmark_tg_xlate (const struct xt_entry_target *target, +struct xt_xlate *xl,int numeric) +{ +const struct xt_connmark_tginfo1 *info = (const void *)target->data; + +switch (info->mode) { +case XT_CONNMARK_SET : +xt_xlate_add (xl,"mark set 0x%x/0x%x" , info->ctmark, info->ctmask); +break ; +case XT_CONNMARK_SAVE : +xt_xlate_add (xl,"mark save nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +case XT_CONNMARK_RESTORE : +xt_xlate_add (xl,"mark restore nfmask 0x%x ctmask 0x%x" , + info->nfmask, info->ctmask); +break ; +default : +/* Should not happen */ +break ; + } + +return 1 ; +} +static struct xtables_target connmark_tg_reg[] = { { .family =NFPROTO_UNSPEC ,@@ -362,6 +388,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = CONNMARK_parse, .x6_fcheck = connmark_tg_check, .x6_options = CONNMARK_opts, + .xlate = connmark_tg_xlate, }, { .version = XTABLES_VERSION,@@ -377,6 +404,7 @@ static struct xtables_target connmark_tg_reg[] = { .x6_parse = connmark_tg_parse, .x6_fcheck = connmark_tg_check, .x6_options = connmark_tg_opts, + .xlate = connmark_tg_xlate, }, }; --1.9.1