Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / tc_flower_l2_miss.sh
blobc2420bb72c128119f005de590e36952dc5960f36
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # +-----------------------+ +----------------------+
5 # | H1 (vrf) | | H2 (vrf) |
6 # | + $h1 | | $h2 + |
7 # | | 192.0.2.1/28 | | 192.0.2.2/28 | |
8 # | | 2001:db8:1::1/64 | | 2001:db8:1::2/64 | |
9 # +----|------------------+ +------------------|---+
10 # | |
11 # +----|-------------------------------------------------------------------|---+
12 # | SW | | |
13 # | +-|-------------------------------------------------------------------|-+ |
14 # | | + $swp1 BR $swp2 + | |
15 # | +-----------------------------------------------------------------------+ |
16 # +----------------------------------------------------------------------------+
18 ALL_TESTS="
19 test_l2_miss_unicast
20 test_l2_miss_multicast
21 test_l2_miss_ll_multicast
22 test_l2_miss_broadcast
25 NUM_NETIFS=4
26 source lib.sh
27 source tc_common.sh
29 h1_create()
31 simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
34 h1_destroy()
36 simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
39 h2_create()
41 simple_if_init $h2 192.0.2.2/28 2001:db8:1::2/64
44 h2_destroy()
46 simple_if_fini $h2 192.0.2.2/28 2001:db8:1::2/64
49 switch_create()
51 ip link add name br1 up type bridge
52 ip link set dev $swp1 master br1
53 ip link set dev $swp1 up
54 ip link set dev $swp2 master br1
55 ip link set dev $swp2 up
57 tc qdisc add dev $swp2 clsact
60 switch_destroy()
62 tc qdisc del dev $swp2 clsact
64 ip link set dev $swp2 down
65 ip link set dev $swp2 nomaster
66 ip link set dev $swp1 down
67 ip link set dev $swp1 nomaster
68 ip link del dev br1
71 test_l2_miss_unicast()
73 local dmac=00:01:02:03:04:05
74 local dip=192.0.2.2
75 local sip=192.0.2.1
77 RET=0
79 # Unknown unicast.
80 tc filter add dev $swp2 egress protocol ipv4 handle 101 pref 1 \
81 flower indev $swp1 l2_miss 1 dst_mac $dmac src_ip $sip \
82 dst_ip $dip action pass
83 # Known unicast.
84 tc filter add dev $swp2 egress protocol ipv4 handle 102 pref 1 \
85 flower indev $swp1 l2_miss 0 dst_mac $dmac src_ip $sip \
86 dst_ip $dip action pass
88 # Before adding FDB entry.
89 $MZ $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q
91 tc_check_packets "dev $swp2 egress" 101 1
92 check_err $? "Unknown unicast filter was not hit before adding FDB entry"
94 tc_check_packets "dev $swp2 egress" 102 0
95 check_err $? "Known unicast filter was hit before adding FDB entry"
97 # Adding FDB entry.
98 bridge fdb replace $dmac dev $swp2 master static
100 $MZ $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q
102 tc_check_packets "dev $swp2 egress" 101 1
103 check_err $? "Unknown unicast filter was hit after adding FDB entry"
105 tc_check_packets "dev $swp2 egress" 102 1
106 check_err $? "Known unicast filter was not hit after adding FDB entry"
108 # Deleting FDB entry.
109 bridge fdb del $dmac dev $swp2 master static
111 $MZ $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q
113 tc_check_packets "dev $swp2 egress" 101 2
114 check_err $? "Unknown unicast filter was not hit after deleting FDB entry"
116 tc_check_packets "dev $swp2 egress" 102 1
117 check_err $? "Known unicast filter was hit after deleting FDB entry"
119 tc filter del dev $swp2 egress protocol ipv4 pref 1 handle 102 flower
120 tc filter del dev $swp2 egress protocol ipv4 pref 1 handle 101 flower
122 log_test "L2 miss - Unicast"
125 test_l2_miss_multicast_common()
127 local proto=$1; shift
128 local sip=$1; shift
129 local dip=$1; shift
130 local dmac=$1; shift
131 local mode=$1; shift
132 local name=$1; shift
134 RET=0
136 # Unregistered multicast.
137 tc filter add dev $swp2 egress protocol $proto handle 101 pref 1 \
138 flower indev $swp1 l2_miss 1 src_ip $sip dst_ip $dip \
139 action pass
140 # Registered multicast.
141 tc filter add dev $swp2 egress protocol $proto handle 102 pref 1 \
142 flower indev $swp1 l2_miss 0 src_ip $sip dst_ip $dip \
143 action pass
145 # Before adding MDB entry.
146 $MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q
148 tc_check_packets "dev $swp2 egress" 101 1
149 check_err $? "Unregistered multicast filter was not hit before adding MDB entry"
151 tc_check_packets "dev $swp2 egress" 102 0
152 check_err $? "Registered multicast filter was hit before adding MDB entry"
154 # Adding MDB entry.
155 bridge mdb replace dev br1 port $swp2 grp $dip permanent
157 $MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q
159 tc_check_packets "dev $swp2 egress" 101 1
160 check_err $? "Unregistered multicast filter was hit after adding MDB entry"
162 tc_check_packets "dev $swp2 egress" 102 1
163 check_err $? "Registered multicast filter was not hit after adding MDB entry"
165 # Deleting MDB entry.
166 bridge mdb del dev br1 port $swp2 grp $dip
168 $MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q
170 tc_check_packets "dev $swp2 egress" 101 2
171 check_err $? "Unregistered multicast filter was not hit after deleting MDB entry"
173 tc_check_packets "dev $swp2 egress" 102 1
174 check_err $? "Registered multicast filter was hit after deleting MDB entry"
176 tc filter del dev $swp2 egress protocol $proto pref 1 handle 102 flower
177 tc filter del dev $swp2 egress protocol $proto pref 1 handle 101 flower
179 log_test "L2 miss - Multicast ($name)"
182 test_l2_miss_multicast_ipv4()
184 local proto="ipv4"
185 local sip=192.0.2.1
186 local dip=239.1.1.1
187 local dmac=01:00:5e:01:01:01
188 local mode="-4"
189 local name="IPv4"
191 test_l2_miss_multicast_common $proto $sip $dip $dmac $mode $name
194 test_l2_miss_multicast_ipv6()
196 local proto="ipv6"
197 local sip=2001:db8:1::1
198 local dip=ff0e::1
199 local dmac=33:33:00:00:00:01
200 local mode="-6"
201 local name="IPv6"
203 test_l2_miss_multicast_common $proto $sip $dip $dmac $mode $name
206 test_l2_miss_multicast()
208 # Configure $swp2 as a multicast router port so that it will forward
209 # both registered and unregistered multicast traffic.
210 bridge link set dev $swp2 mcast_router 2
212 # Set the Max Response Delay to 100 centiseconds (1 second) so that the
213 # bridge will start forwarding according to its MDB soon after a
214 # multicast querier is enabled.
215 ip link set dev br1 type bridge mcast_query_response_interval 100
217 # Forwarding according to MDB entries only takes place when the bridge
218 # detects that there is a valid querier in the network. Set the bridge
219 # as the querier and assign it a valid IPv6 link-local address to be
220 # used as the source address for MLD queries.
221 ip link set dev br1 type bridge mcast_querier 1
222 ip -6 address add fe80::1/64 nodad dev br1
223 sleep 10
225 test_l2_miss_multicast_ipv4
226 test_l2_miss_multicast_ipv6
228 ip -6 address del fe80::1/64 dev br1
229 ip link set dev br1 type bridge mcast_querier 0
230 ip link set dev br1 type bridge mcast_query_response_interval 1000
231 bridge link set dev $swp2 mcast_router 1
234 test_l2_miss_multicast_common2()
236 local name=$1; shift
237 local dmac=$1; shift
238 local dip=224.0.0.1
239 local sip=192.0.2.1
243 test_l2_miss_ll_multicast_common()
245 local proto=$1; shift
246 local dmac=$1; shift
247 local sip=$1; shift
248 local dip=$1; shift
249 local mode=$1; shift
250 local name=$1; shift
252 RET=0
254 tc filter add dev $swp2 egress protocol $proto handle 101 pref 1 \
255 flower indev $swp1 l2_miss 1 dst_mac $dmac src_ip $sip \
256 dst_ip $dip action pass
258 $MZ $mode $h1 -a own -b $dmac -t ip -A $sip -B $dip -c 1 -p 100 -q
260 tc_check_packets "dev $swp2 egress" 101 1
261 check_err $? "Filter was not hit"
263 tc filter del dev $swp2 egress protocol $proto pref 1 handle 101 flower
265 log_test "L2 miss - Link-local multicast ($name)"
268 test_l2_miss_ll_multicast_ipv4()
270 local proto=ipv4
271 local dmac=01:00:5e:00:00:01
272 local sip=192.0.2.1
273 local dip=224.0.0.1
274 local mode="-4"
275 local name="IPv4"
277 test_l2_miss_ll_multicast_common $proto $dmac $sip $dip $mode $name
280 test_l2_miss_ll_multicast_ipv6()
282 local proto=ipv6
283 local dmac=33:33:00:00:00:01
284 local sip=2001:db8:1::1
285 local dip=ff02::1
286 local mode="-6"
287 local name="IPv6"
289 test_l2_miss_ll_multicast_common $proto $dmac $sip $dip $mode $name
292 test_l2_miss_ll_multicast()
294 test_l2_miss_ll_multicast_ipv4
295 test_l2_miss_ll_multicast_ipv6
298 test_l2_miss_broadcast()
300 local dmac=ff:ff:ff:ff:ff:ff
301 local smac=00:01:02:03:04:05
303 RET=0
305 tc filter add dev $swp2 egress protocol all handle 101 pref 1 \
306 flower l2_miss 1 dst_mac $dmac src_mac $smac \
307 action pass
308 tc filter add dev $swp2 egress protocol all handle 102 pref 1 \
309 flower l2_miss 0 dst_mac $dmac src_mac $smac \
310 action pass
312 $MZ $h1 -a $smac -b $dmac -c 1 -p 100 -q
314 tc_check_packets "dev $swp2 egress" 101 0
315 check_err $? "L2 miss filter was hit when should not"
317 tc_check_packets "dev $swp2 egress" 102 1
318 check_err $? "L2 no miss filter was not hit when should"
320 tc filter del dev $swp2 egress protocol all pref 1 handle 102 flower
321 tc filter del dev $swp2 egress protocol all pref 1 handle 101 flower
323 log_test "L2 miss - Broadcast"
326 setup_prepare()
328 h1=${NETIFS[p1]}
329 swp1=${NETIFS[p2]}
331 swp2=${NETIFS[p3]}
332 h2=${NETIFS[p4]}
334 vrf_prepare
335 h1_create
336 h2_create
337 switch_create
340 cleanup()
342 pre_cleanup
344 switch_destroy
345 h2_destroy
346 h1_destroy
347 vrf_cleanup
350 trap cleanup EXIT
352 setup_prepare
353 setup_wait
355 tests_run
357 exit $EXIT_STATUS