diff mbox series

[nft,v4,23/32] evaluate: set eval context to leftmost bitwise operand

Message ID 20220404121410.188509-24-jeremy@azazel.net
State Under Review
Delegated to: Pablo Neira
Headers show
Series Extend values assignable to packet marks and payload fields | expand

Commit Message

Jeremy Sowden April 4, 2022, 12:14 p.m. UTC
A bitwise expression currently derives its type and size from its
left operand.  Thus:

  ct mark & 0xff

has type `mark` and size `32`.

However, currently, something like:

  ct mark | ip dscp | 0x200

will fail because, although evaluation is left-associative, and
therefore this expression will be evaluated as:

 (ct mark | ip dscp) | 0x200

after the evaluation of `ct mark | ip dscp`, the evaluation context
contains the size and data-type of the `ip dscp` expression and so
`0x200` is out of range.

Instead, reset the evaluation context to the values from the left-hand
operand once both operands have been evaluated.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 src/evaluate.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/src/evaluate.c b/src/evaluate.c
index 6b1e295d216a..02bfde2a2ded 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1153,6 +1153,8 @@  static int expr_evaluate_bitwise(struct eval_ctx *ctx, struct expr **expr)
 {
 	struct expr *op = *expr, *left = op->left;
 
+	expr_evaluate_primary(ctx, &left);
+
 	if (byteorder_conversion(ctx, &op->right, left->byteorder) < 0)
 		return -1;