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: [PATCH nftables] make set initializer parsable
Date: Thu, 16 Jan 2014 19:39:52 +0000	[thread overview]
Message-ID: <20140116193951.GA19036@macbook.localnet> (raw)
In-Reply-To: <20140116192249.GA18252@macbook.localnet>

commit 92dfa9b19853c367efbb083d5ad1b7cb56ce3d8a
Author: Patrick McHardy <kaber@trash.net>
Date:   Thu Jan 16 19:37:53 2014 +0000

    set: make set initializer parsable
    
    If a set contains elements, the output is not parsable since the
    elements = { ... } is not understood by the parser. Fix this and
    also add support for creating constant sets (which only makes sense
    when using an initializer).
    
    Signed-off-by: Patrick McHardy <kaber@trash.net>

diff --git a/src/parser.y b/src/parser.y
index eab973c..34d14ec 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -183,7 +183,9 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token RETURN			"return"
 %token QUEUE			"queue"
 
+%token CONSTANT			"constant"
 %token INTERVAL			"interval"
+%token ELEMENTS			"elements"
 
 %token <val> NUM		"number"
 %token <string> STRING		"string"
@@ -747,6 +749,11 @@ set_block		:	/* empty */	{ $$ = $<set>-1; }
 				$1->flags = $3;
 				$$ = $1;
 			}
+			|	set_block	ELEMENTS	'='		set_expr
+			{
+				$1->init = $4;
+				$$ = $1;
+			}
 			;
 
 set_flag_list		:	set_flag_list	COMMA		set_flag
@@ -756,7 +763,8 @@ set_flag_list		:	set_flag_list	COMMA		set_flag
 			|	set_flag
 			;
 
-set_flag		:	INTERVAL	{ $$ = SET_F_INTERVAL; }
+set_flag		:	CONSTANT	{ $$ = SET_F_CONSTANT; }
+			|	INTERVAL	{ $$ = SET_F_INTERVAL; }
 			;
 
 map_block_alloc		:	/* empty */
@@ -794,6 +802,11 @@ map_block		:	/* empty */	{ $$ = $<set>-1; }
 				$1->flags = $3;
 				$$ = $1;
 			}
+			|	map_block	ELEMENTS	'='		set_expr
+			{
+				$1->init = $4;
+				$$ = $1;
+			}
 			;
 
 hook_spec		:	TYPE		STRING		HOOK		STRING		PRIORITY	NUM
diff --git a/src/rule.c b/src/rule.c
index f1fe355..acdddcb 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -100,8 +100,12 @@ void set_print(const struct set *set)
 		printf(" => %s", set->datatype->name);
 	printf("\n");
 
-	if (set->flags & (SET_F_INTERVAL)) {
+	if (set->flags & (SET_F_CONSTANT | SET_F_INTERVAL)) {
 		printf("\t\tflags ");
+		if (set->flags & SET_F_CONSTANT) {
+			printf("%sconstant", delim);
+			delim = ",";
+		}
 		if (set->flags & SET_F_INTERVAL) {
 			printf("%sinterval", delim);
 			delim = ",";
diff --git a/src/scanner.l b/src/scanner.l
index f22fbe8..721b551 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -257,7 +257,9 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 
 "position"		{ return POSITION; }
 
+"constant"		{ return CONSTANT; }
 "interval"		{ return INTERVAL; }
+"elements"		{ return ELEMENTS; }
 
 "counter"		{ return COUNTER; }
 "packets"		{ return PACKETS; }

      reply	other threads:[~2014-01-16 19:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-16 19:22 [PATCH nftables] make set flags output parsable Patrick McHardy
2014-01-16 19:39 ` Patrick McHardy [this message]

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=20140116193951.GA19036@macbook.localnet \
    --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).