parser: fix scope closure of COUNTER token
Florian Westphal
maintainerPATCH 1/1 parser: fix scope closure of COUNTER token
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 <[email protected]>
--- 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
src/parser_bison.y +3 -3
@@ -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;
tests/py/any/counter.t new file +14 -0
@@ -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
tests/py/any/counter.t.json new file +39 -0
@@ -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 + } + } +]
tests/py/any/counter.t.json.output new file +28 -0
@@ -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 + } +] +
tests/py/any/counter.t.payload new file +15 -0
@@ -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 ]
Signature · 1 line
2.26.3