Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / tc_flower.sh
blob20d1077e5a3de9cb8ad9186d866837421b84d518
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"
6 NUM_NETIFS=2
7 source tc_common.sh
8 source lib.sh
10 tcflags="skip_hw"
12 h1_create()
14 simple_if_init $h1 192.0.2.1/24 198.51.100.1/24
17 h1_destroy()
19 simple_if_fini $h1 192.0.2.1/24 198.51.100.1/24
22 h2_create()
24 simple_if_init $h2 192.0.2.2/24 198.51.100.2/24
25 tc qdisc add dev $h2 clsact
28 h2_destroy()
30 tc qdisc del dev $h2 clsact
31 simple_if_fini $h2 192.0.2.2/24 198.51.100.2/24
34 match_dst_mac_test()
36 local dummy_mac=de:ad:be:ef:aa:aa
38 RET=0
40 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
41 $tcflags dst_mac $dummy_mac action drop
42 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
43 $tcflags dst_mac $h2mac action drop
45 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
46 -t ip -q
48 tc_check_packets "dev $h2 ingress" 101 1
49 check_fail $? "Matched on a wrong filter"
51 tc_check_packets "dev $h2 ingress" 102 1
52 check_err $? "Did not match on correct filter"
54 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
55 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
57 log_test "dst_mac match ($tcflags)"
60 match_src_mac_test()
62 local dummy_mac=de:ad:be:ef:aa:aa
64 RET=0
66 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
67 $tcflags src_mac $dummy_mac action drop
68 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
69 $tcflags src_mac $h1mac action drop
71 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
72 -t ip -q
74 tc_check_packets "dev $h2 ingress" 101 1
75 check_fail $? "Matched on a wrong filter"
77 tc_check_packets "dev $h2 ingress" 102 1
78 check_err $? "Did not match on correct filter"
80 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
81 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
83 log_test "src_mac match ($tcflags)"
86 match_dst_ip_test()
88 RET=0
90 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
91 $tcflags dst_ip 198.51.100.2 action drop
92 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
93 $tcflags dst_ip 192.0.2.2 action drop
94 tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
95 $tcflags dst_ip 192.0.2.0/24 action drop
97 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
98 -t ip -q
100 tc_check_packets "dev $h2 ingress" 101 1
101 check_fail $? "Matched on a wrong filter"
103 tc_check_packets "dev $h2 ingress" 102 1
104 check_err $? "Did not match on correct filter"
106 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
108 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
109 -t ip -q
111 tc_check_packets "dev $h2 ingress" 103 1
112 check_err $? "Did not match on correct filter with mask"
114 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
115 tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
117 log_test "dst_ip match ($tcflags)"
120 match_src_ip_test()
122 RET=0
124 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
125 $tcflags src_ip 198.51.100.1 action drop
126 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
127 $tcflags src_ip 192.0.2.1 action drop
128 tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
129 $tcflags src_ip 192.0.2.0/24 action drop
131 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
132 -t ip -q
134 tc_check_packets "dev $h2 ingress" 101 1
135 check_fail $? "Matched on a wrong filter"
137 tc_check_packets "dev $h2 ingress" 102 1
138 check_err $? "Did not match on correct filter"
140 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
142 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
143 -t ip -q
145 tc_check_packets "dev $h2 ingress" 103 1
146 check_err $? "Did not match on correct filter with mask"
148 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
149 tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
151 log_test "src_ip match ($tcflags)"
154 match_ip_flags_test()
156 RET=0
158 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
159 $tcflags ip_flags frag action continue
160 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
161 $tcflags ip_flags firstfrag action continue
162 tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
163 $tcflags ip_flags nofirstfrag action continue
164 tc filter add dev $h2 ingress protocol ip pref 4 handle 104 flower \
165 $tcflags ip_flags nofrag action drop
167 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
168 -t ip "frag=0" -q
170 tc_check_packets "dev $h2 ingress" 101 1
171 check_fail $? "Matched on wrong frag filter (nofrag)"
173 tc_check_packets "dev $h2 ingress" 102 1
174 check_fail $? "Matched on wrong firstfrag filter (nofrag)"
176 tc_check_packets "dev $h2 ingress" 103 1
177 check_err $? "Did not match on nofirstfrag filter (nofrag) "
179 tc_check_packets "dev $h2 ingress" 104 1
180 check_err $? "Did not match on nofrag filter (nofrag)"
182 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
183 -t ip "frag=0,mf" -q
185 tc_check_packets "dev $h2 ingress" 101 1
186 check_err $? "Did not match on frag filter (1stfrag)"
188 tc_check_packets "dev $h2 ingress" 102 1
189 check_err $? "Did not match fistfrag filter (1stfrag)"
191 tc_check_packets "dev $h2 ingress" 103 1
192 check_err $? "Matched on wrong nofirstfrag filter (1stfrag)"
194 tc_check_packets "dev $h2 ingress" 104 1
195 check_err $? "Match on wrong nofrag filter (1stfrag)"
197 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
198 -t ip "frag=256,mf" -q
199 $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
200 -t ip "frag=256" -q
202 tc_check_packets "dev $h2 ingress" 101 3
203 check_err $? "Did not match on frag filter (no1stfrag)"
205 tc_check_packets "dev $h2 ingress" 102 1
206 check_err $? "Matched on wrong firstfrag filter (no1stfrag)"
208 tc_check_packets "dev $h2 ingress" 103 3
209 check_err $? "Did not match on nofirstfrag filter (no1stfrag)"
211 tc_check_packets "dev $h2 ingress" 104 1
212 check_err $? "Matched on nofrag filter (no1stfrag)"
214 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
215 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
216 tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
217 tc filter del dev $h2 ingress protocol ip pref 4 handle 104 flower
219 log_test "ip_flags match ($tcflags)"
222 setup_prepare()
224 h1=${NETIFS[p1]}
225 h2=${NETIFS[p2]}
226 h1mac=$(mac_get $h1)
227 h2mac=$(mac_get $h2)
229 vrf_prepare
231 h1_create
232 h2_create
235 cleanup()
237 pre_cleanup
239 h2_destroy
240 h1_destroy
242 vrf_cleanup
245 trap cleanup EXIT
247 setup_prepare
248 setup_wait
250 tests_run
252 tc_offload_check
253 if [[ $? -ne 0 ]]; then
254 log_info "Could not test offloaded functionality"
255 else
256 tcflags="skip_sw"
257 tests_run
260 exit $EXIT_STATUS