3 # This test is for checking rtnetlink callpaths, and get as much coverage as possible.
11 kci_test_promote_secondaries
25 kci_test_ipsec_offload
29 kci_test_bridge_parent_id
30 kci_test_address_proto
31 kci_test_enslave_bonding
35 devdummy="test-dummy0"
42 # set global exit status, but never reset nonzero one.
45 if [ $ret -eq 0 ]; then
48 [ -n "$2" ] && echo "$2"
51 # same but inverted -- used when command must fail for test to pass
63 if [ "$VERBOSE" = "1" ]; then
64 echo "COMMAND: ${cmd}"
68 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
90 local find="$1"; shift
93 if [ "$VERBOSE" = "1" ]; then
94 echo "COMMAND: ${cmd} 2>&1 | grep -q '${find}'"
96 out=$($cmd 2>&1 | grep -q "${find}" 2>&1)
101 run_cmd_grep_common "$@"
109 run_cmd_grep_common "$@"
118 [ "${VERBOSE}" = "1" ] && echo
120 if [[ $ret -ne 0 ]] && [[ "${PAUSE_ON_FAIL}" = "yes" ]]; then
121 echo "Hit enter to continue"
125 if [ "${PAUSE}" = "yes" ]; then
126 echo "Hit enter to continue"
135 run_cmd ip link add name "$devdummy" type dummy
136 run_cmd ip link set "$devdummy" up
141 run_cmd ip link del dev "$devdummy"
148 run_cmd ip netconf show dev "$dev"
150 run_cmd ip -$f netconf show dev "$dev"
153 if [ $ret -ne 0 ] ;then
154 end_test "FAIL: ip netconf show $dev"
155 test $r -eq 0 && ret=0
160 # add a bridge with vlans on top
164 vlandev="testbr-vlan1"
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
176 for name in "$devbr" "$vlandev" "$devdummy" ; do
177 kci_test_netconf "$name"
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"
187 end_test "PASS: bridge setup"
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
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"
214 end_test "PASS: gre tunnel endpoint"
217 # tc uses rtnetlink too, for full tc testing
218 # please see tools/testing/selftests/tc-testing.
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"
240 end_test "PASS: tc htb hierarchy"
244 kci_test_polrouting()
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
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"
257 end_test "PASS: policy routing"
262 local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
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"
291 end_test "PASS: route get"
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))
302 run_cmd_grep_fail "10.23.11." ip addr show dev "$devdummy"
303 if [ $? -eq 0 ]; then
305 end_test "FAIL: preferred_lft addresses remaining"
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
320 ip -f inet addr add $IP/16 brd + dev "$devdummy"
321 ifconfig "$devdummy" $IP netmask 255.255.0.0
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"
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
345 for i in $(seq 1 1000); do
346 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
351 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
353 if [ $ret -ne 0 ];then
354 end_test "FAIL: ipv6 addrlabel"
358 end_test "PASS: ipv6 addrlabel"
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"
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"
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" &
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"
405 end_test "PASS: set ifalias $namewant for $devdummy"
412 run_cmd ip link show type vrf
413 if [ $? -ne 0 ]; then
414 end_test "SKIP: vrf: iproute2 too old"
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"
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"
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
440 kci_test_encap_vxlan()
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"
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"
482 end_test "PASS: vxlan"
489 run_cmd_grep 'Usage: ip fou' ip fou help
491 end_test "SKIP: fou: iproute2 too old"
495 if ! /sbin/modprobe -q -n fou; then
496 end_test "SKIP: module fou is not found"
499 /sbin/modprobe -q fou
501 run_cmd ip -netns "$testns" fou add port 7777 ipproto 47
503 end_test "FAIL: can't add fou port 7777, skipping test"
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
517 # test various encap methods, use netns to avoid unwanted interference
522 if [ $? -ne 0 ]; then
523 end_test "SKIP encap tests: cannot add net namespace $testns"
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"
538 msname="test_macsec0"
540 run_cmd_grep "^Usage: ip macsec" ip macsec help
541 if [ $? -ne 0 ]; then
542 end_test "SKIP: macsec: iproute2 too old"
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"
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"
561 end_test "PASS: macsec"
564 #-------------------------------------------------------------------
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
581 #-------------------------------------------------------------------
585 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
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`
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
638 lines=`wc -l $tmpfile | cut "-d " -f1`
639 run_cmd test $lines -eq 20
642 # clean up any leftovers
645 ip addr del $srcip/32 dev $devdummy
647 if [ $ret -ne 0 ]; then
648 end_test "FAIL: ipsec"
651 end_test "PASS: ipsec"
654 #-------------------------------------------------------------------
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()
669 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
672 sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
674 sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
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"
691 echo "0" > /sys/bus/netdevsim/new_device
692 while [ ! -d $sysfsnet ] ; do :; done
696 ip addr add $srcip dev $dev
698 if [ ! -d $sysfsd ] ; then
699 end_test "FAIL: ipsec_offload can't create device $dev"
702 if [ ! -f $sysfsf ] ; then
703 end_test "FAIL: ipsec_offload netdevsim doesn't support IPsec offload"
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"
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
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
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"
759 # does offload get removed from driver
762 lines=`grep -c "SA count=0" $sysfsf`
763 if [ $lines -ne 1 ] ; then
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"
776 end_test "PASS: ipsec_offload"
785 if [ $? -ne 0 ]; then
786 end_test "SKIP gretap tests: cannot add net namespace $testns"
790 run_cmd_grep "^Usage:" ip link help gretap
792 end_test "SKIP: gretap: iproute2 too old"
793 ip netns del "$testns"
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"
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"
815 end_test "PASS: gretap"
817 ip netns del "$testns"
826 if [ $? -ne 0 ]; then
827 end_test "SKIP ip6gretap tests: cannot add net namespace $testns"
831 run_cmd_grep "^Usage:" ip link help ip6gretap
833 end_test "SKIP: ip6gretap: iproute2 too old"
834 ip netns del "$testns"
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"
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"
856 end_test "PASS: ip6gretap"
858 ip netns del "$testns"
865 run_cmd_grep "^Usage:" ip link help erspan
867 end_test "SKIP: erspan: iproute2 too old"
871 if [ $? -ne 0 ]; then
872 end_test "SKIP erspan tests: cannot add net namespace $testns"
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"
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"
905 end_test "PASS: erspan"
907 ip netns del "$testns"
914 run_cmd_grep "^Usage:" ip link help ip6erspan
916 end_test "SKIP: ip6erspan: iproute2 too old"
920 if [ $? -ne 0 ]; then
921 end_test "SKIP ip6erspan tests: cannot add net namespace $testns"
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"
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"
956 end_test "PASS: ip6erspan"
958 ip netns del "$testns"
965 test_mac=de:ad:be:ef:13:37
970 run_cmd_grep 'bridge fdb get' bridge fdb help
972 end_test "SKIP: fdb get tests: iproute2 too old"
977 if [ $? -ne 0 ]; then
978 end_test "SKIP fdb get tests: cannot add net namespace $testns"
981 IP="ip -netns $testns"
982 BRIDGE="bridge -netns $testns"
983 run_cmd $IP link add "$vxlandev" type vxlan id 10 local $localip \
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"
1000 end_test "PASS: bridge fdb get"
1005 local test_mac=de:ad:be:ef:13:37
1006 local dummydev="dummy1"
1007 local brdev="test-br0"
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"
1017 if [ $? -ne 0 ]; then
1018 end_test "SKIP fdb del tests: cannot add net namespace $testns"
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"
1039 end_test "PASS: bridge fdb del"
1042 kci_test_neigh_get()
1044 dstmac=de:ad:be:ef:13:37
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"
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"
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"
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"
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"
1080 end_test "PASS: neigh get"
1083 kci_test_bridge_parent_id()
1086 sysfsnet=/sys/bus/netdevsim/devices/netdevsim
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"
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
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"
1122 end_test "PASS: bridge_parent_id"
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'
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#*/}
1151 ip address add dev "$devdummy" "$addr3"
1153 proto=$(address_get_proto "$addr3")
1154 [[ "$proto" == null ]]
1157 ip address add dev "$devdummy" "$addr2" proto 0x99
1159 proto=$(address_get_proto "$addr2")
1160 [[ "$proto" == 0x99 ]]
1163 ip address add dev "$devdummy" "$addr" proto 0xab
1165 proto=$(address_get_proto "$addr")
1166 [[ "$proto" == 0xab ]]
1169 ip address replace dev "$devdummy" "$addr" proto 0x11
1170 proto=$(address_get_proto "$addr")
1172 [[ "$proto" == 0x11 ]]
1175 count=$(address_count)
1177 (( count >= 3 )) # $addr, $addr2 and $addr3 plus any kernel addresses
1180 count=$(address_count proto 0)
1182 (( count == 1 )) # just $addr3
1185 count=$(address_count proto 0x11)
1187 (( count == 2 )) # $addr and $addr3
1190 count=$(address_count proto 0xab)
1192 (( count == 1 )) # just $addr3
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"
1203 end_test "PASS: address proto $what"
1206 kci_test_address_proto()
1210 do_test_address_proto IPv4 192.0.2.1/28
1213 do_test_address_proto IPv6 2001:db8:1::1/64
1219 kci_test_enslave_bonding()
1221 local bond="bond123"
1225 if [ $? -ne 0 ]; then
1226 end_test "SKIP bonding tests: cannot add net namespace $testns"
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"
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()
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!";
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!";
1284 kci_test_mngtmpaddr()
1289 if [ $? -ne 0 ]; then
1290 end_test "SKIP mngtmpaddr tests: cannot add net namespace $testns"
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}
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}
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}
1327 if [ $ret -ne 0 ]; then
1328 end_test "FAIL: mngtmpaddr add/remove incorrect"
1330 end_test "PASS: mngtmpaddr add/remove correctly"
1333 ip netns del "$testns"
1343 if [ $ret -ne 0 ];then
1344 end_test "FAIL: cannot add dummy interface"
1348 for current_test in ${TESTS:-$ALL_TESTS}; do
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"
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"
1384 while getopts t:hvpP o; do
1388 p) PAUSE_ON_FAIL=yes;;
1395 [ $PAUSE = "yes" ] && PAUSE_ON_FAIL="no"