From patchwork Wed Jun 28 10:06:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Westphal X-Patchwork-Id: 781530 X-Patchwork-Delegate: fw@strlen.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wyJNw1825z9s5L for ; Wed, 28 Jun 2017 20:06:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751516AbdF1KGz (ORCPT ); Wed, 28 Jun 2017 06:06:55 -0400 Received: from Chamillionaire.breakpoint.cc ([146.0.238.67]:33352 "EHLO Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751469AbdF1KGz (ORCPT ); Wed, 28 Jun 2017 06:06:55 -0400 Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.84_2) (envelope-from ) id 1dQ9r6-0001kF-M0; Wed, 28 Jun 2017 12:05:52 +0200 From: Florian Westphal To: Cc: Florian Westphal Subject: [PATCH 04/17] parser: compact list of rhs keyword expressions Date: Wed, 28 Jun 2017 12:06:46 +0200 Message-Id: <20170628100659.26976-5-fw@strlen.de> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170628100659.26976-1-fw@strlen.de> References: <20170628100659.26976-1-fw@strlen.de> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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. Suggested-by: Pablo Neira Ayuso Signed-off-by: Florian Westphal --- src/parser_bison.y | 72 ++++++++++++------------------------------------------ 1 file changed, 16 insertions(+), 56 deletions(-) diff --git a/src/parser_bison.y b/src/parser_bison.y index 86f0464295eb..a95c16adde61 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 */ @@ -580,8 +582,8 @@ static void location_update(struct location *loc, struct location *rhs, int n) %type flow_key_expr flow_key_expr_alloc %destructor { expr_free($$); } flow_key_expr flow_key_expr_alloc -%type expr initializer_expr -%destructor { expr_free($$); } expr initializer_expr +%type expr initializer_expr keyword_expr +%destructor { expr_free($$); } expr initializer_expr keyword_expr %type rhs_expr concat_rhs_expr basic_rhs_expr %destructor { expr_free($$); } rhs_expr concat_rhs_expr basic_rhs_expr @@ -2795,39 +2797,21 @@ boolean_expr : boolean_keys } ; +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"); } + | 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_expr { $$ = $1; } | TCP { uint8_t data = IPPROTO_TCP; @@ -2905,30 +2889,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; }