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"
14 simple_if_init
$h1 192.0.2.1/24 198.51.100.1/24
19 simple_if_fini
$h1 192.0.2.1/24 198.51.100.1/24
24 simple_if_init
$h2 192.0.2.2/24 198.51.100.2/24
25 tc qdisc add dev
$h2 clsact
30 tc qdisc del dev
$h2 clsact
31 simple_if_fini
$h2 192.0.2.2/24 198.51.100.2/24
36 local dummy_mac
=de
:ad
:be
:ef
:aa
:aa
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 \
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)"
62 local dummy_mac
=de
:ad
:be
:ef
:aa
:aa
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 \
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)"
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 \
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 \
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)"
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 \
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 \
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
()
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 \
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 \
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 \
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)"
253 if [[ $?
-ne 0 ]]; then
254 log_info
"Could not test offloaded functionality"