[PATCH nft 5/5] tests: add raw payload test cases.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Florian Westphal <fw@xxxxxxxxx>
---
 tests/py/any/rawpayload.t         | 19 +++++++++++++++
 tests/py/any/rawpayload.t.payload | 49 +++++++++++++++++++++++++++++++++++++++
 tests/py/arp/arp.t                |  2 ++
 tests/py/arp/arp.t.payload        | 10 ++++++++
 tests/py/arp/arp.t.payload.netdev | 13 +++++++++++
 5 files changed, 93 insertions(+)
 create mode 100644 tests/py/any/rawpayload.t
 create mode 100644 tests/py/any/rawpayload.t.payload

diff --git a/tests/py/any/rawpayload.t b/tests/py/any/rawpayload.t
new file mode 100644
index 000000000000..9a3402f1a406
--- /dev/null
+++ b/tests/py/any/rawpayload.t
@@ -0,0 +1,19 @@
+:input;type filter hook input priority 0
+:ingress;type filter hook ingress device lo priority 0
+
+*inet;test-inet;input
+*netdev;test-netdev;ingress
+
+meta l4proto { tcp, udp, sctp} @th,16,16 { 22, 23, 80 };ok;meta l4proto { 6, 17, 132} @th,16,16 { 22, 23, 80}
+meta l4proto tcp @th,16,16 { 22, 23, 80};ok;tcp dport { 22, 23, 80}
+@nh,8,8 255;ok
+@nh,8,16 0;ok
+
+# out of range (0-1)
+@th,16,1 2;fail
+
+@ll,0,0 2;fail
+@ll,0,1;fail
+@ll,0,1 1;ok;@ll,0,8 & 128 == 128
+@ll,0,8 and 0x80 eq 0x80;ok;@ll,0,8 & 128 == 128
+@ll,0,128 0xfedcba987654321001234567890abcde;ok;@ll,0,128 338770000845734292516042252062074518750
diff --git a/tests/py/any/rawpayload.t.payload b/tests/py/any/rawpayload.t.payload
new file mode 100644
index 000000000000..a2cc663568e0
--- /dev/null
+++ b/tests/py/any/rawpayload.t.payload
@@ -0,0 +1,49 @@
+# meta l4proto { tcp, udp, sctp} @th,16,16 { 22, 23, 80 }
+__set%d test-inet 3 size 3
+__set%d test-inet 0
+	element 00000006  : 0 [end]	element 00000011  : 0 [end]	element 00000084  : 0 [end]
+__set%d test-inet 3 size 3
+__set%d test-inet 0
+	element 00001600  : 0 [end]	element 00001700  : 0 [end]	element 00005000  : 0 [end]
+inet test-inet input 
+  [ meta load l4proto => reg 1 ]
+  [ lookup reg 1 set __set%d ]
+  [ payload load 2b @ transport header + 2 => reg 1 ]
+  [ lookup reg 1 set __set%d ]
+
+# meta l4proto tcp @th,16,16 { 22, 23, 80}
+__set%d test-inet 3 size 3
+__set%d test-inet 0
+	element 00001600  : 0 [end]	element 00001700  : 0 [end]	element 00005000  : 0 [end]
+inet test-inet input 
+  [ meta load l4proto => reg 1 ]
+  [ cmp eq reg 1 0x00000006 ]
+  [ payload load 2b @ transport header + 2 => reg 1 ]
+  [ lookup reg 1 set __set%d ]
+
+# @nh,8,8 255
+inet test-inet input
+  [ payload load 1b @ network header + 1 => reg 1 ]
+  [ cmp eq reg 1 0x000000ff ]
+
+# @nh,8,16 0
+inet test-inet input
+  [ payload load 2b @ network header + 1 => reg 1 ]
+  [ cmp eq reg 1 0x00000000 ]
+
+# @ll,0,1 1
+inet test-inet input
+  [ payload load 1b @ link header + 0 => reg 1 ]
+  [ bitwise reg 1 = (reg=1 & 0x00000080 ) ^ 0x00000000 ]
+  [ cmp eq reg 1 0x00000080 ]
+
+# @ll,0,8 and 0x80 eq 0x80
+inet test-inet input
+  [ payload load 1b @ link header + 0 => reg 1 ]
+  [ bitwise reg 1 = (reg=1 & 0x00000080 ) ^ 0x00000000 ]
+  [ cmp eq reg 1 0x00000080 ]
+
+# @ll,0,128 0xfedcba987654321001234567890abcde
+inet test-inet input
+  [ payload load 16b @ link header + 0 => reg 1 ]
+  [ cmp eq reg 1 0x98badcfe 0x10325476 0x67452301 0xdebc0a89 ]
diff --git a/tests/py/arp/arp.t b/tests/py/arp/arp.t
index 94ab4a50d0b8..36c7f1964841 100644
--- a/tests/py/arp/arp.t
+++ b/tests/py/arp/arp.t
@@ -54,3 +54,5 @@ arp operation != inrequest;ok
 arp operation != inreply;ok
 arp operation != nak;ok
 arp operation != reply;ok
