summaryrefslogtreecommitdiffstats
path: root/src/parser_json.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2024-03-20 15:54:54 +0100
committerPhil Sutter <phil@nwl.cc>2024-04-12 14:33:14 +0200
commit0ac39384fd9e48ff6bcc5605df2cbeb33af64b9e (patch)
tree1009847e954207c82d829d1c357712723d0cb789 /src/parser_json.c
parent3bccc478d27498f7ecc8a0233176accb1b91f584 (diff)
json: Accept more than two operands in binary expressions
The most common use case is ORing flags like | syn | ack | rst but nft seems to be fine with less intuitive stuff like | meta mark set ip dscp << 2 << 3 so support all of them. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r--src/parser_json.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index efe49494..418d4ad7 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1204,6 +1204,18 @@ static struct expr *json_parse_binop_expr(struct json_ctx *ctx,
return NULL;
}
+ if (json_array_size(root) > 2) {
+ left = json_parse_primary_expr(ctx, json_array_get(root, 0));
+ right = json_parse_primary_expr(ctx, json_array_get(root, 1));
+ left = binop_expr_alloc(int_loc, thisop, left, right);
+ for (i = 2; i < json_array_size(root); i++) {
+ jright = json_array_get(root, i);
+ right = json_parse_primary_expr(ctx, jright);
+ left = binop_expr_alloc(int_loc, thisop, left, right);
+ }
+ return left;
+ }
+
if (json_unpack_err(ctx, root, "[o, o!]", &jleft, &jright))
return NULL;