Skip to contentSkip to conversation

evaluate: follow prefix expression recursively

PATCH New Florian Westphal 1 participant 1 message Oct 17, 2025 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 evaluate: follow prefix expression recursively

Included bogons assert:
Assertion `!expr_is_constant(*expr) || expr_is_singleton(*expr)' failed

This is because the "foo*" + prefix combination causes expr_evaluate to replace the binop + string expression with another prefix that gets allocated while handling "foo*" (wildcard).

This causes expr_evaluate_prefix to build
a prefix -> prefix -> binop chain.

After this, we get:

Error: Right hand side of relational expression (implicit) must be constant a b ct helper "2.2.2.2.3*1"/80

    ~~~~~~~~~~^^^^^^^^^^^^^^^^
Error: Binary operation (&) is undefined for prefix expressions
a b ct helper "2.2.2.****02"/80
              ^^^^^^^^^^^^^^^^^

for those inputs rather than hitting assert() in byteorder_conversion() later on.

---
 src/evaluate.c                                         | 10 ++++++++++
 src/expression.c                                       |  1 +
 .../testcases/bogons/nft-f/byteorder_conversion_assert |  2 ++
 3 files changed, 13 insertions(+)
 create mode 100644 tests/shell/testcases/bogons/nft-f/byteorder_conversion_assert
src/evaluate.c +10 -0
index ffd3ce626859..b984ae4f89b5 100644
@@ -1273,6 +1273,16 @@ static int expr_evaluate_prefix(struct eval_ctx *ctx, struct expr **expr)
 	if (expr_evaluate(ctx, &prefix->prefix) < 0)
 		return -1;
 	base = prefix->prefix;
+
+	/* expr_evaluate may simplify EXPR_AND to another
+	 * prefix expression for inputs like "2.2.2.2.3*1"/80.
+	 *
+	 * Recurse until all the expressions have been simplified.
+	 * This also gets us the error checks for the expression
+	 * chain.
+	 */
+	if (base->etype == EXPR_PREFIX)
+		return expr_evaluate_prefix(ctx, &prefix->prefix);
 	assert(expr_is_constant(base));
 
 	prefix->dtype	  = datatype_get(base->dtype);
src/expression.c +1 -0
index 019c263f187b..81359ad4cc4e 100644
@@ -765,6 +765,7 @@ struct expr *prefix_expr_alloc(const struct location *loc,
 
 const char *expr_op_symbols[] = {
 	[OP_INVALID]	= "invalid",
+	[OP_IMPLICIT]	= "implicit",
 	[OP_HTON]	= "hton",
 	[OP_NTOH]	= "ntoh",
 	[OP_AND]	= "&",
tests/shell/testcases/bogons/nft-f/byteorder_conversion_assert new file +2 -0
new file mode 100644
index 000000000000..26c8914e7bba
@@ -0,0 +1,2 @@
+a b ct helper "2.2.2.2.3*1"/80
+a b ct helper "2.2.2.****02"/80
Signature · 1 line
2.51.0