Skip to contentSkip to conversation

evaluate: allow == and != in the new shortcut syntax to match for flags

PATCH New Pablo Neira Ayuso 1 participant 2 messages May 24, 2021 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 evaluate: allow == and != in the new shortcut syntax to match for flags

The flags / mask syntax only allows for ==, != and the implicit operation (which is == in this case).

 # nft add rule x y tcp flags ! syn / syn,ack
 Error: either == or != is allowed
 add rule x y tcp flags ! syn / syn,ack
              ^^^^^^^^^^^^^^^^^^^^^^^^^
---
 src/evaluate.c | 4 ++++
 1 file changed, 4 insertions(+)
src/evaluate.c +4 -0
index 006b04affbd7..384e2fa786e0 100644
@@ -2139,6 +2139,10 @@ static int expr_evaluate_flagcmp(struct eval_ctx *ctx, struct expr **exprp)
 {
 	struct expr *expr = *exprp, *binop, *rel;
 
+	if (expr->op != OP_EQ &&
+	    expr->op != OP_NEQ)
+		return expr_error(ctx->msgs, expr, "either == or != is allowed");
+
 	binop = binop_expr_alloc(&expr->location, OP_AND,
 				 expr_get(expr->flagcmp.expr),
 				 expr_get(expr->flagcmp.mask));
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 1/1 expression: display an error on unknown datatype

 # nft describe foo
 datatype foo is invalid
Fixes 21cbab5b6ffe ("expression: extend 'nft describe' to allow listing data types")
---
 src/expression.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/expression.c +4 -1
index 7ae075d23ee3..c91333631ad0 100644
@@ -135,9 +135,12 @@ void expr_describe(const struct expr *expr, struct output_ctx *octx)
 		nft_print(octx, "datatype %s (%s)",
 			  dtype->name, dtype->desc);
 		len = dtype->size;
-	} else {
+	} else if (dtype != &invalid_type) {
 		nft_print(octx, "%s expression, datatype %s (%s)",
 			  expr_name(expr), dtype->name, dtype->desc);
+	} else {
+		nft_print(octx, "datatype %s is invalid\n", expr->identifier);
+		return;
 	}
 
 	if (dtype->basetype != NULL) {
Signature · 1 line
2.20.1