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"
15 simple_if_init
$h1 192.0.2.1/24 198.51.100.1/24
20 simple_if_fini
$h1 192.0.2.1/24 198.51.100.1/24
25 simple_if_init
$h2 192.0.2.2/24 198.51.100.2/24
26 tc qdisc add dev
$h2 clsact
31 tc qdisc del dev
$h2 clsact
32 simple_if_fini
$h2 192.0.2.2/24 198.51.100.2/24
37 local dummy_mac
=de
:ad
:be
:ef
:aa
:aa
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 \
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)"
63 local dummy_mac
=de
:ad
:be
:ef
:aa
:aa
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 \
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)"
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 \
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 \
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)"
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 \
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 \
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
()
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 \
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 \
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 \
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)"
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
248 log_test
"PCP match ($tcflags)"
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
277 log_test
"VLAN match ($tcflags)"
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 \
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 \
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)"
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 \
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)"
368 if [[ $?
-ne 0 ]]; then
369 log_info
"Could not test offloaded functionality"