xref: /linux/tools/testing/selftests/drivers/net/mlxsw/rtnetlink.sh (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
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.
9
10lib_dir=$(dirname $0)/../../../net/forwarding
11
12ALL_TESTS="
13	rif_vrf_set_addr_test
14	rif_non_inherit_bridge_addr_test
15	vlan_interface_deletion_test
16	bridge_deletion_test
17	bridge_vlan_flags_test
18	vlan_1_test
19	lag_bridge_upper_test
20	duplicate_vlans_test
21	vlan_rif_refcount_test
22	subport_rif_refcount_test
23	subport_rif_lag_join_test
24	vlan_dev_deletion_test
25	lag_unlink_slaves_test
26	lag_dev_deletion_test
27	vlan_interface_uppers_test
28	bridge_extern_learn_test
29	neigh_offload_test
30	nexthop_offload_test
31	nexthop_obj_invalid_test
32	nexthop_obj_offload_test
33	nexthop_obj_group_offload_test
34	nexthop_obj_bucket_offload_test
35	nexthop_obj_blackhole_offload_test
36	nexthop_obj_route_offload_test
37	devlink_reload_test
38"
39NUM_NETIFS=2
40: ${TIMEOUT:=20000} # ms
41source $lib_dir/lib.sh
42source $lib_dir/devlink_lib.sh
43
44setup_prepare()
45{
46	swp1=${NETIFS[p1]}
47	swp2=${NETIFS[p2]}
48
49	ip link set dev $swp1 up
50	ip link set dev $swp2 up
51}
52
53cleanup()
54{
55	pre_cleanup
56
57	ip link set dev $swp2 down
58	ip link set dev $swp1 down
59}
60
61rif_vrf_set_addr_test()
62{
63	# Test that it is possible to set an IP address on a VRF upper despite
64	# its random MAC address.
65	RET=0
66
67	ip link add name vrf-test type vrf table 10
68	ip link set dev $swp1 master vrf-test
69
70	ip -4 address add 192.0.2.1/24 dev vrf-test
71	check_err $? "failed to set IPv4 address on VRF"
72	ip -6 address add 2001:db8:1::1/64 dev vrf-test
73	check_err $? "failed to set IPv6 address on VRF"
74
75	log_test "RIF - setting IP address on VRF"
76
77	ip link del dev vrf-test
78}
79
80rif_non_inherit_bridge_addr_test()
81{
82	local swp2_mac=$(mac_get $swp2)
83
84	RET=0
85
86	# Create first RIF
87	ip addr add dev $swp1 192.0.2.1/28
88	check_err $?
89
90	# Create a FID RIF
91	ip link add name br1 up type bridge vlan_filtering 0
92	ip link set dev br1 addr $swp2_mac
93	ip link set dev $swp2 master br1
94	ip addr add dev br1 192.0.2.17/28
95	check_err $?
96
97	# Prepare a device with a low MAC address
98	ip link add name d up type dummy
99	ip link set dev d addr 00:11:22:33:44:55
100
101	# Attach the device to br1. Since the bridge address was set, it should
102	# work.
103	ip link set dev d master br1 &>/dev/null
104	check_err $? "Could not attach a device with low MAC to a bridge with RIF"
105
106	# Port MAC address change should be allowed for a bridge with set MAC.
107	ip link set dev $swp2 addr 00:11:22:33:44:55
108	check_err $? "Changing swp2's MAC address not permitted"
109
110	log_test "RIF - attach port with bad MAC to bridge with set MAC"
111
112	ip link set dev $swp2 addr $swp2_mac
113	ip link del dev d
114	ip link del dev br1
115	ip addr del dev $swp1 192.0.2.1/28
116}
117
118vlan_interface_deletion_test()
119{
120	# Test that when a VLAN interface is deleted, its associated router
121	# interface (RIF) is correctly deleted and not leaked. See commit
122	# c360867ec46a ("mlxsw: spectrum: Delete RIF when VLAN device is
123	# removed") for more details
124	RET=0
125
126	ip link add name br0 type bridge vlan_filtering 1
127	ip link set dev $swp1 master br0
128
129	ip link add link br0 name br0.10 type vlan id 10
130	ip -6 address add 2001:db8:1::1/64 dev br0.10
131	ip link del dev br0.10
132
133	# If we leaked the previous RIF, then this should produce a trace
134	ip link add link br0 name br0.20 type vlan id 20
135	ip -6 address add 2001:db8:1::1/64 dev br0.20
136	ip link del dev br0.20
137
138	log_test "vlan interface deletion"
139
140	ip link del dev br0
141}
142
143bridge_deletion_test()
144{
145	# Test that when a bridge with VLAN interfaces is deleted, we correctly
146	# delete the associated RIFs. See commit 602b74eda813 ("mlxsw:
147	# spectrum_switchdev: Do not leak RIFs when removing bridge") for more
148	# details
149	RET=0
150
151	ip link add name br0 type bridge vlan_filtering 1
152	ip link set dev $swp1 master br0
153	ip -6 address add 2001:db8::1/64 dev br0
154
155	ip link add link br0 name br0.10 type vlan id 10
156	ip -6 address add 2001:db8:1::1/64 dev br0.10
157
158	ip link add link br0 name br0.20 type vlan id 20
159	ip -6 address add 2001:db8:2::1/64 dev br0.20
160
161	ip link del dev br0
162
163	# If we leaked previous RIFs, then this should produce a trace
164	ip -6 address add 2001:db8:1::1/64 dev $swp1
165	ip -6 address del 2001:db8:1::1/64 dev $swp1
166
167	log_test "bridge deletion"
168}
169
170bridge_vlan_flags_test()
171{
172	# Test that when bridge VLAN flags are toggled, we do not take
173	# unnecessary references on related structs. See commit 9e25826ffc94
174	# ("mlxsw: spectrum_switchdev: Fix port_vlan refcounting") for more
175	# details
176	RET=0
177
178	ip link add name br0 type bridge vlan_filtering 1
179	ip link set dev $swp1 master br0
180
181	bridge vlan add vid 10 dev $swp1 pvid untagged
182	bridge vlan add vid 10 dev $swp1 untagged
183	bridge vlan add vid 10 dev $swp1 pvid
184	bridge vlan add vid 10 dev $swp1
185	ip link del dev br0
186
187	# If we did not handle references correctly, then this should produce a
188	# trace
189	devlink dev reload "$DEVLINK_DEV"
190
191	# Allow netdevices to be re-created following the reload
192	sleep 20
193
194	log_test "bridge vlan flags"
195}
196
197vlan_1_test()
198{
199	# Test that VLAN 1 can be configured over mlxsw ports. In the past it
200	# was used internally for untagged traffic. See commit 47bf9df2e820
201	# ("mlxsw: spectrum: Forbid creation of VLAN 1 over port/LAG") for more
202	# details
203	RET=0
204
205	ip link add link $swp1 name $swp1.1 type vlan id 1
206	check_err $? "did not manage to create vlan 1 when should"
207
208	log_test "vlan 1"
209
210	ip link del dev $swp1.1
211}
212
213lag_bridge_upper_test()
214{
215	# Test that ports cannot be enslaved to LAG devices that have uppers
216	# and that failure is handled gracefully. See commit b3529af6bb0d
217	# ("spectrum: Reference count VLAN entries") for more details
218	RET=0
219
220	ip link add name bond1 type bond mode 802.3ad
221
222	ip link add name br0 type bridge vlan_filtering 1
223	ip link set dev bond1 master br0
224
225	ip link set dev $swp1 down
226	ip link set dev $swp1 master bond1 &> /dev/null
227	check_fail $? "managed to enslave port to lag when should not"
228
229	# This might generate a trace, if we did not handle the failure
230	# correctly
231	ip -6 address add 2001:db8:1::1/64 dev $swp1
232	ip -6 address del 2001:db8:1::1/64 dev $swp1
233
234	log_test "lag with bridge upper"
235
236	ip link del dev br0
237	ip link del dev bond1
238}
239
240duplicate_vlans_test()
241{
242	# Test that on a given port a VLAN is only used once. Either as VLAN
243	# in a VLAN-aware bridge or as a VLAN device
244	RET=0
245
246	ip link add name br0 type bridge vlan_filtering 1
247	ip link set dev $swp1 master br0
248	bridge vlan add vid 10 dev $swp1
249
250	ip link add link $swp1 name $swp1.10 type vlan id 10 &> /dev/null
251	check_fail $? "managed to create vlan device when should not"
252
253	bridge vlan del vid 10 dev $swp1
254	ip link add link $swp1 name $swp1.10 type vlan id 10
255	check_err $? "did not manage to create vlan device when should"
256	bridge vlan add vid 10 dev $swp1 &> /dev/null
257	check_fail $? "managed to add bridge vlan when should not"
258
259	log_test "duplicate vlans"
260
261	ip link del dev $swp1.10
262	ip link del dev br0
263}
264
265vlan_rif_refcount_test()
266{
267	# Test that RIFs representing VLAN interfaces are not affected from
268	# ports member in the VLAN. We use the offload indication on routes
269	# configured on the RIF to understand if it was created / destroyed
270	RET=0
271
272	ip link add name br0 type bridge vlan_filtering 1
273	ip link set dev $swp1 master br0
274
275	ip link set dev $swp1 up
276	ip link set dev br0 up
277
278	ip link add link br0 name br0.10 up type vlan id 10
279	ip -6 address add 2001:db8:1::1/64 dev br0.10
280
281	busywait "$TIMEOUT" wait_for_offload \
282		ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
283	check_err $? "vlan rif was not created before adding port to vlan"
284
285	bridge vlan add vid 10 dev $swp1
286	busywait "$TIMEOUT" wait_for_offload \
287		ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
288	check_err $? "vlan rif was destroyed after adding port to vlan"
289
290	bridge vlan del vid 10 dev $swp1
291	busywait "$TIMEOUT" wait_for_offload \
292		ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
293	check_err $? "vlan rif was destroyed after removing port from vlan"
294
295	ip link set dev $swp1 nomaster
296	busywait "$TIMEOUT" not wait_for_offload \
297		ip -6 route get fibmatch 2001:db8:1::2 dev br0.10
298	check_err $? "vlan rif was not destroyed after unlinking port from bridge"
299
300	log_test "vlan rif refcount"
301
302	ip link del dev br0.10
303	ip link set dev $swp1 down
304	ip link del dev br0
305}
306
307subport_rif_refcount_test()
308{
309	# Test that RIFs representing upper devices of physical ports are
310	# reference counted correctly and destroyed when should. We use the
311	# offload indication on routes configured on the RIF to understand if
312	# it was created / destroyed
313	RET=0
314
315	ip link add name bond1 type bond mode 802.3ad
316	ip link set dev $swp1 down
317	ip link set dev $swp2 down
318	ip link set dev $swp1 master bond1
319	ip link set dev $swp2 master bond1
320
321	ip link set dev bond1 up
322	ip link add link bond1 name bond1.10 up type vlan id 10
323	ip -6 address add 2001:db8:1::1/64 dev bond1
324	ip -6 address add 2001:db8:2::1/64 dev bond1.10
325
326	busywait "$TIMEOUT" wait_for_offload \
327		ip -6 route get fibmatch 2001:db8:1::2 dev bond1
328	check_err $? "subport rif was not created on lag device"
329	busywait "$TIMEOUT" wait_for_offload \
330		ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10
331	check_err $? "subport rif was not created on vlan device"
332
333	ip link set dev $swp1 nomaster
334	busywait "$TIMEOUT" wait_for_offload \
335		ip -6 route get fibmatch 2001:db8:1::2 dev bond1
336	check_err $? "subport rif of lag device was destroyed when should not"
337	busywait "$TIMEOUT" wait_for_offload \
338		ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10
339	check_err $? "subport rif of vlan device was destroyed when should not"
340
341	ip link set dev $swp2 nomaster
342	busywait "$TIMEOUT" not wait_for_offload \
343		ip -6 route get fibmatch 2001:db8:1::2 dev bond1
344	check_err $? "subport rif of lag device was not destroyed when should"
345	busywait "$TIMEOUT" not wait_for_offload \
346		ip -6 route get fibmatch 2001:db8:2::2 dev bond1.10
347	check_err $? "subport rif of vlan device was not destroyed when should"
348
349	log_test "subport rif refcount"
350
351	ip link del dev bond1.10
352	ip link del dev bond1
353}
354
355subport_rif_lag_join_test()
356{
357	# Test that the reference count of a RIF configured for a LAG is
358	# incremented / decremented when ports join / leave the LAG. We use the
359	# offload indication on routes configured on the RIF to understand if
360	# it was created / destroyed
361	RET=0
362
363	ip link add name bond1 type bond mode 802.3ad
364	ip link set dev $swp1 down
365	ip link set dev $swp2 down
366	ip link set dev $swp1 master bond1
367	ip link set dev $swp2 master bond1
368
369	ip link set dev bond1 up
370	ip -6 address add 2001:db8:1::1/64 dev bond1
371
372	busywait "$TIMEOUT" wait_for_offload \
373		ip -6 route get fibmatch 2001:db8:1::2 dev bond1
374	check_err $? "subport rif was not created on lag device"
375
376	ip link set dev $swp1 nomaster
377	busywait "$TIMEOUT" wait_for_offload \
378		ip -6 route get fibmatch 2001:db8:1::2 dev bond1
379	check_err $? "subport rif of lag device was destroyed after removing one port"
380
381	ip link set dev $swp1 master bond1
382	ip link set dev $swp2 nomaster
383	busywait "$TIMEOUT" wait_for_offload \
384		ip -6 route get fibmatch 2001:db8:1::2 dev bond1
385	check_err $? "subport rif of lag device was destroyed after re-adding a port and removing another"
386
387	ip link set dev $swp1 nomaster
388	busywait "$TIMEOUT" not wait_for_offload \
389		ip -6 route get fibmatch 2001:db8:1::2 dev bond1
390	check_err $? "subport rif of lag device was not destroyed when should"
391
392	log_test "subport rif lag join"
393
394	ip link del dev bond1
395}
396
397vlan_dev_deletion_test()
398{
399	# Test that VLAN devices are correctly deleted / unlinked when enslaved
400	# to bridge
401	RET=0
402
403	ip link add name br10 type bridge
404	ip link add name br20 type bridge
405	ip link add name br30 type bridge
406	ip link add link $swp1 name $swp1.10 type vlan id 10
407	ip link add link $swp1 name $swp1.20 type vlan id 20
408	ip link add link $swp1 name $swp1.30 type vlan id 30
409	ip link set dev $swp1.10 master br10
410	ip link set dev $swp1.20 master br20
411	ip link set dev $swp1.30 master br30
412
413	# If we did not handle the situation correctly, then these operations
414	# might produce a trace
415	ip link set dev $swp1.30 nomaster
416	ip link del dev $swp1.20
417	# Deletion via ioctl uses different code paths from netlink
418	vconfig rem $swp1.10 &> /dev/null
419
420	log_test "vlan device deletion"
421
422	ip link del dev $swp1.30
423	ip link del dev br30
424	ip link del dev br20
425	ip link del dev br10
426}
427
428lag_create()
429{
430	ip link add name bond1 type bond mode 802.3ad
431	ip link set dev $swp1 down
432	ip link set dev $swp2 down
433	ip link set dev $swp1 master bond1
434	ip link set dev $swp2 master bond1
435
436	ip link add link bond1 name bond1.10 type vlan id 10
437	ip link add link bond1 name bond1.20 type vlan id 20
438
439	ip link add name br0 type bridge vlan_filtering 1
440	ip link set dev bond1 master br0
441
442	ip link add name br10 type bridge
443	ip link set dev bond1.10 master br10
444
445	ip link add name br20 type bridge
446	ip link set dev bond1.20 master br20
447}
448
449lag_unlink_slaves_test()
450{
451	# Test that ports are correctly unlinked from their LAG master, when
452	# the LAG and its VLAN uppers are enslaved to bridges
453	RET=0
454
455	lag_create
456
457	ip link set dev $swp1 nomaster
458	check_err $? "lag slave $swp1 was not unlinked from master"
459	ip link set dev $swp2 nomaster
460	check_err $? "lag slave $swp2 was not unlinked from master"
461
462	# Try to configure corresponding VLANs as router interfaces
463	ip -6 address add 2001:db8:1::1/64 dev $swp1
464	check_err $? "failed to configure ip address on $swp1"
465
466	ip link add link $swp1 name $swp1.10 type vlan id 10
467	ip -6 address add 2001:db8:10::1/64 dev $swp1.10
468	check_err $? "failed to configure ip address on $swp1.10"
469
470	ip link add link $swp1 name $swp1.20 type vlan id 20
471	ip -6 address add 2001:db8:20::1/64 dev $swp1.20
472	check_err $? "failed to configure ip address on $swp1.20"
473
474	log_test "lag slaves unlinking"
475
476	ip link del dev $swp1.20
477	ip link del dev $swp1.10
478	ip address flush dev $swp1
479
480	ip link del dev br20
481	ip link del dev br10
482	ip link del dev br0
483	ip link del dev bond1
484}
485
486lag_dev_deletion_test()
487{
488	# Test that LAG device is correctly deleted, when the LAG and its VLAN
489	# uppers are enslaved to bridges
490	RET=0
491
492	lag_create
493
494	ip link del dev bond1
495
496	log_test "lag device deletion"
497
498	ip link del dev br20
499	ip link del dev br10
500	ip link del dev br0
501}
502
503vlan_interface_uppers_test()
504{
505	# Test that uppers of a VLAN interface are correctly sanitized
506	RET=0
507
508	ip link add name br0 type bridge vlan_filtering 1
509	ip link set dev $swp1 master br0
510
511	ip link add link br0 name br0.10 type vlan id 10
512	ip link add link br0.10 name macvlan0 \
513		type macvlan mode private &> /dev/null
514	check_fail $? "managed to create a macvlan when should not"
515
516	ip -6 address add 2001:db8:1::1/64 dev br0.10
517	ip link add link br0.10 name macvlan0 type macvlan mode private
518	check_err $? "did not manage to create a macvlan when should"
519
520	ip link del dev macvlan0
521
522	ip link add name vrf-test type vrf table 10
523	ip link set dev br0.10 master vrf-test
524	check_err $? "did not manage to enslave vlan interface to vrf"
525	ip link del dev vrf-test
526
527	ip link add name br-test type bridge
528	ip link set dev br0.10 master br-test &> /dev/null
529	check_fail $? "managed to enslave vlan interface to bridge when should not"
530	ip link del dev br-test
531
532	log_test "vlan interface uppers"
533
534	ip link del dev br0
535}
536
537bridge_extern_learn_test()
538{
539	# Test that externally learned entries added from user space are
540	# marked as offloaded
541	RET=0
542
543	ip link add name br0 type bridge
544	ip link set dev $swp1 master br0
545
546	bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn
547
548	busywait "$TIMEOUT" wait_for_offload \
549		bridge fdb show brport $swp1 de:ad:be:ef:13:37
550	check_err $? "fdb entry not marked as offloaded when should"
551
552	log_test "externally learned fdb entry"
553
554	ip link del dev br0
555}
556
557neigh_offload_test()
558{
559	# Test that IPv4 and IPv6 neighbour entries are marked as offloaded
560	RET=0
561
562	ip -4 address add 192.0.2.1/24 dev $swp1
563	ip -6 address add 2001:db8:1::1/64 dev $swp1
564
565	ip -4 neigh add 192.0.2.2 lladdr de:ad:be:ef:13:37 nud perm dev $swp1
566	ip -6 neigh add 2001:db8:1::2 lladdr de:ad:be:ef:13:37 nud perm \
567		dev $swp1
568
569	busywait "$TIMEOUT" wait_for_offload \
570		ip -4 neigh show dev $swp1 192.0.2.2
571	check_err $? "ipv4 neigh entry not marked as offloaded when should"
572	busywait "$TIMEOUT" wait_for_offload \
573		ip -6 neigh show dev $swp1 2001:db8:1::2
574	check_err $? "ipv6 neigh entry not marked as offloaded when should"
575
576	log_test "neighbour offload indication"
577
578	ip -6 neigh del 2001:db8:1::2 dev $swp1
579	ip -4 neigh del 192.0.2.2 dev $swp1
580	ip -6 address del 2001:db8:1::1/64 dev $swp1
581	ip -4 address del 192.0.2.1/24 dev $swp1
582}
583
584nexthop_offload_test()
585{
586	# Test that IPv4 and IPv6 nexthops are marked as offloaded
587	RET=0
588
589	sysctl_set net.ipv6.conf.$swp2.keep_addr_on_down 1
590	simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
591	simple_if_init $swp2 192.0.2.2/24 2001:db8:1::2/64
592	setup_wait
593
594	ip -4 route add 198.51.100.0/24 vrf v$swp1 \
595		nexthop via 192.0.2.2 dev $swp1
596	ip -6 route add 2001:db8:2::/64 vrf v$swp1 \
597		nexthop via 2001:db8:1::2 dev $swp1
598
599	busywait "$TIMEOUT" wait_for_offload \
600		ip -4 route show 198.51.100.0/24 vrf v$swp1
601	check_err $? "ipv4 nexthop not marked as offloaded when should"
602	busywait "$TIMEOUT" wait_for_offload \
603		ip -6 route show 2001:db8:2::/64 vrf v$swp1
604	check_err $? "ipv6 nexthop not marked as offloaded when should"
605
606	ip link set dev $swp2 down
607	sleep 1
608
609	busywait "$TIMEOUT" not wait_for_offload \
610		ip -4 route show 198.51.100.0/24 vrf v$swp1
611	check_err $? "ipv4 nexthop marked as offloaded when should not"
612	busywait "$TIMEOUT" not wait_for_offload \
613		ip -6 route show 2001:db8:2::/64 vrf v$swp1
614	check_err $? "ipv6 nexthop marked as offloaded when should not"
615
616	ip link set dev $swp2 up
617	setup_wait
618
619	busywait "$TIMEOUT" wait_for_offload \
620		ip -4 route show 198.51.100.0/24 vrf v$swp1
621	check_err $? "ipv4 nexthop not marked as offloaded after neigh add"
622	busywait "$TIMEOUT" wait_for_offload \
623		ip -6 route show 2001:db8:2::/64 vrf v$swp1
624	check_err $? "ipv6 nexthop not marked as offloaded after neigh add"
625
626	log_test "nexthop offload indication"
627
628	ip -6 route del 2001:db8:2::/64 vrf v$swp1
629	ip -4 route del 198.51.100.0/24 vrf v$swp1
630
631	simple_if_fini $swp2 192.0.2.2/24 2001:db8:1::2/64
632	simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
633	sysctl_restore net.ipv6.conf.$swp2.keep_addr_on_down
634}
635
636nexthop_obj_invalid_test()
637{
638	# Test that invalid nexthop object configurations are rejected
639	RET=0
640
641	simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
642	simple_if_init $swp2 192.0.2.2/24 2001:db8:1::2/64
643	setup_wait
644
645	ip nexthop add id 1 via 192.0.2.3 fdb
646	check_fail $? "managed to configure an FDB nexthop when should not"
647
648	ip nexthop add id 1 encap mpls 200/300 via 192.0.2.3 dev $swp1
649	check_fail $? "managed to configure a nexthop with MPLS encap when should not"
650
651	ip nexthop add id 1 dev $swp1
652	ip nexthop add id 2 dev $swp1
653	ip nexthop add id 3 via 192.0.2.3 dev $swp1
654	ip nexthop add id 10 group 1/2
655	check_fail $? "managed to configure a nexthop group with device-only nexthops when should not"
656
657	ip nexthop add id 10 group 3 type resilient buckets 7
658	check_fail $? "managed to configure a too small resilient nexthop group when should not"
659
660	ip nexthop add id 10 group 3 type resilient buckets 129
661	check_fail $? "managed to configure a resilient nexthop group with invalid number of buckets when should not"
662
663	ip nexthop add id 10 group 1/2 type resilient buckets 32
664	check_fail $? "managed to configure a resilient nexthop group with device-only nexthops when should not"
665
666	ip nexthop add id 10 group 3 type resilient buckets 32
667	check_err $? "failed to configure a valid resilient nexthop group"
668	ip nexthop replace id 3 dev $swp1
669	check_fail $? "managed to populate a nexthop bucket with a device-only nexthop when should not"
670
671	log_test "nexthop objects - invalid configurations"
672
673	ip nexthop del id 10
674	ip nexthop del id 3
675	ip nexthop del id 2
676	ip nexthop del id 1
677
678	simple_if_fini $swp2 192.0.2.2/24 2001:db8:1::2/64
679	simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
680}
681
682nexthop_obj_offload_test()
683{
684	# Test offload indication of nexthop objects
685	RET=0
686
687	simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
688	simple_if_init $swp2
689	setup_wait
690
691	ip nexthop add id 1 via 192.0.2.2 dev $swp1
692	ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud perm \
693		dev $swp1
694
695	busywait "$TIMEOUT" wait_for_offload \
696		ip nexthop show id 1
697	check_err $? "nexthop not marked as offloaded when should"
698
699	ip neigh replace 192.0.2.2 nud failed dev $swp1
700	busywait "$TIMEOUT" not wait_for_offload \
701		ip nexthop show id 1
702	check_err $? "nexthop marked as offloaded after setting neigh to failed state"
703
704	ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud perm \
705		dev $swp1
706	busywait "$TIMEOUT" wait_for_offload \
707		ip nexthop show id 1
708	check_err $? "nexthop not marked as offloaded after neigh replace"
709
710	ip nexthop replace id 1 via 192.0.2.3 dev $swp1
711	busywait "$TIMEOUT" not wait_for_offload \
712		ip nexthop show id 1
713	check_err $? "nexthop marked as offloaded after replacing to use an invalid address"
714
715	ip nexthop replace id 1 via 192.0.2.2 dev $swp1
716	busywait "$TIMEOUT" wait_for_offload \
717		ip nexthop show id 1
718	check_err $? "nexthop not marked as offloaded after replacing to use a valid address"
719
720	log_test "nexthop objects offload indication"
721
722	ip neigh del 192.0.2.2 dev $swp1
723	ip nexthop del id 1
724
725	simple_if_fini $swp2
726	simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
727}
728
729nexthop_obj_group_offload_test()
730{
731	# Test offload indication of nexthop group objects
732	RET=0
733
734	simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
735	simple_if_init $swp2
736	setup_wait
737
738	ip nexthop add id 1 via 192.0.2.2 dev $swp1
739	ip nexthop add id 2 via 2001:db8:1::2 dev $swp1
740	ip nexthop add id 10 group 1/2
741	ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud perm \
742		dev $swp1
743	ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud perm \
744		dev $swp1
745	ip neigh replace 2001:db8:1::2 lladdr 00:11:22:33:44:55 nud perm \
746		dev $swp1
747
748	busywait "$TIMEOUT" wait_for_offload \
749		ip nexthop show id 1
750	check_err $? "IPv4 nexthop not marked as offloaded when should"
751	busywait "$TIMEOUT" wait_for_offload \
752		ip nexthop show id 2
753	check_err $? "IPv6 nexthop not marked as offloaded when should"
754	busywait "$TIMEOUT" wait_for_offload \
755		ip nexthop show id 10
756	check_err $? "nexthop group not marked as offloaded when should"
757
758	# Invalidate nexthop id 1
759	ip neigh replace 192.0.2.2 nud failed dev $swp1
760	busywait "$TIMEOUT" not wait_for_offload \
761		ip nexthop show id 10
762	check_fail $? "nexthop group not marked as offloaded with one valid nexthop"
763
764	# Invalidate nexthop id 2
765	ip neigh replace 2001:db8:1::2 nud failed dev $swp1
766	busywait "$TIMEOUT" not wait_for_offload \
767		ip nexthop show id 10
768	check_err $? "nexthop group marked as offloaded when should not"
769
770	# Revalidate nexthop id 1
771	ip nexthop replace id 1 via 192.0.2.3 dev $swp1
772	busywait "$TIMEOUT" wait_for_offload \
773		ip nexthop show id 10
774	check_err $? "nexthop group not marked as offloaded after revalidating nexthop"
775
776	log_test "nexthop group objects offload indication"
777
778	ip neigh del 2001:db8:1::2 dev $swp1
779	ip neigh del 192.0.2.3 dev $swp1
780	ip neigh del 192.0.2.2 dev $swp1
781	ip nexthop del id 10
782	ip nexthop del id 2
783	ip nexthop del id 1
784
785	simple_if_fini $swp2
786	simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
787}
788
789nexthop_obj_bucket_offload_test()
790{
791	# Test offload indication of nexthop buckets
792	RET=0
793
794	simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
795	simple_if_init $swp2
796	setup_wait
797
798	ip nexthop add id 1 via 192.0.2.2 dev $swp1
799	ip nexthop add id 2 via 2001:db8:1::2 dev $swp1
800	ip nexthop add id 10 group 1/2 type resilient buckets 32 idle_timer 0
801	ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud perm \
802		dev $swp1
803	ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud perm \
804		dev $swp1
805	ip neigh replace 2001:db8:1::2 lladdr 00:11:22:33:44:55 nud perm \
806		dev $swp1
807
808	busywait "$TIMEOUT" wait_for_offload \
809		ip nexthop bucket show nhid 1
810	check_err $? "IPv4 nexthop buckets not marked as offloaded when should"
811	busywait "$TIMEOUT" wait_for_offload \
812		ip nexthop bucket show nhid 2
813	check_err $? "IPv6 nexthop buckets not marked as offloaded when should"
814
815	# Invalidate nexthop id 1
816	ip neigh replace 192.0.2.2 nud failed dev $swp1
817	busywait "$TIMEOUT" wait_for_trap \
818		ip nexthop bucket show nhid 1
819	check_err $? "IPv4 nexthop buckets not marked with trap when should"
820
821	# Invalidate nexthop id 2
822	ip neigh replace 2001:db8:1::2 nud failed dev $swp1
823	busywait "$TIMEOUT" wait_for_trap \
824		ip nexthop bucket show nhid 2
825	check_err $? "IPv6 nexthop buckets not marked with trap when should"
826
827	# Revalidate nexthop id 1 by changing its configuration
828	ip nexthop replace id 1 via 192.0.2.3 dev $swp1
829	busywait "$TIMEOUT" wait_for_offload \
830		ip nexthop bucket show nhid 1
831	check_err $? "nexthop bucket not marked as offloaded after revalidating nexthop"
832
833	# Revalidate nexthop id 2 by changing its neighbour
834	ip neigh replace 2001:db8:1::2 lladdr 00:11:22:33:44:55 nud perm \
835		dev $swp1
836	busywait "$TIMEOUT" wait_for_offload \
837		ip nexthop bucket show nhid 2
838	check_err $? "nexthop bucket not marked as offloaded after revalidating neighbour"
839
840	log_test "nexthop bucket offload indication"
841
842	ip neigh del 2001:db8:1::2 dev $swp1
843	ip neigh del 192.0.2.3 dev $swp1
844	ip neigh del 192.0.2.2 dev $swp1
845	ip nexthop del id 10
846	ip nexthop del id 2
847	ip nexthop del id 1
848
849	simple_if_fini $swp2
850	simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
851}
852
853nexthop_obj_blackhole_offload_test()
854{
855	# Test offload indication of blackhole nexthop objects
856	RET=0
857
858	ip nexthop add id 1 blackhole
859	busywait "$TIMEOUT" wait_for_offload \
860		ip nexthop show id 1
861	check_err $? "Blackhole nexthop not marked as offloaded when should"
862
863	ip nexthop add id 10 group 1
864	busywait "$TIMEOUT" wait_for_offload \
865		ip nexthop show id 10
866	check_err $? "Nexthop group not marked as offloaded when should"
867
868	log_test "blackhole nexthop objects offload indication"
869
870	ip nexthop del id 10
871	ip nexthop del id 1
872}
873
874nexthop_obj_route_offload_test()
875{
876	# Test offload indication of routes using nexthop objects
877	RET=0
878
879	simple_if_init $swp1 192.0.2.1/24 2001:db8:1::1/64
880	simple_if_init $swp2
881	setup_wait
882
883	ip nexthop add id 1 via 192.0.2.2 dev $swp1
884	ip neigh replace 192.0.2.2 lladdr 00:11:22:33:44:55 nud perm \
885		dev $swp1
886	ip neigh replace 192.0.2.3 lladdr 00:11:22:33:44:55 nud perm \
887		dev $swp1
888
889	ip route replace 198.51.100.0/24 nhid 1
890	busywait "$TIMEOUT" wait_for_offload \
891		ip route show 198.51.100.0/24
892	check_err $? "route not marked as offloaded when using valid nexthop"
893
894	ip nexthop replace id 1 via 192.0.2.3 dev $swp1
895	busywait "$TIMEOUT" wait_for_offload \
896		ip route show 198.51.100.0/24
897	check_err $? "route not marked as offloaded after replacing valid nexthop with a valid one"
898
899	ip nexthop replace id 1 via 192.0.2.4 dev $swp1
900	busywait "$TIMEOUT" not wait_for_offload \
901		ip route show 198.51.100.0/24
902	check_err $? "route marked as offloaded after replacing valid nexthop with an invalid one"
903
904	ip nexthop replace id 1 via 192.0.2.2 dev $swp1
905	busywait "$TIMEOUT" wait_for_offload \
906		ip route show 198.51.100.0/24
907	check_err $? "route not marked as offloaded after replacing invalid nexthop with a valid one"
908
909	log_test "routes using nexthop objects offload indication"
910
911	ip route del 198.51.100.0/24
912	ip neigh del 192.0.2.3 dev $swp1
913	ip neigh del 192.0.2.2 dev $swp1
914	ip nexthop del id 1
915
916	simple_if_fini $swp2
917	simple_if_fini $swp1 192.0.2.1/24 2001:db8:1::1/64
918}
919
920devlink_reload_test()
921{
922	# Test that after executing all the above configuration tests, a
923	# devlink reload can be performed without errors
924	RET=0
925
926	devlink dev reload "$DEVLINK_DEV"
927	check_err $? "devlink reload failed"
928
929	log_test "devlink reload - last test"
930
931	sleep 20
932}
933
934trap cleanup EXIT
935
936setup_prepare
937setup_wait
938
939tests_run
940
941exit $EXIT_STATUS
942