Skip to contentSkip to conversation

iptables: extensions: libxt_MARK: Fix translation of --set-xmark option

PATCH In review [email protected] 4 participants 5 messages Jun 21, 2016 – Jun 22, 2016 netfilter

lore
Share & tools
lore
#0 lore raw

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
index ec1ed05..12ab94f 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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 0xaf

After:

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 \
  0xffffff50
---
 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
maintainer
#2 lore raw
In reply to [email protected]
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 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

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

#3 lore raw

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 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

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.

Quoted 8 lines

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

#4 lore raw
In reply to [email protected]
Quoted 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 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

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