03bc6562e79a2a09ce9a8e76cf6626893d1d247d
[flowspec-xdp] / test.sh
1 #!/bin/bash
2
3 set -e
4
5 TEST_PKT='#define TEST \
6 "\x00\x17\x10\x95\xe8\x96\x00\x0d\xb9\x50\x11\x4c\x08\x00\x45\x00" \
7 "\x00\x8c\x7d\x0f\x00\x00\x40\x11\x3a\x31\x48\xe5\x68\xce\x67\x63" \
8 "\xaa\x0a\xdd\x9d\x10\x92\x00\x78\xc3\xaa\x04\x00\x00\x00\x47\x89" \
9 "\x49\xb1\x1f\x0e\x00\x00\x00\x00\x00\x00\xa7\xee\xab\xa4\xc6\x09" \
10 "\xe7\x0f\x41\xfc\xd5\x75\x1d\xc4\x97\xfa\xd7\x96\x8c\x1f\x19\x54" \
11 "\xa7\x74\x08\x5c\x28\xfe\xd9\x32\x4b\xe0\x62\x55\xeb\xb4\x1e\x36" \
12 "\x5f\xf5\x38\x48\x18\x75\x57\x9a\x05\x7e\x3d\xb1\x55\x79\x0f\xd0" \
13 "\x8c\x79\x72\x90\xb7\x16\x12\x18\xa1\x97\x53\xf1\x49\x0a\x35\x40" \
14 "\xc2\x8b\x72\x7a\x38\x22\x04\x96\x01\xd3\x7e\x47\x5d\xaa\x03\xb0" \
15 "\xb5\xc3\xa9\xa6\x21\x14\xc7\xd9\x71\x07"'
16
17 # Test all the things...
18 echo "flow4 { src 72.229.104.206/32; dst 103.99.170.10/32; proto = 17; sport = 56733; dport = 4242; length = 140; dscp 0/0xff; fragment !dont_fragment && !is_fragment && !first_fragment && !last_fragment };" | ./genrules.py
19 echo "$TEST_PKT" >> rules.h
20 echo "#define TEST_EXP XDP_DROP" >> rules.h
21 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
22
23 echo "flow4 { port = 4242; icmp code = 0; };" | ./genrules.py
24 echo "$TEST_PKT" >> rules.h
25 echo "#define TEST_EXP XDP_PASS" >> rules.h
26 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
27
28 # Some port tests...
29 echo "flow4 { port = 4242 && = 56733; };" | ./genrules.py
30 echo "$TEST_PKT" >> rules.h
31 echo "#define TEST_EXP XDP_DROP" >> rules.h
32 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
33
34 echo "flow4 { port = 4242 || 1; sport = 56733 };" | ./genrules.py
35 echo "$TEST_PKT" >> rules.h
36 echo "#define TEST_EXP XDP_DROP" >> rules.h
37 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
38
39 echo "flow4 { port = 4242 && 1 };" | ./genrules.py
40 echo "$TEST_PKT" >> rules.h
41 echo "#define TEST_EXP XDP_PASS" >> rules.h
42 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
43
44 echo "flow4 { icmp code != 0; };" | ./genrules.py parse_8021q
45 echo "$TEST_PKT" >> rules.h
46 echo "#define TEST_EXP XDP_PASS" >> rules.h
47 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
48
49 TEST_PKT='#define TEST \
50 "\x00\x0d\xb9\x50\x11\x4c\x00\x17\x10\x95\xe8\x96\x86\xdd\x60\x00" \
51 "\x00\x00\x00\x20\x06\x37\x2a\x01\x04\xf8\x01\x30\x71\xd2\x00\x00" \
52 "\x00\x00\x00\x00\x00\x02\x26\x20\x00\x6e\xa0\x00\x20\x01\x00\x00" \
53 "\x00\x00\x00\x00\x00\x06\x20\x8d\xc2\x72\xff\x5f\x50\xa7\x1a\xfb" \
54 "\x41\xed\x80\x10\x06\xef\x87\x8c\x00\x00\x01\x01\x08\x0a\x98\x3d" \
55 "\x75\xde\xeb\x22\xd6\x80"'
56
57 # Some v6 TCP tests...
58 echo "flow6 { src 2a01:4f8:130:71d2::2/128; dst 2620:6e:a000:2001::6/128; next header 6; port 8333 && 49778; tcp flags 0x010/0xfff;};" | ./genrules.py
59 echo "$TEST_PKT" >> rules.h
60 echo "#define TEST_EXP XDP_DROP" >> rules.h
61 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
62
63 echo "flow6 { src 0:4f8:130:71d2::2/128 offset 16; dst 0:0:a000:2001::/64 offset 32; next header 6; port 8333 && 49778; tcp flags 0x010/0xfff;};" | ./genrules.py
64 echo "$TEST_PKT" >> rules.h
65 echo "#define TEST_EXP XDP_DROP" >> rules.h
66 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
67
68 echo "flow6 { icmp code != 0; };" | ./genrules.py
69 echo "$TEST_PKT" >> rules.h
70 echo "#define TEST_EXP XDP_PASS" >> rules.h
71 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
72
73 TEST_PKT='#define TEST \
74 "\xcc\x2d\xe0\xf5\x02\xe1\x00\x0d\xb9\x50\x42\xfe\x81\x00\x00\x03" \
75 "\x08\x00\x45\x00\x00\x54\xda\x85\x40\x00\x40\x01\x67\xc6\x0a\x45" \
76 "\x1e\x51\xd1\xfa\xfd\xcc\x08\x00\x18\x82\x7e\xda\x00\x02\xc8\xc4" \
77 "\x67\x60\x00\x00\x00\x00\x69\xa9\x08\x00\x00\x00\x00\x00\x10\x11" \
78 "\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21" \
79 "\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31" \
80 "\x32\x33\x34\x35\x36\x37"'
81
82 # ICMP and VLAN tests
83 echo "flow4 { src 10.0.0.0/8; dst 209.250.0.0/16; proto = 1; icmp type 8; icmp code >= 0; length < 100; fragment dont_fragment; };" | ./genrules.py parse_8021q
84 echo "$TEST_PKT" >> rules.h
85 echo "#define TEST_EXP XDP_DROP" >> rules.h
86 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
87
88 echo "flow4 { icmp type 8; icmp code > 0; };" | ./genrules.py parse_8021q
89 echo "$TEST_PKT" >> rules.h
90 echo "#define TEST_EXP XDP_PASS" >> rules.h
91 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
92
93 echo "flow4 { icmp type 9; };" | ./genrules.py parse_8021q
94 echo "$TEST_PKT" >> rules.h
95 echo "#define TEST_EXP XDP_PASS" >> rules.h
96 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
97
98 echo "flow4 { src 10.0.0.0/8; dst 209.250.0.0/16; proto = 1; icmp type 8; icmp code >= 0; length < 100; fragment dont_fragment; };" | ./genrules.py req_8021q=3
99 echo "$TEST_PKT" >> rules.h
100 echo "#define TEST_EXP XDP_DROP" >> rules.h
101 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
102
103 echo "flow4 { src 0.0.0.0/32; };" | ./genrules.py req_8021q=4
104 echo "$TEST_PKT" >> rules.h
105 echo "#define TEST_EXP XDP_DROP" >> rules.h
106 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
107
108 echo "flow4 { src 0.0.0.0/32; };" | ./genrules.py req_8021q=3
109 echo "$TEST_PKT" >> rules.h
110 echo "#define TEST_EXP XDP_PASS" >> rules.h
111 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
112
113 echo "flow4 { port 42; };" | ./genrules.py parse_8021q
114 echo "$TEST_PKT" >> rules.h
115 echo "#define TEST_EXP XDP_PASS" >> rules.h
116 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
117
118 TEST_PKT='#define TEST \
119 "\x00\x0d\xb9\x50\x11\x4c\x00\x17\x10\x95\xe8\x96\x86\xdd\x60\x0a" \
120 "\xb8\x00\x00\x40\x3a\x3e\x20\x01\x04\x70\x00\x00\x02\xc8\x00\x00" \
121 "\x00\x00\x00\x00\x00\x02\x26\x20\x00\x6e\xa0\x00\x00\x01\x00\x00" \
122 "\x00\x00\x00\x00\xca\xfe\x81\x00\x40\x94\x85\x14\x00\x13\x00\x00" \
123 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
124 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
125 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
126 "\x00\x00\x00\x00\x00\x00"'
127
128 # ICMPv6 tests
129 echo "flow6 { icmp type 129; icmp code 0; };" | ./genrules.py
130 echo "$TEST_PKT" >> rules.h
131 echo "#define TEST_EXP XDP_DROP" >> rules.h
132 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
133
134 echo "flow6 { icmp code != 0; };" | ./genrules.py
135 echo "$TEST_PKT" >> rules.h
136 echo "#define TEST_EXP XDP_PASS" >> rules.h
137 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
138
139 echo "flow6 { tcp flags 0x0/0x0; };" | ./genrules.py
140 echo "$TEST_PKT" >> rules.h
141 echo "#define TEST_EXP XDP_PASS" >> rules.h
142 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
143
144 echo "flow6 { port 42; };" | ./genrules.py
145 echo "$TEST_PKT" >> rules.h
146 echo "#define TEST_EXP XDP_PASS" >> rules.h
147 clang -std=c99 -fsanitize=address -pedantic -Wall -Wextra -Wno-pointer-arith -Wno-unused-variable -O0 -g xdp.c -o xdp && ./xdp
148
149