From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: fw@strlen.de
Subject: [nft 1/3] parser_bison: simplify hook_spec rule
Date: Tue, 15 Mar 2016 17:33:16 +0100 [thread overview]
Message-ID: <1458059598-7470-1-git-send-email-pablo@netfilter.org> (raw)
Consolidate this rule by introducing the dev_spec and prio_spec, we save
50 LOC with this patch.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/parser_bison.y | 66 +++++++++++++-----------------------------------------
1 file changed, 15 insertions(+), 51 deletions(-)
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 90978ab..24c0969 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -423,7 +423,10 @@ static void location_update(struct location *loc, struct location *rhs, int n)
%destructor { handle_free(&$$); } table_spec chain_spec chain_identifier ruleid_spec ruleset_spec
%type <handle> set_spec set_identifier
%destructor { handle_free(&$$); } set_spec set_identifier
-%type <val> handle_spec family_spec family_spec_explicit position_spec chain_policy
+%type <val> handle_spec family_spec family_spec_explicit position_spec chain_policy prio_spec
+
+%type <string> dev_spec
+%destructor { xfree($$); } dev_spec
%type <table> table_block_alloc table_block
%destructor { close_scope(state); table_free($$); } table_block_alloc
@@ -1096,41 +1099,7 @@ type_identifier : STRING { $$ = $1; }
| MARK { $$ = xstrdup("mark"); }
;
-hook_spec : TYPE STRING HOOK STRING PRIORITY NUM
- {
- $<chain>0->type = chain_type_name_lookup($2);
- if ($<chain>0->type == NULL) {
- erec_queue(error(&@2, "unknown chain type %s", $2),
- state->msgs);
- YYERROR;
- }
- $<chain>0->hookstr = chain_hookname_lookup($4);
- if ($<chain>0->hookstr == NULL) {
- erec_queue(error(&@4, "unknown chain hook %s", $4),
- state->msgs);
- YYERROR;
- }
- $<chain>0->priority = $6;
- $<chain>0->flags |= CHAIN_F_BASECHAIN;
- }
- | TYPE STRING HOOK STRING PRIORITY DASH NUM
- {
- $<chain>0->type = chain_type_name_lookup($2);
- if ($<chain>0->type == NULL) {
- erec_queue(error(&@2, "unknown type name %s", $2),
- state->msgs);
- YYERROR;
- }
- $<chain>0->hookstr = chain_hookname_lookup($4);
- if ($<chain>0->hookstr == NULL) {
- erec_queue(error(&@4, "unknown hook name %s", $4),
- state->msgs);
- YYERROR;
- }
- $<chain>0->priority = -$7;
- $<chain>0->flags |= CHAIN_F_BASECHAIN;
- }
- | TYPE STRING HOOK STRING DEVICE STRING PRIORITY NUM
+hook_spec : TYPE STRING HOOK STRING dev_spec PRIORITY prio_spec
{
$<chain>0->type = chain_type_name_lookup($2);
if ($<chain>0->type == NULL) {
@@ -1144,25 +1113,20 @@ hook_spec : TYPE STRING HOOK STRING PRIORITY NUM
state->msgs);
YYERROR;
}
- $<chain>0->dev = $6;
- $<chain>0->priority = $8;
- $<chain>0->flags |= CHAIN_F_BASECHAIN;
- }
- | TYPE STRING HOOK STRING DEVICE STRING PRIORITY DASH NUM
- {
- $<chain>0->type = chain_type_name_lookup($2);
- if ($<chain>0->type == NULL) {
- erec_queue(error(&@2, "unknown type name %s", $2),
- state->msgs);
- YYERROR;
- }
- $<chain>0->hookstr = chain_hookname_lookup($4);
- $<chain>0->dev = $6;
- $<chain>0->priority = -$9;
+ $<chain>0->dev = $5;
+ $<chain>0->priority = $7;
$<chain>0->flags |= CHAIN_F_BASECHAIN;
}
;
+prio_spec : NUM { $$ = $1; }
+ | DASH NUM { $$ = -$2; }
+ ;
+
+dev_spec : DEVICE STRING { $$ = $2; }
+ | /* empty */ { $$ = NULL; }
+ ;
+
policy_spec : POLICY chain_policy
{
if ($<chain>0->policy != -1) {
--
2.1.4
next reply other threads:[~2016-03-15 16:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-15 16:33 Pablo Neira Ayuso [this message]
2016-03-15 16:33 ` [nft 2/3] parser_bison: duplicate string returned by chain_type_name_lookup() Pablo Neira Ayuso
2016-03-15 16:33 ` [nft 3/3] parser_bison: release parsed type and hook name strings Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458059598-7470-1-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).