Skip to content

allow map lookups as operands of bitwise binops

Jochen Seeber netfilter-devel 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3src: allow map lookups as operands of bitwise binopsdoc/statements.txt src/evaluate.c src/expression.c +2 more+50 -40 replies
2/3tests: py: add map lookups as bitwise operandstests/py/ip/sets.t tests/py/ip/sets.t.json tests/py/ip/sets.t.payload.inet +2 more+158 -00 replies
3/3tests: shell: add map lookups as bitwise operandstests/shell/testcases/bitwise/0040mark_binop_14 tests/shell/testcases/bitwise/0040mark_binop_15 tests/shell/testcases/bitwise/dumps/0040mark_binop_14.json-nft +6 more+560 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH nft 0/3] allow map lookups as operands of bitwise binops

Hi,

this series allows a map lookup as operand of the bitwise operations &, | and ^ in statement expressions. This sets part of the packet mark from a map and keeps the other bits:

meta mark set meta mark & 0xffffff80 | (ip daddr . ip saddr map @m)

Today this takes a chain per map value, each running "meta mark set meta mark & 0xffffff80 | <value>", or a detour through the conntrack mark:

ct mark set ip daddr . ip saddr map @m
meta mark set meta mark & 0xffffff80 | ct mark

The kernel side exists already: since Linux 6.13, the bitwise expression operates on two registers, and nft uses this for variable right-hand operands since commit 54bfc38c ("src: allow binop expressions with variable right-hand operands"). Only the parsers rejected map lookups as operands.

Patch 1 changes the bison and JSON parsers, evaluation and printing. Patch 2 adds tests/py cases. Patch 3 adds tests/shell cases, including a packetpath test that checks the resulting mark on map hit and miss. The shell tests require the bitwise_multireg feature.

Two points worth a look in review:

- expr_evaluate_map() flags every map lookup as constant, and statements rely on this to skip byteorder conversion. Instead of changing that, patch 1 clears the flag on binop operands only.

- The grammar change also admits a map lookup as concatenation component. That linearized, but "nft list" then hit an assertion in netlink_parse_concat_expr(). Patch 1 rejects it in the evaluator.

Jochen Seeber (3):
src: allow map lookups as operands of bitwise binops
tests: py: add map lookups as bitwise operands
tests: shell: add map lookups as bitwise operands

 doc/statements.txt                            |   7 +
 src/evaluate.c                                |  26 +-
 src/expression.c                              |   2 +
 src/parser_bison.y                            |   4 +
 src/parser_json.c                             |  15 +-
 tests/py/ip/sets.t                            |   2 +
 tests/py/ip/sets.t.json                       |  91 +++++++
 tests/py/ip/sets.t.payload.inet               |  23 ++
 tests/py/ip/sets.t.payload.ip                 |  19 ++
 tests/py/ip/sets.t.payload.netdev             |  23 ++
 .../shell/testcases/bitwise/0040mark_binop_14 |  14 +
 .../shell/testcases/bitwise/0040mark_binop_15 |  13 +
 .../bitwise/dumps/0040mark_binop_14.json-nft  | 100 +++++++
 .../bitwise/dumps/0040mark_binop_14.nft       |  11 +
 .../bitwise/dumps/0040mark_binop_15.json-nft  |  85 ++++++
 .../bitwise/dumps/0040mark_binop_15.nft       |   6 +
 .../testcases/packetpath/bitwise_map_operand  |  62 +++++
 .../dumps/bitwise_map_operand.json-nft        | 250 ++++++++++++++++++
 .../packetpath/dumps/bitwise_map_operand.nft  |  19 ++
 19 files changed, 768 insertions(+), 4 deletions(-)
 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_14
 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_15
 create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_14.json-nft
 create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_14.nft
 create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_15.json-nft
 create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_15.nft
 create mode 100755 tests/shell/testcases/packetpath/bitwise_map_operand
 create mode 100644 tests/shell/testcases/packetpath/dumps/bitwise_map_operand.json-nft
 create mode 100644 tests/shell/testcases/packetpath/dumps/bitwise_map_operand.nft
Signature · 1 line
2.56.0