WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / tc_flower.sh
blob058c746ee3006e6961367a26973d03e52b6175bf
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
5 match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \
6 match_ip_tos_test match_indev_test"
7 NUM_NETIFS=2
8 source tc_common.sh
9 source lib.sh
11 tcflags="skip_hw"
13 h1_create()
15 simple_if_init $h1 192.0.2.1/24 198.51.100.1/24
18 h1_destroy()
20 simple_if_fini $h1 192.0.2.1/24 198.51.100.1/24
23 h2_create()
25 simple_if_init $h2 192.0.2.2/24 198.51.100.2/24
26 tc qdisc add dev $h2 clsact
29 h2_destroy()
31 tc qdisc del dev $h2 clsact
32 simple_if_fini $h2 192.0.2.2/24 198.51.100.2/24
35 match_dst_mac_test()
37 local dummy_mac=de:ad:be:ef:aa:aa
39 RET=0
41 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
42 $tcflags dst_mac $dummy_mac action drop
43 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
44 $tcflags dst_mac $h2mac action drop
46 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
47 -t ip -q
49 tc_check_packets "dev $h2 ingress" 101 1
50 check_fail $? "Matched on a wrong filter"
52 tc_check_packets "dev $h2 ingress" 102 1
53 check_err $? "Did not match on correct filter"
55 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
56 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
58 log_test "dst_mac match ($tcflags)"
61 match_src_mac_test()
63 local dummy_mac=de:ad:be:ef:aa:aa
65 RET=0
67 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
68 $tcflags src_mac $dummy_mac action drop
69 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
70 $tcflags src_mac $h1mac action drop
72 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
73 -t ip -q
75 tc_check_packets "dev $h2 ingress" 101 1
76 check_fail $? "Matched on a wrong filter"
78 tc_check_packets "dev $h2 ingress" 102 1
79 check_err $? "Did not match on correct filter"
81 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
82 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
84 log_test "src_mac match ($tcflags)"
87 match_dst_ip_test()
89 RET=0
91 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
92 $tcflags dst_ip 198.51.100.2 action drop
93 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
94 $tcflags dst_ip 192.0.2.2 action drop
95 tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
96 $tcflags dst_ip 192.0.2.0/24 action drop
98 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
99 -t ip -q
101 tc_check_packets "dev $h2 ingress" 101 1
102 check_fail $? "Matched on a wrong filter"
104 tc_check_packets "dev $h2 ingress" 102 1
105 check_err $? "Did not match on correct filter"
107 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
109 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
110 -t ip -q
112 tc_check_packets "dev $h2 ingress" 103 1
113 check_err $? "Did not match on correct filter with mask"
115 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
116 tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
118 log_test "dst_ip match ($tcflags)"
121 match_src_ip_test()
123 RET=0
125 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
126 $tcflags src_ip 198.51.100.1 action drop
127 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
128 $tcflags src_ip 192.0.2.1 action drop
129 tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
130 $tcflags src_ip 192.0.2.0/24 action drop
132 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
133 -t ip -q
135 tc_check_packets "dev $h2 ingress" 101 1
136 check_fail $? "Matched on a wrong filter"
138 tc_check_packets "dev $h2 ingress" 102 1
139 check_err $? "Did not match on correct filter"
141 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
143 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
144 -t ip -q
146 tc_check_packets "dev $h2 ingress" 103 1
147 check_err $? "Did not match on correct filter with mask"
149 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
150 tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
152 log_test "src_ip match ($tcflags)"
155 match_ip_flags_test()
157 RET=0
159 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
160 $tcflags ip_flags frag action continue
161 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
162 $tcflags ip_flags firstfrag action continue
163 tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
164 $tcflags ip_flags nofirstfrag action continue
165 tc filter add dev $h2 ingress protocol ip pref 4 handle 104 flower \
166 $tcflags ip_flags nofrag action drop
168 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
169 -t ip "frag=0" -q
171 tc_check_packets "dev $h2 ingress" 101 1
172 check_fail $? "Matched on wrong frag filter (nofrag)"
174 tc_check_packets "dev $h2 ingress" 102 1
175 check_fail $? "Matched on wrong firstfrag filter (nofrag)"
177 tc_check_packets "dev $h2 ingress" 103 1
178 check_err $? "Did not match on nofirstfrag filter (nofrag) "
180 tc_check_packets "dev $h2 ingress" 104 1
181 check_err $? "Did not match on nofrag filter (nofrag)"
183 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
184 -t ip "frag=0,mf" -q
186 tc_check_packets "dev $h2 ingress" 101 1
187 check_err $? "Did not match on frag filter (1stfrag)"
189 tc_check_packets "dev $h2 ingress" 102 1
190 check_err $? "Did not match fistfrag filter (1stfrag)"
192 tc_check_packets "dev $h2 ingress" 103 1
193 check_err $? "Matched on wrong nofirstfrag filter (1stfrag)"
195 tc_check_packets "dev $h2 ingress" 104 1
196 check_err $? "Match on wrong nofrag filter (1stfrag)"
198 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
199 -t ip "frag=256,mf" -q
200 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
201 -t ip "frag=256" -q
203 tc_check_packets "dev $h2 ingress" 101 3
204 check_err $? "Did not match on frag filter (no1stfrag)"
206 tc_check_packets "dev $h2 ingress" 102 1
207 check_err $? "Matched on wrong firstfrag filter (no1stfrag)"
209 tc_check_packets "dev $h2 ingress" 103 3
210 check_err $? "Did not match on nofirstfrag filter (no1stfrag)"
212 tc_check_packets "dev $h2 ingress" 104 1
213 check_err $? "Matched on nofrag filter (no1stfrag)"
215 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
216 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
217 tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
218 tc filter del dev $h2 ingress protocol ip pref 4 handle 104 flower
220 log_test "ip_flags match ($tcflags)"
223 match_pcp_test()
225 RET=0
227 vlan_create $h2 85 v$h2 192.0.2.11/24
229 tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
230 flower vlan_prio 6 $tcflags dst_mac $h2mac action drop
231 tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
232 flower vlan_prio 7 $tcflags dst_mac $h2mac action drop
234 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 7:85 -t ip -q
235 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
237 tc_check_packets "dev $h2 ingress" 101 0
238 check_err $? "Matched on specified PCP when should not"
240 tc_check_packets "dev $h2 ingress" 102 1
241 check_err $? "Did not match on specified PCP"
243 tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
244 tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
246 vlan_destroy $h2 85
248 log_test "PCP match ($tcflags)"
251 match_vlan_test()
253 RET=0
255 vlan_create $h2 85 v$h2 192.0.2.11/24
256 vlan_create $h2 75 v$h2 192.0.2.10/24
258 tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
259 flower vlan_id 75 $tcflags action drop
260 tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
261 flower vlan_id 85 $tcflags action drop
263 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
265 tc_check_packets "dev $h2 ingress" 101 0
266 check_err $? "Matched on specified VLAN when should not"
268 tc_check_packets "dev $h2 ingress" 102 1
269 check_err $? "Did not match on specified VLAN"
271 tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
272 tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
274 vlan_destroy $h2 75
275 vlan_destroy $h2 85
277 log_test "VLAN match ($tcflags)"
280 match_ip_tos_test()
282 RET=0
284 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
285 $tcflags dst_ip 192.0.2.2 ip_tos 0x20 action drop
286 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
287 $tcflags dst_ip 192.0.2.2 ip_tos 0x18 action drop
289 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
290 -t ip tos=18 -q
292 tc_check_packets "dev $h2 ingress" 101 1
293 check_fail $? "Matched on a wrong filter (0x18)"
295 tc_check_packets "dev $h2 ingress" 102 1
296 check_err $? "Did not match on correct filter (0x18)"
298 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
299 -t ip tos=20 -q
301 tc_check_packets "dev $h2 ingress" 102 2
302 check_fail $? "Matched on a wrong filter (0x20)"
304 tc_check_packets "dev $h2 ingress" 101 1
305 check_err $? "Did not match on correct filter (0x20)"
307 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
308 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
310 log_test "ip_tos match ($tcflags)"
313 match_indev_test()
315 RET=0
317 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
318 $tcflags indev $h1 dst_mac $h2mac action drop
319 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
320 $tcflags indev $h2 dst_mac $h2mac action drop
322 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
323 -t ip -q
325 tc_check_packets "dev $h2 ingress" 101 1
326 check_fail $? "Matched on a wrong filter"
328 tc_check_packets "dev $h2 ingress" 102 1
329 check_err $? "Did not match on correct filter"
331 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
332 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
334 log_test "indev match ($tcflags)"
337 setup_prepare()
339 h1=${NETIFS[p1]}
340 h2=${NETIFS[p2]}
341 h1mac=$(mac_get $h1)
342 h2mac=$(mac_get $h2)
344 vrf_prepare
346 h1_create
347 h2_create
350 cleanup()
352 pre_cleanup
354 h2_destroy
355 h1_destroy
357 vrf_cleanup
360 trap cleanup EXIT
362 setup_prepare
363 setup_wait
365 tests_run
367 tc_offload_check
368 if [[ $? -ne 0 ]]; then
369 log_info "Could not test offloaded functionality"
370 else
371 tcflags="skip_sw"
372 tests_run
375 exit $EXIT_STATUS