netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [RFC PATCH nft] parser: add typeof keyword for declarations
Date: Fri, 27 Nov 2015 14:50:52 +0000	[thread overview]
Message-ID: <1448635852-2814-1-git-send-email-kaber@trash.net> (raw)

Add a typeof keyword to automatically use the correct type in set and map
declarations.

table filter {
	set blacklist {
		typeof ip saddr
	}

	chain input {
		ip saddr @blacklist counter drop
	}
}

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 src/parser_bison.y | 17 +++++++++++++++++
 src/scanner.l      |  1 +
 2 files changed, 18 insertions(+)

Just a small hack since as a distraction from the tracing stuff. So far it
only supports primary types, but its still easier than remembering or looking
up the exact type names.

Please not that it is just a parser feature. The output will still use
the type keyword and the actual data type:

table ip filter {
	set blacklist { 
		type ipv4_addr
	}
	...

Any comments?

diff --git a/src/parser_bison.y b/src/parser_bison.y
index fbfe7ea..cd97424 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -163,6 +163,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 
 %token INCLUDE			"include"
 %token DEFINE			"define"
+%token TYPEOF			"typeof"
 
 %token HOOK			"hook"
 %token DEVICE			"device"
@@ -968,6 +969,12 @@ set_block		:	/* empty */	{ $$ = $<set>-1; }
 				$1->keytype = $3;
 				$$ = $1;
 			}
+			|	set_block	TYPEOF		primary_expr	stmt_seperator
+			{
+				$1->keytype = $3->dtype;
+				expr_free($3);
+				$$ = $1;
+			}
 			|	set_block	FLAGS		set_flag_list	stmt_seperator
 			{
 				$1->flags = $3;
@@ -1021,6 +1028,16 @@ map_block		:	/* empty */	{ $$ = $<set>-1; }
 				$1->datatype = $5;
 				$$ = $1;
 			}
+			|	map_block	TYPEOF
+						primary_expr	COLON	primary_expr
+						stmt_seperator
+			{
+				$1->keytype  = $3->dtype;
+				$1->datatype = $5->dtype;
+				expr_free($3);
+				expr_free($5);
+				$$ = $1;
+			}
 			|	map_block	FLAGS		set_flag_list	stmt_seperator
 			{
 				$1->flags = $3;
diff --git a/src/scanner.l b/src/scanner.l
index a98e7b6..e19b13b 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -230,6 +230,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 
 "include"		{ return INCLUDE; }
 "define"		{ return DEFINE; }
+"typeof"		{ return TYPEOF; }
 
 "describe"		{ return DESCRIBE; }
 
-- 
2.5.0


                 reply	other threads:[~2015-11-27 14:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1448635852-2814-1-git-send-email-kaber@trash.net \
    --to=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).