drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / rtnetlink.sh
blob2e8243a65b5070290385f3edd8aa3da81f9935fe
1 #!/bin/bash
3 # This test is for checking rtnetlink callpaths, and get as much coverage as possible.
5 # set -e
7 ALL_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
35 devdummy="test-dummy0"
36 VERBOSE=0
37 PAUSE=no
38 PAUSE_ON_FAIL=no
40 source lib.sh
42 # set global exit status, but never reset nonzero one.
43 check_err()
45 if [ $ret -eq 0 ]; then
46 ret=$1
48 [ -n "$2" ] && echo "$2"
51 # same but inverted -- used when command must fail for test to pass
52 check_fail()
54 if [ $1 -eq 0 ]; then
55 ret=1
59 run_cmd_common()
61 local cmd="$*"
62 local out
63 if [ "$VERBOSE" = "1" ]; then
64 echo "COMMAND: ${cmd}"
66 out=$($cmd 2>&1)
67 rc=$?
68 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
69 echo " $out"
71 return $rc
74 run_cmd() {
75 run_cmd_common "$@"
76 rc=$?
77 check_err $rc
78 return $rc
80 run_cmd_fail()
82 run_cmd_common "$@"
83 rc=$?
84 check_fail $rc
85 return $rc
88 run_cmd_grep_common()
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}'"
96 out=$($cmd 2>&1 | grep -q "${find}" 2>&1)
97 return $?
100 run_cmd_grep() {
101 run_cmd_grep_common "$@"
102 rc=$?
103 check_err $rc
104 return $rc
107 run_cmd_grep_fail()
109 run_cmd_grep_common "$@"
110 rc=$?
111 check_fail $rc
112 return $rc
115 end_test()
117 echo "$*"
118 [ "${VERBOSE}" = "1" ] && echo
120 if [[ $ret -ne 0 ]] && [[ "${PAUSE_ON_FAIL}" = "yes" ]]; then
121 echo "Hit enter to continue"
122 read a
125 if [ "${PAUSE}" = "yes" ]; then
126 echo "Hit enter to continue"
127 read a
133 kci_add_dummy()
135 run_cmd ip link add name "$devdummy" type dummy
136 run_cmd ip link set "$devdummy" up
139 kci_del_dummy()
141 run_cmd ip link del dev "$devdummy"
144 kci_test_netconf()
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
153 if [ $ret -ne 0 ] ;then
154 end_test "FAIL: ip netconf show $dev"
155 test $r -eq 0 && ret=0
156 return 1
160 # add a bridge with vlans on top
161 kci_test_bridge()
163 devbr="test-br0"
164 vlandev="testbr-vlan1"
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
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"
183 if [ $ret -ne 0 ];then
184 end_test "FAIL: bridge setup"
185 return 1
187 end_test "PASS: bridge setup"
191 kci_test_gre()
193 gredev=neta
194 rem=10.42.42.1
195 loc=10.0.0.1
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
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
210 if [ $ret -ne 0 ];then
211 end_test "FAIL: gre tunnel endpoint"
212 return 1
214 end_test "PASS: gre tunnel endpoint"
217 # tc uses rtnetlink too, for full tc testing
218 # please see tools/testing/selftests/tc-testing.
219 kci_test_tc()
221 dev=lo
222 local ret=0
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
236 if [ $ret -ne 0 ];then
237 end_test "FAIL: tc htb hierarchy"
238 return 1
240 end_test "PASS: tc htb hierarchy"
244 kci_test_polrouting()
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
253 if [ $ret -ne 0 ];then
254 end_test "FAIL: policy route test"
255 return 1
257 end_test "PASS: policy routing"
260 kci_test_route_get()
262 local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
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"
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
286 if [ $ret -ne 0 ];then
287 end_test "FAIL: route get"
288 return 1
291 end_test "PASS: route get"
294 kci_test_addrlft()
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
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
309 end_test "PASS: preferred_lft addresses have expired"
312 kci_test_promote_secondaries()
314 promote=$(sysctl -n net.ipv4.conf.$devdummy.promote_secondaries)
316 sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=1
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
324 ip addr flush dev "$devdummy"
326 [ $promote -eq 0 ] && sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=0
328 end_test "PASS: promote_secondaries complete"
331 kci_test_addrlabel()
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
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 &
345 for i in $(seq 1 1000); do
346 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
347 done
349 wait
351 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
353 if [ $ret -ne 0 ];then
354 end_test "FAIL: ipv6 addrlabel"
355 return 1
358 end_test "PASS: ipv6 addrlabel"
361 kci_test_ifalias()
363 local ret=0
364 namewant=$(uuidgen)
365 syspathname="/sys/class/net/$devdummy/ifalias"
366 run_cmd ip link set dev "$devdummy" alias "$namewant"
368 if [ $ret -ne 0 ]; then
369 end_test "FAIL: cannot set interface alias of $devdummy to $namewant"
370 return 1
372 run_cmd_grep "alias $namewant" ip link show "$devdummy"
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
381 namewant=$(uuidgen)
382 echo "$namewant" > "$syspathname"
383 run_cmd_grep "alias $namewant" ip link show "$devdummy"
385 # sysfs interface allows to delete alias again
386 echo "" > "$syspathname"
387 run_cmd_grep_fail "alias $namewant" ip link show "$devdummy"
389 for i in $(seq 1 100); do
390 uuidgen > "$syspathname" &
391 done
393 wait
395 # re-add the alias -- kernel should free mem when dummy dev is removed
396 run_cmd ip link set dev "$devdummy" alias "$namewant"
400 if [ $ret -ne 0 ]; then
401 end_test "FAIL: set interface alias $devdummy to $namewant"
402 return 1
405 end_test "PASS: set ifalias $namewant for $devdummy"
408 kci_test_vrf()
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
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
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
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"
432 if [ $ret -ne 0 ];then
433 end_test "FAIL: vrf"
434 return 1
437 end_test "PASS: vrf"
440 kci_test_encap_vxlan()
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
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
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
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
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"
478 if [ $ret -ne 0 ]; then
479 end_test "FAIL: vxlan"
480 return 1
482 end_test "PASS: vxlan"
485 kci_test_encap_fou()
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
495 if ! /sbin/modprobe -q -n fou; then
496 end_test "SKIP: module fou is not found"
497 return $ksft_skip
499 /sbin/modprobe -q fou
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
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
514 end_test "PASS: fou"
517 # test various encap methods, use netns to avoid unwanted interference
518 kci_test_encap()
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
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
532 ip netns del "$testns"
533 return $ret
536 kci_test_macsec()
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
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
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"
556 if [ $ret -ne 0 ];then
557 end_test "FAIL: macsec"
558 return 1
561 end_test "PASS: macsec"
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
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 #-------------------------------------------------------------------
582 kci_test_ipsec()
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
590 ip addr add $srcip dev $devdummy
592 # flush to be sure there's nothing configured
593 run_cmd ip x s flush ; ip x p flush
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
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
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
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
614 lines=`ip x s list | wc -l`
615 run_cmd test $lines -eq 0
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
623 lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
624 run_cmd test $lines -eq 2
626 run_cmd_grep "SPD IN 0 OUT 1 FWD 0" ip x p count
628 lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
629 run_cmd test $lines -eq 2
631 run_cmd ip x p delete $ipsecsel
633 lines=`ip x p list | wc -l`
634 run_cmd test $lines -eq 0
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
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
647 if [ $ret -ne 0 ]; then
648 end_test "FAIL: ipsec"
649 return 1
651 end_test "PASS: ipsec"
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
665 #-------------------------------------------------------------------
666 kci_test_ipsec_offload()
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
677 if ! mount | grep -q debugfs; then
678 mount -t debugfs none /sys/kernel/debug/ &> /dev/null
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
688 probed=true
691 echo "0" > /sys/bus/netdevsim/new_device
692 while [ ! -d $sysfsnet ] ; do :; done
693 udevadm settle
694 dev=`ls $sysfsnet`
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
702 if [ ! -f $sysfsf ] ; then
703 end_test "FAIL: ipsec_offload netdevsim doesn't support IPsec offload"
704 return 1
707 # flush to be sure there's nothing configured
708 ip x s flush ; ip x p flush
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
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
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
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
727 if [ $ret -ne 0 ]; then
728 end_test "FAIL: ipsec_offload can't create SA"
729 return 1
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"
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
744 # does driver have correct offload info
745 run_cmd diff $sysfsf - << EOF
746 SA count=2 tx=3
747 sa[0] tx ipaddr=$dstip
748 sa[0] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
749 sa[0] key=0x34333231 38373635 32313039 36353433
750 sa[1] rx ipaddr=$srcip
751 sa[1] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
752 sa[1] key=0x34333231 38373635 32313039 36353433
754 if [ $? -ne 0 ] ; then
755 end_test "FAIL: ipsec_offload incorrect driver data"
756 check_err 1
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"
768 # clean up any leftovers
769 echo 0 > /sys/bus/netdevsim/del_device
770 $probed && rmmod netdevsim
772 if [ $ret -ne 0 ]; then
773 end_test "FAIL: ipsec_offload"
774 return 1
776 end_test "PASS: ipsec_offload"
779 kci_test_gretap()
781 DEV_NS=gretap00
782 local ret=0
784 setup_ns testns
785 if [ $? -ne 0 ]; then
786 end_test "SKIP gretap tests: cannot add net namespace $testns"
787 return $ksft_skip
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
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
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"
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"
810 if [ $ret -ne 0 ]; then
811 end_test "FAIL: gretap"
812 ip netns del "$testns"
813 return 1
815 end_test "PASS: gretap"
817 ip netns del "$testns"
820 kci_test_ip6gretap()
822 DEV_NS=ip6gretap00
823 local ret=0
825 setup_ns testns
826 if [ $? -ne 0 ]; then
827 end_test "SKIP ip6gretap tests: cannot add net namespace $testns"
828 return $ksft_skip
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
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
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"
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"
851 if [ $ret -ne 0 ]; then
852 end_test "FAIL: ip6gretap"
853 ip netns del "$testns"
854 return 1
856 end_test "PASS: ip6gretap"
858 ip netns del "$testns"
861 kci_test_erspan()
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
870 setup_ns testns
871 if [ $? -ne 0 ]; then
872 end_test "SKIP erspan tests: cannot add net namespace $testns"
873 return $ksft_skip
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
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"
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
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"
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"
900 if [ $ret -ne 0 ]; then
901 end_test "FAIL: erspan"
902 ip netns del "$testns"
903 return 1
905 end_test "PASS: erspan"
907 ip netns del "$testns"
910 kci_test_ip6erspan()
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
919 setup_ns testns
920 if [ $? -ne 0 ]; then
921 end_test "SKIP ip6erspan tests: cannot add net namespace $testns"
922 return $ksft_skip
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
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"
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
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"
945 # test external mode
946 run_cmd ip -netns "$testns" link add dev "$DEV_NS" \
947 type ip6erspan external
949 run_cmd ip -netns "$testns" link del "$DEV_NS"
951 if [ $ret -ne 0 ]; then
952 end_test "FAIL: ip6erspan"
953 ip netns del "$testns"
954 return 1
956 end_test "PASS: ip6erspan"
958 ip netns del "$testns"
961 kci_test_fdb_get()
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
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
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
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
993 ip netns del $testns &>/dev/null
995 if [ $ret -ne 0 ]; then
996 end_test "FAIL: bridge fdb get"
997 return 1
1000 end_test "PASS: bridge fdb get"
1003 kci_test_fdb_del()
1005 local test_mac=de:ad:be:ef:13:37
1006 local dummydev="dummy1"
1007 local brdev="test-br0"
1008 local ret=0
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
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
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
1032 ip netns del $testns &>/dev/null
1034 if [ $ret -ne 0 ]; then
1035 end_test "FAIL: bridge fdb del"
1036 return 1
1039 end_test "PASS: bridge fdb del"
1042 kci_test_neigh_get()
1044 dstmac=de:ad:be:ef:13:37
1045 dstip=10.0.2.4
1046 dstip6=dead::2
1047 local ret=0
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
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"
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"
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"
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"
1075 if [ $ret -ne 0 ];then
1076 end_test "FAIL: neigh get"
1077 return 1
1080 end_test "PASS: neigh get"
1083 kci_test_bridge_parent_id()
1085 local ret=0
1086 sysfsnet=/sys/bus/netdevsim/devices/netdevsim
1087 probed=false
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
1095 probed=true
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
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
1118 if [ $ret -ne 0 ]; then
1119 end_test "FAIL: bridge_parent_id"
1120 return 1
1122 end_test "PASS: bridge_parent_id"
1125 address_get_proto()
1127 local addr=$1; shift
1129 ip -N -j address show dev "$devdummy" |
1130 jq -e -r --arg addr "${addr%/*}" \
1131 '.[].addr_info[] | select(.local == $addr) | .protocol'
1134 address_count()
1136 ip -N -j address show dev "$devdummy" "$@" |
1137 jq -e -r '[.[].addr_info[] | .local | select(. != null)] | length'
1140 do_test_address_proto()
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
1151 ip address add dev "$devdummy" "$addr3"
1152 check_err $?
1153 proto=$(address_get_proto "$addr3")
1154 [[ "$proto" == null ]]
1155 check_err $?
1157 ip address add dev "$devdummy" "$addr2" proto 0x99
1158 check_err $?
1159 proto=$(address_get_proto "$addr2")
1160 [[ "$proto" == 0x99 ]]
1161 check_err $?
1163 ip address add dev "$devdummy" "$addr" proto 0xab
1164 check_err $?
1165 proto=$(address_get_proto "$addr")
1166 [[ "$proto" == 0xab ]]
1167 check_err $?
1169 ip address replace dev "$devdummy" "$addr" proto 0x11
1170 proto=$(address_get_proto "$addr")
1171 check_err $?
1172 [[ "$proto" == 0x11 ]]
1173 check_err $?
1175 count=$(address_count)
1176 check_err $?
1177 (( count >= 3 )) # $addr, $addr2 and $addr3 plus any kernel addresses
1178 check_err $?
1180 count=$(address_count proto 0)
1181 check_err $?
1182 (( count == 1 )) # just $addr3
1183 check_err $?
1185 count=$(address_count proto 0x11)
1186 check_err $?
1187 (( count == 2 )) # $addr and $addr3
1188 check_err $?
1190 count=$(address_count proto 0xab)
1191 check_err $?
1192 (( count == 1 )) # just $addr3
1193 check_err $?
1195 ip address del dev "$devdummy" "$addr"
1196 ip address del dev "$devdummy" "$addr2"
1197 ip address del dev "$devdummy" "$addr3"
1199 if [ $ret -ne 0 ]; then
1200 end_test "FAIL: address proto $what"
1201 return 1
1203 end_test "PASS: address proto $what"
1206 kci_test_address_proto()
1208 local ret=0
1210 do_test_address_proto IPv4 192.0.2.1/28
1211 check_err $?
1213 do_test_address_proto IPv6 2001:db8:1::1/64
1214 check_err $?
1216 return $ret
1219 kci_test_enslave_bonding()
1221 local bond="bond123"
1222 local ret=0
1224 setup_ns testns
1225 if [ $? -ne 0 ]; then
1226 end_test "SKIP bonding tests: cannot add net namespace $testns"
1227 return $ksft_skip
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
1240 end_test "PASS: enslave interface in a bond"
1241 ip netns del "$testns"
1244 # Called to validate the addresses on $IFNAME:
1246 # 1. Every `temporary` address must have a matching `mngtmpaddr`
1247 # 2. Every `mngtmpaddr` address must have some un`deprecated` `temporary`
1249 # If the mngtmpaddr or tempaddr checking failed, return 0 and stop slowwait
1250 validate_mngtmpaddr()
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' ' ')
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
1271 done
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
1279 done
1281 return 1
1284 kci_test_mngtmpaddr()
1286 local ret=0
1288 setup_ns testns
1289 if [ $? -ne 0 ]; then
1290 end_test "SKIP mngtmpaddr tests: cannot add net namespace $testns"
1291 return $ksft_skip
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
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
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}
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}
1323 # the temp addr should be deleted
1324 validate_mngtmpaddr ${devdummy}
1325 done
1327 if [ $ret -ne 0 ]; then
1328 end_test "FAIL: mngtmpaddr add/remove incorrect"
1329 else
1330 end_test "PASS: mngtmpaddr add/remove correctly"
1333 ip netns del "$testns"
1334 return $ret
1337 kci_test_rtnl()
1339 local current_test
1340 local ret=0
1342 kci_add_dummy
1343 if [ $ret -ne 0 ];then
1344 end_test "FAIL: cannot add dummy interface"
1345 return 1
1348 for current_test in ${TESTS:-$ALL_TESTS}; do
1349 $current_test
1350 check_err $?
1351 done
1353 kci_del_dummy
1354 return $ret
1357 usage()
1359 cat <<EOF
1360 usage: ${0##*/} OPTS
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)
1370 #check for needed privileges
1371 if [ "$(id -u)" -ne 0 ];then
1372 end_test "SKIP: Need root privileges"
1373 exit $ksft_skip
1376 for 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
1382 done
1384 while 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
1393 done
1395 [ $PAUSE = "yes" ] && PAUSE_ON_FAIL="no"
1397 kci_test_rtnl
1399 exit $?