Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / net / fib_tests.sh
blob67048f922ff202d9ef55e3a3f876de25a24112f7
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking IPv4 and IPv6 FIB behavior in response to
5 # different events.
7 ret=0
8 # Kselftest framework requirement - SKIP code is 4.
9 ksft_skip=4
11 # all tests in this script. Can be overridden with -t option
12 TESTS="unregister down carrier nexthop ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric"
13 VERBOSE=0
14 PAUSE_ON_FAIL=no
15 PAUSE=no
16 IP="ip -netns testns"
18 log_test()
20 local rc=$1
21 local expected=$2
22 local msg="$3"
24 if [ ${rc} -eq ${expected} ]; then
25 printf " TEST: %-60s [ OK ]\n" "${msg}"
26 nsuccess=$((nsuccess+1))
27 else
28 ret=1
29 nfail=$((nfail+1))
30 printf " TEST: %-60s [FAIL]\n" "${msg}"
31 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
32 echo
33 echo "hit enter to continue, 'q' to quit"
34 read a
35 [ "$a" = "q" ] && exit 1
39 if [ "${PAUSE}" = "yes" ]; then
40 echo
41 echo "hit enter to continue, 'q' to quit"
42 read a
43 [ "$a" = "q" ] && exit 1
47 setup()
49 set -e
50 ip netns add testns
51 $IP link set dev lo up
53 $IP link add dummy0 type dummy
54 $IP link set dev dummy0 up
55 $IP address add 198.51.100.1/24 dev dummy0
56 $IP -6 address add 2001:db8:1::1/64 dev dummy0
57 set +e
61 cleanup()
63 $IP link del dev dummy0 &> /dev/null
64 ip netns del testns
67 get_linklocal()
69 local dev=$1
70 local addr
72 addr=$($IP -6 -br addr show dev ${dev} | \
73 awk '{
74 for (i = 3; i <= NF; ++i) {
75 if ($i ~ /^fe80/)
76 print $i
80 addr=${addr/\/*}
82 [ -z "$addr" ] && return 1
84 echo $addr
86 return 0
89 fib_unreg_unicast_test()
91 echo
92 echo "Single path route test"
94 setup
96 echo " Start point"
97 $IP route get fibmatch 198.51.100.2 &> /dev/null
98 log_test $? 0 "IPv4 fibmatch"
99 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
100 log_test $? 0 "IPv6 fibmatch"
102 set -e
103 $IP link del dev dummy0
104 set +e
106 echo " Nexthop device deleted"
107 $IP route get fibmatch 198.51.100.2 &> /dev/null
108 log_test $? 2 "IPv4 fibmatch - no route"
109 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
110 log_test $? 2 "IPv6 fibmatch - no route"
112 cleanup
115 fib_unreg_multipath_test()
118 echo
119 echo "Multipath route test"
121 setup
123 set -e
124 $IP link add dummy1 type dummy
125 $IP link set dev dummy1 up
126 $IP address add 192.0.2.1/24 dev dummy1
127 $IP -6 address add 2001:db8:2::1/64 dev dummy1
129 $IP route add 203.0.113.0/24 \
130 nexthop via 198.51.100.2 dev dummy0 \
131 nexthop via 192.0.2.2 dev dummy1
132 $IP -6 route add 2001:db8:3::/64 \
133 nexthop via 2001:db8:1::2 dev dummy0 \
134 nexthop via 2001:db8:2::2 dev dummy1
135 set +e
137 echo " Start point"
138 $IP route get fibmatch 203.0.113.1 &> /dev/null
139 log_test $? 0 "IPv4 fibmatch"
140 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
141 log_test $? 0 "IPv6 fibmatch"
143 set -e
144 $IP link del dev dummy0
145 set +e
147 echo " One nexthop device deleted"
148 $IP route get fibmatch 203.0.113.1 &> /dev/null
149 log_test $? 2 "IPv4 - multipath route removed on delete"
151 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
152 # In IPv6 we do not flush the entire multipath route.
153 log_test $? 0 "IPv6 - multipath down to single path"
155 set -e
156 $IP link del dev dummy1
157 set +e
159 echo " Second nexthop device deleted"
160 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
161 log_test $? 2 "IPv6 - no route"
163 cleanup
166 fib_unreg_test()
168 fib_unreg_unicast_test
169 fib_unreg_multipath_test
172 fib_down_unicast_test()
174 echo
175 echo "Single path, admin down"
177 setup
179 echo " Start point"
180 $IP route get fibmatch 198.51.100.2 &> /dev/null
181 log_test $? 0 "IPv4 fibmatch"
182 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
183 log_test $? 0 "IPv6 fibmatch"
185 set -e
186 $IP link set dev dummy0 down
187 set +e
189 echo " Route deleted on down"
190 $IP route get fibmatch 198.51.100.2 &> /dev/null
191 log_test $? 2 "IPv4 fibmatch"
192 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
193 log_test $? 2 "IPv6 fibmatch"
195 cleanup
198 fib_down_multipath_test_do()
200 local down_dev=$1
201 local up_dev=$2
203 $IP route get fibmatch 203.0.113.1 \
204 oif $down_dev &> /dev/null
205 log_test $? 2 "IPv4 fibmatch on down device"
206 $IP -6 route get fibmatch 2001:db8:3::1 \
207 oif $down_dev &> /dev/null
208 log_test $? 2 "IPv6 fibmatch on down device"
210 $IP route get fibmatch 203.0.113.1 \
211 oif $up_dev &> /dev/null
212 log_test $? 0 "IPv4 fibmatch on up device"
213 $IP -6 route get fibmatch 2001:db8:3::1 \
214 oif $up_dev &> /dev/null
215 log_test $? 0 "IPv6 fibmatch on up device"
217 $IP route get fibmatch 203.0.113.1 | \
218 grep $down_dev | grep -q "dead linkdown"
219 log_test $? 0 "IPv4 flags on down device"
220 $IP -6 route get fibmatch 2001:db8:3::1 | \
221 grep $down_dev | grep -q "dead linkdown"
222 log_test $? 0 "IPv6 flags on down device"
224 $IP route get fibmatch 203.0.113.1 | \
225 grep $up_dev | grep -q "dead linkdown"
226 log_test $? 1 "IPv4 flags on up device"
227 $IP -6 route get fibmatch 2001:db8:3::1 | \
228 grep $up_dev | grep -q "dead linkdown"
229 log_test $? 1 "IPv6 flags on up device"
232 fib_down_multipath_test()
234 echo
235 echo "Admin down multipath"
237 setup
239 set -e
240 $IP link add dummy1 type dummy
241 $IP link set dev dummy1 up
243 $IP address add 192.0.2.1/24 dev dummy1
244 $IP -6 address add 2001:db8:2::1/64 dev dummy1
246 $IP route add 203.0.113.0/24 \
247 nexthop via 198.51.100.2 dev dummy0 \
248 nexthop via 192.0.2.2 dev dummy1
249 $IP -6 route add 2001:db8:3::/64 \
250 nexthop via 2001:db8:1::2 dev dummy0 \
251 nexthop via 2001:db8:2::2 dev dummy1
252 set +e
254 echo " Verify start point"
255 $IP route get fibmatch 203.0.113.1 &> /dev/null
256 log_test $? 0 "IPv4 fibmatch"
258 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
259 log_test $? 0 "IPv6 fibmatch"
261 set -e
262 $IP link set dev dummy0 down
263 set +e
265 echo " One device down, one up"
266 fib_down_multipath_test_do "dummy0" "dummy1"
268 set -e
269 $IP link set dev dummy0 up
270 $IP link set dev dummy1 down
271 set +e
273 echo " Other device down and up"
274 fib_down_multipath_test_do "dummy1" "dummy0"
276 set -e
277 $IP link set dev dummy0 down
278 set +e
280 echo " Both devices down"
281 $IP route get fibmatch 203.0.113.1 &> /dev/null
282 log_test $? 2 "IPv4 fibmatch"
283 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
284 log_test $? 2 "IPv6 fibmatch"
286 $IP link del dev dummy1
287 cleanup
290 fib_down_test()
292 fib_down_unicast_test
293 fib_down_multipath_test
296 # Local routes should not be affected when carrier changes.
297 fib_carrier_local_test()
299 echo
300 echo "Local carrier tests - single path"
302 setup
304 set -e
305 $IP link set dev dummy0 carrier on
306 set +e
308 echo " Start point"
309 $IP route get fibmatch 198.51.100.1 &> /dev/null
310 log_test $? 0 "IPv4 fibmatch"
311 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
312 log_test $? 0 "IPv6 fibmatch"
314 $IP route get fibmatch 198.51.100.1 | \
315 grep -q "linkdown"
316 log_test $? 1 "IPv4 - no linkdown flag"
317 $IP -6 route get fibmatch 2001:db8:1::1 | \
318 grep -q "linkdown"
319 log_test $? 1 "IPv6 - no linkdown flag"
321 set -e
322 $IP link set dev dummy0 carrier off
323 sleep 1
324 set +e
326 echo " Carrier off on nexthop"
327 $IP route get fibmatch 198.51.100.1 &> /dev/null
328 log_test $? 0 "IPv4 fibmatch"
329 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
330 log_test $? 0 "IPv6 fibmatch"
332 $IP route get fibmatch 198.51.100.1 | \
333 grep -q "linkdown"
334 log_test $? 1 "IPv4 - linkdown flag set"
335 $IP -6 route get fibmatch 2001:db8:1::1 | \
336 grep -q "linkdown"
337 log_test $? 1 "IPv6 - linkdown flag set"
339 set -e
340 $IP address add 192.0.2.1/24 dev dummy0
341 $IP -6 address add 2001:db8:2::1/64 dev dummy0
342 set +e
344 echo " Route to local address with carrier down"
345 $IP route get fibmatch 192.0.2.1 &> /dev/null
346 log_test $? 0 "IPv4 fibmatch"
347 $IP -6 route get fibmatch 2001:db8:2::1 &> /dev/null
348 log_test $? 0 "IPv6 fibmatch"
350 $IP route get fibmatch 192.0.2.1 | \
351 grep -q "linkdown"
352 log_test $? 1 "IPv4 linkdown flag set"
353 $IP -6 route get fibmatch 2001:db8:2::1 | \
354 grep -q "linkdown"
355 log_test $? 1 "IPv6 linkdown flag set"
357 cleanup
360 fib_carrier_unicast_test()
362 ret=0
364 echo
365 echo "Single path route carrier test"
367 setup
369 set -e
370 $IP link set dev dummy0 carrier on
371 set +e
373 echo " Start point"
374 $IP route get fibmatch 198.51.100.2 &> /dev/null
375 log_test $? 0 "IPv4 fibmatch"
376 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
377 log_test $? 0 "IPv6 fibmatch"
379 $IP route get fibmatch 198.51.100.2 | \
380 grep -q "linkdown"
381 log_test $? 1 "IPv4 no linkdown flag"
382 $IP -6 route get fibmatch 2001:db8:1::2 | \
383 grep -q "linkdown"
384 log_test $? 1 "IPv6 no linkdown flag"
386 set -e
387 $IP link set dev dummy0 carrier off
388 sleep 1
389 set +e
391 echo " Carrier down"
392 $IP route get fibmatch 198.51.100.2 &> /dev/null
393 log_test $? 0 "IPv4 fibmatch"
394 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
395 log_test $? 0 "IPv6 fibmatch"
397 $IP route get fibmatch 198.51.100.2 | \
398 grep -q "linkdown"
399 log_test $? 0 "IPv4 linkdown flag set"
400 $IP -6 route get fibmatch 2001:db8:1::2 | \
401 grep -q "linkdown"
402 log_test $? 0 "IPv6 linkdown flag set"
404 set -e
405 $IP address add 192.0.2.1/24 dev dummy0
406 $IP -6 address add 2001:db8:2::1/64 dev dummy0
407 set +e
409 echo " Second address added with carrier down"
410 $IP route get fibmatch 192.0.2.2 &> /dev/null
411 log_test $? 0 "IPv4 fibmatch"
412 $IP -6 route get fibmatch 2001:db8:2::2 &> /dev/null
413 log_test $? 0 "IPv6 fibmatch"
415 $IP route get fibmatch 192.0.2.2 | \
416 grep -q "linkdown"
417 log_test $? 0 "IPv4 linkdown flag set"
418 $IP -6 route get fibmatch 2001:db8:2::2 | \
419 grep -q "linkdown"
420 log_test $? 0 "IPv6 linkdown flag set"
422 cleanup
425 fib_carrier_test()
427 fib_carrier_local_test
428 fib_carrier_unicast_test
431 ################################################################################
432 # Tests on nexthop spec
434 # run 'ip route add' with given spec
435 add_rt()
437 local desc="$1"
438 local erc=$2
439 local vrf=$3
440 local pfx=$4
441 local gw=$5
442 local dev=$6
443 local cmd out rc
445 [ "$vrf" = "-" ] && vrf="default"
446 [ -n "$gw" ] && gw="via $gw"
447 [ -n "$dev" ] && dev="dev $dev"
449 cmd="$IP route add vrf $vrf $pfx $gw $dev"
450 if [ "$VERBOSE" = "1" ]; then
451 printf "\n COMMAND: $cmd\n"
454 out=$(eval $cmd 2>&1)
455 rc=$?
456 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
457 echo " $out"
459 log_test $rc $erc "$desc"
462 fib4_nexthop()
464 echo
465 echo "IPv4 nexthop tests"
467 echo "<<< write me >>>"
470 fib6_nexthop()
472 local lldummy=$(get_linklocal dummy0)
473 local llv1=$(get_linklocal dummy0)
475 if [ -z "$lldummy" ]; then
476 echo "Failed to get linklocal address for dummy0"
477 return 1
479 if [ -z "$llv1" ]; then
480 echo "Failed to get linklocal address for veth1"
481 return 1
484 echo
485 echo "IPv6 nexthop tests"
487 add_rt "Directly connected nexthop, unicast address" 0 \
488 - 2001:db8:101::/64 2001:db8:1::2
489 add_rt "Directly connected nexthop, unicast address with device" 0 \
490 - 2001:db8:102::/64 2001:db8:1::2 "dummy0"
491 add_rt "Gateway is linklocal address" 0 \
492 - 2001:db8:103::1/64 $llv1 "veth0"
494 # fails because LL address requires a device
495 add_rt "Gateway is linklocal address, no device" 2 \
496 - 2001:db8:104::1/64 $llv1
498 # local address can not be a gateway
499 add_rt "Gateway can not be local unicast address" 2 \
500 - 2001:db8:105::/64 2001:db8:1::1
501 add_rt "Gateway can not be local unicast address, with device" 2 \
502 - 2001:db8:106::/64 2001:db8:1::1 "dummy0"
503 add_rt "Gateway can not be a local linklocal address" 2 \
504 - 2001:db8:107::1/64 $lldummy "dummy0"
506 # VRF tests
507 add_rt "Gateway can be local address in a VRF" 0 \
508 - 2001:db8:108::/64 2001:db8:51::2
509 add_rt "Gateway can be local address in a VRF, with device" 0 \
510 - 2001:db8:109::/64 2001:db8:51::2 "veth0"
511 add_rt "Gateway can be local linklocal address in a VRF" 0 \
512 - 2001:db8:110::1/64 $llv1 "veth0"
514 add_rt "Redirect to VRF lookup" 0 \
515 - 2001:db8:111::/64 "" "red"
517 add_rt "VRF route, gateway can be local address in default VRF" 0 \
518 red 2001:db8:112::/64 2001:db8:51::1
520 # local address in same VRF fails
521 add_rt "VRF route, gateway can not be a local address" 2 \
522 red 2001:db8:113::1/64 2001:db8:2::1
523 add_rt "VRF route, gateway can not be a local addr with device" 2 \
524 red 2001:db8:114::1/64 2001:db8:2::1 "dummy1"
527 # Default VRF:
528 # dummy0 - 198.51.100.1/24 2001:db8:1::1/64
529 # veth0 - 192.0.2.1/24 2001:db8:51::1/64
531 # VRF red:
532 # dummy1 - 192.168.2.1/24 2001:db8:2::1/64
533 # veth1 - 192.0.2.2/24 2001:db8:51::2/64
535 # [ dummy0 veth0 ]--[ veth1 dummy1 ]
537 fib_nexthop_test()
539 setup
541 set -e
543 $IP -4 rule add pref 32765 table local
544 $IP -4 rule del pref 0
545 $IP -6 rule add pref 32765 table local
546 $IP -6 rule del pref 0
548 $IP link add red type vrf table 1
549 $IP link set red up
550 $IP -4 route add vrf red unreachable default metric 4278198272
551 $IP -6 route add vrf red unreachable default metric 4278198272
553 $IP link add veth0 type veth peer name veth1
554 $IP link set dev veth0 up
555 $IP address add 192.0.2.1/24 dev veth0
556 $IP -6 address add 2001:db8:51::1/64 dev veth0
558 $IP link set dev veth1 vrf red up
559 $IP address add 192.0.2.2/24 dev veth1
560 $IP -6 address add 2001:db8:51::2/64 dev veth1
562 $IP link add dummy1 type dummy
563 $IP link set dev dummy1 vrf red up
564 $IP address add 192.168.2.1/24 dev dummy1
565 $IP -6 address add 2001:db8:2::1/64 dev dummy1
566 set +e
568 sleep 1
569 fib4_nexthop
570 fib6_nexthop
573 $IP link del dev dummy1
574 $IP link del veth0
575 $IP link del red
576 ) 2>/dev/null
577 cleanup
580 ################################################################################
581 # Tests on route add and replace
583 run_cmd()
585 local cmd="$1"
586 local out
587 local stderr="2>/dev/null"
589 if [ "$VERBOSE" = "1" ]; then
590 printf " COMMAND: $cmd\n"
591 stderr=
594 out=$(eval $cmd $stderr)
595 rc=$?
596 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
597 echo " $out"
600 [ "$VERBOSE" = "1" ] && echo
602 return $rc
605 check_expected()
607 local out="$1"
608 local expected="$2"
609 local rc=0
611 [ "${out}" = "${expected}" ] && return 0
613 if [ -z "${out}" ]; then
614 if [ "$VERBOSE" = "1" ]; then
615 printf "\nNo route entry found\n"
616 printf "Expected:\n"
617 printf " ${expected}\n"
619 return 1
622 # tricky way to convert output to 1-line without ip's
623 # messy '\'; this drops all extra white space
624 out=$(echo ${out})
625 if [ "${out}" != "${expected}" ]; then
626 rc=1
627 if [ "${VERBOSE}" = "1" ]; then
628 printf " Unexpected route entry. Have:\n"
629 printf " ${out}\n"
630 printf " Expected:\n"
631 printf " ${expected}\n\n"
635 return $rc
638 # add route for a prefix, flushing any existing routes first
639 # expected to be the first step of a test
640 add_route6()
642 local pfx="$1"
643 local nh="$2"
644 local out
646 if [ "$VERBOSE" = "1" ]; then
647 echo
648 echo " ##################################################"
649 echo
652 run_cmd "$IP -6 ro flush ${pfx}"
653 [ $? -ne 0 ] && exit 1
655 out=$($IP -6 ro ls match ${pfx})
656 if [ -n "$out" ]; then
657 echo "Failed to flush routes for prefix used for tests."
658 exit 1
661 run_cmd "$IP -6 ro add ${pfx} ${nh}"
662 if [ $? -ne 0 ]; then
663 echo "Failed to add initial route for test."
664 exit 1
668 # add initial route - used in replace route tests
669 add_initial_route6()
671 add_route6 "2001:db8:104::/64" "$1"
674 check_route6()
676 local pfx="2001:db8:104::/64"
677 local expected="$1"
678 local out
679 local rc=0
681 out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//')
682 check_expected "${out}" "${expected}"
685 route_cleanup()
687 $IP li del red 2>/dev/null
688 $IP li del dummy1 2>/dev/null
689 $IP li del veth1 2>/dev/null
690 $IP li del veth3 2>/dev/null
692 cleanup &> /dev/null
695 route_setup()
697 route_cleanup
698 setup
700 [ "${VERBOSE}" = "1" ] && set -x
701 set -e
703 $IP li add red up type vrf table 101
704 $IP li add veth1 type veth peer name veth2
705 $IP li add veth3 type veth peer name veth4
707 $IP li set veth1 up
708 $IP li set veth3 up
709 $IP li set veth2 vrf red up
710 $IP li set veth4 vrf red up
711 $IP li add dummy1 type dummy
712 $IP li set dummy1 vrf red up
714 $IP -6 addr add 2001:db8:101::1/64 dev veth1
715 $IP -6 addr add 2001:db8:101::2/64 dev veth2
716 $IP -6 addr add 2001:db8:103::1/64 dev veth3
717 $IP -6 addr add 2001:db8:103::2/64 dev veth4
718 $IP -6 addr add 2001:db8:104::1/64 dev dummy1
720 $IP addr add 172.16.101.1/24 dev veth1
721 $IP addr add 172.16.101.2/24 dev veth2
722 $IP addr add 172.16.103.1/24 dev veth3
723 $IP addr add 172.16.103.2/24 dev veth4
724 $IP addr add 172.16.104.1/24 dev dummy1
726 set +e
729 # assumption is that basic add of a single path route works
730 # otherwise just adding an address on an interface is broken
731 ipv6_rt_add()
733 local rc
735 echo
736 echo "IPv6 route add / append tests"
738 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
739 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
740 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2"
741 log_test $? 2 "Attempt to add duplicate route - gw"
743 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
744 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
745 run_cmd "$IP -6 ro add 2001:db8:104::/64 dev veth3"
746 log_test $? 2 "Attempt to add duplicate route - dev only"
748 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
749 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
750 run_cmd "$IP -6 ro add unreachable 2001:db8:104::/64"
751 log_test $? 2 "Attempt to add duplicate route - reject route"
753 # route append with same prefix adds a new route
754 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
755 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
756 run_cmd "$IP -6 ro append 2001:db8:104::/64 via 2001:db8:103::2"
757 check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
758 log_test $? 0 "Append nexthop to existing route - gw"
760 # insert mpath directly
761 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
762 check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
763 log_test $? 0 "Add multipath route"
765 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
766 run_cmd "$IP -6 ro add 2001:db8:104::/64 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
767 log_test $? 2 "Attempt to add duplicate multipath route"
769 # insert of a second route without append but different metric
770 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
771 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2 metric 512"
772 rc=$?
773 if [ $rc -eq 0 ]; then
774 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::3 metric 256"
775 rc=$?
777 log_test $rc 0 "Route add with different metrics"
779 run_cmd "$IP -6 ro del 2001:db8:104::/64 metric 512"
780 rc=$?
781 if [ $rc -eq 0 ]; then
782 check_route6 "2001:db8:104::/64 via 2001:db8:103::3 dev veth3 metric 256 2001:db8:104::/64 via 2001:db8:101::2 dev veth1 metric 1024"
783 rc=$?
785 log_test $rc 0 "Route delete with metric"
788 ipv6_rt_replace_single()
790 # single path with single path
792 add_initial_route6 "via 2001:db8:101::2"
793 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:103::2"
794 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
795 log_test $? 0 "Single path with single path"
797 # single path with multipath
799 add_initial_route6 "nexthop via 2001:db8:101::2"
800 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::2"
801 check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::3 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
802 log_test $? 0 "Single path with multipath"
804 # single path with single path using MULTIPATH attribute
806 add_initial_route6 "via 2001:db8:101::2"
807 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:103::2"
808 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
809 log_test $? 0 "Single path with single path via multipath attribute"
811 # route replace fails - invalid nexthop
812 add_initial_route6 "via 2001:db8:101::2"
813 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:104::2"
814 if [ $? -eq 0 ]; then
815 # previous command is expected to fail so if it returns 0
816 # that means the test failed.
817 log_test 0 1 "Invalid nexthop"
818 else
819 check_route6 "2001:db8:104::/64 via 2001:db8:101::2 dev veth1 metric 1024"
820 log_test $? 0 "Invalid nexthop"
823 # replace non-existent route
824 # - note use of change versus replace since ip adds NLM_F_CREATE
825 # for replace
826 add_initial_route6 "via 2001:db8:101::2"
827 run_cmd "$IP -6 ro change 2001:db8:105::/64 via 2001:db8:101::2"
828 log_test $? 2 "Single path - replace of non-existent route"
831 ipv6_rt_replace_mpath()
833 # multipath with multipath
834 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
835 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
836 check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::3 dev veth1 weight 1 nexthop via 2001:db8:103::3 dev veth3 weight 1"
837 log_test $? 0 "Multipath with multipath"
839 # multipath with single
840 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
841 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:101::3"
842 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
843 log_test $? 0 "Multipath with single path"
845 # multipath with single
846 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
847 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3"
848 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
849 log_test $? 0 "Multipath with single path via multipath attribute"
851 # multipath with dev-only
852 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
853 run_cmd "$IP -6 ro replace 2001:db8:104::/64 dev veth1"
854 check_route6 "2001:db8:104::/64 dev veth1 metric 1024"
855 log_test $? 0 "Multipath with dev-only"
857 # route replace fails - invalid nexthop 1
858 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
859 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:111::3 nexthop via 2001:db8:103::3"
860 check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
861 log_test $? 0 "Multipath - invalid first nexthop"
863 # route replace fails - invalid nexthop 2
864 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
865 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:113::3"
866 check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
867 log_test $? 0 "Multipath - invalid second nexthop"
869 # multipath non-existent route
870 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
871 run_cmd "$IP -6 ro change 2001:db8:105::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
872 log_test $? 2 "Multipath - replace of non-existent route"
875 ipv6_rt_replace()
877 echo
878 echo "IPv6 route replace tests"
880 ipv6_rt_replace_single
881 ipv6_rt_replace_mpath
884 ipv6_route_test()
886 route_setup
888 ipv6_rt_add
889 ipv6_rt_replace
891 route_cleanup
894 ip_addr_metric_check()
896 ip addr help 2>&1 | grep -q metric
897 if [ $? -ne 0 ]; then
898 echo "iproute2 command does not support metric for addresses. Skipping test"
899 return 1
902 return 0
905 ipv6_addr_metric_test()
907 local rc
909 echo
910 echo "IPv6 prefix route tests"
912 ip_addr_metric_check || return 1
914 setup
916 set -e
917 $IP li add dummy1 type dummy
918 $IP li add dummy2 type dummy
919 $IP li set dummy1 up
920 $IP li set dummy2 up
922 # default entry is metric 256
923 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64"
924 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64"
925 set +e
927 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 256 2001:db8:104::/64 dev dummy2 proto kernel metric 256"
928 log_test $? 0 "Default metric"
930 set -e
931 run_cmd "$IP -6 addr flush dev dummy1"
932 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64 metric 257"
933 set +e
935 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 256 2001:db8:104::/64 dev dummy1 proto kernel metric 257"
936 log_test $? 0 "User specified metric on first device"
938 set -e
939 run_cmd "$IP -6 addr flush dev dummy2"
940 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64 metric 258"
941 set +e
943 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 257 2001:db8:104::/64 dev dummy2 proto kernel metric 258"
944 log_test $? 0 "User specified metric on second device"
946 run_cmd "$IP -6 addr del dev dummy1 2001:db8:104::1/64 metric 257"
947 rc=$?
948 if [ $rc -eq 0 ]; then
949 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 258"
950 rc=$?
952 log_test $rc 0 "Delete of address on first device"
954 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::2/64 metric 259"
955 rc=$?
956 if [ $rc -eq 0 ]; then
957 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
958 rc=$?
960 log_test $rc 0 "Modify metric of address"
962 # verify prefix route removed on down
963 run_cmd "ip netns exec testns sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1"
964 run_cmd "$IP li set dev dummy2 down"
965 rc=$?
966 if [ $rc -eq 0 ]; then
967 out=$($IP -6 ro ls match 2001:db8:104::/64)
968 check_expected "${out}" ""
969 rc=$?
971 log_test $rc 0 "Prefix route removed on link down"
973 # verify prefix route re-inserted with assigned metric
974 run_cmd "$IP li set dev dummy2 up"
975 rc=$?
976 if [ $rc -eq 0 ]; then
977 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
978 rc=$?
980 log_test $rc 0 "Prefix route with metric on link up"
982 # verify peer metric added correctly
983 set -e
984 run_cmd "$IP -6 addr flush dev dummy2"
985 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::1 peer 2001:db8:104::2 metric 260"
986 set +e
988 check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 260"
989 log_test $? 0 "Set metric with peer route on local side"
990 log_test $? 0 "User specified metric on local address"
991 check_route6 "2001:db8:104::2 dev dummy2 proto kernel metric 260"
992 log_test $? 0 "Set metric with peer route on peer side"
994 set -e
995 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::1 peer 2001:db8:104::3 metric 261"
996 set +e
998 check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 261"
999 log_test $? 0 "Modify metric and peer address on local side"
1000 check_route6 "2001:db8:104::3 dev dummy2 proto kernel metric 261"
1001 log_test $? 0 "Modify metric and peer address on peer side"
1003 $IP li del dummy1
1004 $IP li del dummy2
1005 cleanup
1008 # add route for a prefix, flushing any existing routes first
1009 # expected to be the first step of a test
1010 add_route()
1012 local pfx="$1"
1013 local nh="$2"
1014 local out
1016 if [ "$VERBOSE" = "1" ]; then
1017 echo
1018 echo " ##################################################"
1019 echo
1022 run_cmd "$IP ro flush ${pfx}"
1023 [ $? -ne 0 ] && exit 1
1025 out=$($IP ro ls match ${pfx})
1026 if [ -n "$out" ]; then
1027 echo "Failed to flush routes for prefix used for tests."
1028 exit 1
1031 run_cmd "$IP ro add ${pfx} ${nh}"
1032 if [ $? -ne 0 ]; then
1033 echo "Failed to add initial route for test."
1034 exit 1
1038 # add initial route - used in replace route tests
1039 add_initial_route()
1041 add_route "172.16.104.0/24" "$1"
1044 check_route()
1046 local pfx="172.16.104.0/24"
1047 local expected="$1"
1048 local out
1050 out=$($IP ro ls match ${pfx})
1051 check_expected "${out}" "${expected}"
1054 # assumption is that basic add of a single path route works
1055 # otherwise just adding an address on an interface is broken
1056 ipv4_rt_add()
1058 local rc
1060 echo
1061 echo "IPv4 route add / append tests"
1063 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1064 add_route "172.16.104.0/24" "via 172.16.101.2"
1065 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2"
1066 log_test $? 2 "Attempt to add duplicate route - gw"
1068 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1069 add_route "172.16.104.0/24" "via 172.16.101.2"
1070 run_cmd "$IP ro add 172.16.104.0/24 dev veth3"
1071 log_test $? 2 "Attempt to add duplicate route - dev only"
1073 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1074 add_route "172.16.104.0/24" "via 172.16.101.2"
1075 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1076 log_test $? 2 "Attempt to add duplicate route - reject route"
1078 # iproute2 prepend only sets NLM_F_CREATE
1079 # - adds a new route; does NOT convert existing route to ECMP
1080 add_route "172.16.104.0/24" "via 172.16.101.2"
1081 run_cmd "$IP ro prepend 172.16.104.0/24 via 172.16.103.2"
1082 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3 172.16.104.0/24 via 172.16.101.2 dev veth1"
1083 log_test $? 0 "Add new nexthop for existing prefix"
1085 # route append with same prefix adds a new route
1086 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
1087 add_route "172.16.104.0/24" "via 172.16.101.2"
1088 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
1089 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 via 172.16.103.2 dev veth3"
1090 log_test $? 0 "Append nexthop to existing route - gw"
1092 add_route "172.16.104.0/24" "via 172.16.101.2"
1093 run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
1094 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 dev veth3 scope link"
1095 log_test $? 0 "Append nexthop to existing route - dev only"
1097 add_route "172.16.104.0/24" "via 172.16.101.2"
1098 run_cmd "$IP ro append unreachable 172.16.104.0/24"
1099 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 unreachable 172.16.104.0/24"
1100 log_test $? 0 "Append nexthop to existing route - reject route"
1102 run_cmd "$IP ro flush 172.16.104.0/24"
1103 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1104 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
1105 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 via 172.16.103.2 dev veth3"
1106 log_test $? 0 "Append nexthop to existing reject route - gw"
1108 run_cmd "$IP ro flush 172.16.104.0/24"
1109 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1110 run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
1111 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 dev veth3 scope link"
1112 log_test $? 0 "Append nexthop to existing reject route - dev only"
1114 # insert mpath directly
1115 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1116 check_route "172.16.104.0/24 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
1117 log_test $? 0 "add multipath route"
1119 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1120 run_cmd "$IP ro add 172.16.104.0/24 nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1121 log_test $? 2 "Attempt to add duplicate multipath route"
1123 # insert of a second route without append but different metric
1124 add_route "172.16.104.0/24" "via 172.16.101.2"
1125 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2 metric 512"
1126 rc=$?
1127 if [ $rc -eq 0 ]; then
1128 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.3 metric 256"
1129 rc=$?
1131 log_test $rc 0 "Route add with different metrics"
1133 run_cmd "$IP ro del 172.16.104.0/24 metric 512"
1134 rc=$?
1135 if [ $rc -eq 0 ]; then
1136 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 via 172.16.103.3 dev veth3 metric 256"
1137 rc=$?
1139 log_test $rc 0 "Route delete with metric"
1142 ipv4_rt_replace_single()
1144 # single path with single path
1146 add_initial_route "via 172.16.101.2"
1147 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.103.2"
1148 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
1149 log_test $? 0 "Single path with single path"
1151 # single path with multipath
1153 add_initial_route "nexthop via 172.16.101.2"
1154 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.2"
1155 check_route "172.16.104.0/24 nexthop via 172.16.101.3 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
1156 log_test $? 0 "Single path with multipath"
1158 # single path with reject
1160 add_initial_route "nexthop via 172.16.101.2"
1161 run_cmd "$IP ro replace unreachable 172.16.104.0/24"
1162 check_route "unreachable 172.16.104.0/24"
1163 log_test $? 0 "Single path with reject route"
1165 # single path with single path using MULTIPATH attribute
1167 add_initial_route "via 172.16.101.2"
1168 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.103.2"
1169 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
1170 log_test $? 0 "Single path with single path via multipath attribute"
1172 # route replace fails - invalid nexthop
1173 add_initial_route "via 172.16.101.2"
1174 run_cmd "$IP ro replace 172.16.104.0/24 via 2001:db8:104::2"
1175 if [ $? -eq 0 ]; then
1176 # previous command is expected to fail so if it returns 0
1177 # that means the test failed.
1178 log_test 0 1 "Invalid nexthop"
1179 else
1180 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1"
1181 log_test $? 0 "Invalid nexthop"
1184 # replace non-existent route
1185 # - note use of change versus replace since ip adds NLM_F_CREATE
1186 # for replace
1187 add_initial_route "via 172.16.101.2"
1188 run_cmd "$IP ro change 172.16.105.0/24 via 172.16.101.2"
1189 log_test $? 2 "Single path - replace of non-existent route"
1192 ipv4_rt_replace_mpath()
1194 # multipath with multipath
1195 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1196 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
1197 check_route "172.16.104.0/24 nexthop via 172.16.101.3 dev veth1 weight 1 nexthop via 172.16.103.3 dev veth3 weight 1"
1198 log_test $? 0 "Multipath with multipath"
1200 # multipath with single
1201 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1202 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.101.3"
1203 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
1204 log_test $? 0 "Multipath with single path"
1206 # multipath with single
1207 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1208 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3"
1209 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
1210 log_test $? 0 "Multipath with single path via multipath attribute"
1212 # multipath with reject
1213 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1214 run_cmd "$IP ro replace unreachable 172.16.104.0/24"
1215 check_route "unreachable 172.16.104.0/24"
1216 log_test $? 0 "Multipath with reject route"
1218 # route replace fails - invalid nexthop 1
1219 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1220 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.111.3 nexthop via 172.16.103.3"
1221 check_route "172.16.104.0/24 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
1222 log_test $? 0 "Multipath - invalid first nexthop"
1224 # route replace fails - invalid nexthop 2
1225 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1226 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.113.3"
1227 check_route "172.16.104.0/24 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
1228 log_test $? 0 "Multipath - invalid second nexthop"
1230 # multipath non-existent route
1231 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1232 run_cmd "$IP ro change 172.16.105.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
1233 log_test $? 2 "Multipath - replace of non-existent route"
1236 ipv4_rt_replace()
1238 echo
1239 echo "IPv4 route replace tests"
1241 ipv4_rt_replace_single
1242 ipv4_rt_replace_mpath
1245 ipv4_route_test()
1247 route_setup
1249 ipv4_rt_add
1250 ipv4_rt_replace
1252 route_cleanup
1255 ipv4_addr_metric_test()
1257 local rc
1259 echo
1260 echo "IPv4 prefix route tests"
1262 ip_addr_metric_check || return 1
1264 setup
1266 set -e
1267 $IP li add dummy1 type dummy
1268 $IP li add dummy2 type dummy
1269 $IP li set dummy1 up
1270 $IP li set dummy2 up
1272 # default entry is metric 256
1273 run_cmd "$IP addr add dev dummy1 172.16.104.1/24"
1274 run_cmd "$IP addr add dev dummy2 172.16.104.2/24"
1275 set +e
1277 check_route "172.16.104.0/24 dev dummy1 proto kernel scope link src 172.16.104.1 172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2"
1278 log_test $? 0 "Default metric"
1280 set -e
1281 run_cmd "$IP addr flush dev dummy1"
1282 run_cmd "$IP addr add dev dummy1 172.16.104.1/24 metric 257"
1283 set +e
1285 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 172.16.104.0/24 dev dummy1 proto kernel scope link src 172.16.104.1 metric 257"
1286 log_test $? 0 "User specified metric on first device"
1288 set -e
1289 run_cmd "$IP addr flush dev dummy2"
1290 run_cmd "$IP addr add dev dummy2 172.16.104.2/24 metric 258"
1291 set +e
1293 check_route "172.16.104.0/24 dev dummy1 proto kernel scope link src 172.16.104.1 metric 257 172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 258"
1294 log_test $? 0 "User specified metric on second device"
1296 run_cmd "$IP addr del dev dummy1 172.16.104.1/24 metric 257"
1297 rc=$?
1298 if [ $rc -eq 0 ]; then
1299 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 258"
1300 rc=$?
1302 log_test $rc 0 "Delete of address on first device"
1304 run_cmd "$IP addr change dev dummy2 172.16.104.2/24 metric 259"
1305 rc=$?
1306 if [ $rc -eq 0 ]; then
1307 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
1308 rc=$?
1310 log_test $rc 0 "Modify metric of address"
1312 # verify prefix route removed on down
1313 run_cmd "$IP li set dev dummy2 down"
1314 rc=$?
1315 if [ $rc -eq 0 ]; then
1316 out=$($IP ro ls match 172.16.104.0/24)
1317 check_expected "${out}" ""
1318 rc=$?
1320 log_test $rc 0 "Prefix route removed on link down"
1322 # verify prefix route re-inserted with assigned metric
1323 run_cmd "$IP li set dev dummy2 up"
1324 rc=$?
1325 if [ $rc -eq 0 ]; then
1326 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
1327 rc=$?
1329 log_test $rc 0 "Prefix route with metric on link up"
1331 # explicitly check for metric changes on edge scenarios
1332 run_cmd "$IP addr flush dev dummy2"
1333 run_cmd "$IP addr add dev dummy2 172.16.104.0/24 metric 259"
1334 run_cmd "$IP addr change dev dummy2 172.16.104.0/24 metric 260"
1335 rc=$?
1336 if [ $rc -eq 0 ]; then
1337 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.0 metric 260"
1338 rc=$?
1340 log_test $rc 0 "Modify metric of .0/24 address"
1342 run_cmd "$IP addr flush dev dummy2"
1343 run_cmd "$IP addr add dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 260"
1344 rc=$?
1345 if [ $rc -eq 0 ]; then
1346 check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 260"
1347 rc=$?
1349 log_test $rc 0 "Set metric of address with peer route"
1351 run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.3 metric 261"
1352 rc=$?
1353 if [ $rc -eq 0 ]; then
1354 check_route "172.16.104.3 dev dummy2 proto kernel scope link src 172.16.104.1 metric 261"
1355 rc=$?
1357 log_test $rc 0 "Modify metric and peer address for peer route"
1359 $IP li del dummy1
1360 $IP li del dummy2
1361 cleanup
1364 ################################################################################
1365 # usage
1367 usage()
1369 cat <<EOF
1370 usage: ${0##*/} OPTS
1372 -t <test> Test(s) to run (default: all)
1373 (options: $TESTS)
1374 -p Pause on fail
1375 -P Pause after each test before cleanup
1376 -v verbose mode (show commands and output)
1380 ################################################################################
1381 # main
1383 while getopts :t:pPhv o
1385 case $o in
1386 t) TESTS=$OPTARG;;
1387 p) PAUSE_ON_FAIL=yes;;
1388 P) PAUSE=yes;;
1389 v) VERBOSE=$(($VERBOSE + 1));;
1390 h) usage; exit 0;;
1391 *) usage; exit 1;;
1392 esac
1393 done
1395 PEER_CMD="ip netns exec ${PEER_NS}"
1397 # make sure we don't pause twice
1398 [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
1400 if [ "$(id -u)" -ne 0 ];then
1401 echo "SKIP: Need root privileges"
1402 exit $ksft_skip;
1405 if [ ! -x "$(command -v ip)" ]; then
1406 echo "SKIP: Could not run test without ip tool"
1407 exit $ksft_skip
1410 ip route help 2>&1 | grep -q fibmatch
1411 if [ $? -ne 0 ]; then
1412 echo "SKIP: iproute2 too old, missing fibmatch"
1413 exit $ksft_skip
1416 # start clean
1417 cleanup &> /dev/null
1419 for t in $TESTS
1421 case $t in
1422 fib_unreg_test|unregister) fib_unreg_test;;
1423 fib_down_test|down) fib_down_test;;
1424 fib_carrier_test|carrier) fib_carrier_test;;
1425 fib_nexthop_test|nexthop) fib_nexthop_test;;
1426 ipv6_route_test|ipv6_rt) ipv6_route_test;;
1427 ipv4_route_test|ipv4_rt) ipv4_route_test;;
1428 ipv6_addr_metric) ipv6_addr_metric_test;;
1429 ipv4_addr_metric) ipv4_addr_metric_test;;
1431 help) echo "Test names: $TESTS"; exit 0;;
1432 esac
1433 done
1435 if [ "$TESTS" != "none" ]; then
1436 printf "\nTests passed: %3d\n" ${nsuccess}
1437 printf "Tests failed: %3d\n" ${nfail}
1440 exit $ret