Lines Matching +full:route +full:- +full:up
2 # SPDX-License-Identifier: GPL-2.0
9 # all tests in this script. Can be overridden with -t option
28 if [ ${rc} -eq ${expected} ]; then
29 printf " TEST: %-60s [ OK ]\n" "${msg}"
34 printf " TEST: %-60s [FAIL]\n" "${msg}"
53 set -e
55 IP="$(which ip) -netns $ns1"
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
61 $IP link set dev dummy0 up
63 $IP -6 address add 2001:db8:1::1/64 dev dummy0
79 addr=$($IP -6 -br addr show dev ${dev} | \
89 [ -z "$addr" ] && return 1
99 echo "Single path route test"
104 $IP route get fibmatch 198.51.100.2 &> /dev/null
106 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
109 set -e
114 $IP route get fibmatch 198.51.100.2 &> /dev/null
115 log_test $? 2 "IPv4 fibmatch - no route"
116 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
117 log_test $? 2 "IPv6 fibmatch - no route"
126 echo "Multipath route test"
130 set -e
132 $IP link set dev dummy1 up
134 $IP -6 address add 2001:db8:2::1/64 dev dummy1
136 $IP route add 203.0.113.0/24 \
139 $IP -6 route add 2001:db8:3::/64 \
145 $IP route get fibmatch 203.0.113.1 &> /dev/null
147 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
150 set -e
155 $IP route get fibmatch 203.0.113.1 &> /dev/null
156 log_test $? 2 "IPv4 - multipath route removed on delete"
158 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
159 # In IPv6 we do not flush the entire multipath route.
160 log_test $? 0 "IPv6 - multipath down to single path"
162 set -e
167 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
168 log_test $? 2 "IPv6 - no route"
187 $IP route get fibmatch 198.51.100.2 &> /dev/null
189 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
192 set -e
196 echo " Route deleted on down"
197 $IP route get fibmatch 198.51.100.2 &> /dev/null
199 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
210 $IP route get fibmatch 203.0.113.1 \
213 $IP -6 route get fibmatch 2001:db8:3::1 \
217 $IP route get fibmatch 203.0.113.1 \
219 log_test $? 0 "IPv4 fibmatch on up device"
220 $IP -6 route get fibmatch 2001:db8:3::1 \
222 log_test $? 0 "IPv6 fibmatch on up device"
224 $IP route get fibmatch 203.0.113.1 | \
225 grep $down_dev | grep -q "dead linkdown"
227 $IP -6 route get fibmatch 2001:db8:3::1 | \
228 grep $down_dev | grep -q "dead linkdown"
231 $IP route get fibmatch 203.0.113.1 | \
232 grep $up_dev | grep -q "dead linkdown"
233 log_test $? 1 "IPv4 flags on up device"
234 $IP -6 route get fibmatch 2001:db8:3::1 | \
235 grep $up_dev | grep -q "dead linkdown"
236 log_test $? 1 "IPv6 flags on up device"
246 set -e
248 $IP link set dev dummy1 up
251 $IP -6 address add 2001:db8:2::1/64 dev dummy1
253 $IP route add 203.0.113.0/24 \
256 $IP -6 route add 2001:db8:3::/64 \
262 $IP route get fibmatch 203.0.113.1 &> /dev/null
265 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
268 set -e
272 echo " One device down, one up"
275 set -e
276 $IP link set dev dummy0 up
280 echo " Other device down and up"
283 set -e
288 $IP route get fibmatch 203.0.113.1 &> /dev/null
290 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
307 echo "Local carrier tests - single path"
311 set -e
316 $IP route get fibmatch 198.51.100.1 &> /dev/null
318 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
321 $IP route get fibmatch 198.51.100.1 | \
322 grep -q "linkdown"
323 log_test $? 1 "IPv4 - no linkdown flag"
324 $IP -6 route get fibmatch 2001:db8:1::1 | \
325 grep -q "linkdown"
326 log_test $? 1 "IPv6 - no linkdown flag"
328 set -e
334 $IP route get fibmatch 198.51.100.1 &> /dev/null
336 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
339 $IP route get fibmatch 198.51.100.1 | \
340 grep -q "linkdown"
341 log_test $? 1 "IPv4 - linkdown flag set"
342 $IP -6 route get fibmatch 2001:db8:1::1 | \
343 grep -q "linkdown"
344 log_test $? 1 "IPv6 - linkdown flag set"
346 set -e
348 $IP -6 address add 2001:db8:2::1/64 dev dummy0
351 echo " Route to local address with carrier down"
352 $IP route get fibmatch 192.0.2.1 &> /dev/null
354 $IP -6 route get fibmatch 2001:db8:2::1 &> /dev/null
357 $IP route get fibmatch 192.0.2.1 | \
358 grep -q "linkdown"
360 $IP -6 route get fibmatch 2001:db8:2::1 | \
361 grep -q "linkdown"
372 echo "Single path route carrier test"
376 set -e
381 $IP route get fibmatch 198.51.100.2 &> /dev/null
383 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
386 $IP route get fibmatch 198.51.100.2 | \
387 grep -q "linkdown"
389 $IP -6 route get fibmatch 2001:db8:1::2 | \
390 grep -q "linkdown"
393 set -e
399 $IP route get fibmatch 198.51.100.2 &> /dev/null
401 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
404 $IP route get fibmatch 198.51.100.2 | \
405 grep -q "linkdown"
407 $IP -6 route get fibmatch 2001:db8:1::2 | \
408 grep -q "linkdown"
411 set -e
413 $IP -6 address add 2001:db8:2::1/64 dev dummy0
417 $IP route get fibmatch 192.0.2.2 &> /dev/null
419 $IP -6 route get fibmatch 2001:db8:2::2 &> /dev/null
422 $IP route get fibmatch 192.0.2.2 | \
423 grep -q "linkdown"
425 $IP -6 route get fibmatch 2001:db8:2::2 | \
426 grep -q "linkdown"
445 set -e
451 ip -netns $ns2 address add 192.0.2.1/24 dev veth2
452 $IP link set dev veth1 up
453 ip -netns $ns2 link set dev veth2 up
457 ip -netns $ns2 link set dev lo address 52:54:00:6a:c7:5e
458 ip -netns $ns2 link set dev veth2 address 52:54:00:6a:c7:5e
488 $NS_EXEC sysctl -qw net.ipv4.conf.all.rp_filter=1
489 $NS_EXEC sysctl -qw net.ipv4.conf.all.accept_local=1
490 $NS_EXEC sysctl -qw net.ipv4.conf.all.route_localnet=1
491 ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.rp_filter=1
492 ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.accept_local=1
493 ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.route_localnet=1
496 run_cmd "ip netns exec $ns2 ping -w1 -c1 192.0.2.1"
499 run_cmd "ip netns exec $ns2 ping -w1 -c1 127.0.0.1"
508 # run 'ip route add' with given spec
519 [ "$vrf" = "-" ] && vrf="default"
520 [ -n "$gw" ] && gw="via $gw"
521 [ -n "$dev" ] && dev="dev $dev"
523 cmd="$IP route add vrf $vrf $pfx $gw $dev"
530 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
549 if [ -z "$lldummy" ]; then
553 if [ -z "$llv1" ]; then
562 - 2001:db8:101::/64 2001:db8:1::2
564 - 2001:db8:102::/64 2001:db8:1::2 "dummy0"
566 - 2001:db8:103::1/64 $llv1 "veth0"
570 - 2001:db8:104::1/64 $llv1
574 - 2001:db8:105::/64 2001:db8:1::1
576 - 2001:db8:106::/64 2001:db8:1::1 "dummy0"
578 - 2001:db8:107::1/64 $lldummy "dummy0"
582 - 2001:db8:108::/64 2001:db8:51::2
584 - 2001:db8:109::/64 2001:db8:51::2 "veth0"
586 - 2001:db8:110::1/64 $llv1 "veth0"
589 - 2001:db8:111::/64 "" "red"
591 add_rt "VRF route, gateway can be local address in default VRF" 0 \
595 add_rt "VRF route, gateway can not be a local address" 2 \
597 add_rt "VRF route, gateway can not be a local addr with device" 2 \
602 # dummy0 - 198.51.100.1/24 2001:db8:1::1/64
603 # veth0 - 192.0.2.1/24 2001:db8:51::1/64
606 # dummy1 - 192.168.2.1/24 2001:db8:2::1/64
607 # veth1 - 192.0.2.2/24 2001:db8:51::2/64
609 # [ dummy0 veth0 ]--[ veth1 dummy1 ]
615 set -e
617 $IP -4 rule add pref 32765 table local
618 $IP -4 rule del pref 0
619 $IP -6 rule add pref 32765 table local
620 $IP -6 rule del pref 0
623 $IP link set red up
624 $IP -4 route add vrf red unreachable default metric 4278198272
625 $IP -6 route add vrf red unreachable default metric 4278198272
628 $IP link set dev veth0 up
630 $IP -6 address add 2001:db8:51::1/64 dev veth0
632 $IP link set dev veth1 vrf red up
634 $IP -6 address add 2001:db8:51::2/64 dev veth1
637 $IP link set dev dummy1 vrf red up
639 $IP -6 address add 2001:db8:2::1/64 dev dummy1
659 echo "Fib6 info length calculation in route notify test"
660 set -e
665 $IP link set dev dummy_$i up
666 $IP -6 address add 2001:$i::1/64 dev dummy_$i
669 $NS_EXEC ip monitor route &> errors.txt &
672 $IP -6 route add 2001::/64 \
684 if [ -z "$err" ];then
690 log_test $ret 0 "ipv6 route add notify"
705 echo "Fib4 info length calculation in route notify test"
707 set -e
712 $IP link set dev dummy_$i up
716 $NS_EXEC ip monitor route &> errors.txt &
719 $IP route add 10.0.0.0/24 \
731 if [ -z "$err" ];then
737 log_test $ret 0 "ipv4 route add notify"
752 $IP link set dev dummy_10 up
753 $IP -6 address add 2001:10::1/64 dev dummy_10
761 if [ $num -ne $expected ]; then
774 if [ $num -ne $expected ]; then
789 set -e
795 $NS_EXEC sysctl -wq net.ipv6.route.gc_interval=$EXPIRE
798 $IP link set dev dummy_10 up
799 $IP -6 address add 2001:10::1/64 dev dummy_10
801 $NS_EXEC sysctl -wq net.ipv6.route.flush=1
805 # Expire route after $EXPIRE seconds
806 $IP -6 route add 2001:20::$i \
810 $NS_EXEC sysctl -wq net.ipv6.route.flush=1
811 check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
812 log_test $ret 0 "ipv6 route garbage collection"
818 $IP -6 route add 2001:30::$i \
823 # Expire route after $EXPIRE seconds
824 $IP -6 route add 2001:20::$i \
829 check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
830 log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"
836 $IP -6 route add 2001:20::$i \
841 # Expire route after $EXPIRE seconds
842 $IP -6 route replace 2001:20::$i \
847 check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
848 log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
854 # Expire route after $EXPIRE seconds
855 $IP -6 route add 2001:20::$i \
860 $IP -6 route replace 2001:20::$i \
863 check_rt_num_clean 0 $($IP -6 route list |grep expires|wc -l) || return
867 check_rt_num 5 $($IP -6 route list |grep -v expires|grep 2001:20::|wc -l)
868 log_test $ret 0 "ipv6 route garbage collection (replace with permanent)"
871 if [ ! -x "$(command -v ra6)" ]; then
884 $IP link set dev veth1 up
885 $IP link set dev veth2 up
886 $IP -6 address add 2001:10::1/64 dev veth1 nodad
887 $IP -6 address add 2001:10::2/64 dev veth2 nodad
890 $NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra=2
892 # Send a RA message with a route from veth2 to veth1.
893 $NS_EXEC ra6 -i veth2 -d 2001:10::1 -t $EXPIRE
898 # systemd may mess up the test. You syould make sure that
899 # systemd-networkd.service and systemd-networkd.socket are stopped.
900 check_rt_num_clean 1 $($IP -6 route list|grep expires|wc -l) || return
904 check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
905 log_test $ret 0 "ipv6 route garbage collection (RA message)"
919 $IP link set dummy1 up
920 $IP -6 route add default dev dummy1
921 $IP -6 rule add table main suppress_prefixlength 0
922 ping -f -c 1000 -W 1 1234::1 >/dev/null 2>&1
923 $IP -6 rule del table main suppress_prefixlength 0
933 # Tests on route add and replace
948 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
965 if [ -z "${out}" ]; then
967 printf "\nNo route entry found\n"
974 # tricky way to convert output to 1-line without ip's
980 printf " Unexpected route entry. Have:\n"
990 # add route for a prefix, flushing any existing routes first
1004 run_cmd "$IP -6 ro flush ${pfx}"
1005 [ $? -ne 0 ] && exit 1
1007 out=$($IP -6 ro ls match ${pfx})
1008 if [ -n "$out" ]; then
1013 run_cmd "$IP -6 ro add ${pfx} ${nh}"
1014 if [ $? -ne 0 ]; then
1015 echo "Failed to add initial route for test."
1020 # add initial route - used in replace route tests
1033 set -- $expected
1036 out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//')
1055 [ "${VERBOSE}" = "1" ] && set -x
1056 set -e
1059 ip netns exec $ns2 sysctl -qw net.ipv4.ip_forward=1
1060 ip netns exec $ns2 sysctl -qw net.ipv6.conf.all.forwarding=1
1065 $IP li set veth1 up
1066 $IP li set veth3 up
1067 $IP li set veth2 netns $ns2 up
1068 $IP li set veth4 netns $ns2 up
1069 ip -netns $ns2 li add dummy1 type dummy
1070 ip -netns $ns2 li set dummy1 up
1072 $IP -6 addr add 2001:db8:101::1/64 dev veth1 nodad
1073 $IP -6 addr add 2001:db8:103::1/64 dev veth3 nodad
1077 ip -netns $ns2 -6 addr add 2001:db8:101::2/64 dev veth2 nodad
1078 ip -netns $ns2 -6 addr add 2001:db8:103::2/64 dev veth4 nodad
1079 ip -netns $ns2 -6 addr add 2001:db8:104::1/64 dev dummy1 nodad
1081 ip -netns $ns2 addr add 172.16.101.2/24 dev veth2
1082 ip -netns $ns2 addr add 172.16.103.2/24 dev veth4
1083 ip -netns $ns2 addr add 172.16.104.1/24 dev dummy1
1088 # assumption is that basic add of a single path route works
1095 echo "IPv6 route add / append tests"
1097 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1099 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2"
1100 log_test $? 2 "Attempt to add duplicate route - gw"
1102 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1104 run_cmd "$IP -6 ro add 2001:db8:104::/64 dev veth3"
1105 log_test $? 2 "Attempt to add duplicate route - dev only"
1107 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1109 run_cmd "$IP -6 ro add unreachable 2001:db8:104::/64"
1110 log_test $? 2 "Attempt to add duplicate route - reject route"
1112 # route append with same prefix adds a new route
1113 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
1115 run_cmd "$IP -6 ro append 2001:db8:104::/64 via 2001:db8:103::2"
1117 log_test $? 0 "Append nexthop to existing route - gw"
1122 log_test $? 0 "Add multipath route"
1125 run_cmd "$IP -6 ro add 2001:db8:104::/64 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
1126 log_test $? 2 "Attempt to add duplicate multipath route"
1128 # insert of a second route without append but different metric
1130 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2 metric 512"
1132 if [ $rc -eq 0 ]; then
1133 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::3 metric 256"
1136 log_test $rc 0 "Route add with different metrics"
1138 run_cmd "$IP -6 ro del 2001:db8:104::/64 metric 512"
1140 if [ $rc -eq 0 ]; then
1144 log_test $rc 0 "Route delete with metric"
1152 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:103::2"
1159 …run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103:…
1166 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:103::2"
1170 # route replace fails - invalid nexthop
1172 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:104::2"
1173 if [ $? -eq 0 ]; then
1182 # replace non-existent route
1183 # - note use of change versus replace since ip adds NLM_F_CREATE
1186 run_cmd "$IP -6 ro change 2001:db8:105::/64 via 2001:db8:101::2"
1187 log_test $? 2 "Single path - replace of non-existent route"
1194 …run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103:…
1200 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:101::3"
1206 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3"
1210 # multipath with dev-only
1212 run_cmd "$IP -6 ro replace 2001:db8:104::/64 dev veth1"
1214 log_test $? 0 "Multipath with dev-only"
1216 # route replace fails - invalid nexthop 1
1218 …run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:111::3 nexthop via 2001:db8:103:…
1220 log_test $? 0 "Multipath - invalid first nexthop"
1222 # route replace fails - invalid nexthop 2
1224 …run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:113:…
1226 log_test $? 0 "Multipath - invalid second nexthop"
1228 # multipath non-existent route
1230 …run_cmd "$IP -6 ro change 2001:db8:105::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::…
1231 log_test $? 2 "Multipath - replace of non-existent route"
1237 echo "IPv6 route replace tests"
1246 echo "IPv6 route with dsfield tests"
1248 run_cmd "$IP -6 route flush 2001:db8:102::/64"
1251 run_cmd "$IP -6 route add 2001:db8:102::/64 dsfield 0x04 via 2001:db8:101::2"
1252 log_test $? 2 "Reject route with dsfield"
1268 ip addr help 2>&1 | grep -q metric
1269 if [ $? -ne 0 ]; then
1282 echo "IPv6 prefix route tests"
1288 set -e
1291 $IP li set dummy1 up
1292 $IP li set dummy2 up
1295 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64"
1296 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64"
1302 set -e
1303 run_cmd "$IP -6 addr flush dev dummy1"
1304 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64 metric 257"
1310 set -e
1311 run_cmd "$IP -6 addr flush dev dummy2"
1312 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64 metric 258"
1318 run_cmd "$IP -6 addr del dev dummy1 2001:db8:104::1/64 metric 257"
1320 if [ $rc -eq 0 ]; then
1326 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::2/64 metric 259"
1328 if [ $rc -eq 0 ]; then
1334 # verify prefix route removed on down
1335 run_cmd "ip netns exec $ns1 sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1"
1338 if [ $rc -eq 0 ]; then
1339 out=$($IP -6 ro ls match 2001:db8:104::/64)
1343 log_test $rc 0 "Prefix route removed on link down"
1345 # verify prefix route re-inserted with assigned metric
1346 run_cmd "$IP li set dev dummy2 up"
1348 if [ $rc -eq 0 ]; then
1352 log_test $rc 0 "Prefix route with metric on link up"
1355 set -e
1356 run_cmd "$IP -6 addr flush dev dummy2"
1357 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::1 peer 2001:db8:104::2 metric 260"
1361 log_test $? 0 "Set metric with peer route on local side"
1363 log_test $? 0 "Set metric with peer route on peer side"
1365 set -e
1366 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::1 peer 2001:db8:104::3 metric 261"
1391 run_cmd "$IP -6 ro add 2001:db8:111::/64 via 2001:db8:101::2 mtu 1400"
1393 if [ $rc -eq 0 ]; then
1397 log_test $rc 0 "Single path route with mtu metric"
1403 run_cmd "$IP -6 ro add 2001:db8:112::/64 via 2001:db8:101::2 mtu 1400"
1404 run_cmd "$IP -6 ro append 2001:db8:112::/64 via 2001:db8:103::2"
1406 if [ $rc -eq 0 ]; then
1410 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on first"
1412 # second route is coalesced to first to make a multipath route.
1414 run_cmd "$IP -6 ro add 2001:db8:113::/64 via 2001:db8:101::2"
1415 run_cmd "$IP -6 ro append 2001:db8:113::/64 via 2001:db8:103::2 mtu 1400"
1417 if [ $rc -eq 0 ]; then
1421 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on 2nd"
1423 run_cmd "$IP -6 ro del 2001:db8:113::/64 via 2001:db8:101::2"
1424 if [ $? -eq 0 ]; then
1432 …run_cmd "$IP -6 ro add 2001:db8:115::/64 mtu 1400 nexthop via 2001:db8:101::2 nexthop via 2001:db8…
1434 if [ $rc -eq 0 ]; then
1438 log_test $rc 0 "Multipath route with mtu metric"
1440 $IP -6 ro add 2001:db8:104::/64 via 2001:db8:101::2 mtu 1300
1441 run_cmd "ip netns exec $ns1 ${ping6} -w1 -c1 -s 1500 2001:db8:104::1"
1442 log_test $? 0 "Using route with mtu metric"
1444 run_cmd "$IP -6 ro add 2001:db8:114::/64 via 2001:db8:101::2 congctl lock foo"
1450 # add route for a prefix, flushing any existing routes first
1465 [ $? -ne 0 ] && exit 1
1468 if [ -n "$out" ]; then
1474 if [ $? -ne 0 ]; then
1475 echo "Failed to add initial route for test."
1480 # add initial route - used in replace route tests
1492 set -- $expected
1500 # assumption is that basic add of a single path route works
1507 echo "IPv4 route add / append tests"
1509 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1512 log_test $? 2 "Attempt to add duplicate route - gw"
1514 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1517 log_test $? 2 "Attempt to add duplicate route - dev only"
1519 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1522 log_test $? 2 "Attempt to add duplicate route - reject route"
1525 # - adds a new route; does NOT convert existing route to ECMP
1531 # route append with same prefix adds a new route
1532 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
1536 log_test $? 0 "Append nexthop to existing route - gw"
1541 log_test $? 0 "Append nexthop to existing route - dev only"
1546 log_test $? 0 "Append nexthop to existing route - reject route"
1552 log_test $? 0 "Append nexthop to existing reject route - gw"
1558 log_test $? 0 "Append nexthop to existing reject route - dev only"
1563 log_test $? 0 "add multipath route"
1567 log_test $? 2 "Attempt to add duplicate multipath route"
1569 # insert of a second route without append but different metric
1573 if [ $rc -eq 0 ]; then
1577 log_test $rc 0 "Route add with different metrics"
1581 if [ $rc -eq 0 ]; then
1585 log_test $rc 0 "Route delete with metric"
1609 log_test $? 0 "Single path with reject route"
1618 # route replace fails - invalid nexthop
1621 if [ $? -eq 0 ]; then
1630 # replace non-existent route
1631 # - note use of change versus replace since ip adds NLM_F_CREATE
1635 log_test $? 2 "Single path - replace of non-existent route"
1662 log_test $? 0 "Multipath with reject route"
1664 # route replace fails - invalid nexthop 1
1668 log_test $? 0 "Multipath - invalid first nexthop"
1670 # route replace fails - invalid nexthop 2
1674 log_test $? 0 "Multipath - invalid second nexthop"
1676 # multipath non-existent route
1679 log_test $? 2 "Multipath - replace of non-existent route"
1685 echo "IPv4 route replace tests"
1691 # checks that cached input route on VRF port is deleted
1696 run_cmd "setup_ns test-ns"
1697 run_cmd "ip link add veth-outside type veth peer name veth-inside"
1698 run_cmd "ip link add vrf-100 type vrf table 1100"
1699 run_cmd "ip link set veth-outside master vrf-100"
1700 run_cmd "ip link set veth-inside netns $test-ns"
1701 run_cmd "ip link set veth-outside up"
1702 run_cmd "ip link set vrf-100 up"
1703 run_cmd "ip route add 10.1.1.1/32 dev veth-outside table 1100"
1704 run_cmd "ip netns exec $test-ns ip link set veth-inside up"
1705 run_cmd "ip netns exec $test-ns ip addr add 10.1.1.1/32 dev veth-inside"
1706 run_cmd "ip netns exec $test-ns ip route add 10.0.0.1/32 dev veth-inside"
1707 run_cmd "ip netns exec $test-ns ip route add default via 10.0.0.1"
1708 run_cmd "ip netns exec $test-ns ping 10.0.0.1 -c 1 -i 1"
1709 run_cmd "ip link delete vrf-100"
1712 log_test $? 0 "Cached route removed from VRF port device"
1718 echo "IPv4 route with dsfield tests"
1720 run_cmd "$IP route flush 172.16.102.0/24"
1723 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x01 via 172.16.101.2"
1724 log_test $? 2 "Reject route with dsfield 0x01"
1726 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x02 via 172.16.101.2"
1727 log_test $? 2 "Reject route with dsfield 0x02"
1729 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x03 via 172.16.101.2"
1730 log_test $? 2 "Reject route with dsfield 0x03"
1732 # A generic route that doesn't take DSCP into account
1733 run_cmd "$IP route add 172.16.102.0/24 via 172.16.101.2"
1735 # A more specific route for DSCP 0x10
1736 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x10 via 172.16.103.2"
1738 # DSCP 0x10 should match the specific route, no matter the ECN bits
1739 $IP route get fibmatch 172.16.102.1 dsfield 0x10 | \
1740 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
1741 log_test $? 0 "IPv4 route with DSCP and ECN:Not-ECT"
1743 $IP route get fibmatch 172.16.102.1 dsfield 0x11 | \
1744 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
1745 log_test $? 0 "IPv4 route with DSCP and ECN:ECT(1)"
1747 $IP route get fibmatch 172.16.102.1 dsfield 0x12 | \
1748 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
1749 log_test $? 0 "IPv4 route with DSCP and ECN:ECT(0)"
1751 $IP route get fibmatch 172.16.102.1 dsfield 0x13 | \
1752 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
1753 log_test $? 0 "IPv4 route with DSCP and ECN:CE"
1755 # Unknown DSCP should match the generic route, no matter the ECN bits
1756 $IP route get fibmatch 172.16.102.1 dsfield 0x14 | \
1757 grep -q "172.16.102.0/24 via 172.16.101.2"
1758 log_test $? 0 "IPv4 route with unknown DSCP and ECN:Not-ECT"
1760 $IP route get fibmatch 172.16.102.1 dsfield 0x15 | \
1761 grep -q "172.16.102.0/24 via 172.16.101.2"
1762 log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(1)"
1764 $IP route get fibmatch 172.16.102.1 dsfield 0x16 | \
1765 grep -q "172.16.102.0/24 via 172.16.101.2"
1766 log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(0)"
1768 $IP route get fibmatch 172.16.102.1 dsfield 0x17 | \
1769 grep -q "172.16.102.0/24 via 172.16.101.2"
1770 log_test $? 0 "IPv4 route with unknown DSCP and ECN:CE"
1772 # Null DSCP should match the generic route, no matter the ECN bits
1773 $IP route get fibmatch 172.16.102.1 dsfield 0x00 | \
1774 grep -q "172.16.102.0/24 via 172.16.101.2"
1775 log_test $? 0 "IPv4 route with no DSCP and ECN:Not-ECT"
1777 $IP route get fibmatch 172.16.102.1 dsfield 0x01 | \
1778 grep -q "172.16.102.0/24 via 172.16.101.2"
1779 log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(1)"
1781 $IP route get fibmatch 172.16.102.1 dsfield 0x02 | \
1782 grep -q "172.16.102.0/24 via 172.16.101.2"
1783 log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(0)"
1785 $IP route get fibmatch 172.16.102.1 dsfield 0x03 | \
1786 grep -q "172.16.102.0/24 via 172.16.101.2"
1787 log_test $? 0 "IPv4 route with no DSCP and ECN:CE"
1807 echo "IPv4 prefix route tests"
1813 set -e
1816 $IP li set dummy1 up
1817 $IP li set dummy2 up
1827 set -e
1835 set -e
1845 if [ $rc -eq 0 ]; then
1853 if [ $rc -eq 0 ]; then
1859 # verify prefix route removed on down
1862 if [ $rc -eq 0 ]; then
1867 log_test $rc 0 "Prefix route removed on link down"
1869 # verify prefix route re-inserted with assigned metric
1870 run_cmd "$IP li set dev dummy2 up"
1872 if [ $rc -eq 0 ]; then
1876 log_test $rc 0 "Prefix route with metric on link up"
1883 if [ $rc -eq 0 ]; then
1892 if [ $rc -eq 0 ]; then
1896 log_test $rc 0 "Set metric of address with peer route"
1900 if [ $rc -eq 0 ]; then
1904 log_test $rc 0 "Modify metric and peer address for peer route"
1916 echo "IPv4 route add / append tests"
1922 if [ $rc -eq 0 ]; then
1926 log_test $rc 0 "Single path route with mtu metric"
1931 if [ $rc -eq 0 ]; then
1935 log_test $rc 0 "Multipath route with mtu metric"
1938 run_cmd "ip netns exec $ns1 ping -w1 -c1 -s 1500 172.16.104.1"
1939 log_test $? 0 "Using route with mtu metric"
1950 echo "IPv4 delete address route tests"
1954 set -e
1956 $IP li set dummy1 up
1958 $IP li set dummy2 up
1960 $IP li set red up
1971 $IP route add 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
1972 $IP route add 172.16.106.0/24 dev lo src 172.16.104.12
1973 $IP route add table 0 172.16.107.0/24 via 172.16.104.2 src 172.16.104.13
1974 $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
1975 $IP route add vrf red 172.16.106.0/24 dev lo src 172.16.104.12
1978 # removing address from device in vrf should only remove route from vrf table
1982 $IP ro ls vrf red | grep -q 172.16.105.0/24
1983 log_test $? 1 "Route removed from VRF when source address deleted"
1985 $IP ro ls | grep -q 172.16.105.0/24
1986 log_test $? 0 "Route in default VRF not removed"
1989 $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
1992 $IP ro ls | grep -q 172.16.105.0/24
1993 log_test $? 1 "Route removed in default VRF when source address deleted"
1995 $IP ro ls vrf red | grep -q 172.16.105.0/24
1996 log_test $? 0 "Route in VRF is not removed by address delete"
1998 # removing address from device in vrf should only remove route from vrf
2003 $IP ro ls vrf red | grep -q 172.16.106.0/24
2004 log_test $? 1 "Route removed from VRF when source address deleted"
2006 $IP ro ls | grep -q 172.16.106.0/24
2007 log_test $? 0 "Route in default VRF not removed"
2010 $IP route add vrf red 172.16.106.0/24 dev lo src 172.16.104.12
2013 $IP ro ls | grep -q 172.16.106.0/24
2014 log_test $? 1 "Route removed in default VRF when source address deleted"
2016 $IP ro ls vrf red | grep -q 172.16.106.0/24
2017 log_test $? 0 "Route in VRF is not removed by address delete"
2019 # removing address from device in default vrf should remove route from
2020 # the default vrf even when route was inserted with a table ID of 0.
2024 $IP ro ls | grep -q 172.16.107.0/24
2025 log_test $? 1 "Route removed in default VRF when source address deleted"
2035 echo "IPv6 delete address route tests"
2039 set -e
2041 $IP li add dummy${i} up type dummy
2044 $IP li add red up type vrf table 1111
2073 $IP route add 2001:db8:110::/64 dev dummy3 src 2001:db8:101::10
2075 $IP route add 2001:db8:111::/64 dev dummy3 src 2001:db8:101::11
2077 $IP route add vrf red 2001:db8:110::/64 dev dummy6 src 2001:db8:101::10
2079 $IP route add vrf red 2001:db8:111::/64 dev dummy6 src 2001:db8:101::11
2081 $IP route add 2001:db8:112::/64 dev dummy3 src 2001:db8:101::12
2082 $IP route add vrf red 2001:db8:112::/64 dev dummy6 src 2001:db8:101::12
2084 $IP route add 2001:db8:113::/64 dev lo src 2001:db8:101::13
2085 $IP route add vrf red 2001:db8:113::/64 dev lo src 2001:db8:101::13
2087 $IP route add table 0 2001:db8:115::/64 via 2001:db8:101::2 src 2001:db8:101::15
2088 # Link local source route
2089 $IP route add 2001:db8:116::/64 dev dummy2 src fe80::1
2090 $IP route add 2001:db8:117::/64 dev dummy3 src fe80::1
2096 $IP -6 route show | grep -q "src 2001:db8:101::10 "
2102 $IP -6 route show | grep -q "src 2001:db8:101::11 "
2106 $IP -6 route show | grep -q "src 2001:db8:101::11 "
2112 $IP -6 route show vrf red | grep -q "src 2001:db8:101::10 "
2118 $IP -6 route show vrf red | grep -q "src 2001:db8:101::11 "
2122 $IP -6 route show vrf red | grep -q "src 2001:db8:101::11 "
2128 $IP -6 route show vrf red | grep -q "src 2001:db8:101::12 "
2130 $IP -6 route show | grep -q " src 2001:db8:101::12 "
2134 $IP route replace vrf red 2001:db8:112::/64 dev dummy6 src 2001:db8:101::12
2136 $IP -6 route show vrf red | grep -q "src 2001:db8:101::12 "
2138 $IP -6 route show | grep -q " src 2001:db8:101::12 "
2144 $IP -6 route show vrf red | grep -q "src 2001:db8:101::13 "
2146 $IP -6 route show | grep -q "src 2001:db8:101::13 "
2151 $IP -6 route show vrf red | grep -q "src 2001:db8:101::13 "
2153 $IP -6 route show | grep -q "src 2001:db8:101::13 "
2159 $IP -6 route show | grep -q "src 2001:db8:101::15"
2162 echo " Link local source route"
2164 $IP -6 route show | grep -q "2001:db8:116::/64 dev dummy2 src fe80::1"
2167 $IP -6 route show | grep -q "2001:db8:116::/64 dev dummy2 src fe80::1"
2169 $IP -6 route show | grep -q "2001:db8:117::/64 dev dummy3 src fe80::1"
2173 $IP -6 route show | grep -q "2001:db8:117::/64 dev dummy3 src fe80::1"
2187 echo "IPv4 route with IPv6 gateway tests"
2193 # single path route
2197 log_test $rc 0 "Single path route with IPv6 gateway"
2198 if [ $rc -eq 0 ]; then
2202 run_cmd "ip netns exec $ns1 ping -w1 -c1 172.16.104.1"
2203 log_test $rc 0 "Single path route with IPv6 gateway - ping"
2207 log_test $rc 0 "Single path route delete"
2208 if [ $rc -eq 0 ]; then
2213 # multipath - v6 then v4
2217 log_test $rc 0 "Multipath route add - v6 nexthop then v4"
2218 if [ $rc -eq 0 ]; then
2223 log_test $? 2 " Multipath route delete - nexthops in wrong order"
2226 log_test $? 0 " Multipath route delete exact match"
2229 # multipath - v4 then v6
2233 log_test $rc 0 "Multipath route add - v4 nexthop then v6"
2234 if [ $rc -eq 0 ]; then
2239 log_test $? 2 " Multipath route delete - nexthops in wrong order"
2242 log_test $? 0 " Multipath route delete exact match"
2249 if [ ! -x "$(command -v socat)" ]; then
2259 iptables -t mangle -L OUTPUT &> /dev/null
2260 if [ $? -ne 0 ]; then
2270 ip6tables -t mangle -L OUTPUT &> /dev/null
2271 if [ $? -ne 0 ]; then
2293 ip netns exec $ns2 socat UDP4-LISTEN:54321,fork $tmp_file &
2295 # Add a FIB rule and a route that will direct our connection to the
2298 $IP route add table 123 172.16.101.0/24 dev veth1
2300 # Add an unreachable route to the main table that will block our
2302 $IP route add unreachable 172.16.101.2/32
2311 $NS_EXEC iptables -t mangle -A OUTPUT -j MARK --set-mark 1
2314 log_test $? 0 " Connection with correct parameters - mangling"
2318 $NS_EXEC iptables -t mangle -D OUTPUT -j MARK --set-mark 1
2321 log_test $? 0 " Connection with correct parameters - no mangling"
2324 [[ $(cat $tmp_file | wc -l) -eq 3 ]]
2325 log_test $? 0 " Connection check - server side"
2327 $IP route del unreachable 172.16.101.2/32
2328 $IP route del table 123 172.16.101.0/24 dev veth1
2351 ip netns exec $ns2 socat UDP6-LISTEN:54321,fork $tmp_file &
2353 # Add a FIB rule and a route that will direct our connection to the
2355 $IP -6 rule add pref 100 ipproto udp sport 12345 dport 54321 table 123
2356 $IP -6 route add table 123 2001:db8:101::/64 dev veth1
2358 # Add an unreachable route to the main table that will block our
2360 $IP -6 route add unreachable 2001:db8:101::2/128
2369 $NS_EXEC ip6tables -t mangle -A OUTPUT -j MARK --set-mark 1
2372 log_test $? 0 " Connection with correct parameters - mangling"
2376 $NS_EXEC ip6tables -t mangle -D OUTPUT -j MARK --set-mark 1
2379 log_test $? 0 " Connection with correct parameters - no mangling"
2382 [[ $(cat $tmp_file | wc -l) -eq 3 ]]
2383 log_test $? 0 " Connection check - server side"
2385 $IP -6 route del unreachable 2001:db8:101::2/128
2386 $IP -6 route del table 123 2001:db8:101::/64 dev veth1
2387 $IP -6 rule del pref 100
2397 ip neigh help 2>&1 | grep -q 'ip neigh get'
2398 if [ $? -ne 0 ]; then
2417 set -e
2452 if [ ! -x "$(command -v mausezahn)" ]; then
2457 if [ ! -x "$(command -v jq)" ]; then
2462 if [ ! -x "$(command -v bc)" ]; then
2467 if [ ! -x "$(command -v perf)" ]; then
2472 perf list fib:* | grep -q fib_table_lookup
2473 if [ $? -ne 0 ]; then
2478 perf list fib6:* | grep -q fib6_table_lookup
2479 if [ $? -ne 0 ]; then
2494 ip -n $ns -j -s link show dev $dev \
2503 local count=$(tail -n 1 $file | jq '.["counter-value"] | tonumber | floor')
2504 local ratio=$(echo "scale=2; $count / $expected" | bc -l)
2506 [[ $res -eq 1 ]]
2507 log_test $? 0 "Multipath route hit ratio ($ratio)"
2519 set -e
2520 run_cmd "ip netns exec $ns1 ethtool -K veth1 tcp-segmentation-offload off"
2522 run_cmd "ip netns exec $ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
2523 run_cmd "ip netns exec $ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
2524 run_cmd "ip netns exec $ns2 ethtool -K veth2 generic-receive-offload on"
2525 run_cmd "ip -n $ns2 link add name nh1 up type dummy"
2526 run_cmd "ip -n $ns2 link add name nh2 up type dummy"
2527 run_cmd "ip -n $ns2 address add 172.16.201.1/24 dev nh1"
2528 run_cmd "ip -n $ns2 address add 172.16.202.1/24 dev nh2"
2529 run_cmd "ip -n $ns2 neigh add 172.16.201.2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
2530 run_cmd "ip -n $ns2 neigh add 172.16.202.2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
2531 run_cmd "ip -n $ns2 route add 203.0.113.0/24
2533 run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.fib_multipath_hash_policy=1"
2534 run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.conf.veth2.rp_filter=0"
2535 run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.rp_filter=0"
2536 run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.conf.default.rp_filter=0"
2539 local dmac=$(ip -n $ns2 -j link show dev veth2 | jq -r '.[]["address"]')
2541 local cmd="ip netns exec $ns1 mausezahn veth1 -a own -b $dmac
2542 -A 172.16.101.1 -B 203.0.113.1 -t udp 'sp=12345,dp=0-65535' -q"
2544 # Packets forwarded in a list using a multipath route must not reuse a
2549 run_cmd "perf stat -a -e fib:fib_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
2551 local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
2567 set -e
2568 run_cmd "ip netns exec $ns1 ethtool -K veth1 tcp-segmentation-offload off"
2570 run_cmd "ip netns exec $ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
2571 run_cmd "ip netns exec $ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
2572 run_cmd "ip netns exec $ns2 ethtool -K veth2 generic-receive-offload on"
2573 run_cmd "ip -n $ns2 link add name nh1 up type dummy"
2574 run_cmd "ip -n $ns2 link add name nh2 up type dummy"
2575 run_cmd "ip -n $ns2 -6 address add 2001:db8:201::1/64 dev nh1"
2576 run_cmd "ip -n $ns2 -6 address add 2001:db8:202::1/64 dev nh2"
2577 run_cmd "ip -n $ns2 -6 neigh add 2001:db8:201::2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
2578 run_cmd "ip -n $ns2 -6 neigh add 2001:db8:202::2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
2579 run_cmd "ip -n $ns2 -6 route add 2001:db8:301::/64
2581 run_cmd "ip netns exec $ns2 sysctl -qw net.ipv6.fib_multipath_hash_policy=1"
2584 local dmac=$(ip -n $ns2 -j link show dev veth2 | jq -r '.[]["address"]')
2586 local cmd="ip netns exec $ns1 mausezahn -6 veth1 -a own -b $dmac
2587 -A 2001:db8:101::1 -B 2001:db8:301::1 -t udp 'sp=12345,dp=0-65535' -q"
2589 # Packets forwarded in a list using a multipath route must not reuse a
2594 run_cmd "perf stat -a -e fib6:fib6_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
2596 local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
2611 -t <test> Test(s) to run (default: all)
2613 -p Pause on fail
2614 -P Pause after each test before cleanup
2615 -v verbose mode (show commands and output)
2641 if [ "$(id -u)" -ne 0 ];then
2646 if [ ! -x "$(command -v ip)" ]; then
2651 ip route help 2>&1 | grep -q fibmatch
2652 if [ $? -ne 0 ]; then