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