]> git.ipfire.org Git - thirdparty/nftables.git/commit
evaluate: place byteorder conversion before rshift in payload expressions
authorPablo Neira Ayuso <pablo@netfilter.org>
Sun, 5 Nov 2023 20:54:25 +0000 (21:54 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 6 Nov 2023 11:29:22 +0000 (12:29 +0100)
commitcb9b72a43c5684379c027908d9f332170bf8dd15
tree56eb594412a9d0f5debfd08b89389a7504034dd9
parent57f092a87fc4bc61e29cff31dfff976e1f2005ab
evaluate: place byteorder conversion before rshift in payload expressions

Use the key from the evaluation context to perform the byteorder
conversion in case that this expression is used for lookups and updates
on explicit sets.

 # nft --debug=netlink add rule ip6 t output ip6 dscp @mapv6
 ip6 t output
  [ payload load 2b @ network header + 0 => reg 1 ]
  [ bitwise reg 1 = ( reg 1 & 0x0000c00f ) ^ 0x00000000 ]
  [ byteorder reg 1 = ntoh(reg 1, 2, 2) ]   <-------------- this was missing!
  [ bitwise reg 1 = ( reg 1 >> 0x00000006 ) ]
  [ lookup reg 1 set mapv6 ]

Also with set statements (updates from packet path):

 # nft --debug=netlink add rule ip6 t output update @mapv6 { ip6 dscp }
 ip6 t output
  [ payload load 2b @ network header + 0 => reg 1 ]
  [ bitwise reg 1 = ( reg 1 & 0x0000c00f ) ^ 0x00000000 ]
  [ byteorder reg 1 = ntoh(reg 1, 2, 2) ]   <------------- also here!
  [ bitwise reg 1 = ( reg 1 >> 0x00000006 ) ]
  [ dynset update reg_key 1 set mapv6 ]

Simple matches on values and implicit sets rely on the binary transfer
mechanism to propagate the shift to the constant, no explicit byteorder
is required in such case.

Fixes: 668c18f67203 ("evaluate: place byteorder conversion before rshift in payload statement")
Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c
tests/py/ip6/ip6.t
tests/py/ip6/ip6.t.json
tests/py/ip6/ip6.t.payload.inet
tests/py/ip6/ip6.t.payload.ip6