summaryrefslogtreecommitdiffstats
path: root/src/parser_bison.y
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2016-07-27 15:16:32 +0200
committerFlorian Westphal <fw@strlen.de>2017-07-16 19:52:07 +0200
commit0802d4f1fe7c65112633f002fbd56f97388f8ef5 (patch)
treee31abe74f446514ebe8ba8f33c43cefbfcd751ed /src/parser_bison.y
parent92b74b562551a34b210667b692689cf224521209 (diff)
parser: compact list of rhs keyword expressions
Condenses the copy/pastry via a define to avoid repeating this when the list gets extended. Based on earlier patch from Pablo. Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/parser_bison.y')
-rw-r--r--src/parser_bison.y72
1 files changed, 16 insertions, 56 deletions
diff --git a/src/parser_bison.y b/src/parser_bison.y
index a8448e14..71c5c77c 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -97,6 +97,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 */
@@ -573,8 +575,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_rhs_expr
+%destructor { expr_free($$); } expr initializer_expr keyword_rhs_expr
%type <expr> rhs_expr concat_rhs_expr basic_rhs_expr
%destructor { expr_free($$); } rhs_expr concat_rhs_expr basic_rhs_expr
@@ -2836,39 +2838,21 @@ boolean_expr : boolean_keys
}
;
+keyword_rhs_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"); }
+ | RESET { $$ = symbol_value(&@$, "reset"); }
+ ;
+
primary_rhs_expr : symbol_expr { $$ = $1; }
| integer_expr { $$ = $1; }
| boolean_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_rhs_expr { $$ = $1; }
| TCP
{
uint8_t data = IPPROTO_TCP;
@@ -2946,30 +2930,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");
- }
- | RESET
- {
- $$ = symbol_expr_alloc(&@$, SYMBOL_VALUE,
- current_scope(state),
- "reset");
- }
;
relational_op : EQ { $$ = OP_EQ; }