[PATCH nft 2/5] parser_bison: consolidate limit grammar rule for set elements

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

 



Define limit_stmt_alloc and limit_args to follow similar idiom that is
used for counters.

Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
---
 src/parser_bison.y | 77 ++++++++++++++++++++++------------------------
 1 file changed, 37 insertions(+), 40 deletions(-)

diff --git a/src/parser_bison.y b/src/parser_bison.y
index 0d37c920f00c..1605c26df843 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -769,6 +769,8 @@ int nft_lex(void *, void *, void *);
 %destructor { stmt_free($$); }	stmt match_stmt verdict_stmt set_elem_stmt
 %type <stmt>			counter_stmt counter_stmt_alloc stateful_stmt last_stmt
 %destructor { stmt_free($$); }	counter_stmt counter_stmt_alloc stateful_stmt last_stmt
+%type <stmt>			limit_stmt_alloc
+%destructor { stmt_free($$); }	limit_stmt_alloc
 %type <stmt>			objref_stmt objref_stmt_counter objref_stmt_limit objref_stmt_quota objref_stmt_ct objref_stmt_synproxy
 %destructor { stmt_free($$); }	objref_stmt objref_stmt_counter objref_stmt_limit objref_stmt_quota objref_stmt_ct objref_stmt_synproxy
 
@@ -3177,7 +3179,7 @@ objref_stmt		:	objref_stmt_counter
 			;
 
 stateful_stmt		:	counter_stmt	close_scope_counter
-			|	limit_stmt
+			|	limit_stmt	close_scope_limit
 			|	quota_stmt
 			|	connlimit_stmt
 			|	last_stmt	close_scope_last
@@ -3461,28 +3463,45 @@ log_flag_tcp		:	SEQUENCE
 			}
 			;
 
-limit_stmt		:	LIMIT	RATE	limit_mode	limit_rate_pkts	limit_burst_pkts	close_scope_limit
+limit_stmt_alloc	:	LIMIT	RATE
+			{
+				$$ = limit_stmt_alloc(&@$);
+			}
+			;
+
+limit_stmt		:	limit_stmt_alloc limit_args
+			;
+
+limit_args		:	limit_mode	limit_rate_pkts	limit_burst_pkts
 	    		{
-				if ($5 == 0) {
-					erec_queue(error(&@5, "packet limit burst must be > 0"),
+				struct limit_stmt *limit;
+
+				assert($<stmt>0->type == STMT_LIMIT);
+
+				if ($3 == 0) {
+					erec_queue(error(&@3, "packet limit burst must be > 0"),
 						   state->msgs);
 					YYERROR;
 				}
-				$$ = limit_stmt_alloc(&@$);
-				$$->limit.rate	= $4.rate;
-				$$->limit.unit	= $4.unit;
-				$$->limit.burst	= $5;
-				$$->limit.type	= NFT_LIMIT_PKTS;
-				$$->limit.flags = $3;
+				limit = &$<stmt>0->limit;
+				limit->rate = $2.rate;
+				limit->unit = $2.unit;
+				limit->burst = $3;
+				limit->type = NFT_LIMIT_PKTS;
+				limit->flags = $1;
 			}
-			|	LIMIT	RATE	limit_mode	limit_rate_bytes	limit_burst_bytes	close_scope_limit
+			|	limit_mode	limit_rate_bytes	limit_burst_bytes
 			{
-				$$ = limit_stmt_alloc(&@$);
-				$$->limit.rate	= $4.rate;
-				$$->limit.unit	= $4.unit;
-				$$->limit.burst	= $5;
-				$$->limit.type	= NFT_LIMIT_PKT_BYTES;
-				$$->limit.flags = $3;
+				struct limit_stmt *limit;
+
+				assert($<stmt>0->type == STMT_LIMIT);
+
+				limit = &$<stmt>0->limit;
+				limit->rate = $2.rate;
+				limit->unit = $2.unit;
+				limit->burst = $3;
+				limit->type = NFT_LIMIT_PKT_BYTES;
+				limit->flags = $1;
 			}
 			;
 
@@ -4591,29 +4610,7 @@ set_elem_stmt_list	:	set_elem_stmt
 			;
 
 set_elem_stmt		:	counter_stmt	close_scope_counter
-			|	LIMIT   RATE    limit_mode      limit_rate_pkts       limit_burst_pkts	close_scope_limit
-			{
-				if ($5 == 0) {
-					erec_queue(error(&@5, "limit burst must be > 0"),
-						   state->msgs);
-					YYERROR;
-				}
-				$$ = limit_stmt_alloc(&@$);
-				$$->limit.rate  = $4.rate;
-				$$->limit.unit  = $4.unit;
-				$$->limit.burst = $5;
-				$$->limit.type  = NFT_LIMIT_PKTS;
-				$$->limit.flags = $3;
-			}
-			|       LIMIT   RATE    limit_mode      limit_rate_bytes  limit_burst_bytes	close_scope_limit
-			{
-				$$ = limit_stmt_alloc(&@$);
-				$$->limit.rate  = $4.rate;
-				$$->limit.unit  = $4.unit;
-				$$->limit.burst = $5;
-				$$->limit.type  = NFT_LIMIT_PKT_BYTES;
-				$$->limit.flags = $3;
-			}
+			|	limit_stmt	close_scope_limit
 			|	CT	COUNT	NUM	close_scope_ct
 			{
 				$$ = connlimit_stmt_alloc(&@$);
-- 
2.30.2





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

  Powered by Linux