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