]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser: fix scope closure of COUNTER token
authorFlorian Westphal <fw@strlen.de>
Thu, 25 Mar 2021 09:34:40 +0000 (10:34 +0100)
committerFlorian Westphal <fw@strlen.de>
Thu, 25 Mar 2021 11:40:30 +0000 (12:40 +0100)
It is closed after allocation, which is too early: this
stopped 'packets' and 'bytes' from getting parsed correctly.

Also add a test case for this.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/parser_bison.y
tests/py/any/counter.t [new file with mode: 0644]
tests/py/any/counter.t.json [new file with mode: 0644]
tests/py/any/counter.t.json.output [new file with mode: 0644]
tests/py/any/counter.t.payload [new file with mode: 0644]

index ca64141ec2d79f30bda156aaf87478a05b7454bb..abe117814db04121af6afe3b222db555a656c732 100644 (file)
@@ -2692,7 +2692,7 @@ stateful_stmt_list        :       stateful_stmt
                        }
                        ;
 
-stateful_stmt          :       counter_stmt
+stateful_stmt          :       counter_stmt    close_scope_counter
                        |       limit_stmt
                        |       quota_stmt
                        |       connlimit_stmt
@@ -2792,11 +2792,11 @@ connlimit_stmt          :       CT      COUNT   NUM     close_scope_ct
 counter_stmt           :       counter_stmt_alloc
                        |       counter_stmt_alloc      counter_args
 
-counter_stmt_alloc     :       COUNTER close_scope_counter
+counter_stmt_alloc     :       COUNTER
                        {
                                $$ = counter_stmt_alloc(&@$);
                        }
-                       |       COUNTER         NAME    stmt_expr       close_scope_counter
+                       |       COUNTER         NAME    stmt_expr
                        {
                                $$ = objref_stmt_alloc(&@$);
                                $$->objref.type = NFT_OBJECT_COUNTER;
diff --git a/tests/py/any/counter.t b/tests/py/any/counter.t
new file mode 100644 (file)
index 0000000..1c72742
--- /dev/null
@@ -0,0 +1,14 @@
+:input;type filter hook input priority 0
+:ingress;type filter hook ingress device lo priority 0
+
+*ip;test-ip4;input
+*ip6;test-ip6;input
+*inet;test-inet;input
+*arp;test-arp;input
+*bridge;test-bridge;input
+*netdev;test-netdev;ingress
+
+counter;ok
+counter packets 0 bytes 0;ok;counter
+counter packets 2 bytes 1;ok;counter
+counter bytes 1024 packets 1;ok;counter
diff --git a/tests/py/any/counter.t.json b/tests/py/any/counter.t.json
new file mode 100644 (file)
index 0000000..2d1eaa9
--- /dev/null
@@ -0,0 +1,39 @@
+# counter
+[
+    {
+        "counter": {
+            "bytes": 0,
+            "packets": 0
+        }
+    }
+]
+
+# counter packets 0 bytes 0
+[
+    {
+        "counter": {
+            "bytes": 0,
+            "packets": 0
+        }
+    }
+]
+
+# counter packets 2 bytes 1
+[
+    {
+        "counter": {
+            "bytes": 1,
+            "packets": 2
+        }
+    }
+]
+
+# counter bytes 1024 packets 1
+[
+    {
+        "counter": {
+            "bytes": 1024,
+            "packets": 1
+        }
+    }
+]
diff --git a/tests/py/any/counter.t.json.output b/tests/py/any/counter.t.json.output
new file mode 100644 (file)
index 0000000..6a62ffb
--- /dev/null
@@ -0,0 +1,28 @@
+# counter
+[
+    {
+        "counter": null
+    }
+]
+
+# counter packets 0 bytes 0
+[
+    {
+        "counter": null
+    }
+]
+
+# counter packets 2 bytes 1
+[
+    {
+        "counter": null
+    }
+]
+
+# counter bytes 1024 packets 1
+[
+    {
+        "counter": null
+    }
+]
+
diff --git a/tests/py/any/counter.t.payload b/tests/py/any/counter.t.payload
new file mode 100644 (file)
index 0000000..23e96ba
--- /dev/null
@@ -0,0 +1,15 @@
+# counter
+ip
+  [ counter pkts 0 bytes 0 ]
+
+# counter packets 0 bytes 0
+ip
+  [ counter pkts 0 bytes 0 ]
+
+# counter packets 2 bytes 1
+ip
+  [ counter pkts 2 bytes 1 ]
+
+# counter bytes 1024 packets 1
+ip
+  [ counter pkts 1 bytes 1024 ]