allow map lookups as operands of bitwise binops
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | src: allow map lookups as operands of bitwise binopsdoc/ src/ src/ +2 more | +50 | 0 replies | |
| 2/3 | tests: py: add map lookups as bitwise operandstests/ tests/ tests/ +2 more | +158 | 0 replies | |
| 3/3 | tests: shell: add map lookups as bitwise operandstests/ tests/ tests/ +6 more | +560 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
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