drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / local_termination.sh
blobc35548767756d0116f0e442cde657d93f20a71ae
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="standalone vlan_unaware_bridge vlan_aware_bridge test_vlan \
5 vlan_over_vlan_unaware_bridged_port vlan_over_vlan_aware_bridged_port \
6 vlan_over_vlan_unaware_bridge vlan_over_vlan_aware_bridge"
7 NUM_NETIFS=2
8 PING_COUNT=1
9 REQUIRE_MTOOLS=yes
10 REQUIRE_MZ=no
12 source lib.sh
14 H1_IPV4="192.0.2.1"
15 H2_IPV4="192.0.2.2"
16 H1_IPV6="2001:db8:1::1"
17 H2_IPV6="2001:db8:1::2"
19 BRIDGE_ADDR="00:00:de:ad:be:ee"
20 MACVLAN_ADDR="00:00:de:ad:be:ef"
21 UNKNOWN_UC_ADDR1="de:ad:be:ef:ee:03"
22 UNKNOWN_UC_ADDR2="de:ad:be:ef:ee:04"
23 UNKNOWN_UC_ADDR3="de:ad:be:ef:ee:05"
24 JOINED_IPV4_MC_ADDR="225.1.2.3"
25 UNKNOWN_IPV4_MC_ADDR1="225.1.2.4"
26 UNKNOWN_IPV4_MC_ADDR2="225.1.2.5"
27 UNKNOWN_IPV4_MC_ADDR3="225.1.2.6"
28 JOINED_IPV6_MC_ADDR="ff2e::0102:0304"
29 UNKNOWN_IPV6_MC_ADDR1="ff2e::0102:0305"
30 UNKNOWN_IPV6_MC_ADDR2="ff2e::0102:0306"
31 UNKNOWN_IPV6_MC_ADDR3="ff2e::0102:0307"
33 JOINED_MACV4_MC_ADDR="01:00:5e:01:02:03"
34 UNKNOWN_MACV4_MC_ADDR1="01:00:5e:01:02:04"
35 UNKNOWN_MACV4_MC_ADDR2="01:00:5e:01:02:05"
36 UNKNOWN_MACV4_MC_ADDR3="01:00:5e:01:02:06"
37 JOINED_MACV6_MC_ADDR="33:33:01:02:03:04"
38 UNKNOWN_MACV6_MC_ADDR1="33:33:01:02:03:05"
39 UNKNOWN_MACV6_MC_ADDR2="33:33:01:02:03:06"
40 UNKNOWN_MACV6_MC_ADDR3="33:33:01:02:03:07"
42 PTP_1588_L2_SYNC=" \
43 01:1b:19:00:00:00 00:00:de:ad:be:ef 88:f7 00 02 \
44 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00 \
45 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 00 00 \
46 00 00 00 00 00 00 00 00 00 00"
47 PTP_1588_L2_FOLLOW_UP=" \
48 01:1b:19:00:00:00 00:00:de:ad:be:ef 88:f7 08 02 \
49 00 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
50 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 02 00 \
51 00 00 66 83 c5 f1 17 97 ed f0"
52 PTP_1588_L2_PDELAY_REQ=" \
53 01:80:c2:00:00:0e 00:00:de:ad:be:ef 88:f7 02 02 \
54 00 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
55 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 06 05 7f \
56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
57 00 00 00 00"
58 PTP_1588_IPV4_SYNC=" \
59 01:00:5e:00:01:81 00:00:de:ad:be:ef 08:00 45 00 \
60 00 48 0a 9a 40 00 01 11 cb 88 c0 00 02 01 e0 00 \
61 01 81 01 3f 01 3f 00 34 a3 c8 00 02 00 2c 00 00 \
62 02 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \
63 63 ff fe cf 17 0e 00 01 00 00 00 00 00 00 00 00 \
64 00 00 00 00 00 00"
65 PTP_1588_IPV4_FOLLOW_UP="
66 01:00:5e:00:01:81 00:00:de:ad:be:ef 08:00 45 00 \
67 00 48 0a 9b 40 00 01 11 cb 87 c0 00 02 01 e0 00 \
68 01 81 01 40 01 40 00 34 a3 c8 08 02 00 2c 00 00 \
69 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \
70 63 ff fe cf 17 0e 00 01 00 00 02 00 00 00 66 83 \
71 c6 0f 1d 9a 61 87"
72 PTP_1588_IPV4_PDELAY_REQ=" \
73 01:00:5e:00:00:6b 00:00:de:ad:be:ef 08:00 45 00 \
74 00 52 35 a9 40 00 01 11 a1 85 c0 00 02 01 e0 00 \
75 00 6b 01 3f 01 3f 00 3e a2 bc 02 02 00 36 00 00 \
76 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \
77 63 ff fe cf 17 0e 00 01 00 01 05 7f 00 00 00 00 \
78 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
79 PTP_1588_IPV6_SYNC=" \
80 33:33:00:00:01:81 00:00:de:ad:be:ef 86:dd 60 06 \
81 7c 2f 00 36 11 01 20 01 0d b8 00 01 00 00 00 00 \
82 00 00 00 00 00 01 ff 0e 00 00 00 00 00 00 00 00 \
83 00 00 00 00 01 81 01 3f 01 3f 00 36 2e 92 00 02 \
84 00 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00 \
85 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 00 00 \
86 00 00 00 00 00 00 00 00 00 00 00 00"
87 PTP_1588_IPV6_FOLLOW_UP=" \
88 33:33:00:00:01:81 00:00:de:ad:be:ef 86:dd 60 0a \
89 00 bc 00 36 11 01 20 01 0d b8 00 01 00 00 00 00 \
90 00 00 00 00 00 01 ff 0e 00 00 00 00 00 00 00 00 \
91 00 00 00 00 01 81 01 40 01 40 00 36 2e 92 08 02 \
92 00 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
93 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 02 00 \
94 00 00 66 83 c6 2a 32 09 bd 74 00 00"
95 PTP_1588_IPV6_PDELAY_REQ=" \
96 33:33:00:00:00:6b 00:00:de:ad:be:ef 86:dd 60 0c \
97 5c fd 00 40 11 01 fe 80 00 00 00 00 00 00 3c 37 \
98 63 ff fe cf 17 0e ff 02 00 00 00 00 00 00 00 00 \
99 00 00 00 00 00 6b 01 3f 01 3f 00 40 b4 54 02 02 \
100 00 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
101 00 00 3e 37 63 ff fe cf 17 0e 00 01 00 01 05 7f \
102 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
103 00 00 00 00 00 00"
105 # Disable promisc to ensure we don't receive unknown MAC DA packets
106 export TCPDUMP_EXTRA_FLAGS="-pl"
108 h1=${NETIFS[p1]}
109 h2=${NETIFS[p2]}
111 send_raw()
113 local if_name=$1; shift
114 local pkt="$1"; shift
115 local smac=$(mac_get $if_name)
117 pkt="${pkt/00:00:de:ad:be:ef/$smac}"
119 $MZ -q $if_name "$pkt"
122 send_uc_ipv4()
124 local if_name=$1
125 local dmac=$2
127 ip neigh add $H2_IPV4 lladdr $dmac dev $if_name
128 ping_do $if_name $H2_IPV4
129 ip neigh del $H2_IPV4 dev $if_name
132 check_rcv()
134 local if_name=$1; shift
135 local type=$1; shift
136 local pattern=$1; shift
137 local should_receive=$1; shift
138 local test_name="$1"; shift
139 local should_fail=
141 [ $should_receive = true ] && should_fail=0 || should_fail=1
142 RET=0
144 tcpdump_show $if_name | grep -q "$pattern"
146 check_err_fail "$should_fail" "$?" "reception"
148 log_test "$test_name: $type"
151 mc_route_prepare()
153 local if_name=$1
154 local vrf_name=$(master_name_get $if_name)
156 ip route add 225.100.1.0/24 dev $if_name vrf $vrf_name
157 ip -6 route add ff2e::/64 dev $if_name vrf $vrf_name
160 mc_route_destroy()
162 local if_name=$1
163 local vrf_name=$(master_name_get $if_name)
165 ip route del 225.100.1.0/24 dev $if_name vrf $vrf_name
166 ip -6 route del ff2e::/64 dev $if_name vrf $vrf_name
169 run_test()
171 local send_if_name=$1; shift
172 local rcv_if_name=$1; shift
173 local skip_ptp=$1; shift
174 local no_unicast_flt=$1; shift
175 local test_name="$1"; shift
176 local smac=$(mac_get $send_if_name)
177 local rcv_dmac=$(mac_get $rcv_if_name)
178 local should_receive
180 tcpdump_start $rcv_if_name
182 mc_route_prepare $send_if_name
183 mc_route_prepare $rcv_if_name
185 send_uc_ipv4 $send_if_name $rcv_dmac
186 send_uc_ipv4 $send_if_name $MACVLAN_ADDR
187 send_uc_ipv4 $send_if_name $UNKNOWN_UC_ADDR1
189 ip link set dev $rcv_if_name promisc on
190 send_uc_ipv4 $send_if_name $UNKNOWN_UC_ADDR2
191 mc_send $send_if_name $UNKNOWN_IPV4_MC_ADDR2
192 mc_send $send_if_name $UNKNOWN_IPV6_MC_ADDR2
193 ip link set dev $rcv_if_name promisc off
195 mc_join $rcv_if_name $JOINED_IPV4_MC_ADDR
196 mc_send $send_if_name $JOINED_IPV4_MC_ADDR
197 mc_leave
199 mc_join $rcv_if_name $JOINED_IPV6_MC_ADDR
200 mc_send $send_if_name $JOINED_IPV6_MC_ADDR
201 mc_leave
203 mc_send $send_if_name $UNKNOWN_IPV4_MC_ADDR1
204 mc_send $send_if_name $UNKNOWN_IPV6_MC_ADDR1
206 ip link set dev $rcv_if_name allmulticast on
207 send_uc_ipv4 $send_if_name $UNKNOWN_UC_ADDR3
208 mc_send $send_if_name $UNKNOWN_IPV4_MC_ADDR3
209 mc_send $send_if_name $UNKNOWN_IPV6_MC_ADDR3
210 ip link set dev $rcv_if_name allmulticast off
212 mc_route_destroy $rcv_if_name
213 mc_route_destroy $send_if_name
215 if [ $skip_ptp = false ]; then
216 ip maddress add 01:1b:19:00:00:00 dev $rcv_if_name
217 send_raw $send_if_name "$PTP_1588_L2_SYNC"
218 send_raw $send_if_name "$PTP_1588_L2_FOLLOW_UP"
219 ip maddress del 01:1b:19:00:00:00 dev $rcv_if_name
221 ip maddress add 01:80:c2:00:00:0e dev $rcv_if_name
222 send_raw $send_if_name "$PTP_1588_L2_PDELAY_REQ"
223 ip maddress del 01:80:c2:00:00:0e dev $rcv_if_name
225 mc_join $rcv_if_name 224.0.1.129
226 send_raw $send_if_name "$PTP_1588_IPV4_SYNC"
227 send_raw $send_if_name "$PTP_1588_IPV4_FOLLOW_UP"
228 mc_leave
230 mc_join $rcv_if_name 224.0.0.107
231 send_raw $send_if_name "$PTP_1588_IPV4_PDELAY_REQ"
232 mc_leave
234 mc_join $rcv_if_name ff0e::181
235 send_raw $send_if_name "$PTP_1588_IPV6_SYNC"
236 send_raw $send_if_name "$PTP_1588_IPV6_FOLLOW_UP"
237 mc_leave
239 mc_join $rcv_if_name ff02::6b
240 send_raw $send_if_name "$PTP_1588_IPV6_PDELAY_REQ"
241 mc_leave
244 sleep 1
246 tcpdump_stop $rcv_if_name
248 check_rcv $rcv_if_name "Unicast IPv4 to primary MAC address" \
249 "$smac > $rcv_dmac, ethertype IPv4 (0x0800)" \
250 true "$test_name"
252 check_rcv $rcv_if_name "Unicast IPv4 to macvlan MAC address" \
253 "$smac > $MACVLAN_ADDR, ethertype IPv4 (0x0800)" \
254 true "$test_name"
256 [ $no_unicast_flt = true ] && should_receive=true || should_receive=false
257 check_rcv $rcv_if_name "Unicast IPv4 to unknown MAC address" \
258 "$smac > $UNKNOWN_UC_ADDR1, ethertype IPv4 (0x0800)" \
259 $should_receive "$test_name"
261 check_rcv $rcv_if_name "Unicast IPv4 to unknown MAC address, promisc" \
262 "$smac > $UNKNOWN_UC_ADDR2, ethertype IPv4 (0x0800)" \
263 true "$test_name"
265 [ $no_unicast_flt = true ] && should_receive=true || should_receive=false
266 check_rcv $rcv_if_name \
267 "Unicast IPv4 to unknown MAC address, allmulti" \
268 "$smac > $UNKNOWN_UC_ADDR3, ethertype IPv4 (0x0800)" \
269 $should_receive "$test_name"
271 check_rcv $rcv_if_name "Multicast IPv4 to joined group" \
272 "$smac > $JOINED_MACV4_MC_ADDR, ethertype IPv4 (0x0800)" \
273 true "$test_name"
275 xfail \
276 check_rcv $rcv_if_name \
277 "Multicast IPv4 to unknown group" \
278 "$smac > $UNKNOWN_MACV4_MC_ADDR1, ethertype IPv4 (0x0800)" \
279 false "$test_name"
281 check_rcv $rcv_if_name "Multicast IPv4 to unknown group, promisc" \
282 "$smac > $UNKNOWN_MACV4_MC_ADDR2, ethertype IPv4 (0x0800)" \
283 true "$test_name"
285 check_rcv $rcv_if_name "Multicast IPv4 to unknown group, allmulti" \
286 "$smac > $UNKNOWN_MACV4_MC_ADDR3, ethertype IPv4 (0x0800)" \
287 true "$test_name"
289 check_rcv $rcv_if_name "Multicast IPv6 to joined group" \
290 "$smac > $JOINED_MACV6_MC_ADDR, ethertype IPv6 (0x86dd)" \
291 true "$test_name"
293 xfail \
294 check_rcv $rcv_if_name "Multicast IPv6 to unknown group" \
295 "$smac > $UNKNOWN_MACV6_MC_ADDR1, ethertype IPv6 (0x86dd)" \
296 false "$test_name"
298 check_rcv $rcv_if_name "Multicast IPv6 to unknown group, promisc" \
299 "$smac > $UNKNOWN_MACV6_MC_ADDR2, ethertype IPv6 (0x86dd)" \
300 true "$test_name"
302 check_rcv $rcv_if_name "Multicast IPv6 to unknown group, allmulti" \
303 "$smac > $UNKNOWN_MACV6_MC_ADDR3, ethertype IPv6 (0x86dd)" \
304 true "$test_name"
306 if [ $skip_ptp = false ]; then
307 check_rcv $rcv_if_name "1588v2 over L2 transport, Sync" \
308 "ethertype PTP (0x88f7).* PTPv2.* msg type : sync msg" \
309 true "$test_name"
311 check_rcv $rcv_if_name "1588v2 over L2 transport, Follow-Up" \
312 "ethertype PTP (0x88f7).* PTPv2.* msg type : follow up msg" \
313 true "$test_name"
315 check_rcv $rcv_if_name "1588v2 over L2 transport, Peer Delay Request" \
316 "ethertype PTP (0x88f7).* PTPv2.* msg type : peer delay req msg" \
317 true "$test_name"
319 check_rcv $rcv_if_name "1588v2 over IPv4, Sync" \
320 "ethertype IPv4 (0x0800).* PTPv2.* msg type : sync msg" \
321 true "$test_name"
323 check_rcv $rcv_if_name "1588v2 over IPv4, Follow-Up" \
324 "ethertype IPv4 (0x0800).* PTPv2.* msg type : follow up msg" \
325 true "$test_name"
327 check_rcv $rcv_if_name "1588v2 over IPv4, Peer Delay Request" \
328 "ethertype IPv4 (0x0800).* PTPv2.* msg type : peer delay req msg" \
329 true "$test_name"
331 check_rcv $rcv_if_name "1588v2 over IPv6, Sync" \
332 "ethertype IPv6 (0x86dd).* PTPv2.* msg type : sync msg" \
333 true "$test_name"
335 check_rcv $rcv_if_name "1588v2 over IPv6, Follow-Up" \
336 "ethertype IPv6 (0x86dd).* PTPv2.* msg type : follow up msg" \
337 true "$test_name"
339 check_rcv $rcv_if_name "1588v2 over IPv6, Peer Delay Request" \
340 "ethertype IPv6 (0x86dd).* PTPv2.* msg type : peer delay req msg" \
341 true "$test_name"
344 tcpdump_cleanup $rcv_if_name
347 h1_create()
349 simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64
352 h1_destroy()
354 simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64
357 h2_create()
359 simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64
362 h2_destroy()
364 simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64
367 h1_vlan_create()
369 simple_if_init $h1
370 vlan_create $h1 100 v$h1 $H1_IPV4/24 $H1_IPV6/64
373 h1_vlan_destroy()
375 vlan_destroy $h1 100
376 simple_if_fini $h1
379 h2_vlan_create()
381 simple_if_init $h2
382 vlan_create $h2 100 v$h2 $H2_IPV4/24 $H2_IPV6/64
385 h2_vlan_destroy()
387 vlan_destroy $h2 100
388 simple_if_fini $h2
391 bridge_create()
393 local vlan_filtering=$1
395 ip link add br0 type bridge vlan_filtering $vlan_filtering
396 ip link set br0 address $BRIDGE_ADDR
397 ip link set br0 up
399 ip link set $h2 master br0
400 ip link set $h2 up
403 bridge_destroy()
405 ip link del br0
408 macvlan_create()
410 local lower=$1
412 ip link add link $lower name macvlan0 type macvlan mode private
413 ip link set macvlan0 address $MACVLAN_ADDR
414 ip link set macvlan0 up
417 macvlan_destroy()
419 ip link del macvlan0
422 standalone()
424 local no_unicast_flt=true
425 local skip_ptp=false
427 if [ $(has_unicast_flt $h2) = yes ]; then
428 no_unicast_flt=false
431 h1_create
432 h2_create
433 macvlan_create $h2
435 run_test $h1 $h2 $skip_ptp $no_unicast_flt "$h2"
437 macvlan_destroy
438 h2_destroy
439 h1_destroy
442 test_bridge()
444 local no_unicast_flt=true
445 local vlan_filtering=$1
446 local skip_ptp=true
448 h1_create
449 bridge_create $vlan_filtering
450 simple_if_init br0 $H2_IPV4/24 $H2_IPV6/64
451 macvlan_create br0
453 run_test $h1 br0 $skip_ptp $no_unicast_flt \
454 "vlan_filtering=$vlan_filtering bridge"
456 macvlan_destroy
457 simple_if_fini br0 $H2_IPV4/24 $H2_IPV6/64
458 bridge_destroy
459 h1_destroy
462 vlan_unaware_bridge()
464 test_bridge 0
467 vlan_aware_bridge()
469 test_bridge 1
472 test_vlan()
474 local no_unicast_flt=true
475 local skip_ptp=false
477 if [ $(has_unicast_flt $h2) = yes ]; then
478 no_unicast_flt=false
481 h1_vlan_create
482 h2_vlan_create
483 macvlan_create $h2.100
485 run_test $h1.100 $h2.100 $skip_ptp $no_unicast_flt "VLAN upper"
487 macvlan_destroy
488 h2_vlan_destroy
489 h1_vlan_destroy
492 vlan_over_bridged_port()
494 local no_unicast_flt=true
495 local vlan_filtering=$1
496 local skip_ptp=false
498 # br_manage_promisc() will not force a single vlan_filtering port to
499 # promiscuous mode, so we should still expect unicast filtering to take
500 # place if the device can do it.
501 if [ $(has_unicast_flt $h2) = yes ] && [ $vlan_filtering = 1 ]; then
502 no_unicast_flt=false
505 h1_vlan_create
506 h2_vlan_create
507 bridge_create $vlan_filtering
508 macvlan_create $h2.100
510 run_test $h1.100 $h2.100 $skip_ptp $no_unicast_flt \
511 "VLAN over vlan_filtering=$vlan_filtering bridged port"
513 macvlan_destroy
514 bridge_destroy
515 h2_vlan_destroy
516 h1_vlan_destroy
519 vlan_over_vlan_unaware_bridged_port()
521 vlan_over_bridged_port 0
524 vlan_over_vlan_aware_bridged_port()
526 vlan_over_bridged_port 1
529 vlan_over_bridge()
531 local no_unicast_flt=true
532 local vlan_filtering=$1
533 local skip_ptp=true
535 h1_vlan_create
536 bridge_create $vlan_filtering
537 simple_if_init br0
538 vlan_create br0 100 vbr0 $H2_IPV4/24 $H2_IPV6/64
539 macvlan_create br0.100
541 if [ $vlan_filtering = 1 ]; then
542 bridge vlan add dev $h2 vid 100 master
543 bridge vlan add dev br0 vid 100 self
546 run_test $h1.100 br0.100 $skip_ptp $no_unicast_flt \
547 "VLAN over vlan_filtering=$vlan_filtering bridge"
549 if [ $vlan_filtering = 1 ]; then
550 bridge vlan del dev br0 vid 100 self
551 bridge vlan del dev $h2 vid 100 master
554 macvlan_destroy
555 vlan_destroy br0 100
556 simple_if_fini br0
557 bridge_destroy
558 h1_vlan_destroy
561 vlan_over_vlan_unaware_bridge()
563 vlan_over_bridge 0
566 vlan_over_vlan_aware_bridge()
568 vlan_over_bridge 1
571 cleanup()
573 pre_cleanup
575 ip link set $h2 down
576 ip link set $h1 down
578 vrf_cleanup
581 setup_prepare()
583 vrf_prepare
584 # setup_wait() needs this
585 ip link set $h1 up
586 ip link set $h2 up
589 trap cleanup EXIT
591 setup_prepare
592 setup_wait
594 tests_run
596 exit $EXIT_STATUS