Now that we support non-constant RHS side in binary operations, reject XOR with non-constant key: we cannot transfer the expression. Fixes: 54bfc38c522b ("src: allow binop expressions with variable right-hand operands") Signed-off-by: Florian Westphal --- I suggest to defer this until after 1.1.4 is out. src/evaluate.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/evaluate.c b/src/evaluate.c index 81e88d11aecb..1d102f842df0 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -2578,16 +2578,20 @@ static int binop_can_transfer(struct eval_ctx *ctx, switch (left->op) { case OP_LSHIFT: + assert(left->right->etype == EXPR_VALUE); + assert(right->etype == EXPR_VALUE); + if (mpz_scan1(right->value, 0) < mpz_get_uint32(left->right->value)) return expr_binary_error(ctx->msgs, right, left, "Comparison is always false"); return 1; case OP_RSHIFT: + assert(left->right->etype == EXPR_VALUE); if (ctx->ectx.len < right->len + mpz_get_uint32(left->right->value)) ctx->ectx.len += mpz_get_uint32(left->right->value); return 1; case OP_XOR: - return 1; + return expr_is_constant(left->right); default: return 0; } -- 2.49.1 One to validate parsing, and one to test that packets match the expected mapping. omits json file because of: internal:0:0-0: Error: Expression type payload not allowed in context (RHS, STMT). i.e. there is more work to be done on json side to support this. Signed-off-by: Florian Westphal --- I suggest to defer this until after 1.1.4 is out. .../bitwise/bitwise_in_sets_and_maps | 27 ++++++++ .../dumps/bitwise_in_sets_and_maps.nft | 17 ++++++ .../testcases/packetpath/bitwise_with_map | 61 +++++++++++++++++++ .../packetpath/dumps/bitwise_with_map.nft | 16 +++++ 4 files changed, 121 insertions(+) create mode 100755 tests/shell/testcases/bitwise/bitwise_in_sets_and_maps create mode 100644 tests/shell/testcases/bitwise/dumps/bitwise_in_sets_and_maps.nft create mode 100755 tests/shell/testcases/packetpath/bitwise_with_map create mode 100644 tests/shell/testcases/packetpath/dumps/bitwise_with_map.nft diff --git a/tests/shell/testcases/bitwise/bitwise_in_sets_and_maps b/tests/shell/testcases/bitwise/bitwise_in_sets_and_maps new file mode 100755 index 000000000000..4f5044f512aa --- /dev/null +++ b/tests/shell/testcases/bitwise/bitwise_in_sets_and_maps @@ -0,0 +1,27 @@ +#!/bin/bash + +# NFT_TEST_REQUIRES(NFT_TEST_HAVE_bitshift) + +set -e + +$NFT -f - <