]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: fix parse of flagcmp expression
authorFlorian Westphal <fw@strlen.de>
Wed, 2 Jun 2021 11:39:39 +0000 (13:39 +0200)
committerFlorian Westphal <fw@strlen.de>
Wed, 2 Jun 2021 13:07:51 +0000 (15:07 +0200)
The json test case for the flagcmp notation ('tcp flags syn,fin / syn,fin') fails with:
command: {"nftables": [{"add": {"rule": {"family": "ip", "table": "test-ip4", "chain": "input", "expr": [{"match": {"left": {"&": [{"payload": {"field": "flags", "protocol": "tcp"}}, ["fin", "syn"]]}, "op": "==", "right": ["fin", "syn"]}}]}}}]}
internal:0:0-0: Error: List expression only allowed on RHS or in statement expression.
internal:0:0-0: Error: Failed to parse RHS of binop expression.
internal:0:0-0: Error: Invalid LHS of relational.
internal:0:0-0: Error: Parsing expr array at index 0 failed.
internal:0:0-0: Error: Parsing command array at index 0 failed.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/parser_json.c
tests/py/inet/tcp.t.json

index fd0d4fd85a2d488ca2eb3cbe9df5d409ac0ba646..2e791807cce61b51bd59f0f437450050f1473520 100644 (file)
@@ -1135,7 +1135,7 @@ static struct expr *json_parse_binop_expr(struct json_ctx *ctx,
                json_error(ctx, "Failed to parse LHS of binop expression.");
                return NULL;
        }
-       right = json_parse_primary_expr(ctx, jright);
+       right = json_parse_rhs_expr(ctx, jright);
        if (!right) {
                json_error(ctx, "Failed to parse RHS of binop expression.");
                expr_free(left);
index 922ab91c9f0e63f7319d87ab8588d836abd746c0..b04556769c813591784437fecaa5f077d7c74ab6 100644 (file)
         }
     }
 ]
+
+# tcp flags fin,syn / fin,syn
+[
+    {
+        "match": {
+            "left": {
+                "&": [
+                    {
+                        "payload": {
+                            "field": "flags",
+                            "protocol": "tcp"
+                        }
+                    },
+                    [
+                        "fin",
+                        "syn"
+                    ]
+                ]
+            },
+            "op": "==",
+            "right": [
+                "fin",
+                "syn"
+            ]
+        }
+    }
+]