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 / vxlan_symmetric_ipv6.sh
blob904633427fd04606df1ee33fc11055bfd15e138b
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
5 # +--------------------------------+ +-----------------------------+
6 # | vrf-h1 | | vrf-h2 |
7 # | + $h1 | | + $h2 |
8 # | | 2001:db8:1::1/64 | | | 2001:db8:2::1/64 |
9 # | | default via 2001:db8:1::3 | | | default via 2001:db8:2::3 |
10 # +----|---------------------------+ +-|---------------------------+
11 # | |
12 # +----|------------------------------------------|---------------------------+
13 # | SW | | |
14 # | +--|------------------------------------------|-------------------------+ |
15 # | | + $swp1 br1 + $swp2 | |
16 # | | vid 10 pvid untagged vid 20 pvid untagged | |
17 # | | | |
18 # | | + vx10 + vx20 | |
19 # | | local 2001:db8:3::1 local 2001:db8:3::1 | |
20 # | | remote 2001:db8:3::2 remote 2001:db8:3::2 | |
21 # | | id 1010 id 1020 | |
22 # | | dstport 4789 dstport 4789 | |
23 # | | vid 10 pvid untagged vid 20 pvid untagged | |
24 # | | | |
25 # | | + vx4001 | |
26 # | | local 2001:db8:3::1 | |
27 # | | remote 2001:db8:3::2 | |
28 # | | id 104001 | |
29 # | | dstport 4789 | |
30 # | | vid 4001 pvid untagged | |
31 # | | | |
32 # | +-----------------------------------+-----------------------------------+ |
33 # | | |
34 # | +-----------------------------------|-----------------------------------+ |
35 # | | | | |
36 # | | +--------------------------------+--------------------------------+ | |
37 # | | | | | | |
38 # | | + vlan10 | vlan20 + | |
39 # | | | 2001:db8:1::2/64 | 2001:db8:2::2/64 | | |
40 # | | | | | | |
41 # | | + vlan10-v (macvlan) + vlan20-v (macvlan) + | |
42 # | | 2001:db8:1::3/64 vlan4001 2001:db8:2::3/64 | |
43 # | | 00:00:5e:00:01:01 00:00:5e:00:01:01 | |
44 # | | vrf-green | |
45 # | +-----------------------------------------------------------------------+ |
46 # | |
47 # | + $rp1 +lo |
48 # | | 2001:db8:4::1/64 2001:db8:3::1 |
49 # +----|----------------------------------------------------------------------+
50 # |
51 # +----|--------------------------------------------------------+
52 # | | vrf-spine |
53 # | + $rp2 |
54 # | 2001:db8:4::2/64 |
55 # | | (maybe) HW
56 # =============================================================================
57 # | | (likely) SW
58 # | |
59 # | + v1 (veth) |
60 # | | 2001:db8:5::2/64 |
61 # +----|--------------------------------------------------------+
62 # |
63 # +----|----------------------------------------------------------------------+
64 # | + v2 (veth) +lo NS1 (netns) |
65 # | 2001:db8:5::1/64 2001:db8:3::2/128 |
66 # | |
67 # | +-----------------------------------------------------------------------+ |
68 # | | vrf-green | |
69 # | | + vlan10-v (macvlan) vlan20-v (macvlan) + | |
70 # | | | 2001:db8:1::3/64 2001:db8:2::3/64 | | |
71 # | | | 00:00:5e:00:01:01 00:00:5e:00:01:01 | | |
72 # | | | vlan4001 | | |
73 # | | + vlan10 + vlan20 + | |
74 # | | | 2001:db8:1::3/64 | 2001:db8:2::3/64 | | |
75 # | | | | | | |
76 # | | +--------------------------------+--------------------------------+ | |
77 # | | | | |
78 # | +-----------------------------------|-----------------------------------+ |
79 # | | |
80 # | +-----------------------------------+-----------------------------------+ |
81 # | | | |
82 # | | + vx10 + vx20 | |
83 # | | local 2001:db8:3::2 local 2001:db8:3::2 | |
84 # | | remote 2001:db8:3::1 remote 2001:db8:3::1 | |
85 # | | id 1010 id 1020 | |
86 # | | dstport 4789 dstport 4789 | |
87 # | | vid 10 pvid untagged vid 20 pvid untagged | |
88 # | | | |
89 # | | + vx4001 | |
90 # | | local 2001:db8:3::2 | |
91 # | | remote 2001:db8:3::1 | |
92 # | | id 104001 | |
93 # | | dstport 4789 | |
94 # | | vid 4001 pvid untagged | |
95 # | | | |
96 # | | + w1 (veth) + w3 (veth) | |
97 # | | | vid 10 pvid untagged br1 | vid 20 pvid untagged | |
98 # | +--|------------------------------------------|-------------------------+ |
99 # | | | |
100 # | | | |
101 # | +--|----------------------+ +--|-------------------------+ |
102 # | | | vrf-h1 | | | vrf-h2 | |
103 # | | + w2 (veth) | | + w4 (veth) | |
104 # | | 2001:db8:1::4/64 | | 2001:db8:2::4/64 | |
105 # | | default via | | default via | |
106 # | | 2001:db8:1::3/64 | | 2001:db8:2::3/64 | |
107 # | +-------------------------+ +----------------------------+ |
108 # +---------------------------------------------------------------------------+
110 ALL_TESTS="
111 ping_ipv6
113 NUM_NETIFS=6
114 source lib.sh
116 hx_create()
118 local vrf_name=$1; shift
119 local if_name=$1; shift
120 local ip_addr=$1; shift
121 local gw_ip=$1; shift
123 vrf_create $vrf_name
124 ip link set dev $if_name master $vrf_name
125 ip link set dev $vrf_name up
126 ip link set dev $if_name up
128 ip address add $ip_addr/64 dev $if_name
129 ip neigh replace $gw_ip lladdr 00:00:5e:00:01:01 nud permanent \
130 dev $if_name
131 ip route add default vrf $vrf_name nexthop via $gw_ip
133 export -f hx_create
135 hx_destroy()
137 local vrf_name=$1; shift
138 local if_name=$1; shift
139 local ip_addr=$1; shift
140 local gw_ip=$1; shift
142 ip route del default vrf $vrf_name nexthop via $gw_ip
143 ip neigh del $gw_ip dev $if_name
144 ip address del $ip_addr/64 dev $if_name
146 ip link set dev $if_name down
147 vrf_destroy $vrf_name
150 h1_create()
152 hx_create "vrf-h1" $h1 2001:db8:1::1 2001:db8:1::3
155 h1_destroy()
157 hx_destroy "vrf-h1" $h1 2001:db8:1::1 2001:db8:1::3
160 h2_create()
162 hx_create "vrf-h2" $h2 2001:db8:2::1 2001:db8:2::3
165 h2_destroy()
167 hx_destroy "vrf-h2" $h2 2001:db8:2::1 2001:db8:2::3
170 switch_create()
172 ip link add name br1 type bridge vlan_filtering 1 vlan_default_pvid 0 \
173 mcast_snooping 0
174 # Make sure the bridge uses the MAC address of the local port and not
175 # that of the VxLAN's device.
176 ip link set dev br1 address $(mac_get $swp1)
177 ip link set dev br1 up
179 ip link set dev $rp1 up
180 ip address add dev $rp1 2001:db8:4::1/64
181 ip route add 2001:db8:3::2/128 nexthop via 2001:db8:4::2
183 ip link add name vx10 type vxlan id 1010 \
184 local 2001:db8:3::1 remote 2001:db8:3::2 dstport 4789 \
185 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl 100
186 ip link set dev vx10 up
188 ip link set dev vx10 master br1
189 bridge vlan add vid 10 dev vx10 pvid untagged
191 ip link add name vx20 type vxlan id 1020 \
192 local 2001:db8:3::1 remote 2001:db8:3::2 dstport 4789 \
193 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl 100
194 ip link set dev vx20 up
196 ip link set dev vx20 master br1
197 bridge vlan add vid 20 dev vx20 pvid untagged
199 ip link set dev $swp1 master br1
200 ip link set dev $swp1 up
202 ip link set dev $swp2 master br1
203 ip link set dev $swp2 up
205 ip link add name vx4001 type vxlan id 104001 \
206 local 2001:db8:3::1 dstport 4789 \
207 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl 100
208 ip link set dev vx4001 up
210 ip link set dev vx4001 master br1
211 bridge vlan add vid 4001 dev vx4001 pvid untagged
213 ip address add 2001:db8:3::1/128 dev lo
215 # Create SVIs
216 vrf_create "vrf-green"
217 ip link set dev vrf-green up
219 ip link add link br1 name vlan10 up master vrf-green type vlan id 10
220 ip address add 2001:db8:1::2/64 dev vlan10
221 ip link add link vlan10 name vlan10-v up master vrf-green \
222 address 00:00:5e:00:01:01 type macvlan mode private
223 ip address add 2001:db8:1::3/64 dev vlan10-v
225 ip link add link br1 name vlan20 up master vrf-green type vlan id 20
226 ip address add 2001:db8:2::2/64 dev vlan20
227 ip link add link vlan20 name vlan20-v up master vrf-green \
228 address 00:00:5e:00:01:01 type macvlan mode private
229 ip address add 2001:db8:2::3/64 dev vlan20-v
231 ip link add link br1 name vlan4001 up master vrf-green \
232 type vlan id 4001
234 bridge vlan add vid 10 dev br1 self
235 bridge vlan add vid 20 dev br1 self
236 bridge vlan add vid 4001 dev br1 self
238 bridge fdb add 00:00:5e:00:01:01 dev br1 self local vlan 10
239 bridge fdb add 00:00:5e:00:01:01 dev br1 self local vlan 20
241 bridge vlan add vid 10 dev $swp1 pvid untagged
242 bridge vlan add vid 20 dev $swp2 pvid untagged
245 switch_destroy()
247 bridge vlan del vid 20 dev br1 self
248 bridge vlan del vid 10 dev br1 self
250 bridge fdb del 00:00:5e:00:01:01 dev br1 self local vlan 20
251 bridge fdb del 00:00:5e:00:01:01 dev br1 self local vlan 10
253 bridge vlan del vid 4001 dev br1 self
254 ip link del dev vlan4001
256 ip link del dev vlan20
258 ip link del dev vlan10
260 vrf_destroy "vrf-green"
262 ip address del 2001:db8:3::1/128 dev lo
264 bridge vlan del vid 20 dev $swp2
265 ip link set dev $swp2 down
266 ip link set dev $swp2 nomaster
268 bridge vlan del vid 10 dev $swp1
269 ip link set dev $swp1 down
270 ip link set dev $swp1 nomaster
272 bridge vlan del vid 4001 dev vx4001
273 ip link set dev vx4001 nomaster
275 ip link set dev vx4001 down
276 ip link del dev vx4001
278 bridge vlan del vid 20 dev vx20
279 ip link set dev vx20 nomaster
281 ip link set dev vx20 down
282 ip link del dev vx20
284 bridge vlan del vid 10 dev vx10
285 ip link set dev vx10 nomaster
287 ip link set dev vx10 down
288 ip link del dev vx10
290 ip route del 2001:db8:3::2 nexthop via 2001:db8:4::2
291 ip address del dev $rp1 2001:db8:4::1/64
292 ip link set dev $rp1 down
294 ip link set dev br1 down
295 ip link del dev br1
298 spine_create()
300 vrf_create "vrf-spine"
301 ip link set dev $rp2 master vrf-spine
302 ip link set dev v1 master vrf-spine
303 ip link set dev vrf-spine up
304 ip link set dev $rp2 up
305 ip link set dev v1 up
307 ip address add 2001:db8:4::2/64 dev $rp2
308 ip address add 2001:db8:5::2/64 dev v1
310 ip route add 2001:db8:3::1/128 vrf vrf-spine nexthop via \
311 2001:db8:4::1
312 ip route add 2001:db8:3::2/128 vrf vrf-spine nexthop via \
313 2001:db8:5::1
316 spine_destroy()
318 ip route del 2001:db8:3::2/128 vrf vrf-spine nexthop via \
319 2001:db8:5::1
320 ip route del 2001:db8:3::1/128 vrf vrf-spine nexthop via \
321 2001:db8:4::1
323 ip address del 2001:db8:5::2/64 dev v1
324 ip address del 2001:db8:4::2/64 dev $rp2
326 ip link set dev v1 down
327 ip link set dev $rp2 down
328 vrf_destroy "vrf-spine"
331 ns_h1_create()
333 hx_create "vrf-h1" w2 2001:db8:1::4 2001:db8:1::3
335 export -f ns_h1_create
337 ns_h2_create()
339 hx_create "vrf-h2" w4 2001:db8:2::4 2001:db8:2::3
341 export -f ns_h2_create
343 ns_switch_create()
345 ip link add name br1 type bridge vlan_filtering 1 vlan_default_pvid 0 \
346 mcast_snooping 0
347 ip link set dev br1 up
349 ip link set dev v2 up
350 ip address add dev v2 2001:db8:5::1/64
351 ip route add 2001:db8:3::1 nexthop via 2001:db8:5::2
353 ip link add name vx10 type vxlan id 1010 \
354 local 2001:db8:3::2 remote 2001:db8:3::1 dstport 4789 \
355 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl 100
356 ip link set dev vx10 up
358 ip link set dev vx10 master br1
359 bridge vlan add vid 10 dev vx10 pvid untagged
361 ip link add name vx20 type vxlan id 1020 \
362 local 2001:db8:3::2 remote 2001:db8:3::1 dstport 4789 \
363 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl 100
364 ip link set dev vx20 up
366 ip link set dev vx20 master br1
367 bridge vlan add vid 20 dev vx20 pvid untagged
369 ip link add name vx4001 type vxlan id 104001 \
370 local 2001:db8:3::2 dstport 4789 \
371 nolearning udp6zerocsumrx udp6zerocsumtx tos inherit ttl 100
372 ip link set dev vx4001 up
374 ip link set dev vx4001 master br1
375 bridge vlan add vid 4001 dev vx4001 pvid untagged
377 ip link set dev w1 master br1
378 ip link set dev w1 up
379 bridge vlan add vid 10 dev w1 pvid untagged
381 ip link set dev w3 master br1
382 ip link set dev w3 up
383 bridge vlan add vid 20 dev w3 pvid untagged
385 ip address add 2001:db8:3::2/128 dev lo
387 # Create SVIs
388 vrf_create "vrf-green"
389 ip link set dev vrf-green up
391 ip link add link br1 name vlan10 up master vrf-green type vlan id 10
392 ip address add 2001:db8:1::3/64 dev vlan10
393 ip link add link vlan10 name vlan10-v up master vrf-green \
394 address 00:00:5e:00:01:01 type macvlan mode private
395 ip address add 2001:db8:1::3/64 dev vlan10-v
397 ip link add link br1 name vlan20 up master vrf-green type vlan id 20
398 ip address add 2001:db8:2::3/64 dev vlan20
399 ip link add link vlan20 name vlan20-v up master vrf-green \
400 address 00:00:5e:00:01:01 type macvlan mode private
401 ip address add 2001:db8:2::3/64 dev vlan20-v
403 ip link add link br1 name vlan4001 up master vrf-green \
404 type vlan id 4001
406 bridge vlan add vid 10 dev br1 self
407 bridge vlan add vid 20 dev br1 self
408 bridge vlan add vid 4001 dev br1 self
410 bridge fdb add 00:00:5e:00:01:01 dev br1 self local vlan 10
411 bridge fdb add 00:00:5e:00:01:01 dev br1 self local vlan 20
413 export -f ns_switch_create
415 ns_init()
417 ip link add name w1 type veth peer name w2
418 ip link add name w3 type veth peer name w4
420 ip link set dev lo up
422 ns_h1_create
423 ns_h2_create
424 ns_switch_create
426 export -f ns_init
428 ns1_create()
430 ip netns add ns1
431 ip link set dev v2 netns ns1
432 in_ns ns1 ns_init
435 ns1_destroy()
437 ip netns exec ns1 ip link set dev v2 netns 1
438 ip netns del ns1
441 __l2_vni_init()
443 local mac1=$1; shift
444 local mac2=$1; shift
445 local ip1=$1; shift
446 local ip2=$1; shift
447 local dst=$1; shift
449 bridge fdb add $mac1 dev vx10 self master extern_learn static \
450 dst $dst vlan 10
451 bridge fdb add $mac2 dev vx20 self master extern_learn static \
452 dst $dst vlan 20
454 ip neigh add $ip1 lladdr $mac1 nud noarp dev vlan10 \
455 extern_learn
456 ip neigh add $ip2 lladdr $mac2 nud noarp dev vlan20 \
457 extern_learn
459 export -f __l2_vni_init
461 l2_vni_init()
463 local h1_ns_mac=$(in_ns ns1 mac_get w2)
464 local h2_ns_mac=$(in_ns ns1 mac_get w4)
465 local h1_mac=$(mac_get $h1)
466 local h2_mac=$(mac_get $h2)
468 __l2_vni_init $h1_ns_mac $h2_ns_mac 2001:db8:1::4 2001:db8:2::4 \
469 2001:db8:3::2
470 in_ns ns1 __l2_vni_init $h1_mac $h2_mac 2001:db8:1::1 2001:db8:2::1 \
471 2001:db8:3::1
474 __l3_vni_init()
476 local mac=$1; shift
477 local vtep_ip=$1; shift
478 local host1_ip=$1; shift
479 local host2_ip=$1; shift
481 bridge fdb add $mac dev vx4001 self master extern_learn static \
482 dst $vtep_ip vlan 4001
484 ip neigh add $vtep_ip lladdr $mac nud noarp dev vlan4001 extern_learn
486 ip route add $host1_ip/128 vrf vrf-green nexthop via $vtep_ip \
487 dev vlan4001 onlink
488 ip route add $host2_ip/128 vrf vrf-green nexthop via $vtep_ip \
489 dev vlan4001 onlink
491 export -f __l3_vni_init
493 l3_vni_init()
495 local vlan4001_ns_mac=$(in_ns ns1 mac_get vlan4001)
496 local vlan4001_mac=$(mac_get vlan4001)
498 __l3_vni_init $vlan4001_ns_mac 2001:db8:3::2 2001:db8:1::4 \
499 2001:db8:2::4
500 in_ns ns1 __l3_vni_init $vlan4001_mac 2001:db8:3::1 2001:db8:1::1 \
501 2001:db8:2::1
504 setup_prepare()
506 h1=${NETIFS[p1]}
507 swp1=${NETIFS[p2]}
509 swp2=${NETIFS[p3]}
510 h2=${NETIFS[p4]}
512 rp1=${NETIFS[p5]}
513 rp2=${NETIFS[p6]}
515 vrf_prepare
516 forwarding_enable
518 h1_create
519 h2_create
520 switch_create
522 ip link add name v1 type veth peer name v2
523 spine_create
524 ns1_create
525 in_ns ns1 forwarding_enable
527 l2_vni_init
528 l3_vni_init
531 cleanup()
533 pre_cleanup
535 ns1_destroy
536 spine_destroy
537 ip link del dev v1
539 switch_destroy
540 h2_destroy
541 h1_destroy
543 forwarding_restore
544 vrf_cleanup
547 ping_ipv6()
549 ping6_test $h1 2001:db8:2::1 ": local->local vid 10->vid 20"
550 ping6_test $h1 2001:db8:1::4 ": local->remote vid 10->vid 10"
551 ping6_test $h2 2001:db8:2::4 ": local->remote vid 20->vid 20"
552 ping6_test $h1 2001:db8:2::4 ": local->remote vid 10->vid 20"
553 ping6_test $h2 2001:db8:1::4 ": local->remote vid 20->vid 10"
556 trap cleanup EXIT
558 setup_prepare
559 setup_wait
561 tests_run
563 exit $EXIT_STATUS