]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - tools/testing/selftests/net/fib_tests.sh
selftests: net: fib_tests: remove duplicate log test
[mirror_ubuntu-focal-kernel.git] / tools / testing / selftests / net / fib_tests.sh
CommitLineData
607bd2e5
IS
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This test is for checking IPv4 and IPv6 FIB behavior in response to
5# different events.
6
7ret=0
57aefc7c
SKSO
8# Kselftest framework requirement - SKIP code is 4.
9ksft_skip=4
607bd2e5 10
d69faad7 11# all tests in this script. Can be overridden with -t option
ca7a03c4 12TESTS="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"
228ddb33 13
1c7447b4
DA
14VERBOSE=0
15PAUSE_ON_FAIL=no
7df15e6c 16PAUSE=no
a0e11da7 17IP="ip -netns ns1"
adb701d6 18NS_EXEC="ip netns exec ns1"
607bd2e5 19
0360894a
DA
20which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
21
1056691b 22log_test()
607bd2e5 23{
1056691b
DA
24 local rc=$1
25 local expected=$2
26 local msg="$3"
27
28 if [ ${rc} -eq ${expected} ]; then
654d3a78 29 printf " TEST: %-60s [ OK ]\n" "${msg}"
37ce42c1 30 nsuccess=$((nsuccess+1))
1056691b 31 else
607bd2e5 32 ret=1
37ce42c1 33 nfail=$((nfail+1))
654d3a78 34 printf " TEST: %-60s [FAIL]\n" "${msg}"
1056691b
DA
35 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
36 echo
37 echo "hit enter to continue, 'q' to quit"
38 read a
39 [ "$a" = "q" ] && exit 1
40 fi
607bd2e5 41 fi
7df15e6c
DA
42
43 if [ "${PAUSE}" = "yes" ]; then
44 echo
45 echo "hit enter to continue, 'q' to quit"
46 read a
47 [ "$a" = "q" ] && exit 1
48 fi
607bd2e5
IS
49}
50
ee395a5e 51setup()
607bd2e5 52{
ee395a5e 53 set -e
a0e11da7 54 ip netns add ns1
228ddb33 55 ip netns set ns1 auto
171a4871 56 $IP link set dev lo up
a0e11da7
DA
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
ee395a5e 59
171a4871
DA
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
ee395a5e
DA
64 set +e
65
66}
607bd2e5 67
ee395a5e
DA
68cleanup()
69{
171a4871 70 $IP link del dev dummy0 &> /dev/null
a0e11da7
DA
71 ip netns del ns1
72 ip netns del ns2 &> /dev/null
607bd2e5
IS
73}
74
654d3a78
DA
75get_linklocal()
76{
77 local dev=$1
78 local addr
79
80 addr=$($IP -6 -br addr show dev ${dev} | \
81 awk '{
82 for (i = 3; i <= NF; ++i) {
83 if ($i ~ /^fe80/)
84 print $i
85 }
86 }'
87 )
88 addr=${addr/\/*}
89
90 [ -z "$addr" ] && return 1
91
92 echo $addr
93
94 return 0
95}
96
607bd2e5
IS
97fib_unreg_unicast_test()
98{
1056691b
DA
99 echo
100 echo "Single path route test"
607bd2e5 101
ee395a5e 102 setup
607bd2e5 103
1056691b 104 echo " Start point"
171a4871 105 $IP route get fibmatch 198.51.100.2 &> /dev/null
1056691b 106 log_test $? 0 "IPv4 fibmatch"
171a4871 107 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
1056691b 108 log_test $? 0 "IPv6 fibmatch"
607bd2e5 109
1056691b 110 set -e
171a4871 111 $IP link del dev dummy0
1056691b 112 set +e
607bd2e5 113
1056691b 114 echo " Nexthop device deleted"
171a4871 115 $IP route get fibmatch 198.51.100.2 &> /dev/null
1056691b 116 log_test $? 2 "IPv4 fibmatch - no route"
171a4871 117 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
1056691b 118 log_test $? 2 "IPv6 fibmatch - no route"
607bd2e5 119
ee395a5e 120 cleanup
607bd2e5
IS
121}
122
123fib_unreg_multipath_test()
124{
607bd2e5 125
1056691b
DA
126 echo
127 echo "Multipath route test"
128
ee395a5e 129 setup
607bd2e5 130
ee395a5e 131 set -e
171a4871
DA
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
607bd2e5 136
171a4871 137 $IP route add 203.0.113.0/24 \
607bd2e5
IS
138 nexthop via 198.51.100.2 dev dummy0 \
139 nexthop via 192.0.2.2 dev dummy1
171a4871 140 $IP -6 route add 2001:db8:3::/64 \
607bd2e5
IS
141 nexthop via 2001:db8:1::2 dev dummy0 \
142 nexthop via 2001:db8:2::2 dev dummy1
1056691b 143 set +e
607bd2e5 144
1056691b 145 echo " Start point"
171a4871 146 $IP route get fibmatch 203.0.113.1 &> /dev/null
1056691b 147 log_test $? 0 "IPv4 fibmatch"
171a4871 148 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
1056691b 149 log_test $? 0 "IPv6 fibmatch"
607bd2e5 150
1056691b 151 set -e
171a4871 152 $IP link del dev dummy0
1056691b 153 set +e
607bd2e5 154
1056691b 155 echo " One nexthop device deleted"
171a4871 156 $IP route get fibmatch 203.0.113.1 &> /dev/null
1056691b
DA
157 log_test $? 2 "IPv4 - multipath route removed on delete"
158
171a4871 159 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
607bd2e5 160 # In IPv6 we do not flush the entire multipath route.
1056691b 161 log_test $? 0 "IPv6 - multipath down to single path"
607bd2e5 162
1056691b 163 set -e
171a4871 164 $IP link del dev dummy1
1056691b 165 set +e
607bd2e5 166
1056691b 167 echo " Second nexthop device deleted"
171a4871 168 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
1056691b 169 log_test $? 2 "IPv6 - no route"
607bd2e5 170
ee395a5e 171 cleanup
607bd2e5
IS
172}
173
174fib_unreg_test()
175{
607bd2e5
IS
176 fib_unreg_unicast_test
177 fib_unreg_multipath_test
178}
179
5adb7683
IS
180fib_down_unicast_test()
181{
1056691b
DA
182 echo
183 echo "Single path, admin down"
5adb7683 184
ee395a5e 185 setup
5adb7683 186
1056691b 187 echo " Start point"
171a4871 188 $IP route get fibmatch 198.51.100.2 &> /dev/null
1056691b 189 log_test $? 0 "IPv4 fibmatch"
171a4871 190 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
1056691b 191 log_test $? 0 "IPv6 fibmatch"
5adb7683 192
1056691b 193 set -e
171a4871 194 $IP link set dev dummy0 down
1056691b 195 set +e
5adb7683 196
1056691b 197 echo " Route deleted on down"
171a4871 198 $IP route get fibmatch 198.51.100.2 &> /dev/null
1056691b 199 log_test $? 2 "IPv4 fibmatch"
171a4871 200 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
1056691b 201 log_test $? 2 "IPv6 fibmatch"
5adb7683 202
ee395a5e 203 cleanup
5adb7683
IS
204}
205
206fib_down_multipath_test_do()
207{
208 local down_dev=$1
209 local up_dev=$2
210
171a4871 211 $IP route get fibmatch 203.0.113.1 \
5adb7683 212 oif $down_dev &> /dev/null
1056691b 213 log_test $? 2 "IPv4 fibmatch on down device"
171a4871 214 $IP -6 route get fibmatch 2001:db8:3::1 \
5adb7683 215 oif $down_dev &> /dev/null
1056691b 216 log_test $? 2 "IPv6 fibmatch on down device"
5adb7683 217
171a4871 218 $IP route get fibmatch 203.0.113.1 \
5adb7683 219 oif $up_dev &> /dev/null
1056691b 220 log_test $? 0 "IPv4 fibmatch on up device"
171a4871 221 $IP -6 route get fibmatch 2001:db8:3::1 \
5adb7683 222 oif $up_dev &> /dev/null
1056691b 223 log_test $? 0 "IPv6 fibmatch on up device"
5adb7683 224
171a4871 225 $IP route get fibmatch 203.0.113.1 | \
5adb7683 226 grep $down_dev | grep -q "dead linkdown"
1056691b 227 log_test $? 0 "IPv4 flags on down device"
171a4871 228 $IP -6 route get fibmatch 2001:db8:3::1 | \
5adb7683 229 grep $down_dev | grep -q "dead linkdown"
1056691b 230 log_test $? 0 "IPv6 flags on down device"
5adb7683 231
171a4871 232 $IP route get fibmatch 203.0.113.1 | \
5adb7683 233 grep $up_dev | grep -q "dead linkdown"
1056691b 234 log_test $? 1 "IPv4 flags on up device"
171a4871 235 $IP -6 route get fibmatch 2001:db8:3::1 | \
5adb7683 236 grep $up_dev | grep -q "dead linkdown"
1056691b 237 log_test $? 1 "IPv6 flags on up device"
5adb7683
IS
238}
239
240fib_down_multipath_test()
241{
1056691b
DA
242 echo
243 echo "Admin down multipath"
5adb7683 244
ee395a5e 245 setup
5adb7683 246
ee395a5e 247 set -e
171a4871
DA
248 $IP link add dummy1 type dummy
249 $IP link set dev dummy1 up
5adb7683 250
171a4871
DA
251 $IP address add 192.0.2.1/24 dev dummy1
252 $IP -6 address add 2001:db8:2::1/64 dev dummy1
5adb7683 253
171a4871 254 $IP route add 203.0.113.0/24 \
5adb7683
IS
255 nexthop via 198.51.100.2 dev dummy0 \
256 nexthop via 192.0.2.2 dev dummy1
171a4871 257 $IP -6 route add 2001:db8:3::/64 \
5adb7683
IS
258 nexthop via 2001:db8:1::2 dev dummy0 \
259 nexthop via 2001:db8:2::2 dev dummy1
1056691b 260 set +e
5adb7683 261
1056691b 262 echo " Verify start point"
171a4871 263 $IP route get fibmatch 203.0.113.1 &> /dev/null
1056691b
DA
264 log_test $? 0 "IPv4 fibmatch"
265
171a4871 266 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
1056691b 267 log_test $? 0 "IPv6 fibmatch"
5adb7683 268
1056691b 269 set -e
171a4871 270 $IP link set dev dummy0 down
1056691b 271 set +e
5adb7683 272
1056691b 273 echo " One device down, one up"
5adb7683
IS
274 fib_down_multipath_test_do "dummy0" "dummy1"
275
1056691b 276 set -e
171a4871
DA
277 $IP link set dev dummy0 up
278 $IP link set dev dummy1 down
1056691b 279 set +e
5adb7683 280
1056691b 281 echo " Other device down and up"
5adb7683
IS
282 fib_down_multipath_test_do "dummy1" "dummy0"
283
1056691b 284 set -e
171a4871 285 $IP link set dev dummy0 down
1056691b 286 set +e
5adb7683 287
1056691b 288 echo " Both devices down"
171a4871 289 $IP route get fibmatch 203.0.113.1 &> /dev/null
1056691b 290 log_test $? 2 "IPv4 fibmatch"
171a4871 291 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
1056691b 292 log_test $? 2 "IPv6 fibmatch"
5adb7683 293
171a4871 294 $IP link del dev dummy1
ee395a5e 295 cleanup
5adb7683
IS
296}
297
298fib_down_test()
299{
5adb7683
IS
300 fib_down_unicast_test
301 fib_down_multipath_test
302}
303
1056691b 304# Local routes should not be affected when carrier changes.
82e45b6f
IS
305fib_carrier_local_test()
306{
1056691b
DA
307 echo
308 echo "Local carrier tests - single path"
82e45b6f 309
ee395a5e 310 setup
82e45b6f 311
ee395a5e 312 set -e
171a4871 313 $IP link set dev dummy0 carrier on
1056691b 314 set +e
82e45b6f 315
1056691b 316 echo " Start point"
171a4871 317 $IP route get fibmatch 198.51.100.1 &> /dev/null
1056691b 318 log_test $? 0 "IPv4 fibmatch"
171a4871 319 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
1056691b 320 log_test $? 0 "IPv6 fibmatch"
82e45b6f 321
171a4871 322 $IP route get fibmatch 198.51.100.1 | \
82e45b6f 323 grep -q "linkdown"
1056691b 324 log_test $? 1 "IPv4 - no linkdown flag"
171a4871 325 $IP -6 route get fibmatch 2001:db8:1::1 | \
82e45b6f 326 grep -q "linkdown"
1056691b 327 log_test $? 1 "IPv6 - no linkdown flag"
82e45b6f 328
1056691b 329 set -e
171a4871 330 $IP link set dev dummy0 carrier off
e2ba732a 331 sleep 1
1056691b 332 set +e
82e45b6f 333
1056691b 334 echo " Carrier off on nexthop"
171a4871 335 $IP route get fibmatch 198.51.100.1 &> /dev/null
1056691b 336 log_test $? 0 "IPv4 fibmatch"
171a4871 337 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
1056691b 338 log_test $? 0 "IPv6 fibmatch"
82e45b6f 339
171a4871 340 $IP route get fibmatch 198.51.100.1 | \
82e45b6f 341 grep -q "linkdown"
1056691b 342 log_test $? 1 "IPv4 - linkdown flag set"
171a4871 343 $IP -6 route get fibmatch 2001:db8:1::1 | \
82e45b6f 344 grep -q "linkdown"
1056691b 345 log_test $? 1 "IPv6 - linkdown flag set"
82e45b6f 346
1056691b 347 set -e
171a4871
DA
348 $IP address add 192.0.2.1/24 dev dummy0
349 $IP -6 address add 2001:db8:2::1/64 dev dummy0
1056691b 350 set +e
82e45b6f 351
1056691b 352 echo " Route to local address with carrier down"
171a4871 353 $IP route get fibmatch 192.0.2.1 &> /dev/null
1056691b 354 log_test $? 0 "IPv4 fibmatch"
171a4871 355 $IP -6 route get fibmatch 2001:db8:2::1 &> /dev/null
1056691b 356 log_test $? 0 "IPv6 fibmatch"
82e45b6f 357
171a4871 358 $IP route get fibmatch 192.0.2.1 | \
82e45b6f 359 grep -q "linkdown"
1056691b 360 log_test $? 1 "IPv4 linkdown flag set"
171a4871 361 $IP -6 route get fibmatch 2001:db8:2::1 | \
82e45b6f 362 grep -q "linkdown"
1056691b 363 log_test $? 1 "IPv6 linkdown flag set"
82e45b6f 364
ee395a5e 365 cleanup
82e45b6f
IS
366}
367
368fib_carrier_unicast_test()
369{
370 ret=0
371
1056691b
DA
372 echo
373 echo "Single path route carrier test"
374
ee395a5e 375 setup
82e45b6f 376
1056691b 377 set -e
171a4871 378 $IP link set dev dummy0 carrier on
1056691b 379 set +e
82e45b6f 380
1056691b 381 echo " Start point"
171a4871 382 $IP route get fibmatch 198.51.100.2 &> /dev/null
1056691b 383 log_test $? 0 "IPv4 fibmatch"
171a4871 384 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
1056691b 385 log_test $? 0 "IPv6 fibmatch"
82e45b6f 386
171a4871 387 $IP route get fibmatch 198.51.100.2 | \
82e45b6f 388 grep -q "linkdown"
1056691b 389 log_test $? 1 "IPv4 no linkdown flag"
171a4871 390 $IP -6 route get fibmatch 2001:db8:1::2 | \
82e45b6f 391 grep -q "linkdown"
1056691b 392 log_test $? 1 "IPv6 no linkdown flag"
82e45b6f 393
1056691b 394 set -e
171a4871 395 $IP link set dev dummy0 carrier off
af548a27 396 sleep 1
1056691b 397 set +e
82e45b6f 398
1056691b 399 echo " Carrier down"
171a4871 400 $IP route get fibmatch 198.51.100.2 &> /dev/null
1056691b 401 log_test $? 0 "IPv4 fibmatch"
171a4871 402 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
1056691b 403 log_test $? 0 "IPv6 fibmatch"
82e45b6f 404
171a4871 405 $IP route get fibmatch 198.51.100.2 | \
82e45b6f 406 grep -q "linkdown"
1056691b 407 log_test $? 0 "IPv4 linkdown flag set"
171a4871 408 $IP -6 route get fibmatch 2001:db8:1::2 | \
82e45b6f 409 grep -q "linkdown"
1056691b 410 log_test $? 0 "IPv6 linkdown flag set"
82e45b6f 411
1056691b 412 set -e
171a4871
DA
413 $IP address add 192.0.2.1/24 dev dummy0
414 $IP -6 address add 2001:db8:2::1/64 dev dummy0
1056691b 415 set +e
82e45b6f 416
1056691b 417 echo " Second address added with carrier down"
171a4871 418 $IP route get fibmatch 192.0.2.2 &> /dev/null
1056691b 419 log_test $? 0 "IPv4 fibmatch"
171a4871 420 $IP -6 route get fibmatch 2001:db8:2::2 &> /dev/null
1056691b 421 log_test $? 0 "IPv6 fibmatch"
82e45b6f 422
171a4871 423 $IP route get fibmatch 192.0.2.2 | \
82e45b6f 424 grep -q "linkdown"
1056691b 425 log_test $? 0 "IPv4 linkdown flag set"
171a4871 426 $IP -6 route get fibmatch 2001:db8:2::2 | \
82e45b6f 427 grep -q "linkdown"
1056691b 428 log_test $? 0 "IPv6 linkdown flag set"
82e45b6f 429
ee395a5e 430 cleanup
82e45b6f
IS
431}
432
433fib_carrier_test()
434{
82e45b6f
IS
435 fib_carrier_local_test
436 fib_carrier_unicast_test
437}
438
adb701d6
CW
439fib_rp_filter_test()
440{
441 echo
442 echo "IPv4 rp_filter tests"
443
444 setup
445
446 set -e
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
8708be2e 452 $IP address add 192.0.2.1/24 dev dummy1
adb701d6
CW
453 $NS_EXEC sysctl -qw net.ipv4.conf.all.rp_filter=1
454 $NS_EXEC sysctl -qw net.ipv4.conf.all.accept_local=1
455 $NS_EXEC sysctl -qw net.ipv4.conf.all.route_localnet=1
456
457 $NS_EXEC tc qd add dev dummy1 parent root handle 1: fq_codel
458 $NS_EXEC tc filter add dev dummy1 parent 1: protocol arp basic action mirred egress redirect dev lo
459 $NS_EXEC tc filter add dev dummy1 parent 1: protocol ip basic action mirred egress redirect dev lo
460 set +e
461
462 run_cmd "ip netns exec ns1 ping -I dummy1 -w1 -c1 198.51.100.1"
463 log_test $? 0 "rp_filter passes local packets"
464
465 run_cmd "ip netns exec ns1 ping -I dummy1 -w1 -c1 127.0.0.1"
466 log_test $? 0 "rp_filter passes loopback packets"
467
468 cleanup
469}
470
654d3a78
DA
471################################################################################
472# Tests on nexthop spec
473
474# run 'ip route add' with given spec
475add_rt()
476{
477 local desc="$1"
478 local erc=$2
479 local vrf=$3
480 local pfx=$4
481 local gw=$5
482 local dev=$6
483 local cmd out rc
484
485 [ "$vrf" = "-" ] && vrf="default"
486 [ -n "$gw" ] && gw="via $gw"
487 [ -n "$dev" ] && dev="dev $dev"
488
489 cmd="$IP route add vrf $vrf $pfx $gw $dev"
490 if [ "$VERBOSE" = "1" ]; then
491 printf "\n COMMAND: $cmd\n"
492 fi
493
494 out=$(eval $cmd 2>&1)
495 rc=$?
496 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
497 echo " $out"
498 fi
499 log_test $rc $erc "$desc"
500}
501
502fib4_nexthop()
503{
504 echo
505 echo "IPv4 nexthop tests"
506
507 echo "<<< write me >>>"
508}
509
510fib6_nexthop()
511{
512 local lldummy=$(get_linklocal dummy0)
513 local llv1=$(get_linklocal dummy0)
514
515 if [ -z "$lldummy" ]; then
516 echo "Failed to get linklocal address for dummy0"
517 return 1
518 fi
519 if [ -z "$llv1" ]; then
520 echo "Failed to get linklocal address for veth1"
521 return 1
522 fi
523
524 echo
525 echo "IPv6 nexthop tests"
526
527 add_rt "Directly connected nexthop, unicast address" 0 \
528 - 2001:db8:101::/64 2001:db8:1::2
529 add_rt "Directly connected nexthop, unicast address with device" 0 \
530 - 2001:db8:102::/64 2001:db8:1::2 "dummy0"
531 add_rt "Gateway is linklocal address" 0 \
532 - 2001:db8:103::1/64 $llv1 "veth0"
533
534 # fails because LL address requires a device
535 add_rt "Gateway is linklocal address, no device" 2 \
536 - 2001:db8:104::1/64 $llv1
537
538 # local address can not be a gateway
539 add_rt "Gateway can not be local unicast address" 2 \
540 - 2001:db8:105::/64 2001:db8:1::1
541 add_rt "Gateway can not be local unicast address, with device" 2 \
542 - 2001:db8:106::/64 2001:db8:1::1 "dummy0"
543 add_rt "Gateway can not be a local linklocal address" 2 \
544 - 2001:db8:107::1/64 $lldummy "dummy0"
545
546 # VRF tests
547 add_rt "Gateway can be local address in a VRF" 0 \
548 - 2001:db8:108::/64 2001:db8:51::2
549 add_rt "Gateway can be local address in a VRF, with device" 0 \
550 - 2001:db8:109::/64 2001:db8:51::2 "veth0"
551 add_rt "Gateway can be local linklocal address in a VRF" 0 \
552 - 2001:db8:110::1/64 $llv1 "veth0"
553
554 add_rt "Redirect to VRF lookup" 0 \
555 - 2001:db8:111::/64 "" "red"
556
557 add_rt "VRF route, gateway can be local address in default VRF" 0 \
558 red 2001:db8:112::/64 2001:db8:51::1
559
560 # local address in same VRF fails
561 add_rt "VRF route, gateway can not be a local address" 2 \
562 red 2001:db8:113::1/64 2001:db8:2::1
563 add_rt "VRF route, gateway can not be a local addr with device" 2 \
564 red 2001:db8:114::1/64 2001:db8:2::1 "dummy1"
565}
566
567# Default VRF:
568# dummy0 - 198.51.100.1/24 2001:db8:1::1/64
569# veth0 - 192.0.2.1/24 2001:db8:51::1/64
570#
571# VRF red:
572# dummy1 - 192.168.2.1/24 2001:db8:2::1/64
573# veth1 - 192.0.2.2/24 2001:db8:51::2/64
574#
575# [ dummy0 veth0 ]--[ veth1 dummy1 ]
576
577fib_nexthop_test()
578{
579 setup
580
581 set -e
582
583 $IP -4 rule add pref 32765 table local
584 $IP -4 rule del pref 0
585 $IP -6 rule add pref 32765 table local
586 $IP -6 rule del pref 0
587
588 $IP link add red type vrf table 1
589 $IP link set red up
590 $IP -4 route add vrf red unreachable default metric 4278198272
591 $IP -6 route add vrf red unreachable default metric 4278198272
592
593 $IP link add veth0 type veth peer name veth1
594 $IP link set dev veth0 up
595 $IP address add 192.0.2.1/24 dev veth0
596 $IP -6 address add 2001:db8:51::1/64 dev veth0
597
598 $IP link set dev veth1 vrf red up
599 $IP address add 192.0.2.2/24 dev veth1
600 $IP -6 address add 2001:db8:51::2/64 dev veth1
601
602 $IP link add dummy1 type dummy
603 $IP link set dev dummy1 vrf red up
604 $IP address add 192.168.2.1/24 dev dummy1
605 $IP -6 address add 2001:db8:2::1/64 dev dummy1
606 set +e
607
608 sleep 1
609 fib4_nexthop
610 fib6_nexthop
611
612 (
613 $IP link del dev dummy1
614 $IP link del veth0
615 $IP link del red
616 ) 2>/dev/null
617 cleanup
618}
619
ca7a03c4
JD
620fib_suppress_test()
621{
b8642e3a
DA
622 echo
623 echo "FIB rule with suppress_prefixlength"
624 setup
625
ca7a03c4
JD
626 $IP link add dummy1 type dummy
627 $IP link set dummy1 up
628 $IP -6 route add default dev dummy1
629 $IP -6 rule add table main suppress_prefixlength 0
b8642e3a 630 ping -f -c 1000 -W 1 1234::1 >/dev/null 2>&1
ca7a03c4
JD
631 $IP -6 rule del table main suppress_prefixlength 0
632 $IP link del dummy1
633
634 # If we got here without crashing, we're good.
b8642e3a
DA
635 log_test 0 0 "FIB rule suppress test"
636
637 cleanup
ca7a03c4
JD
638}
639
654d3a78 640################################################################################
f9a5a9d8
DA
641# Tests on route add and replace
642
643run_cmd()
644{
645 local cmd="$1"
646 local out
647 local stderr="2>/dev/null"
648
649 if [ "$VERBOSE" = "1" ]; then
650 printf " COMMAND: $cmd\n"
651 stderr=
652 fi
653
654 out=$(eval $cmd $stderr)
655 rc=$?
656 if [ "$VERBOSE" = "1" -a -n "$out" ]; then
657 echo " $out"
658 fi
659
660 [ "$VERBOSE" = "1" ] && echo
661
662 return $rc
663}
664
a5f62298
DA
665check_expected()
666{
667 local out="$1"
668 local expected="$2"
669 local rc=0
670
671 [ "${out}" = "${expected}" ] && return 0
672
673 if [ -z "${out}" ]; then
674 if [ "$VERBOSE" = "1" ]; then
675 printf "\nNo route entry found\n"
676 printf "Expected:\n"
677 printf " ${expected}\n"
678 fi
679 return 1
680 fi
681
682 # tricky way to convert output to 1-line without ip's
683 # messy '\'; this drops all extra white space
684 out=$(echo ${out})
685 if [ "${out}" != "${expected}" ]; then
686 rc=1
687 if [ "${VERBOSE}" = "1" ]; then
688 printf " Unexpected route entry. Have:\n"
689 printf " ${out}\n"
690 printf " Expected:\n"
691 printf " ${expected}\n\n"
692 fi
693 fi
694
695 return $rc
696}
697
f9a5a9d8
DA
698# add route for a prefix, flushing any existing routes first
699# expected to be the first step of a test
700add_route6()
701{
702 local pfx="$1"
703 local nh="$2"
704 local out
705
706 if [ "$VERBOSE" = "1" ]; then
707 echo
708 echo " ##################################################"
709 echo
710 fi
711
712 run_cmd "$IP -6 ro flush ${pfx}"
713 [ $? -ne 0 ] && exit 1
714
715 out=$($IP -6 ro ls match ${pfx})
716 if [ -n "$out" ]; then
717 echo "Failed to flush routes for prefix used for tests."
718 exit 1
719 fi
720
721 run_cmd "$IP -6 ro add ${pfx} ${nh}"
722 if [ $? -ne 0 ]; then
723 echo "Failed to add initial route for test."
724 exit 1
725 fi
726}
727
728# add initial route - used in replace route tests
729add_initial_route6()
730{
731 add_route6 "2001:db8:104::/64" "$1"
732}
733
734check_route6()
735{
a0e11da7 736 local pfx
f9a5a9d8
DA
737 local expected="$1"
738 local out
739 local rc=0
740
a0e11da7
DA
741 set -- $expected
742 pfx=$1
743
f9a5a9d8 744 out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//')
a5f62298 745 check_expected "${out}" "${expected}"
f9a5a9d8
DA
746}
747
748route_cleanup()
749{
750 $IP li del red 2>/dev/null
751 $IP li del dummy1 2>/dev/null
752 $IP li del veth1 2>/dev/null
753 $IP li del veth3 2>/dev/null
754
755 cleanup &> /dev/null
756}
757
758route_setup()
759{
760 route_cleanup
761 setup
762
763 [ "${VERBOSE}" = "1" ] && set -x
764 set -e
765
a0e11da7 766 ip netns add ns2
228ddb33 767 ip netns set ns2 auto
a0e11da7
DA
768 ip -netns ns2 link set dev lo up
769 ip netns exec ns2 sysctl -qw net.ipv4.ip_forward=1
770 ip netns exec ns2 sysctl -qw net.ipv6.conf.all.forwarding=1
771
f9a5a9d8
DA
772 $IP li add veth1 type veth peer name veth2
773 $IP li add veth3 type veth peer name veth4
774
775 $IP li set veth1 up
776 $IP li set veth3 up
a0e11da7
DA
777 $IP li set veth2 netns ns2 up
778 $IP li set veth4 netns ns2 up
779 ip -netns ns2 li add dummy1 type dummy
780 ip -netns ns2 li set dummy1 up
f9a5a9d8 781
226407dd
DA
782 $IP -6 addr add 2001:db8:101::1/64 dev veth1 nodad
783 $IP -6 addr add 2001:db8:103::1/64 dev veth3 nodad
abb1860a 784 $IP addr add 172.16.101.1/24 dev veth1
abb1860a 785 $IP addr add 172.16.103.1/24 dev veth3
a0e11da7 786
226407dd
DA
787 ip -netns ns2 -6 addr add 2001:db8:101::2/64 dev veth2 nodad
788 ip -netns ns2 -6 addr add 2001:db8:103::2/64 dev veth4 nodad
789 ip -netns ns2 -6 addr add 2001:db8:104::1/64 dev dummy1 nodad
a0e11da7
DA
790
791 ip -netns ns2 addr add 172.16.101.2/24 dev veth2
792 ip -netns ns2 addr add 172.16.103.2/24 dev veth4
793 ip -netns ns2 addr add 172.16.104.1/24 dev dummy1
abb1860a 794
a5f62298 795 set +e
f9a5a9d8
DA
796}
797
798# assumption is that basic add of a single path route works
799# otherwise just adding an address on an interface is broken
800ipv6_rt_add()
801{
802 local rc
803
804 echo
805 echo "IPv6 route add / append tests"
806
807 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
808 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
809 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2"
810 log_test $? 2 "Attempt to add duplicate route - gw"
811
812 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
813 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
814 run_cmd "$IP -6 ro add 2001:db8:104::/64 dev veth3"
815 log_test $? 2 "Attempt to add duplicate route - dev only"
816
817 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
818 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
819 run_cmd "$IP -6 ro add unreachable 2001:db8:104::/64"
820 log_test $? 2 "Attempt to add duplicate route - reject route"
821
f9a5a9d8
DA
822 # route append with same prefix adds a new route
823 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
824 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
825 run_cmd "$IP -6 ro append 2001:db8:104::/64 via 2001:db8:103::2"
826 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"
827 log_test $? 0 "Append nexthop to existing route - gw"
828
f9a5a9d8
DA
829 # insert mpath directly
830 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
831 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"
832 log_test $? 0 "Add multipath route"
833
834 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
835 run_cmd "$IP -6 ro add 2001:db8:104::/64 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
836 log_test $? 2 "Attempt to add duplicate multipath route"
837
838 # insert of a second route without append but different metric
839 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
840 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2 metric 512"
841 rc=$?
842 if [ $rc -eq 0 ]; then
843 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::3 metric 256"
844 rc=$?
845 fi
846 log_test $rc 0 "Route add with different metrics"
847
848 run_cmd "$IP -6 ro del 2001:db8:104::/64 metric 512"
849 rc=$?
850 if [ $rc -eq 0 ]; then
851 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"
852 rc=$?
853 fi
854 log_test $rc 0 "Route delete with metric"
855}
654d3a78 856
f9a5a9d8 857ipv6_rt_replace_single()
607bd2e5 858{
f9a5a9d8
DA
859 # single path with single path
860 #
861 add_initial_route6 "via 2001:db8:101::2"
862 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:103::2"
863 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
864 log_test $? 0 "Single path with single path"
865
866 # single path with multipath
867 #
868 add_initial_route6 "nexthop via 2001:db8:101::2"
869 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::2"
870 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"
871 log_test $? 0 "Single path with multipath"
872
f9a5a9d8
DA
873 # single path with single path using MULTIPATH attribute
874 #
875 add_initial_route6 "via 2001:db8:101::2"
876 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:103::2"
877 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
878 log_test $? 0 "Single path with single path via multipath attribute"
879
880 # route replace fails - invalid nexthop
881 add_initial_route6 "via 2001:db8:101::2"
882 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:104::2"
883 if [ $? -eq 0 ]; then
884 # previous command is expected to fail so if it returns 0
885 # that means the test failed.
886 log_test 0 1 "Invalid nexthop"
a511858c 887 else
f9a5a9d8
DA
888 check_route6 "2001:db8:104::/64 via 2001:db8:101::2 dev veth1 metric 1024"
889 log_test $? 0 "Invalid nexthop"
a511858c 890 fi
f9a5a9d8
DA
891
892 # replace non-existent route
893 # - note use of change versus replace since ip adds NLM_F_CREATE
894 # for replace
895 add_initial_route6 "via 2001:db8:101::2"
896 run_cmd "$IP -6 ro change 2001:db8:105::/64 via 2001:db8:101::2"
897 log_test $? 2 "Single path - replace of non-existent route"
898}
899
900ipv6_rt_replace_mpath()
901{
902 # multipath with multipath
903 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
904 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
905 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"
906 log_test $? 0 "Multipath with multipath"
907
908 # multipath with single
909 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
910 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:101::3"
911 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
912 log_test $? 0 "Multipath with single path"
913
914 # multipath with single
915 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
916 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3"
917 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
918 log_test $? 0 "Multipath with single path via multipath attribute"
919
8b2892d2
BP
920 # multipath with dev-only
921 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
922 run_cmd "$IP -6 ro replace 2001:db8:104::/64 dev veth1"
923 check_route6 "2001:db8:104::/64 dev veth1 metric 1024"
924 log_test $? 0 "Multipath with dev-only"
925
f9a5a9d8
DA
926 # route replace fails - invalid nexthop 1
927 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
928 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:111::3 nexthop via 2001:db8:103::3"
929 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"
930 log_test $? 0 "Multipath - invalid first nexthop"
931
932 # route replace fails - invalid nexthop 2
933 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
934 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:113::3"
935 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"
936 log_test $? 0 "Multipath - invalid second nexthop"
937
938 # multipath non-existent route
939 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
940 run_cmd "$IP -6 ro change 2001:db8:105::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
941 log_test $? 2 "Multipath - replace of non-existent route"
942}
943
944ipv6_rt_replace()
945{
946 echo
947 echo "IPv6 route replace tests"
948
949 ipv6_rt_replace_single
950 ipv6_rt_replace_mpath
951}
952
953ipv6_route_test()
954{
955 route_setup
956
957 ipv6_rt_add
958 ipv6_rt_replace
959
960 route_cleanup
607bd2e5
IS
961}
962
d69faad7
DA
963ip_addr_metric_check()
964{
965 ip addr help 2>&1 | grep -q metric
966 if [ $? -ne 0 ]; then
967 echo "iproute2 command does not support metric for addresses. Skipping test"
968 return 1
969 fi
970
971 return 0
972}
973
974ipv6_addr_metric_test()
975{
976 local rc
977
978 echo
979 echo "IPv6 prefix route tests"
980
981 ip_addr_metric_check || return 1
982
983 setup
984
985 set -e
986 $IP li add dummy1 type dummy
987 $IP li add dummy2 type dummy
988 $IP li set dummy1 up
989 $IP li set dummy2 up
990
991 # default entry is metric 256
992 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64"
993 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64"
994 set +e
995
996 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 256 2001:db8:104::/64 dev dummy2 proto kernel metric 256"
997 log_test $? 0 "Default metric"
998
999 set -e
1000 run_cmd "$IP -6 addr flush dev dummy1"
1001 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64 metric 257"
1002 set +e
1003
1004 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 256 2001:db8:104::/64 dev dummy1 proto kernel metric 257"
1005 log_test $? 0 "User specified metric on first device"
1006
1007 set -e
1008 run_cmd "$IP -6 addr flush dev dummy2"
1009 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64 metric 258"
1010 set +e
1011
1012 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 257 2001:db8:104::/64 dev dummy2 proto kernel metric 258"
1013 log_test $? 0 "User specified metric on second device"
1014
1015 run_cmd "$IP -6 addr del dev dummy1 2001:db8:104::1/64 metric 257"
1016 rc=$?
1017 if [ $rc -eq 0 ]; then
1018 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 258"
1019 rc=$?
1020 fi
1021 log_test $rc 0 "Delete of address on first device"
1022
1023 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::2/64 metric 259"
1024 rc=$?
1025 if [ $rc -eq 0 ]; then
1026 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
1027 rc=$?
1028 fi
1029 log_test $rc 0 "Modify metric of address"
1030
1031 # verify prefix route removed on down
a0e11da7 1032 run_cmd "ip netns exec ns1 sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1"
d69faad7
DA
1033 run_cmd "$IP li set dev dummy2 down"
1034 rc=$?
1035 if [ $rc -eq 0 ]; then
a5f62298
DA
1036 out=$($IP -6 ro ls match 2001:db8:104::/64)
1037 check_expected "${out}" ""
d69faad7
DA
1038 rc=$?
1039 fi
1040 log_test $rc 0 "Prefix route removed on link down"
1041
1042 # verify prefix route re-inserted with assigned metric
1043 run_cmd "$IP li set dev dummy2 up"
1044 rc=$?
1045 if [ $rc -eq 0 ]; then
1046 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
1047 rc=$?
1048 fi
1049 log_test $rc 0 "Prefix route with metric on link up"
1050
0bbbd6b4
HL
1051 # verify peer metric added correctly
1052 set -e
1053 run_cmd "$IP -6 addr flush dev dummy2"
1054 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::1 peer 2001:db8:104::2 metric 260"
1055 set +e
1056
1057 check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 260"
1058 log_test $? 0 "Set metric with peer route on local side"
0bbbd6b4
HL
1059 check_route6 "2001:db8:104::2 dev dummy2 proto kernel metric 260"
1060 log_test $? 0 "Set metric with peer route on peer side"
1061
1062 set -e
1063 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::1 peer 2001:db8:104::3 metric 261"
1064 set +e
1065
1066 check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 261"
1067 log_test $? 0 "Modify metric and peer address on local side"
1068 check_route6 "2001:db8:104::3 dev dummy2 proto kernel metric 261"
1069 log_test $? 0 "Modify metric and peer address on peer side"
1070
d69faad7
DA
1071 $IP li del dummy1
1072 $IP li del dummy2
1073 cleanup
1074}
1075
a0e11da7
DA
1076ipv6_route_metrics_test()
1077{
1078 local rc
1079
1080 echo
1081 echo "IPv6 routes with metrics"
1082
1083 route_setup
1084
1085 #
1086 # single path with metrics
1087 #
1088 run_cmd "$IP -6 ro add 2001:db8:111::/64 via 2001:db8:101::2 mtu 1400"
1089 rc=$?
1090 if [ $rc -eq 0 ]; then
1091 check_route6 "2001:db8:111::/64 via 2001:db8:101::2 dev veth1 metric 1024 mtu 1400"
1092 rc=$?
1093 fi
1094 log_test $rc 0 "Single path route with mtu metric"
1095
1096
1097 #
1098 # multipath via separate routes with metrics
1099 #
1100 run_cmd "$IP -6 ro add 2001:db8:112::/64 via 2001:db8:101::2 mtu 1400"
1101 run_cmd "$IP -6 ro append 2001:db8:112::/64 via 2001:db8:103::2"
1102 rc=$?
1103 if [ $rc -eq 0 ]; then
1104 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"
1105 rc=$?
1106 fi
1107 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on first"
1108
1109 # second route is coalesced to first to make a multipath route.
1110 # MTU of the second path is hidden from display!
1111 run_cmd "$IP -6 ro add 2001:db8:113::/64 via 2001:db8:101::2"
1112 run_cmd "$IP -6 ro append 2001:db8:113::/64 via 2001:db8:103::2 mtu 1400"
1113 rc=$?
1114 if [ $rc -eq 0 ]; then
1115 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"
1116 rc=$?
1117 fi
1118 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on 2nd"
1119
1120 run_cmd "$IP -6 ro del 2001:db8:113::/64 via 2001:db8:101::2"
1121 if [ $? -eq 0 ]; then
1122 check_route6 "2001:db8:113::/64 via 2001:db8:103::2 dev veth3 metric 1024 mtu 1400"
1123 log_test $? 0 " MTU of second leg"
1124 fi
1125
1126 #
1127 # multipath with metrics
1128 #
1129 run_cmd "$IP -6 ro add 2001:db8:115::/64 mtu 1400 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
1130 rc=$?
1131 if [ $rc -eq 0 ]; then
1132 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"
1133 rc=$?
1134 fi
1135 log_test $rc 0 "Multipath route with mtu metric"
1136
1137 $IP -6 ro add 2001:db8:104::/64 via 2001:db8:101::2 mtu 1300
0360894a 1138 run_cmd "ip netns exec ns1 ${ping6} -w1 -c1 -s 1500 2001:db8:104::1"
a0e11da7
DA
1139 log_test $? 0 "Using route with mtu metric"
1140
226407dd
DA
1141 run_cmd "$IP -6 ro add 2001:db8:114::/64 via 2001:db8:101::2 congctl lock foo"
1142 log_test $? 2 "Invalid metric (fails metric_convert)"
1143
a0e11da7
DA
1144 route_cleanup
1145}
1146
abb1860a
DA
1147# add route for a prefix, flushing any existing routes first
1148# expected to be the first step of a test
1149add_route()
1150{
1151 local pfx="$1"
1152 local nh="$2"
1153 local out
1154
1155 if [ "$VERBOSE" = "1" ]; then
1156 echo
1157 echo " ##################################################"
1158 echo
1159 fi
1160
1161 run_cmd "$IP ro flush ${pfx}"
1162 [ $? -ne 0 ] && exit 1
1163
1164 out=$($IP ro ls match ${pfx})
1165 if [ -n "$out" ]; then
1166 echo "Failed to flush routes for prefix used for tests."
1167 exit 1
1168 fi
1169
1170 run_cmd "$IP ro add ${pfx} ${nh}"
1171 if [ $? -ne 0 ]; then
1172 echo "Failed to add initial route for test."
1173 exit 1
1174 fi
1175}
1176
1177# add initial route - used in replace route tests
1178add_initial_route()
1179{
1180 add_route "172.16.104.0/24" "$1"
1181}
1182
1183check_route()
1184{
a0e11da7 1185 local pfx
abb1860a
DA
1186 local expected="$1"
1187 local out
abb1860a 1188
a0e11da7
DA
1189 set -- $expected
1190 pfx=$1
1191 [ "${pfx}" = "unreachable" ] && pfx=$2
1192
abb1860a 1193 out=$($IP ro ls match ${pfx})
a5f62298 1194 check_expected "${out}" "${expected}"
abb1860a
DA
1195}
1196
1197# assumption is that basic add of a single path route works
1198# otherwise just adding an address on an interface is broken
1199ipv4_rt_add()
1200{
1201 local rc
1202
1203 echo
1204 echo "IPv4 route add / append tests"
1205
1206 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1207 add_route "172.16.104.0/24" "via 172.16.101.2"
1208 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2"
1209 log_test $? 2 "Attempt to add duplicate route - gw"
1210
1211 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1212 add_route "172.16.104.0/24" "via 172.16.101.2"
1213 run_cmd "$IP ro add 172.16.104.0/24 dev veth3"
1214 log_test $? 2 "Attempt to add duplicate route - dev only"
1215
1216 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
1217 add_route "172.16.104.0/24" "via 172.16.101.2"
1218 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1219 log_test $? 2 "Attempt to add duplicate route - reject route"
1220
1221 # iproute2 prepend only sets NLM_F_CREATE
1222 # - adds a new route; does NOT convert existing route to ECMP
1223 add_route "172.16.104.0/24" "via 172.16.101.2"
1224 run_cmd "$IP ro prepend 172.16.104.0/24 via 172.16.103.2"
1225 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"
1226 log_test $? 0 "Add new nexthop for existing prefix"
1227
1228 # route append with same prefix adds a new route
1229 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
1230 add_route "172.16.104.0/24" "via 172.16.101.2"
1231 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
1232 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"
1233 log_test $? 0 "Append nexthop to existing route - gw"
1234
1235 add_route "172.16.104.0/24" "via 172.16.101.2"
1236 run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
1237 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 dev veth3 scope link"
1238 log_test $? 0 "Append nexthop to existing route - dev only"
1239
1240 add_route "172.16.104.0/24" "via 172.16.101.2"
1241 run_cmd "$IP ro append unreachable 172.16.104.0/24"
1242 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 unreachable 172.16.104.0/24"
1243 log_test $? 0 "Append nexthop to existing route - reject route"
1244
1245 run_cmd "$IP ro flush 172.16.104.0/24"
1246 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1247 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
1248 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 via 172.16.103.2 dev veth3"
1249 log_test $? 0 "Append nexthop to existing reject route - gw"
1250
1251 run_cmd "$IP ro flush 172.16.104.0/24"
1252 run_cmd "$IP ro add unreachable 172.16.104.0/24"
1253 run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
1254 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 dev veth3 scope link"
1255 log_test $? 0 "Append nexthop to existing reject route - dev only"
1256
1257 # insert mpath directly
1258 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1259 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"
1260 log_test $? 0 "add multipath route"
1261
1262 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1263 run_cmd "$IP ro add 172.16.104.0/24 nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1264 log_test $? 2 "Attempt to add duplicate multipath route"
1265
1266 # insert of a second route without append but different metric
1267 add_route "172.16.104.0/24" "via 172.16.101.2"
1268 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2 metric 512"
1269 rc=$?
1270 if [ $rc -eq 0 ]; then
1271 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.3 metric 256"
1272 rc=$?
1273 fi
1274 log_test $rc 0 "Route add with different metrics"
1275
1276 run_cmd "$IP ro del 172.16.104.0/24 metric 512"
1277 rc=$?
1278 if [ $rc -eq 0 ]; then
1279 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"
1280 rc=$?
1281 fi
1282 log_test $rc 0 "Route delete with metric"
1283}
1284
1285ipv4_rt_replace_single()
1286{
1287 # single path with single path
1288 #
1289 add_initial_route "via 172.16.101.2"
1290 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.103.2"
1291 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
1292 log_test $? 0 "Single path with single path"
1293
1294 # single path with multipath
1295 #
1296 add_initial_route "nexthop via 172.16.101.2"
1297 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.2"
1298 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"
1299 log_test $? 0 "Single path with multipath"
1300
1301 # single path with reject
1302 #
1303 add_initial_route "nexthop via 172.16.101.2"
1304 run_cmd "$IP ro replace unreachable 172.16.104.0/24"
1305 check_route "unreachable 172.16.104.0/24"
1306 log_test $? 0 "Single path with reject route"
1307
1308 # single path with single path using MULTIPATH attribute
1309 #
1310 add_initial_route "via 172.16.101.2"
1311 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.103.2"
1312 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
1313 log_test $? 0 "Single path with single path via multipath attribute"
1314
1315 # route replace fails - invalid nexthop
1316 add_initial_route "via 172.16.101.2"
1317 run_cmd "$IP ro replace 172.16.104.0/24 via 2001:db8:104::2"
1318 if [ $? -eq 0 ]; then
1319 # previous command is expected to fail so if it returns 0
1320 # that means the test failed.
1321 log_test 0 1 "Invalid nexthop"
1322 else
1323 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1"
1324 log_test $? 0 "Invalid nexthop"
1325 fi
1326
1327 # replace non-existent route
1328 # - note use of change versus replace since ip adds NLM_F_CREATE
1329 # for replace
1330 add_initial_route "via 172.16.101.2"
1331 run_cmd "$IP ro change 172.16.105.0/24 via 172.16.101.2"
1332 log_test $? 2 "Single path - replace of non-existent route"
1333}
1334
1335ipv4_rt_replace_mpath()
1336{
1337 # multipath with multipath
1338 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1339 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
1340 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"
1341 log_test $? 0 "Multipath with multipath"
1342
1343 # multipath with single
1344 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1345 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.101.3"
1346 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
1347 log_test $? 0 "Multipath with single path"
1348
1349 # multipath with single
1350 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1351 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3"
1352 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
1353 log_test $? 0 "Multipath with single path via multipath attribute"
1354
1355 # multipath with reject
1356 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1357 run_cmd "$IP ro replace unreachable 172.16.104.0/24"
1358 check_route "unreachable 172.16.104.0/24"
1359 log_test $? 0 "Multipath with reject route"
1360
1361 # route replace fails - invalid nexthop 1
1362 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1363 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.111.3 nexthop via 172.16.103.3"
1364 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"
1365 log_test $? 0 "Multipath - invalid first nexthop"
1366
1367 # route replace fails - invalid nexthop 2
1368 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1369 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.113.3"
1370 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"
1371 log_test $? 0 "Multipath - invalid second nexthop"
1372
1373 # multipath non-existent route
1374 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1375 run_cmd "$IP ro change 172.16.105.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
1376 log_test $? 2 "Multipath - replace of non-existent route"
1377}
1378
1379ipv4_rt_replace()
1380{
1381 echo
1382 echo "IPv4 route replace tests"
1383
1384 ipv4_rt_replace_single
1385 ipv4_rt_replace_mpath
1386}
1387
1388ipv4_route_test()
1389{
1390 route_setup
1391
1392 ipv4_rt_add
1393 ipv4_rt_replace
1394
1395 route_cleanup
1396}
1397
d69faad7
DA
1398ipv4_addr_metric_test()
1399{
1400 local rc
1401
1402 echo
1403 echo "IPv4 prefix route tests"
1404
1405 ip_addr_metric_check || return 1
1406
1407 setup
1408
1409 set -e
1410 $IP li add dummy1 type dummy
1411 $IP li add dummy2 type dummy
1412 $IP li set dummy1 up
1413 $IP li set dummy2 up
1414
1415 # default entry is metric 256
1416 run_cmd "$IP addr add dev dummy1 172.16.104.1/24"
1417 run_cmd "$IP addr add dev dummy2 172.16.104.2/24"
1418 set +e
1419
1420 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"
1421 log_test $? 0 "Default metric"
1422
1423 set -e
1424 run_cmd "$IP addr flush dev dummy1"
1425 run_cmd "$IP addr add dev dummy1 172.16.104.1/24 metric 257"
1426 set +e
1427
1428 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"
1429 log_test $? 0 "User specified metric on first device"
1430
1431 set -e
1432 run_cmd "$IP addr flush dev dummy2"
1433 run_cmd "$IP addr add dev dummy2 172.16.104.2/24 metric 258"
1434 set +e
1435
1436 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"
1437 log_test $? 0 "User specified metric on second device"
1438
1439 run_cmd "$IP addr del dev dummy1 172.16.104.1/24 metric 257"
1440 rc=$?
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 258"
1443 rc=$?
1444 fi
1445 log_test $rc 0 "Delete of address on first device"
1446
1447 run_cmd "$IP addr change dev dummy2 172.16.104.2/24 metric 259"
1448 rc=$?
1449 if [ $rc -eq 0 ]; then
1450 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
1451 rc=$?
1452 fi
1453 log_test $rc 0 "Modify metric of address"
1454
1455 # verify prefix route removed on down
1456 run_cmd "$IP li set dev dummy2 down"
1457 rc=$?
1458 if [ $rc -eq 0 ]; then
a5f62298
DA
1459 out=$($IP ro ls match 172.16.104.0/24)
1460 check_expected "${out}" ""
d69faad7
DA
1461 rc=$?
1462 fi
1463 log_test $rc 0 "Prefix route removed on link down"
1464
1465 # verify prefix route re-inserted with assigned metric
1466 run_cmd "$IP li set dev dummy2 up"
1467 rc=$?
1468 if [ $rc -eq 0 ]; then
1469 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
1470 rc=$?
1471 fi
1472 log_test $rc 0 "Prefix route with metric on link up"
1473
37de3b35
PA
1474 # explicitly check for metric changes on edge scenarios
1475 run_cmd "$IP addr flush dev dummy2"
1476 run_cmd "$IP addr add dev dummy2 172.16.104.0/24 metric 259"
1477 run_cmd "$IP addr change dev dummy2 172.16.104.0/24 metric 260"
1478 rc=$?
1479 if [ $rc -eq 0 ]; then
1480 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.0 metric 260"
1481 rc=$?
1482 fi
1483 log_test $rc 0 "Modify metric of .0/24 address"
1484
1485 run_cmd "$IP addr flush dev dummy2"
1486 run_cmd "$IP addr add dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 260"
37de3b35
PA
1487 rc=$?
1488 if [ $rc -eq 0 ]; then
0bbbd6b4
HL
1489 check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 260"
1490 rc=$?
1491 fi
1492 log_test $rc 0 "Set metric of address with peer route"
1493
1494 run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.3 metric 261"
1495 rc=$?
1496 if [ $rc -eq 0 ]; then
1497 check_route "172.16.104.3 dev dummy2 proto kernel scope link src 172.16.104.1 metric 261"
37de3b35
PA
1498 rc=$?
1499 fi
0bbbd6b4 1500 log_test $rc 0 "Modify metric and peer address for peer route"
37de3b35 1501
d69faad7
DA
1502 $IP li del dummy1
1503 $IP li del dummy2
1504 cleanup
1505}
1506
a0e11da7
DA
1507ipv4_route_metrics_test()
1508{
1509 local rc
1510
1511 echo
1512 echo "IPv4 route add / append tests"
1513
1514 route_setup
1515
1516 run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 mtu 1400"
1517 rc=$?
1518 if [ $rc -eq 0 ]; then
1519 check_route "172.16.111.0/24 via 172.16.101.2 dev veth1 mtu 1400"
1520 rc=$?
1521 fi
1522 log_test $rc 0 "Single path route with mtu metric"
1523
1524
1525 run_cmd "$IP ro add 172.16.112.0/24 mtu 1400 nexthop via 172.16.101.2 nexthop via 172.16.103.2"
1526 rc=$?
1527 if [ $rc -eq 0 ]; then
1528 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"
1529 rc=$?
1530 fi
1531 log_test $rc 0 "Multipath route with mtu metric"
1532
1533 $IP ro add 172.16.104.0/24 via 172.16.101.2 mtu 1300
1534 run_cmd "ip netns exec ns1 ping -w1 -c1 -s 1500 172.16.104.1"
1535 log_test $? 0 "Using route with mtu metric"
1536
226407dd
DA
1537 run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 congctl lock foo"
1538 log_test $? 2 "Invalid metric (fails metric_convert)"
1539
a0e11da7
DA
1540 route_cleanup
1541}
1542
228ddb33
DA
1543ipv4_route_v6_gw_test()
1544{
1545 local rc
1546
1547 echo
1548 echo "IPv4 route with IPv6 gateway tests"
1549
1550 route_setup
1551 sleep 2
1552
1553 #
1554 # single path route
1555 #
1556 run_cmd "$IP ro add 172.16.104.0/24 via inet6 2001:db8:101::2"
1557 rc=$?
1558 log_test $rc 0 "Single path route with IPv6 gateway"
1559 if [ $rc -eq 0 ]; then
1560 check_route "172.16.104.0/24 via inet6 2001:db8:101::2 dev veth1"
1561 fi
1562
1563 run_cmd "ip netns exec ns1 ping -w1 -c1 172.16.104.1"
1564 log_test $rc 0 "Single path route with IPv6 gateway - ping"
1565
1566 run_cmd "$IP ro del 172.16.104.0/24 via inet6 2001:db8:101::2"
1567 rc=$?
1568 log_test $rc 0 "Single path route delete"
1569 if [ $rc -eq 0 ]; then
1570 check_route "172.16.112.0/24"
1571 fi
1572
1573 #
1574 # multipath - v6 then v4
1575 #
1576 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"
1577 rc=$?
1578 log_test $rc 0 "Multipath route add - v6 nexthop then v4"
1579 if [ $rc -eq 0 ]; then
1580 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"
1581 fi
1582
1583 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"
1584 log_test $? 2 " Multipath route delete - nexthops in wrong order"
1585
1586 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"
1587 log_test $? 0 " Multipath route delete exact match"
1588
1589 #
1590 # multipath - v4 then v6
1591 #
1592 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"
1593 rc=$?
1594 log_test $rc 0 "Multipath route add - v4 nexthop then v6"
1595 if [ $rc -eq 0 ]; then
1596 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"
1597 fi
1598
1599 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"
1600 log_test $? 2 " Multipath route delete - nexthops in wrong order"
1601
1602 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"
1603 log_test $? 0 " Multipath route delete exact match"
1604
1605 route_cleanup
1606}
a0e11da7 1607
654d3a78 1608################################################################################
1c7447b4 1609# usage
654d3a78 1610
1c7447b4 1611usage()
607bd2e5 1612{
1c7447b4
DA
1613 cat <<EOF
1614usage: ${0##*/} OPTS
1615
1616 -t <test> Test(s) to run (default: all)
1617 (options: $TESTS)
1618 -p Pause on fail
7df15e6c 1619 -P Pause after each test before cleanup
1c7447b4
DA
1620 -v verbose mode (show commands and output)
1621EOF
607bd2e5
IS
1622}
1623
1c7447b4
DA
1624################################################################################
1625# main
1626
1627while getopts :t:pPhv o
1628do
1629 case $o in
1630 t) TESTS=$OPTARG;;
1631 p) PAUSE_ON_FAIL=yes;;
7df15e6c 1632 P) PAUSE=yes;;
1c7447b4
DA
1633 v) VERBOSE=$(($VERBOSE + 1));;
1634 h) usage; exit 0;;
1635 *) usage; exit 1;;
1636 esac
1637done
1638
1639PEER_CMD="ip netns exec ${PEER_NS}"
1640
7df15e6c
DA
1641# make sure we don't pause twice
1642[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
1643
607bd2e5
IS
1644if [ "$(id -u)" -ne 0 ];then
1645 echo "SKIP: Need root privileges"
57aefc7c 1646 exit $ksft_skip;
607bd2e5
IS
1647fi
1648
1649if [ ! -x "$(command -v ip)" ]; then
1650 echo "SKIP: Could not run test without ip tool"
57aefc7c 1651 exit $ksft_skip
607bd2e5
IS
1652fi
1653
1654ip route help 2>&1 | grep -q fibmatch
1655if [ $? -ne 0 ]; then
1656 echo "SKIP: iproute2 too old, missing fibmatch"
57aefc7c 1657 exit $ksft_skip
607bd2e5
IS
1658fi
1659
ee395a5e
DA
1660# start clean
1661cleanup &> /dev/null
1662
1c7447b4
DA
1663for t in $TESTS
1664do
1665 case $t in
1666 fib_unreg_test|unregister) fib_unreg_test;;
1667 fib_down_test|down) fib_down_test;;
1668 fib_carrier_test|carrier) fib_carrier_test;;
adb701d6 1669 fib_rp_filter_test|rp_filter) fib_rp_filter_test;;
1c7447b4 1670 fib_nexthop_test|nexthop) fib_nexthop_test;;
ca7a03c4 1671 fib_suppress_test|suppress) fib_suppress_test;;
f9a5a9d8 1672 ipv6_route_test|ipv6_rt) ipv6_route_test;;
abb1860a 1673 ipv4_route_test|ipv4_rt) ipv4_route_test;;
d69faad7
DA
1674 ipv6_addr_metric) ipv6_addr_metric_test;;
1675 ipv4_addr_metric) ipv4_addr_metric_test;;
a0e11da7
DA
1676 ipv6_route_metrics) ipv6_route_metrics_test;;
1677 ipv4_route_metrics) ipv4_route_metrics_test;;
228ddb33 1678 ipv4_route_v6_gw) ipv4_route_v6_gw_test;;
1c7447b4
DA
1679
1680 help) echo "Test names: $TESTS"; exit 0;;
1681 esac
1682done
607bd2e5 1683
37ce42c1
DA
1684if [ "$TESTS" != "none" ]; then
1685 printf "\nTests passed: %3d\n" ${nsuccess}
1686 printf "Tests failed: %3d\n" ${nfail}
1687fi
607bd2e5
IS
1688
1689exit $ret