]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: never merge across non-expression statements
authorFlorian Westphal <fw@strlen.de>
Thu, 28 Sep 2023 21:27:55 +0000 (23:27 +0200)
committerFlorian Westphal <fw@strlen.de>
Fri, 29 Sep 2023 10:36:33 +0000 (12:36 +0200)
The existing logic can merge across non-expression statements,
if there is only one payload expression.

Example:
ether saddr 00:11:22:33:44:55 counter ether type 8021q

is turned into
counter ether saddr 00:11:22:33:44:55 ether type 8021q

which isn't the same thing.

Fix this up and add test cases for adjacent vlan and ip header
fields.  'Counter' serves as a non-merge fence.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/rule.c
tests/py/bridge/vlan.t
tests/py/bridge/vlan.t.payload
tests/py/bridge/vlan.t.payload.netdev
tests/py/ip/ip.t
tests/py/ip/ip.t.payload

index 52c0672d4cf08be8fe6df4b538d709c4d576df12..739b7a5415835f5f98baf140d712959b16befb5a 100644 (file)
@@ -2744,10 +2744,8 @@ static void stmt_reduce(const struct rule *rule)
 
                /* Must not merge across other statements */
                if (stmt->ops->type != STMT_EXPRESSION) {
-                       if (idx < 2)
-                               continue;
-
-                       payload_do_merge(sa, idx);
+                       if (idx >= 2)
+                               payload_do_merge(sa, idx);
                        idx = 0;
                        continue;
                }
index 95bdff4f1b7534c8db1879246b79fab5fc3f4d84..8fa90dac7416974316a22e37f44990ffa37d06e4 100644 (file)
@@ -52,3 +52,5 @@ ether saddr 00:01:02:03:04:05 vlan id 1;ok
 vlan id 2 ether saddr 0:1:2:3:4:6;ok;ether saddr 00:01:02:03:04:06 vlan id 2
 
 ether saddr . vlan id { 0a:0b:0c:0d:0e:0f . 42, 0a:0b:0c:0d:0e:0f . 4095 };ok
+
+ether saddr 00:11:22:33:44:55 counter ether type 8021q;ok
index 62e4b89bd0b25bdb55eeccbc48ccf9dd32b00ade..2592bb96ad7c9b52e994942ee0a9d4025d6a6509 100644 (file)
@@ -304,3 +304,11 @@ bridge test-bridge input
   [ payload load 2b @ link header + 14 => reg 10 ]
   [ bitwise reg 10 = ( reg 10 & 0x0000ff0f ) ^ 0x00000000 ]
   [ lookup reg 1 set __set%d ]
+
+# ether saddr 00:11:22:33:44:55 counter ether type 8021q
+bridge test-bridge input
+  [ payload load 6b @ link header + 6 => reg 1 ]
+  [ cmp eq reg 1 0x33221100 0x00005544 ]
+  [ counter pkts 0 bytes 0 ]
+  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ cmp eq reg 1 0x00000081 ]
index 1018d4c6588ffdae24e36821a4632b35ef2bb566..f33419470ad5f6d526983b7f8882890894c43232 100644 (file)
@@ -356,3 +356,13 @@ netdev test-netdev ingress
   [ payload load 2b @ link header + 14 => reg 10 ]
   [ bitwise reg 10 = ( reg 10 & 0x0000ff0f ) ^ 0x00000000 ]
   [ lookup reg 1 set __set%d ]
+
+# ether saddr 00:11:22:33:44:55 counter ether type 8021q
+bridge test-bridge input
+  [ meta load iiftype => reg 1 ]
+  [ cmp eq reg 1 0x00000001 ]
+  [ payload load 6b @ link header + 6 => reg 1 ]
+  [ cmp eq reg 1 0x33221100 0x00005544 ]
+  [ counter pkts 0 bytes 0 ]
+  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ cmp eq reg 1 0x00000081 ]
index a8f0d820240075a3199dd4f900ed54e32dce3e01..720d9ae92b60da74d5b4dfd546632eac7b1e30a4 100644 (file)
@@ -130,3 +130,6 @@ iif "lo" ip dscp set cs0;ok
 
 ip saddr . ip daddr { 192.0.2.1 . 10.0.0.1-10.0.0.2 };ok
 ip saddr . ip daddr vmap { 192.168.5.1-192.168.5.128 . 192.168.6.1-192.168.6.128 : accept };ok
+
+ip saddr 1.2.3.4 ip daddr 3.4.5.6;ok
+ip saddr 1.2.3.4 counter ip daddr 3.4.5.6;ok
index 8224d4cd46debfed8c6a1424bc1a94c87457ae3e..43605a361a7a778fb5fe2ccf02bcfdc5aa4e9c90 100644 (file)
@@ -541,3 +541,18 @@ ip
   [ payload load 4b @ network header + 12 => reg 1 ]
   [ payload load 4b @ network header + 16 => reg 9 ]
   [ lookup reg 1 set __map%d dreg 0 ]
+
+# ip saddr 1.2.3.4 ip daddr 3.4.5.6
+ip test-ip4 input
+  [ payload load 4b @ network header + 12 => reg 1 ]
+  [ cmp eq reg 1 0x04030201 ]
+  [ payload load 4b @ network header + 16 => reg 1 ]
+  [ cmp eq reg 1 0x06050403 ]
+
+# ip saddr 1.2.3.4 counter ip daddr 3.4.5.6
+ip test-ip4 input
+  [ payload load 4b @ network header + 12 => reg 1 ]
+  [ cmp eq reg 1 0x04030201 ]
+  [ counter pkts 0 bytes 0 ]
+  [ payload load 4b @ network header + 16 => reg 1 ]
+  [ cmp eq reg 1 0x06050403 ]