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"
38 # Kselftest framework requirement - SKIP code is 4.
41 # set global exit status, but never reset nonzero one.
44 if [ $ret -eq 0 ]; then
49 # same but inverted -- used when command must fail for test to pass
61 if [ "$VERBOSE" = "1" ]; then
62 echo "COMMAND: ${cmd}"
66 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
88 local find="$1"; shift
91 if [ "$VERBOSE" = "1" ]; then
92 echo "COMMAND: ${cmd} 2>&1 | grep -q '${find}'"
94 out=$($cmd 2>&1 | grep -q "${find}" 2>&1)
99 run_cmd_grep_common "$@"
107 run_cmd_grep_common "$@"
116 [ "${VERBOSE}" = "1" ] && echo
118 if [[ $ret -ne 0 ]] && [[ "${PAUSE_ON_FAIL}" = "yes" ]]; then
119 echo "Hit enter to continue"
123 if [ "${PAUSE}" = "yes" ]; then
124 echo "Hit enter to continue"
133 run_cmd ip link add name "$devdummy" type dummy
134 run_cmd ip link set "$devdummy" up
139 run_cmd ip link del dev "$devdummy"
146 run_cmd ip netconf show dev "$dev"
148 run_cmd ip -$f netconf show dev "$dev"
151 if [ $ret -ne 0 ] ;then
152 end_test "FAIL: ip netconf show $dev"
153 test $r -eq 0 && ret=0
158 # add a bridge with vlans on top
162 vlandev="testbr-vlan1"
165 run_cmd ip link add name "$devbr" type bridge
166 run_cmd ip link set dev "$devdummy" master "$devbr"
167 run_cmd ip link set "$devbr" up
168 run_cmd ip link add link "$devbr" name "$vlandev" type vlan id 1
169 run_cmd ip addr add dev "$vlandev" 10.200.7.23/30
170 run_cmd ip -6 addr add dev "$vlandev" dead:42::1234/64
174 for name in "$devbr" "$vlandev" "$devdummy" ; do
175 kci_test_netconf "$name"
177 run_cmd ip -6 addr del dev "$vlandev" dead:42::1234/64
178 run_cmd ip link del dev "$vlandev"
179 run_cmd ip link del dev "$devbr"
181 if [ $ret -ne 0 ];then
182 end_test "FAIL: bridge setup"
185 end_test "PASS: bridge setup"
196 run_cmd ip tunnel add $gredev mode gre remote $rem local $loc ttl 1
197 run_cmd ip link set $gredev up
198 run_cmd ip addr add 10.23.7.10 dev $gredev
199 run_cmd ip route add 10.23.8.0/30 dev $gredev
200 run_cmd ip addr add dev "$devdummy" 10.23.7.11/24
204 kci_test_netconf "$gredev"
205 run_cmd ip addr del dev "$devdummy" 10.23.7.11/24
206 run_cmd ip link del $gredev
208 if [ $ret -ne 0 ];then
209 end_test "FAIL: gre tunnel endpoint"
212 end_test "PASS: gre tunnel endpoint"
215 # tc uses rtnetlink too, for full tc testing
216 # please see tools/testing/selftests/tc-testing.
222 run_cmd tc qdisc add dev "$dev" root handle 1: htb
223 run_cmd tc class add dev "$dev" parent 1: classid 1:10 htb rate 1mbit
224 run_cmd tc filter add dev "$dev" parent 1:0 prio 5 handle ffe: protocol ip u32 divisor 256
225 run_cmd tc filter add dev "$dev" parent 1:0 prio 5 handle ffd: protocol ip u32 divisor 256
226 run_cmd tc filter add dev "$dev" parent 1:0 prio 5 handle ffc: protocol ip u32 divisor 256
227 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
228 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
229 run_cmd tc filter show dev "$dev" parent 1:0
230 run_cmd tc filter del dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32
231 run_cmd tc filter show dev "$dev" parent 1:0
232 run_cmd tc qdisc del dev "$dev" root handle 1: htb
234 if [ $ret -ne 0 ];then
235 end_test "FAIL: tc htb hierarchy"
238 end_test "PASS: tc htb hierarchy"
242 kci_test_polrouting()
245 run_cmd ip rule add fwmark 1 lookup 100
246 run_cmd ip route add local 0.0.0.0/0 dev lo table 100
248 run_cmd ip rule del fwmark 1 lookup 100
249 run_cmd ip route del local 0.0.0.0/0 dev lo table 100
251 if [ $ret -ne 0 ];then
252 end_test "FAIL: policy route test"
255 end_test "PASS: policy routing"
260 local hash_policy=$(sysctl -n net.ipv4.fib_multipath_hash_policy)
263 run_cmd ip route get 127.0.0.1
264 run_cmd ip route get 127.0.0.1 dev "$devdummy"
265 run_cmd ip route get ::1
266 run_cmd ip route get fe80::1 dev "$devdummy"
267 run_cmd ip route get 127.0.0.1 from 127.0.0.1 oif lo tos 0x10 mark 0x1
268 run_cmd ip route get ::1 from ::1 iif lo oif lo tos 0x10 mark 0x1
269 run_cmd ip addr add dev "$devdummy" 10.23.7.11/24
270 run_cmd ip route get 10.23.7.11 from 10.23.7.12 iif "$devdummy"
271 run_cmd ip route add 10.23.8.0/24 \
272 nexthop via 10.23.7.13 dev "$devdummy" \
273 nexthop via 10.23.7.14 dev "$devdummy"
275 sysctl -wq net.ipv4.fib_multipath_hash_policy=0
276 run_cmd ip route get 10.23.8.11
277 sysctl -wq net.ipv4.fib_multipath_hash_policy=1
278 run_cmd ip route get 10.23.8.11
279 sysctl -wq net.ipv4.fib_multipath_hash_policy="$hash_policy"
280 run_cmd ip route del 10.23.8.0/24
281 run_cmd ip addr del dev "$devdummy" 10.23.7.11/24
284 if [ $ret -ne 0 ];then
285 end_test "FAIL: route get"
289 end_test "PASS: route get"
294 for i in $(seq 10 100) ;do
295 lft=$(((RANDOM%3) + 1))
296 run_cmd ip addr add 10.23.11.$i/32 dev "$devdummy" preferred_lft $lft valid_lft $((lft+1))
300 run_cmd_grep "10.23.11." ip addr show dev "$devdummy"
301 if [ $? -eq 0 ]; then
303 end_test "FAIL: preferred_lft addresses remaining"
307 end_test "PASS: preferred_lft addresses have expired"
310 kci_test_promote_secondaries()
312 promote=$(sysctl -n net.ipv4.conf.$devdummy.promote_secondaries)
314 sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=1
316 for i in $(seq 2 254);do
318 ip -f inet addr add $IP/16 brd + dev "$devdummy"
319 ifconfig "$devdummy" $IP netmask 255.255.0.0
322 ip addr flush dev "$devdummy"
324 [ $promote -eq 0 ] && sysctl -q net.ipv4.conf.$devdummy.promote_secondaries=0
326 end_test "PASS: promote_secondaries complete"
332 run_cmd ip addrlabel add prefix dead::/64 dev lo label 1
333 run_cmd_grep "prefix dead::/64 dev lo label 1" ip addrlabel list
334 run_cmd ip addrlabel del prefix dead::/64 dev lo label 1
335 run_cmd ip addrlabel add prefix dead::/64 label 1
336 run_cmd ip addrlabel del prefix dead::/64 label 1
338 # concurrent add/delete
339 for i in $(seq 1 1000); do
340 ip addrlabel add prefix 1c3::/64 label 12345 2>/dev/null
343 for i in $(seq 1 1000); do
344 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
349 ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
351 if [ $ret -ne 0 ];then
352 end_test "FAIL: ipv6 addrlabel"
356 end_test "PASS: ipv6 addrlabel"
363 syspathname="/sys/class/net/$devdummy/ifalias"
364 run_cmd ip link set dev "$devdummy" alias "$namewant"
366 if [ $ret -ne 0 ]; then
367 end_test "FAIL: cannot set interface alias of $devdummy to $namewant"
370 run_cmd_grep "alias $namewant" ip link show "$devdummy"
372 if [ -r "$syspathname" ] ; then
373 read namehave < "$syspathname"
374 if [ "$namewant" != "$namehave" ]; then
375 end_test "FAIL: did set ifalias $namewant but got $namehave"
380 echo "$namewant" > "$syspathname"
381 run_cmd_grep "alias $namewant" ip link show "$devdummy"
383 # sysfs interface allows to delete alias again
384 echo "" > "$syspathname"
385 run_cmd_grep_fail "alias $namewant" ip link show "$devdummy"
387 for i in $(seq 1 100); do
388 uuidgen > "$syspathname" &
393 # re-add the alias -- kernel should free mem when dummy dev is removed
394 run_cmd ip link set dev "$devdummy" alias "$namewant"
398 if [ $ret -ne 0 ]; then
399 end_test "FAIL: set interface alias $devdummy to $namewant"
403 end_test "PASS: set ifalias $namewant for $devdummy"
410 run_cmd ip link show type vrf
411 if [ $? -ne 0 ]; then
412 end_test "SKIP: vrf: iproute2 too old"
415 run_cmd ip link add "$vrfname" type vrf table 10
416 if [ $ret -ne 0 ];then
417 end_test "FAIL: can't add vrf interface, skipping test"
420 run_cmd_grep "$vrfname" ip -br link show type vrf
421 if [ $ret -ne 0 ];then
422 end_test "FAIL: created vrf device not found"
426 run_cmd ip link set dev "$vrfname" up
427 run_cmd ip link set dev "$devdummy" master "$vrfname"
428 run_cmd ip link del dev "$vrfname"
430 if [ $ret -ne 0 ];then
438 kci_test_encap_vxlan()
444 run_cmd ip -netns "$testns" link add "$vxlan" type vxlan id 42 group 239.1.1.1 \
445 dev "$devdummy" dstport 4789
446 if [ $? -ne 0 ]; then
447 end_test "FAIL: can't add vxlan interface, skipping test"
451 run_cmd ip -netns "$testns" addr add 10.2.11.49/24 dev "$vxlan"
452 run_cmd ip -netns "$testns" link set up dev "$vxlan"
453 run_cmd ip -netns "$testns" link add link "$vxlan" name "$vlan" type vlan id 1
455 # changelink testcases
456 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan vni 43
457 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan group ffe5::5 dev "$devdummy"
458 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan ttl inherit
460 run_cmd ip -netns "$testns" link set dev "$vxlan" type vxlan ttl 64
461 run_cmd ip -netns "$testns" link set dev "$vxlan" type vxlan nolearning
463 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan proxy
464 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan norsc
465 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan l2miss
466 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan l3miss
467 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan external
468 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan udpcsum
469 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumtx
470 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan udp6zerocsumrx
471 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumtx
472 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan remcsumrx
473 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan gbp
474 run_cmd_fail ip -netns "$testns" link set dev "$vxlan" type vxlan gpe
475 run_cmd ip -netns "$testns" link del "$vxlan"
477 if [ $ret -ne 0 ]; then
478 end_test "FAIL: vxlan"
481 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 run_cmd ip netns add "$testns"
523 if [ $? -ne 0 ]; then
524 end_test "SKIP encap tests: cannot add net namespace $testns"
527 run_cmd ip -netns "$testns" link set lo up
528 run_cmd ip -netns "$testns" link add name "$devdummy" type dummy
529 run_cmd ip -netns "$testns" link set "$devdummy" up
530 run_cmd kci_test_encap_vxlan "$testns"
531 run_cmd kci_test_encap_fou "$testns"
533 ip netns del "$testns"
539 msname="test_macsec0"
541 run_cmd_grep "^Usage: ip macsec" ip macsec help
542 if [ $? -ne 0 ]; then
543 end_test "SKIP: macsec: iproute2 too old"
546 run_cmd ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on
547 if [ $ret -ne 0 ];then
548 end_test "FAIL: can't add macsec interface, skipping test"
551 run_cmd ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
552 run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
553 run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on key 00 0123456789abcdef0123456789abcdef
554 run_cmd ip macsec show
555 run_cmd ip link del dev "$msname"
557 if [ $ret -ne 0 ];then
558 end_test "FAIL: macsec"
562 end_test "PASS: macsec"
565 kci_test_macsec_offload()
567 sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
568 sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
571 run_cmd_grep "^Usage: ip macsec" ip macsec help
572 if [ $? -ne 0 ]; then
573 end_test "SKIP: macsec: iproute2 too old"
577 # setup netdevsim since dummydev doesn't have offload support
578 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
579 run_cmd modprobe -q netdevsim
581 if [ $ret -ne 0 ]; then
582 end_test "SKIP: macsec_offload can't load netdevsim"
588 echo "0" > /sys/bus/netdevsim/new_device
589 while [ ! -d $sysfsnet ] ; do :; done
594 if [ ! -d $sysfsd ] ; then
595 end_test "FAIL: macsec_offload can't create device $dev"
598 run_cmd_grep 'macsec-hw-offload: on' ethtool -k $dev
599 if [ $? -eq 1 ] ; then
600 end_test "FAIL: macsec_offload netdevsim doesn't support MACsec offload"
603 run_cmd ip link add link $dev kci_macsec1 type macsec port 4 offload mac
604 run_cmd ip link add link $dev kci_macsec2 type macsec address "aa:bb:cc:dd:ee:ff" port 5 offload mac
605 run_cmd ip link add link $dev kci_macsec3 type macsec sci abbacdde01020304 offload mac
606 run_cmd_fail ip link add link $dev kci_macsec4 type macsec port 8 offload mac
609 run_cmd ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
610 run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
611 run_cmd ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on \
612 key 00 0123456789abcdef0123456789abcdef
613 run_cmd_fail ip macsec add "$msname" rx port 1235 address "1c:ed:de:ad:be:ef"
614 # clean up any leftovers
615 for msdev in kci_macsec{1,2,3,4} ; do
616 ip link del $msdev 2> /dev/null
618 echo 0 > /sys/bus/netdevsim/del_device
619 $probed && rmmod netdevsim
621 if [ $ret -ne 0 ]; then
622 end_test "FAIL: macsec_offload"
625 end_test "PASS: macsec_offload"
628 #-------------------------------------------------------------------
630 # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
631 # spi 0x07 mode transport reqid 0x07 replay-window 32 \
632 # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
633 # sel src 14.0.0.52/24 dst 14.0.0.70/24
634 # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
635 # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
636 # spi 0x07 mode transport reqid 0x07
638 # Subcommands not tested
645 #-------------------------------------------------------------------
649 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
654 ip addr add $srcip dev $devdummy
656 # flush to be sure there's nothing configured
657 run_cmd ip x s flush ; ip x p flush
659 # start the monitor in the background
660 tmpfile=`mktemp /var/run/ipsectestXXX`
661 mpid=`(ip x m > $tmpfile & echo $!) 2>/dev/null`
664 ipsecid="proto esp src $srcip dst $dstip spi 0x07"
665 run_cmd ip x s add $ipsecid \
666 mode transport reqid 0x07 replay-window 32 \
667 $algo sel src $srcip/24 dst $dstip/24
670 lines=`ip x s list | grep $srcip | grep $dstip | wc -l`
671 run_cmd test $lines -eq 2
672 run_cmd_grep "SAD count 1" ip x s count
674 lines=`ip x s get $ipsecid | grep $srcip | grep $dstip | wc -l`
675 run_cmd test $lines -eq 2
676 run_cmd ip x s delete $ipsecid
678 lines=`ip x s list | wc -l`
679 run_cmd test $lines -eq 0
681 ipsecsel="dir out src $srcip/24 dst $dstip/24"
682 run_cmd ip x p add $ipsecsel \
683 tmpl proto esp src $srcip dst $dstip \
684 spi 0x07 mode transport reqid 0x07
687 lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
688 run_cmd test $lines -eq 2
690 run_cmd_grep "SPD IN 0 OUT 1 FWD 0" ip x p count
692 lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
693 run_cmd test $lines -eq 2
695 run_cmd ip x p delete $ipsecsel
697 lines=`ip x p list | wc -l`
698 run_cmd test $lines -eq 0
700 # check the monitor results
702 lines=`wc -l $tmpfile | cut "-d " -f1`
703 run_cmd test $lines -eq 20
706 # clean up any leftovers
709 ip addr del $srcip/32 dev $devdummy
711 if [ $ret -ne 0 ]; then
712 end_test "FAIL: ipsec"
715 end_test "PASS: ipsec"
718 #-------------------------------------------------------------------
720 # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
721 # spi 0x07 mode transport reqid 0x07 replay-window 32 \
722 # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
723 # sel src 14.0.0.52/24 dst 14.0.0.70/24
724 # offload dev sim1 dir out
725 # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
726 # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
727 # spi 0x07 mode transport reqid 0x07
729 #-------------------------------------------------------------------
730 kci_test_ipsec_offload()
733 algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
736 sysfsd=/sys/kernel/debug/netdevsim/netdevsim0/ports/0/
738 sysfsnet=/sys/bus/netdevsim/devices/netdevsim0/net/
741 # setup netdevsim since dummydev doesn't have offload support
742 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
743 run_cmd modprobe -q netdevsim
744 if [ $ret -ne 0 ]; then
745 end_test "SKIP: ipsec_offload can't load netdevsim"
751 echo "0" > /sys/bus/netdevsim/new_device
752 while [ ! -d $sysfsnet ] ; do :; done
756 ip addr add $srcip dev $dev
758 if [ ! -d $sysfsd ] ; then
759 end_test "FAIL: ipsec_offload can't create device $dev"
762 if [ ! -f $sysfsf ] ; then
763 end_test "FAIL: ipsec_offload netdevsim doesn't support IPsec offload"
767 # flush to be sure there's nothing configured
768 ip x s flush ; ip x p flush
770 # create offloaded SAs, both in and out
771 run_cmd ip x p add dir out src $srcip/24 dst $dstip/24 \
772 tmpl proto esp src $srcip dst $dstip spi 9 \
773 mode transport reqid 42
775 run_cmd ip x p add dir in src $dstip/24 dst $srcip/24 \
776 tmpl proto esp src $dstip dst $srcip spi 9 \
777 mode transport reqid 42
779 run_cmd ip x s add proto esp src $srcip dst $dstip spi 9 \
780 mode transport reqid 42 $algo sel src $srcip/24 dst $dstip/24 \
781 offload dev $dev dir out
783 run_cmd ip x s add proto esp src $dstip dst $srcip spi 9 \
784 mode transport reqid 42 $algo sel src $dstip/24 dst $srcip/24 \
785 offload dev $dev dir in
787 if [ $ret -ne 0 ]; then
788 end_test "FAIL: ipsec_offload can't create SA"
792 # does offload show up in ip output
793 lines=`ip x s list | grep -c "crypto offload parameters: dev $dev dir"`
794 if [ $lines -ne 2 ] ; then
796 end_test "FAIL: ipsec_offload SA offload missing from list output"
799 # use ping to exercise the Tx path
800 ping -I $dev -c 3 -W 1 -i 0 $dstip >/dev/null
802 # does driver have correct offload info
803 run_cmd diff $sysfsf - << EOF
805 sa[0] tx ipaddr=0x00000000 00000000 00000000 00000000
806 sa[0] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
807 sa[0] key=0x34333231 38373635 32313039 36353433
808 sa[1] rx ipaddr=0x00000000 00000000 00000000 037ba8c0
809 sa[1] spi=0x00000009 proto=0x32 salt=0x61626364 crypt=1
810 sa[1] key=0x34333231 38373635 32313039 36353433
812 if [ $? -ne 0 ] ; then
813 end_test "FAIL: ipsec_offload incorrect driver data"
817 # does offload get removed from driver
820 lines=`grep -c "SA count=0" $sysfsf`
821 if [ $lines -ne 1 ] ; then
823 end_test "FAIL: ipsec_offload SA not removed from driver"
826 # clean up any leftovers
827 echo 0 > /sys/bus/netdevsim/del_device
828 $probed && rmmod netdevsim
830 if [ $ret -ne 0 ]; then
831 end_test "FAIL: ipsec_offload"
834 end_test "PASS: ipsec_offload"
843 run_cmd ip netns add "$testns"
844 if [ $? -ne 0 ]; then
845 end_test "SKIP gretap tests: cannot add net namespace $testns"
849 run_cmd_grep "^Usage:" ip link help gretap
851 end_test "SKIP: gretap: iproute2 too old"
852 ip netns del "$testns"
857 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type gretap seq \
858 key 102 local 172.16.1.100 remote 172.16.1.200
861 run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
862 run_cmd ip -netns "$testns" link set dev $DEV_NS ups
863 run_cmd ip -netns "$testns" link del "$DEV_NS"
866 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type gretap external
867 run_cmd ip -netns "$testns" link del "$DEV_NS"
869 if [ $ret -ne 0 ]; then
870 end_test "FAIL: gretap"
871 ip netns del "$testns"
874 end_test "PASS: gretap"
876 ip netns del "$testns"
885 run_cmd ip netns add "$testns"
886 if [ $? -ne 0 ]; then
887 end_test "SKIP ip6gretap tests: cannot add net namespace $testns"
891 run_cmd_grep "^Usage:" ip link help ip6gretap
893 end_test "SKIP: ip6gretap: iproute2 too old"
894 ip netns del "$testns"
899 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap seq \
900 key 102 local fc00:100::1 remote fc00:100::2
903 run_cmd ip -netns "$testns" addr add dev "$DEV_NS" fc00:200::1/96
904 run_cmd ip -netns "$testns" link set dev $DEV_NS up
905 run_cmd ip -netns "$testns" link del "$DEV_NS"
908 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6gretap external
909 run_cmd ip -netns "$testns" link del "$DEV_NS"
911 if [ $ret -ne 0 ]; then
912 end_test "FAIL: ip6gretap"
913 ip netns del "$testns"
916 end_test "PASS: ip6gretap"
918 ip netns del "$testns"
926 run_cmd_grep "^Usage:" ip link help erspan
928 end_test "SKIP: erspan: iproute2 too old"
931 run_cmd ip netns add "$testns"
932 if [ $? -ne 0 ]; then
933 end_test "SKIP erspan tests: cannot add net namespace $testns"
937 # test native tunnel erspan v1
938 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
939 key 102 local 172.16.1.100 remote 172.16.1.200 \
940 erspan_ver 1 erspan 488
943 run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
944 run_cmd ip -netns "$testns" link set dev $DEV_NS up
945 run_cmd ip -netns "$testns" link del "$DEV_NS"
947 # test native tunnel erspan v2
948 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type erspan seq \
949 key 102 local 172.16.1.100 remote 172.16.1.200 \
950 erspan_ver 2 erspan_dir ingress erspan_hwid 7
953 run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
954 run_cmd ip -netns "$testns" link set dev $DEV_NS up
955 run_cmd ip -netns "$testns" link del "$DEV_NS"
958 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type erspan external
959 run_cmd ip -netns "$testns" link del "$DEV_NS"
961 if [ $ret -ne 0 ]; then
962 end_test "FAIL: erspan"
963 ip netns del "$testns"
966 end_test "PASS: erspan"
968 ip netns del "$testns"
976 run_cmd_grep "^Usage:" ip link help ip6erspan
978 end_test "SKIP: ip6erspan: iproute2 too old"
981 run_cmd ip netns add "$testns"
982 if [ $? -ne 0 ]; then
983 end_test "SKIP ip6erspan tests: cannot add net namespace $testns"
987 # test native tunnel ip6erspan v1
988 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
989 key 102 local fc00:100::1 remote fc00:100::2 \
990 erspan_ver 1 erspan 488
993 run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
994 run_cmd ip -netns "$testns" link set dev $DEV_NS up
995 run_cmd ip -netns "$testns" link del "$DEV_NS"
997 # test native tunnel ip6erspan v2
998 run_cmd ip -netns "$testns" link add dev "$DEV_NS" type ip6erspan seq \
999 key 102 local fc00:100::1 remote fc00:100::2 \
1000 erspan_ver 2 erspan_dir ingress erspan_hwid 7
1003 run_cmd ip -netns "$testns" addr add dev "$DEV_NS" 10.1.1.100/24
1004 run_cmd ip -netns "$testns" link set dev $DEV_NS up
1005 run_cmd ip -netns "$testns" link del "$DEV_NS"
1007 # test external mode
1008 run_cmd ip -netns "$testns" link add dev "$DEV_NS" \
1009 type ip6erspan external
1011 run_cmd ip -netns "$testns" link del "$DEV_NS"
1013 if [ $ret -ne 0 ]; then
1014 end_test "FAIL: ip6erspan"
1015 ip netns del "$testns"
1018 end_test "PASS: ip6erspan"
1020 ip netns del "$testns"
1025 IP="ip -netns testns"
1026 BRIDGE="bridge -netns testns"
1029 test_mac=de:ad:be:ef:13:37
1034 run_cmd_grep 'bridge fdb get' bridge fdb help
1035 if [ $? -ne 0 ];then
1036 end_test "SKIP: fdb get tests: iproute2 too old"
1040 run_cmd ip netns add testns
1041 if [ $? -ne 0 ]; then
1042 end_test "SKIP fdb get tests: cannot add net namespace $testns"
1045 run_cmd $IP link add "$vxlandev" type vxlan id 10 local $localip \
1047 run_cmd $IP link add name "$brdev" type bridge
1048 run_cmd $IP link set dev "$vxlandev" master "$brdev"
1049 run_cmd $BRIDGE fdb add $test_mac dev "$vxlandev" master
1050 run_cmd $BRIDGE fdb add $test_mac dev "$vxlandev" dst $dstip self
1051 run_cmd_grep "dev $vxlandev master $brdev" $BRIDGE fdb get $test_mac brport "$vxlandev"
1052 run_cmd_grep "dev $vxlandev master $brdev" $BRIDGE fdb get $test_mac br "$brdev"
1053 run_cmd_grep "dev $vxlandev dst $dstip" $BRIDGE fdb get $test_mac dev "$vxlandev" self
1055 ip netns del testns &>/dev/null
1057 if [ $ret -ne 0 ]; then
1058 end_test "FAIL: bridge fdb get"
1062 end_test "PASS: bridge fdb get"
1065 kci_test_neigh_get()
1067 dstmac=de:ad:be:ef:13:37
1072 run_cmd_grep 'ip neigh get' ip neigh help
1073 if [ $? -ne 0 ];then
1074 end_test "SKIP: fdb get tests: iproute2 too old"
1079 run_cmd ip neigh add $dstip lladdr $dstmac dev "$devdummy"
1080 run_cmd_grep "$dstmac" ip neigh get $dstip dev "$devdummy"
1081 run_cmd ip neigh del $dstip lladdr $dstmac dev "$devdummy"
1084 run_cmd ip neigh add proxy $dstip dev "$devdummy"
1085 run_cmd_grep "$dstip" ip neigh get proxy $dstip dev "$devdummy"
1086 run_cmd ip neigh del proxy $dstip dev "$devdummy"
1089 run_cmd ip neigh add $dstip6 lladdr $dstmac dev "$devdummy"
1090 run_cmd_grep "$dstmac" ip neigh get $dstip6 dev "$devdummy"
1091 run_cmd ip neigh del $dstip6 lladdr $dstmac dev "$devdummy"
1094 run_cmd ip neigh add proxy $dstip6 dev "$devdummy"
1095 run_cmd_grep "$dstip6" ip neigh get proxy $dstip6 dev "$devdummy"
1096 run_cmd ip neigh del proxy $dstip6 dev "$devdummy"
1098 if [ $ret -ne 0 ];then
1099 end_test "FAIL: neigh get"
1103 end_test "PASS: neigh get"
1106 kci_test_bridge_parent_id()
1109 sysfsnet=/sys/bus/netdevsim/devices/netdevsim
1112 if [ ! -w /sys/bus/netdevsim/new_device ] ; then
1113 run_cmd modprobe -q netdevsim
1114 if [ $ret -ne 0 ]; then
1115 end_test "SKIP: bridge_parent_id can't load netdevsim"
1121 echo "10 1" > /sys/bus/netdevsim/new_device
1122 while [ ! -d ${sysfsnet}10 ] ; do :; done
1123 echo "20 1" > /sys/bus/netdevsim/new_device
1124 while [ ! -d ${sysfsnet}20 ] ; do :; done
1126 dev10=`ls ${sysfsnet}10/net/`
1127 dev20=`ls ${sysfsnet}20/net/`
1128 run_cmd ip link add name test-bond0 type bond mode 802.3ad
1129 run_cmd ip link set dev $dev10 master test-bond0
1130 run_cmd ip link set dev $dev20 master test-bond0
1131 run_cmd ip link add name test-br0 type bridge
1132 run_cmd ip link set dev test-bond0 master test-br0
1134 # clean up any leftovers
1135 ip link del dev test-br0
1136 ip link del dev test-bond0
1137 echo 20 > /sys/bus/netdevsim/del_device
1138 echo 10 > /sys/bus/netdevsim/del_device
1139 $probed && rmmod netdevsim
1141 if [ $ret -ne 0 ]; then
1142 end_test "FAIL: bridge_parent_id"
1145 end_test "PASS: bridge_parent_id"
1150 local addr=$1; shift
1152 ip -N -j address show dev "$devdummy" |
1153 jq -e -r --arg addr "${addr%/*}" \
1154 '.[].addr_info[] | select(.local == $addr) | .protocol'
1159 ip -N -j address show dev "$devdummy" "$@" |
1160 jq -e -r '[.[].addr_info[] | .local | select(. != null)] | length'
1163 do_test_address_proto()
1165 local what=$1; shift
1166 local addr=$1; shift
1167 local addr2=${addr%/*}2/${addr#*/}
1168 local addr3=${addr%/*}3/${addr#*/}
1174 ip address add dev "$devdummy" "$addr3"
1176 proto=$(address_get_proto "$addr3")
1177 [[ "$proto" == null ]]
1180 ip address add dev "$devdummy" "$addr2" proto 0x99
1182 proto=$(address_get_proto "$addr2")
1183 [[ "$proto" == 0x99 ]]
1186 ip address add dev "$devdummy" "$addr" proto 0xab
1188 proto=$(address_get_proto "$addr")
1189 [[ "$proto" == 0xab ]]
1192 ip address replace dev "$devdummy" "$addr" proto 0x11
1193 proto=$(address_get_proto "$addr")
1195 [[ "$proto" == 0x11 ]]
1198 count=$(address_count)
1200 (( count >= 3 )) # $addr, $addr2 and $addr3 plus any kernel addresses
1203 count=$(address_count proto 0)
1205 (( count == 1 )) # just $addr3
1208 count=$(address_count proto 0x11)
1210 (( count == 2 )) # $addr and $addr3
1213 count=$(address_count proto 0xab)
1215 (( count == 1 )) # just $addr3
1218 ip address del dev "$devdummy" "$addr"
1219 ip address del dev "$devdummy" "$addr2"
1220 ip address del dev "$devdummy" "$addr3"
1222 if [ $ret -ne 0 ]; then
1223 end_test "FAIL: address proto $what"
1226 end_test "PASS: address proto $what"
1229 kci_test_address_proto()
1233 do_test_address_proto IPv4 192.0.2.1/28
1236 do_test_address_proto IPv6 2001:db8:1::1/64
1248 if [ $ret -ne 0 ];then
1249 end_test "FAIL: cannot add dummy interface"
1253 for current_test in ${TESTS:-$ALL_TESTS}; do
1265 usage: ${0##*/} OPTS
1267 -t <test> Test(s) to run (default: all)
1268 (options: $(echo $ALL_TESTS))
1269 -v Verbose mode (show commands and output)
1270 -P Pause after every test
1271 -p Pause after every failing test before cleanup (for debugging)
1275 #check for needed privileges
1276 if [ "$(id -u)" -ne 0 ];then
1277 end_test "SKIP: Need root privileges"
1282 $x -Version 2>/dev/null >/dev/null
1283 if [ $? -ne 0 ];then
1284 end_test "SKIP: Could not run test without the $x tool"
1289 while getopts t:hvpP o; do
1293 p) PAUSE_ON_FAIL=yes;;
1300 [ $PAUSE = "yes" ] && PAUSE_ON_FAIL="no"