staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / rtnetlink.sh
blob5c39e5f6a48005135b5385bf9862778365c6f1c3
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # Test various interface configuration scenarios. Observe that configurations
5 # deemed valid by mlxsw succeed, invalid configurations fail and that no traces
6 # are produced. To prevent the test from passing in case traces are produced,
7 # the user can set the 'kernel.panic_on_warn' and 'kernel.panic_on_oops'
8 # sysctls in its environment.
10 lib_dir=$(dirname $0)/../../../net/forwarding
12 ALL_TESTS="
13 rif_set_addr_test
14 rif_vrf_set_addr_test
15 rif_inherit_bridge_addr_test
16 rif_non_inherit_bridge_addr_test
17 vlan_interface_deletion_test
18 bridge_deletion_test
19 bridge_vlan_flags_test
20 vlan_1_test
21 lag_bridge_upper_test
22 duplicate_vlans_test
23 vlan_rif_refcount_test
24 subport_rif_refcount_test
25 vlan_dev_deletion_test
26 lag_unlink_slaves_test
27 lag_dev_deletion_test
28 vlan_interface_uppers_test
29 bridge_extern_learn_test
30 neigh_offload_test
31 nexthop_offload_test
32 devlink_reload_test
34 NUM_NETIFS=2
35 source $lib_dir/lib.sh
36 source $lib_dir/devlink_lib.sh
38 setup_prepare()
40 swp1=${NETIFS[p1]}
41 swp2=${NETIFS[p2]}
43 ip link set dev $swp1 up
44 ip link set dev $swp2 up
47 cleanup()
49 pre_cleanup
51 ip link set dev $swp2 down
52 ip link set dev $swp1 down
55 rif_set_addr_test()
57 local swp1_mac=$(mac_get $swp1)
58 local swp2_mac=$(mac_get $swp2)
60 RET=0
62 # $swp1 and $swp2 likely got their IPv6 local addresses already, but
63 # here we need to test the transition to RIF.
64 ip addr flush dev $swp1
65 ip addr flush dev $swp2
66 sleep .1
68 ip addr add dev $swp1 192.0.2.1/28
69 check_err $?
71 ip link set dev $swp1 addr 00:11:22:33:44:55
72 check_err $?
74 # IP address enablement should be rejected if the MAC address prefix
75 # doesn't match other RIFs.
76 ip addr add dev $swp2 192.0.2.2/28 &>/dev/null
77 check_fail $? "IP address addition passed for a device with a wrong MAC"
78 ip addr add dev $swp2 192.0.2.2/28 2>&1 >/dev/null \
79 | grep -q mlxsw_spectrum
80 check_err $? "no extack for IP address addition"
82 ip link set dev $swp2 addr 00:11:22:33:44:66
83 check_err $?
84 ip addr add dev $swp2 192.0.2.2/28 &>/dev/null
85 check_err $?
87 # Change of MAC address of a RIF should be forbidden if the new MAC
88 # doesn't share the prefix with other MAC addresses.
89 ip link set dev $swp2 addr 00:11:22:33:00:66 &>/dev/null
90 check_fail $? "change of MAC address passed for a wrong MAC"
91 ip link set dev $swp2 addr 00:11:22:33:00:66 2>&1 >/dev/null \
92 | grep -q mlxsw_spectrum
93 check_err $? "no extack for MAC address change"
95 log_test "RIF - bad MAC change"
97 ip addr del dev $swp2 192.0.2.2/28
98 ip addr del dev $swp1 192.0.2.1/28
100 ip link set dev $swp2 addr $swp2_mac
101 ip link set dev $swp1 addr $swp1_mac
104 rif_vrf_set_addr_test()
106 # Test that it is possible to set an IP address on a VRF upper despite
107 # its random MAC address.
108 RET=0
110 ip link add name vrf-test type vrf table 10
111 ip link set dev $swp1 master vrf-test
113 ip -4 address add 192.0.2.1/24 dev vrf-test
114 check_err $? "failed to set IPv4 address on VRF"
115 ip -6 address add 2001:db8:1::1/64 dev vrf-test
116 check_err $? "failed to set IPv6 address on VRF"
118 log_test "RIF - setting IP address on VRF"
120 ip link del dev vrf-test
123 rif_inherit_bridge_addr_test()
125 RET=0
127 # Create first RIF
128 ip addr add dev $swp1 192.0.2.1/28
129 check_err $?
131 # Create a FID RIF
132 ip link add name br1 up type bridge vlan_filtering 0
133 ip link set dev $swp2 master br1
134 ip addr add dev br1 192.0.2.17/28
135 check_err $?
137 # Prepare a device with a low MAC address
138 ip link add name d up type dummy
139 ip link set dev d addr 00:11:22:33:44:55
141 # Attach the device to br1. That prompts bridge address change, which
142 # should be vetoed, thus preventing the attachment.
143 ip link set dev d master br1 &>/dev/null
144 check_fail $? "Device with low MAC was permitted to attach a bridge with RIF"
145 ip link set dev d master br1 2>&1 >/dev/null \
146 | grep -q mlxsw_spectrum
147 check_err $? "no extack for bridge attach rejection"
149 ip link set dev $swp2 addr 00:11:22:33:44:55 &>/dev/null
150 check_fail $? "Changing swp2's MAC address permitted"
151 ip link set dev $swp2 addr 00:11:22:33:44:55 2>&1 >/dev/null \
152 | grep -q mlxsw_spectrum
153 check_err $? "no extack for bridge port MAC address change rejection"
155 log_test "RIF - attach port with bad MAC to bridge"
157 ip link del dev d
158 ip link del dev br1
159 ip addr del dev $swp1 192.0.2.1/28
162 rif_non_inherit_bridge_addr_test()
164 local swp2_mac=$(mac_get $swp2)
166 RET=0
168 # Create first RIF
169 ip addr add dev $swp1 192.0.2.1/28
170 check_err $?
172 # Create a FID RIF
173 ip link add name br1 up type bridge vlan_filtering 0
174 ip link set dev br1 addr $swp2_mac
175 ip link set dev $swp2 master br1
176 ip addr add dev br1 192.0.2.17/28
177 check_err $?
179 # Prepare a device with a low MAC address
180 ip link add name d up type dummy
181 ip link set dev d addr 00:11:22:33:44:55
183 # Attach the device to br1. Since the bridge address was set, it should
184 # work.
185 ip link set dev d master br1 &>/dev/null
186 check_err $? "Could not attach a device with low MAC to a bridge with RIF"
188 # Port MAC address change should be allowed for a bridge with set MAC.
189 ip link set dev $swp2 addr 00:11:22:33:44:55
190 check_err $? "Changing swp2's MAC address not permitted"
192 log_test "RIF - attach port with bad MAC to bridge with set MAC"
194 ip link set dev $swp2 addr $swp2_mac
195 ip link del dev d
196 ip link del dev br1
197 ip addr del dev $swp1 192.0.2.1/28
200 vlan_interface_deletion_test()
202 # Test that when a VLAN interface is deleted, its associated router
203 # interface (RIF) is correctly deleted and not leaked. See commit
204 # c360867ec46a ("mlxsw: spectrum: Delete RIF when VLAN device is
205 # removed") for more details
206 RET=0
208 ip link add name br0 type bridge vlan_filtering 1
209 ip link set dev $swp1 master br0
211 ip link add link br0 name br0.10 type vlan id 10
212 ip -6 address add 2001:db8:1::1/64 dev br0.10
213 ip link del dev br0.10
215 # If we leaked the previous RIF, then this should produce a trace
216 ip link add link br0 name br0.20 type vlan id 20
217 ip -6 address add 2001:db8:1::1/64 dev br0.20
218 ip link del dev br0.20
220 log_test "vlan interface deletion"
222 ip link del dev br0
225 bridge_deletion_test()
227 # Test that when a bridge with VLAN interfaces is deleted, we correctly
228 # delete the associated RIFs. See commit 602b74eda813 ("mlxsw:
229 # spectrum_switchdev: Do not leak RIFs when removing bridge") for more
230 # details
231 RET=0
233 ip link add name br0 type bridge vlan_filtering 1
234 ip link set dev $swp1 master br0
235 ip -6 address add 2001:db8::1/64 dev br0
237 ip link add link br0 name br0.10 type vlan id 10
238 ip -6 address add 2001:db8:1::1/64 dev br0.10
240 ip link add link br0 name br0.20 type vlan id 20
241 ip -6 address add 2001:db8:2::1/64 dev br0.20
243 ip link del dev br0
245 # If we leaked previous RIFs, then this should produce a trace
246 ip -6 address add 2001:db8:1::1/64 dev $swp1
247 ip -6 address del 2001:db8:1::1/64 dev $swp1
249 log_test "bridge deletion"
252 bridge_vlan_flags_test()
254 # Test that when bridge VLAN flags are toggled, we do not take
255 # unnecessary references on related structs. See commit 9e25826ffc94
256 # ("mlxsw: spectrum_switchdev: Fix port_vlan refcounting") for more
257 # details
258 RET=0
260 ip link add name br0 type bridge vlan_filtering 1
261 ip link set dev $swp1 master br0
263 bridge vlan add vid 10 dev $swp1 pvid untagged
264 bridge vlan add vid 10 dev $swp1 untagged
265 bridge vlan add vid 10 dev $swp1 pvid
266 bridge vlan add vid 10 dev $swp1
267 ip link del dev br0
269 # If we did not handle references correctly, then this should produce a
270 # trace
271 devlink dev reload "$DEVLINK_DEV"
273 # Allow netdevices to be re-created following the reload
274 sleep 20
276 log_test "bridge vlan flags"
279 vlan_1_test()
281 # Test that VLAN 1 can be configured over mlxsw ports. In the past it
282 # was used internally for untagged traffic. See commit 47bf9df2e820
283 # ("mlxsw: spectrum: Forbid creation of VLAN 1 over port/LAG") for more
284 # details
285 RET=0
287 ip link add link $swp1 name $swp1.1 type vlan id 1
288 check_err $? "did not manage to create vlan 1 when should"
290 log_test "vlan 1"
292 ip link del dev $swp1.1
295 lag_bridge_upper_test()
297 # Test that ports cannot be enslaved to LAG devices that have uppers
298 # and that failure is handled gracefully. See commit b3529af6bb0d
299 # ("spectrum: Reference count VLAN entries") for more details
300 RET=0
302 ip link add name bond1 type bond mode 802.3ad
304 ip link add name br0 type bridge vlan_filtering 1
305 ip link set dev bond1 master br0
307 ip link set dev $swp1 down
308 ip link set dev $swp1 master bond1 &> /dev/null
309 check_fail $? "managed to enslave port to lag when should not"
311 # This might generate a trace, if we did not handle the failure
312 # correctly
313 ip -6 address add 2001:db8:1::1/64 dev $swp1
314 ip -6 address del 2001:db8:1::1/64 dev $swp1
316 log_test "lag with bridge upper"
318 ip link del dev br0
319 ip link del dev bond1
322 duplicate_vlans_test()
324 # Test that on a given port a VLAN is only used once. Either as VLAN
325 # in a VLAN-aware bridge or as a VLAN device
326 RET=0
328 ip link add name br0 type bridge vlan_filtering 1
329 ip link set dev $swp1 master br0
330 bridge vlan add vid 10 dev $swp1
332 ip link add link $swp1 name $swp1.10 type vlan id 10 &> /dev/null
333 check_fail $? "managed to create vlan device when should not"
335 bridge vlan del vid 10 dev $swp1
336 ip link add link $swp1 name $swp1.10 type vlan id 10
337 check_err $? "did not manage to create vlan device when should"
338 bridge vlan add vid 10 dev $swp1 &> /dev/null
339 check_fail $? "managed to add bridge vlan when should not"
341 log_test "duplicate vlans"
343 ip link del dev $swp1.10
344 ip link del dev br0
347 vlan_rif_refcount_test()
349 # Test that RIFs representing VLAN interfaces are not affected from
350 # ports member in the VLAN. We use the offload indication on routes
351 # configured on the RIF to understand if it was created / destroyed
352 RET=0
354 ip link add name br0 type bridge vlan_filtering 1
355 ip link set dev $swp1 master br0
357 ip link set dev $swp1 up
358 ip link set dev br0 up
360 ip link add link br0 name br0.10 up type vlan id 10
361 ip -6 address add 2001:db8:1::1/64 dev br0.10
363 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 | grep -q offload
364 check_err $? "vlan rif was not created before adding port to vlan"
366 bridge vlan add vid 10 dev $swp1
367 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 | grep -q offload
368 check_err $? "vlan rif was destroyed after adding port to vlan"
370 bridge vlan del vid 10 dev $swp1
371 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 | grep -q offload
372 check_err $? "vlan rif was destroyed after removing port from vlan"
374 ip link set dev $swp1 nomaster
375 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10 | grep -q offload
376 check_fail $? "vlan rif was not destroyed after unlinking port from bridge"
378 log_test "vlan rif refcount"
380 ip link del dev br0.10
381 ip link set dev $swp1 down
382 ip link del dev br0
385 subport_rif_refcount_test()
387 # Test that RIFs representing upper devices of physical ports are
388 # reference counted correctly and destroyed when should. We use the
389 # offload indication on routes configured on the RIF to understand if
390 # it was created / destroyed
391 RET=0
393 ip link add name bond1 type bond mode 802.3ad
394 ip link set dev $swp1 down
395 ip link set dev $swp2 down
396 ip link set dev $swp1 master bond1
397 ip link set dev $swp2 master bond1
399 ip link set dev bond1 up
400 ip link add link bond1 name bond1.10 up type vlan id 10
401 ip -6 address add 2001:db8:1::1/64 dev bond1
402 ip -6 address add 2001:db8:2::1/64 dev bond1.10
404 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 | grep -q offload
405 check_err $? "subport rif was not created on lag device"
406 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10 | grep -q offload
407 check_err $? "subport rif was not created on vlan device"
409 ip link set dev $swp1 nomaster
410 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 | grep -q offload
411 check_err $? "subport rif of lag device was destroyed when should not"
412 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10 | grep -q offload
413 check_err $? "subport rif of vlan device was destroyed when should not"
415 ip link set dev $swp2 nomaster
416 ip -6 route get fibmatch 2001:db8:1::2 dev bond1 | grep -q offload
417 check_fail $? "subport rif of lag device was not destroyed when should"
418 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10 | grep -q offload
419 check_fail $? "subport rif of vlan device was not destroyed when should"
421 log_test "subport rif refcount"
423 ip link del dev bond1.10
424 ip link del dev bond1
427 vlan_dev_deletion_test()
429 # Test that VLAN devices are correctly deleted / unlinked when enslaved
430 # to bridge
431 RET=0
433 ip link add name br10 type bridge
434 ip link add name br20 type bridge
435 ip link add name br30 type bridge
436 ip link add link $swp1 name $swp1.10 type vlan id 10
437 ip link add link $swp1 name $swp1.20 type vlan id 20
438 ip link add link $swp1 name $swp1.30 type vlan id 30
439 ip link set dev $swp1.10 master br10
440 ip link set dev $swp1.20 master br20
441 ip link set dev $swp1.30 master br30
443 # If we did not handle the situation correctly, then these operations
444 # might produce a trace
445 ip link set dev $swp1.30 nomaster
446 ip link del dev $swp1.20
447 # Deletion via ioctl uses different code paths from netlink
448 vconfig rem $swp1.10 &> /dev/null
450 log_test "vlan device deletion"
452 ip link del dev $swp1.30
453 ip link del dev br30
454 ip link del dev br20
455 ip link del dev br10
458 lag_create()
460 ip link add name bond1 type bond mode 802.3ad
461 ip link set dev $swp1 down
462 ip link set dev $swp2 down
463 ip link set dev $swp1 master bond1
464 ip link set dev $swp2 master bond1
466 ip link add link bond1 name bond1.10 type vlan id 10
467 ip link add link bond1 name bond1.20 type vlan id 20
469 ip link add name br0 type bridge vlan_filtering 1
470 ip link set dev bond1 master br0
472 ip link add name br10 type bridge
473 ip link set dev bond1.10 master br10
475 ip link add name br20 type bridge
476 ip link set dev bond1.20 master br20
479 lag_unlink_slaves_test()
481 # Test that ports are correctly unlinked from their LAG master, when
482 # the LAG and its VLAN uppers are enslaved to bridges
483 RET=0
485 lag_create
487 ip link set dev $swp1 nomaster
488 check_err $? "lag slave $swp1 was not unlinked from master"
489 ip link set dev $swp2 nomaster
490 check_err $? "lag slave $swp2 was not unlinked from master"
492 # Try to configure corresponding VLANs as router interfaces
493 ip -6 address add 2001:db8:1::1/64 dev $swp1
494 check_err $? "failed to configure ip address on $swp1"
496 ip link add link $swp1 name $swp1.10 type vlan id 10
497 ip -6 address add 2001:db8:10::1/64 dev $swp1.10
498 check_err $? "failed to configure ip address on $swp1.10"
500 ip link add link $swp1 name $swp1.20 type vlan id 20
501 ip -6 address add 2001:db8:20::1/64 dev $swp1.20
502 check_err $? "failed to configure ip address on $swp1.20"
504 log_test "lag slaves unlinking"
506 ip link del dev $swp1.20
507 ip link del dev $swp1.10
508 ip address flush dev $swp1
510 ip link del dev br20
511 ip link del dev br10
512 ip link del dev br0
513 ip link del dev bond1
516 lag_dev_deletion_test()
518 # Test that LAG device is correctly deleted, when the LAG and its VLAN
519 # uppers are enslaved to bridges
520 RET=0
522 lag_create
524 ip link del dev bond1
526 log_test "lag device deletion"
528 ip link del dev br20
529 ip link del dev br10
530 ip link del dev br0
533 vlan_interface_uppers_test()
535 # Test that uppers of a VLAN interface are correctly sanitized
536 RET=0
538 ip link add name br0 type bridge vlan_filtering 1
539 ip link set dev $swp1 master br0
541 ip link add link br0 name br0.10 type vlan id 10
542 ip link add link br0.10 name macvlan0 \
543 type macvlan mode private &> /dev/null
544 check_fail $? "managed to create a macvlan when should not"
546 ip -6 address add 2001:db8:1::1/64 dev br0.10
547 ip link add link br0.10 name macvlan0 type macvlan mode private
548 check_err $? "did not manage to create a macvlan when should"
550 ip link del dev macvlan0
552 ip link add name vrf-test type vrf table 10
553 ip link set dev br0.10 master vrf-test
554 check_err $? "did not manage to enslave vlan interface to vrf"
555 ip link del dev vrf-test
557 ip link add name br-test type bridge
558 ip link set dev br0.10 master br-test &> /dev/null
559 check_fail $? "managed to enslave vlan interface to bridge when should not"
560 ip link del dev br-test
562 log_test "vlan interface uppers"
564 ip link del dev br0
567 bridge_extern_learn_test()
569 # Test that externally learned entries added from user space are
570 # marked as offloaded
571 RET=0
573 ip link add name br0 type bridge
574 ip link set dev $swp1 master br0
576 bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn
578 bridge fdb show brport $swp1 | grep de:ad:be:ef:13:37 | grep -q offload
579 check_err $? "fdb entry not marked as offloaded when should"
581 log_test "externally learned fdb entry"
583 ip link del dev br0
586 neigh_offload_test()
588 # Test that IPv4 and IPv6 neighbour entries are marked as offloaded
589 RET=0
591 ip -4 address add 192.0.2.1/24 dev $swp1
592 ip -6 address add 2001:db8:1::1/64 dev $swp1
594 ip -4 neigh add 192.0.2.2 lladdr de:ad:be:ef:13:37 nud perm dev $swp1
595 ip -6 neigh add 2001:db8:1::2 lladdr de:ad:be:ef:13:37 nud perm \
596 dev $swp1
598 ip -4 neigh show dev $swp1 | grep 192.0.2.2 | grep -q offload
599 check_err $? "ipv4 neigh entry not marked as offloaded when should"
600 ip -6 neigh show dev $swp1 | grep 2001:db8:1::2 | grep -q offload
601 check_err $? "ipv6 neigh entry not marked as offloaded when should"
603 log_test "neighbour offload indication"
605 ip -6 neigh del 2001:db8:1::2 dev $swp1
606 ip -4 neigh del 192.0.2.2 dev $swp1
607 ip -6 address del 2001:db8:1::1/64 dev $swp1
608 ip -4 address del 192.0.2.1/24 dev $swp1
611 nexthop_offload_test()
613 # Test that IPv4 and IPv6 nexthops are marked as offloaded
614 RET=0
616 sysctl_set net.ipv6.conf.$swp2.keep_addr_on_down 1
617 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
618 simple_if_init $swp2 192.0.2.2/24 2001:db8:1::2/64
619 setup_wait
621 ip -4 route add 198.51.100.0/24 vrf v$swp1 \
622 nexthop via 192.0.2.2 dev $swp1
623 ip -6 route add 2001:db8:2::/64 vrf v$swp1 \
624 nexthop via 2001:db8:1::2 dev $swp1
626 ip -4 route show 198.51.100.0/24 vrf v$swp1 | grep -q offload
627 check_err $? "ipv4 nexthop not marked as offloaded when should"
628 ip -6 route show 2001:db8:2::/64 vrf v$swp1 | grep -q offload
629 check_err $? "ipv6 nexthop not marked as offloaded when should"
631 ip link set dev $swp2 down
632 sleep 1
634 ip -4 route show 198.51.100.0/24 vrf v$swp1 | grep -q offload
635 check_fail $? "ipv4 nexthop marked as offloaded when should not"
636 ip -6 route show 2001:db8:2::/64 vrf v$swp1 | grep -q offload
637 check_fail $? "ipv6 nexthop marked as offloaded when should not"
639 ip link set dev $swp2 up
640 setup_wait
642 ip -4 route show 198.51.100.0/24 vrf v$swp1 | grep -q offload
643 check_err $? "ipv4 nexthop not marked as offloaded after neigh add"
644 ip -6 route show 2001:db8:2::/64 vrf v$swp1 | grep -q offload
645 check_err $? "ipv6 nexthop not marked as offloaded after neigh add"
647 log_test "nexthop offload indication"
649 ip -6 route del 2001:db8:2::/64 vrf v$swp1
650 ip -4 route del 198.51.100.0/24 vrf v$swp1
652 simple_if_fini $swp2 192.0.2.2/24 2001:db8:1::2/64
653 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
654 sysctl_restore net.ipv6.conf.$swp2.keep_addr_on_down
657 devlink_reload_test()
659 # Test that after executing all the above configuration tests, a
660 # devlink reload can be performed without errors
661 RET=0
663 devlink dev reload "$DEVLINK_DEV"
664 check_err $? "devlink reload failed"
666 log_test "devlink reload - last test"
668 sleep 20
671 trap cleanup EXIT
673 setup_prepare
674 setup_wait
676 tests_run
678 exit $EXIT_STATUS