[PATCH nft] parser: fix scope closure of COUNTER token

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 src/parser_bison.y                 |  6 ++---
 tests/py/any/counter.t             | 14 +++++++++++
 tests/py/any/counter.t.json        | 39 ++++++++++++++++++++++++++++++
 tests/py/any/counter.t.json.output | 28 +++++++++++++++++++++
 tests/py/any/counter.t.payload     | 15 ++++++++++++
 5 files changed, 99 insertions(+), 3 deletions(-)
 create mode 100644 tests/py/any/counter.t
 create mode 100644 tests/py/any/counter.t.json
 create mode 100644 tests/py/any/counter.t.json.output
 create mode 100644 tests/py/any/counter.t.payload

diff --git a/src/parser_bison.y b/src/parser_bison.y
index 5cb4f8e1be9f..cd0a717de033 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -2685,7 +2685,7 @@ stateful_stmt_list	:	stateful_stmt
 			}
 			;
 
-stateful_stmt		:	counter_stmt
+stateful_stmt		:	counter_stmt	close_scope_counter
 			|	limit_stmt
 			|	quota_stmt
 			|	connlimit_stmt
@@ -2785,11 +2785,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
index 000000000000..1c72742c1363
--- /dev/null
+++ b/tests/py/any/counter.t
@@ -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
index 000000000000..2d1eaa999aab
--- /dev/null
+++ b/tests/py/any/counter.t.json
@@ -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
index 000000000000..6a62ffb03d9b
--- /dev/null
+++ b/tests/py/any/counter.t.json.output
@@ -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
index 000000000000..23e96bae14f3
--- /dev/null
+++ b/tests/py/any/counter.t.payload
@@ -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 ]
-- 
2.26.3




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux