xref: /linux/tools/testing/selftests/net/rtnetlink.sh (revision 65ae975e97d5aab3ee9dc5ec701b12090572ed43)
1#!/bin/bash
2#
3# This test is for checking rtnetlink callpaths, and get as much coverage as possible.
4#
5# set -e
6
7ALL_TESTS="
8	kci_test_polrouting
9	kci_test_route_get
10	kci_test_addrlft
11	kci_test_promote_secondaries
12	kci_test_tc
13	kci_test_gre
14	kci_test_gretap
15	kci_test_ip6gretap
16	kci_test_erspan
17	kci_test_ip6erspan
18	kci_test_bridge
19	kci_test_addrlabel
20	kci_test_ifalias
21	kci_test_vrf
22	kci_test_encap
23	kci_test_macsec
24	kci_test_ipsec
25	kci_test_ipsec_offload
26	kci_test_fdb_get
27	kci_test_fdb_del
28	kci_test_neigh_get
29	kci_test_bridge_parent_id
30	kci_test_address_proto
31	kci_test_enslave_bonding
32	kci_test_mngtmpaddr
33"
34
35devdummy="test-dummy0"
36VERBOSE=0
37PAUSE=no
38PAUSE_ON_FAIL=no
39
40source lib.sh
41
42# set global exit status, but never reset nonzero one.
43check_err()
44{
45	if [ $ret -eq 0 ]; then
46		ret=$1
47	fi
48	[ -n "$2" ] && echo "$2"
49}
50
51# same but inverted -- used when command must fail for test to pass
52check_fail()
53{
54	if [ $1 -eq 0 ]; then
55		ret=1
56	fi
57}
58
59run_cmd_common()
60{
61	local cmd="$*"
62	local out
63	if [ "$VERBOSE" = "1" ]; then
64		echo "COMMAND: ${cmd}"
65	fi
66	out=$($cmd 2>&1)
67	rc=$?
68	if [ "$VERBOSE" = "1" -a -n "$out" ]; then
69		echo "    $out"
70	fi
71	return $rc
72}
73
74run_cmd() {
75	run_cmd_common "$@"
76	rc=$?
77	check_err $rc
78	return $rc
79}
80run_cmd_fail()
81{
82	run_cmd_common "$@"
83	rc=$?
84	check_fail $rc
85	return $rc
86}
87
88run_cmd_grep_common()
89{
90	local find="$1"; shift
91	local cmd="$*"
92	local out
93	if [ "$VERBOSE" = "1" ]; then
94		echo "COMMAND: ${cmd} 2>&1 | grep -q '${find}'"
95	fi
96	out=$($cmd 2>&1 | grep -q "${find}" 2>&1)
97	return $?
98}
99
100run_cmd_grep() {
101	run_cmd_grep_common "$@"
102	rc=$?
103	check_err $rc
104	return $rc
105}
106
107run_cmd_grep_fail()
108{
109	run_cmd_grep_common "$@"
110	rc=$?
111	check_fail $rc
112	return $rc
113}
114
115end_test()
116{
117	echo "$*"
118	[ "${VERBOSE}" = "1" ] && echo
119
120	if [[ $ret -ne 0 ]] && [[ "${PAUSE_ON_FAIL}" = "yes" ]]; then
121		echo "Hit enter to continue"
122		read a
123	fi;
124
125	if [ "${PAUSE}" = "yes" ]; then
126		echo "Hit enter to continue"
127		read a
128	fi
129
130}
131
132
133kci_add_dummy()
134{
135	run_cmd ip link add name "$devdummy" type dummy
136	run_cmd ip link set "$devdummy" up
137}
138
139kci_del_dummy()
140{
141	run_cmd ip link del dev "$devdummy"
142}
143
144kci_test_netconf()
145{
146	dev="$1"
147	r=$ret
148	run_cmd ip netconf show dev "$dev"
149	for f in 4 6; do
150		run_cmd ip -$f netconf show dev "$dev"
151	done
152
153	if [ $ret -ne 0 ] ;then
154		end_test "FAIL: ip netconf show $dev"
155		test $r -eq 0 && ret=0
156		return 1
157	fi
158}
159
160# add a bridge with vlans on top
161kci_test_bridge()
162{
163	devbr="test-br0"
164	vlandev="testbr-vlan1"
165
166	local ret=0
167	run_cmd ip link add name "$devbr" type bridge
168	run_cmd ip link set dev "$devdummy" master "$devbr"
169	run_cmd ip link set "$devbr" up
170	run_cmd ip link add link "$devbr" name "$vlandev" type vlan id 1
171	run_cmd ip addr add dev "$vlandev" 10.200.7.23/30
172	run_cmd ip -6 addr add dev "$vlandev" dead:42::1234/64
173	run_cmd ip -d link
174	run_cmd ip r s t all
175
176	for name in "$devbr" "$vlandev" "$devdummy" ; do
177		kci_test_netconf "$name"
178	done
179	run_cmd ip -6 addr del dev "$vlandev" dead:42::1234/64
180	run_cmd ip link del dev "$vlandev"
181	run_cmd ip link del dev "$devbr"
182
183	if [ $ret -ne 0 ];then
184		end_test "FAIL: bridge setup"
185		return 1
186	fi
187	end_test "PASS: bridge setup"
188
189}
190
191kci_test_gre()
192{
193	gredev=neta
194	rem=10.42.42.1
195	loc=10.0.0.1
196
197	local ret=0
198	run_cmd ip tunnel add $gredev mode gre remote $rem local $loc ttl 1
199	run_cmd ip link set $gredev up
200	run_cmd ip addr add 10.23.7.10 dev $gredev
201	run_cmd ip route add 10.23.8.0/30 dev $gredev
202	run_cmd ip addr add dev "$devdummy" 10.23.7.11/24
203	run_cmd ip link
204	run_cmd ip addr
205
206	kci_test_netconf "$gredev"
207	run_cmd ip addr del dev "$devdummy" 10.23.7.11/24
208	run_cmd ip link del $gredev
209
210	if [ $ret -ne 0 ];then
211		end_test "FAIL: gre tunnel endpoint"
212		return 1
213	fi
214	end_test "PASS: gre tunnel endpoint"
215}
216
217# tc uses rtnetlink too, for full tc testing
218# please see tools/testing/selftests/tc-testing.
219kci_test_tc()
220{
221	dev=lo
222	local ret=0
223
224	run_cmd tc qdisc add dev "$dev" root handle 1: htb
225	run_cmd tc class add dev "$dev" parent 1: classid 1:10 htb rate 1mbit
226	run_cmd tc filter add dev "$dev" parent 1:0 prio 5 handle ffe: protocol ip u32 divisor 256
227	run_cmd tc filter add dev "$dev" parent 1:0 prio 5 handle ffd: protocol ip u32 divisor 256
228	run_cmd tc filter add dev "$dev" parent 1:0 prio 5 handle ffc: protocol ip u32 divisor 256
229	run_cmd tc filter add dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32 ht ffe:2: match ip src 10.0.0.3 flowid 1:10
230	run_cmd tc filter add dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:2 u32 ht ffe:2: match ip src 10.0.0.2 flowid 1:10
231	run_cmd tc filter show dev "$dev" parent  1:0
232	run_cmd tc filter del dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32
233	run_cmd tc filter show dev "$dev" parent  1:0
234	run_cmd tc qdisc del dev "$dev" root handle 1: htb
235
236	if [ $ret -ne 0 ];then
237		end_test "FAIL: tc htb hierarchy"
238		return 1
239	fi
240	end_test "PASS: tc htb hierarchy"
241
242}
243
244kci_test_polrouting()
245{
246	local ret=0
247	run_cmd ip rule add fwmark 1 lookup 100
248	run_cmd ip route add local 0.0.0.0/0 dev lo table 100
249	run_cmd ip r s t all
250	run_cmd ip rule del fwmark 1 lookup 100
251	run_cmd ip route del local 0.0.0.0/0 dev lo table 100
252
253	if [ $ret -ne 0 ];then
254		end_test "FAIL: policy route test"
255		return 1
256	fi
257	end_test "PASS: policy routing"
258}
259
260kci_test_route_get()
261{
262	local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
263
264	local ret=0
265	run_cmd ip route get 127.0.0.1
266	run_cmd ip route get 127.0.0.1 dev "$devdummy"
267	run_cmd ip route get ::1
268	run_cmd ip route get fe80::1 dev "$devdummy"
269	run_cmd ip route get 127.0.0.1 from 127.0.0.1 oif lo tos 0x10 mark 0x1
270	run_cmd ip route get ::1 from ::1 iif lo oif lo tos 0x10 mark 0x1
271	run_cmd ip addr add dev "$devdummy" 10.23.7.11/24
272	run_cmd ip route get 10.23.7.11 from 10.23.7.12 iif "$devdummy"
273	run_cmd ip route add 10.23.8.0/24 \
274		nexthop via 10.23.7.13 dev "$devdummy" \
275		nexthop via 10.23.7.14 dev "$devdummy"
276
277	sysctl -wq net.ipv4.fib_multipath_hash_policy=0
278	run_cmd ip route get 10.23.8.11
279	sysctl -wq net.ipv4.fib_multipath_hash_policy=1
280	run_cmd ip route get 10.23.8.11
281	sysctl -wq net.ipv4.fib_multipath_hash_policy="$hash_policy"
282	run_cmd ip route del 10.23.8.0/24
283	run_cmd ip addr del dev "$devdummy" 10.23.7.11/24
284
285
286	if [ $ret -ne 0 ];then
287		end_test "FAIL: route get"
288		return 1
289	fi
290
291	end_test "PASS: route get"
292}
293
294kci_test_addrlft()
295{
296	for i in $(seq 10 100) ;do
297		lft=$(((RANDOM%3) + 1))
298		run_cmd ip addr add 10.23.11.$i/32 dev "$devdummy" preferred_lft $lft valid_lft $((lft+1))
299	done
300
301	sleep 5
302	run_cmd_grep_fail "10.23.11." ip addr show dev "$devdummy"
303	if [ $? -eq 0 ]; then
304		check_err 1
305		end_test "FAIL: preferred_lft addresses remaining"
306		return
307	fi
308
309	end_test "PASS: preferred_lft addresses have expired"
310}
311
312kci_test_promote_secondaries()
313{
314	promote=$(sysctl -n net.ipv4.conf.$devdummy.promote_secondaries)
315
316	sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=1
317
318	for i in $(seq 2 254);do
319		IP="10.23.11.$i"
320		ip -f inet addr add $IP/16 brd + dev "$devdummy"
321		ifconfig "$devdummy" $IP netmask 255.255.0.0
322	done
323
324	ip addr flush dev "$devdummy"
325
326	[ $promote -eq 0 ] && sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=0
327
328	end_test "PASS: promote_secondaries complete"
329}
330
331kci_test_addrlabel()
332{
333	local ret=0
334	run_cmd ip addrlabel add prefix dead::/64 dev lo label 1
335	run_cmd_grep "prefix dead::/64 dev lo label 1" ip addrlabel list
336	run_cmd ip addrlabel del prefix dead::/64 dev lo label 1
337	run_cmd ip addrlabel add prefix dead::/64 label 1
338	run_cmd ip addrlabel del prefix dead::/64 label 1
339
340	# concurrent add/delete
341	for i in $(seq 1 1000); do
342		ip addrlabel add prefix 1c3::/64 label 12345 2>/dev/null
343	done &
344
345	for i in $(seq 1 1000); do
346		ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
347	done
348
349	wait
350
351	ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
352
353	if [ $ret -ne 0 ];then
354		end_test "FAIL: ipv6 addrlabel"
355		return 1
356	fi
357
358	end_test "PASS: ipv6 addrlabel"
359}
360
361kci_test_ifalias()
362{
363	local ret=0
364	namewant=$(uuidgen)
365	syspathname="/sys/class/net/$devdummy/ifalias"
366	run_cmd ip link set dev "$devdummy" alias "$namewant"
367
368	if [ $ret -ne 0 ]; then
369		end_test "FAIL: cannot set interface alias of $devdummy to $namewant"
370		return 1
371	fi
372	run_cmd_grep "alias $namewant" ip link show "$devdummy"
373
374	if [ -r "$syspathname" ] ; then
375		read namehave < "$syspathname"
376		if [ "$namewant" != "$namehave" ]; then
377			end_test "FAIL: did set ifalias $namewant but got $namehave"
378			return 1
379		fi
380
381		namewant=$(uuidgen)
382		echo "$namewant" > "$syspathname"
383	        run_cmd_grep "alias $namewant" ip link show "$devdummy"
384
385		# sysfs interface allows to delete alias again
386		echo "" > "$syspathname"
387	        run_cmd_grep_fail "alias $namewant" ip link show "$devdummy"
388
389		for i in $(seq 1 100); do
390			uuidgen > "$syspathname" &
391		done
392
393		wait
394
395		# re-add the alias -- kernel should free mem when dummy dev is removed
396		run_cmd ip link set dev "$devdummy" alias "$namewant"
397
398	fi
399
400	if [ $ret -ne 0 ]; then
401		end_test "FAIL: set interface alias $devdummy to $namewant"
402		return 1
403	fi
404
405	end_test "PASS: set ifalias $namewant for $devdummy"
406}
407
408kci_test_vrf()
409{
410	vrfname="test-vrf"
411	local ret=0
412	run_cmd ip link show type vrf
413	if [ $? -ne 0 ]; then
414		end_test "SKIP: vrf: iproute2 too old"
415		return $ksft_skip
416	fi
417	run_cmd ip link add "$vrfname" type vrf table 10
418	if [ $ret -ne 0 ];then
419		end_test "FAIL: can't add vrf interface, skipping test"
420		return 0
421	fi
422	run_cmd_grep "$vrfname" ip -br link show type vrf
423	if [ $ret -ne 0 ];then
424		end_test "FAIL: created vrf device not found"
425		return 1
426	fi
427
428	run_cmd ip link set dev "$vrfname" up
429	run_cmd ip link set dev "$devdummy" master "$vrfname"
430	run_cmd ip link del dev "$vrfname"
431
432	if [ $ret -ne 0 ];then
433		end_test "FAIL: vrf"
434		return 1
435	fi
436
437	end_test "PASS: vrf"
438}
439
440kci_test_encap_vxlan()
441{
442	local ret=0
443	vxlan="test-vxlan0"
444	vlan="test-vlan0"
445	run_cmd ip -netns "$testns" link add "$vxlan" type vxlan id 42 group 239.1.1.1 \
446		dev "$devdummy" dstport 4789
447	if [ $? -ne 0 ]; then
448		end_test "FAIL: can't add vxlan interface, skipping test"
449		return 0
450	fi
451
452	run_cmd ip -netns "$testns" addr add 10.2.11.49/24 dev "$vxlan"
453	run_cmd ip -netns "$testns" link set up dev "$vxlan"
454	run_cmd ip -netns "$testns" link add link "$vxlan" name "$vlan" type vlan id 1
455
456	# changelink testcases
457	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan vni 43
458	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan group ffe5::5 dev "$devdummy"
459	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan ttl inherit
460
461	run_cmd ip -netns "$testns" link set dev "$vxlan" type vxlan ttl 64
462	run_cmd ip -netns "$testns" link set dev "$vxlan" type vxlan nolearning
463
464	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan proxy
465	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan norsc
466	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan l2miss
467	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan l3miss
468	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan external
469	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan udpcsum
470	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumtx
471	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumrx
472	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumtx
473	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumrx
474	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan gbp
475	run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan gpe
476	run_cmd ip -netns "$testns" link del "$vxlan"
477
478	if [ $ret -ne 0 ]; then
479		end_test "FAIL: vxlan"
480		return 1
481	fi
482	end_test "PASS: vxlan"
483}
484
485kci_test_encap_fou()
486{
487	local ret=0
488	name="test-fou"
489	run_cmd_grep 'Usage: ip fou' ip fou help
490	if [ $? -ne 0 ];then
491		end_test "SKIP: fou: iproute2 too old"
492		return $ksft_skip
493	fi
494
495	if ! /sbin/modprobe -q -n fou; then
496		end_test "SKIP: module fou is not found"
497		return $ksft_skip
498	fi
499	/sbin/modprobe -q fou
500
501	run_cmd ip -netns "$testns" fou add port 7777 ipproto 47
502	if [ $? -ne 0 ];then
503		end_test "FAIL: can't add fou port 7777, skipping test"
504		return 1
505	fi
506	run_cmd ip -netns "$testns" fou add port 8888 ipproto 4
507	run_cmd_fail ip -netns "$testns" fou del port 9999
508	run_cmd ip -netns "$testns" fou del port 7777
509	if [ $ret -ne 0 ]; then
510		end_test "FAIL: fou"s
511		return 1
512	fi
513
514	end_test "PASS: fou"
515}
516
517# test various encap methods, use netns to avoid unwanted interference
518kci_test_encap()
519{
520	local ret=0
521	setup_ns testns
522	if [ $? -ne 0 ]; then
523		end_test "SKIP encap tests: cannot add net namespace $testns"
524		return $ksft_skip
525	fi
526	run_cmd ip -netns "$testns" link set lo up
527	run_cmd ip -netns "$testns" link add name "$devdummy" type dummy
528	run_cmd ip -netns "$testns" link set "$devdummy" up
529	run_cmd kci_test_encap_vxlan
530	run_cmd kci_test_encap_fou
531
532	ip netns del "$testns"
533	return $ret
534}
535
536kci_test_macsec()
537{
538	msname="test_macsec0"
539	local ret=0
540	run_cmd_grep "^Usage: ip macsec" ip macsec help
541	if [ $? -ne 0 ]; then
542		end_test "SKIP: macsec: iproute2 too old"
543		return $ksft_skip
544	fi
545	run_cmd ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on
546	if [ $ret -ne 0 ];then
547		end_test "FAIL: can't add macsec interface, skipping test"
548		return 1
549	fi
550	run_cmd ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
551	run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
552	run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on key 00 0123456789abcdef0123456789abcdef
553	run_cmd ip macsec show
554	run_cmd ip link del dev "$msname"
555
556	if [ $ret -ne 0 ];then
557		end_test "FAIL: macsec"
558		return 1
559	fi
560
561	end_test "PASS: macsec"
562}
563
564#-------------------------------------------------------------------
565# Example commands
566#   ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
567#            spi 0x07 mode transport reqid 0x07 replay-window 32 \
568#            aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
569#            sel src 14.0.0.52/24 dst 14.0.0.70/24
570#   ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
571#            tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
572#            spi 0x07 mode transport reqid 0x07
573#
574# Subcommands not tested
575#    ip x s update
576#    ip x s allocspi
577#    ip x s deleteall
578#    ip x p update
579#    ip x p deleteall
580#    ip x p set
581#-------------------------------------------------------------------
582kci_test_ipsec()
583{
584	local ret=0
585	algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
586	srcip=192.168.123.1
587	dstip=192.168.123.2
588	spi=7
589
590	ip addr add $srcip dev $devdummy
591
592	# flush to be sure there's nothing configured
593	run_cmd ip x s flush ; ip x p flush
594
595	# start the monitor in the background
596	tmpfile=`mktemp /var/run/ipsectestXXX`
597	mpid=`(ip x m > $tmpfile & echo $!) 2>/dev/null`
598	sleep 0.2
599
600	ipsecid="proto esp src $srcip dst $dstip spi 0x07"
601	run_cmd ip x s add $ipsecid \
602            mode transport reqid 0x07 replay-window 32 \
603            $algo sel src $srcip/24 dst $dstip/24
604
605
606	lines=`ip x s list | grep $srcip | grep $dstip | wc -l`
607	run_cmd test $lines -eq 2
608	run_cmd_grep "SAD count 1" ip x s count
609
610	lines=`ip x s get $ipsecid | grep $srcip | grep $dstip | wc -l`
611	run_cmd test $lines -eq 2
612	run_cmd ip x s delete $ipsecid
613
614	lines=`ip x s list | wc -l`
615	run_cmd test $lines -eq 0
616
617	ipsecsel="dir out src $srcip/24 dst $dstip/24"
618	run_cmd ip x p add $ipsecsel \
619		    tmpl proto esp src $srcip dst $dstip \
620		    spi 0x07 mode transport reqid 0x07
621
622
623	lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
624	run_cmd test $lines -eq 2
625
626	run_cmd_grep "SPD IN  0 OUT 1 FWD 0" ip x p count
627
628	lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
629	run_cmd test $lines -eq 2
630
631	run_cmd ip x p delete $ipsecsel
632
633	lines=`ip x p list | wc -l`
634	run_cmd test $lines -eq 0
635
636	# check the monitor results
637	kill $mpid
638	lines=`wc -l $tmpfile | cut "-d " -f1`
639	run_cmd test $lines -eq 20
640	rm -rf $tmpfile
641
642	# clean up any leftovers
643	run_cmd ip x s flush
644	run_cmd ip x p flush
645	ip addr del $srcip/32 dev $devdummy
646
647	if [ $ret -ne 0 ]; then
648		end_test "FAIL: ipsec"
649		return 1
650	fi
651	end_test "PASS: ipsec"
652}
653
654#-------------------------------------------------------------------
655# Example commands
656#   ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
657#            spi 0x07 mode transport reqid 0x07 replay-window 32 \
658#            aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
659#            sel src 14.0.0.52/24 dst 14.0.0.70/24
660#            offload dev sim1 dir out
661#   ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
662#            tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
663#            spi 0x07 mode transport reqid 0x07
664#
665#-------------------------------------------------------------------
666kci_test_ipsec_offload()
667{
668	local ret=0
669	algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
670	srcip=192.168.123.3
671	dstip=192.168.123.4
672	sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
673	sysfsf=$sysfsd/ipsec
674	sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
675	probed=false
676
677	if ! mount | grep -q debugfs; then
678		mount -t debugfs none /sys/kernel/debug/ &> /dev/null
679	fi
680
681	# setup netdevsim since dummydev doesn't have offload support
682	if [ ! -w /sys/bus/netdevsim/new_device ] ; then
683		run_cmd modprobe -q netdevsim
684		if [ $ret -ne 0 ]; then
685			end_test "SKIP: ipsec_offload can't load netdevsim"
686			return $ksft_skip
687		fi
688		probed=true
689	fi
690
691	echo "0" > /sys/bus/netdevsim/new_device
692	while [ ! -d $sysfsnet ] ; do :; done
693	udevadm settle
694	dev=`ls $sysfsnet`
695
696	ip addr add $srcip dev $dev
697	ip link set $dev up
698	if [ ! -d $sysfsd ] ; then
699		end_test "FAIL: ipsec_offload can't create device $dev"
700		return 1
701	fi
702	if [ ! -f $sysfsf ] ; then
703		end_test "FAIL: ipsec_offload netdevsim doesn't support IPsec offload"
704		return 1
705	fi
706
707	# flush to be sure there's nothing configured
708	ip x s flush ; ip x p flush
709
710	# create offloaded SAs, both in and out
711	run_cmd ip x p add dir out src $srcip/24 dst $dstip/24 \
712	    tmpl proto esp src $srcip dst $dstip spi 9 \
713	    mode transport reqid 42
714
715	run_cmd ip x p add dir in src $dstip/24 dst $srcip/24 \
716	    tmpl proto esp src $dstip dst $srcip spi 9 \
717	    mode transport reqid 42
718
719	run_cmd ip x s add proto esp src $srcip dst $dstip spi 9 \
720	    mode transport reqid 42 $algo sel src $srcip/24 dst $dstip/24 \
721	    offload dev $dev dir out
722
723	run_cmd ip x s add proto esp src $dstip dst $srcip spi 9 \
724	    mode transport reqid 42 $algo sel src $dstip/24 dst $srcip/24 \
725	    offload dev $dev dir in
726
727	if [ $ret -ne 0 ]; then
728		end_test "FAIL: ipsec_offload can't create SA"
729		return 1
730	fi
731
732	# does offload show up in ip output
733	lines=`ip x s list | grep -c "crypto offload parameters: dev $dev dir"`
734	if [ $lines -ne 2 ] ; then
735		check_err 1
736		end_test "FAIL: ipsec_offload SA offload missing from list output"
737	fi
738
739	# we didn't create a peer, make sure we can Tx
740	ip neigh add $dstip dev $dev lladdr 00:11:22:33:44:55
741	# use ping to exercise the Tx path
742	ping -I $dev -c 3 -W 1 -i 0 $dstip >/dev/null
743
744	# does driver have correct offload info
745	run_cmd diff $sysfsf - << EOF
746SA count=2 tx=3
747sa[0] tx ipaddr=$dstip
748sa[0]    spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
749sa[0]    key=0x34333231 38373635 32313039 36353433
750sa[1] rx ipaddr=$srcip
751sa[1]    spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
752sa[1]    key=0x34333231 38373635 32313039 36353433
753EOF
754	if [ $? -ne 0 ] ; then
755		end_test "FAIL: ipsec_offload incorrect driver data"
756		check_err 1
757	fi
758
759	# does offload get removed from driver
760	ip x s flush
761	ip x p flush
762	lines=`grep -c "SA count=0" $sysfsf`
763	if [ $lines -ne 1 ] ; then
764		check_err 1
765		end_test "FAIL: ipsec_offload SA not removed from driver"
766	fi
767
768	# clean up any leftovers
769	echo 0 > /sys/bus/netdevsim/del_device
770	$probed && rmmod netdevsim
771
772	if [ $ret -ne 0 ]; then
773		end_test "FAIL: ipsec_offload"
774		return 1
775	fi
776	end_test "PASS: ipsec_offload"
777}
778
779kci_test_gretap()
780{
781	DEV_NS=gretap00
782	local ret=0
783
784	setup_ns testns
785	if [ $? -ne 0 ]; then
786		end_test "SKIP gretap tests: cannot add net namespace $testns"
787		return $ksft_skip
788	fi
789
790	run_cmd_grep "^Usage:" ip link help gretap
791	if [ $? -ne 0 ];then
792		end_test "SKIP: gretap: iproute2 too old"
793		ip netns del "$testns"
794		return $ksft_skip
795	fi
796
797	# test native tunnel
798	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type gretap seq \
799		key 102 local 172.16.1.100 remote 172.16.1.200
800
801
802	run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
803	run_cmd ip -netns "$testns" link set dev $DEV_NS up
804	run_cmd ip -netns "$testns" link del "$DEV_NS"
805
806	# test external mode
807	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type gretap external
808	run_cmd ip -netns "$testns" link del "$DEV_NS"
809
810	if [ $ret -ne 0 ]; then
811		end_test "FAIL: gretap"
812		ip netns del "$testns"
813		return 1
814	fi
815	end_test "PASS: gretap"
816
817	ip netns del "$testns"
818}
819
820kci_test_ip6gretap()
821{
822	DEV_NS=ip6gretap00
823	local ret=0
824
825	setup_ns testns
826	if [ $? -ne 0 ]; then
827		end_test "SKIP ip6gretap tests: cannot add net namespace $testns"
828		return $ksft_skip
829	fi
830
831	run_cmd_grep "^Usage:" ip link help ip6gretap
832	if [ $? -ne 0 ];then
833		end_test "SKIP: ip6gretap: iproute2 too old"
834		ip netns del "$testns"
835		return $ksft_skip
836	fi
837
838	# test native tunnel
839	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap seq \
840		key 102 local fc00:100::1 remote fc00:100::2
841
842
843	run_cmd ip -netns "$testns" addr add dev "$DEV_NS" fc00:200::1/96
844	run_cmd ip -netns "$testns" link set dev $DEV_NS up
845	run_cmd ip -netns "$testns" link del "$DEV_NS"
846
847	# test external mode
848	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap external
849	run_cmd ip -netns "$testns" link del "$DEV_NS"
850
851	if [ $ret -ne 0 ]; then
852		end_test "FAIL: ip6gretap"
853		ip netns del "$testns"
854		return 1
855	fi
856	end_test "PASS: ip6gretap"
857
858	ip netns del "$testns"
859}
860
861kci_test_erspan()
862{
863	DEV_NS=erspan00
864	local ret=0
865	run_cmd_grep "^Usage:" ip link help erspan
866	if [ $? -ne 0 ];then
867		end_test "SKIP: erspan: iproute2 too old"
868		return $ksft_skip
869	fi
870	setup_ns testns
871	if [ $? -ne 0 ]; then
872		end_test "SKIP erspan tests: cannot add net namespace $testns"
873		return $ksft_skip
874	fi
875
876	# test native tunnel erspan v1
877	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
878		key 102 local 172.16.1.100 remote 172.16.1.200 \
879		erspan_ver 1 erspan 488
880
881
882	run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
883	run_cmd ip -netns "$testns" link set dev $DEV_NS up
884	run_cmd ip -netns "$testns" link del "$DEV_NS"
885
886	# test native tunnel erspan v2
887	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
888		key 102 local 172.16.1.100 remote 172.16.1.200 \
889		erspan_ver 2 erspan_dir ingress erspan_hwid 7
890
891
892	run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
893	run_cmd ip -netns "$testns" link set dev $DEV_NS up
894	run_cmd ip -netns "$testns" link del "$DEV_NS"
895
896	# test external mode
897	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type erspan external
898	run_cmd ip -netns "$testns" link del "$DEV_NS"
899
900	if [ $ret -ne 0 ]; then
901		end_test "FAIL: erspan"
902		ip netns del "$testns"
903		return 1
904	fi
905	end_test "PASS: erspan"
906
907	ip netns del "$testns"
908}
909
910kci_test_ip6erspan()
911{
912	DEV_NS=ip6erspan00
913	local ret=0
914	run_cmd_grep "^Usage:" ip link help ip6erspan
915	if [ $? -ne 0 ];then
916		end_test "SKIP: ip6erspan: iproute2 too old"
917		return $ksft_skip
918	fi
919	setup_ns testns
920	if [ $? -ne 0 ]; then
921		end_test "SKIP ip6erspan tests: cannot add net namespace $testns"
922		return $ksft_skip
923	fi
924
925	# test native tunnel ip6erspan v1
926	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
927		key 102 local fc00:100::1 remote fc00:100::2 \
928		erspan_ver 1 erspan 488
929
930
931	run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
932	run_cmd ip -netns "$testns" link set dev $DEV_NS up
933	run_cmd ip -netns "$testns" link del "$DEV_NS"
934
935	# test native tunnel ip6erspan v2
936	run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
937		key 102 local fc00:100::1 remote fc00:100::2 \
938		erspan_ver 2 erspan_dir ingress erspan_hwid 7
939
940
941	run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
942	run_cmd ip -netns "$testns" link set dev $DEV_NS up
943	run_cmd ip -netns "$testns" link del "$DEV_NS"
944
945	# test external mode
946	run_cmd ip -netns "$testns" link add dev "$DEV_NS" \
947		type ip6erspan external
948
949	run_cmd ip -netns "$testns" link del "$DEV_NS"
950
951	if [ $ret -ne 0 ]; then
952		end_test "FAIL: ip6erspan"
953		ip netns del "$testns"
954		return 1
955	fi
956	end_test "PASS: ip6erspan"
957
958	ip netns del "$testns"
959}
960
961kci_test_fdb_get()
962{
963	brdev="test-br0"
964	vxlandev="vxlan10"
965	test_mac=de:ad:be:ef:13:37
966	localip="10.0.2.2"
967	dstip="10.0.2.3"
968	local ret=0
969
970	run_cmd_grep 'bridge fdb get' bridge fdb help
971	if [ $? -ne 0 ];then
972		end_test "SKIP: fdb get tests: iproute2 too old"
973		return $ksft_skip
974	fi
975
976	setup_ns testns
977	if [ $? -ne 0 ]; then
978		end_test "SKIP fdb get tests: cannot add net namespace $testns"
979		return $ksft_skip
980	fi
981	IP="ip -netns $testns"
982	BRIDGE="bridge -netns $testns"
983	run_cmd $IP link add "$vxlandev" type vxlan id 10 local $localip \
984                dstport 4789
985	run_cmd $IP link add name "$brdev" type bridge
986	run_cmd $IP link set dev "$vxlandev" master "$brdev"
987	run_cmd $BRIDGE fdb add $test_mac dev "$vxlandev" master
988	run_cmd $BRIDGE fdb add $test_mac dev "$vxlandev" dst $dstip self
989	run_cmd_grep "dev $vxlandev master $brdev" $BRIDGE fdb get $test_mac brport "$vxlandev"
990	run_cmd_grep "dev $vxlandev master $brdev" $BRIDGE fdb get $test_mac br "$brdev"
991	run_cmd_grep "dev $vxlandev dst $dstip" $BRIDGE fdb get $test_mac dev "$vxlandev" self
992
993	ip netns del $testns &>/dev/null
994
995	if [ $ret -ne 0 ]; then
996		end_test "FAIL: bridge fdb get"
997		return 1
998	fi
999
1000	end_test "PASS: bridge fdb get"
1001}
1002
1003kci_test_fdb_del()
1004{
1005	local test_mac=de:ad:be:ef:13:37
1006	local dummydev="dummy1"
1007	local brdev="test-br0"
1008	local ret=0
1009
1010	run_cmd_grep 'bridge fdb get' bridge fdb help
1011	if [ $? -ne 0 ]; then
1012		end_test "SKIP: fdb del tests: iproute2 too old"
1013		return $ksft_skip
1014	fi
1015
1016	setup_ns testns
1017	if [ $? -ne 0 ]; then
1018		end_test "SKIP fdb del tests: cannot add net namespace $testns"
1019		return $ksft_skip
1020	fi
1021	IP="ip -netns $testns"
1022	BRIDGE="bridge -netns $testns"
1023	run_cmd $IP link add $dummydev type dummy
1024	run_cmd $IP link add name $brdev type bridge vlan_filtering 1
1025	run_cmd $IP link set dev $dummydev master $brdev
1026	run_cmd $BRIDGE fdb add $test_mac dev $dummydev master static vlan 1
1027	run_cmd $BRIDGE vlan del vid 1 dev $dummydev
1028	run_cmd $BRIDGE fdb get $test_mac br $brdev vlan 1
1029	run_cmd $BRIDGE fdb del $test_mac dev $dummydev master vlan 1
1030	run_cmd_fail $BRIDGE fdb get $test_mac br $brdev vlan 1
1031
1032	ip netns del $testns &>/dev/null
1033
1034	if [ $ret -ne 0 ]; then
1035		end_test "FAIL: bridge fdb del"
1036		return 1
1037	fi
1038
1039	end_test "PASS: bridge fdb del"
1040}
1041
1042kci_test_neigh_get()
1043{
1044	dstmac=de:ad:be:ef:13:37
1045	dstip=10.0.2.4
1046	dstip6=dead::2
1047	local ret=0
1048
1049	run_cmd_grep 'ip neigh get' ip neigh help
1050	if [ $? -ne 0 ];then
1051		end_test "SKIP: fdb get tests: iproute2 too old"
1052		return $ksft_skip
1053	fi
1054
1055	# ipv4
1056	run_cmd ip neigh add $dstip lladdr $dstmac dev "$devdummy"
1057	run_cmd_grep "$dstmac" ip neigh get $dstip dev "$devdummy"
1058	run_cmd ip neigh del $dstip lladdr $dstmac dev "$devdummy"
1059
1060	# ipv4 proxy
1061	run_cmd ip neigh add proxy $dstip dev "$devdummy"
1062	run_cmd_grep "$dstip" ip neigh get proxy $dstip dev "$devdummy"
1063	run_cmd ip neigh del proxy $dstip dev "$devdummy"
1064
1065	# ipv6
1066	run_cmd ip neigh add $dstip6 lladdr $dstmac dev "$devdummy"
1067	run_cmd_grep "$dstmac" ip neigh get $dstip6 dev "$devdummy"
1068	run_cmd ip neigh del $dstip6 lladdr $dstmac dev "$devdummy"
1069
1070	# ipv6 proxy
1071	run_cmd ip neigh add proxy $dstip6 dev "$devdummy"
1072	run_cmd_grep "$dstip6" ip neigh get proxy $dstip6 dev "$devdummy"
1073	run_cmd ip neigh del proxy $dstip6 dev "$devdummy"
1074
1075	if [ $ret -ne 0 ];then
1076		end_test "FAIL: neigh get"
1077		return 1
1078	fi
1079
1080	end_test "PASS: neigh get"
1081}
1082
1083kci_test_bridge_parent_id()
1084{
1085	local ret=0
1086	sysfsnet=/sys/bus/netdevsim/devices/netdevsim
1087	probed=false
1088
1089	if [ ! -w /sys/bus/netdevsim/new_device ] ; then
1090		run_cmd modprobe -q netdevsim
1091		if [ $ret -ne 0 ]; then
1092			end_test "SKIP: bridge_parent_id can't load netdevsim"
1093			return $ksft_skip
1094		fi
1095		probed=true
1096	fi
1097
1098	echo "10 1" > /sys/bus/netdevsim/new_device
1099	while [ ! -d ${sysfsnet}10 ] ; do :; done
1100	echo "20 1" > /sys/bus/netdevsim/new_device
1101	while [ ! -d ${sysfsnet}20 ] ; do :; done
1102	udevadm settle
1103	dev10=`ls ${sysfsnet}10/net/`
1104	dev20=`ls ${sysfsnet}20/net/`
1105	run_cmd ip link add name test-bond0 type bond mode 802.3ad
1106	run_cmd ip link set dev $dev10 master test-bond0
1107	run_cmd ip link set dev $dev20 master test-bond0
1108	run_cmd ip link add name test-br0 type bridge
1109	run_cmd ip link set dev test-bond0 master test-br0
1110
1111	# clean up any leftovers
1112	ip link del dev test-br0
1113	ip link del dev test-bond0
1114	echo 20 > /sys/bus/netdevsim/del_device
1115	echo 10 > /sys/bus/netdevsim/del_device
1116	$probed && rmmod netdevsim
1117
1118	if [ $ret -ne 0 ]; then
1119		end_test "FAIL: bridge_parent_id"
1120		return 1
1121	fi
1122	end_test "PASS: bridge_parent_id"
1123}
1124
1125address_get_proto()
1126{
1127	local addr=$1; shift
1128
1129	ip -N -j address show dev "$devdummy" |
1130	    jq -e -r --arg addr "${addr%/*}" \
1131	       '.[].addr_info[] | select(.local == $addr) | .protocol'
1132}
1133
1134address_count()
1135{
1136	ip -N -j address show dev "$devdummy" "$@" |
1137	    jq -e -r '[.[].addr_info[] | .local | select(. != null)] | length'
1138}
1139
1140do_test_address_proto()
1141{
1142	local what=$1; shift
1143	local addr=$1; shift
1144	local addr2=${addr%/*}2/${addr#*/}
1145	local addr3=${addr%/*}3/${addr#*/}
1146	local proto
1147	local count
1148	local ret=0
1149	local err
1150
1151	ip address add dev "$devdummy" "$addr3"
1152	check_err $?
1153	proto=$(address_get_proto "$addr3")
1154	[[ "$proto" == null ]]
1155	check_err $?
1156
1157	ip address add dev "$devdummy" "$addr2" proto 0x99
1158	check_err $?
1159	proto=$(address_get_proto "$addr2")
1160	[[ "$proto" == 0x99 ]]
1161	check_err $?
1162
1163	ip address add dev "$devdummy" "$addr" proto 0xab
1164	check_err $?
1165	proto=$(address_get_proto "$addr")
1166	[[ "$proto" == 0xab ]]
1167	check_err $?
1168
1169	ip address replace dev "$devdummy" "$addr" proto 0x11
1170	proto=$(address_get_proto "$addr")
1171	check_err $?
1172	[[ "$proto" == 0x11 ]]
1173	check_err $?
1174
1175	count=$(address_count)
1176	check_err $?
1177	(( count >= 3 )) # $addr, $addr2 and $addr3 plus any kernel addresses
1178	check_err $?
1179
1180	count=$(address_count proto 0)
1181	check_err $?
1182	(( count == 1 )) # just $addr3
1183	check_err $?
1184
1185	count=$(address_count proto 0x11)
1186	check_err $?
1187	(( count == 2 )) # $addr and $addr3
1188	check_err $?
1189
1190	count=$(address_count proto 0xab)
1191	check_err $?
1192	(( count == 1 )) # just $addr3
1193	check_err $?
1194
1195	ip address del dev "$devdummy" "$addr"
1196	ip address del dev "$devdummy" "$addr2"
1197	ip address del dev "$devdummy" "$addr3"
1198
1199	if [ $ret -ne 0 ]; then
1200		end_test "FAIL: address proto $what"
1201		return 1
1202	fi
1203	end_test "PASS: address proto $what"
1204}
1205
1206kci_test_address_proto()
1207{
1208	local ret=0
1209
1210	do_test_address_proto IPv4 192.0.2.1/28
1211	check_err $?
1212
1213	do_test_address_proto IPv6 2001:db8:1::1/64
1214	check_err $?
1215
1216	return $ret
1217}
1218
1219kci_test_enslave_bonding()
1220{
1221	local bond="bond123"
1222	local ret=0
1223
1224	setup_ns testns
1225	if [ $? -ne 0 ]; then
1226		end_test "SKIP bonding tests: cannot add net namespace $testns"
1227		return $ksft_skip
1228	fi
1229
1230	run_cmd ip -netns $testns link add dev $bond type bond mode balance-rr
1231	run_cmd ip -netns $testns link add dev $devdummy type dummy
1232	run_cmd ip -netns $testns link set dev $devdummy up
1233	run_cmd ip -netns $testns link set dev $devdummy master $bond down
1234	if [ $ret -ne 0 ]; then
1235		end_test "FAIL: initially up interface added to a bond and set down"
1236		ip netns del "$testns"
1237		return 1
1238	fi
1239
1240	end_test "PASS: enslave interface in a bond"
1241	ip netns del "$testns"
1242}
1243
1244# Called to validate the addresses on $IFNAME:
1245#
1246# 1. Every `temporary` address must have a matching `mngtmpaddr`
1247# 2. Every `mngtmpaddr` address must have some un`deprecated` `temporary`
1248#
1249# If the mngtmpaddr or tempaddr checking failed, return 0 and stop slowwait
1250validate_mngtmpaddr()
1251{
1252	local dev=$1
1253	local prefix=""
1254	local addr_list=$(ip -j -n $testns addr show dev ${dev})
1255	local temp_addrs=$(echo ${addr_list} | \
1256		jq -r '.[].addr_info[] | select(.temporary == true) | .local')
1257	local mng_prefixes=$(echo ${addr_list} | \
1258		jq -r '.[].addr_info[] | select(.mngtmpaddr == true) | .local' | \
1259		cut -d: -f1-4 | tr '\n' ' ')
1260	local undep_prefixes=$(echo ${addr_list} | \
1261		jq -r '.[].addr_info[] | select(.temporary == true and .deprecated != true) | .local' | \
1262		cut -d: -f1-4 | tr '\n' ' ')
1263
1264	# 1. All temporary addresses (temp and dep) must have a matching mngtmpaddr
1265	for address in ${temp_addrs}; do
1266		prefix=$(echo ${address} | cut -d: -f1-4)
1267		if [[ ! " ${mng_prefixes} " =~ " $prefix " ]]; then
1268			check_err 1 "FAIL: Temporary $address with no matching mngtmpaddr!";
1269			return 0
1270		fi
1271	done
1272
1273	# 2. All mngtmpaddr addresses must have a temporary address (not dep)
1274	for prefix in ${mng_prefixes}; do
1275		if [[ ! " ${undep_prefixes} " =~ " $prefix " ]]; then
1276			check_err 1 "FAIL: No undeprecated temporary in $prefix!";
1277			return 0
1278		fi
1279	done
1280
1281	return 1
1282}
1283
1284kci_test_mngtmpaddr()
1285{
1286	local ret=0
1287
1288	setup_ns testns
1289	if [ $? -ne 0 ]; then
1290		end_test "SKIP mngtmpaddr tests: cannot add net namespace $testns"
1291		return $ksft_skip
1292	fi
1293
1294	# 1. Create a dummy Ethernet interface
1295	run_cmd ip -n $testns link add ${devdummy} type dummy
1296	run_cmd ip -n $testns link set ${devdummy} up
1297	run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.use_tempaddr=1
1298	run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.temp_prefered_lft=10
1299	run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.temp_valid_lft=25
1300	run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.max_desync_factor=1
1301
1302	# 2. Create several mngtmpaddr addresses on that interface.
1303	# with temp_*_lft configured to be pretty short (10 and 35 seconds
1304	# for prefer/valid respectively)
1305	for i in $(seq 1 9); do
1306		run_cmd ip -n $testns addr add 2001:db8:7e57:${i}::1/64 mngtmpaddr dev ${devdummy}
1307	done
1308
1309	# 3. Confirm that a preferred temporary address exists for each mngtmpaddr
1310	# address at all times, polling once per second for 30 seconds.
1311	slowwait 30 validate_mngtmpaddr ${devdummy}
1312
1313	# 4. Delete each mngtmpaddr address, one at a time (alternating between
1314	# deleting and merely un-mngtmpaddr-ing), and confirm that the other
1315	# mngtmpaddr addresses still have preferred temporaries.
1316	for i in $(seq 1 9); do
1317		(( $i % 4 == 0 )) && mng_flag="mngtmpaddr" || mng_flag=""
1318		if (( $i % 2 == 0 )); then
1319			run_cmd ip -n $testns addr del 2001:db8:7e57:${i}::1/64 $mng_flag dev ${devdummy}
1320		else
1321			run_cmd ip -n $testns addr change 2001:db8:7e57:${i}::1/64 dev ${devdummy}
1322		fi
1323		# the temp addr should be deleted
1324		validate_mngtmpaddr ${devdummy}
1325	done
1326
1327	if [ $ret -ne 0 ]; then
1328		end_test "FAIL: mngtmpaddr add/remove incorrect"
1329	else
1330		end_test "PASS: mngtmpaddr add/remove correctly"
1331	fi
1332
1333	ip netns del "$testns"
1334	return $ret
1335}
1336
1337kci_test_rtnl()
1338{
1339	local current_test
1340	local ret=0
1341
1342	kci_add_dummy
1343	if [ $ret -ne 0 ];then
1344		end_test "FAIL: cannot add dummy interface"
1345		return 1
1346	fi
1347
1348	for current_test in ${TESTS:-$ALL_TESTS}; do
1349		$current_test
1350		check_err $?
1351	done
1352
1353	kci_del_dummy
1354	return $ret
1355}
1356
1357usage()
1358{
1359	cat <<EOF
1360usage: ${0##*/} OPTS
1361
1362        -t <test>   Test(s) to run (default: all)
1363                    (options: $(echo $ALL_TESTS))
1364        -v          Verbose mode (show commands and output)
1365        -P          Pause after every test
1366        -p          Pause after every failing test before cleanup (for debugging)
1367EOF
1368}
1369
1370#check for needed privileges
1371if [ "$(id -u)" -ne 0 ];then
1372	end_test "SKIP: Need root privileges"
1373	exit $ksft_skip
1374fi
1375
1376for x in ip tc;do
1377	$x -Version 2>/dev/null >/dev/null
1378	if [ $? -ne 0 ];then
1379		end_test "SKIP: Could not run test without the $x tool"
1380		exit $ksft_skip
1381	fi
1382done
1383
1384while getopts t:hvpP o; do
1385	case $o in
1386		t) TESTS=$OPTARG;;
1387		v) VERBOSE=1;;
1388		p) PAUSE_ON_FAIL=yes;;
1389		P) PAUSE=yes;;
1390		h) usage; exit 0;;
1391		*) usage; exit 1;;
1392	esac
1393done
1394
1395[ $PAUSE = "yes" ] && PAUSE_ON_FAIL="no"
1396
1397kci_test_rtnl
1398
1399exit $?
1400