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
28 kci_test_bridge_parent_id
29 kci_test_address_proto
32 devdummy="test-dummy0"
34 # Kselftest framework requirement - SKIP code is 4.
37 # set global exit status, but never reset nonzero one.
40 if [ $ret -eq 0 ]; then
45 # same but inverted -- used when command must fail for test to pass
55 ip link add name "$devdummy" type dummy
57 ip link set "$devdummy" up
63 ip link del dev "$devdummy"
72 ip netconf show dev "$dev" > /dev/null
76 ip -$f netconf show dev "$dev" > /dev/null
80 if [ $ret -ne 0 ] ;then
81 echo "FAIL: ip netconf show $dev"
82 test $r -eq 0 && ret=0
87 # add a bridge with vlans on top
91 vlandev="testbr-vlan1"
94 ip link add name "$devbr" type bridge
97 ip link set dev "$devdummy" master "$devbr"
100 ip link set "$devbr" up
103 ip link add link "$devbr" name "$vlandev" type vlan id 1
105 ip addr add dev "$vlandev" 10.200.7.23/30
107 ip -6 addr add dev "$vlandev" dead:42::1234/64
109 ip -d link > /dev/null
111 ip r s t all > /dev/null
114 for name in "$devbr" "$vlandev" "$devdummy" ; do
115 kci_test_netconf "$name"
118 ip -6 addr del dev "$vlandev" dead:42::1234/64
121 ip link del dev "$vlandev"
123 ip link del dev "$devbr"
126 if [ $ret -ne 0 ];then
127 echo "FAIL: bridge setup"
130 echo "PASS: bridge setup"
141 ip tunnel add $gredev mode gre remote $rem local $loc ttl 1
143 ip link set $gredev up
145 ip addr add 10.23.7.10 dev $gredev
147 ip route add 10.23.8.0/30 dev $gredev
149 ip addr add dev "$devdummy" 10.23.7.11/24
156 kci_test_netconf "$gredev"
158 ip addr del dev "$devdummy" 10.23.7.11/24
164 if [ $ret -ne 0 ];then
165 echo "FAIL: gre tunnel endpoint"
168 echo "PASS: gre tunnel endpoint"
171 # tc uses rtnetlink too, for full tc testing
172 # please see tools/testing/selftests/tc-testing.
178 tc qdisc add dev "$dev" root handle 1: htb
180 tc class add dev "$dev" parent 1: classid 1:10 htb rate 1mbit
182 tc filter add dev "$dev" parent 1:0 prio 5 handle ffe: protocol ip u32 divisor 256
184 tc filter add dev "$dev" parent 1:0 prio 5 handle ffd: protocol ip u32 divisor 256
186 tc filter add dev "$dev" parent 1:0 prio 5 handle ffc: protocol ip u32 divisor 256
188 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
190 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
192 tc filter show dev "$dev" parent 1:0 > /dev/null
194 tc filter del dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32
196 tc filter show dev "$dev" parent 1:0 > /dev/null
198 tc qdisc del dev "$dev" root handle 1: htb
201 if [ $ret -ne 0 ];then
202 echo "FAIL: tc htb hierarchy"
205 echo "PASS: tc htb hierarchy"
209 kci_test_polrouting()
212 ip rule add fwmark 1 lookup 100
214 ip route add local 0.0.0.0/0 dev lo table 100
216 ip r s t all > /dev/null
218 ip rule del fwmark 1 lookup 100
220 ip route del local 0.0.0.0/0 dev lo table 100
223 if [ $ret -ne 0 ];then
224 echo "FAIL: policy route test"
227 echo "PASS: policy routing"
232 local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
236 ip route get 127.0.0.1 > /dev/null
238 ip route get 127.0.0.1 dev "$devdummy" > /dev/null
240 ip route get ::1 > /dev/null
242 ip route get fe80::1 dev "$devdummy" > /dev/null
244 ip route get 127.0.0.1 from 127.0.0.1 oif lo tos 0x10 mark 0x1 > /dev/null
246 ip route get ::1 from ::1 iif lo oif lo tos 0x10 mark 0x1 > /dev/null
248 ip addr add dev "$devdummy" 10.23.7.11/24
250 ip route get 10.23.7.11 from 10.23.7.12 iif "$devdummy" > /dev/null
252 ip route add 10.23.8.0/24 \
253 nexthop via 10.23.7.13 dev "$devdummy" \
254 nexthop via 10.23.7.14 dev "$devdummy"
256 sysctl -wq net.ipv4.fib_multipath_hash_policy=0
257 ip route get 10.23.8.11 > /dev/null
259 sysctl -wq net.ipv4.fib_multipath_hash_policy=1
260 ip route get 10.23.8.11 > /dev/null
262 sysctl -wq net.ipv4.fib_multipath_hash_policy="$hash_policy"
263 ip route del 10.23.8.0/24
265 ip addr del dev "$devdummy" 10.23.7.11/24
268 if [ $ret -ne 0 ];then
269 echo "FAIL: route get"
273 echo "PASS: route get"
278 for i in $(seq 10 100) ;do
279 lft=$(((RANDOM%3) + 1))
280 ip addr add 10.23.11.$i/32 dev "$devdummy" preferred_lft $lft valid_lft $((lft+1))
286 ip addr show dev "$devdummy" | grep "10.23.11."
287 if [ $? -eq 0 ]; then
288 echo "FAIL: preferred_lft addresses remaining"
293 echo "PASS: preferred_lft addresses have expired"
296 kci_test_promote_secondaries()
298 promote=$(sysctl -n net.ipv4.conf.$devdummy.promote_secondaries)
300 sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=1
302 for i in $(seq 2 254);do
304 ip -f inet addr add $IP/16 brd + dev "$devdummy"
305 ifconfig "$devdummy" $IP netmask 255.255.0.0
308 ip addr flush dev "$devdummy"
310 [ $promote -eq 0 ] && sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=0
312 echo "PASS: promote_secondaries complete"
319 ip addrlabel add prefix dead::/64 dev lo label 1
322 ip addrlabel list |grep -q "prefix dead::/64 dev lo label 1"
325 ip addrlabel del prefix dead::/64 dev lo label 1 2> /dev/null
328 ip addrlabel add prefix dead::/64 label 1 2> /dev/null
331 ip addrlabel del prefix dead::/64 label 1 2> /dev/null
334 # concurrent add/delete
335 for i in $(seq 1 1000); do
336 ip addrlabel add prefix 1c3::/64 label 12345 2>/dev/null
339 for i in $(seq 1 1000); do
340 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
345 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
347 if [ $ret -ne 0 ];then
348 echo "FAIL: ipv6 addrlabel"
352 echo "PASS: ipv6 addrlabel"
359 syspathname="/sys/class/net/$devdummy/ifalias"
361 ip link set dev "$devdummy" alias "$namewant"
364 if [ $ret -ne 0 ]; then
365 echo "FAIL: cannot set interface alias of $devdummy to $namewant"
369 ip link show "$devdummy" | grep -q "alias $namewant"
372 if [ -r "$syspathname" ] ; then
373 read namehave < "$syspathname"
374 if [ "$namewant" != "$namehave" ]; then
375 echo "FAIL: did set ifalias $namewant but got $namehave"
380 echo "$namewant" > "$syspathname"
381 ip link show "$devdummy" | grep -q "alias $namewant"
384 # sysfs interface allows to delete alias again
385 echo "" > "$syspathname"
387 ip link show "$devdummy" | grep -q "alias $namewant"
390 for i in $(seq 1 100); do
391 uuidgen > "$syspathname" &
396 # re-add the alias -- kernel should free mem when dummy dev is removed
397 ip link set dev "$devdummy" alias "$namewant"
401 if [ $ret -ne 0 ]; then
402 echo "FAIL: set interface alias $devdummy to $namewant"
406 echo "PASS: set ifalias $namewant for $devdummy"
414 ip link show type vrf 2>/dev/null
415 if [ $? -ne 0 ]; then
416 echo "SKIP: vrf: iproute2 too old"
420 ip link add "$vrfname" type vrf table 10
422 if [ $ret -ne 0 ];then
423 echo "FAIL: can't add vrf interface, skipping test"
427 ip -br link show type vrf | grep -q "$vrfname"
429 if [ $ret -ne 0 ];then
430 echo "FAIL: created vrf device not found"
434 ip link set dev "$vrfname" up
437 ip link set dev "$devdummy" master "$vrfname"
439 ip link del dev "$vrfname"
442 if [ $ret -ne 0 ];then
450 kci_test_encap_vxlan()
457 ip -netns "$testns" link add "$vxlan" type vxlan id 42 group 239.1.1.1 \
458 dev "$devdummy" dstport 4789 2>/dev/null
459 if [ $? -ne 0 ]; then
460 echo "FAIL: can't add vxlan interface, skipping test"
465 ip -netns "$testns" addr add 10.2.11.49/24 dev "$vxlan"
468 ip -netns "$testns" link set up dev "$vxlan"
471 ip -netns "$testns" link add link "$vxlan" name "$vlan" type vlan id 1
474 # changelink testcases
475 ip -netns "$testns" link set dev "$vxlan" type vxlan vni 43 2>/dev/null
478 ip -netns "$testns" link set dev "$vxlan" type vxlan group ffe5::5 dev "$devdummy" 2>/dev/null
481 ip -netns "$testns" link set dev "$vxlan" type vxlan ttl inherit 2>/dev/null
484 ip -netns "$testns" link set dev "$vxlan" type vxlan ttl 64
487 ip -netns "$testns" link set dev "$vxlan" type vxlan nolearning
490 ip -netns "$testns" link set dev "$vxlan" type vxlan proxy 2>/dev/null
493 ip -netns "$testns" link set dev "$vxlan" type vxlan norsc 2>/dev/null
496 ip -netns "$testns" link set dev "$vxlan" type vxlan l2miss 2>/dev/null
499 ip -netns "$testns" link set dev "$vxlan" type vxlan l3miss 2>/dev/null
502 ip -netns "$testns" link set dev "$vxlan" type vxlan external 2>/dev/null
505 ip -netns "$testns" link set dev "$vxlan" type vxlan udpcsum 2>/dev/null
508 ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumtx 2>/dev/null
511 ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumrx 2>/dev/null
514 ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumtx 2>/dev/null
517 ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumrx 2>/dev/null
520 ip -netns "$testns" link set dev "$vxlan" type vxlan gbp 2>/dev/null
523 ip -netns "$testns" link set dev "$vxlan" type vxlan gpe 2>/dev/null
526 ip -netns "$testns" link del "$vxlan"
529 if [ $ret -ne 0 ]; then
542 ip fou help 2>&1 |grep -q 'Usage: ip fou'
544 echo "SKIP: fou: iproute2 too old"
548 if ! /sbin/modprobe -q -n fou; then
549 echo "SKIP: module fou is not found"
552 /sbin/modprobe -q fou
553 ip -netns "$testns" fou add port 7777 ipproto 47 2>/dev/null
555 echo "FAIL: can't add fou port 7777, skipping test"
559 ip -netns "$testns" fou add port 8888 ipproto 4
562 ip -netns "$testns" fou del port 9999 2>/dev/null
565 ip -netns "$testns" fou del port 7777
568 if [ $ret -ne 0 ]; then
576 # test various encap methods, use netns to avoid unwanted interference
582 ip netns add "$testns"
583 if [ $? -ne 0 ]; then
584 echo "SKIP encap tests: cannot add net namespace $testns"
588 ip -netns "$testns" link set lo up
591 ip -netns "$testns" link add name "$devdummy" type dummy
593 ip -netns "$testns" link set "$devdummy" up
596 kci_test_encap_vxlan "$testns"
598 kci_test_encap_fou "$testns"
601 ip netns del "$testns"
607 msname="test_macsec0"
610 ip macsec help 2>&1 | grep -q "^Usage: ip macsec"
611 if [ $? -ne 0 ]; then
612 echo "SKIP: macsec: iproute2 too old"
616 ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on
618 if [ $ret -ne 0 ];then
619 echo "FAIL: can't add macsec interface, skipping test"
623 ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
626 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
629 ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on key 00 0123456789abcdef0123456789abcdef
632 ip macsec show > /dev/null
635 ip link del dev "$msname"
638 if [ $ret -ne 0 ];then
646 #-------------------------------------------------------------------
648 # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
649 # spi 0x07 mode transport reqid 0x07 replay-window 32 \
650 # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
651 # sel src 14.0.0.52/24 dst 14.0.0.70/24
652 # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
653 # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
654 # spi 0x07 mode transport reqid 0x07
656 # Subcommands not tested
663 #-------------------------------------------------------------------
667 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
672 ip addr add $srcip dev $devdummy
674 # flush to be sure there's nothing configured
675 ip x s flush ; ip x p flush
678 # start the monitor in the background
679 tmpfile=`mktemp /var/run/ipsectestXXX`
680 mpid=`(ip x m > $tmpfile & echo $!) 2>/dev/null`
683 ipsecid="proto esp src $srcip dst $dstip spi 0x07"
684 ip x s add $ipsecid \
685 mode transport reqid 0x07 replay-window 32 \
686 $algo sel src $srcip/24 dst $dstip/24
689 lines=`ip x s list | grep $srcip | grep $dstip | wc -l`
693 ip x s count | grep -q "SAD count 1"
696 lines=`ip x s get $ipsecid | grep $srcip | grep $dstip | wc -l`
700 ip x s delete $ipsecid
703 lines=`ip x s list | wc -l`
707 ipsecsel="dir out src $srcip/24 dst $dstip/24"
708 ip x p add $ipsecsel \
709 tmpl proto esp src $srcip dst $dstip \
710 spi 0x07 mode transport reqid 0x07
713 lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
717 ip x p count | grep -q "SPD IN 0 OUT 1 FWD 0"
720 lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
724 ip x p delete $ipsecsel
727 lines=`ip x p list | wc -l`
731 # check the monitor results
733 lines=`wc -l $tmpfile | cut "-d " -f1`
738 # clean up any leftovers
743 ip addr del $srcip/32 dev $devdummy
745 if [ $ret -ne 0 ]; then
752 #-------------------------------------------------------------------
754 # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
755 # spi 0x07 mode transport reqid 0x07 replay-window 32 \
756 # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
757 # sel src 14.0.0.52/24 dst 14.0.0.70/24
758 # offload dev sim1 dir out
759 # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
760 # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
761 # spi 0x07 mode transport reqid 0x07
763 #-------------------------------------------------------------------
764 kci_test_ipsec_offload()
767 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
770 sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
772 sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
775 # setup netdevsim since dummydev doesn't have offload support
776 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
777 modprobe -q netdevsim
779 if [ $ret -ne 0 ]; then
780 echo "SKIP: ipsec_offload can't load netdevsim"
786 echo "0" > /sys/bus/netdevsim/new_device
787 while [ ! -d $sysfsnet ] ; do :; done
791 ip addr add $srcip dev $dev
793 if [ ! -d $sysfsd ] ; then
794 echo "FAIL: ipsec_offload can't create device $dev"
797 if [ ! -f $sysfsf ] ; then
798 echo "FAIL: ipsec_offload netdevsim doesn't support IPsec offload"
802 # flush to be sure there's nothing configured
803 ip x s flush ; ip x p flush
805 # create offloaded SAs, both in and out
806 ip x p add dir out src $srcip/24 dst $dstip/24 \
807 tmpl proto esp src $srcip dst $dstip spi 9 \
808 mode transport reqid 42
810 ip x p add dir in src $dstip/24 dst $srcip/24 \
811 tmpl proto esp src $dstip dst $srcip spi 9 \
812 mode transport reqid 42
815 ip x s add proto esp src $srcip dst $dstip spi 9 \
816 mode transport reqid 42 $algo sel src $srcip/24 dst $dstip/24 \
817 offload dev $dev dir out
819 ip x s add proto esp src $dstip dst $srcip spi 9 \
820 mode transport reqid 42 $algo sel src $dstip/24 dst $srcip/24 \
821 offload dev $dev dir in
823 if [ $ret -ne 0 ]; then
824 echo "FAIL: ipsec_offload can't create SA"
828 # does offload show up in ip output
829 lines=`ip x s list | grep -c "crypto offload parameters: dev $dev dir"`
830 if [ $lines -ne 2 ] ; then
831 echo "FAIL: ipsec_offload SA offload missing from list output"
835 # use ping to exercise the Tx path
836 ping -I $dev -c 3 -W 1 -i 0 $dstip >/dev/null
838 # does driver have correct offload info
839 diff $sysfsf - << EOF
841 sa[0] tx ipaddr=0x00000000 00000000 00000000 00000000
842 sa[0] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
843 sa[0] key=0x34333231 38373635 32313039 36353433
844 sa[1] rx ipaddr=0x00000000 00000000 00000000 037ba8c0
845 sa[1] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
846 sa[1] key=0x34333231 38373635 32313039 36353433
848 if [ $? -ne 0 ] ; then
849 echo "FAIL: ipsec_offload incorrect driver data"
853 # does offload get removed from driver
856 lines=`grep -c "SA count=0" $sysfsf`
857 if [ $lines -ne 1 ] ; then
858 echo "FAIL: ipsec_offload SA not removed from driver"
862 # clean up any leftovers
863 $probed && rmmod netdevsim
865 if [ $ret -ne 0 ]; then
866 echo "FAIL: ipsec_offload"
869 echo "PASS: ipsec_offload"
878 ip netns add "$testns"
879 if [ $? -ne 0 ]; then
880 echo "SKIP gretap tests: cannot add net namespace $testns"
884 ip link help gretap 2>&1 | grep -q "^Usage:"
886 echo "SKIP: gretap: iproute2 too old"
887 ip netns del "$testns"
892 ip -netns "$testns" link add dev "$DEV_NS" type gretap seq \
893 key 102 local 172.16.1.100 remote 172.16.1.200
896 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
899 ip -netns "$testns" link set dev $DEV_NS up
902 ip -netns "$testns" link del "$DEV_NS"
906 ip -netns "$testns" link add dev "$DEV_NS" type gretap external
909 ip -netns "$testns" link del "$DEV_NS"
912 if [ $ret -ne 0 ]; then
914 ip netns del "$testns"
919 ip netns del "$testns"
928 ip netns add "$testns"
929 if [ $? -ne 0 ]; then
930 echo "SKIP ip6gretap tests: cannot add net namespace $testns"
934 ip link help ip6gretap 2>&1 | grep -q "^Usage:"
936 echo "SKIP: ip6gretap: iproute2 too old"
937 ip netns del "$testns"
942 ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap seq \
943 key 102 local fc00:100::1 remote fc00:100::2
946 ip -netns "$testns" addr add dev "$DEV_NS" fc00:200::1/96
949 ip -netns "$testns" link set dev $DEV_NS up
952 ip -netns "$testns" link del "$DEV_NS"
956 ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap external
959 ip -netns "$testns" link del "$DEV_NS"
962 if [ $ret -ne 0 ]; then
963 echo "FAIL: ip6gretap"
964 ip netns del "$testns"
967 echo "PASS: ip6gretap"
969 ip netns del "$testns"
978 ip link help erspan 2>&1 | grep -q "^Usage:"
980 echo "SKIP: erspan: iproute2 too old"
984 ip netns add "$testns"
985 if [ $? -ne 0 ]; then
986 echo "SKIP erspan tests: cannot add net namespace $testns"
990 # test native tunnel erspan v1
991 ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
992 key 102 local 172.16.1.100 remote 172.16.1.200 \
993 erspan_ver 1 erspan 488
996 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
999 ip -netns "$testns" link set dev $DEV_NS up
1002 ip -netns "$testns" link del "$DEV_NS"
1005 # test native tunnel erspan v2
1006 ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
1007 key 102 local 172.16.1.100 remote 172.16.1.200 \
1008 erspan_ver 2 erspan_dir ingress erspan_hwid 7
1011 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1014 ip -netns "$testns" link set dev $DEV_NS up
1017 ip -netns "$testns" link del "$DEV_NS"
1020 # test external mode
1021 ip -netns "$testns" link add dev "$DEV_NS" type erspan external
1024 ip -netns "$testns" link del "$DEV_NS"
1027 if [ $ret -ne 0 ]; then
1029 ip netns del "$testns"
1034 ip netns del "$testns"
1037 kci_test_ip6erspan()
1043 ip link help ip6erspan 2>&1 | grep -q "^Usage:"
1044 if [ $? -ne 0 ];then
1045 echo "SKIP: ip6erspan: iproute2 too old"
1049 ip netns add "$testns"
1050 if [ $? -ne 0 ]; then
1051 echo "SKIP ip6erspan tests: cannot add net namespace $testns"
1055 # test native tunnel ip6erspan v1
1056 ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
1057 key 102 local fc00:100::1 remote fc00:100::2 \
1058 erspan_ver 1 erspan 488
1061 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1064 ip -netns "$testns" link set dev $DEV_NS up
1067 ip -netns "$testns" link del "$DEV_NS"
1070 # test native tunnel ip6erspan v2
1071 ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
1072 key 102 local fc00:100::1 remote fc00:100::2 \
1073 erspan_ver 2 erspan_dir ingress erspan_hwid 7
1076 ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1079 ip -netns "$testns" link set dev $DEV_NS up
1082 ip -netns "$testns" link del "$DEV_NS"
1085 # test external mode
1086 ip -netns "$testns" link add dev "$DEV_NS" \
1087 type ip6erspan external
1090 ip -netns "$testns" link del "$DEV_NS"
1093 if [ $ret -ne 0 ]; then
1094 echo "FAIL: ip6erspan"
1095 ip netns del "$testns"
1098 echo "PASS: ip6erspan"
1100 ip netns del "$testns"
1105 IP="ip -netns testns"
1106 BRIDGE="bridge -netns testns"
1109 test_mac=de:ad:be:ef:13:37
1114 bridge fdb help 2>&1 |grep -q 'bridge fdb get'
1115 if [ $? -ne 0 ];then
1116 echo "SKIP: fdb get tests: iproute2 too old"
1121 if [ $? -ne 0 ]; then
1122 echo "SKIP fdb get tests: cannot add net namespace $testns"
1126 $IP link add "$vxlandev" type vxlan id 10 local $localip \
1127 dstport 4789 2>/dev/null
1129 $IP link add name "$brdev" type bridge &>/dev/null
1131 $IP link set dev "$vxlandev" master "$brdev" &>/dev/null
1133 $BRIDGE fdb add $test_mac dev "$vxlandev" master &>/dev/null
1135 $BRIDGE fdb add $test_mac dev "$vxlandev" dst $dstip self &>/dev/null
1138 $BRIDGE fdb get $test_mac brport "$vxlandev" 2>/dev/null | grep -q "dev $vxlandev master $brdev"
1140 $BRIDGE fdb get $test_mac br "$brdev" 2>/dev/null | grep -q "dev $vxlandev master $brdev"
1142 $BRIDGE fdb get $test_mac dev "$vxlandev" self 2>/dev/null | grep -q "dev $vxlandev dst $dstip"
1145 ip netns del testns &>/dev/null
1147 if [ $ret -ne 0 ]; then
1148 echo "FAIL: bridge fdb get"
1152 echo "PASS: bridge fdb get"
1155 kci_test_neigh_get()
1157 dstmac=de:ad:be:ef:13:37
1162 ip neigh help 2>&1 |grep -q 'ip neigh get'
1163 if [ $? -ne 0 ];then
1164 echo "SKIP: fdb get tests: iproute2 too old"
1169 ip neigh add $dstip lladdr $dstmac dev "$devdummy" > /dev/null
1171 ip neigh get $dstip dev "$devdummy" 2> /dev/null | grep -q "$dstmac"
1173 ip neigh del $dstip lladdr $dstmac dev "$devdummy" > /dev/null
1177 ip neigh add proxy $dstip dev "$devdummy" > /dev/null
1179 ip neigh get proxy $dstip dev "$devdummy" 2>/dev/null | grep -q "$dstip"
1181 ip neigh del proxy $dstip dev "$devdummy" > /dev/null
1185 ip neigh add $dstip6 lladdr $dstmac dev "$devdummy" > /dev/null
1187 ip neigh get $dstip6 dev "$devdummy" 2> /dev/null | grep -q "$dstmac"
1189 ip neigh del $dstip6 lladdr $dstmac dev "$devdummy" > /dev/null
1193 ip neigh add proxy $dstip6 dev "$devdummy" > /dev/null
1195 ip neigh get proxy $dstip6 dev "$devdummy" 2>/dev/null | grep -q "$dstip6"
1197 ip neigh del proxy $dstip6 dev "$devdummy" > /dev/null
1200 if [ $ret -ne 0 ];then
1201 echo "FAIL: neigh get"
1205 echo "PASS: neigh get"
1208 kci_test_bridge_parent_id()
1211 sysfsnet=/sys/bus/netdevsim/devices/netdevsim
1214 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
1215 modprobe -q netdevsim
1217 if [ $ret -ne 0 ]; then
1218 echo "SKIP: bridge_parent_id can't load netdevsim"
1224 echo "10 1" > /sys/bus/netdevsim/new_device
1225 while [ ! -d ${sysfsnet}10 ] ; do :; done
1226 echo "20 1" > /sys/bus/netdevsim/new_device
1227 while [ ! -d ${sysfsnet}20 ] ; do :; done
1229 dev10=`ls ${sysfsnet}10/net/`
1230 dev20=`ls ${sysfsnet}20/net/`
1232 ip link add name test-bond0 type bond mode 802.3ad
1233 ip link set dev $dev10 master test-bond0
1234 ip link set dev $dev20 master test-bond0
1235 ip link add name test-br0 type bridge
1236 ip link set dev test-bond0 master test-br0
1239 # clean up any leftovers
1240 ip link del dev test-br0
1241 ip link del dev test-bond0
1242 echo 20 > /sys/bus/netdevsim/del_device
1243 echo 10 > /sys/bus/netdevsim/del_device
1244 $probed && rmmod netdevsim
1246 if [ $ret -ne 0 ]; then
1247 echo "FAIL: bridge_parent_id"
1250 echo "PASS: bridge_parent_id"
1255 local addr=$1; shift
1257 ip -N -j address show dev "$devdummy" |
1258 jq -e -r --arg addr "${addr%/*}" \
1259 '.[].addr_info[] | select(.local == $addr) | .protocol'
1264 ip -N -j address show dev "$devdummy" "$@" |
1265 jq -e -r '[.[].addr_info[] | .local | select(. != null)] | length'
1268 do_test_address_proto()
1270 local what=$1; shift
1271 local addr=$1; shift
1272 local addr2=${addr%/*}2/${addr#*/}
1273 local addr3=${addr%/*}3/${addr#*/}
1279 ip address add dev "$devdummy" "$addr3"
1281 proto=$(address_get_proto "$addr3")
1282 [[ "$proto" == null ]]
1285 ip address add dev "$devdummy" "$addr2" proto 0x99
1287 proto=$(address_get_proto "$addr2")
1288 [[ "$proto" == 0x99 ]]
1291 ip address add dev "$devdummy" "$addr" proto 0xab
1293 proto=$(address_get_proto "$addr")
1294 [[ "$proto" == 0xab ]]
1297 ip address replace dev "$devdummy" "$addr" proto 0x11
1298 proto=$(address_get_proto "$addr")
1300 [[ "$proto" == 0x11 ]]
1303 count=$(address_count)
1305 (( count >= 3 )) # $addr, $addr2 and $addr3 plus any kernel addresses
1308 count=$(address_count proto 0)
1310 (( count == 1 )) # just $addr3
1313 count=$(address_count proto 0x11)
1315 (( count == 2 )) # $addr and $addr3
1318 count=$(address_count proto 0xab)
1320 (( count == 1 )) # just $addr3
1323 ip address del dev "$devdummy" "$addr"
1324 ip address del dev "$devdummy" "$addr2"
1325 ip address del dev "$devdummy" "$addr3"
1327 if [ $ret -ne 0 ]; then
1328 echo "FAIL: address proto $what"
1331 echo "PASS: address proto $what"
1334 kci_test_address_proto()
1338 do_test_address_proto IPv4 192.0.2.1/28
1341 do_test_address_proto IPv6 2001:db8:1::1/64
1353 if [ $ret -ne 0 ];then
1354 echo "FAIL: cannot add dummy interface"
1358 for current_test in ${TESTS:-$ALL_TESTS}; do
1370 usage: ${0##*/} OPTS
1372 -t <test> Test(s) to run (default: all)
1373 (options: $(echo $ALL_TESTS))
1377 #check for needed privileges
1378 if [ "$(id -u)" -ne 0 ];then
1379 echo "SKIP: Need root privileges"
1384 $x -Version 2>/dev/null >/dev/null
1385 if [ $? -ne 0 ];then
1386 echo "SKIP: Could not run test without the $x tool"
1391 while getopts t:h o; do