Skip to contentSkip to conversation

parser: compact list of rhs keyword expressions

PATCH In review Florian Westphal 2 participants 2 messages Jul 27, 2016 – Aug 1, 2016 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 parser: compact list of rhs keyword expressions

Condenses the copy/pastry via a define, will make it less of a hassle to extend this list later if needed.

Based on earlier patch from Pablo.

---
 src/parser_bison.y | 65 +++++++++++++-----------------------------------------
 1 file changed, 15 insertions(+), 50 deletions(-)
src/parser_bison.y +15 -50
index 119fd09..31257fd 100644
@@ -96,6 +96,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 
 #define YYLLOC_DEFAULT(Current, Rhs, N)	location_update(&Current, Rhs, N)
 
+#define symbol_value(loc, str) \
+	symbol_expr_alloc(loc, SYMBOL_VALUE, current_scope(state), str)
 %}
 
 /* Declaration section */
@@ -529,8 +531,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %type <expr>			flow_key_expr flow_key_expr_alloc
 %destructor { expr_free($$); }	flow_key_expr flow_key_expr_alloc
 
-%type <expr>			expr initializer_expr
-%destructor { expr_free($$); }	expr initializer_expr
+%type <expr>			expr initializer_expr keyword_expr
+%destructor { expr_free($$); }	expr initializer_expr keyword_expr
 
 %type <expr>			rhs_expr concat_rhs_expr basic_rhs_expr
 %destructor { expr_free($$); }	rhs_expr concat_rhs_expr basic_rhs_expr
@@ -2166,38 +2168,19 @@ concat_rhs_expr		:	basic_rhs_expr
 			}
 			;
 
+keyword_expr		:	ETHER                   { $$ = symbol_value(&@$, "ether"); }
+			|	IP			{ $$ = symbol_value(&@$, "ip"); }
+			|	IP6			{ $$ = symbol_value(&@$, "ip6"); }
+			|	VLAN			{ $$ = symbol_value(&@$, "vlan"); }
+			|	ARP			{ $$ = symbol_value(&@$, "arp"); }
+			|	DNAT			{ $$ = symbol_value(&@$, "dnat"); }
+			|	SNAT			{ $$ = symbol_value(&@$, "snat"); }
+			|	ECN			{ $$ = symbol_value(&@$, "ecn"); }
+			;
+
 primary_rhs_expr	:	symbol_expr		{ $$ = $1; }
 			|	integer_expr		{ $$ = $1; }
-			|	ETHER
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "ether");
-			}
-			|	IP
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "ip");
-			}
-			|	IP6
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "ip6");
-			}
-			|	VLAN
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "vlan");
-			}
-			|	ARP
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "arp");
-			}
+			|	keyword_expr		{ $$ = $1; }
 			|	TCP
 			{
 				uint8_t data = IPPROTO_TCP;
@@ -2275,24 +2258,6 @@ primary_rhs_expr	:	symbol_expr		{ $$ = $1; }
 							 BYTEORDER_HOST_ENDIAN,
 							 sizeof(data) * BITS_PER_BYTE, &data);
 			}
-			|	SNAT
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "snat");
-			}
-			|	DNAT
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "dnat");
-			}
-			|	ECN
-			{
-				$$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
-						       current_scope(state),
-						       "ecn");
-			}
 			;
 
 relational_op		:	EQ		{ $$ = OP_EQ; }
Signature · 1 line
2.7.3
#1 lore raw
Quoted 2 lines · Florian Westphal

Condenses the copy/pastry via a define, will make it less of a hassle to extend this list later if needed.

So the main goal of this is to find a solution for meta skuid, ct label and such that allow any arbitrary string as value.

I continued a patch on top of this to place in the keyword_expr rule the remaining keywords and return a symbol expression here.

I didn't finish this, but still MAP and SET tokens cannot be used from there as they are valid to show after the selectors (bison detects this by complaining on shift/reduce conflicts), so still the user cannot create a gid whose name is 'map'.

Another possibility to display this values using quotes, so the scanner always handles them as arbitrary values. So the syntax looks like:

meta skuid "daemon"

or
ct label "http"

Quoted 1 line

From a user side, it would be also visible that these are an arbitrary

user-defined string.