2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking IPv4 and IPv6 FIB behavior in response to
8 # Kselftest framework requirement - SKIP code is 4.
11 # all tests in this script. Can be overridden with -t option
12 TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr"
18 NS_EXEC="ip netns exec ns1"
20 which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
28 if [ ${rc} -eq ${expected} ]; then
29 printf " TEST: %-60s [ OK ]\n" "${msg}"
30 nsuccess=$((nsuccess+1))
34 printf " TEST: %-60s [FAIL]\n" "${msg}"
35 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
37 echo "hit enter to continue, 'q' to quit"
39 [ "$a" = "q" ] && exit 1
43 if [ "${PAUSE}" = "yes" ]; then
45 echo "hit enter to continue, 'q' to quit"
47 [ "$a" = "q" ] && exit 1
56 $IP link set dev lo up
57 ip netns exec ns1 sysctl -qw net.ipv4.ip_forward=1
58 ip netns exec ns1 sysctl -qw net.ipv6.conf.all.forwarding=1
60 $IP link add dummy0 type dummy
61 $IP link set dev dummy0 up
62 $IP address add 198.51.100.1/24 dev dummy0
63 $IP -6 address add 2001:db8:1::1/64 dev dummy0
70 $IP link del dev dummy0 &> /dev/null
72 ip netns del ns2 &> /dev/null
80 addr=$($IP -6 -br addr show dev ${dev} | \
82 for (i = 3; i <= NF; ++i) {
90 [ -z "$addr" ] && return 1
97 fib_unreg_unicast_test()
100 echo "Single path route test"
105 $IP route get fibmatch 198.51.100.2 &> /dev/null
106 log_test $? 0 "IPv4 fibmatch"
107 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
108 log_test $? 0 "IPv6 fibmatch"
111 $IP link del dev dummy0
114 echo " Nexthop device deleted"
115 $IP route get fibmatch 198.51.100.2 &> /dev/null
116 log_test $? 2 "IPv4 fibmatch - no route"
117 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
118 log_test $? 2 "IPv6 fibmatch - no route"
123 fib_unreg_multipath_test()
127 echo "Multipath route test"
132 $IP link add dummy1 type dummy
133 $IP link set dev dummy1 up
134 $IP address add 192.0.2.1/24 dev dummy1
135 $IP -6 address add 2001:db8:2::1/64 dev dummy1
137 $IP route add 203.0.113.0/24 \
138 nexthop via 198.51.100.2 dev dummy0 \
139 nexthop via 192.0.2.2 dev dummy1
140 $IP -6 route add 2001:db8:3::/64 \
141 nexthop via 2001:db8:1::2 dev dummy0 \
142 nexthop via 2001:db8:2::2 dev dummy1
146 $IP route get fibmatch 203.0.113.1 &> /dev/null
147 log_test $? 0 "IPv4 fibmatch"
148 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
149 log_test $? 0 "IPv6 fibmatch"
152 $IP link del dev dummy0
155 echo " One nexthop device deleted"
156 $IP route get fibmatch 203.0.113.1 &> /dev/null
157 log_test $? 2 "IPv4 - multipath route removed on delete"
159 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
160 # In IPv6 we do not flush the entire multipath route.
161 log_test $? 0 "IPv6 - multipath down to single path"
164 $IP link del dev dummy1
167 echo " Second nexthop device deleted"
168 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
169 log_test $? 2 "IPv6 - no route"
176 fib_unreg_unicast_test
177 fib_unreg_multipath_test
180 fib_down_unicast_test()
183 echo "Single path, admin down"
188 $IP route get fibmatch 198.51.100.2 &> /dev/null
189 log_test $? 0 "IPv4 fibmatch"
190 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
191 log_test $? 0 "IPv6 fibmatch"
194 $IP link set dev dummy0 down
197 echo " Route deleted on down"
198 $IP route get fibmatch 198.51.100.2 &> /dev/null
199 log_test $? 2 "IPv4 fibmatch"
200 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
201 log_test $? 2 "IPv6 fibmatch"
206 fib_down_multipath_test_do()
211 $IP route get fibmatch 203.0.113.1 \
212 oif $down_dev &> /dev/null
213 log_test $? 2 "IPv4 fibmatch on down device"
214 $IP -6 route get fibmatch 2001:db8:3::1 \
215 oif $down_dev &> /dev/null
216 log_test $? 2 "IPv6 fibmatch on down device"
218 $IP route get fibmatch 203.0.113.1 \
219 oif $up_dev &> /dev/null
220 log_test $? 0 "IPv4 fibmatch on up device"
221 $IP -6 route get fibmatch 2001:db8:3::1 \
222 oif $up_dev &> /dev/null
223 log_test $? 0 "IPv6 fibmatch on up device"
225 $IP route get fibmatch 203.0.113.1 | \
226 grep $down_dev | grep -q "dead linkdown"
227 log_test $? 0 "IPv4 flags on down device"
228 $IP -6 route get fibmatch 2001:db8:3::1 | \
229 grep $down_dev | grep -q "dead linkdown"
230 log_test $? 0 "IPv6 flags on down device"
232 $IP route get fibmatch 203.0.113.1 | \
233 grep $up_dev | grep -q "dead linkdown"
234 log_test $? 1 "IPv4 flags on up device"
235 $IP -6 route get fibmatch 2001:db8:3::1 | \
236 grep $up_dev | grep -q "dead linkdown"
237 log_test $? 1 "IPv6 flags on up device"
240 fib_down_multipath_test()
243 echo "Admin down multipath"
248 $IP link add dummy1 type dummy
249 $IP link set dev dummy1 up
251 $IP address add 192.0.2.1/24 dev dummy1
252 $IP -6 address add 2001:db8:2::1/64 dev dummy1
254 $IP route add 203.0.113.0/24 \
255 nexthop via 198.51.100.2 dev dummy0 \
256 nexthop via 192.0.2.2 dev dummy1
257 $IP -6 route add 2001:db8:3::/64 \
258 nexthop via 2001:db8:1::2 dev dummy0 \
259 nexthop via 2001:db8:2::2 dev dummy1
262 echo " Verify start point"
263 $IP route get fibmatch 203.0.113.1 &> /dev/null
264 log_test $? 0 "IPv4 fibmatch"
266 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
267 log_test $? 0 "IPv6 fibmatch"
270 $IP link set dev dummy0 down
273 echo " One device down, one up"
274 fib_down_multipath_test_do "dummy0" "dummy1"
277 $IP link set dev dummy0 up
278 $IP link set dev dummy1 down
281 echo " Other device down and up"
282 fib_down_multipath_test_do "dummy1" "dummy0"
285 $IP link set dev dummy0 down
288 echo " Both devices down"
289 $IP route get fibmatch 203.0.113.1 &> /dev/null
290 log_test $? 2 "IPv4 fibmatch"
291 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
292 log_test $? 2 "IPv6 fibmatch"
294 $IP link del dev dummy1
300 fib_down_unicast_test
301 fib_down_multipath_test
304 # Local routes should not be affected when carrier changes.
305 fib_carrier_local_test()
308 echo "Local carrier tests - single path"
313 $IP link set dev dummy0 carrier on
317 $IP route get fibmatch 198.51.100.1 &> /dev/null
318 log_test $? 0 "IPv4 fibmatch"
319 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
320 log_test $? 0 "IPv6 fibmatch"
322 $IP route get fibmatch 198.51.100.1 | \
324 log_test $? 1 "IPv4 - no linkdown flag"
325 $IP -6 route get fibmatch 2001:db8:1::1 | \
327 log_test $? 1 "IPv6 - no linkdown flag"
330 $IP link set dev dummy0 carrier off
334 echo " Carrier off on nexthop"
335 $IP route get fibmatch 198.51.100.1 &> /dev/null
336 log_test $? 0 "IPv4 fibmatch"
337 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
338 log_test $? 0 "IPv6 fibmatch"
340 $IP route get fibmatch 198.51.100.1 | \
342 log_test $? 1 "IPv4 - linkdown flag set"
343 $IP -6 route get fibmatch 2001:db8:1::1 | \
345 log_test $? 1 "IPv6 - linkdown flag set"
348 $IP address add 192.0.2.1/24 dev dummy0
349 $IP -6 address add 2001:db8:2::1/64 dev dummy0
352 echo " Route to local address with carrier down"
353 $IP route get fibmatch 192.0.2.1 &> /dev/null
354 log_test $? 0 "IPv4 fibmatch"
355 $IP -6 route get fibmatch 2001:db8:2::1 &> /dev/null
356 log_test $? 0 "IPv6 fibmatch"
358 $IP route get fibmatch 192.0.2.1 | \
360 log_test $? 1 "IPv4 linkdown flag set"
361 $IP -6 route get fibmatch 2001:db8:2::1 | \
363 log_test $? 1 "IPv6 linkdown flag set"
368 fib_carrier_unicast_test()
373 echo "Single path route carrier test"
378 $IP link set dev dummy0 carrier on
382 $IP route get fibmatch 198.51.100.2 &> /dev/null
383 log_test $? 0 "IPv4 fibmatch"
384 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
385 log_test $? 0 "IPv6 fibmatch"
387 $IP route get fibmatch 198.51.100.2 | \
389 log_test $? 1 "IPv4 no linkdown flag"
390 $IP -6 route get fibmatch 2001:db8:1::2 | \
392 log_test $? 1 "IPv6 no linkdown flag"
395 $IP link set dev dummy0 carrier off
400 $IP route get fibmatch 198.51.100.2 &> /dev/null
401 log_test $? 0 "IPv4 fibmatch"
402 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
403 log_test $? 0 "IPv6 fibmatch"
405 $IP route get fibmatch 198.51.100.2 | \
407 log_test $? 0 "IPv4 linkdown flag set"
408 $IP -6 route get fibmatch 2001:db8:1::2 | \
410 log_test $? 0 "IPv6 linkdown flag set"
413 $IP address add 192.0.2.1/24 dev dummy0
414 $IP -6 address add 2001:db8:2::1/64 dev dummy0
417 echo " Second address added with carrier down"
418 $IP route get fibmatch 192.0.2.2 &> /dev/null
419 log_test $? 0 "IPv4 fibmatch"
420 $IP -6 route get fibmatch 2001:db8:2::2 &> /dev/null
421 log_test $? 0 "IPv6 fibmatch"
423 $IP route get fibmatch 192.0.2.2 | \
425 log_test $? 0 "IPv4 linkdown flag set"
426 $IP -6 route get fibmatch 2001:db8:2::2 | \
428 log_test $? 0 "IPv6 linkdown flag set"
435 fib_carrier_local_test
436 fib_carrier_unicast_test
442 echo "IPv4 rp_filter tests"
447 $IP link set dev lo address 52:54:00:6a:c7:5e
448 $IP link set dummy0 address 52:54:00:6a:c7:5e
449 $IP link add dummy1 type dummy
450 $IP link set dummy1 address 52:54:00:6a:c7:5e
451 $IP link set dev dummy1 up
452 $NS_EXEC sysctl -qw net.ipv4.conf.all.rp_filter=1
453 $NS_EXEC sysctl -qw net.ipv4.conf.all.accept_local=1
454 $NS_EXEC sysctl -qw net.ipv4.conf.all.route_localnet=1
456 $NS_EXEC tc qd add dev dummy1 parent root handle 1: fq_codel
457 $NS_EXEC tc filter add dev dummy1 parent 1: protocol arp basic action mirred egress redirect dev lo
458 $NS_EXEC tc filter add dev dummy1 parent 1: protocol ip basic action mirred egress redirect dev lo
461 run_cmd "ip netns exec ns1 ping -I dummy1 -w1 -c1 198.51.100.1"
462 log_test $? 0 "rp_filter passes local packets"
464 run_cmd "ip netns exec ns1 ping -I dummy1 -w1 -c1 127.0.0.1"
465 log_test $? 0 "rp_filter passes loopback packets"
470 ################################################################################
471 # Tests on nexthop spec
473 # run 'ip route add' with given spec
484 [ "$vrf" = "-" ] && vrf="default"
485 [ -n "$gw" ] && gw="via $gw"
486 [ -n "$dev" ] && dev="dev $dev"
488 cmd="$IP route add vrf $vrf $pfx $gw $dev"
489 if [ "$VERBOSE" = "1" ]; then
490 printf "\n COMMAND: $cmd\n"
493 out=$(eval $cmd 2>&1)
495 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
498 log_test $rc $erc "$desc"
504 echo "IPv4 nexthop tests"
506 echo "<<< write me >>>"
511 local lldummy=$(get_linklocal dummy0)
512 local llv1=$(get_linklocal dummy0)
514 if [ -z "$lldummy" ]; then
515 echo "Failed to get linklocal address for dummy0"
518 if [ -z "$llv1" ]; then
519 echo "Failed to get linklocal address for veth1"
524 echo "IPv6 nexthop tests"
526 add_rt "Directly connected nexthop, unicast address" 0 \
527 - 2001:db8:101::/64 2001:db8:1::2
528 add_rt "Directly connected nexthop, unicast address with device" 0 \
529 - 2001:db8:102::/64 2001:db8:1::2 "dummy0"
530 add_rt "Gateway is linklocal address" 0 \
531 - 2001:db8:103::1/64 $llv1 "veth0"
533 # fails because LL address requires a device
534 add_rt "Gateway is linklocal address, no device" 2 \
535 - 2001:db8:104::1/64 $llv1
537 # local address can not be a gateway
538 add_rt "Gateway can not be local unicast address" 2 \
539 - 2001:db8:105::/64 2001:db8:1::1
540 add_rt "Gateway can not be local unicast address, with device" 2 \
541 - 2001:db8:106::/64 2001:db8:1::1 "dummy0"
542 add_rt "Gateway can not be a local linklocal address" 2 \
543 - 2001:db8:107::1/64 $lldummy "dummy0"
546 add_rt "Gateway can be local address in a VRF" 0 \
547 - 2001:db8:108::/64 2001:db8:51::2
548 add_rt "Gateway can be local address in a VRF, with device" 0 \
549 - 2001:db8:109::/64 2001:db8:51::2 "veth0"
550 add_rt "Gateway can be local linklocal address in a VRF" 0 \
551 - 2001:db8:110::1/64 $llv1 "veth0"
553 add_rt "Redirect to VRF lookup" 0 \
554 - 2001:db8:111::/64 "" "red"
556 add_rt "VRF route, gateway can be local address in default VRF" 0 \
557 red 2001:db8:112::/64 2001:db8:51::1
559 # local address in same VRF fails
560 add_rt "VRF route, gateway can not be a local address" 2 \
561 red 2001:db8:113::1/64 2001:db8:2::1
562 add_rt "VRF route, gateway can not be a local addr with device" 2 \
563 red 2001:db8:114::1/64 2001:db8:2::1 "dummy1"
567 # dummy0 - 198.51.100.1/24 2001:db8:1::1/64
568 # veth0 - 192.0.2.1/24 2001:db8:51::1/64
571 # dummy1 - 192.168.2.1/24 2001:db8:2::1/64
572 # veth1 - 192.0.2.2/24 2001:db8:51::2/64
574 # [ dummy0 veth0 ]--[ veth1 dummy1 ]
582 $IP -4 rule add pref 32765 table local
583 $IP -4 rule del pref 0
584 $IP -6 rule add pref 32765 table local
585 $IP -6 rule del pref 0
587 $IP link add red type vrf table 1
589 $IP -4 route add vrf red unreachable default metric 4278198272
590 $IP -6 route add vrf red unreachable default metric 4278198272
592 $IP link add veth0 type veth peer name veth1
593 $IP link set dev veth0 up
594 $IP address add 192.0.2.1/24 dev veth0
595 $IP -6 address add 2001:db8:51::1/64 dev veth0
597 $IP link set dev veth1 vrf red up
598 $IP address add 192.0.2.2/24 dev veth1
599 $IP -6 address add 2001:db8:51::2/64 dev veth1
601 $IP link add dummy1 type dummy
602 $IP link set dev dummy1 vrf red up
603 $IP address add 192.168.2.1/24 dev dummy1
604 $IP -6 address add 2001:db8:2::1/64 dev dummy1
612 $IP link del dev dummy1
621 $IP link add dummy1 type dummy
622 $IP link set dummy1 up
623 $IP -6 route add default dev dummy1
624 $IP -6 rule add table main suppress_prefixlength 0
625 ping -f -c 1000 -W 1 1234::1 || true
626 $IP -6 rule del table main suppress_prefixlength 0
629 # If we got here without crashing, we're good.
633 ################################################################################
634 # Tests on route add and replace
640 local stderr="2>/dev/null"
642 if [ "$VERBOSE" = "1" ]; then
643 printf " COMMAND: $cmd\n"
647 out=$(eval $cmd $stderr)
649 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
653 [ "$VERBOSE" = "1" ] && echo
664 [ "${out}" = "${expected}" ] && return 0
666 if [ -z "${out}" ]; then
667 if [ "$VERBOSE" = "1" ]; then
668 printf "\nNo route entry found\n"
670 printf " ${expected}\n"
675 # tricky way to convert output to 1-line without ip's
676 # messy '\'; this drops all extra white space
678 if [ "${out}" != "${expected}" ]; then
680 if [ "${VERBOSE}" = "1" ]; then
681 printf " Unexpected route entry. Have:\n"
683 printf " Expected:\n"
684 printf " ${expected}\n\n"
691 # add route for a prefix, flushing any existing routes first
692 # expected to be the first step of a test
699 if [ "$VERBOSE" = "1" ]; then
701 echo " ##################################################"
705 run_cmd "$IP -6 ro flush ${pfx}"
706 [ $? -ne 0 ] && exit 1
708 out=$($IP -6 ro ls match ${pfx})
709 if [ -n "$out" ]; then
710 echo "Failed to flush routes for prefix used for tests."
714 run_cmd "$IP -6 ro add ${pfx} ${nh}"
715 if [ $? -ne 0 ]; then
716 echo "Failed to add initial route for test."
721 # add initial route - used in replace route tests
724 add_route6 "2001:db8:104::/64" "$1"
737 out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//')
738 check_expected "${out}" "${expected}"
743 $IP li del red 2>/dev/null
744 $IP li del dummy1 2>/dev/null
745 $IP li del veth1 2>/dev/null
746 $IP li del veth3 2>/dev/null
756 [ "${VERBOSE}" = "1" ] && set -x
760 ip netns set ns2 auto
761 ip -netns ns2 link set dev lo up
762 ip netns exec ns2 sysctl -qw net.ipv4.ip_forward=1
763 ip netns exec ns2 sysctl -qw net.ipv6.conf.all.forwarding=1
765 $IP li add veth1 type veth peer name veth2
766 $IP li add veth3 type veth peer name veth4
770 $IP li set veth2 netns ns2 up
771 $IP li set veth4 netns ns2 up
772 ip -netns ns2 li add dummy1 type dummy
773 ip -netns ns2 li set dummy1 up
775 $IP -6 addr add 2001:db8:101::1/64 dev veth1 nodad
776 $IP -6 addr add 2001:db8:103::1/64 dev veth3 nodad
777 $IP addr add 172.16.101.1/24 dev veth1
778 $IP addr add 172.16.103.1/24 dev veth3
780 ip -netns ns2 -6 addr add 2001:db8:101::2/64 dev veth2 nodad
781 ip -netns ns2 -6 addr add 2001:db8:103::2/64 dev veth4 nodad
782 ip -netns ns2 -6 addr add 2001:db8:104::1/64 dev dummy1 nodad
784 ip -netns ns2 addr add 172.16.101.2/24 dev veth2
785 ip -netns ns2 addr add 172.16.103.2/24 dev veth4
786 ip -netns ns2 addr add 172.16.104.1/24 dev dummy1
791 # assumption is that basic add of a single path route works
792 # otherwise just adding an address on an interface is broken
798 echo "IPv6 route add / append tests"
800 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
801 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
802 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2"
803 log_test $? 2 "Attempt to add duplicate route - gw"
805 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
806 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
807 run_cmd "$IP -6 ro add 2001:db8:104::/64 dev veth3"
808 log_test $? 2 "Attempt to add duplicate route - dev only"
810 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
811 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
812 run_cmd "$IP -6 ro add unreachable 2001:db8:104::/64"
813 log_test $? 2 "Attempt to add duplicate route - reject route"
815 # route append with same prefix adds a new route
816 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
817 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
818 run_cmd "$IP -6 ro append 2001:db8:104::/64 via 2001:db8:103::2"
819 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"
820 log_test $? 0 "Append nexthop to existing route - gw"
822 # insert mpath directly
823 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
824 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"
825 log_test $? 0 "Add multipath route"
827 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
828 run_cmd "$IP -6 ro add 2001:db8:104::/64 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
829 log_test $? 2 "Attempt to add duplicate multipath route"
831 # insert of a second route without append but different metric
832 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
833 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2 metric 512"
835 if [ $rc -eq 0 ]; then
836 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::3 metric 256"
839 log_test $rc 0 "Route add with different metrics"
841 run_cmd "$IP -6 ro del 2001:db8:104::/64 metric 512"
843 if [ $rc -eq 0 ]; then
844 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"
847 log_test $rc 0 "Route delete with metric"
850 ipv6_rt_replace_single()
852 # single path with single path
854 add_initial_route6 "via 2001:db8:101::2"
855 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:103::2"
856 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
857 log_test $? 0 "Single path with single path"
859 # single path with multipath
861 add_initial_route6 "nexthop via 2001:db8:101::2"
862 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::2"
863 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"
864 log_test $? 0 "Single path with multipath"
866 # single path with single path using MULTIPATH attribute
868 add_initial_route6 "via 2001:db8:101::2"
869 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:103::2"
870 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
871 log_test $? 0 "Single path with single path via multipath attribute"
873 # route replace fails - invalid nexthop
874 add_initial_route6 "via 2001:db8:101::2"
875 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:104::2"
876 if [ $? -eq 0 ]; then
877 # previous command is expected to fail so if it returns 0
878 # that means the test failed.
879 log_test 0 1 "Invalid nexthop"
881 check_route6 "2001:db8:104::/64 via 2001:db8:101::2 dev veth1 metric 1024"
882 log_test $? 0 "Invalid nexthop"
885 # replace non-existent route
886 # - note use of change versus replace since ip adds NLM_F_CREATE
888 add_initial_route6 "via 2001:db8:101::2"
889 run_cmd "$IP -6 ro change 2001:db8:105::/64 via 2001:db8:101::2"
890 log_test $? 2 "Single path - replace of non-existent route"
893 ipv6_rt_replace_mpath()
895 # multipath with multipath
896 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
897 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
898 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"
899 log_test $? 0 "Multipath with multipath"
901 # multipath with single
902 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
903 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:101::3"
904 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
905 log_test $? 0 "Multipath with single path"
907 # multipath with single
908 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
909 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3"
910 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
911 log_test $? 0 "Multipath with single path via multipath attribute"
913 # multipath with dev-only
914 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
915 run_cmd "$IP -6 ro replace 2001:db8:104::/64 dev veth1"
916 check_route6 "2001:db8:104::/64 dev veth1 metric 1024"
917 log_test $? 0 "Multipath with dev-only"
919 # route replace fails - invalid nexthop 1
920 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
921 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:111::3 nexthop via 2001:db8:103::3"
922 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"
923 log_test $? 0 "Multipath - invalid first nexthop"
925 # route replace fails - invalid nexthop 2
926 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
927 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:113::3"
928 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"
929 log_test $? 0 "Multipath - invalid second nexthop"
931 # multipath non-existent route
932 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
933 run_cmd "$IP -6 ro change 2001:db8:105::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
934 log_test $? 2 "Multipath - replace of non-existent route"
940 echo "IPv6 route replace tests"
942 ipv6_rt_replace_single
943 ipv6_rt_replace_mpath
956 ip_addr_metric_check()
958 ip addr help 2>&1 | grep -q metric
959 if [ $? -ne 0 ]; then
960 echo "iproute2 command does not support metric for addresses. Skipping test"
967 ipv6_addr_metric_test()
972 echo "IPv6 prefix route tests"
974 ip_addr_metric_check || return 1
979 $IP li add dummy1 type dummy
980 $IP li add dummy2 type dummy
984 # default entry is metric 256
985 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64"
986 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64"
989 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 256 2001:db8:104::/64 dev dummy2 proto kernel metric 256"
990 log_test $? 0 "Default metric"
993 run_cmd "$IP -6 addr flush dev dummy1"
994 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64 metric 257"
997 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 256 2001:db8:104::/64 dev dummy1 proto kernel metric 257"
998 log_test $? 0 "User specified metric on first device"
1001 run_cmd "$IP -6 addr flush dev dummy2"
1002 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64 metric 258"
1005 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 257 2001:db8:104::/64 dev dummy2 proto kernel metric 258"
1006 log_test $? 0 "User specified metric on second device"
1008 run_cmd "$IP -6 addr del dev dummy1 2001:db8:104::1/64 metric 257"
1010 if [ $rc -eq 0 ]; then
1011 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 258"
1014 log_test $rc 0 "Delete of address on first device"
1016 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::2/64 metric 259"
1018 if [ $rc -eq 0 ]; then
1019 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
1022 log_test $rc 0 "Modify metric of address"
1024 # verify prefix route removed on down
1025 run_cmd "ip netns exec ns1 sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1"
1026 run_cmd "$IP li set dev dummy2 down"
1028 if [ $rc -eq 0 ]; then
1029 out=$($IP -6 ro ls match 2001:db8:104::/64)
1030 check_expected "${out}" ""
1033 log_test $rc 0 "Prefix route removed on link down"
1035 # verify prefix route re-inserted with assigned metric
1036 run_cmd "$IP li set dev dummy2 up"
1038 if [ $rc -eq 0 ]; then
1039 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
1042 log_test $rc 0 "Prefix route with metric on link up"
1049 ipv6_route_metrics_test()
1054 echo "IPv6 routes with metrics"
1059 # single path with metrics
1061 run_cmd "$IP -6 ro add 2001:db8:111::/64 via 2001:db8:101::2 mtu 1400"
1063 if [ $rc -eq 0 ]; then
1064 check_route6 "2001:db8:111::/64 via 2001:db8:101::2 dev veth1 metric 1024 mtu 1400"
1067 log_test $rc 0 "Single path route with mtu metric"
1071 # multipath via separate routes with metrics
1073 run_cmd "$IP -6 ro add 2001:db8:112::/64 via 2001:db8:101::2 mtu 1400"
1074 run_cmd "$IP -6 ro append 2001:db8:112::/64 via 2001:db8:103::2"
1076 if [ $rc -eq 0 ]; then
1077 check_route6 "2001:db8:112::/64 metric 1024 mtu 1400 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
1080 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on first"
1082 # second route is coalesced to first to make a multipath route.
1083 # MTU of the second path is hidden from display!
1084 run_cmd "$IP -6 ro add 2001:db8:113::/64 via 2001:db8:101::2"
1085 run_cmd "$IP -6 ro append 2001:db8:113::/64 via 2001:db8:103::2 mtu 1400"
1087 if [ $rc -eq 0 ]; then
1088 check_route6 "2001:db8:113::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
1091 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on 2nd"
1093 run_cmd "$IP -6 ro del 2001:db8:113::/64 via 2001:db8:101::2"
1094 if [ $? -eq 0 ]; then
1095 check_route6 "2001:db8:113::/64 via 2001:db8:103::2 dev veth3 metric 1024 mtu 1400"
1096 log_test $? 0 " MTU of second leg"
1100 # multipath with metrics
1102 run_cmd "$IP -6 ro add 2001:db8:115::/64 mtu 1400 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
1104 if [ $rc -eq 0 ]; then
1105 check_route6 "2001:db8:115::/64 metric 1024 mtu 1400 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
1108 log_test $rc 0 "Multipath route with mtu metric"
1110 $IP -6 ro add 2001:db8:104::/64 via 2001:db8:101::2 mtu 1300
1111 run_cmd "ip netns exec ns1 ${ping6} -w1 -c1 -s 1500 2001:db8:104::1"
1112 log_test $? 0 "Using route with mtu metric"
1114 run_cmd "$IP -6 ro add 2001:db8:114::/64 via 2001:db8:101::2 congctl lock foo"
1115 log_test $? 2 "Invalid metric (fails metric_convert)"
1120 # add route for a prefix, flushing any existing routes first
1121 # expected to be the first step of a test
1128 if [ "$VERBOSE" = "1" ]; then
1130 echo " ##################################################"
1134 run_cmd "$IP ro flush ${pfx}"
1135 [ $? -ne 0 ] && exit 1
1137 out=$($IP ro ls match ${pfx})
1138 if [ -n "$out" ]; then
1139 echo "Failed to flush routes for prefix used for tests."
1143 run_cmd "$IP ro add ${pfx} ${nh}"
1144 if [ $? -ne 0 ]; then
1145 echo "Failed to add initial route for test."
1150 # add initial route - used in replace route tests
1153 add_route "172.16.104.0/24" "$1"
1164 [ "${pfx}" = "unreachable" ] && pfx=$2
1166 out=$($IP ro ls match ${pfx})
1167 check_expected "${out}" "${expected}"
1170 # assumption is that basic add of a single path route works
1171 # otherwise just adding an address on an interface is broken
1177 echo "IPv4 route add / append tests"
1179 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1180 add_route "172.16.104.0/24" "via 172.16.101.2"
1181 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2"
1182 log_test $? 2 "Attempt to add duplicate route - gw"
1184 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1185 add_route "172.16.104.0/24" "via 172.16.101.2"
1186 run_cmd "$IP ro add 172.16.104.0/24 dev veth3"
1187 log_test $? 2 "Attempt to add duplicate route - dev only"
1189 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1190 add_route "172.16.104.0/24" "via 172.16.101.2"
1191 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1192 log_test $? 2 "Attempt to add duplicate route - reject route"
1194 # iproute2 prepend only sets NLM_F_CREATE
1195 # - adds a new route; does NOT convert existing route to ECMP
1196 add_route "172.16.104.0/24" "via 172.16.101.2"
1197 run_cmd "$IP ro prepend 172.16.104.0/24 via 172.16.103.2"
1198 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"
1199 log_test $? 0 "Add new nexthop for existing prefix"
1201 # route append with same prefix adds a new route
1202 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
1203 add_route "172.16.104.0/24" "via 172.16.101.2"
1204 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
1205 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"
1206 log_test $? 0 "Append nexthop to existing route - gw"
1208 add_route "172.16.104.0/24" "via 172.16.101.2"
1209 run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
1210 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 dev veth3 scope link"
1211 log_test $? 0 "Append nexthop to existing route - dev only"
1213 add_route "172.16.104.0/24" "via 172.16.101.2"
1214 run_cmd "$IP ro append unreachable 172.16.104.0/24"
1215 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 unreachable 172.16.104.0/24"
1216 log_test $? 0 "Append nexthop to existing route - reject route"
1218 run_cmd "$IP ro flush 172.16.104.0/24"
1219 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1220 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
1221 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 via 172.16.103.2 dev veth3"
1222 log_test $? 0 "Append nexthop to existing reject route - gw"
1224 run_cmd "$IP ro flush 172.16.104.0/24"
1225 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1226 run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
1227 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 dev veth3 scope link"
1228 log_test $? 0 "Append nexthop to existing reject route - dev only"
1230 # insert mpath directly
1231 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1232 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"
1233 log_test $? 0 "add multipath route"
1235 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1236 run_cmd "$IP ro add 172.16.104.0/24 nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1237 log_test $? 2 "Attempt to add duplicate multipath route"
1239 # insert of a second route without append but different metric
1240 add_route "172.16.104.0/24" "via 172.16.101.2"
1241 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2 metric 512"
1243 if [ $rc -eq 0 ]; then
1244 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.3 metric 256"
1247 log_test $rc 0 "Route add with different metrics"
1249 run_cmd "$IP ro del 172.16.104.0/24 metric 512"
1251 if [ $rc -eq 0 ]; then
1252 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"
1255 log_test $rc 0 "Route delete with metric"
1258 ipv4_rt_replace_single()
1260 # single path with single path
1262 add_initial_route "via 172.16.101.2"
1263 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.103.2"
1264 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
1265 log_test $? 0 "Single path with single path"
1267 # single path with multipath
1269 add_initial_route "nexthop via 172.16.101.2"
1270 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.2"
1271 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"
1272 log_test $? 0 "Single path with multipath"
1274 # single path with reject
1276 add_initial_route "nexthop via 172.16.101.2"
1277 run_cmd "$IP ro replace unreachable 172.16.104.0/24"
1278 check_route "unreachable 172.16.104.0/24"
1279 log_test $? 0 "Single path with reject route"
1281 # single path with single path using MULTIPATH attribute
1283 add_initial_route "via 172.16.101.2"
1284 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.103.2"
1285 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
1286 log_test $? 0 "Single path with single path via multipath attribute"
1288 # route replace fails - invalid nexthop
1289 add_initial_route "via 172.16.101.2"
1290 run_cmd "$IP ro replace 172.16.104.0/24 via 2001:db8:104::2"
1291 if [ $? -eq 0 ]; then
1292 # previous command is expected to fail so if it returns 0
1293 # that means the test failed.
1294 log_test 0 1 "Invalid nexthop"
1296 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1"
1297 log_test $? 0 "Invalid nexthop"
1300 # replace non-existent route
1301 # - note use of change versus replace since ip adds NLM_F_CREATE
1303 add_initial_route "via 172.16.101.2"
1304 run_cmd "$IP ro change 172.16.105.0/24 via 172.16.101.2"
1305 log_test $? 2 "Single path - replace of non-existent route"
1308 ipv4_rt_replace_mpath()
1310 # multipath with multipath
1311 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1312 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
1313 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"
1314 log_test $? 0 "Multipath with multipath"
1316 # multipath with single
1317 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1318 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.101.3"
1319 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
1320 log_test $? 0 "Multipath with single path"
1322 # multipath with single
1323 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1324 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3"
1325 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
1326 log_test $? 0 "Multipath with single path via multipath attribute"
1328 # multipath with reject
1329 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1330 run_cmd "$IP ro replace unreachable 172.16.104.0/24"
1331 check_route "unreachable 172.16.104.0/24"
1332 log_test $? 0 "Multipath with reject route"
1334 # route replace fails - invalid nexthop 1
1335 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1336 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.111.3 nexthop via 172.16.103.3"
1337 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"
1338 log_test $? 0 "Multipath - invalid first nexthop"
1340 # route replace fails - invalid nexthop 2
1341 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1342 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.113.3"
1343 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"
1344 log_test $? 0 "Multipath - invalid second nexthop"
1346 # multipath non-existent route
1347 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1348 run_cmd "$IP ro change 172.16.105.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
1349 log_test $? 2 "Multipath - replace of non-existent route"
1355 echo "IPv4 route replace tests"
1357 ipv4_rt_replace_single
1358 ipv4_rt_replace_mpath
1371 ipv4_addr_metric_test()
1376 echo "IPv4 prefix route tests"
1378 ip_addr_metric_check || return 1
1383 $IP li add dummy1 type dummy
1384 $IP li add dummy2 type dummy
1385 $IP li set dummy1 up
1386 $IP li set dummy2 up
1388 # default entry is metric 256
1389 run_cmd "$IP addr add dev dummy1 172.16.104.1/24"
1390 run_cmd "$IP addr add dev dummy2 172.16.104.2/24"
1393 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"
1394 log_test $? 0 "Default metric"
1397 run_cmd "$IP addr flush dev dummy1"
1398 run_cmd "$IP addr add dev dummy1 172.16.104.1/24 metric 257"
1401 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"
1402 log_test $? 0 "User specified metric on first device"
1405 run_cmd "$IP addr flush dev dummy2"
1406 run_cmd "$IP addr add dev dummy2 172.16.104.2/24 metric 258"
1409 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"
1410 log_test $? 0 "User specified metric on second device"
1412 run_cmd "$IP addr del dev dummy1 172.16.104.1/24 metric 257"
1414 if [ $rc -eq 0 ]; then
1415 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 258"
1418 log_test $rc 0 "Delete of address on first device"
1420 run_cmd "$IP addr change dev dummy2 172.16.104.2/24 metric 259"
1422 if [ $rc -eq 0 ]; then
1423 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
1426 log_test $rc 0 "Modify metric of address"
1428 # verify prefix route removed on down
1429 run_cmd "$IP li set dev dummy2 down"
1431 if [ $rc -eq 0 ]; then
1432 out=$($IP ro ls match 172.16.104.0/24)
1433 check_expected "${out}" ""
1436 log_test $rc 0 "Prefix route removed on link down"
1438 # verify prefix route re-inserted with assigned metric
1439 run_cmd "$IP li set dev dummy2 up"
1441 if [ $rc -eq 0 ]; then
1442 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
1445 log_test $rc 0 "Prefix route with metric on link up"
1447 # explicitly check for metric changes on edge scenarios
1448 run_cmd "$IP addr flush dev dummy2"
1449 run_cmd "$IP addr add dev dummy2 172.16.104.0/24 metric 259"
1450 run_cmd "$IP addr change dev dummy2 172.16.104.0/24 metric 260"
1452 if [ $rc -eq 0 ]; then
1453 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.0 metric 260"
1456 log_test $rc 0 "Modify metric of .0/24 address"
1458 run_cmd "$IP addr flush dev dummy2"
1459 run_cmd "$IP addr add dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 260"
1460 run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 261"
1462 if [ $rc -eq 0 ]; then
1463 check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 261"
1466 log_test $rc 0 "Modify metric of address with peer route"
1473 ipv4_route_metrics_test()
1478 echo "IPv4 route add / append tests"
1482 run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 mtu 1400"
1484 if [ $rc -eq 0 ]; then
1485 check_route "172.16.111.0/24 via 172.16.101.2 dev veth1 mtu 1400"
1488 log_test $rc 0 "Single path route with mtu metric"
1491 run_cmd "$IP ro add 172.16.112.0/24 mtu 1400 nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1493 if [ $rc -eq 0 ]; then
1494 check_route "172.16.112.0/24 mtu 1400 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
1497 log_test $rc 0 "Multipath route with mtu metric"
1499 $IP ro add 172.16.104.0/24 via 172.16.101.2 mtu 1300
1500 run_cmd "ip netns exec ns1 ping -w1 -c1 -s 1500 172.16.104.1"
1501 log_test $? 0 "Using route with mtu metric"
1503 run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 congctl lock foo"
1504 log_test $? 2 "Invalid metric (fails metric_convert)"
1509 ipv4_del_addr_test()
1512 echo "IPv4 delete address route tests"
1517 $IP li add dummy1 type dummy
1518 $IP li set dummy1 up
1519 $IP li add dummy2 type dummy
1520 $IP li set dummy2 up
1521 $IP li add red type vrf table 1111
1523 $IP ro add vrf red unreachable default
1524 $IP li set dummy2 vrf red
1526 $IP addr add dev dummy1 172.16.104.1/24
1527 $IP addr add dev dummy1 172.16.104.11/24
1528 $IP addr add dev dummy2 172.16.104.1/24
1529 $IP addr add dev dummy2 172.16.104.11/24
1530 $IP route add 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
1531 $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
1534 # removing address from device in vrf should only remove route from vrf table
1535 $IP addr del dev dummy2 172.16.104.11/24
1536 $IP ro ls vrf red | grep -q 172.16.105.0/24
1537 log_test $? 1 "Route removed from VRF when source address deleted"
1539 $IP ro ls | grep -q 172.16.105.0/24
1540 log_test $? 0 "Route in default VRF not removed"
1542 $IP addr add dev dummy2 172.16.104.11/24
1543 $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
1545 $IP addr del dev dummy1 172.16.104.11/24
1546 $IP ro ls | grep -q 172.16.105.0/24
1547 log_test $? 1 "Route removed in default VRF when source address deleted"
1549 $IP ro ls vrf red | grep -q 172.16.105.0/24
1550 log_test $? 0 "Route in VRF is not removed by address delete"
1558 ipv4_route_v6_gw_test()
1563 echo "IPv4 route with IPv6 gateway tests"
1571 run_cmd "$IP ro add 172.16.104.0/24 via inet6 2001:db8:101::2"
1573 log_test $rc 0 "Single path route with IPv6 gateway"
1574 if [ $rc -eq 0 ]; then
1575 check_route "172.16.104.0/24 via inet6 2001:db8:101::2 dev veth1"
1578 run_cmd "ip netns exec ns1 ping -w1 -c1 172.16.104.1"
1579 log_test $rc 0 "Single path route with IPv6 gateway - ping"
1581 run_cmd "$IP ro del 172.16.104.0/24 via inet6 2001:db8:101::2"
1583 log_test $rc 0 "Single path route delete"
1584 if [ $rc -eq 0 ]; then
1585 check_route "172.16.112.0/24"
1589 # multipath - v6 then v4
1591 run_cmd "$IP ro add 172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 nexthop via 172.16.103.2 dev veth3"
1593 log_test $rc 0 "Multipath route add - v6 nexthop then v4"
1594 if [ $rc -eq 0 ]; then
1595 check_route "172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
1598 run_cmd "$IP ro del 172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 nexthop via inet6 2001:db8:101::2 dev veth1"
1599 log_test $? 2 " Multipath route delete - nexthops in wrong order"
1601 run_cmd "$IP ro del 172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 nexthop via 172.16.103.2 dev veth3"
1602 log_test $? 0 " Multipath route delete exact match"
1605 # multipath - v4 then v6
1607 run_cmd "$IP ro add 172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 nexthop via inet6 2001:db8:101::2 dev veth1"
1609 log_test $rc 0 "Multipath route add - v4 nexthop then v6"
1610 if [ $rc -eq 0 ]; then
1611 check_route "172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 weight 1 nexthop via inet6 2001:db8:101::2 dev veth1 weight 1"
1614 run_cmd "$IP ro del 172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 nexthop via 172.16.103.2 dev veth3"
1615 log_test $? 2 " Multipath route delete - nexthops in wrong order"
1617 run_cmd "$IP ro del 172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 nexthop via inet6 2001:db8:101::2 dev veth1"
1618 log_test $? 0 " Multipath route delete exact match"
1623 ################################################################################
1629 usage: ${0##*/} OPTS
1631 -t <test> Test(s) to run (default: all)
1634 -P Pause after each test before cleanup
1635 -v verbose mode (show commands and output)
1639 ################################################################################
1642 while getopts :t:pPhv o
1646 p) PAUSE_ON_FAIL=yes;;
1648 v) VERBOSE=$(($VERBOSE + 1));;
1654 PEER_CMD="ip netns exec ${PEER_NS}"
1656 # make sure we don't pause twice
1657 [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
1659 if [ "$(id -u)" -ne 0 ];then
1660 echo "SKIP: Need root privileges"
1664 if [ ! -x "$(command -v ip)" ]; then
1665 echo "SKIP: Could not run test without ip tool"
1669 ip route help 2>&1 | grep -q fibmatch
1670 if [ $? -ne 0 ]; then
1671 echo "SKIP: iproute2 too old, missing fibmatch"
1676 cleanup &> /dev/null
1681 fib_unreg_test|unregister) fib_unreg_test;;
1682 fib_down_test|down) fib_down_test;;
1683 fib_carrier_test|carrier) fib_carrier_test;;
1684 fib_rp_filter_test|rp_filter) fib_rp_filter_test;;
1685 fib_nexthop_test|nexthop) fib_nexthop_test;;
1686 fib_suppress_test|suppress) fib_suppress_test;;
1687 ipv6_route_test|ipv6_rt) ipv6_route_test;;
1688 ipv4_route_test|ipv4_rt) ipv4_route_test;;
1689 ipv6_addr_metric) ipv6_addr_metric_test;;
1690 ipv4_addr_metric) ipv4_addr_metric_test;;
1691 ipv4_del_addr) ipv4_del_addr_test;;
1692 ipv6_route_metrics) ipv6_route_metrics_test;;
1693 ipv4_route_metrics) ipv4_route_metrics_test;;
1694 ipv4_route_v6_gw) ipv4_route_v6_gw_test;;
1696 help) echo "Test names: $TESTS"; exit 0;;
1700 if [ "$TESTS" != "none" ]; then
1701 printf "\nTests passed: %3d\n" ${nsuccess}
1702 printf "Tests failed: %3d\n" ${nfail}