nftables: convert single-elem anon sets to compare operation
Florian Westphal
maintainercover nftables: convert single-elem anon sets to compare operation
Auto-translate 'match { bar }' to 'match bar'. Doing this causes tons of failures in the python test suite, so first remove all test cases that use this pattern.
This is fine because all of these tests are redundant. A new test is added to cover the auto-removal.
This also includes cases where the set must not be auto-converted.
Florian Westphal (4):
tests: ct: prefer normal cmp
tests: remove redundant test cases
evaluate: remove anon sets with exactly one element
tests: add test case for removal of anon sets with only a single element
src/evaluate.c | 21 +- tests/py/any/meta.t | 4 - tests/py/any/meta.t.json | 40 -- tests/py/any/meta.t.payload | 38 -- tests/py/arp/arp.t | 6 - tests/py/arp/arp.t.json | 120 ------ tests/py/arp/arp.t.payload | 48 --- tests/py/arp/arp.t.payload.netdev | 60 --- tests/py/inet/ah.t | 8 - tests/py/inet/ah.t.json | 160 ------- tests/py/inet/ah.t.payload | 80 ---- tests/py/inet/comp.t | 4 - tests/py/inet/comp.t.json | 80 ---- tests/py/inet/comp.t.payload | 40 -- tests/py/inet/ct.t | 2 +- tests/py/inet/ct.t.json | 8 +- tests/py/inet/ct.t.payload | 7 +- tests/py/inet/dccp.t | 5 - tests/py/inet/dccp.t.json | 100 ----- tests/py/inet/dccp.t.payload | 50 --- tests/py/inet/esp.t | 5 - tests/py/inet/esp.t.json | 80 ---- tests/py/inet/esp.t.payload | 40 -- tests/py/inet/sctp.t | 8 - tests/py/inet/sctp.t.json | 160 ------- tests/py/inet/sctp.t.payload | 80 ---- tests/py/inet/tcp.t | 16 - tests/py/inet/tcp.t.json | 280 ------------ tests/py/inet/tcp.t.payload | 140 ------ tests/py/inet/udp.t | 8 - tests/py/inet/udp.t.json | 166 ------- tests/py/inet/udp.t.payload | 82 ---- tests/py/inet/udplite.t | 8 - tests/py/inet/udplite.t.json | 126 ------ tests/py/inet/udplite.t.payload | 62 --- tests/py/ip/icmp.t | 14 - tests/py/ip/icmp.t.json | 407 ------------------ tests/py/ip/icmp.t.payload.ip | 174 -------- tests/py/ip/igmp.t | 2 - tests/py/ip/igmp.t.json | 50 --- tests/py/ip/igmp.t.payload | 20 - tests/py/ip/ip.t | 12 - tests/py/ip/ip.t.json | 240 ----------- tests/py/ip/ip.t.payload | 96 ----- tests/py/ip/ip.t.payload.bridge | 120 ------ tests/py/ip/ip.t.payload.inet | 120 ------ tests/py/ip/ip.t.payload.netdev | 120 ------ tests/py/ip6/dst.t | 5 - tests/py/ip6/dst.t.json | 81 ---- tests/py/ip6/dst.t.payload.inet | 41 -- tests/py/ip6/dst.t.payload.ip6 | 34 -- tests/py/ip6/frag.t | 6 - tests/py/ip6/frag.t.payload.inet | 62 --- tests/py/ip6/frag.t.payload.ip6 | 50 --- tests/py/ip6/hbh.t | 4 - tests/py/ip6/hbh.t.json | 80 ---- tests/py/ip6/hbh.t.payload.inet | 40 -- tests/py/ip6/hbh.t.payload.ip6 | 32 -- tests/py/ip6/icmpv6.t | 12 - tests/py/ip6/icmpv6.t.json | 240 ----------- tests/py/ip6/icmpv6.t.payload.ip6 | 148 ------- tests/py/ip6/ip6.t | 8 - tests/py/ip6/ip6.t.json | 122 ------ tests/py/ip6/ip6.t.payload.inet | 82 ---- tests/py/ip6/ip6.t.payload.ip6 | 66 --- tests/py/ip6/mh.t | 8 - tests/py/ip6/mh.t.json | 162 ------- tests/py/ip6/mh.t.payload.inet | 81 ---- tests/py/ip6/mh.t.payload.ip6 | 65 --- tests/py/ip6/rt.t | 8 - tests/py/ip6/rt.t.json | 160 ------- tests/py/ip6/rt.t.payload.inet | 80 ---- tests/py/ip6/rt.t.payload.ip6 | 64 --- .../optimizations/dumps/single_anon_set.nft | 15 + .../dumps/single_anon_set.nft.input | 35 ++ .../testcases/optimizations/single_anon_set | 13 + .../shell/testcases/sets/dumps/0053echo_0.nft | 2 +- 77 files changed, 88 insertions(+), 5235 deletions(-) create mode 100644 tests/shell/testcases/optimizations/dumps/single_anon_set.nft create mode 100644 tests/shell/testcases/optimizations/dumps/single_anon_set.nft.input create mode 100755 tests/shell/testcases/optimizations/single_anon_set
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH 1/4 tests: ct: prefer normal cmp
Followup patch will replace the { 1.2.3.4 } with single cmp, so this will cause an error when the netlink dump gets compared.
--- tests/py/inet/ct.t | 2 +- tests/py/inet/ct.t.json | 8 ++------ tests/py/inet/ct.t.payload | 7 ++----- 3 files changed, 5 insertions(+), 12 deletions(-)
tests/py/inet/ct.t +1 -1
@@ -6,7 +6,7 @@ meta nfproto ipv4 ct original saddr 1.2.3.4;ok;ct original ip saddr 1.2.3.4 ct original ip6 saddr ::1;ok -ct original ip daddr {1.2.3.4} accept;ok +ct original ip daddr 1.2.3.4 accept;ok # missing protocol context ct original saddr ::1;fail
tests/py/inet/ct.t.json +2 -6
@@ -39,7 +39,7 @@ } ] -# ct original ip daddr {1.2.3.4} accept +# ct original ip daddr 1.2.3.4 accept [ { "match": {
@@ -50,11 +50,7 @@ } }, "op": "==", - "right": { - "set": [ - "1.2.3.4" - ] - } + "right": "1.2.3.4" } }, {
tests/py/inet/ct.t.payload +2 -5
@@ -10,11 +10,8 @@ inet test-inet input [ ct load src_ip6 => reg 1 , dir original ] [ cmp eq reg 1 0x00000000 0x00000000 0x00000000 0x01000000 ] -# ct original ip daddr {1.2.3.4} accept -__set%d test-inet 3 size 1 -__set%d test-inet 0 - element 04030201 : 0 [end] +# ct original ip daddr 1.2.3.4 accept inet test-inet input [ ct load dst_ip => reg 1 , dir original ] - [ lookup reg 1 set __set%d ] + [ cmp eq reg 1 0x04030201 ] [ immediate reg 0 accept ]
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH 2/4 tests: remove redundant test cases
In reply to Florian WestphalCheck for
... 23-42 ...
... { 23-42 } ...
and remove the latter. Followup patch will translate the former to the latter during evaluation step to avoid the unneded anon set.
A separate test case will be added that checks for such rewrites.
--- tests/py/any/meta.t | 4 - tests/py/any/meta.t.json | 40 --- tests/py/any/meta.t.payload | 38 --- tests/py/arp/arp.t | 6 - tests/py/arp/arp.t.json | 120 --------- tests/py/arp/arp.t.payload | 48 ---- tests/py/arp/arp.t.payload.netdev | 60 ----- tests/py/inet/ah.t | 8 - tests/py/inet/ah.t.json | 160 ------------ tests/py/inet/ah.t.payload | 80 ------ tests/py/inet/comp.t | 4 - tests/py/inet/comp.t.json | 80 ------ tests/py/inet/comp.t.payload | 40 --- tests/py/inet/dccp.t | 5 - tests/py/inet/dccp.t.json | 100 -------- tests/py/inet/dccp.t.payload | 50 ---- tests/py/inet/esp.t | 5 - tests/py/inet/esp.t.json | 80 ------ tests/py/inet/esp.t.payload | 40 --- tests/py/inet/sctp.t | 8 - tests/py/inet/sctp.t.json | 160 ------------ tests/py/inet/sctp.t.payload | 80 ------ tests/py/inet/tcp.t | 16 -- tests/py/inet/tcp.t.json | 280 -------------------- tests/py/inet/tcp.t.payload | 140 ---------- tests/py/inet/udp.t | 8 - tests/py/inet/udp.t.json | 166 ------------ tests/py/inet/udp.t.payload | 82 ------ tests/py/inet/udplite.t | 8 - tests/py/inet/udplite.t.json | 126 --------- tests/py/inet/udplite.t.payload | 62 ----- tests/py/ip/icmp.t | 14 - tests/py/ip/icmp.t.json | 407 ------------------------------ tests/py/ip/icmp.t.payload.ip | 174 ------------- tests/py/ip/igmp.t | 2 - tests/py/ip/igmp.t.json | 50 ---- tests/py/ip/igmp.t.payload | 20 -- tests/py/ip/ip.t | 12 - tests/py/ip/ip.t.json | 240 ------------------ tests/py/ip/ip.t.payload | 96 ------- tests/py/ip/ip.t.payload.bridge | 120 --------- tests/py/ip/ip.t.payload.inet | 120 --------- tests/py/ip/ip.t.payload.netdev | 120 --------- tests/py/ip6/dst.t | 5 - tests/py/ip6/dst.t.json | 81 ------ tests/py/ip6/dst.t.payload.inet | 41 --- tests/py/ip6/dst.t.payload.ip6 | 34 --- tests/py/ip6/frag.t | 6 - tests/py/ip6/frag.t.payload.inet | 62 ----- tests/py/ip6/frag.t.payload.ip6 | 50 ---- tests/py/ip6/hbh.t | 4 - tests/py/ip6/hbh.t.json | 80 ------ tests/py/ip6/hbh.t.payload.inet | 40 --- tests/py/ip6/hbh.t.payload.ip6 | 32 --- tests/py/ip6/icmpv6.t | 12 - tests/py/ip6/icmpv6.t.json | 240 ------------------ tests/py/ip6/icmpv6.t.payload.ip6 | 148 ----------- tests/py/ip6/ip6.t | 8 - tests/py/ip6/ip6.t.json | 122 --------- tests/py/ip6/ip6.t.payload.inet | 82 ------ tests/py/ip6/ip6.t.payload.ip6 | 66 ----- tests/py/ip6/mh.t | 8 - tests/py/ip6/mh.t.json | 162 ------------ tests/py/ip6/mh.t.payload.inet | 81 ------ tests/py/ip6/mh.t.payload.ip6 | 65 ----- tests/py/ip6/rt.t | 8 - tests/py/ip6/rt.t.json | 160 ------------ tests/py/ip6/rt.t.payload.inet | 80 ------ tests/py/ip6/rt.t.payload.ip6 | 64 ----- 69 files changed, 5220 deletions(-)
tests/py/any/meta.t +0 -4
@@ -115,8 +115,6 @@ meta skgid gt 3000 accept;ok;meta skgid > 3000 accept meta skgid eq 3000 accept;ok;meta skgid 3000 accept meta skgid 2001-2005 accept;ok meta skgid != 2001-2005 accept;ok -meta skgid { 2001-2005} accept;ok -meta skgid != { 2001-2005} accept;ok # BUG: meta nftrace 2 and meta nftrace 1 # $ sudo nft add rule ip test input meta nftrace 2
@@ -194,8 +192,6 @@ meta cgroup { 1048577, 1048578 };ok meta cgroup != { 1048577, 1048578};ok meta cgroup 1048577-1048578;ok meta cgroup != 1048577-1048578;ok -meta cgroup {1048577-1048578};ok -meta cgroup != { 1048577-1048578};ok meta iif . meta oif { "lo" . "lo" };ok;iif . oif { "lo" . "lo" } meta iif . meta oif . meta mark { "lo" . "lo" . 0x0000000a };ok;iif . oif . meta mark { "lo" . "lo" . 0x0000000a }
tests/py/any/meta.t.json +0 -40
@@ -1476,46 +1476,6 @@ } ] -# meta skgid { 2001-2005} accept -[ - { - "match": { - "left": { - "meta": { "key": "skgid" } - }, - "op": "==", - "right": { - "set": [ - { "range": [ 2001, 2005 ] } - ] - } - } - }, - { - "accept": null - } -] - -# meta skgid != { 2001-2005} accept -[ - { - "match": { - "left": { - "meta": { "key": "skgid" } - }, - "op": "!=", - "right": { - "set": [ - { "range": [ 2001, 2005 ] } - ] - } - } - }, - { - "accept": null - } -] - # meta mark set 0xffffffc8 xor 0x16 [ {
tests/py/any/meta.t.payload +0 -38
@@ -961,44 +961,6 @@ ip test-ip4 input [ meta load oifgroup => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] -# meta skgid { 2001-2005} accept -__set%d test-ip4 7 size 3 -__set%d test-ip4 0 - element 00000000 : 1 [end] element d1070000 : 0 [end] element d6070000 : 1 [end] -ip test-ip4 input - [ meta load skgid => reg 1 ] - [ byteorder reg 1 = hton(reg 1, 4, 4) ] - [ lookup reg 1 set __set%d ] - [ immediate reg 0 accept ] - -# meta skgid != { 2001-2005} accept -__set%d test-ip4 7 size 3 -__set%d test-ip4 0 - element 00000000 : 1 [end] element d1070000 : 0 [end] element d6070000 : 1 [end] -ip test-ip4 input - [ meta load skgid => reg 1 ] - [ byteorder reg 1 = hton(reg 1, 4, 4) ] - [ lookup reg 1 set __set%d 0x1 ] - [ immediate reg 0 accept ] - -# meta cgroup {1048577-1048578} -__set%d test-ip4 7 size 3 -__set%d test-ip4 0 - element 00000000 : 1 [end] element 01001000 : 0 [end] element 03001000 : 1 [end] -ip test-ip4 input - [ meta load cgroup => reg 1 ] - [ byteorder reg 1 = hton(reg 1, 4, 4) ] - [ lookup reg 1 set __set%d ] - -# meta cgroup != { 1048577-1048578} -__set%d test-ip4 7 size 3 -__set%d test-ip4 0 - element 00000000 : 1 [end] element 01001000 : 0 [end] element 03001000 : 1 [end] -ip test-ip4 input - [ meta load cgroup => reg 1 ] - [ byteorder reg 1 = hton(reg 1, 4, 4) ] - [ lookup reg 1 set __set%d 0x1 ] - # meta time "1970-05-23 21:07:14" drop ip meta-test input [ meta load time => reg 1 ]
tests/py/arp/arp.t +0 -6
@@ -13,8 +13,6 @@ arp htype 33-45;ok arp htype != 33-45;ok arp htype { 33, 55, 67, 88};ok arp htype != { 33, 55, 67, 88};ok -arp htype { 33-55};ok -arp htype != { 33-55};ok arp ptype 0x0800;ok;arp ptype ip
@@ -24,8 +22,6 @@ arp hlen 33-45;ok arp hlen != 33-45;ok arp hlen { 33, 55, 67, 88};ok arp hlen != { 33, 55, 67, 88};ok -arp hlen { 33-55};ok -arp hlen != { 33-55};ok arp plen 22;ok arp plen != 233;ok
@@ -33,8 +29,6 @@ arp plen 33-45;ok arp plen != 33-45;ok arp plen { 33, 55, 67, 88};ok arp plen != { 33, 55, 67, 88};ok -arp plen { 33-55};ok -arp plen != {33-55};ok arp operation {nak, inreply, inrequest, rreply, rrequest, reply, request};ok arp operation != {nak, inreply, inrequest, rreply, rrequest, reply, request};ok
tests/py/arp/arp.t.json +0 -120
138 lines not on this page · raw message
tests/py/arp/arp.t.payload +0 -48
66 lines not on this page · raw message
tests/py/arp/arp.t.payload.netdev +0 -60
78 lines not on this page · raw message
tests/py/inet/ah.t +0 -8
@@ -20,8 +20,6 @@ ah hdrlength 11-23;ok ah hdrlength != 11-23;ok -ah hdrlength { 11-23};ok -ah hdrlength != { 11-23};ok ah hdrlength {11, 23, 44 };ok ah hdrlength != {11, 23, 44 };ok
@@ -31,8 +29,6 @@ ah reserved 33-45;ok ah reserved != 33-45;ok ah reserved {23, 100};ok ah reserved != {23, 100};ok -ah reserved { 33-55};ok -ah reserved != { 33-55};ok ah spi 111;ok ah spi != 111;ok
@@ -40,15 +36,11 @@ ah spi 111-222;ok ah spi != 111-222;ok ah spi {111, 122};ok ah spi != {111, 122};ok -ah spi { 111-122};ok -ah spi != { 111-122};ok # sequence ah sequence 123;ok ah sequence != 123;ok ah sequence {23, 25, 33};ok ah sequence != {23, 25, 33};ok -ah sequence { 23-33};ok -ah sequence != { 23-33};ok ah sequence 23-33;ok ah sequence != 23-33;ok
tests/py/inet/ah.t.json +0 -160
184 lines not on this page · raw message
tests/py/inet/ah.t.payload +0 -80
104 lines not on this page · raw message
tests/py/inet/comp.t +0 -4
@@ -20,8 +20,6 @@ comp flags 0x33-0x45;ok comp flags != 0x33-0x45;ok comp flags {0x33, 0x55, 0x67, 0x88};ok comp flags != {0x33, 0x55, 0x67, 0x88};ok -comp flags { 0x33-0x55};ok -comp flags != { 0x33-0x55};ok comp cpi 22;ok comp cpi != 233;ok
@@ -29,5 +27,3 @@ comp cpi 33-45;ok comp cpi != 33-45;ok comp cpi {33, 55, 67, 88};ok comp cpi != {33, 55, 67, 88};ok -comp cpi { 33-55};ok -comp cpi != { 33-55};ok
tests/py/inet/comp.t.json +0 -80
89 lines not on this page · raw message
tests/py/inet/comp.t.payload +0 -40
@@ -54,26 +54,6 @@ inet test-inet input [ payload load 1b @ transport header + 1 => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] -# comp flags { 0x33-0x55} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 00000033 : 0 [end] element 00000056 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x0000006c ] - [ payload load 1b @ transport header + 1 => reg 1 ] - [ lookup reg 1 set __set%d ] - -# comp flags != { 0x33-0x55} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 00000033 : 0 [end] element 00000056 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x0000006c ] - [ payload load 1b @ transport header + 1 => reg 1 ] - [ lookup reg 1 set __set%d 0x1 ] - # comp cpi 22 inet test-inet input [ meta load l4proto => reg 1 ]
@@ -123,23 +103,3 @@ inet test-inet input [ payload load 2b @ transport header + 2 => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] -# comp cpi { 33-55} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 00002100 : 0 [end] element 00003800 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x0000006c ] - [ payload load 2b @ transport header + 2 => reg 1 ] - [ lookup reg 1 set __set%d ] - -# comp cpi != { 33-55} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 00002100 : 0 [end] element 00003800 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x0000006c ] - [ payload load 2b @ transport header + 2 => reg 1 ] - [ lookup reg 1 set __set%d 0x1 ] -
tests/py/inet/dccp.t +0 -5
@@ -11,17 +11,12 @@ dccp sport != 21-35;ok dccp sport {23, 24, 25};ok dccp sport != {23, 24, 25};ok -dccp sport { 20-50 };ok dccp sport 20-50;ok -dccp sport { 20-50};ok -dccp sport != { 20-50};ok # dccp dport 21-35;ok # dccp dport != 21-35;ok dccp dport {23, 24, 25};ok dccp dport != {23, 24, 25};ok -dccp dport { 20-50};ok -dccp dport != { 20-50};ok dccp type {request, response, data, ack, dataack, closereq, close, reset, sync, syncack};ok dccp type != {request, response, data, ack, dataack, closereq, close, reset, sync, syncack};ok
tests/py/inet/dccp.t.json +0 -100
118 lines not on this page · raw message
tests/py/inet/dccp.t.payload +0 -50
68 lines not on this page · raw message
tests/py/inet/esp.t +0 -5
@@ -12,14 +12,9 @@ esp spi 111-222;ok esp spi != 111-222;ok esp spi { 100, 102};ok esp spi != { 100, 102};ok -esp spi { 100-102};ok -esp spi != { 100-102};ok -- esp spi {100-102};ok esp sequence 22;ok esp sequence 22-24;ok esp sequence != 22-24;ok esp sequence { 22, 24};ok esp sequence != { 22, 24};ok -esp sequence { 22-25};ok -esp sequence != { 22-25};ok
tests/py/inet/esp.t.json +0 -80
89 lines not on this page · raw message
tests/py/inet/esp.t.payload +0 -40
@@ -47,26 +47,6 @@ inet test-inet input [ payload load 4b @ transport header + 0 => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] -# esp spi { 100-102} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 64000000 : 0 [end] element 67000000 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x00000032 ] - [ payload load 4b @ transport header + 0 => reg 1 ] - [ lookup reg 1 set __set%d ] - -# esp spi != { 100-102} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 64000000 : 0 [end] element 67000000 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x00000032 ] - [ payload load 4b @ transport header + 0 => reg 1 ] - [ lookup reg 1 set __set%d 0x1 ] - # esp sequence 22 inet test-inet input [ meta load l4proto => reg 1 ]
@@ -109,23 +89,3 @@ inet test-inet input [ payload load 4b @ transport header + 4 => reg 1 ] [ lookup reg 1 set __set%d 0x1 ] -# esp sequence { 22-25} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 16000000 : 0 [end] element 1a000000 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x00000032 ] - [ payload load 4b @ transport header + 4 => reg 1 ] - [ lookup reg 1 set __set%d ] - -# esp sequence != { 22-25} -__set%d test-inet 7 -__set%d test-inet 0 - element 00000000 : 1 [end] element 16000000 : 0 [end] element 1a000000 : 1 [end] -inet test-inet input - [ meta load l4proto => reg 1 ] - [ cmp eq reg 1 0x00000032 ] - [ payload load 4b @ transport header + 4 => reg 1 ] - [ lookup reg 1 set __set%d 0x1 ] -
tests/py/inet/sctp.t +0 -8
@@ -12,8 +12,6 @@ sctp sport 23-44;ok sctp sport != 23-44;ok sctp sport { 23, 24, 25};ok sctp sport != { 23, 24, 25};ok -sctp sport { 23-44};ok -sctp sport != { 23-44};ok sctp dport 23;ok sctp dport != 23;ok
@@ -21,8 +19,6 @@ sctp dport 23-44;ok sctp dport != 23-44;ok sctp dport { 23, 24, 25};ok sctp dport != { 23, 24, 25};ok -sctp dport { 23-44};ok -sctp dport != { 23-44};ok sctp checksum 1111;ok sctp checksum != 11;ok
@@ -30,8 +26,6 @@ sctp checksum 21-333;ok sctp checksum != 32-111;ok sctp checksum { 22, 33, 44};ok sctp checksum != { 22, 33, 44};ok -sctp checksum { 22-44};ok -sctp checksum != { 22-44};ok sctp vtag 22;ok sctp vtag != 233;ok
@@ -39,8 +33,6 @@ sctp vtag 33-45;ok sctp vtag != 33-45;ok sctp vtag {33, 55, 67, 88};ok sctp vtag != {33, 55, 67, 88};ok -sctp vtag { 33-55};ok -sctp vtag != { 33-55};ok # assert all chunk types are recognized sctp chunk data exists;ok
tests/py/inet/sctp.t.json +0 -160
184 lines not on this page · raw message
tests/py/inet/sctp.t.payload +0 -80
104 lines not on this page · raw message
tests/py/inet/tcp.t +0 -16
@@ -14,8 +14,6 @@ tcp dport 33-45;ok tcp dport != 33-45;ok tcp dport { 33, 55, 67, 88};ok tcp dport != { 33, 55, 67, 88};ok -tcp dport { 33-55};ok -tcp dport != { 33-55};ok tcp dport {telnet, http, https} accept;ok;tcp dport { 443, 23, 80} accept tcp dport vmap { 22 : accept, 23 : drop };ok tcp dport vmap { 25:accept, 28:drop };ok
@@ -30,8 +28,6 @@ tcp sport 33-45;ok tcp sport != 33-45;ok tcp sport { 33, 55, 67, 88};ok tcp sport != { 33, 55, 67, 88};ok -tcp sport { 33-55};ok -tcp sport != { 33-55};ok tcp sport vmap { 25:accept, 28:drop };ok tcp sport 8080 drop;ok
@@ -47,8 +43,6 @@ tcp sequence 33-45;ok tcp sequence != 33-45;ok tcp sequence { 33, 55, 67, 88};ok tcp sequence != { 33, 55, 67, 88};ok -tcp sequence { 33-55};ok -tcp sequence != { 33-55};ok tcp ackseq 42949672 drop;ok tcp ackseq 22;ok
@@ -57,8 +51,6 @@ tcp ackseq 33-45;ok tcp ackseq != 33-45;ok tcp ackseq { 33, 55, 67, 88};ok tcp ackseq != { 33, 55, 67, 88};ok -tcp ackseq { 33-55};ok -tcp ackseq != { 33-55};ok - tcp doff 22;ok - tcp doff != 233;ok
@@ -66,8 +58,6 @@ tcp ackseq != { 33-55};ok - tcp doff != 33-45;ok - tcp doff { 33, 55, 67, 88};ok - tcp doff != { 33, 55, 67, 88};ok -- tcp doff { 33-55};ok -- tcp doff != { 33-55};ok # BUG reserved # BUG: It is accepted but it is not shown then. tcp reserver
@@ -90,8 +80,6 @@ tcp window 33-45;ok tcp window != 33-45;ok tcp window { 33, 55, 67, 88};ok tcp window != { 33, 55, 67, 88};ok -tcp window { 33-55};ok -tcp window != { 33-55};ok tcp checksum 22;ok tcp checksum != 233;ok
@@ -99,8 +87,6 @@ tcp checksum 33-45;ok tcp checksum != 33-45;ok tcp checksum { 33, 55, 67, 88};ok tcp checksum != { 33, 55, 67, 88};ok -tcp checksum { 33-55};ok -tcp checksum != { 33-55};ok tcp urgptr 1234 accept;ok tcp urgptr 22;ok
@@ -109,7 +95,5 @@ tcp urgptr 33-45;ok tcp urgptr != 33-45;ok tcp urgptr { 33, 55, 67, 88};ok tcp urgptr != { 33, 55, 67, 88};ok -tcp urgptr { 33-55};ok -tcp urgptr != { 33-55};ok tcp doff 8;ok
tests/py/inet/tcp.t.json +0 -280
322 lines not on this page · raw message
tests/py/inet/tcp.t.payload +0 -140
182 lines not on this page · raw message
tests/py/inet/udp.t +0 -8
@@ -12,8 +12,6 @@ udp sport 50-70 accept;ok udp sport != 50-60 accept;ok udp sport { 49, 50} drop;ok udp sport != { 50, 60} accept;ok -udp sport { 12-40};ok -udp sport != { 13-24};ok udp dport set {1, 2, 3};fail
@@ -23,8 +21,6 @@ udp dport 70-75 accept;ok udp dport != 50-60 accept;ok udp dport { 49, 50} drop;ok udp dport != { 50, 60} accept;ok -udp dport { 70-75} accept;ok -udp dport != { 50-60} accept;ok udp length 6666;ok udp length != 6666;ok
@@ -32,8 +28,6 @@ udp length 50-65 accept;ok udp length != 50-65 accept;ok udp length { 50, 65} accept;ok udp length != { 50, 65} accept;ok -udp length { 35-50};ok -udp length != { 35-50};ok udp checksum 6666 drop;ok udp checksum != { 444, 555} accept;ok
@@ -44,8 +38,6 @@ udp checksum 33-45;ok udp checksum != 33-45;ok udp checksum { 33, 55, 67, 88};ok udp checksum != { 33, 55, 67, 88};ok -udp checksum { 33-55};ok -udp checksum != { 33-55};ok # limit impact to lo iif "lo" udp checksum set 0;ok
tests/py/inet/udp.t.json +0 -166
190 lines not on this page · raw message
tests/py/inet/udp.t.payload +0 -82
106 lines not on this page · raw message
tests/py/inet/udplite.t +0 -8
@@ -12,8 +12,6 @@ udplite sport 50-70 accept;ok udplite sport != 50-60 accept;ok udplite sport { 49, 50} drop;ok udplite sport != { 49, 50} accept;ok -udplite sport { 12-40};ok -udplite sport != { 12-40};ok udplite dport 80 accept;ok udplite dport != 60 accept;ok
@@ -21,8 +19,6 @@ udplite dport 70-75 accept;ok udplite dport != 50-60 accept;ok udplite dport { 49, 50} drop;ok udplite dport != { 49, 50} accept;ok -udplite dport { 70-75} accept;ok -udplite dport != { 70-75} accept;ok - udplite csumcov 6666;ok - udplite csumcov != 6666;ok
@@ -30,8 +26,6 @@ udplite dport != { 70-75} accept;ok - udplite csumcov != 50-65 accept;ok - udplite csumcov { 50, 65} accept;ok - udplite csumcov != { 50, 65} accept;ok -- udplite csumcov { 35-50};ok -- udplite csumcov != { 35-50};ok udplite checksum 6666 drop;ok udplite checksum != { 444, 555} accept;ok
@@ -41,5 +35,3 @@ udplite checksum 33-45;ok udplite checksum != 33-45;ok udplite checksum { 33, 55, 67, 88};ok udplite checksum != { 33, 55, 67, 88};ok -udplite checksum { 33-55};ok -udplite checksum != { 33-55};ok
tests/py/inet/udplite.t.json +0 -126
141 lines not on this page · raw message
tests/py/inet/udplite.t.payload +0 -62
77 lines not on this page · raw message
tests/py/ip/icmp.t +0 -14
@@ -26,8 +26,6 @@ icmp code 111 accept;ok icmp code != 111 accept;ok icmp code 33-55;ok icmp code != 33-55;ok -icmp code { 33-55};ok -icmp code != { 33-55};ok icmp code { 2, 4, 54, 33, 56};ok;icmp code { prot-unreachable, frag-needed, 33, 54, 56} icmp code != { prot-unreachable, frag-needed, 33, 54, 56};ok
@@ -35,8 +33,6 @@ icmp checksum 12343 accept;ok icmp checksum != 12343 accept;ok icmp checksum 11-343 accept;ok icmp checksum != 11-343 accept;ok -icmp checksum { 11-343} accept;ok -icmp checksum != { 11-343} accept;ok icmp checksum { 1111, 222, 343} accept;ok icmp checksum != { 1111, 222, 343} accept;ok
@@ -45,8 +41,6 @@ icmp id 22;ok;icmp type { echo-reply, echo-request} icmp id 22 icmp id != 233;ok;icmp type { echo-reply, echo-request} icmp id != 233 icmp id 33-45;ok;icmp type { echo-reply, echo-request} icmp id 33-45 icmp id != 33-45;ok;icmp type { echo-reply, echo-request} icmp id != 33-45 -icmp id { 33-55};ok;icmp type { echo-reply, echo-request} icmp id { 33-55} -icmp id != { 33-55};ok;icmp type { echo-reply, echo-request} icmp id != { 33-55} icmp id { 22, 34, 333};ok;icmp type { echo-request, echo-reply} icmp id { 22, 34, 333} icmp id != { 22, 34, 333};ok;icmp type { echo-request, echo-reply} icmp id != { 22, 34, 333}
@@ -57,23 +51,17 @@ icmp sequence 33-45;ok;icmp type { echo-reply, echo-request} icmp sequence 33-45 icmp sequence != 33-45;ok;icmp type { echo-reply, echo-request} icmp sequence != 33-45 icmp sequence { 33, 55, 67, 88};ok;icmp type { echo-request, echo-reply} icmp sequence { 33, 55, 67, 88} icmp sequence != { 33, 55, 67, 88};ok;icmp type { echo-request, echo-reply} icmp sequence != { 33, 55, 67, 88} -icmp sequence { 33-55};ok;icmp type { echo-request, echo-reply} icmp sequence { 33-55} -icmp sequence != { 33-55};ok;icmp type { echo-request, echo-reply} icmp sequence != { 33-55} icmp id 1 icmp sequence 2;ok;icmp type { echo-reply, echo-request} icmp id 1 icmp sequence 2 icmp type { echo-reply, echo-request} icmp id 1 icmp sequence 2;ok icmp mtu 33;ok icmp mtu 22-33;ok -icmp mtu { 22-33};ok -icmp mtu != { 22-33};ok icmp mtu 22;ok icmp mtu != 233;ok icmp mtu 33-45;ok icmp mtu != 33-45;ok icmp mtu { 33, 55, 67, 88};ok icmp mtu != { 33, 55, 67, 88};ok -icmp mtu { 33-55};ok -icmp mtu != { 33-55};ok icmp gateway 22;ok icmp gateway != 233;ok
@@ -81,8 +69,6 @@ icmp gateway 33-45;ok icmp gateway != 33-45;ok icmp gateway { 33, 55, 67, 88};ok icmp gateway != { 33, 55, 67, 88};ok -icmp gateway { 33-55};ok -icmp gateway != { 33-55};ok icmp gateway != 34;ok icmp gateway != { 333, 334};ok
tests/py/ip/icmp.t.json +0 -407
246 lines not on this page · raw message
tests/py/ip/icmp.t.payload.ip +0 -174
174 lines not on this page · raw message
tests/py/ip/igmp.t.json +0 -50
50 lines not on this page · raw message
tests/py/ip/ip.t.json +0 -240
240 lines not on this page · raw message
tests/py/ip/ip.t.payload +0 -96
96 lines not on this page · raw message
tests/py/ip/ip.t.payload.bridge +0 -120
120 lines not on this page · raw message
tests/py/ip/ip.t.payload.inet +0 -120
120 lines not on this page · raw message
tests/py/ip/ip.t.payload.netdev +0 -120
120 lines not on this page · raw message
tests/py/ip6/dst.t.json +0 -81
81 lines not on this page · raw message
tests/py/ip6/dst.t.payload.inet +0 -41
41 lines not on this page · raw message
tests/py/ip6/frag.t.payload.inet +0 -62
62 lines not on this page · raw message
tests/py/ip6/frag.t.payload.ip6 +0 -50
50 lines not on this page · raw message
tests/py/ip6/hbh.t.json +0 -80
80 lines not on this page · raw message
tests/py/ip6/icmpv6.t.json +0 -240
240 lines not on this page · raw message
tests/py/ip6/icmpv6.t.payload.ip6 +0 -148
148 lines not on this page · raw message
tests/py/ip6/ip6.t.json +0 -122
122 lines not on this page · raw message
tests/py/ip6/ip6.t.payload.inet +0 -82
82 lines not on this page · raw message
tests/py/ip6/ip6.t.payload.ip6 +0 -66
66 lines not on this page · raw message
tests/py/ip6/mh.t.json +0 -162
162 lines not on this page · raw message
tests/py/ip6/mh.t.payload.inet +0 -81
81 lines not on this page · raw message
tests/py/ip6/mh.t.payload.ip6 +0 -65
65 lines not on this page · raw message
tests/py/ip6/rt.t.json +0 -160
160 lines not on this page · raw message
tests/py/ip6/rt.t.payload.inet +0 -80
80 lines not on this page · raw message
tests/py/ip6/rt.t.payload.ip6 +0 -64
64 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.26.3
Part of the diff is not shown here. View the raw message.
Florian Westphal
maintainerPATCH 3/4 evaluate: remove anon sets with exactly one element
In reply to Florian WestphalAuto-replace lookups in single-element anon sets with a standard compare.
'add rule foo bar meta iif { "lo" }' gets replaced with 'add rule foo bar meta iif "lo"'.
The former is a set lookup, the latter is a comparision. Comparisions are faster for the one-element case.
Only prefixes, ranges and values are handled at this time.
Anonymous maps are left alone, same for concatenations.
Concatenations could be handled, but it would require more work:
the concatenation would have to be replaced with a singleton value. Evaluation step rejects concat RHS on a relational expression.
--- src/evaluate.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
src/evaluate.c +19 -2
@@ -1455,8 +1455,25 @@ static int expr_evaluate_set(struct eval_ctx *ctx, struct expr **expr) } } -if (ctx->set && (ctx->set->flags &NFT_SET_CONCAT )) - set->set_flags |=NFT_SET_CONCAT ; +if (ctx->set) { +if (ctx->set->flags &NFT_SET_CONCAT ) + set->set_flags |=NFT_SET_CONCAT ; + }else if (set->size ==1 ) { + i = list_first_entry(&set->expressions, struct expr, list); +if (i->etype ==EXPR_SET_ELEM ) { +switch (i->key->etype) { +case EXPR_PREFIX : +case EXPR_RANGE : +case EXPR_VALUE : + *expr = i->key; + i->key =NULL ; +expr_free (set); +return 0 ; +default : +break ; + } + } + } set->set_flags |=NFT_SET_CONSTANT ;
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH 4/4 tests: add test case for removal of anon sets with only a single element
In reply to Florian WestphalAlso add a few examples that should not be changed:
- anon set with 2 elements
- anon map with 1 element
- anon set with a concatenation
The latter could be done with cmp but this currently triggers 'Error: Use concatenations with sets and maps, not singleton values' after removing the anon set.
--- .../optimizations/dumps/single_anon_set.nft | 15 ++++++++ .../dumps/single_anon_set.nft.input | 35 +++++++++++++++++++ .../testcases/optimizations/single_anon_set | 13 +++++++ .../shell/testcases/sets/dumps/0053echo_0.nft | 2 +- 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/shell/testcases/optimizations/dumps/single_anon_set.nft create mode 100644 tests/shell/testcases/optimizations/dumps/single_anon_set.nft.input create mode 100755 tests/shell/testcases/optimizations/single_anon_set
tests/shell/testcases/optimizations/dumps/single_anon_set.nft new file +15 -0
@@ -0,0 +1,15 @@ +table ip test { + chain test { + ip saddr 127.0.0.1 accept + iif "lo" accept + tcp dport != 22 drop + ip saddr 127.0.0.0/8 accept + ip saddr 127.0.0.1-192.168.7.3 accept + tcp sport 1-1023 drop + ip daddr { 192.168.7.1, 192.168.7.5 } accept + tcp dport { 80, 443 } accept + ip daddr . tcp dport { 192.168.0.1 . 22 } accept + meta mark set ip daddr map { 192.168.0.1 : 0x00000001 } + ct state { established, related } accept + } +}
tests/shell/testcases/optimizations/dumps/single_anon_set.nft.input new file +35 -0
@@ -0,0 +1,35 @@ +table ip test { + chain test { + # Test cases where anon set can be removed: + ip saddr { 127.0.0.1 } accept + iif { "lo" } accept + + # negation, can change to != 22. + tcp dport != { 22 } drop + + # single prefix, can remove anon set. + ip saddr { 127.0.0.0/8 } accept + + # range, can remove anon set. + ip saddr { 127.0.0.1-192.168.7.3 } accept + tcp sport { 1-1023 } drop + + # Test cases where anon set must be kept. + + # 2 elements, cannot remove the anon set. + ip daddr { 192.168.7.1, 192.168.7.5 } accept + tcp dport { 80, 443 } accept + + # single element, but concatenation which is not + # supported outside of set/map context at this time. + ip daddr . tcp dport { 192.168.0.1 . 22 } accept + + # single element, but a map. + meta mark set ip daddr map { 192.168.0.1 : 1 } + + # 2 elements. This could be converted because + # ct state cannot be both established and related + # at the same time, but this needs extra work. + ct state { established, related } accept + } +}
tests/shell/testcases/optimizations/single_anon_set new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +# Input file contains rules with anon sets that contain +# one element, plus extra rule with two elements (that should be +# left alone). + +# Dump file has the simplified rules where anon sets have been +# replaced by equality tests where possible. +dumpfile=$(dirname $0)/dumps/$(basename $0).nft + +$NFT -f "$dumpfile".input
tests/shell/testcases/sets/dumps/0053echo_0.nft +1 -1
@@ -1,6 +1,6 @@ table inet filter { chain input { type filter hook input priority filter; policy drop; - iifname { "lo" } ip saddr { 10.0.0.0/8 } ip daddr { 192.168.100.62 } tcp dport { 2001 } counter packets 0 bytes 0 accept + iifname "lo" ip saddr 10.0.0.0/8 ip daddr 192.168.100.62 tcp dport 2001 counter packets 0 bytes 0 accept } }
Signature · 1 line
2.26.3