+
+meta iifname \"invalid\" arp ptype 0x0800 arp htype 1 arp hlen 6 arp plen 4 @nh,192,32 0xc0a88f10 @nh,144,48 set 0x112233445566;ok;iifname "invalid" arp htype 1 arp ptype ip arp hlen 6 arp plen 4 @nh,192,32 3232272144 @nh,144,48 set 18838586676582
diff --git a/tests/py/arp/arp.t.payload b/tests/py/arp/arp.t.payload
index ea778b2d0296..34ae24144806 100644
--- a/tests/py/arp/arp.t.payload
+++ b/tests/py/arp/arp.t.payload
@@ -268,3 +268,13 @@ arp test-arp input
   [ payload load 2b @ network header + 6 => reg 1 ]
   [ cmp neq reg 1 0x00000200 ]
 
+# meta iifname \"invalid\" arp ptype 0x0800 arp htype 1 arp hlen 6 arp plen 4 @nh,192,32 0xc0a88f10 @nh,144,48 set 0x112233445566
+arp test-arp input
+  [ meta load iifname => reg 1 ]
+  [ cmp eq reg 1 0x61766e69 0x0064696c 0x00000000 0x00000000 ]
+  [ payload load 6b @ network header + 0 => reg 1 ]
+  [ cmp eq reg 1 0x00080100 0x00000406 ]
+  [ payload load 4b @ network header + 24 => reg 1 ]
+  [ cmp eq reg 1 0x108fa8c0 ]
+  [ immediate reg 1 0x44332211 0x00006655 ]
+  [ payload write reg 1 => 6b @ network header + 18 csum_type 0 csum_off 0 csum_flags 0x0 ]
diff --git a/tests/py/arp/arp.t.payload.netdev b/tests/py/arp/arp.t.payload.netdev
index acf9eb1ca5ff..21818ba2f2db 100644
--- a/tests/py/arp/arp.t.payload.netdev
+++ b/tests/py/arp/arp.t.payload.netdev
@@ -358,3 +358,16 @@ netdev test-netdev ingress
   [ payload load 2b @ network header + 6 => reg 1 ]
   [ cmp neq reg 1 0x00000200 ]
 
+# meta iifname \"invalid\" arp ptype 0x0800 arp htype 1 arp hlen 6 arp plen 4 @nh,192,32 0xc0a88f10 @nh,144,48 set 0x112233445566
+netdev test-netdev ingress
+  [ meta load iifname => reg 1 ]
+  [ cmp eq reg 1 0x61766e69 0x0064696c 0x00000000 0x00000000 ]
+  [ meta load protocol => reg 1 ]
+  [ cmp eq reg 1 0x00000608 ]
+  [ payload load 6b @ network header + 0 => reg 1 ]
+  [ cmp eq reg 1 0x00080100 0x00000406 ]
+  [ payload load 4b @ network header + 24 => reg 1 ]
+  [ cmp eq reg 1 0x108fa8c0 ]
+  [ immediate reg 1 0x44332211 0x00006655 ]
+  [ payload write reg 1 => 6b @ network header + 18 csum_type 0 csum_off 0 csum_flags 0x0 ]
+
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux