3 # This test is for checking rtnetlink callpaths, and get as much coverage as possible.
10 # set global exit status, but never reset nonzero one.
13 if [ $ret -eq 0 ]; then
18 # same but inverted -- used when command must fail for test to pass
28 ip link add name
"$devdummy" type dummy
30 ip link
set "$devdummy" up
36 ip link del dev
"$devdummy"
45 ip netconf show dev
"$dev" > /dev
/null
49 ip
-$f netconf show dev
"$dev" > /dev
/null
53 if [ $ret -ne 0 ] ;then
54 echo "FAIL: ip netconf show $dev"
55 test $r -eq 0 && ret
=0
60 # add a bridge with vlans on top
64 vlandev
="testbr-vlan1"
67 ip link add name
"$devbr" type bridge
70 ip link
set dev
"$devdummy" master
"$devbr"
73 ip link
set "$devbr" up
76 ip link add link
"$devbr" name
"$vlandev" type vlan id
1
78 ip addr add dev
"$vlandev" 10.200.7.23/30
80 ip
-6 addr add dev
"$vlandev" dead
:42::1234/64
82 ip
-d link
> /dev
/null
84 ip r s t all
> /dev
/null
87 for name
in "$devbr" "$vlandev" "$devdummy" ; do
88 kci_test_netconf
"$name"
91 ip
-6 addr del dev
"$vlandev" dead
:42::1234/64
94 ip link del dev
"$vlandev"
96 ip link del dev
"$devbr"
99 if [ $ret -ne 0 ];then
100 echo "FAIL: bridge setup"
103 echo "PASS: bridge setup"
114 ip tunnel add
$gredev mode gre remote
$rem local $loc ttl
1
116 ip link
set $gredev up
118 ip addr add
10.23.7.10 dev
$gredev
120 ip route add
10.23.8.0/30 dev
$gredev
122 ip addr add dev
"$devdummy" 10.23.7.11/24
129 kci_test_netconf
"$gredev"
131 ip addr del dev
"$devdummy" 10.23.7.11/24
137 if [ $ret -ne 0 ];then
138 echo "FAIL: gre tunnel endpoint"
141 echo "PASS: gre tunnel endpoint"
144 # tc uses rtnetlink too, for full tc testing
145 # please see tools/testing/selftests/tc-testing.
151 tc qdisc add dev
"$dev" root handle
1: htb
153 tc class add dev
"$dev" parent
1: classid
1:10 htb rate
1mbit
155 tc filter add dev
"$dev" parent
1:0 prio
5 handle ffe
: protocol ip u32 divisor
256
157 tc filter add dev
"$dev" parent
1:0 prio
5 handle ffd
: protocol ip u32 divisor
256
159 tc filter add dev
"$dev" parent
1:0 prio
5 handle ffc
: protocol ip u32 divisor
256
161 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
163 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
165 tc filter show dev
"$dev" parent
1:0 > /dev
/null
167 tc filter del dev
"$dev" protocol ip parent
1: prio
5 handle ffe
:2:3 u32
169 tc filter show dev
"$dev" parent
1:0 > /dev
/null
171 tc qdisc del dev
"$dev" root handle
1: htb
174 if [ $ret -ne 0 ];then
175 echo "FAIL: tc htb hierarchy"
178 echo "PASS: tc htb hierarchy"
182 kci_test_polrouting
()
185 ip rule add fwmark
1 lookup
100
187 ip route add
local 0.0.0.0/0 dev lo table
100
189 ip r s t all
> /dev
/null
191 ip rule del fwmark
1 lookup
100
193 ip route del
local 0.0.0.0/0 dev lo table
100
196 if [ $ret -ne 0 ];then
197 echo "FAIL: policy route test"
200 echo "PASS: policy routing"
207 ip route get
127.0.0.1 > /dev
/null
209 ip route get
127.0.0.1 dev
"$devdummy" > /dev
/null
211 ip route get
::1 > /dev
/null
213 ip route get fe80
::1 dev
"$devdummy" > /dev
/null
215 ip route get
127.0.0.1 from
127.0.0.1 oif lo tos
0x1 mark
0x1 > /dev
/null
217 ip route get
::1 from
::1 iif lo oif lo tos
0x1 mark
0x1 > /dev
/null
219 ip addr add dev
"$devdummy" 10.23.7.11/24
221 ip route get
10.23.7.11 from
10.23.7.12 iif
"$devdummy" > /dev
/null
223 ip addr del dev
"$devdummy" 10.23.7.11/24
226 if [ $ret -ne 0 ];then
227 echo "FAIL: route get"
231 echo "PASS: route get"
238 ip addrlabel add prefix dead
::/64 dev lo label
1
241 ip addrlabel list |
grep -q "prefix dead::/64 dev lo label 1"
244 ip addrlabel del prefix dead
::/64 dev lo label
1 2> /dev
/null
247 ip addrlabel add prefix dead
::/64 label
1 2> /dev
/null
250 ip addrlabel del prefix dead
::/64 label
1 2> /dev
/null
253 # concurrent add/delete
254 for i
in $
(seq 1 1000); do
255 ip addrlabel add prefix
1c3
::/64 label
12345 2>/dev
/null
258 for i
in $
(seq 1 1000); do
259 ip addrlabel del prefix
1c3
::/64 label
12345 2>/dev
/null
264 ip addrlabel del prefix
1c3
::/64 label
12345 2>/dev
/null
266 if [ $ret -ne 0 ];then
267 echo "FAIL: ipv6 addrlabel"
271 echo "PASS: ipv6 addrlabel"
278 syspathname
="/sys/class/net/$devdummy/ifalias"
280 ip link
set dev
"$devdummy" alias "$namewant"
283 if [ $ret -ne 0 ]; then
284 echo "FAIL: cannot set interface alias of $devdummy to $namewant"
288 ip link show
"$devdummy" |
grep -q "alias $namewant"
291 if [ -r "$syspathname" ] ; then
292 read namehave
< "$syspathname"
293 if [ "$namewant" != "$namehave" ]; then
294 echo "FAIL: did set ifalias $namewant but got $namehave"
299 echo "$namewant" > "$syspathname"
300 ip link show
"$devdummy" |
grep -q "alias $namewant"
303 # sysfs interface allows to delete alias again
304 echo "" > "$syspathname"
306 ip link show
"$devdummy" |
grep -q "alias $namewant"
309 for i
in $
(seq 1 100); do
310 uuidgen
> "$syspathname" &
315 # re-add the alias -- kernel should free mem when dummy dev is removed
316 ip link
set dev
"$devdummy" alias "$namewant"
320 if [ $ret -ne 0 ]; then
321 echo "FAIL: set interface alias $devdummy to $namewant"
325 echo "PASS: set ifalias $namewant for $devdummy"
333 ip link show
type vrf
2>/dev
/null
334 if [ $?
-ne 0 ]; then
335 echo "SKIP: vrf: iproute2 too old"
339 ip link add
"$vrfname" type vrf table
10
341 if [ $ret -ne 0 ];then
342 echo "FAIL: can't add vrf interface, skipping test"
346 ip
-br link show
type vrf |
grep -q "$vrfname"
348 if [ $ret -ne 0 ];then
349 echo "FAIL: created vrf device not found"
353 ip link
set dev
"$vrfname" up
356 ip link
set dev
"$devdummy" master
"$vrfname"
358 ip link del dev
"$vrfname"
361 if [ $ret -ne 0 ];then
369 kci_test_encap_vxlan
()
376 ip netns
exec "$testns" ip link add
"$vxlan" type vxlan id
42 group
239.1.1.1 \
377 dev
"$devdummy" dstport
4789 2>/dev
/null
378 if [ $?
-ne 0 ]; then
379 echo "FAIL: can't add vxlan interface, skipping test"
384 ip netns
exec "$testns" ip addr add
10.2.11.49/24 dev
"$vxlan"
387 ip netns
exec "$testns" ip link
set up dev
"$vxlan"
390 ip netns
exec "$testns" ip link add link
"$vxlan" name
"$vlan" type vlan id
1
393 ip netns
exec "$testns" ip link del
"$vxlan"
396 if [ $ret -ne 0 ]; then
409 ip fou
help 2>&1 |
grep -q 'Usage: ip fou'
411 echo "SKIP: fou: iproute2 too old"
415 ip netns
exec "$testns" ip fou add port
7777 ipproto
47 2>/dev
/null
417 echo "FAIL: can't add fou port 7777, skipping test"
421 ip netns
exec "$testns" ip fou add port
8888 ipproto
4
424 ip netns
exec "$testns" ip fou del port
9999 2>/dev
/null
427 ip netns
exec "$testns" ip fou del port
7777
430 if [ $ret -ne 0 ]; then
438 # test various encap methods, use netns to avoid unwanted interference
444 ip netns add
"$testns"
445 if [ $?
-ne 0 ]; then
446 echo "SKIP encap tests: cannot add net namespace $testns"
450 ip netns
exec "$testns" ip link
set lo up
453 ip netns
exec "$testns" ip link add name
"$devdummy" type dummy
455 ip netns
exec "$testns" ip link
set "$devdummy" up
458 kci_test_encap_vxlan
"$testns"
459 kci_test_encap_fou
"$testns"
461 ip netns del
"$testns"
466 msname
="test_macsec0"
469 ip macsec
help 2>&1 |
grep -q "^Usage: ip macsec"
470 if [ $?
-ne 0 ]; then
471 echo "SKIP: macsec: iproute2 too old"
475 ip link add link
"$devdummy" "$msname" type macsec port
42 encrypt on
477 if [ $ret -ne 0 ];then
478 echo "FAIL: can't add macsec interface, skipping test"
482 ip macsec add
"$msname" tx sa
0 pn
1024 on key
01 12345678901234567890123456789012
485 ip macsec add
"$msname" rx port
1234 address
"1c:ed:de:ad:be:ef"
488 ip macsec add
"$msname" rx port
1234 address
"1c:ed:de:ad:be:ef" sa
0 pn
1 on key
00 0123456789abcdef0123456789abcdef
491 ip macsec show
> /dev
/null
494 ip link del dev
"$msname"
497 if [ $ret -ne 0 ];then
511 ip netns add
"$testns"
512 if [ $?
-ne 0 ]; then
513 echo "SKIP gretap tests: cannot add net namespace $testns"
517 ip link
help gretap
2>&1 |
grep -q "^Usage:"
519 echo "SKIP: gretap: iproute2 too old"
524 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type gretap
seq \
525 key
102 local 172.16.1.100 remote
172.16.1.200
528 ip netns
exec "$testns" ip addr add dev
"$DEV_NS" 10.1.1.100/24
531 ip netns
exec "$testns" ip link
set dev
$DEV_NS up
534 ip netns
exec "$testns" ip link del
"$DEV_NS"
538 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type gretap external
541 ip netns
exec "$testns" ip link del
"$DEV_NS"
544 if [ $ret -ne 0 ]; then
550 ip netns del
"$testns"
559 ip netns add
"$testns"
560 if [ $?
-ne 0 ]; then
561 echo "SKIP ip6gretap tests: cannot add net namespace $testns"
565 ip link
help ip6gretap
2>&1 |
grep -q "^Usage:"
567 echo "SKIP: ip6gretap: iproute2 too old"
572 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type ip6gretap
seq \
573 key
102 local fc00
:100::1 remote fc00
:100::2
576 ip netns
exec "$testns" ip addr add dev
"$DEV_NS" fc00
:200::1/96
579 ip netns
exec "$testns" ip link
set dev
$DEV_NS up
582 ip netns
exec "$testns" ip link del
"$DEV_NS"
586 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type ip6gretap external
589 ip netns
exec "$testns" ip link del
"$DEV_NS"
592 if [ $ret -ne 0 ]; then
593 echo "FAIL: ip6gretap"
596 echo "PASS: ip6gretap"
598 ip netns del
"$testns"
607 ip link
help erspan
2>&1 |
grep -q "^Usage:"
609 echo "SKIP: erspan: iproute2 too old"
613 ip netns add
"$testns"
614 if [ $?
-ne 0 ]; then
615 echo "SKIP erspan tests: cannot add net namespace $testns"
619 # test native tunnel erspan v1
620 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type erspan
seq \
621 key
102 local 172.16.1.100 remote
172.16.1.200 \
622 erspan_ver
1 erspan
488
625 ip netns
exec "$testns" ip addr add dev
"$DEV_NS" 10.1.1.100/24
628 ip netns
exec "$testns" ip link
set dev
$DEV_NS up
631 ip netns
exec "$testns" ip link del
"$DEV_NS"
634 # test native tunnel erspan v2
635 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type erspan
seq \
636 key
102 local 172.16.1.100 remote
172.16.1.200 \
637 erspan_ver
2 erspan_dir ingress erspan_hwid
7
640 ip netns
exec "$testns" ip addr add dev
"$DEV_NS" 10.1.1.100/24
643 ip netns
exec "$testns" ip link
set dev
$DEV_NS up
646 ip netns
exec "$testns" ip link del
"$DEV_NS"
650 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type erspan external
653 ip netns
exec "$testns" ip link del
"$DEV_NS"
656 if [ $ret -ne 0 ]; then
662 ip netns del
"$testns"
671 ip link
help ip6erspan
2>&1 |
grep -q "^Usage:"
673 echo "SKIP: ip6erspan: iproute2 too old"
677 ip netns add
"$testns"
678 if [ $?
-ne 0 ]; then
679 echo "SKIP ip6erspan tests: cannot add net namespace $testns"
683 # test native tunnel ip6erspan v1
684 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type ip6erspan
seq \
685 key
102 local fc00
:100::1 remote fc00
:100::2 \
686 erspan_ver
1 erspan
488
689 ip netns
exec "$testns" ip addr add dev
"$DEV_NS" 10.1.1.100/24
692 ip netns
exec "$testns" ip link
set dev
$DEV_NS up
695 ip netns
exec "$testns" ip link del
"$DEV_NS"
698 # test native tunnel ip6erspan v2
699 ip netns
exec "$testns" ip link add dev
"$DEV_NS" type ip6erspan
seq \
700 key
102 local fc00
:100::1 remote fc00
:100::2 \
701 erspan_ver
2 erspan_dir ingress erspan_hwid
7
704 ip netns
exec "$testns" ip addr add dev
"$DEV_NS" 10.1.1.100/24
707 ip netns
exec "$testns" ip link
set dev
$DEV_NS up
710 ip netns
exec "$testns" ip link del
"$DEV_NS"
714 ip netns
exec "$testns" ip link add dev
"$DEV_NS" \
715 type ip6erspan external
718 ip netns
exec "$testns" ip link del
"$DEV_NS"
721 if [ $ret -ne 0 ]; then
722 echo "FAIL: ip6erspan"
725 echo "PASS: ip6erspan"
727 ip netns del
"$testns"
733 if [ $ret -ne 0 ];then
734 echo "FAIL: cannot add dummy interface"
756 #check for needed privileges
757 if [ "$(id -u)" -ne 0 ];then
758 echo "SKIP: Need root privileges"
763 $x -Version 2>/dev
/null
>/dev
/null
765 echo "SKIP: Could not run test without the $x tool"