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