WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / rtnetlink.sh
blobed346da5d3cb7fc9707ef5bbe2b1bf6f34d62565
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 subport_rif_lag_join_test
26 vlan_dev_deletion_test
27 lag_unlink_slaves_test
28 lag_dev_deletion_test
29 vlan_interface_uppers_test
30 bridge_extern_learn_test
31 neigh_offload_test
32 nexthop_offload_test
33 nexthop_obj_invalid_test
34 nexthop_obj_offload_test
35 nexthop_obj_group_offload_test
36 nexthop_obj_blackhole_offload_test
37 nexthop_obj_route_offload_test
38 devlink_reload_test
40 NUM_NETIFS=2
41 : ${TIMEOUT:=20000} # ms
42 source $lib_dir/lib.sh
43 source $lib_dir/devlink_lib.sh
45 setup_prepare()
47 swp1=${NETIFS[p1]}
48 swp2=${NETIFS[p2]}
50 ip link set dev $swp1 up
51 ip link set dev $swp2 up
54 cleanup()
56 pre_cleanup
58 ip link set dev $swp2 down
59 ip link set dev $swp1 down
62 rif_set_addr_test()
64 local swp1_mac=$(mac_get $swp1)
65 local swp2_mac=$(mac_get $swp2)
67 RET=0
69 # $swp1 and $swp2 likely got their IPv6 local addresses already, but
70 # here we need to test the transition to RIF.
71 ip addr flush dev $swp1
72 ip addr flush dev $swp2
73 sleep .1
75 ip addr add dev $swp1 192.0.2.1/28
76 check_err $?
78 ip link set dev $swp1 addr 00:11:22:33:44:55
79 check_err $?
81 # IP address enablement should be rejected if the MAC address prefix
82 # doesn't match other RIFs.
83 ip addr add dev $swp2 192.0.2.2/28 &>/dev/null
84 check_fail $? "IP address addition passed for a device with a wrong MAC"
85 ip addr add dev $swp2 192.0.2.2/28 2>&1 >/dev/null \
86 | grep -q mlxsw_spectrum
87 check_err $? "no extack for IP address addition"
89 ip link set dev $swp2 addr 00:11:22:33:44:66
90 check_err $?
91 ip addr add dev $swp2 192.0.2.2/28 &>/dev/null
92 check_err $?
94 # Change of MAC address of a RIF should be forbidden if the new MAC
95 # doesn't share the prefix with other MAC addresses.
96 ip link set dev $swp2 addr 00:11:22:33:00:66 &>/dev/null
97 check_fail $? "change of MAC address passed for a wrong MAC"
98 ip link set dev $swp2 addr 00:11:22:33:00:66 2>&1 >/dev/null \
99 | grep -q mlxsw_spectrum
100 check_err $? "no extack for MAC address change"
102 log_test "RIF - bad MAC change"
104 ip addr del dev $swp2 192.0.2.2/28
105 ip addr del dev $swp1 192.0.2.1/28
107 ip link set dev $swp2 addr $swp2_mac
108 ip link set dev $swp1 addr $swp1_mac
111 rif_vrf_set_addr_test()
113 # Test that it is possible to set an IP address on a VRF upper despite
114 # its random MAC address.
115 RET=0
117 ip link add name vrf-test type vrf table 10
118 ip link set dev $swp1 master vrf-test
120 ip -4 address add 192.0.2.1/24 dev vrf-test
121 check_err $? "failed to set IPv4 address on VRF"
122 ip -6 address add 2001:db8:1::1/64 dev vrf-test
123 check_err $? "failed to set IPv6 address on VRF"
125 log_test "RIF - setting IP address on VRF"
127 ip link del dev vrf-test
130 rif_inherit_bridge_addr_test()
132 RET=0
134 # Create first RIF
135 ip addr add dev $swp1 192.0.2.1/28
136 check_err $?
138 # Create a FID RIF
139 ip link add name br1 up type bridge vlan_filtering 0
140 ip link set dev $swp2 master br1
141 ip addr add dev br1 192.0.2.17/28
142 check_err $?
144 # Prepare a device with a low MAC address
145 ip link add name d up type dummy
146 ip link set dev d addr 00:11:22:33:44:55
148 # Attach the device to br1. That prompts bridge address change, which
149 # should be vetoed, thus preventing the attachment.
150 ip link set dev d master br1 &>/dev/null
151 check_fail $? "Device with low MAC was permitted to attach a bridge with RIF"
152 ip link set dev d master br1 2>&1 >/dev/null \
153 | grep -q mlxsw_spectrum
154 check_err $? "no extack for bridge attach rejection"
156 ip link set dev $swp2 addr 00:11:22:33:44:55 &>/dev/null
157 check_fail $? "Changing swp2's MAC address permitted"
158 ip link set dev $swp2 addr 00:11:22:33:44:55 2>&1 >/dev/null \
159 | grep -q mlxsw_spectrum
160 check_err $? "no extack for bridge port MAC address change rejection"
162 log_test "RIF - attach port with bad MAC to bridge"
164 ip link del dev d
165 ip link del dev br1
166 ip addr del dev $swp1 192.0.2.1/28
169 rif_non_inherit_bridge_addr_test()
171 local swp2_mac=$(mac_get $swp2)
173 RET=0
175 # Create first RIF
176 ip addr add dev $swp1 192.0.2.1/28
177 check_err $?
179 # Create a FID RIF
180 ip link add name br1 up type bridge vlan_filtering 0
181 ip link set dev br1 addr $swp2_mac
182 ip link set dev $swp2 master br1
183 ip addr add dev br1 192.0.2.17/28
184 check_err $?
186 # Prepare a device with a low MAC address
187 ip link add name d up type dummy
188 ip link set dev d addr 00:11:22:33:44:55
190 # Attach the device to br1. Since the bridge address was set, it should
191 # work.
192 ip link set dev d master br1 &>/dev/null
193 check_err $? "Could not attach a device with low MAC to a bridge with RIF"
195 # Port MAC address change should be allowed for a bridge with set MAC.
196 ip link set dev $swp2 addr 00:11:22:33:44:55
197 check_err $? "Changing swp2's MAC address not permitted"
199 log_test "RIF - attach port with bad MAC to bridge with set MAC"
201 ip link set dev $swp2 addr $swp2_mac
202 ip link del dev d
203 ip link del dev br1
204 ip addr del dev $swp1 192.0.2.1/28
207 vlan_interface_deletion_test()
209 # Test that when a VLAN interface is deleted, its associated router
210 # interface (RIF) is correctly deleted and not leaked. See commit
211 # c360867ec46a ("mlxsw: spectrum: Delete RIF when VLAN device is
212 # removed") for more details
213 RET=0
215 ip link add name br0 type bridge vlan_filtering 1
216 ip link set dev $swp1 master br0
218 ip link add link br0 name br0.10 type vlan id 10
219 ip -6 address add 2001:db8:1::1/64 dev br0.10
220 ip link del dev br0.10
222 # If we leaked the previous RIF, then this should produce a trace
223 ip link add link br0 name br0.20 type vlan id 20
224 ip -6 address add 2001:db8:1::1/64 dev br0.20
225 ip link del dev br0.20
227 log_test "vlan interface deletion"
229 ip link del dev br0
232 bridge_deletion_test()
234 # Test that when a bridge with VLAN interfaces is deleted, we correctly
235 # delete the associated RIFs. See commit 602b74eda813 ("mlxsw:
236 # spectrum_switchdev: Do not leak RIFs when removing bridge") for more
237 # details
238 RET=0
240 ip link add name br0 type bridge vlan_filtering 1
241 ip link set dev $swp1 master br0
242 ip -6 address add 2001:db8::1/64 dev br0
244 ip link add link br0 name br0.10 type vlan id 10
245 ip -6 address add 2001:db8:1::1/64 dev br0.10
247 ip link add link br0 name br0.20 type vlan id 20
248 ip -6 address add 2001:db8:2::1/64 dev br0.20
250 ip link del dev br0
252 # If we leaked previous RIFs, then this should produce a trace
253 ip -6 address add 2001:db8:1::1/64 dev $swp1
254 ip -6 address del 2001:db8:1::1/64 dev $swp1
256 log_test "bridge deletion"
259 bridge_vlan_flags_test()
261 # Test that when bridge VLAN flags are toggled, we do not take
262 # unnecessary references on related structs. See commit 9e25826ffc94
263 # ("mlxsw: spectrum_switchdev: Fix port_vlan refcounting") for more
264 # details
265 RET=0
267 ip link add name br0 type bridge vlan_filtering 1
268 ip link set dev $swp1 master br0
270 bridge vlan add vid 10 dev $swp1 pvid untagged
271 bridge vlan add vid 10 dev $swp1 untagged
272 bridge vlan add vid 10 dev $swp1 pvid
273 bridge vlan add vid 10 dev $swp1
274 ip link del dev br0
276 # If we did not handle references correctly, then this should produce a
277 # trace
278 devlink dev reload "$DEVLINK_DEV"
280 # Allow netdevices to be re-created following the reload
281 sleep 20
283 log_test "bridge vlan flags"
286 vlan_1_test()
288 # Test that VLAN 1 can be configured over mlxsw ports. In the past it
289 # was used internally for untagged traffic. See commit 47bf9df2e820
290 # ("mlxsw: spectrum: Forbid creation of VLAN 1 over port/LAG") for more
291 # details
292 RET=0
294 ip link add link $swp1 name $swp1.1 type vlan id 1
295 check_err $? "did not manage to create vlan 1 when should"
297 log_test "vlan 1"
299 ip link del dev $swp1.1
302 lag_bridge_upper_test()
304 # Test that ports cannot be enslaved to LAG devices that have uppers
305 # and that failure is handled gracefully. See commit b3529af6bb0d
306 # ("spectrum: Reference count VLAN entries") for more details
307 RET=0
309 ip link add name bond1 type bond mode 802.3ad
311 ip link add name br0 type bridge vlan_filtering 1
312 ip link set dev bond1 master br0
314 ip link set dev $swp1 down
315 ip link set dev $swp1 master bond1 &> /dev/null
316 check_fail $? "managed to enslave port to lag when should not"
318 # This might generate a trace, if we did not handle the failure
319 # correctly
320 ip -6 address add 2001:db8:1::1/64 dev $swp1
321 ip -6 address del 2001:db8:1::1/64 dev $swp1
323 log_test "lag with bridge upper"
325 ip link del dev br0
326 ip link del dev bond1
329 duplicate_vlans_test()
331 # Test that on a given port a VLAN is only used once. Either as VLAN
332 # in a VLAN-aware bridge or as a VLAN device
333 RET=0
335 ip link add name br0 type bridge vlan_filtering 1
336 ip link set dev $swp1 master br0
337 bridge vlan add vid 10 dev $swp1
339 ip link add link $swp1 name $swp1.10 type vlan id 10 &> /dev/null
340 check_fail $? "managed to create vlan device when should not"
342 bridge vlan del vid 10 dev $swp1
343 ip link add link $swp1 name $swp1.10 type vlan id 10
344 check_err $? "did not manage to create vlan device when should"
345 bridge vlan add vid 10 dev $swp1 &> /dev/null
346 check_fail $? "managed to add bridge vlan when should not"
348 log_test "duplicate vlans"
350 ip link del dev $swp1.10
351 ip link del dev br0
354 vlan_rif_refcount_test()
356 # Test that RIFs representing VLAN interfaces are not affected from
357 # ports member in the VLAN. We use the offload indication on routes
358 # configured on the RIF to understand if it was created / destroyed
359 RET=0
361 ip link add name br0 type bridge vlan_filtering 1
362 ip link set dev $swp1 master br0
364 ip link set dev $swp1 up
365 ip link set dev br0 up
367 ip link add link br0 name br0.10 up type vlan id 10
368 ip -6 address add 2001:db8:1::1/64 dev br0.10
370 busywait "$TIMEOUT" wait_for_offload \
371 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
372 check_err $? "vlan rif was not created before adding port to vlan"
374 bridge vlan add vid 10 dev $swp1
375 busywait "$TIMEOUT" wait_for_offload \
376 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
377 check_err $? "vlan rif was destroyed after adding port to vlan"
379 bridge vlan del vid 10 dev $swp1
380 busywait "$TIMEOUT" wait_for_offload \
381 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
382 check_err $? "vlan rif was destroyed after removing port from vlan"
384 ip link set dev $swp1 nomaster
385 busywait "$TIMEOUT" not wait_for_offload \
386 ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
387 check_err $? "vlan rif was not destroyed after unlinking port from bridge"
389 log_test "vlan rif refcount"
391 ip link del dev br0.10
392 ip link set dev $swp1 down
393 ip link del dev br0
396 subport_rif_refcount_test()
398 # Test that RIFs representing upper devices of physical ports are
399 # reference counted correctly and destroyed when should. We use the
400 # offload indication on routes configured on the RIF to understand if
401 # it was created / destroyed
402 RET=0
404 ip link add name bond1 type bond mode 802.3ad
405 ip link set dev $swp1 down
406 ip link set dev $swp2 down
407 ip link set dev $swp1 master bond1
408 ip link set dev $swp2 master bond1
410 ip link set dev bond1 up
411 ip link add link bond1 name bond1.10 up type vlan id 10
412 ip -6 address add 2001:db8:1::1/64 dev bond1
413 ip -6 address add 2001:db8:2::1/64 dev bond1.10
415 busywait "$TIMEOUT" wait_for_offload \
416 ip -6 route get fibmatch 2001:db8:1::2 dev bond1
417 check_err $? "subport rif was not created on lag device"
418 busywait "$TIMEOUT" wait_for_offload \
419 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10
420 check_err $? "subport rif was not created on vlan device"
422 ip link set dev $swp1 nomaster
423 busywait "$TIMEOUT" wait_for_offload \
424 ip -6 route get fibmatch 2001:db8:1::2 dev bond1
425 check_err $? "subport rif of lag device was destroyed when should not"
426 busywait "$TIMEOUT" wait_for_offload \
427 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10
428 check_err $? "subport rif of vlan device was destroyed when should not"
430 ip link set dev $swp2 nomaster
431 busywait "$TIMEOUT" not wait_for_offload \
432 ip -6 route get fibmatch 2001:db8:1::2 dev bond1
433 check_err $? "subport rif of lag device was not destroyed when should"
434 busywait "$TIMEOUT" not wait_for_offload \
435 ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10
436 check_err $? "subport rif of vlan device was not destroyed when should"
438 log_test "subport rif refcount"
440 ip link del dev bond1.10
441 ip link del dev bond1
444 subport_rif_lag_join_test()
446 # Test that the reference count of a RIF configured for a LAG is
447 # incremented / decremented when ports join / leave the LAG. We use the
448 # offload indication on routes configured on the RIF to understand if
449 # it was created / destroyed
450 RET=0
452 ip link add name bond1 type bond mode 802.3ad
453 ip link set dev $swp1 down
454 ip link set dev $swp2 down
455 ip link set dev $swp1 master bond1
456 ip link set dev $swp2 master bond1
458 ip link set dev bond1 up
459 ip -6 address add 2001:db8:1::1/64 dev bond1
461 busywait "$TIMEOUT" wait_for_offload \
462 ip -6 route get fibmatch 2001:db8:1::2 dev bond1
463 check_err $? "subport rif was not created on lag device"
465 ip link set dev $swp1 nomaster
466 busywait "$TIMEOUT" wait_for_offload \
467 ip -6 route get fibmatch 2001:db8:1::2 dev bond1
468 check_err $? "subport rif of lag device was destroyed after removing one port"
470 ip link set dev $swp1 master bond1
471 ip link set dev $swp2 nomaster
472 busywait "$TIMEOUT" wait_for_offload \
473 ip -6 route get fibmatch 2001:db8:1::2 dev bond1
474 check_err $? "subport rif of lag device was destroyed after re-adding a port and removing another"
476 ip link set dev $swp1 nomaster
477 busywait "$TIMEOUT" not wait_for_offload \
478 ip -6 route get fibmatch 2001:db8:1::2 dev bond1
479 check_err $? "subport rif of lag device was not destroyed when should"
481 log_test "subport rif lag join"
483 ip link del dev bond1
486 vlan_dev_deletion_test()
488 # Test that VLAN devices are correctly deleted / unlinked when enslaved
489 # to bridge
490 RET=0
492 ip link add name br10 type bridge
493 ip link add name br20 type bridge
494 ip link add name br30 type bridge
495 ip link add link $swp1 name $swp1.10 type vlan id 10
496 ip link add link $swp1 name $swp1.20 type vlan id 20
497 ip link add link $swp1 name $swp1.30 type vlan id 30
498 ip link set dev $swp1.10 master br10
499 ip link set dev $swp1.20 master br20
500 ip link set dev $swp1.30 master br30
502 # If we did not handle the situation correctly, then these operations
503 # might produce a trace
504 ip link set dev $swp1.30 nomaster
505 ip link del dev $swp1.20
506 # Deletion via ioctl uses different code paths from netlink
507 vconfig rem $swp1.10 &> /dev/null
509 log_test "vlan device deletion"
511 ip link del dev $swp1.30
512 ip link del dev br30
513 ip link del dev br20
514 ip link del dev br10
517 lag_create()
519 ip link add name bond1 type bond mode 802.3ad
520 ip link set dev $swp1 down
521 ip link set dev $swp2 down
522 ip link set dev $swp1 master bond1
523 ip link set dev $swp2 master bond1
525 ip link add link bond1 name bond1.10 type vlan id 10
526 ip link add link bond1 name bond1.20 type vlan id 20
528 ip link add name br0 type bridge vlan_filtering 1
529 ip link set dev bond1 master br0
531 ip link add name br10 type bridge
532 ip link set dev bond1.10 master br10
534 ip link add name br20 type bridge
535 ip link set dev bond1.20 master br20
538 lag_unlink_slaves_test()
540 # Test that ports are correctly unlinked from their LAG master, when
541 # the LAG and its VLAN uppers are enslaved to bridges
542 RET=0
544 lag_create
546 ip link set dev $swp1 nomaster
547 check_err $? "lag slave $swp1 was not unlinked from master"
548 ip link set dev $swp2 nomaster
549 check_err $? "lag slave $swp2 was not unlinked from master"
551 # Try to configure corresponding VLANs as router interfaces
552 ip -6 address add 2001:db8:1::1/64 dev $swp1
553 check_err $? "failed to configure ip address on $swp1"
555 ip link add link $swp1 name $swp1.10 type vlan id 10
556 ip -6 address add 2001:db8:10::1/64 dev $swp1.10
557 check_err $? "failed to configure ip address on $swp1.10"
559 ip link add link $swp1 name $swp1.20 type vlan id 20
560 ip -6 address add 2001:db8:20::1/64 dev $swp1.20
561 check_err $? "failed to configure ip address on $swp1.20"
563 log_test "lag slaves unlinking"
565 ip link del dev $swp1.20
566 ip link del dev $swp1.10
567 ip address flush dev $swp1
569 ip link del dev br20
570 ip link del dev br10
571 ip link del dev br0
572 ip link del dev bond1
575 lag_dev_deletion_test()
577 # Test that LAG device is correctly deleted, when the LAG and its VLAN
578 # uppers are enslaved to bridges
579 RET=0
581 lag_create
583 ip link del dev bond1
585 log_test "lag device deletion"
587 ip link del dev br20
588 ip link del dev br10
589 ip link del dev br0
592 vlan_interface_uppers_test()
594 # Test that uppers of a VLAN interface are correctly sanitized
595 RET=0
597 ip link add name br0 type bridge vlan_filtering 1
598 ip link set dev $swp1 master br0
600 ip link add link br0 name br0.10 type vlan id 10
601 ip link add link br0.10 name macvlan0 \
602 type macvlan mode private &> /dev/null
603 check_fail $? "managed to create a macvlan when should not"
605 ip -6 address add 2001:db8:1::1/64 dev br0.10
606 ip link add link br0.10 name macvlan0 type macvlan mode private
607 check_err $? "did not manage to create a macvlan when should"
609 ip link del dev macvlan0
611 ip link add name vrf-test type vrf table 10
612 ip link set dev br0.10 master vrf-test
613 check_err $? "did not manage to enslave vlan interface to vrf"
614 ip link del dev vrf-test
616 ip link add name br-test type bridge
617 ip link set dev br0.10 master br-test &> /dev/null
618 check_fail $? "managed to enslave vlan interface to bridge when should not"
619 ip link del dev br-test
621 log_test "vlan interface uppers"
623 ip link del dev br0
626 bridge_extern_learn_test()
628 # Test that externally learned entries added from user space are
629 # marked as offloaded
630 RET=0
632 ip link add name br0 type bridge
633 ip link set dev $swp1 master br0
635 bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn
637 busywait "$TIMEOUT" wait_for_offload \
638 bridge fdb show brport $swp1 de:ad:be:ef:13:37
639 check_err $? "fdb entry not marked as offloaded when should"
641 log_test "externally learned fdb entry"
643 ip link del dev br0
646 neigh_offload_test()
648 # Test that IPv4 and IPv6 neighbour entries are marked as offloaded
649 RET=0
651 ip -4 address add 192.0.2.1/24 dev $swp1
652 ip -6 address add 2001:db8:1::1/64 dev $swp1
654 ip -4 neigh add 192.0.2.2 lladdr de:ad:be:ef:13:37 nud perm dev $swp1
655 ip -6 neigh add 2001:db8:1::2 lladdr de:ad:be:ef:13:37 nud perm \
656 dev $swp1
658 busywait "$TIMEOUT" wait_for_offload \
659 ip -4 neigh show dev $swp1 192.0.2.2
660 check_err $? "ipv4 neigh entry not marked as offloaded when should"
661 busywait "$TIMEOUT" wait_for_offload \
662 ip -6 neigh show dev $swp1 2001:db8:1::2
663 check_err $? "ipv6 neigh entry not marked as offloaded when should"
665 log_test "neighbour offload indication"
667 ip -6 neigh del 2001:db8:1::2 dev $swp1
668 ip -4 neigh del 192.0.2.2 dev $swp1
669 ip -6 address del 2001:db8:1::1/64 dev $swp1
670 ip -4 address del 192.0.2.1/24 dev $swp1
673 nexthop_offload_test()
675 # Test that IPv4 and IPv6 nexthops are marked as offloaded
676 RET=0
678 sysctl_set net.ipv6.conf.$swp2.keep_addr_on_down 1
679 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
680 simple_if_init $swp2 192.0.2.2/24 2001:db8:1::2/64
681 setup_wait
683 ip -4 route add 198.51.100.0/24 vrf v$swp1 \
684 nexthop via 192.0.2.2 dev $swp1
685 ip -6 route add 2001:db8:2::/64 vrf v$swp1 \
686 nexthop via 2001:db8:1::2 dev $swp1
688 busywait "$TIMEOUT" wait_for_offload \
689 ip -4 route show 198.51.100.0/24 vrf v$swp1
690 check_err $? "ipv4 nexthop not marked as offloaded when should"
691 busywait "$TIMEOUT" wait_for_offload \
692 ip -6 route show 2001:db8:2::/64 vrf v$swp1
693 check_err $? "ipv6 nexthop not marked as offloaded when should"
695 ip link set dev $swp2 down
696 sleep 1
698 busywait "$TIMEOUT" not wait_for_offload \
699 ip -4 route show 198.51.100.0/24 vrf v$swp1
700 check_err $? "ipv4 nexthop marked as offloaded when should not"
701 busywait "$TIMEOUT" not wait_for_offload \
702 ip -6 route show 2001:db8:2::/64 vrf v$swp1
703 check_err $? "ipv6 nexthop marked as offloaded when should not"
705 ip link set dev $swp2 up
706 setup_wait
708 busywait "$TIMEOUT" wait_for_offload \
709 ip -4 route show 198.51.100.0/24 vrf v$swp1
710 check_err $? "ipv4 nexthop not marked as offloaded after neigh add"
711 busywait "$TIMEOUT" wait_for_offload \
712 ip -6 route show 2001:db8:2::/64 vrf v$swp1
713 check_err $? "ipv6 nexthop not marked as offloaded after neigh add"
715 log_test "nexthop offload indication"
717 ip -6 route del 2001:db8:2::/64 vrf v$swp1
718 ip -4 route del 198.51.100.0/24 vrf v$swp1
720 simple_if_fini $swp2 192.0.2.2/24 2001:db8:1::2/64
721 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
722 sysctl_restore net.ipv6.conf.$swp2.keep_addr_on_down
725 nexthop_obj_invalid_test()
727 # Test that invalid nexthop object configurations are rejected
728 RET=0
730 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
731 simple_if_init $swp2 192.0.2.2/24 2001:db8:1::2/64
732 setup_wait
734 ip nexthop add id 1 via 192.0.2.3 fdb
735 check_fail $? "managed to configure an FDB nexthop when should not"
737 ip nexthop add id 1 encap mpls 200/300 via 192.0.2.3 dev $swp1
738 check_fail $? "managed to configure a nexthop with MPLS encap when should not"
740 ip nexthop add id 1 dev $swp1
741 ip nexthop add id 2 dev $swp1
742 ip nexthop add id 10 group 1/2
743 check_fail $? "managed to configure a nexthop group with device-only nexthops when should not"
745 log_test "nexthop objects - invalid configurations"
747 ip nexthop del id 2
748 ip nexthop del id 1
750 simple_if_fini $swp2 192.0.2.2/24 2001:db8:1::2/64
751 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
754 nexthop_obj_offload_test()
756 # Test offload indication of nexthop objects
757 RET=0
759 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
760 simple_if_init $swp2
761 setup_wait
763 ip nexthop add id 1 via 192.0.2.2 dev $swp1
764 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \
765 dev $swp1
767 busywait "$TIMEOUT" wait_for_offload \
768 ip nexthop show id 1
769 check_err $? "nexthop not marked as offloaded when should"
771 ip neigh replace 192.0.2.2 nud failed dev $swp1
772 busywait "$TIMEOUT" not wait_for_offload \
773 ip nexthop show id 1
774 check_err $? "nexthop marked as offloaded after setting neigh to failed state"
776 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \
777 dev $swp1
778 busywait "$TIMEOUT" wait_for_offload \
779 ip nexthop show id 1
780 check_err $? "nexthop not marked as offloaded after neigh replace"
782 ip nexthop replace id 1 via 192.0.2.3 dev $swp1
783 busywait "$TIMEOUT" not wait_for_offload \
784 ip nexthop show id 1
785 check_err $? "nexthop marked as offloaded after replacing to use an invalid address"
787 ip nexthop replace id 1 via 192.0.2.2 dev $swp1
788 busywait "$TIMEOUT" wait_for_offload \
789 ip nexthop show id 1
790 check_err $? "nexthop not marked as offloaded after replacing to use a valid address"
792 log_test "nexthop objects offload indication"
794 ip neigh del 192.0.2.2 dev $swp1
795 ip nexthop del id 1
797 simple_if_fini $swp2
798 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
801 nexthop_obj_group_offload_test()
803 # Test offload indication of nexthop group objects
804 RET=0
806 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
807 simple_if_init $swp2
808 setup_wait
810 ip nexthop add id 1 via 192.0.2.2 dev $swp1
811 ip nexthop add id 2 via 2001:db8:1::2 dev $swp1
812 ip nexthop add id 10 group 1/2
813 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \
814 dev $swp1
815 ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud reachable \
816 dev $swp1
817 ip neigh replace 2001:db8:1::2 lladdr 00:11:22:33:44:55 nud reachable \
818 dev $swp1
820 busywait "$TIMEOUT" wait_for_offload \
821 ip nexthop show id 1
822 check_err $? "IPv4 nexthop not marked as offloaded when should"
823 busywait "$TIMEOUT" wait_for_offload \
824 ip nexthop show id 2
825 check_err $? "IPv6 nexthop not marked as offloaded when should"
826 busywait "$TIMEOUT" wait_for_offload \
827 ip nexthop show id 10
828 check_err $? "nexthop group not marked as offloaded when should"
830 # Invalidate nexthop id 1
831 ip neigh replace 192.0.2.2 nud failed dev $swp1
832 busywait "$TIMEOUT" not wait_for_offload \
833 ip nexthop show id 10
834 check_fail $? "nexthop group not marked as offloaded with one valid nexthop"
836 # Invalidate nexthop id 2
837 ip neigh replace 2001:db8:1::2 nud failed dev $swp1
838 busywait "$TIMEOUT" not wait_for_offload \
839 ip nexthop show id 10
840 check_err $? "nexthop group marked as offloaded when should not"
842 # Revalidate nexthop id 1
843 ip nexthop replace id 1 via 192.0.2.3 dev $swp1
844 busywait "$TIMEOUT" wait_for_offload \
845 ip nexthop show id 10
846 check_err $? "nexthop group not marked as offloaded after revalidating nexthop"
848 log_test "nexthop group objects offload indication"
850 ip neigh del 2001:db8:1::2 dev $swp1
851 ip neigh del 192.0.2.3 dev $swp1
852 ip neigh del 192.0.2.2 dev $swp1
853 ip nexthop del id 10
854 ip nexthop del id 2
855 ip nexthop del id 1
857 simple_if_fini $swp2
858 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
861 nexthop_obj_blackhole_offload_test()
863 # Test offload indication of blackhole nexthop objects
864 RET=0
866 ip nexthop add id 1 blackhole
867 busywait "$TIMEOUT" wait_for_offload \
868 ip nexthop show id 1
869 check_err $? "Blackhole nexthop not marked as offloaded when should"
871 ip nexthop add id 10 group 1
872 busywait "$TIMEOUT" wait_for_offload \
873 ip nexthop show id 10
874 check_err $? "Nexthop group not marked as offloaded when should"
876 log_test "blackhole nexthop objects offload indication"
878 ip nexthop del id 10
879 ip nexthop del id 1
882 nexthop_obj_route_offload_test()
884 # Test offload indication of routes using nexthop objects
885 RET=0
887 simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
888 simple_if_init $swp2
889 setup_wait
891 ip nexthop add id 1 via 192.0.2.2 dev $swp1
892 ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud reachable \
893 dev $swp1
894 ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud reachable \
895 dev $swp1
897 ip route replace 198.51.100.0/24 nhid 1
898 busywait "$TIMEOUT" wait_for_offload \
899 ip route show 198.51.100.0/24
900 check_err $? "route not marked as offloaded when using valid nexthop"
902 ip nexthop replace id 1 via 192.0.2.3 dev $swp1
903 busywait "$TIMEOUT" wait_for_offload \
904 ip route show 198.51.100.0/24
905 check_err $? "route not marked as offloaded after replacing valid nexthop with a valid one"
907 ip nexthop replace id 1 via 192.0.2.4 dev $swp1
908 busywait "$TIMEOUT" not wait_for_offload \
909 ip route show 198.51.100.0/24
910 check_err $? "route marked as offloaded after replacing valid nexthop with an invalid one"
912 ip nexthop replace id 1 via 192.0.2.2 dev $swp1
913 busywait "$TIMEOUT" wait_for_offload \
914 ip route show 198.51.100.0/24
915 check_err $? "route not marked as offloaded after replacing invalid nexthop with a valid one"
917 log_test "routes using nexthop objects offload indication"
919 ip route del 198.51.100.0/24
920 ip neigh del 192.0.2.3 dev $swp1
921 ip neigh del 192.0.2.2 dev $swp1
922 ip nexthop del id 1
924 simple_if_fini $swp2
925 simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
928 devlink_reload_test()
930 # Test that after executing all the above configuration tests, a
931 # devlink reload can be performed without errors
932 RET=0
934 devlink dev reload "$DEVLINK_DEV"
935 check_err $? "devlink reload failed"
937 log_test "devlink reload - last test"
939 sleep 20
942 trap cleanup EXIT
944 setup_prepare
945 setup_wait
947 tests_run
949 exit $EXIT_STATUS