All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nft] json: fix parse of flagcmp expression
@ 2021-06-02 11:39 Florian Westphal
  0 siblings, 0 replies; only message in thread
From: Florian Westphal @ 2021-06-02 11:39 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

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        |  2 +-
 tests/py/inet/tcp.t.json | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/parser_json.c b/src/parser_json.c
index fd0d4fd85a2d..2e791807cce6 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -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);
diff --git a/tests/py/inet/tcp.t.json b/tests/py/inet/tcp.t.json
index 922ab91c9f0e..b04556769c81 100644
--- a/tests/py/inet/tcp.t.json
+++ b/tests/py/inet/tcp.t.json
@@ -1749,3 +1749,30 @@
         }
     }
 ]
+
+# tcp flags fin,syn / fin,syn
+[
+    {
+        "match": {
+            "left": {
+                "&": [
+                    {
+                        "payload": {
+                            "field": "flags",
+                            "protocol": "tcp"
+                        }
+                    },
+                    [
+                        "fin",
+                        "syn"
+                    ]
+                ]
+            },
+            "op": "==",
+            "right": [
+                "fin",
+                "syn"
+            ]
+        }
+    }
+]
-- 
2.26.3


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-02 11:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 11:39 [PATCH nft] json: fix parse of flagcmp expression Florian Westphal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.