netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nftables 5/8] src: add "typeof" keyword
Date: Fri, 16 Aug 2019 16:42:38 +0200	[thread overview]
Message-ID: <20190816144241.11469-6-fw@strlen.de> (raw)
In-Reply-To: <20190816144241.11469-1-fw@strlen.de>

This allows users to specify named sets by using the expression
directly, rather than having to lookup the data type to use, or
the needed size via 'nft describe".

Example:

table filter {
    set allowed_dports {
        type typeof(tcp dport);
    }
    map nametomark {
        type typeof(osf name) : typeof(meta mark);
    }
    map port2helper {
        type ipv4_addr . inet_service : typeof(ct helper);
    }
}

Currently, listing such a table will lose the typeof() expression:

nft will print the datatype instead, just as if "type inet_service"
would have been used.

For types with non-fixed widths, the new "type, width" format
added in previous patch is used.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/parser_bison.y | 5 +++++
 src/scanner.l      | 1 +
 2 files changed, 6 insertions(+)

diff --git a/src/parser_bison.y b/src/parser_bison.y
index ee169fbac194..876050ba6863 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -192,6 +192,7 @@ int nft_lex(void *, void *, void *);
 %token DEFINE			"define"
 %token REDEFINE			"redefine"
 %token UNDEFINE			"undefine"
+%token TYPEOF			"typeof"
 
 %token FIB			"fib"
 
@@ -1844,6 +1845,10 @@ data_type_atom_expr	:	type_identifier
 							 $3, NULL);
 				xfree($1);
 			}
+			|	TYPEOF	'('	primary_expr	')'
+			{
+				$$ = $3;
+			}
 			;
 
 data_type_expr		:	data_type_atom_expr
diff --git a/src/scanner.l b/src/scanner.l
index c1adcbddbd73..cd563aa0ca1f 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -243,6 +243,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 "define"		{ return DEFINE; }
 "redefine"		{ return REDEFINE; }
 "undefine"		{ return UNDEFINE; }
+"typeof"		{ return TYPEOF; }
 
 "describe"		{ return DESCRIBE; }
 
-- 
2.21.0


  parent reply	other threads:[~2019-08-16 14:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-16 14:42 [PATCH nftables 0/8] add typeof keyword Florian Westphal
2019-08-16 14:42 ` [PATCH nftables 1/8] src: libnftnl: run single-initcalls only once Florian Westphal
2019-08-16 14:42 ` [PATCH nftables 2/8] src: libnftnl: split nft_ctx_new/free Florian Westphal
2019-08-16 14:42 ` [PATCH nftables 3/8] src: store expr, not dtype to track data in sets Florian Westphal
2019-08-16 14:42 ` [PATCH nftables 4/8] src: parser: add syntax to provide bitsize for non-spcific types Florian Westphal
2019-08-16 14:42 ` Florian Westphal [this message]
2019-08-16 14:42 ` [PATCH nftables 6/8] src: add "typeof" print support Florian Westphal
2019-08-16 14:42 ` [PATCH nftables 7/8] src: netlink: remove assertion Florian Westphal
2019-08-16 14:42 ` [PATCH nftables 8/8] tests: add typeof test cases Florian Westphal
2019-08-17 10:23 ` [PATCH nftables 0/8] add typeof keyword Pablo Neira Ayuso
2019-08-17 10:33   ` Pablo Neira Ayuso
2019-08-17 19:26     ` Florian Westphal
2019-08-17 20:55   ` Florian Westphal
2019-08-18 14:33     ` Arturo Borrero Gonzalez
2019-08-26  9:49       ` 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=20190816144241.11469-6-fw@strlen.de \
    --to=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).