3 # This test is for checking rtnetlink callpaths, and get as much coverage as possible.
11 kci_test_promote_secondaries
24 kci_test_macsec_offload
26 kci_test_ipsec_offload
29 kci_test_bridge_parent_id
30 kci_test_address_proto
33 devdummy="test-dummy0"
35 # Kselftest framework requirement - SKIP code is 4.
38 # set global exit status, but never reset nonzero one.
41 if [ $ret -eq 0 ]; then
46 # same but inverted -- used when command must fail for test to pass
56 ip link add name "$devdummy" type dummy
58 ip link set "$devdummy" up
64 ip link del dev "$devdummy"
73 ip netconf show dev "$dev" > /dev/null
77 ip -$f netconf show dev "$dev" > /dev/null
81 if [ $ret -ne 0 ] ;then
82 echo "FAIL: ip netconf show $dev"
83 test $r -eq 0 && ret=0
88 # add a bridge with vlans on top
92 vlandev="testbr-vlan1"
95 ip link add name "$devbr" type bridge
98 ip link set dev "$devdummy" master "$devbr"
101 ip link set "$devbr" up
104 ip link add link "$devbr" name "$vlandev" type vlan id 1
106 ip addr add dev "$vlandev" 10.200.7.23/30
108 ip -6 addr add dev "$vlandev" dead:42::1234/64
110 ip -d link > /dev/null
112 ip r s t all > /dev/null
115 for name in "$devbr" "$vlandev" "$devdummy" ; do
116 kci_test_netconf "$name"
119 ip -6 addr del dev "$vlandev" dead:42::1234/64
122 ip link del dev "$vlandev"
124 ip link del dev "$devbr"
127 if [ $ret -ne 0 ];then
128 echo "FAIL: bridge setup"
131 echo "PASS: bridge setup"
142 ip tunnel add $gredev mode gre remote $rem local $loc ttl 1
144 ip link set $gredev up
146 ip addr add 10.23.7.10 dev $gredev
148 ip route add 10.23.8.0/30 dev $gredev
150 ip addr add dev "$devdummy" 10.23.7.11/24
157 kci_test_netconf "$gredev"
159 ip addr del dev "$devdummy" 10.23.7.11/24
165 if [ $ret -ne 0 ];then
166 echo "FAIL: gre tunnel endpoint"
169 echo "PASS: gre tunnel endpoint"
172 # tc uses rtnetlink too, for full tc testing
173 # please see tools/testing/selftests/tc-testing.
179 tc qdisc add dev "$dev" root handle 1: htb
181 tc class add dev "$dev" parent 1: classid 1:10 htb rate 1mbit
183 tc filter add dev "$dev" parent 1:0 prio 5 handle ffe: protocol ip u32 divisor 256
185 tc filter add dev "$dev" parent 1:0 prio 5 handle ffd: protocol ip u32 divisor 256
187 tc filter add dev "$dev" parent 1:0 prio 5 handle ffc: protocol ip u32 divisor 256
189 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
191 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
193 tc filter show dev "$dev" parent 1:0 > /dev/null
195 tc filter del dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32
197 tc filter show dev "$dev" parent 1:0 > /dev/null
199 tc qdisc del dev "$dev" root handle 1: htb
202 if [ $ret -ne 0 ];then
203 echo "FAIL: tc htb hierarchy"
206 echo "PASS: tc htb hierarchy"
210 kci_test_polrouting()
213 ip rule add fwmark 1 lookup 100
215 ip route add local 0.0.0.0/0 dev lo table 100
217 ip r s t all > /dev/null
219 ip rule del fwmark 1 lookup 100
221 ip route del local 0.0.0.0/0 dev lo table 100
224 if [ $ret -ne 0 ];then
225 echo "FAIL: policy route test"
228 echo "PASS: policy routing"
233 local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
237 ip route get 127.0.0.1 > /dev/null
239 ip route get 127.0.0.1 dev "$devdummy" > /dev/null
241 ip route get ::1 > /dev/null
243 ip route get fe80::1 dev "$devdummy" > /dev/null
245 ip route get 127.0.0.1 from 127.0.0.1 oif lo tos 0x10 mark 0x1 > /dev/null
247 ip route get ::1 from ::1 iif lo oif lo tos 0x10 mark 0x1 > /dev/null
249 ip addr add dev "$devdummy" 10.23.7.11/24
251 ip route get 10.23.7.11 from 10.23.7.12 iif "$devdummy" > /dev/null
253 ip route add 10.23.8.0/24 \
254 nexthop via 10.23.7.13 dev "$devdummy" \
255 nexthop via 10.23.7.14 dev "$devdummy"
257 sysctl -wq net.ipv4.fib_multipath_hash_policy=0
258 ip route get 10.23.8.11 > /dev/null
260 sysctl -wq net.ipv4.fib_multipath_hash_policy=1
261 ip route get 10.23.8.11 > /dev/null
263 sysctl -wq net.ipv4.fib_multipath_hash_policy="$hash_policy"
264 ip route del 10.23.8.0/24
266 ip addr del dev "$devdummy" 10.23.7.11/24
269 if [ $ret -ne 0 ];then
270 echo "FAIL: route get"
274 echo "PASS: route get"
279 for i in $(seq 10 100) ;do
280 lft=$(((RANDOM%3) + 1))
281 ip addr add 10.23.11.$i/32 dev "$devdummy" preferred_lft $lft valid_lft $((lft+1))
287 ip addr show dev "$devdummy" | grep "10.23.11."
288 if [ $? -eq 0 ]; then
289 echo "FAIL: preferred_lft addresses remaining"
294 echo "PASS: preferred_lft addresses have expired"
297 kci_test_promote_secondaries()
299 promote=$(sysctl -n net.ipv4.conf.$devdummy.promote_secondaries)
301 sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=1
303 for i in $(seq 2 254);do
305 ip -f inet addr add $IP/16 brd + dev "$devdummy"
306 ifconfig "$devdummy" $IP netmask 255.255.0.0
309 ip addr flush dev "$devdummy"
311 [ $promote -eq 0 ] && sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=0
313 echo "PASS: promote_secondaries complete"
320 ip addrlabel add prefix dead::/64 dev lo label 1
323 ip addrlabel list |grep -q "prefix dead::/64 dev lo label 1"
326 ip addrlabel del prefix dead::/64 dev lo label 1 2> /dev/null
329 ip addrlabel add prefix dead::/64 label 1 2> /dev/null
332 ip addrlabel del prefix dead::/64 label 1 2> /dev/null
335 # concurrent add/delete
336 for i in $(seq 1 1000); do
337 ip addrlabel add prefix 1c3::/64 label 12345 2>/dev/null
340 for i in $(seq 1 1000); do
341 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
346 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
348 if [ $ret -ne 0 ];then
349 echo "FAIL: ipv6 addrlabel"
353 echo "PASS: ipv6 addrlabel"
360 syspathname="/sys/class/net/$devdummy/ifalias"
362 ip link set dev "$devdummy" alias "$namewant"
365 if [ $ret -ne 0 ]; then
366 echo "FAIL: cannot set interface alias of $devdummy to $namewant"
370 ip link show "$devdummy" | grep -q "alias $namewant"
373 if [ -r "$syspathname" ] ; then
374 read namehave < "$syspathname"
375 if [ "$namewant" != "$namehave" ]; then
376 echo "FAIL: did set ifalias $namewant but got $namehave"
381 echo "$namewant" > "$syspathname"
382 ip link show "$devdummy" | grep -q "alias $namewant"
385 # sysfs interface allows to delete alias again
386 echo "" > "$syspathname"
388 ip link show "$devdummy" | grep -q "alias $namewant"
391 for i in $(seq 1 100); do
392 uuidgen > "$syspathname" &
397 # re-add the alias -- kernel should free mem when dummy dev is removed
398 ip link set dev "$devdummy" alias "$namewant"
402 if [ $ret -ne 0 ]; then
403 echo "FAIL: set interface alias $devdummy to $namewant"
407 echo "PASS: set ifalias $namewant for $devdummy"
415 ip link show type vrf 2>/dev/null
416 if [ $? -ne 0 ]; then
417 echo "SKIP: vrf: iproute2 too old"
421 ip link add "$vrfname" type vrf table 10
423 if [ $ret -ne 0 ];then
424 echo "FAIL: can't add vrf interface, skipping test"
428 ip -br link show type vrf | grep -q "$vrfname"
430 if [ $ret -ne 0 ];then
431 echo "FAIL: created vrf device not found"
435 ip link set dev "$vrfname" up
438 ip link set dev "$devdummy" master "$vrfname"
440 ip link del dev "$vrfname"
443 if [ $ret -ne 0 ];then
451 kci_test_encap_vxlan()
458 ip -netns "$testns" link add "$vxlan" type vxlan id 42 group 239.1.1.1 \
459 dev "$devdummy" dstport 4789 2>/dev/null
460 if [ $? -ne 0 ]; then
461 echo "FAIL: can't add vxlan interface, skipping test"
466 ip -netns "$testns" addr add 10.2.11.49/24 dev "$vxlan"
469 ip -netns "$testns" link set up dev "$vxlan"
472 ip -netns "$testns" link add link "$vxlan" name "$vlan" type vlan id 1
475 # changelink testcases
476 ip -netns "$testns" link set dev "$vxlan" type vxlan vni 43 2>/dev/null
479 ip -netns "$testns" link set dev "$vxlan" type vxlan group ffe5::5 dev "$devdummy" 2>/dev/null
482 ip -netns "$testns" link set dev "$vxlan" type vxlan ttl inherit 2>/dev/null
485 ip -netns "$testns" link set dev "$vxlan" type vxlan ttl 64
488 ip -netns "$testns" link set dev "$vxlan" type vxlan nolearning
491 ip -netns "$testns" link set dev "$vxlan" type vxlan proxy 2>/dev/null
494 ip -netns "$testns" link set dev "$vxlan" type vxlan norsc 2>/dev/null
497 ip -netns "$testns" link set dev "$vxlan" type vxlan l2miss 2>/dev/null
500 ip -netns "$testns" link set dev "$vxlan" type vxlan l3miss 2>/dev/null
503 ip -netns "$testns" link set dev "$vxlan" type vxlan external 2>/dev/null
506 ip -netns "$testns" link set dev "$vxlan" type vxlan udpcsum 2>/dev/null
509 ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumtx 2>/dev/null
512 ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumrx 2>/dev/null
515 ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumtx 2>/dev/null
518 ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumrx 2>/dev/null
521 ip -netns "$testns" link set dev "$vxlan" type vxlan gbp 2>/dev/null
524 ip -netns "$testns" link set dev "$vxlan" type vxlan gpe 2>/dev/null
527 ip -netns "$testns" link del "$vxlan"
530 if [ $ret -ne 0 ]; then
543 ip fou help 2>&1 |grep -q 'Usage: ip fou'
545 echo "SKIP: fou: iproute2 too old"
549 if ! /sbin/modprobe -q -n fou; then
550 echo "SKIP: module fou is not found"
553 /sbin/modprobe -q fou
554 ip -netns "$testns" fou add port 7777 ipproto 47 2>/dev/null
556 echo "FAIL: can't add fou port 7777, skipping test"
560 ip -netns "$testns" fou add port 8888 ipproto 4
563 ip -netns "$testns" fou del port 9999 2>/dev/null
566 ip -netns "$testns" fou del port 7777
569 if [ $ret -ne 0 ]; then
577 # test various encap methods, use netns to avoid unwanted interference
583 ip netns add "$testns"
584 if [ $? -ne 0 ]; then
585 echo "SKIP encap tests: cannot add net namespace $testns"
589 ip -netns "$testns" link set lo up
592 ip -netns "$testns" link add name "$devdummy" type dummy
594 ip -netns "$testns" link set "$devdummy" up
597 kci_test_encap_vxlan "$testns"
599 kci_test_encap_fou "$testns"
602 ip netns del "$testns"
608 msname="test_macsec0"
611 ip macsec help 2>&1 | grep -q "^Usage: ip macsec"
612 if [ $? -ne 0 ]; then
613 echo "SKIP: macsec: iproute2 too old"
617 ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on
619 if [ $ret -ne 0 ];then
620 echo "FAIL: can't add macsec interface, skipping test"
624 ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
627 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
630 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on key 00 0123456789abcdef0123456789abcdef
633 ip macsec show > /dev/null
636 ip link del dev "$msname"
639 if [ $ret -ne 0 ];then
647 kci_test_macsec_offload()
649 sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
650 sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
654 ip macsec help 2>&1 | grep -q "^Usage: ip macsec"
655 if [ $? -ne 0 ]; then
656 echo "SKIP: macsec: iproute2 too old"
660 # setup netdevsim since dummydev doesn't have offload support
661 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
662 modprobe -q netdevsim
664 if [ $ret -ne 0 ]; then
665 echo "SKIP: macsec_offload can't load netdevsim"
671 echo "0" > /sys/bus/netdevsim/new_device
672 while [ ! -d $sysfsnet ] ; do :; done
677 if [ ! -d $sysfsd ] ; then
678 echo "FAIL: macsec_offload can't create device $dev"
682 ethtool -k $dev | grep -q 'macsec-hw-offload: on'
683 if [ $? -eq 1 ] ; then
684 echo "FAIL: macsec_offload netdevsim doesn't support MACsec offload"
688 ip link add link $dev kci_macsec1 type macsec port 4 offload mac
691 ip link add link $dev kci_macsec2 type macsec address "aa:bb:cc:dd:ee:ff" port 5 offload mac
694 ip link add link $dev kci_macsec3 type macsec sci abbacdde01020304 offload mac
697 ip link add link $dev kci_macsec4 type macsec port 8 offload mac 2> /dev/null
702 ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
705 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
708 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on \
709 key 00 0123456789abcdef0123456789abcdef
712 ip macsec add "$msname" rx port 1235 address "1c:ed:de:ad:be:ef" 2> /dev/null
715 # clean up any leftovers
716 for msdev in kci_macsec{1,2,3,4} ; do
717 ip link del $msdev 2> /dev/null
719 echo 0 > /sys/bus/netdevsim/del_device
720 $probed && rmmod netdevsim
722 if [ $ret -ne 0 ]; then
723 echo "FAIL: macsec_offload"
726 echo "PASS: macsec_offload"
729 #-------------------------------------------------------------------
731 # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
732 # spi 0x07 mode transport reqid 0x07 replay-window 32 \
733 # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
734 # sel src 14.0.0.52/24 dst 14.0.0.70/24
735 # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
736 # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
737 # spi 0x07 mode transport reqid 0x07
739 # Subcommands not tested
746 #-------------------------------------------------------------------
750 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
755 ip addr add $srcip dev $devdummy
757 # flush to be sure there's nothing configured
758 ip x s flush ; ip x p flush
761 # start the monitor in the background
762 tmpfile=`mktemp /var/run/ipsectestXXX`
763 mpid=`(ip x m > $tmpfile & echo $!) 2>/dev/null`
766 ipsecid="proto esp src $srcip dst $dstip spi 0x07"
767 ip x s add $ipsecid \
768 mode transport reqid 0x07 replay-window 32 \
769 $algo sel src $srcip/24 dst $dstip/24
772 lines=`ip x s list | grep $srcip | grep $dstip | wc -l`
776 ip x s count | grep -q "SAD count 1"
779 lines=`ip x s get $ipsecid | grep $srcip | grep $dstip | wc -l`
783 ip x s delete $ipsecid
786 lines=`ip x s list | wc -l`
790 ipsecsel="dir out src $srcip/24 dst $dstip/24"
791 ip x p add $ipsecsel \
792 tmpl proto esp src $srcip dst $dstip \
793 spi 0x07 mode transport reqid 0x07
796 lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
800 ip x p count | grep -q "SPD IN 0 OUT 1 FWD 0"
803 lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
807 ip x p delete $ipsecsel
810 lines=`ip x p list | wc -l`
814 # check the monitor results
816 lines=`wc -l $tmpfile | cut "-d " -f1`
821 # clean up any leftovers
826 ip addr del $srcip/32 dev $devdummy
828 if [ $ret -ne 0 ]; then
835 #-------------------------------------------------------------------
837 # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
838 # spi 0x07 mode transport reqid 0x07 replay-window 32 \
839 # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
840 # sel src 14.0.0.52/24 dst 14.0.0.70/24
841 # offload dev sim1 dir out
842 # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
843 # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
844 # spi 0x07 mode transport reqid 0x07
846 #-------------------------------------------------------------------
847 kci_test_ipsec_offload()
850 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
853 sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
855 sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
858 # setup netdevsim since dummydev doesn't have offload support
859 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
860 modprobe -q netdevsim
862 if [ $ret -ne 0 ]; then
863 echo "SKIP: ipsec_offload can't load netdevsim"
869 echo "0" > /sys/bus/netdevsim/new_device
870 while [ ! -d $sysfsnet ] ; do :; done
874 ip addr add $srcip dev $dev
876 if [ ! -d $sysfsd ] ; then
877 echo "FAIL: ipsec_offload can't create device $dev"
880 if [ ! -f $sysfsf ] ; then
881 echo "FAIL: ipsec_offload netdevsim doesn't support IPsec offload"
885 # flush to be sure there's nothing configured
886 ip x s flush ; ip x p flush
888 # create offloaded SAs, both in and out
889 ip x p add dir out src $srcip/24 dst $dstip/24 \
890 tmpl proto esp src $srcip dst $dstip spi 9 \
891 mode transport reqid 42
893 ip x p add dir in src $dstip/24 dst $srcip/24 \
894 tmpl proto esp src $dstip dst $srcip spi 9 \
895 mode transport reqid 42
898 ip x s add proto esp src $srcip dst $dstip spi 9 \
899 mode transport reqid 42 $algo sel src $srcip/24 dst $dstip/24 \
900 offload dev $dev dir out
902 ip x s add proto esp src $dstip dst $srcip spi 9 \
903 mode transport reqid 42 $algo sel src $dstip/24 dst $srcip/24 \
904 offload dev $dev dir in
906 if [ $ret -ne 0 ]; then
907 echo "FAIL: ipsec_offload can't create SA"
911 # does offload show up in ip output
912 lines=`ip x s list | grep -c "crypto offload parameters: dev $dev dir"`
913 if [ $lines -ne 2 ] ; then
914 echo "FAIL: ipsec_offload SA offload missing from list output"
918 # use ping to exercise the Tx path
919 ping -I $dev -c 3 -W 1 -i 0 $dstip >/dev/null
921 # does driver have correct offload info
922 diff $sysfsf - << EOF
924 sa[0] tx ipaddr=0x00000000 00000000 00000000 00000000
925 sa[0] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
926 sa[0] key=0x34333231 38373635 32313039 36353433
927 sa[1] rx ipaddr=0x00000000 00000000 00000000 037ba8c0
928 sa[1] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
929 sa[1] key=0x34333231 38373635 32313039 36353433
931 if [ $? -ne 0 ] ; then
932 echo "FAIL: ipsec_offload incorrect driver data"
936 # does offload get removed from driver
939 lines=`grep -c "SA count=0" $sysfsf`
940 if [ $lines -ne 1 ] ; then
941 echo "FAIL: ipsec_offload SA not removed from driver"
945 # clean up any leftovers
946 echo 0 > /sys/bus/netdevsim/del_device
947 $probed && rmmod netdevsim
949 if [ $ret -ne 0 ]; then
950 echo "FAIL: ipsec_offload"
953 echo "PASS: ipsec_offload"
962 ip netns add "$testns"
963 if [ $? -ne 0 ]; then
964 echo "SKIP gretap tests: cannot add net namespace $testns"
968 ip link help gretap 2>&1 | grep -q "^Usage:"
970 echo "SKIP: gretap: iproute2 too old"
971 ip netns del "$testns"
976 ip -netns "$testns" link add dev "$DEV_NS" type gretap seq \
977 key 102 local 172.16.1.100 remote 172.16.1.200
980 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
983 ip -netns "$testns" link set dev $DEV_NS up
986 ip -netns "$testns" link del "$DEV_NS"
990 ip -netns "$testns" link add dev "$DEV_NS" type gretap external
993 ip -netns "$testns" link del "$DEV_NS"
996 if [ $ret -ne 0 ]; then
998 ip netns del "$testns"
1003 ip netns del "$testns"
1006 kci_test_ip6gretap()
1012 ip netns add "$testns"
1013 if [ $? -ne 0 ]; then
1014 echo "SKIP ip6gretap tests: cannot add net namespace $testns"
1018 ip link help ip6gretap 2>&1 | grep -q "^Usage:"
1019 if [ $? -ne 0 ];then
1020 echo "SKIP: ip6gretap: iproute2 too old"
1021 ip netns del "$testns"
1025 # test native tunnel
1026 ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap seq \
1027 key 102 local fc00:100::1 remote fc00:100::2
1030 ip -netns "$testns" addr add dev "$DEV_NS" fc00:200::1/96
1033 ip -netns "$testns" link set dev $DEV_NS up
1036 ip -netns "$testns" link del "$DEV_NS"
1039 # test external mode
1040 ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap external
1043 ip -netns "$testns" link del "$DEV_NS"
1046 if [ $ret -ne 0 ]; then
1047 echo "FAIL: ip6gretap"
1048 ip netns del "$testns"
1051 echo "PASS: ip6gretap"
1053 ip netns del "$testns"
1062 ip link help erspan 2>&1 | grep -q "^Usage:"
1063 if [ $? -ne 0 ];then
1064 echo "SKIP: erspan: iproute2 too old"
1068 ip netns add "$testns"
1069 if [ $? -ne 0 ]; then
1070 echo "SKIP erspan tests: cannot add net namespace $testns"
1074 # test native tunnel erspan v1
1075 ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
1076 key 102 local 172.16.1.100 remote 172.16.1.200 \
1077 erspan_ver 1 erspan 488
1080 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1083 ip -netns "$testns" link set dev $DEV_NS up
1086 ip -netns "$testns" link del "$DEV_NS"
1089 # test native tunnel erspan v2
1090 ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
1091 key 102 local 172.16.1.100 remote 172.16.1.200 \
1092 erspan_ver 2 erspan_dir ingress erspan_hwid 7
1095 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1098 ip -netns "$testns" link set dev $DEV_NS up
1101 ip -netns "$testns" link del "$DEV_NS"
1104 # test external mode
1105 ip -netns "$testns" link add dev "$DEV_NS" type erspan external
1108 ip -netns "$testns" link del "$DEV_NS"
1111 if [ $ret -ne 0 ]; then
1113 ip netns del "$testns"
1118 ip netns del "$testns"
1121 kci_test_ip6erspan()
1127 ip link help ip6erspan 2>&1 | grep -q "^Usage:"
1128 if [ $? -ne 0 ];then
1129 echo "SKIP: ip6erspan: iproute2 too old"
1133 ip netns add "$testns"
1134 if [ $? -ne 0 ]; then
1135 echo "SKIP ip6erspan tests: cannot add net namespace $testns"
1139 # test native tunnel ip6erspan v1
1140 ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
1141 key 102 local fc00:100::1 remote fc00:100::2 \
1142 erspan_ver 1 erspan 488
1145 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1148 ip -netns "$testns" link set dev $DEV_NS up
1151 ip -netns "$testns" link del "$DEV_NS"
1154 # test native tunnel ip6erspan v2
1155 ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
1156 key 102 local fc00:100::1 remote fc00:100::2 \
1157 erspan_ver 2 erspan_dir ingress erspan_hwid 7
1160 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1163 ip -netns "$testns" link set dev $DEV_NS up
1166 ip -netns "$testns" link del "$DEV_NS"
1169 # test external mode
1170 ip -netns "$testns" link add dev "$DEV_NS" \
1171 type ip6erspan external
1174 ip -netns "$testns" link del "$DEV_NS"
1177 if [ $ret -ne 0 ]; then
1178 echo "FAIL: ip6erspan"
1179 ip netns del "$testns"
1182 echo "PASS: ip6erspan"
1184 ip netns del "$testns"
1189 IP="ip -netns testns"
1190 BRIDGE="bridge -netns testns"
1193 test_mac=de:ad:be:ef:13:37
1198 bridge fdb help 2>&1 |grep -q 'bridge fdb get'
1199 if [ $? -ne 0 ];then
1200 echo "SKIP: fdb get tests: iproute2 too old"
1205 if [ $? -ne 0 ]; then
1206 echo "SKIP fdb get tests: cannot add net namespace $testns"
1210 $IP link add "$vxlandev" type vxlan id 10 local $localip \
1211 dstport 4789 2>/dev/null
1213 $IP link add name "$brdev" type bridge &>/dev/null
1215 $IP link set dev "$vxlandev" master "$brdev" &>/dev/null
1217 $BRIDGE fdb add $test_mac dev "$vxlandev" master &>/dev/null
1219 $BRIDGE fdb add $test_mac dev "$vxlandev" dst $dstip self &>/dev/null
1222 $BRIDGE fdb get $test_mac brport "$vxlandev" 2>/dev/null | grep -q "dev $vxlandev master $brdev"
1224 $BRIDGE fdb get $test_mac br "$brdev" 2>/dev/null | grep -q "dev $vxlandev master $brdev"
1226 $BRIDGE fdb get $test_mac dev "$vxlandev" self 2>/dev/null | grep -q "dev $vxlandev dst $dstip"
1229 ip netns del testns &>/dev/null
1231 if [ $ret -ne 0 ]; then
1232 echo "FAIL: bridge fdb get"
1236 echo "PASS: bridge fdb get"
1239 kci_test_neigh_get()
1241 dstmac=de:ad:be:ef:13:37
1246 ip neigh help 2>&1 |grep -q 'ip neigh get'
1247 if [ $? -ne 0 ];then
1248 echo "SKIP: fdb get tests: iproute2 too old"
1253 ip neigh add $dstip lladdr $dstmac dev "$devdummy" > /dev/null
1255 ip neigh get $dstip dev "$devdummy" 2> /dev/null | grep -q "$dstmac"
1257 ip neigh del $dstip lladdr $dstmac dev "$devdummy" > /dev/null
1261 ip neigh add proxy $dstip dev "$devdummy" > /dev/null
1263 ip neigh get proxy $dstip dev "$devdummy" 2>/dev/null | grep -q "$dstip"
1265 ip neigh del proxy $dstip dev "$devdummy" > /dev/null
1269 ip neigh add $dstip6 lladdr $dstmac dev "$devdummy" > /dev/null
1271 ip neigh get $dstip6 dev "$devdummy" 2> /dev/null | grep -q "$dstmac"
1273 ip neigh del $dstip6 lladdr $dstmac dev "$devdummy" > /dev/null
1277 ip neigh add proxy $dstip6 dev "$devdummy" > /dev/null
1279 ip neigh get proxy $dstip6 dev "$devdummy" 2>/dev/null | grep -q "$dstip6"
1281 ip neigh del proxy $dstip6 dev "$devdummy" > /dev/null
1284 if [ $ret -ne 0 ];then
1285 echo "FAIL: neigh get"
1289 echo "PASS: neigh get"
1292 kci_test_bridge_parent_id()
1295 sysfsnet=/sys/bus/netdevsim/devices/netdevsim
1298 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
1299 modprobe -q netdevsim
1301 if [ $ret -ne 0 ]; then
1302 echo "SKIP: bridge_parent_id can't load netdevsim"
1308 echo "10 1" > /sys/bus/netdevsim/new_device
1309 while [ ! -d ${sysfsnet}10 ] ; do :; done
1310 echo "20 1" > /sys/bus/netdevsim/new_device
1311 while [ ! -d ${sysfsnet}20 ] ; do :; done
1313 dev10=`ls ${sysfsnet}10/net/`
1314 dev20=`ls ${sysfsnet}20/net/`
1316 ip link add name test-bond0 type bond mode 802.3ad
1317 ip link set dev $dev10 master test-bond0
1318 ip link set dev $dev20 master test-bond0
1319 ip link add name test-br0 type bridge
1320 ip link set dev test-bond0 master test-br0
1323 # clean up any leftovers
1324 ip link del dev test-br0
1325 ip link del dev test-bond0
1326 echo 20 > /sys/bus/netdevsim/del_device
1327 echo 10 > /sys/bus/netdevsim/del_device
1328 $probed && rmmod netdevsim
1330 if [ $ret -ne 0 ]; then
1331 echo "FAIL: bridge_parent_id"
1334 echo "PASS: bridge_parent_id"
1339 local addr=$1; shift
1341 ip -N -j address show dev "$devdummy" |
1342 jq -e -r --arg addr "${addr%/*}" \
1343 '.[].addr_info[] | select(.local == $addr) | .protocol'
1348 ip -N -j address show dev "$devdummy" "$@" |
1349 jq -e -r '[.[].addr_info[] | .local | select(. != null)] | length'
1352 do_test_address_proto()
1354 local what=$1; shift
1355 local addr=$1; shift
1356 local addr2=${addr%/*}2/${addr#*/}
1357 local addr3=${addr%/*}3/${addr#*/}
1363 ip address add dev "$devdummy" "$addr3"
1365 proto=$(address_get_proto "$addr3")
1366 [[ "$proto" == null ]]
1369 ip address add dev "$devdummy" "$addr2" proto 0x99
1371 proto=$(address_get_proto "$addr2")
1372 [[ "$proto" == 0x99 ]]
1375 ip address add dev "$devdummy" "$addr" proto 0xab
1377 proto=$(address_get_proto "$addr")
1378 [[ "$proto" == 0xab ]]
1381 ip address replace dev "$devdummy" "$addr" proto 0x11
1382 proto=$(address_get_proto "$addr")
1384 [[ "$proto" == 0x11 ]]
1387 count=$(address_count)
1389 (( count >= 3 )) # $addr, $addr2 and $addr3 plus any kernel addresses
1392 count=$(address_count proto 0)
1394 (( count == 1 )) # just $addr3
1397 count=$(address_count proto 0x11)
1399 (( count == 2 )) # $addr and $addr3
1402 count=$(address_count proto 0xab)
1404 (( count == 1 )) # just $addr3
1407 ip address del dev "$devdummy" "$addr"
1408 ip address del dev "$devdummy" "$addr2"
1409 ip address del dev "$devdummy" "$addr3"
1411 if [ $ret -ne 0 ]; then
1412 echo "FAIL: address proto $what"
1415 echo "PASS: address proto $what"
1418 kci_test_address_proto()
1422 do_test_address_proto IPv4 192.0.2.1/28
1425 do_test_address_proto IPv6 2001:db8:1::1/64
1437 if [ $ret -ne 0 ];then
1438 echo "FAIL: cannot add dummy interface"
1442 for current_test in ${TESTS:-$ALL_TESTS}; do
1454 usage: ${0##*/} OPTS
1456 -t <test> Test(s) to run (default: all)
1457 (options: $(echo $ALL_TESTS))
1461 #check for needed privileges
1462 if [ "$(id -u)" -ne 0 ];then
1463 echo "SKIP: Need root privileges"
1468 $x -Version 2>/dev/null >/dev/null
1469 if [ $? -ne 0 ];then
1470 echo "SKIP: Could not run test without the $x tool"
1475 while getopts t:h o; do