meta: deprecate unqualified meta statements
Florian Westphal
maintainerRFC 1/1 meta: deprecate unqualified meta statements
During NFWS we discussed reducing the number of keywords in nftables.
Obviously keywords are required for the parser to know what to expect.
But always requiring the 'meta' keyword would allow us to handle iif, oif, iifname etc without defining them in the scanner, i.e. we could later use 'meta STRING' and resolve/map the keyword at run time based on the meta template pseudo-header.
Note that this change does not yet reject 'iif eth0', this only makes nft always print the 'meta' keyword when listing and updates the test cases as required.
--- doc/nft.xml | 17 +--- src/meta.c | 25 +---- tests/py/any/ct.t | 4 +- tests/py/any/ct.t.payload | 4 +- tests/py/any/meta.t | 194 ++++++++++++++++++------------------- tests/py/inet/udp.t | 4 +- tests/py/inet/udp.t.payload.inet | 4 +- tests/py/inet/udp.t.payload.ip | 4 +- tests/py/inet/udp.t.payload.ip6 | 4 +- tests/py/inet/udp.t.payload.netdev | 4 +- tests/py/ip/dnat.t | 8 +- tests/py/ip/dnat.t.payload.ip | 8 +- tests/py/ip/ip.t | 6 +- tests/py/ip/ip.t.payload | 6 +- tests/py/ip/ip.t.payload.inet | 6 +- tests/py/ip/ip.t.payload.netdev | 6 +- tests/py/ip/snat.t | 12 +-- tests/py/ip/snat.t.payload | 8 +- tests/py/ip6/ip6.t | 4 +- tests/py/ip6/ip6.t.payload.inet | 4 +- tests/py/ip6/ip6.t.payload.ip6 | 4 +- 21 files changed, 150 insertions(+), 186 deletions(-)
doc/nft.xml +1 -16
@@ -956,7 +956,7 @@ filter output ip6 daddr ::1 datum from a packet's payload, meta data or a stateful module. </para> <refsect2> - <title>Meta expressions</title> + <title>Meta expression</title> <para> <cmdsynopsis> <command>meta</command>
@@ -966,11 +966,6 @@ filter output ip6 daddr ::1 <arg>l4proto</arg> <arg>protocol</arg> <arg>priority</arg> - </group> - </cmdsynopsis> - <cmdsynopsis> - <arg choice="opt">meta</arg> - <group choice="req"> <arg>mark</arg> <arg>iif</arg> <arg>iifname</arg>
@@ -996,12 +991,6 @@ filter output ip6 daddr ::1 A meta expression refers to meta data associated with a packet. </para> <para> - There are two types of meta expressions: unqualified and qualified meta expressions. - Qualified meta expressions require the <command>meta</command> keyword before the - meta key, unqualified meta expressions can be specified by using the meta key directly - or as qualified meta expressions. - </para> - <para> <table frame="all"> <title>Meta expression types</title> <tgroup cols='3' align='left' colsep='1' rowsep='1'>
@@ -1195,11 +1184,7 @@ filter output ip6 daddr ::1 <example> <title>Using meta expressions</title> <programlisting> -# qualified meta expression filter output meta oif eth0 - -# unqualified meta expression -filter output oif eth0 </programlisting> </example> </para>
src/meta.c +2 -23
@@ -423,27 +423,9 @@ static const struct meta_template meta_templates[] = { BYTEORDER_BIG_ENDIAN), /* avoid conversion; doesn't have endianess */ }; -static bool meta_key_is_qualified (enum nft_meta_keys key) -{ -switch (key) { -case NFT_META_LEN : -case NFT_META_NFPROTO : -case NFT_META_L4PROTO : -case NFT_META_PROTOCOL : -case NFT_META_PRIORITY : -case NFT_META_PRANDOM : -return true; -default : -return false; - } -} -static void meta_expr_print (const struct expr *expr) { -if (meta_key_is_qualified (expr->meta.key)) -printf ("meta %s" , meta_templates[expr->meta.key].token); -else -printf ("%s" , meta_templates[expr->meta.key].token); +printf ("meta %s" , meta_templates[expr->meta.key].token); }static bool meta_expr_cmp (const struct expr *e1,const struct expr *e2)
@@ -560,10 +542,7 @@ struct expr *meta_expr_alloc(const struct location *loc, enum nft_meta_keys key)static void meta_stmt_print (const struct stmt *stmt) { -if (meta_key_is_qualified (stmt->meta.key)) -printf ("meta %s set " , meta_templates[stmt->meta.key].token); -else -printf ("%s set " , meta_templates[stmt->meta.key].token); +printf ("meta %s set " , meta_templates[stmt->meta.key].token);expr_print (stmt->meta.expr); }
tests/py/any/ct.t +2 -2
@@ -55,8 +55,8 @@ ct mark set 0x11 xor 0x1331;ok;ct mark set 0x00001320 ct mark set 0x11333 and 0x11;ok;ct mark set 0x00000011 ct mark set 0x12 or 0x11;ok;ct mark set 0x00000013 ct mark set 0x11;ok;ct mark set 0x00000011 -ct mark set mark;ok;ct mark set mark -ct mark set mark map { 1 : 10, 2 : 20, 3 : 30 };ok;ct mark set mark map { 0x00000003 : 0x0000001e, 0x00000002 : 0x00000014, 0x00000001 : 0x0000000a} +ct mark set meta mark;ok +ct mark set meta mark map { 1 : 10, 2 : 20, 3 : 30 };ok;ct mark set meta mark map { 0x00000003 : 0x0000001e, 0x00000002 : 0x00000014, 0x00000001 : 0x0000000a} ct expiration 30;ok;ct expiration 30s ct expiration 22;ok;ct expiration 22s
tests/py/any/ct.t.payload +2 -2
@@ -282,12 +282,12 @@ ip test-ip4 output [ ct load mark => reg 9 ] [ lookup reg 1 set __map%d dreg 0 ] -# ct mark set mark +# ct mark set meta mark ip test-ip4 output [ meta load mark => reg 1 ] [ ct set mark with reg 1 ] -# ct mark set mark map { 1 : 10, 2 : 20, 3 : 30 } +# ct mark set meta mark map { 1 : 10, 2 : 20, 3 : 30 } __map%d test-ip4 b __map%d test-ip4 0 element 00000001 : 0000000a 0 [end] element 00000002 : 00000014 0 [end] element 00000003 : 0000001e 0 [end]
tests/py/any/meta.t +97 -97
245 lines not on this page · raw message
tests/py/inet/udp.t +2 -2
@@ -52,5 +52,5 @@ udp checksum { 33-55};ok - udp checksum != { 33-55};ok # limit impact to lo -iif lo udp checksum set 0;ok -iif lo udp dport set 65535;ok +meta iif lo udp checksum set 0;ok +meta iif lo udp dport set 65535;ok
tests/py/inet/udp.t.payload.inet +2 -2
@@ -220,7 +220,7 @@ inet test-inet input [ payload load 2b @ transport header + 6 => reg 1 ] [ lookup reg 1 set __set%d ] -# iif lo udp checksum set 0 +# meta iif lo udp checksum set 0 inet test-inet input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -229,7 +229,7 @@ inet test-inet input [ immediate reg 1 0x00000000 ] [ payload write reg 1 => 2b @ transport header + 6 csum_type 1 csum_off 6 ] -# iif lo udp dport set 65535 +# meta iif lo udp dport set 65535 inet test-inet input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/inet/udp.t.payload.ip +2 -2
@@ -220,7 +220,7 @@ ip test-ip4 input [ payload load 2b @ transport header + 6 => reg 1 ] [ lookup reg 1 set __set%d ] -# iif lo udp checksum set 0 +# meta iif lo udp checksum set 0 ip test-ip4 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -229,7 +229,7 @@ ip test-ip4 input [ immediate reg 1 0x00000000 ] [ payload write reg 1 => 2b @ transport header + 6 csum_type 1 csum_off 6 ] -# iif lo udp dport set 65535 +# meta iif lo udp dport set 65535 ip test-ip4 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/inet/udp.t.payload.ip6 +2 -2
@@ -220,7 +220,7 @@ ip6 test-ip6 input [ payload load 2b @ transport header + 6 => reg 1 ] [ lookup reg 1 set __set%d ] -# iif lo udp checksum set 0 +# meta iif lo udp checksum set 0 ip6 test-ip6 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -229,7 +229,7 @@ ip6 test-ip6 input [ immediate reg 1 0x00000000 ] [ payload write reg 1 => 2b @ transport header + 6 csum_type 1 csum_off 6 ] -# iif lo udp dport set 65535 +# meta iif lo udp dport set 65535 ip test-ip4 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/inet/udp.t.payload.netdev +2 -2
@@ -220,7 +220,7 @@ inet test-inet input [ payload load 2b @ transport header + 6 => reg 1 ] [ lookup reg 1 set __set%d ] -# iif lo udp checksum set 0 +# meta iif lo udp checksum set 0 netdev test-netdev ingress [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -229,7 +229,7 @@ netdev test-netdev ingress [ immediate reg 1 0x00000000 ] [ payload write reg 1 => 2b @ transport header + 6 csum_type 1 csum_off 6 ] -# iif lo udp dport set 65535 +# meta iif lo udp dport set 65535 netdev test-netdev ingress [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/ip/dnat.t +4 -4
@@ -2,15 +2,15 @@ *ip;test-ip4;prerouting -iifname "eth0" tcp dport 80-90 dnat 192.168.3.2;ok -iifname "eth0" tcp dport != 80-90 dnat 192.168.3.2;ok -iifname "eth0" tcp dport {80, 90, 23} dnat 192.168.3.2;ok +meta iifname "eth0" tcp dport 80-90 dnat 192.168.3.2;ok +meta iifname "eth0" tcp dport != 80-90 dnat 192.168.3.2;ok +meta iifname "eth0" tcp dport {80, 90, 23} dnat 192.168.3.2;ok - iifname "eth0" tcp dport != {80, 90, 23} dnat 192.168.3.2;ok - iifname "eth0" tcp dport != {80, 90, 23} dnat 192.168.3.2;ok # BUG: invalid expression type set # nft: src/evaluate.c:975: expr_evaluate_relational: Assertion '0' failed. -iifname "eth0" tcp dport != 23-34 dnat 192.168.3.2;ok +meta iifname "eth0" tcp dport != 23-34 dnat 192.168.3.2;ok dnat ct mark map { 0x00000014 : 1.2.3.4};ok dnat ct mark . ip daddr map { 0x00000014 . 1.1.1.1 : 1.2.3.4};ok
tests/py/ip/dnat.t.payload.ip +4 -4
@@ -1,4 +1,4 @@ -# iifname "eth0" tcp dport 80-90 dnat 192.168.3.2 +# meta iifname "eth0" tcp dport 80-90 dnat 192.168.3.2 ip test-ip4 prerouting [ meta load iifname => reg 1 ] [ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]
@@ -10,7 +10,7 @@ ip test-ip4 prerouting [ immediate reg 1 0x0203a8c0 ] [ nat dnat ip addr_min reg 1 addr_max reg 0 ] -# iifname "eth0" tcp dport != 80-90 dnat 192.168.3.2 +# meta iifname "eth0" tcp dport != 80-90 dnat 192.168.3.2 ip test-ip4 prerouting [ meta load iifname => reg 1 ] [ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]
@@ -22,7 +22,7 @@ ip test-ip4 prerouting [ immediate reg 1 0x0203a8c0 ] [ nat dnat ip addr_min reg 1 addr_max reg 0 ] -# iifname "eth0" tcp dport {80, 90, 23} dnat 192.168.3.2 +# meta iifname "eth0" tcp dport {80, 90, 23} dnat 192.168.3.2 __set%d test-ip4 3 __set%d test-ip4 0 element 00005000 : 0 [end] element 00005a00 : 0 [end] element 00001700 : 0 [end]
@@ -36,7 +36,7 @@ ip test-ip4 prerouting [ immediate reg 1 0x0203a8c0 ] [ nat dnat ip addr_min reg 1 addr_max reg 0 ] -# iifname "eth0" tcp dport != 23-34 dnat 192.168.3.2 +# meta iifname "eth0" tcp dport != 23-34 dnat 192.168.3.2 ip test-ip4 prerouting [ meta load iifname => reg 1 ] [ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]
tests/py/ip/ip.t +3 -3
@@ -123,6 +123,6 @@ ip hdrlength 15;ok ip hdrlength 16;fail # limit impact to lo -iif lo ip daddr set 127.0.0.1;ok -iif lo ip checksum set 0;ok -iif lo ip id set 0;ok +meta iif lo ip daddr set 127.0.0.1;ok +meta iif lo ip checksum set 0;ok +meta iif lo ip id set 0;ok
tests/py/ip/ip.t.payload +3 -3
@@ -416,21 +416,21 @@ ip test-ip4 input [ bitwise reg 1 = (reg=1 & 0x0000000f ) ^ 0x00000000 ] [ cmp eq reg 1 0x0000000f ] -# iif lo ip daddr set 127.0.0.1 +# meta iif lo ip daddr set 127.0.0.1 ip test-ip4 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ] [ immediate reg 1 0x0100007f ] [ payload write reg 1 => 4b @ network header + 16 csum_type 1 csum_off 10 ] -# iif lo ip checksum set 0 +# meta iif lo ip checksum set 0 ip test-ip4 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ] [ immediate reg 1 0x00000000 ] [ payload write reg 1 => 2b @ network header + 10 csum_type 1 csum_off 10 ] -# iif lo ip id set 0 +# meta iif lo ip id set 0 ip test-ip4 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/ip/ip.t.payload.inet +3 -3
@@ -548,7 +548,7 @@ inet test-inet input [ bitwise reg 1 = (reg=1 & 0x0000000f ) ^ 0x00000000 ] [ cmp eq reg 1 0x0000000f ] -# iif lo ip daddr set 127.0.0.1 +# meta iif lo ip daddr set 127.0.0.1 inet test-inet input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -557,7 +557,7 @@ inet test-inet input [ immediate reg 1 0x0100007f ] [ payload write reg 1 => 4b @ network header + 16 csum_type 1 csum_off 10 ] -# iif lo ip checksum set 0 +# meta iif lo ip checksum set 0 inet test-inet input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -566,7 +566,7 @@ inet test-inet input [ immediate reg 1 0x00000000 ] [ payload write reg 1 => 2b @ network header + 10 csum_type 1 csum_off 10 ] -# iif lo ip id set 0 +# meta iif lo ip id set 0 inet test-inet input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/ip/ip.t.payload.netdev +3 -3
@@ -648,7 +648,7 @@ netdev test-netdev ingress [ bitwise reg 1 = (reg=1 & 0x000000fc ) ^ 0x00000000 ] [ lookup reg 1 set __set%d ] -# iif lo ip daddr set 127.0.0.1 +# meta iif lo ip daddr set 127.0.0.1 netdev test-netdev ingress [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -657,7 +657,7 @@ netdev test-netdev ingress [ immediate reg 1 0x0100007f ] [ payload write reg 1 => 4b @ network header + 16 csum_type 1 csum_off 10 ] -# iif lo ip checksum set 0 +# meta iif lo ip checksum set 0 netdev test-netdev ingress [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -666,7 +666,7 @@ netdev test-netdev ingress [ immediate reg 1 0x00000000 ] [ payload write reg 1 => 2b @ network header + 10 csum_type 1 csum_off 10 ] -# iif lo ip id set 0 +# meta iif lo ip id set 0 netdev test-netdev ingress [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/ip/snat.t +6 -6
@@ -2,12 +2,12 @@ *ip;test-ip4;postrouting -iifname "eth0" tcp dport 80-90 snat 192.168.3.2;ok -iifname "eth0" tcp dport != 80-90 snat 192.168.3.2;ok -iifname "eth0" tcp dport {80, 90, 23} snat 192.168.3.2;ok -- iifname "eth0" tcp dport != {80, 90, 23} snat 192.168.3.2;ok -- iifname "eth0" tcp dport != {80, 90, 23} snat 192.168.3.2;ok +meta iifname "eth0" tcp dport 80-90 snat 192.168.3.2;ok +meta iifname "eth0" tcp dport != 80-90 snat 192.168.3.2;ok +meta iifname "eth0" tcp dport {80, 90, 23} snat 192.168.3.2;ok +- meta iifname "eth0" tcp dport != {80, 90, 23} snat 192.168.3.2;ok +- meta iifname "eth0" tcp dport != {80, 90, 23} snat 192.168.3.2;ok # BUG: invalid expression type set # nft: src/evaluate.c:975: expr_evaluate_relational: Assertion '0' failed. -iifname "eth0" tcp dport != 23-34 snat 192.168.3.2;ok +meta iifname "eth0" tcp dport != 23-34 snat 192.168.3.2;ok
tests/py/ip/snat.t.payload +4 -4
@@ -1,4 +1,4 @@ -# iifname "eth0" tcp dport 80-90 snat 192.168.3.2 +# meta iifname "eth0" tcp dport 80-90 snat 192.168.3.2 ip test-ip4 postrouting [ meta load iifname => reg 1 ] [ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]
@@ -10,7 +10,7 @@ ip test-ip4 postrouting [ immediate reg 1 0x0203a8c0 ] [ nat snat ip addr_min reg 1 addr_max reg 0 ] -# iifname "eth0" tcp dport != 80-90 snat 192.168.3.2 +# meta iifname "eth0" tcp dport != 80-90 snat 192.168.3.2 ip test-ip4 postrouting [ meta load iifname => reg 1 ] [ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]
@@ -22,7 +22,7 @@ ip test-ip4 postrouting [ immediate reg 1 0x0203a8c0 ] [ nat snat ip addr_min reg 1 addr_max reg 0 ] -# iifname "eth0" tcp dport {80, 90, 23} snat 192.168.3.2 +# meta iifname "eth0" tcp dport {80, 90, 23} snat 192.168.3.2 __set%d test-ip4 3 __set%d test-ip4 0 element 00005000 : 0 [end] element 00005a00 : 0 [end] element 00001700 : 0 [end]
@@ -36,7 +36,7 @@ ip test-ip4 postrouting [ immediate reg 1 0x0203a8c0 ] [ nat snat ip addr_min reg 1 addr_max reg 0 ] -# iifname "eth0" tcp dport != 23-34 snat 192.168.3.2 +# meta iifname "eth0" tcp dport != 23-34 snat 192.168.3.2 ip test-ip4 postrouting [ meta load iifname => reg 1 ] [ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]
tests/py/ip6/ip6.t +2 -2
@@ -143,5 +143,5 @@ ip6 saddr ::1 ip6 daddr ::2;ok ip6 daddr != ::1234:1234:1234:1234:1234:1234:1234-1234:1234::1234:1234:1234:1234:1234;ok;ip6 daddr != 0:1234:1234:1234:1234:1234:1234:1234-1234:1234:0:1234:1234:1234:1234:1234 # limit impact to lo -iif lo ip6 daddr set ::1;ok -iif lo ip6 hoplimit set 1;ok +meta iif lo ip6 daddr set ::1;ok +meta iif lo ip6 hoplimit set 1;ok
tests/py/ip6/ip6.t.payload.inet +2 -2
@@ -513,7 +513,7 @@ inet test-inet input [ cmp lt reg 1 0x34120000 0x34123412 0x34123412 0x34123412 ] [ cmp gt reg 1 0x34123412 0x34120000 0x34123412 0x34123412 ] -# iif lo ip6 daddr set ::1 +# meta iif lo ip6 daddr set ::1 inet test-inet input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -522,7 +522,7 @@ inet test-inet input [ immediate reg 1 0x00000000 0x00000000 0x00000000 0x01000000 ] [ payload write reg 1 => 16b @ network header + 24 csum_type 0 csum_off 0 ] -# iif lo ip6 hoplimit set 1 +# meta iif lo ip6 hoplimit set 1 inet test-inet input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
tests/py/ip6/ip6.t.payload.ip6 +2 -2
@@ -379,14 +379,14 @@ ip6 test-ip6 input [ cmp lt reg 1 0x34120000 0x34123412 0x34123412 0x34123412 ] [ cmp gt reg 1 0x34123412 0x34120000 0x34123412 0x34123412 ] -# iif lo ip6 daddr set ::1 +# meta iif lo ip6 daddr set ::1 ip6 test-ip6 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ] [ immediate reg 1 0x00000000 0x00000000 0x00000000 0x01000000 ] [ payload write reg 1 => 16b @ network header + 24 csum_type 0 csum_off 0 ] -# iif lo ip6 hoplimit set 1 +# meta iif lo ip6 hoplimit set 1 ip6 test-ip6 input [ meta load iif => reg 1 ] [ cmp eq reg 1 0x00000001 ]
Signature · 1 line
2.7.3
Quoted 9 lines · Florian Westphal
During NFWS we discussed reducing the number of keywords in nftables.
Obviously keywords are required for the parser to know what to expect.
But always requiring the 'meta' keyword would allow us to handle iif, oif, iifname etc without defining them in the scanner, i.e. we could later use 'meta STRING' and resolve/map the keyword at run time based on the meta template pseudo-header.
Quoted 5 lines
Note that this change does not yet reject 'iif eth0', this only makes nft always print the 'meta' keyword when listing and updates the test cases as required.
Signed-off-by Florian Westphal <[email protected]>
If we are to break the syntax sooner or later, I would ask to be as soon as possible.
Signature · 5 lines
Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerQuoted 4 lines · Florian Westphal
During NFWS we discussed reducing the number of keywords in nftables.
Obviously keywords are required for the parser to know what to expect.
Quoted 8 lines
But always requiring the 'meta' keyword would allow us to handle iif, oif, iifname etc without defining them in the scanner, i.e. we could later use 'meta STRING' and resolve/map the keyword at run time based on the meta template pseudo-header.
Note that this change does not yet reject 'iif eth0', this only makes nft always print the 'meta' keyword when listing and updates the test cases as required.
The main problem I have hit with this unqualified meta statements is that I cannot reuse selectors from other statements, eg.
dup to 1.2.3.4 device eth0
I had to use device here, when oif would have fit more naturally.
Apart from that, I remember that the intention was to get the command line syntax more compact, that also results in more compact listings.
If the main argument is to reduce the number of keywords, it would be good to see the patch that helps you reduce them after getting rid of this.