iptables: extensions: libxt_MARK: Fix translation of --set-xmark option
PATCH 1/1 iptables: extensions: libxt_MARK: Fix translation of --set-xmark option
From: Roberto García <[email protected]>
Fix translation of MARK target's --set-xmark option.
Before:
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and 0xaf
After:
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and \ 0xffffff50
--- extensions/libxt_MARK.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
extensions/libxt_MARK.c +1 -1
@@ -262,7 +262,7 @@ static int mark_tg_xlate(const void *ip, const struct xt_entry_target *target,xt_xlate_add (xl,"0x%x " , info->mark); else xt_xlate_add(xl, "mark xor 0x%x and 0x%x ", info->mark, - info->mask); + ~info->mask);return 1 ; }
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 11 lines · On 21 June 2016 at 23:03, <[email protected]> wrote:
From: Roberto García <[email protected]>
Fix translation of MARK target's --set-xmark option.
Before:
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and 0xafAfter:
Quoted 9 lines
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and \ 0xffffff50Signed-off-by Roberto García <[email protected]>--- extensions/libxt_MARK.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Seems good to me :-)
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
Florian Westphal
maintainerQuoted 6 lines · [email protected] <[email protected]> wrote:
From: Roberto García <[email protected]>
Fix translation of MARK target's --set-xmark option.
Before:
Quoted 8 lines
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and 0xafAfter:
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and \ 0xffffff50
Hmm, I wonder if this is correct... iptables man page says:
--set-xmark value[/mask]
Zeroes out the bits given by mask and XORs value into the packet mark ("nfmark"). If mask is omitted, 0xFFFFFFFF is assumed.
So the iptables command is supposed to
mark = skb->mark
mark = mark & ~0xaf
mark ^= 0x64
skb->mark = mark
The proposed translation results in:
nft --debug=netlink add rule ip mangle PREROUTING meta mark set mark xor 0x64 and 0xffffff50
[ meta load mark => reg 1 ]
[ bitwise reg 1 = (reg=1 & 0xffffffff ) ^ 0x00000040 ]
[ meta set mark with reg 1 ]
As you can see nft did perform the '0x64 and 0xffffff50' part in an optimization pass so we end up not masking anything and then xor'ing 0x40.
I think this should be:
nft --debug=netlink add rule ip mangle PREROUTING meta mark set mark and 0xffffff50 xor 0x64
[ meta load mark => reg 1 ]
[ bitwise reg 1 = (reg=1 & 0xffffff50 ) ^ 0x00000064 ]
[ meta set mark with reg 1 ]
which -- afaiu -- matches what the xtables target would do.
--
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
I misunderstood the explanation of the option. I'm going to fix that right now.
Thanks for pointing out the error!
Quoted 39 lines · Florian Westphal
Quoted 6 lines · [email protected] <[email protected]> wrote:
From: Roberto García <[email protected]>
Fix translation of MARK target's --set-xmark option.
Before:
Quoted 8 lines
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and 0xafAfter:
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and \ 0xffffff50Hmm, I wonder if this is correct... iptables man page says:
--set-xmark value[/mask]
Zeroes out the bits given by mask and XORs value into the packet mark ("nfmark"). If mask is omitted,0xFFFFFFFFis assumed.So the iptables command is supposed to
mark = skb->mark mark = mark & ~0xaf mark ^= 0x64 skb->mark = markThe proposed translation results in:
nft --debug=netlink add rule ip mangle PREROUTING meta mark set mark xor0x64and0xffffff50
[ meta load mark => reg 1 ]
[ bitwise reg 1 = (reg=1 &0xffffffff) ^0x00000040]
[ meta set mark with reg 1 ]As you can see nft did perform the '
0x64and0xffffff50' part in an optimization pass so we end up not masking anything and then xor'ing0x40.
Quoted 8 lines
I think this should be:
nft --debug=netlink add rule ip mangle PREROUTING meta mark set mark and0xffffff50xor0x64
[ meta load mark => reg 1 ]
[ bitwise reg 1 = (reg=1 &0xffffff50) ^0x00000064]
[ meta set mark with reg 1 ]which -- afaiu -- matches what the xtables target would do.
--
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
Pablo Neira Ayuso
maintainerQuoted 6 lines · On Tue, Jun 21, 2016 at 11:03:43PM +0200, [email protected] wrote:
From: Roberto García <[email protected]>
Fix translation of MARK target's --set-xmark option.
Before:
Quoted 8 lines
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and 0xafAfter:
# iptables-translate -t mangle -A PREROUTING -j MARK --set-xmark 0x64/0xaf nft add rule ip mangle PREROUTING counter meta mark set mark xor 0x64 and \ 0xffffff50
Applied, thanks.
--
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