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. 6source lib.sh 7ret=0 8 9# all tests in this script. Can be overridden with -t option 10TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \ 11 ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics \ 12 ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \ 13 ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test \ 14 ipv4_mpath_list ipv6_mpath_list ipv4_mpath_balance ipv6_mpath_balance \ 15 ipv4_mpath_balance_preferred fib6_ra_to_static" 16 17VERBOSE=0 18PAUSE_ON_FAIL=no 19PAUSE=no 20 21which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping) 22 23log_test() 24{ 25 local rc=$1 26 local expected=$2 27 local msg="$3" 28 29 if [ ${rc} -eq ${expected} ]; then 30 printf " TEST: %-60s [ OK ]\n" "${msg}" 31 nsuccess=$((nsuccess+1)) 32 else 33 ret=1 34 nfail=$((nfail+1)) 35 printf " TEST: %-60s [FAIL]\n" "${msg}" 36 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then 37 echo 38 echo "hit enter to continue, 'q' to quit" 39 read a 40 [ "$a" = "q" ] && exit 1 41 fi 42 fi 43 44 if [ "${PAUSE}" = "yes" ]; then 45 echo 46 echo "hit enter to continue, 'q' to quit" 47 read a 48 [ "$a" = "q" ] && exit 1 49 fi 50} 51 52setup() 53{ 54 set -e 55 setup_ns ns1 56 IP="$(which ip) -netns $ns1" 57 NS_EXEC="$(which ip) netns exec $ns1" 58 ip netns exec $ns1 sysctl -qw net.ipv4.ip_forward=1 59 ip netns exec $ns1 sysctl -qw net.ipv6.conf.all.forwarding=1 60 61 $IP link add dummy0 type dummy 62 $IP link set dev dummy0 up 63 $IP address add 198.51.100.1/24 dev dummy0 64 $IP -6 address add 2001:db8:1::1/64 dev dummy0 65 set +e 66 67} 68 69cleanup() 70{ 71 $IP link del dev dummy0 &> /dev/null 72 cleanup_ns $ns1 $ns2 73} 74 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 97fib_unreg_unicast_test() 98{ 99 echo 100 echo "Single path route test" 101 102 setup 103 104 echo " Start point" 105 $IP route get fibmatch 198.51.100.2 &> /dev/null 106 log_test $? 0 "IPv4 fibmatch" 107 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null 108 log_test $? 0 "IPv6 fibmatch" 109 110 set -e 111 $IP link del dev dummy0 112 set +e 113 114 echo " Nexthop device deleted" 115 $IP route get fibmatch 198.51.100.2 &> /dev/null 116 log_test $? 2 "IPv4 fibmatch - no route" 117 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null 118 log_test $? 2 "IPv6 fibmatch - no route" 119 120 cleanup 121} 122 123fib_unreg_multipath_test() 124{ 125 126 echo 127 echo "Multipath route test" 128 129 setup 130 131 set -e 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 136 137 $IP route add 203.0.113.0/24 \ 138 nexthop via 198.51.100.2 dev dummy0 \ 139 nexthop via 192.0.2.2 dev dummy1 140 $IP -6 route add 2001:db8:3::/64 \ 141 nexthop via 2001:db8:1::2 dev dummy0 \ 142 nexthop via 2001:db8:2::2 dev dummy1 143 set +e 144 145 echo " Start point" 146 $IP route get fibmatch 203.0.113.1 &> /dev/null 147 log_test $? 0 "IPv4 fibmatch" 148 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null 149 log_test $? 0 "IPv6 fibmatch" 150 151 set -e 152 $IP link del dev dummy0 153 set +e 154 155 echo " One nexthop device deleted" 156 $IP route get fibmatch 203.0.113.1 &> /dev/null 157 log_test $? 2 "IPv4 - multipath route removed on delete" 158 159 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null 160 # In IPv6 we do not flush the entire multipath route. 161 log_test $? 0 "IPv6 - multipath down to single path" 162 163 set -e 164 $IP link del dev dummy1 165 set +e 166 167 echo " Second nexthop device deleted" 168 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null 169 log_test $? 2 "IPv6 - no route" 170 171 cleanup 172} 173 174fib_unreg_test() 175{ 176 fib_unreg_unicast_test 177 fib_unreg_multipath_test 178} 179 180fib_down_unicast_test() 181{ 182 echo 183 echo "Single path, admin down" 184 185 setup 186 187 echo " Start point" 188 $IP route get fibmatch 198.51.100.2 &> /dev/null 189 log_test $? 0 "IPv4 fibmatch" 190 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null 191 log_test $? 0 "IPv6 fibmatch" 192 193 set -e 194 $IP link set dev dummy0 down 195 set +e 196 197 echo " Route deleted on down" 198 $IP route get fibmatch 198.51.100.2 &> /dev/null 199 log_test $? 2 "IPv4 fibmatch" 200 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null 201 log_test $? 2 "IPv6 fibmatch" 202 203 cleanup 204} 205 206fib_down_multipath_test_do() 207{ 208 local down_dev=$1 209 local up_dev=$2 210 211 $IP route get fibmatch 203.0.113.1 \ 212 oif $down_dev &> /dev/null 213 log_test $? 2 "IPv4 fibmatch on down device" 214 $IP -6 route get fibmatch 2001:db8:3::1 \ 215 oif $down_dev &> /dev/null 216 log_test $? 2 "IPv6 fibmatch on down device" 217 218 $IP route get fibmatch 203.0.113.1 \ 219 oif $up_dev &> /dev/null 220 log_test $? 0 "IPv4 fibmatch on up device" 221 $IP -6 route get fibmatch 2001:db8:3::1 \ 222 oif $up_dev &> /dev/null 223 log_test $? 0 "IPv6 fibmatch on up device" 224 225 $IP route get fibmatch 203.0.113.1 | \ 226 grep $down_dev | grep -q "dead linkdown" 227 log_test $? 0 "IPv4 flags on down device" 228 $IP -6 route get fibmatch 2001:db8:3::1 | \ 229 grep $down_dev | grep -q "dead linkdown" 230 log_test $? 0 "IPv6 flags on down device" 231 232 $IP route get fibmatch 203.0.113.1 | \ 233 grep $up_dev | grep -q "dead linkdown" 234 log_test $? 1 "IPv4 flags on up device" 235 $IP -6 route get fibmatch 2001:db8:3::1 | \ 236 grep $up_dev | grep -q "dead linkdown" 237 log_test $? 1 "IPv6 flags on up device" 238} 239 240fib_down_multipath_test() 241{ 242 echo 243 echo "Admin down multipath" 244 245 setup 246 247 set -e 248 $IP link add dummy1 type dummy 249 $IP link set dev dummy1 up 250 251 $IP address add 192.0.2.1/24 dev dummy1 252 $IP -6 address add 2001:db8:2::1/64 dev dummy1 253 254 $IP route add 203.0.113.0/24 \ 255 nexthop via 198.51.100.2 dev dummy0 \ 256 nexthop via 192.0.2.2 dev dummy1 257 $IP -6 route add 2001:db8:3::/64 \ 258 nexthop via 2001:db8:1::2 dev dummy0 \ 259 nexthop via 2001:db8:2::2 dev dummy1 260 set +e 261 262 echo " Verify start point" 263 $IP route get fibmatch 203.0.113.1 &> /dev/null 264 log_test $? 0 "IPv4 fibmatch" 265 266 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null 267 log_test $? 0 "IPv6 fibmatch" 268 269 set -e 270 $IP link set dev dummy0 down 271 set +e 272 273 echo " One device down, one up" 274 fib_down_multipath_test_do "dummy0" "dummy1" 275 276 set -e 277 $IP link set dev dummy0 up 278 $IP link set dev dummy1 down 279 set +e 280 281 echo " Other device down and up" 282 fib_down_multipath_test_do "dummy1" "dummy0" 283 284 set -e 285 $IP link set dev dummy0 down 286 set +e 287 288 echo " Both devices down" 289 $IP route get fibmatch 203.0.113.1 &> /dev/null 290 log_test $? 2 "IPv4 fibmatch" 291 $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null 292 log_test $? 2 "IPv6 fibmatch" 293 294 $IP link del dev dummy1 295 cleanup 296} 297 298fib_down_test() 299{ 300 fib_down_unicast_test 301 fib_down_multipath_test 302} 303 304# Local routes should not be affected when carrier changes. 305fib_carrier_local_test() 306{ 307 echo 308 echo "Local carrier tests - single path" 309 310 setup 311 312 set -e 313 $IP link set dev dummy0 carrier on 314 set +e 315 316 echo " Start point" 317 $IP route get fibmatch 198.51.100.1 &> /dev/null 318 log_test $? 0 "IPv4 fibmatch" 319 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null 320 log_test $? 0 "IPv6 fibmatch" 321 322 $IP route get fibmatch 198.51.100.1 | \ 323 grep -q "linkdown" 324 log_test $? 1 "IPv4 - no linkdown flag" 325 $IP -6 route get fibmatch 2001:db8:1::1 | \ 326 grep -q "linkdown" 327 log_test $? 1 "IPv6 - no linkdown flag" 328 329 set -e 330 $IP link set dev dummy0 carrier off 331 sleep 1 332 set +e 333 334 echo " Carrier off on nexthop" 335 $IP route get fibmatch 198.51.100.1 &> /dev/null 336 log_test $? 0 "IPv4 fibmatch" 337 $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null 338 log_test $? 0 "IPv6 fibmatch" 339 340 $IP route get fibmatch 198.51.100.1 | \ 341 grep -q "linkdown" 342 log_test $? 1 "IPv4 - linkdown flag set" 343 $IP -6 route get fibmatch 2001:db8:1::1 | \ 344 grep -q "linkdown" 345 log_test $? 1 "IPv6 - linkdown flag set" 346 347 set -e 348 $IP address add 192.0.2.1/24 dev dummy0 349 $IP -6 address add 2001:db8:2::1/64 dev dummy0 350 set +e 351 352 echo " Route to local address with carrier down" 353 $IP route get fibmatch 192.0.2.1 &> /dev/null 354 log_test $? 0 "IPv4 fibmatch" 355 $IP -6 route get fibmatch 2001:db8:2::1 &> /dev/null 356 log_test $? 0 "IPv6 fibmatch" 357 358 $IP route get fibmatch 192.0.2.1 | \ 359 grep -q "linkdown" 360 log_test $? 1 "IPv4 linkdown flag set" 361 $IP -6 route get fibmatch 2001:db8:2::1 | \ 362 grep -q "linkdown" 363 log_test $? 1 "IPv6 linkdown flag set" 364 365 cleanup 366} 367 368fib_carrier_unicast_test() 369{ 370 ret=0 371 372 echo 373 echo "Single path route carrier test" 374 375 setup 376 377 set -e 378 $IP link set dev dummy0 carrier on 379 set +e 380 381 echo " Start point" 382 $IP route get fibmatch 198.51.100.2 &> /dev/null 383 log_test $? 0 "IPv4 fibmatch" 384 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null 385 log_test $? 0 "IPv6 fibmatch" 386 387 $IP route get fibmatch 198.51.100.2 | \ 388 grep -q "linkdown" 389 log_test $? 1 "IPv4 no linkdown flag" 390 $IP -6 route get fibmatch 2001:db8:1::2 | \ 391 grep -q "linkdown" 392 log_test $? 1 "IPv6 no linkdown flag" 393 394 set -e 395 $IP link set dev dummy0 carrier off 396 sleep 1 397 set +e 398 399 echo " Carrier down" 400 $IP route get fibmatch 198.51.100.2 &> /dev/null 401 log_test $? 0 "IPv4 fibmatch" 402 $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null 403 log_test $? 0 "IPv6 fibmatch" 404 405 $IP route get fibmatch 198.51.100.2 | \ 406 grep -q "linkdown" 407 log_test $? 0 "IPv4 linkdown flag set" 408 $IP -6 route get fibmatch 2001:db8:1::2 | \ 409 grep -q "linkdown" 410 log_test $? 0 "IPv6 linkdown flag set" 411 412 set -e 413 $IP address add 192.0.2.1/24 dev dummy0 414 $IP -6 address add 2001:db8:2::1/64 dev dummy0 415 set +e 416 417 echo " Second address added with carrier down" 418 $IP route get fibmatch 192.0.2.2 &> /dev/null 419 log_test $? 0 "IPv4 fibmatch" 420 $IP -6 route get fibmatch 2001:db8:2::2 &> /dev/null 421 log_test $? 0 "IPv6 fibmatch" 422 423 $IP route get fibmatch 192.0.2.2 | \ 424 grep -q "linkdown" 425 log_test $? 0 "IPv4 linkdown flag set" 426 $IP -6 route get fibmatch 2001:db8:2::2 | \ 427 grep -q "linkdown" 428 log_test $? 0 "IPv6 linkdown flag set" 429 430 cleanup 431} 432 433fib_carrier_test() 434{ 435 fib_carrier_local_test 436 fib_carrier_unicast_test 437} 438 439fib_rp_filter_test() 440{ 441 echo 442 echo "IPv4 rp_filter tests" 443 444 setup 445 446 set -e 447 setup_ns ns2 448 449 $IP link add name veth1 type veth peer name veth2 450 $IP link set dev veth2 netns $ns2 451 $IP address add 192.0.2.1/24 dev veth1 452 ip -netns $ns2 address add 192.0.2.1/24 dev veth2 453 $IP link set dev veth1 up 454 ip -netns $ns2 link set dev veth2 up 455 456 $IP link set dev lo address 52:54:00:6a:c7:5e 457 $IP link set dev veth1 address 52:54:00:6a:c7:5e 458 ip -netns $ns2 link set dev lo address 52:54:00:6a:c7:5e 459 ip -netns $ns2 link set dev veth2 address 52:54:00:6a:c7:5e 460 461 # 1. (ns2) redirect lo's egress to veth2's egress 462 ip netns exec $ns2 tc qdisc add dev lo parent root handle 1: fq_codel 463 ip netns exec $ns2 tc filter add dev lo parent 1: protocol arp basic \ 464 action mirred egress redirect dev veth2 465 ip netns exec $ns2 tc filter add dev lo parent 1: protocol ip basic \ 466 action mirred egress redirect dev veth2 467 468 # 2. (ns1) redirect veth1's ingress to lo's ingress 469 $NS_EXEC tc qdisc add dev veth1 ingress 470 $NS_EXEC tc filter add dev veth1 ingress protocol arp basic \ 471 action mirred ingress redirect dev lo 472 $NS_EXEC tc filter add dev veth1 ingress protocol ip basic \ 473 action mirred ingress redirect dev lo 474 475 # 3. (ns1) redirect lo's egress to veth1's egress 476 $NS_EXEC tc qdisc add dev lo parent root handle 1: fq_codel 477 $NS_EXEC tc filter add dev lo parent 1: protocol arp basic \ 478 action mirred egress redirect dev veth1 479 $NS_EXEC tc filter add dev lo parent 1: protocol ip basic \ 480 action mirred egress redirect dev veth1 481 482 # 4. (ns2) redirect veth2's ingress to lo's ingress 483 ip netns exec $ns2 tc qdisc add dev veth2 ingress 484 ip netns exec $ns2 tc filter add dev veth2 ingress protocol arp basic \ 485 action mirred ingress redirect dev lo 486 ip netns exec $ns2 tc filter add dev veth2 ingress protocol ip basic \ 487 action mirred ingress redirect dev lo 488 489 $NS_EXEC sysctl -qw net.ipv4.conf.all.rp_filter=1 490 $NS_EXEC sysctl -qw net.ipv4.conf.all.accept_local=1 491 $NS_EXEC sysctl -qw net.ipv4.conf.all.route_localnet=1 492 ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.rp_filter=1 493 ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.accept_local=1 494 ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.route_localnet=1 495 set +e 496 497 run_cmd "ip netns exec $ns2 ping -w1 -c1 192.0.2.1" 498 log_test $? 0 "rp_filter passes local packets" 499 500 run_cmd "ip netns exec $ns2 ping -w1 -c1 127.0.0.1" 501 log_test $? 0 "rp_filter passes loopback packets" 502 503 cleanup 504} 505 506################################################################################ 507# Tests on nexthop spec 508 509# run 'ip route add' with given spec 510add_rt() 511{ 512 local desc="$1" 513 local erc=$2 514 local vrf=$3 515 local pfx=$4 516 local gw=$5 517 local dev=$6 518 local cmd out rc 519 520 [ "$vrf" = "-" ] && vrf="default" 521 [ -n "$gw" ] && gw="via $gw" 522 [ -n "$dev" ] && dev="dev $dev" 523 524 cmd="$IP route add vrf $vrf $pfx $gw $dev" 525 if [ "$VERBOSE" = "1" ]; then 526 printf "\n COMMAND: $cmd\n" 527 fi 528 529 out=$(eval $cmd 2>&1) 530 rc=$? 531 if [ "$VERBOSE" = "1" -a -n "$out" ]; then 532 echo " $out" 533 fi 534 log_test $rc $erc "$desc" 535} 536 537fib4_nexthop() 538{ 539 echo 540 echo "IPv4 nexthop tests" 541 542 echo "<<< write me >>>" 543} 544 545fib6_nexthop() 546{ 547 local lldummy=$(get_linklocal dummy0) 548 local llv1=$(get_linklocal veth1) 549 550 if [ -z "$lldummy" ]; then 551 echo "Failed to get linklocal address for dummy0" 552 return 1 553 fi 554 if [ -z "$llv1" ]; then 555 echo "Failed to get linklocal address for veth1" 556 return 1 557 fi 558 559 echo 560 echo "IPv6 nexthop tests" 561 562 add_rt "Directly connected nexthop, unicast address" 0 \ 563 - 2001:db8:101::/64 2001:db8:1::2 564 add_rt "Directly connected nexthop, unicast address with device" 0 \ 565 - 2001:db8:102::/64 2001:db8:1::2 "dummy0" 566 add_rt "Gateway is linklocal address" 0 \ 567 - 2001:db8:103::1/64 $llv1 "veth0" 568 569 # fails because LL address requires a device 570 add_rt "Gateway is linklocal address, no device" 2 \ 571 - 2001:db8:104::1/64 $llv1 572 573 # local address can not be a gateway 574 add_rt "Gateway can not be local unicast address" 2 \ 575 - 2001:db8:105::/64 2001:db8:1::1 576 add_rt "Gateway can not be local unicast address, with device" 2 \ 577 - 2001:db8:106::/64 2001:db8:1::1 "dummy0" 578 add_rt "Gateway can not be a local linklocal address" 2 \ 579 - 2001:db8:107::1/64 $lldummy "dummy0" 580 581 # VRF tests 582 add_rt "Gateway can be local address in a VRF" 0 \ 583 - 2001:db8:108::/64 2001:db8:51::2 584 add_rt "Gateway can be local address in a VRF, with device" 0 \ 585 - 2001:db8:109::/64 2001:db8:51::2 "veth0" 586 add_rt "Gateway can be local linklocal address in a VRF" 0 \ 587 - 2001:db8:110::1/64 $llv1 "veth0" 588 589 add_rt "Redirect to VRF lookup" 0 \ 590 - 2001:db8:111::/64 "" "red" 591 592 add_rt "VRF route, gateway can be local address in default VRF" 0 \ 593 red 2001:db8:112::/64 2001:db8:51::1 594 595 # local address in same VRF fails 596 add_rt "VRF route, gateway can not be a local address" 2 \ 597 red 2001:db8:113::1/64 2001:db8:2::1 598 add_rt "VRF route, gateway can not be a local addr with device" 2 \ 599 red 2001:db8:114::1/64 2001:db8:2::1 "dummy1" 600} 601 602# Default VRF: 603# dummy0 - 198.51.100.1/24 2001:db8:1::1/64 604# veth0 - 192.0.2.1/24 2001:db8:51::1/64 605# 606# VRF red: 607# dummy1 - 192.168.2.1/24 2001:db8:2::1/64 608# veth1 - 192.0.2.2/24 2001:db8:51::2/64 609# 610# [ dummy0 veth0 ]--[ veth1 dummy1 ] 611 612fib_nexthop_test() 613{ 614 setup 615 616 set -e 617 618 $IP -4 rule add pref 32765 table local 619 $IP -4 rule del pref 0 620 $IP -6 rule add pref 32765 table local 621 $IP -6 rule del pref 0 622 623 $IP link add red type vrf table 1 624 $IP link set red up 625 $IP -4 route add vrf red unreachable default metric 4278198272 626 $IP -6 route add vrf red unreachable default metric 4278198272 627 628 $IP link add veth0 type veth peer name veth1 629 $IP link set dev veth0 up 630 $IP address add 192.0.2.1/24 dev veth0 631 $IP -6 address add 2001:db8:51::1/64 dev veth0 632 633 $IP link set dev veth1 vrf red up 634 $IP address add 192.0.2.2/24 dev veth1 635 $IP -6 address add 2001:db8:51::2/64 dev veth1 636 637 $IP link add dummy1 type dummy 638 $IP link set dev dummy1 vrf red up 639 $IP address add 192.168.2.1/24 dev dummy1 640 $IP -6 address add 2001:db8:2::1/64 dev dummy1 641 set +e 642 643 sleep 1 644 fib4_nexthop 645 fib6_nexthop 646 647 ( 648 $IP link del dev dummy1 649 $IP link del veth0 650 $IP link del red 651 ) 2>/dev/null 652 cleanup 653} 654 655fib6_notify_test() 656{ 657 setup 658 659 echo 660 echo "Fib6 info length calculation in route notify test" 661 set -e 662 663 for i in 10 20 30 40 50 60 70; 664 do 665 $IP link add dummy_$i type dummy 666 $IP link set dev dummy_$i up 667 $IP -6 address add 2001:$i::1/64 dev dummy_$i 668 done 669 670 $NS_EXEC ip monitor route &> errors.txt & 671 sleep 2 672 673 $IP -6 route add 2001::/64 \ 674 nexthop via 2001:10::2 dev dummy_10 \ 675 nexthop encap ip6 dst 2002::20 via 2001:20::2 dev dummy_20 \ 676 nexthop encap ip6 dst 2002::30 via 2001:30::2 dev dummy_30 \ 677 nexthop encap ip6 dst 2002::40 via 2001:40::2 dev dummy_40 \ 678 nexthop encap ip6 dst 2002::50 via 2001:50::2 dev dummy_50 \ 679 nexthop encap ip6 dst 2002::60 via 2001:60::2 dev dummy_60 \ 680 nexthop encap ip6 dst 2002::70 via 2001:70::2 dev dummy_70 681 682 set +e 683 684 err=`cat errors.txt |grep "Message too long"` 685 if [ -z "$err" ];then 686 ret=0 687 else 688 ret=1 689 fi 690 691 log_test $ret 0 "ipv6 route add notify" 692 693 kill_process %% 694 695 #rm errors.txt 696 697 cleanup &> /dev/null 698} 699 700 701fib_notify_test() 702{ 703 setup 704 705 echo 706 echo "Fib4 info length calculation in route notify test" 707 708 set -e 709 710 for i in 10 20 30 40 50 60 70; 711 do 712 $IP link add dummy_$i type dummy 713 $IP link set dev dummy_$i up 714 $IP address add 20.20.$i.2/24 dev dummy_$i 715 done 716 717 $NS_EXEC ip monitor route &> errors.txt & 718 sleep 2 719 720 $IP route add 10.0.0.0/24 \ 721 nexthop via 20.20.10.1 dev dummy_10 \ 722 nexthop encap ip dst 192.168.10.20 via 20.20.20.1 dev dummy_20 \ 723 nexthop encap ip dst 192.168.10.30 via 20.20.30.1 dev dummy_30 \ 724 nexthop encap ip dst 192.168.10.40 via 20.20.40.1 dev dummy_40 \ 725 nexthop encap ip dst 192.168.10.50 via 20.20.50.1 dev dummy_50 \ 726 nexthop encap ip dst 192.168.10.60 via 20.20.60.1 dev dummy_60 \ 727 nexthop encap ip dst 192.168.10.70 via 20.20.70.1 dev dummy_70 728 729 set +e 730 731 err=`cat errors.txt |grep "Message too long"` 732 if [ -z "$err" ];then 733 ret=0 734 else 735 ret=1 736 fi 737 738 log_test $ret 0 "ipv4 route add notify" 739 740 kill_process %% 741 742 rm errors.txt 743 744 cleanup &> /dev/null 745} 746 747# Create a new dummy_10 to remove all associated routes. 748reset_dummy_10() 749{ 750 $IP link del dev dummy_10 751 752 $IP link add dummy_10 type dummy 753 $IP link set dev dummy_10 up 754 $IP -6 address add 2001:10::1/64 dev dummy_10 755} 756 757check_rt_num() 758{ 759 local expected=$1 760 local num=$2 761 762 if [ $num -ne $expected ]; then 763 echo "FAIL: Expected $expected routes, got $num" 764 ret=1 765 else 766 ret=0 767 fi 768} 769 770check_rt_num_clean() 771{ 772 local expected=$1 773 local num=$2 774 775 if [ $num -ne $expected ]; then 776 log_test 1 0 "expected $expected routes, got $num" 777 set +e 778 cleanup &> /dev/null 779 return 1 780 fi 781 return 0 782} 783 784fib6_gc_test() 785{ 786 setup 787 788 echo 789 echo "Fib6 garbage collection test" 790 set -e 791 792 EXPIRE=5 793 GC_WAIT_TIME=$((EXPIRE * 2 + 2)) 794 795 # Check expiration of routes every $EXPIRE seconds (GC) 796 $NS_EXEC sysctl -wq net.ipv6.route.gc_interval=$EXPIRE 797 798 $IP link add dummy_10 type dummy 799 $IP link set dev dummy_10 up 800 $IP -6 address add 2001:10::1/64 dev dummy_10 801 802 $NS_EXEC sysctl -wq net.ipv6.route.flush=1 803 804 # Temporary routes 805 for i in $(seq 1 5); do 806 # Expire route after $EXPIRE seconds 807 $IP -6 route add 2001:20::$i \ 808 via 2001:10::2 dev dummy_10 expires $EXPIRE 809 done 810 sleep $GC_WAIT_TIME 811 $NS_EXEC sysctl -wq net.ipv6.route.flush=1 812 check_rt_num 0 $($IP -6 route list |grep expires|wc -l) 813 log_test $ret 0 "ipv6 route garbage collection" 814 815 reset_dummy_10 816 817 # Permanent routes 818 for i in $(seq 1 5); do 819 $IP -6 route add 2001:30::$i \ 820 via 2001:10::2 dev dummy_10 821 done 822 # Temporary routes 823 for i in $(seq 1 5); do 824 # Expire route after $EXPIRE seconds 825 $IP -6 route add 2001:20::$i \ 826 via 2001:10::2 dev dummy_10 expires $EXPIRE 827 done 828 # Wait for GC 829 sleep $GC_WAIT_TIME 830 check_rt_num 0 $($IP -6 route list |grep expires|wc -l) 831 log_test $ret 0 "ipv6 route garbage collection (with permanent routes)" 832 833 reset_dummy_10 834 835 # Permanent routes 836 for i in $(seq 1 5); do 837 $IP -6 route add 2001:20::$i \ 838 via 2001:10::2 dev dummy_10 839 done 840 # Replace with temporary routes 841 for i in $(seq 1 5); do 842 # Expire route after $EXPIRE seconds 843 $IP -6 route replace 2001:20::$i \ 844 via 2001:10::2 dev dummy_10 expires $EXPIRE 845 done 846 # Wait for GC 847 sleep $GC_WAIT_TIME 848 check_rt_num 0 $($IP -6 route list |grep expires|wc -l) 849 log_test $ret 0 "ipv6 route garbage collection (replace with expires)" 850 851 reset_dummy_10 852 853 # Temporary routes 854 for i in $(seq 1 5); do 855 # Expire route after $EXPIRE seconds 856 $IP -6 route add 2001:20::$i \ 857 via 2001:10::2 dev dummy_10 expires $EXPIRE 858 done 859 # Replace with permanent routes 860 for i in $(seq 1 5); do 861 $IP -6 route replace 2001:20::$i \ 862 via 2001:10::2 dev dummy_10 863 done 864 check_rt_num_clean 0 $($IP -6 route list |grep expires|wc -l) || return 865 866 # Wait for GC 867 sleep $GC_WAIT_TIME 868 check_rt_num 5 $($IP -6 route list |grep -v expires|grep 2001:20::|wc -l) 869 log_test $ret 0 "ipv6 route garbage collection (replace with permanent)" 870 871 # ra6 is required for the next test. (ipv6toolkit) 872 if [ ! -x "$(command -v ra6)" ]; then 873 echo "SKIP: ra6 not found." 874 set +e 875 cleanup &> /dev/null 876 return 877 fi 878 879 # Delete dummy_10 and remove all routes 880 $IP link del dev dummy_10 881 882 # Create a pair of veth devices to send a RA message from one 883 # device to another. 884 $IP link add veth1 type veth peer name veth2 885 $IP link set dev veth1 up 886 $IP link set dev veth2 up 887 $IP -6 address add 2001:10::1/64 dev veth1 nodad 888 $IP -6 address add 2001:10::2/64 dev veth2 nodad 889 890 # Make veth1 ready to receive RA messages. 891 $NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra=2 892 893 # Send a RA message with a route from veth2 to veth1. 894 $NS_EXEC ra6 -i veth2 -d 2001:10::1 -t $EXPIRE 895 896 # Wait for the RA message. 897 sleep 1 898 899 # systemd may mess up the test. You syould make sure that 900 # systemd-networkd.service and systemd-networkd.socket are stopped. 901 check_rt_num_clean 1 $($IP -6 route list|grep expires|wc -l) || return 902 903 # Wait for GC 904 sleep $GC_WAIT_TIME 905 check_rt_num 0 $($IP -6 route list |grep expires|wc -l) 906 log_test $ret 0 "ipv6 route garbage collection (RA message)" 907 908 set +e 909 910 cleanup &> /dev/null 911} 912 913fib_suppress_test() 914{ 915 echo 916 echo "FIB rule with suppress_prefixlength" 917 setup 918 919 $IP link add dummy1 type dummy 920 $IP link set dummy1 up 921 $IP -6 route add default dev dummy1 922 $IP -6 rule add table main suppress_prefixlength 0 923 ping -f -c 1000 -W 1 1234::1 >/dev/null 2>&1 924 $IP -6 rule del table main suppress_prefixlength 0 925 $IP link del dummy1 926 927 # If we got here without crashing, we're good. 928 log_test 0 0 "FIB rule suppress test" 929 930 cleanup 931} 932 933################################################################################ 934# Tests on route add and replace 935 936run_cmd() 937{ 938 local cmd="$1" 939 local out 940 local stderr="2>/dev/null" 941 942 if [ "$VERBOSE" = "1" ]; then 943 printf " COMMAND: $cmd\n" 944 stderr= 945 fi 946 947 out=$(eval $cmd $stderr) 948 rc=$? 949 if [ "$VERBOSE" = "1" -a -n "$out" ]; then 950 echo " $out" 951 fi 952 953 [ "$VERBOSE" = "1" ] && echo 954 955 return $rc 956} 957 958check_expected() 959{ 960 local out="$1" 961 local expected="$2" 962 local rc=0 963 964 [ "${out}" = "${expected}" ] && return 0 965 966 if [ -z "${out}" ]; then 967 if [ "$VERBOSE" = "1" ]; then 968 printf "\nNo route entry found\n" 969 printf "Expected:\n" 970 printf " ${expected}\n" 971 fi 972 return 1 973 fi 974 975 # tricky way to convert output to 1-line without ip's 976 # messy '\'; this drops all extra white space 977 out=$(echo ${out}) 978 if [ "${out}" != "${expected}" ]; then 979 rc=1 980 if [ "${VERBOSE}" = "1" ]; then 981 printf " Unexpected route entry. Have:\n" 982 printf " ${out}\n" 983 printf " Expected:\n" 984 printf " ${expected}\n\n" 985 fi 986 fi 987 988 return $rc 989} 990 991# add route for a prefix, flushing any existing routes first 992# expected to be the first step of a test 993add_route6() 994{ 995 local pfx="$1" 996 local nh="$2" 997 local out 998 999 if [ "$VERBOSE" = "1" ]; then 1000 echo 1001 echo " ##################################################" 1002 echo 1003 fi 1004 1005 run_cmd "$IP -6 ro flush ${pfx}" 1006 [ $? -ne 0 ] && exit 1 1007 1008 out=$($IP -6 ro ls match ${pfx}) 1009 if [ -n "$out" ]; then 1010 echo "Failed to flush routes for prefix used for tests." 1011 exit 1 1012 fi 1013 1014 run_cmd "$IP -6 ro add ${pfx} ${nh}" 1015 if [ $? -ne 0 ]; then 1016 echo "Failed to add initial route for test." 1017 exit 1 1018 fi 1019} 1020 1021# add initial route - used in replace route tests 1022add_initial_route6() 1023{ 1024 add_route6 "2001:db8:104::/64" "$1" 1025} 1026 1027check_route6() 1028{ 1029 local pfx 1030 local expected="$1" 1031 local out 1032 local rc=0 1033 1034 set -- $expected 1035 pfx=$1 1036 1037 out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//') 1038 check_expected "${out}" "${expected}" 1039} 1040 1041route_cleanup() 1042{ 1043 $IP li del red 2>/dev/null 1044 $IP li del dummy1 2>/dev/null 1045 $IP li del veth1 2>/dev/null 1046 $IP li del veth3 2>/dev/null 1047 1048 cleanup &> /dev/null 1049} 1050 1051route_setup() 1052{ 1053 route_cleanup 1054 setup 1055 1056 [ "${VERBOSE}" = "1" ] && set -x 1057 set -e 1058 1059 setup_ns ns2 1060 ip netns exec $ns2 sysctl -qw net.ipv4.ip_forward=1 1061 ip netns exec $ns2 sysctl -qw net.ipv6.conf.all.forwarding=1 1062 1063 $IP li add veth1 type veth peer name veth2 1064 $IP li add veth3 type veth peer name veth4 1065 1066 $IP li set veth1 up 1067 $IP li set veth3 up 1068 $IP li set veth2 netns $ns2 up 1069 $IP li set veth4 netns $ns2 up 1070 ip -netns $ns2 li add dummy1 type dummy 1071 ip -netns $ns2 li set dummy1 up 1072 1073 $IP -6 addr add 2001:db8:101::1/64 dev veth1 nodad 1074 $IP -6 addr add 2001:db8:103::1/64 dev veth3 nodad 1075 $IP addr add 172.16.101.1/24 dev veth1 1076 $IP addr add 172.16.103.1/24 dev veth3 1077 1078 ip -netns $ns2 -6 addr add 2001:db8:101::2/64 dev veth2 nodad 1079 ip -netns $ns2 -6 addr add 2001:db8:103::2/64 dev veth4 nodad 1080 ip -netns $ns2 -6 addr add 2001:db8:104::1/64 dev dummy1 nodad 1081 1082 ip -netns $ns2 addr add 172.16.101.2/24 dev veth2 1083 ip -netns $ns2 addr add 172.16.103.2/24 dev veth4 1084 ip -netns $ns2 addr add 172.16.104.1/24 dev dummy1 1085 1086 set +e 1087} 1088 1089forwarding_cleanup() 1090{ 1091 cleanup_ns $ns3 1092 1093 route_cleanup 1094} 1095 1096# extend route_setup with an ns3 reachable through ns2 over both devices 1097forwarding_setup() 1098{ 1099 forwarding_cleanup 1100 1101 route_setup 1102 1103 setup_ns ns3 1104 1105 ip link add veth5 netns $ns3 type veth peer name veth6 netns $ns2 1106 ip -netns $ns3 link set veth5 up 1107 ip -netns $ns2 link set veth6 up 1108 1109 ip -netns $ns3 -4 addr add dev veth5 172.16.105.1/24 1110 ip -netns $ns2 -4 addr add dev veth6 172.16.105.2/24 1111 ip -netns $ns3 -4 route add 172.16.100.0/22 via 172.16.105.2 1112 1113 ip -netns $ns3 -6 addr add dev veth5 2001:db8:105::1/64 nodad 1114 ip -netns $ns2 -6 addr add dev veth6 2001:db8:105::2/64 nodad 1115 ip -netns $ns3 -6 route add 2001:db8:101::/33 via 2001:db8:105::2 1116} 1117 1118# assumption is that basic add of a single path route works 1119# otherwise just adding an address on an interface is broken 1120ipv6_rt_add() 1121{ 1122 local rc 1123 1124 echo 1125 echo "IPv6 route add / append tests" 1126 1127 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL 1128 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2" 1129 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2" 1130 log_test $? 2 "Attempt to add duplicate route - gw" 1131 1132 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL 1133 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2" 1134 run_cmd "$IP -6 ro add 2001:db8:104::/64 dev veth3" 1135 log_test $? 2 "Attempt to add duplicate route - dev only" 1136 1137 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL 1138 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2" 1139 run_cmd "$IP -6 ro add unreachable 2001:db8:104::/64" 1140 log_test $? 2 "Attempt to add duplicate route - reject route" 1141 1142 # route append with same prefix adds a new route 1143 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND 1144 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2" 1145 run_cmd "$IP -6 ro append 2001:db8:104::/64 via 2001:db8:103::2" 1146 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" 1147 log_test $? 0 "Append nexthop to existing route - gw" 1148 1149 # insert mpath directly 1150 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1151 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" 1152 log_test $? 0 "Add multipath route" 1153 1154 add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1155 run_cmd "$IP -6 ro add 2001:db8:104::/64 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1156 log_test $? 2 "Attempt to add duplicate multipath route" 1157 1158 # insert of a second route without append but different metric 1159 add_route6 "2001:db8:104::/64" "via 2001:db8:101::2" 1160 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2 metric 512" 1161 rc=$? 1162 if [ $rc -eq 0 ]; then 1163 run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::3 metric 256" 1164 rc=$? 1165 fi 1166 log_test $rc 0 "Route add with different metrics" 1167 1168 run_cmd "$IP -6 ro del 2001:db8:104::/64 metric 512" 1169 rc=$? 1170 if [ $rc -eq 0 ]; then 1171 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" 1172 rc=$? 1173 fi 1174 log_test $rc 0 "Route delete with metric" 1175} 1176 1177ipv6_rt_replace_single() 1178{ 1179 # single path with single path 1180 # 1181 add_initial_route6 "via 2001:db8:101::2" 1182 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:103::2" 1183 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024" 1184 log_test $? 0 "Single path with single path" 1185 1186 # single path with multipath 1187 # 1188 add_initial_route6 "nexthop via 2001:db8:101::2" 1189 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::2" 1190 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" 1191 log_test $? 0 "Single path with multipath" 1192 1193 # single path with single path using MULTIPATH attribute 1194 # 1195 add_initial_route6 "via 2001:db8:101::2" 1196 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:103::2" 1197 check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024" 1198 log_test $? 0 "Single path with single path via multipath attribute" 1199 1200 # route replace fails - invalid nexthop 1201 add_initial_route6 "via 2001:db8:101::2" 1202 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:104::2" 1203 if [ $? -eq 0 ]; then 1204 # previous command is expected to fail so if it returns 0 1205 # that means the test failed. 1206 log_test 0 1 "Invalid nexthop" 1207 else 1208 check_route6 "2001:db8:104::/64 via 2001:db8:101::2 dev veth1 metric 1024" 1209 log_test $? 0 "Invalid nexthop" 1210 fi 1211 1212 # replace non-existent route 1213 # - note use of change versus replace since ip adds NLM_F_CREATE 1214 # for replace 1215 add_initial_route6 "via 2001:db8:101::2" 1216 run_cmd "$IP -6 ro change 2001:db8:105::/64 via 2001:db8:101::2" 1217 log_test $? 2 "Single path - replace of non-existent route" 1218} 1219 1220ipv6_rt_replace_mpath() 1221{ 1222 # multipath with multipath 1223 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1224 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3" 1225 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" 1226 log_test $? 0 "Multipath with multipath" 1227 1228 # multipath with single 1229 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1230 run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:101::3" 1231 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024" 1232 log_test $? 0 "Multipath with single path" 1233 1234 # multipath with single 1235 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1236 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3" 1237 check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024" 1238 log_test $? 0 "Multipath with single path via multipath attribute" 1239 1240 # multipath with dev-only 1241 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1242 run_cmd "$IP -6 ro replace 2001:db8:104::/64 dev veth1" 1243 check_route6 "2001:db8:104::/64 dev veth1 metric 1024" 1244 log_test $? 0 "Multipath with dev-only" 1245 1246 # route replace fails - invalid nexthop 1 1247 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1248 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:111::3 nexthop via 2001:db8:103::3" 1249 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" 1250 log_test $? 0 "Multipath - invalid first nexthop" 1251 1252 # route replace fails - invalid nexthop 2 1253 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1254 run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:113::3" 1255 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" 1256 log_test $? 0 "Multipath - invalid second nexthop" 1257 1258 # multipath non-existent route 1259 add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1260 run_cmd "$IP -6 ro change 2001:db8:105::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3" 1261 log_test $? 2 "Multipath - replace of non-existent route" 1262} 1263 1264ipv6_rt_replace() 1265{ 1266 echo 1267 echo "IPv6 route replace tests" 1268 1269 ipv6_rt_replace_single 1270 ipv6_rt_replace_mpath 1271} 1272 1273ipv6_rt_dsfield() 1274{ 1275 echo 1276 echo "IPv6 route with dsfield tests" 1277 1278 run_cmd "$IP -6 route flush 2001:db8:102::/64" 1279 1280 # IPv6 doesn't support routing based on dsfield 1281 run_cmd "$IP -6 route add 2001:db8:102::/64 dsfield 0x04 via 2001:db8:101::2" 1282 log_test $? 2 "Reject route with dsfield" 1283} 1284 1285ipv6_route_test() 1286{ 1287 route_setup 1288 1289 ipv6_rt_add 1290 ipv6_rt_replace 1291 ipv6_rt_dsfield 1292 1293 route_cleanup 1294} 1295 1296ip_addr_metric_check() 1297{ 1298 ip addr help 2>&1 | grep -q metric 1299 if [ $? -ne 0 ]; then 1300 echo "iproute2 command does not support metric for addresses. Skipping test" 1301 return 1 1302 fi 1303 1304 return 0 1305} 1306 1307ipv6_addr_metric_test() 1308{ 1309 local rc 1310 1311 echo 1312 echo "IPv6 prefix route tests" 1313 1314 ip_addr_metric_check || return 1 1315 1316 setup 1317 1318 set -e 1319 $IP li add dummy1 type dummy 1320 $IP li add dummy2 type dummy 1321 $IP li set dummy1 up 1322 $IP li set dummy2 up 1323 1324 # default entry is metric 256 1325 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64" 1326 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64" 1327 set +e 1328 1329 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 256 2001:db8:104::/64 dev dummy2 proto kernel metric 256" 1330 log_test $? 0 "Default metric" 1331 1332 set -e 1333 run_cmd "$IP -6 addr flush dev dummy1" 1334 run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64 metric 257" 1335 set +e 1336 1337 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 256 2001:db8:104::/64 dev dummy1 proto kernel metric 257" 1338 log_test $? 0 "User specified metric on first device" 1339 1340 set -e 1341 run_cmd "$IP -6 addr flush dev dummy2" 1342 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64 metric 258" 1343 set +e 1344 1345 check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 257 2001:db8:104::/64 dev dummy2 proto kernel metric 258" 1346 log_test $? 0 "User specified metric on second device" 1347 1348 run_cmd "$IP -6 addr del dev dummy1 2001:db8:104::1/64 metric 257" 1349 rc=$? 1350 if [ $rc -eq 0 ]; then 1351 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 258" 1352 rc=$? 1353 fi 1354 log_test $rc 0 "Delete of address on first device" 1355 1356 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::2/64 metric 259" 1357 rc=$? 1358 if [ $rc -eq 0 ]; then 1359 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259" 1360 rc=$? 1361 fi 1362 log_test $rc 0 "Modify metric of address" 1363 1364 # verify prefix route removed on down 1365 run_cmd "ip netns exec $ns1 sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1" 1366 run_cmd "$IP li set dev dummy2 down" 1367 rc=$? 1368 if [ $rc -eq 0 ]; then 1369 out=$($IP -6 ro ls match 2001:db8:104::/64) 1370 check_expected "${out}" "" 1371 rc=$? 1372 fi 1373 log_test $rc 0 "Prefix route removed on link down" 1374 1375 # verify prefix route re-inserted with assigned metric 1376 run_cmd "$IP li set dev dummy2 up" 1377 rc=$? 1378 if [ $rc -eq 0 ]; then 1379 check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259" 1380 rc=$? 1381 fi 1382 log_test $rc 0 "Prefix route with metric on link up" 1383 1384 # verify peer metric added correctly 1385 set -e 1386 run_cmd "$IP -6 addr flush dev dummy2" 1387 run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::1 peer 2001:db8:104::2 metric 260" 1388 set +e 1389 1390 check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 260" 1391 log_test $? 0 "Set metric with peer route on local side" 1392 check_route6 "2001:db8:104::2 dev dummy2 proto kernel metric 260" 1393 log_test $? 0 "Set metric with peer route on peer side" 1394 1395 set -e 1396 run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::1 peer 2001:db8:104::3 metric 261" 1397 set +e 1398 1399 check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 261" 1400 log_test $? 0 "Modify metric and peer address on local side" 1401 check_route6 "2001:db8:104::3 dev dummy2 proto kernel metric 261" 1402 log_test $? 0 "Modify metric and peer address on peer side" 1403 1404 $IP li del dummy1 1405 $IP li del dummy2 1406 cleanup 1407} 1408 1409ipv6_route_metrics_test() 1410{ 1411 local rc 1412 1413 echo 1414 echo "IPv6 routes with metrics" 1415 1416 route_setup 1417 1418 # 1419 # single path with metrics 1420 # 1421 run_cmd "$IP -6 ro add 2001:db8:111::/64 via 2001:db8:101::2 mtu 1400" 1422 rc=$? 1423 if [ $rc -eq 0 ]; then 1424 check_route6 "2001:db8:111::/64 via 2001:db8:101::2 dev veth1 metric 1024 mtu 1400" 1425 rc=$? 1426 fi 1427 log_test $rc 0 "Single path route with mtu metric" 1428 1429 1430 # 1431 # multipath via separate routes with metrics 1432 # 1433 run_cmd "$IP -6 ro add 2001:db8:112::/64 via 2001:db8:101::2 mtu 1400" 1434 run_cmd "$IP -6 ro append 2001:db8:112::/64 via 2001:db8:103::2" 1435 rc=$? 1436 if [ $rc -eq 0 ]; then 1437 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" 1438 rc=$? 1439 fi 1440 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on first" 1441 1442 # second route is coalesced to first to make a multipath route. 1443 # MTU of the second path is hidden from display! 1444 run_cmd "$IP -6 ro add 2001:db8:113::/64 via 2001:db8:101::2" 1445 run_cmd "$IP -6 ro append 2001:db8:113::/64 via 2001:db8:103::2 mtu 1400" 1446 rc=$? 1447 if [ $rc -eq 0 ]; then 1448 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" 1449 rc=$? 1450 fi 1451 log_test $rc 0 "Multipath route via 2 single routes with mtu metric on 2nd" 1452 1453 run_cmd "$IP -6 ro del 2001:db8:113::/64 via 2001:db8:101::2" 1454 if [ $? -eq 0 ]; then 1455 check_route6 "2001:db8:113::/64 via 2001:db8:103::2 dev veth3 metric 1024 mtu 1400" 1456 log_test $? 0 " MTU of second leg" 1457 fi 1458 1459 # 1460 # multipath with metrics 1461 # 1462 run_cmd "$IP -6 ro add 2001:db8:115::/64 mtu 1400 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2" 1463 rc=$? 1464 if [ $rc -eq 0 ]; then 1465 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" 1466 rc=$? 1467 fi 1468 log_test $rc 0 "Multipath route with mtu metric" 1469 1470 $IP -6 ro add 2001:db8:104::/64 via 2001:db8:101::2 mtu 1300 1471 run_cmd "ip netns exec $ns1 ${ping6} -w1 -c1 -s 1500 2001:db8:104::1" 1472 log_test $? 0 "Using route with mtu metric" 1473 1474 run_cmd "$IP -6 ro add 2001:db8:114::/64 via 2001:db8:101::2 congctl lock foo" 1475 log_test $? 2 "Invalid metric (fails metric_convert)" 1476 1477 route_cleanup 1478} 1479 1480fib6_ra_to_static() 1481{ 1482 setup 1483 1484 echo 1485 echo "Fib6 route promotion from RA-learned to static test" 1486 set -e 1487 1488 # ra6 is required for the test. (ipv6toolkit) 1489 if [ ! -x "$(command -v ra6)" ]; then 1490 echo "SKIP: ra6 not found." 1491 set +e 1492 cleanup &> /dev/null 1493 return 1494 fi 1495 1496 # Create a pair of veth devices to send a RA message from one 1497 # device to another. 1498 $IP link add veth1 type veth peer name veth2 1499 $IP link set dev veth1 up 1500 $IP link set dev veth2 up 1501 $IP -6 address add 2001:10::1/64 dev veth1 nodad 1502 $IP -6 address add 2001:10::2/64 dev veth2 nodad 1503 1504 # Make veth1 ready to receive RA messages. 1505 $NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra=2 1506 1507 # Send a RA message with a prefix from veth2. 1508 $NS_EXEC ra6 -i veth2 -d 2001:10::1 -P 2001:12::/64\#LA\#120\#60 1509 1510 # Wait for the RA message. 1511 sleep 1 1512 1513 # systemd may mess up the test. Make sure that 1514 # systemd-networkd.service and systemd-networkd.socket are stopped. 1515 check_rt_num_clean 2 $($IP -6 route list|grep expires|wc -l) || return 1516 1517 # Configure static address on the same prefix 1518 $IP -6 address add 2001:12::dead/64 dev veth1 nodad 1519 1520 # On-link route won't expire anymore, default route still owned by RA 1521 check_rt_num 1 $($IP -6 route list |grep expires|wc -l) 1522 1523 # Send a second RA message with a prefix from veth2. 1524 $NS_EXEC ra6 -i veth2 -d 2001:10::1 -P 2001:12::/64\#LA\#120\#60 1525 sleep 1 1526 1527 # Expire is not back, on-link route is still static 1528 check_rt_num 1 $($IP -6 route list |grep expires|wc -l) 1529 1530 $IP -6 address del 2001:12::dead/64 dev veth1 nodad 1531 1532 # Expire is back, on-link route is now owned by RA again 1533 check_rt_num 2 $($IP -6 route list |grep expires|wc -l) 1534 1535 log_test $ret 0 "ipv6 promote RA route to static" 1536 1537 # Prepare for RA route with gateway 1538 $NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra_rt_info_max_plen=64 1539 1540 # Add initial route to cause ECMP merging 1541 $IP -6 route add 2001:12::/64 via fe80::dead:beef dev veth1 1542 1543 $NS_EXEC ra6 -i veth2 -d 2001:10::1 -R 2001:12::/64#1#120 1544 1545 # Routes are not merged as RA routes are not elegible for ECMP 1546 check_rt_num 2 "$($IP -6 route list | grep -c "2001:12::/64 via")" 1547 1548 $IP -6 route append 2001:12::/64 via fe80::dead:feeb dev veth1 1549 1550 check_rt_num 2 "$($IP -6 route list | grep -c "nexthop via")" 1551 1552 log_test "$ret" 0 "ipv6 RA route with nexthop do not merge into ECMP with static" 1553 1554 set +e 1555 1556 cleanup &> /dev/null 1557} 1558 1559# add route for a prefix, flushing any existing routes first 1560# expected to be the first step of a test 1561add_route() 1562{ 1563 local pfx="$1" 1564 local nh="$2" 1565 local out 1566 1567 if [ "$VERBOSE" = "1" ]; then 1568 echo 1569 echo " ##################################################" 1570 echo 1571 fi 1572 1573 run_cmd "$IP ro flush ${pfx}" 1574 [ $? -ne 0 ] && exit 1 1575 1576 out=$($IP ro ls match ${pfx}) 1577 if [ -n "$out" ]; then 1578 echo "Failed to flush routes for prefix used for tests." 1579 exit 1 1580 fi 1581 1582 run_cmd "$IP ro add ${pfx} ${nh}" 1583 if [ $? -ne 0 ]; then 1584 echo "Failed to add initial route for test." 1585 exit 1 1586 fi 1587} 1588 1589# add initial route - used in replace route tests 1590add_initial_route() 1591{ 1592 add_route "172.16.104.0/24" "$1" 1593} 1594 1595check_route() 1596{ 1597 local pfx 1598 local expected="$1" 1599 local out 1600 1601 set -- $expected 1602 pfx=$1 1603 [ "${pfx}" = "unreachable" ] && pfx=$2 1604 1605 out=$($IP ro ls match ${pfx}) 1606 check_expected "${out}" "${expected}" 1607} 1608 1609# assumption is that basic add of a single path route works 1610# otherwise just adding an address on an interface is broken 1611ipv4_rt_add() 1612{ 1613 local rc 1614 1615 echo 1616 echo "IPv4 route add / append tests" 1617 1618 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL 1619 add_route "172.16.104.0/24" "via 172.16.101.2" 1620 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2" 1621 log_test $? 2 "Attempt to add duplicate route - gw" 1622 1623 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL 1624 add_route "172.16.104.0/24" "via 172.16.101.2" 1625 run_cmd "$IP ro add 172.16.104.0/24 dev veth3" 1626 log_test $? 2 "Attempt to add duplicate route - dev only" 1627 1628 # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL 1629 add_route "172.16.104.0/24" "via 172.16.101.2" 1630 run_cmd "$IP ro add unreachable 172.16.104.0/24" 1631 log_test $? 2 "Attempt to add duplicate route - reject route" 1632 1633 # iproute2 prepend only sets NLM_F_CREATE 1634 # - adds a new route; does NOT convert existing route to ECMP 1635 add_route "172.16.104.0/24" "via 172.16.101.2" 1636 run_cmd "$IP ro prepend 172.16.104.0/24 via 172.16.103.2" 1637 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" 1638 log_test $? 0 "Add new nexthop for existing prefix" 1639 1640 # route append with same prefix adds a new route 1641 # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND 1642 add_route "172.16.104.0/24" "via 172.16.101.2" 1643 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2" 1644 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" 1645 log_test $? 0 "Append nexthop to existing route - gw" 1646 1647 add_route "172.16.104.0/24" "via 172.16.101.2" 1648 run_cmd "$IP ro append 172.16.104.0/24 dev veth3" 1649 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 dev veth3 scope link" 1650 log_test $? 0 "Append nexthop to existing route - dev only" 1651 1652 add_route "172.16.104.0/24" "via 172.16.101.2" 1653 run_cmd "$IP ro append unreachable 172.16.104.0/24" 1654 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 unreachable 172.16.104.0/24" 1655 log_test $? 0 "Append nexthop to existing route - reject route" 1656 1657 run_cmd "$IP ro flush 172.16.104.0/24" 1658 run_cmd "$IP ro add unreachable 172.16.104.0/24" 1659 run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2" 1660 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 via 172.16.103.2 dev veth3" 1661 log_test $? 0 "Append nexthop to existing reject route - gw" 1662 1663 run_cmd "$IP ro flush 172.16.104.0/24" 1664 run_cmd "$IP ro add unreachable 172.16.104.0/24" 1665 run_cmd "$IP ro append 172.16.104.0/24 dev veth3" 1666 check_route "unreachable 172.16.104.0/24 172.16.104.0/24 dev veth3 scope link" 1667 log_test $? 0 "Append nexthop to existing reject route - dev only" 1668 1669 # insert mpath directly 1670 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1671 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" 1672 log_test $? 0 "add multipath route" 1673 1674 add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1675 run_cmd "$IP ro add 172.16.104.0/24 nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1676 log_test $? 2 "Attempt to add duplicate multipath route" 1677 1678 # insert of a second route without append but different metric 1679 add_route "172.16.104.0/24" "via 172.16.101.2" 1680 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2 metric 512" 1681 rc=$? 1682 if [ $rc -eq 0 ]; then 1683 run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.3 metric 256" 1684 rc=$? 1685 fi 1686 log_test $rc 0 "Route add with different metrics" 1687 1688 run_cmd "$IP ro del 172.16.104.0/24 metric 512" 1689 rc=$? 1690 if [ $rc -eq 0 ]; then 1691 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" 1692 rc=$? 1693 fi 1694 log_test $rc 0 "Route delete with metric" 1695} 1696 1697ipv4_rt_replace_single() 1698{ 1699 # single path with single path 1700 # 1701 add_initial_route "via 172.16.101.2" 1702 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.103.2" 1703 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3" 1704 log_test $? 0 "Single path with single path" 1705 1706 # single path with multipath 1707 # 1708 add_initial_route "nexthop via 172.16.101.2" 1709 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.2" 1710 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" 1711 log_test $? 0 "Single path with multipath" 1712 1713 # single path with reject 1714 # 1715 add_initial_route "nexthop via 172.16.101.2" 1716 run_cmd "$IP ro replace unreachable 172.16.104.0/24" 1717 check_route "unreachable 172.16.104.0/24" 1718 log_test $? 0 "Single path with reject route" 1719 1720 # single path with single path using MULTIPATH attribute 1721 # 1722 add_initial_route "via 172.16.101.2" 1723 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.103.2" 1724 check_route "172.16.104.0/24 via 172.16.103.2 dev veth3" 1725 log_test $? 0 "Single path with single path via multipath attribute" 1726 1727 # route replace fails - invalid nexthop 1728 add_initial_route "via 172.16.101.2" 1729 run_cmd "$IP ro replace 172.16.104.0/24 via 2001:db8:104::2" 1730 if [ $? -eq 0 ]; then 1731 # previous command is expected to fail so if it returns 0 1732 # that means the test failed. 1733 log_test 0 1 "Invalid nexthop" 1734 else 1735 check_route "172.16.104.0/24 via 172.16.101.2 dev veth1" 1736 log_test $? 0 "Invalid nexthop" 1737 fi 1738 1739 # replace non-existent route 1740 # - note use of change versus replace since ip adds NLM_F_CREATE 1741 # for replace 1742 add_initial_route "via 172.16.101.2" 1743 run_cmd "$IP ro change 172.16.105.0/24 via 172.16.101.2" 1744 log_test $? 2 "Single path - replace of non-existent route" 1745} 1746 1747ipv4_rt_replace_mpath() 1748{ 1749 # multipath with multipath 1750 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1751 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3" 1752 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" 1753 log_test $? 0 "Multipath with multipath" 1754 1755 # multipath with single 1756 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1757 run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.101.3" 1758 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1" 1759 log_test $? 0 "Multipath with single path" 1760 1761 # multipath with single 1762 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1763 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3" 1764 check_route "172.16.104.0/24 via 172.16.101.3 dev veth1" 1765 log_test $? 0 "Multipath with single path via multipath attribute" 1766 1767 # multipath with reject 1768 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1769 run_cmd "$IP ro replace unreachable 172.16.104.0/24" 1770 check_route "unreachable 172.16.104.0/24" 1771 log_test $? 0 "Multipath with reject route" 1772 1773 # route replace fails - invalid nexthop 1 1774 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1775 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.111.3 nexthop via 172.16.103.3" 1776 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" 1777 log_test $? 0 "Multipath - invalid first nexthop" 1778 1779 # route replace fails - invalid nexthop 2 1780 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1781 run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.113.3" 1782 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" 1783 log_test $? 0 "Multipath - invalid second nexthop" 1784 1785 # multipath non-existent route 1786 add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2" 1787 run_cmd "$IP ro change 172.16.105.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3" 1788 log_test $? 2 "Multipath - replace of non-existent route" 1789} 1790 1791ipv4_rt_replace() 1792{ 1793 echo 1794 echo "IPv4 route replace tests" 1795 1796 ipv4_rt_replace_single 1797 ipv4_rt_replace_mpath 1798} 1799 1800# checks that cached input route on VRF port is deleted 1801# when VRF is deleted 1802ipv4_local_rt_cache() 1803{ 1804 run_cmd "ip addr add 10.0.0.1/32 dev lo" 1805 run_cmd "setup_ns test-ns" 1806 run_cmd "ip link add veth-outside type veth peer name veth-inside" 1807 run_cmd "ip link add vrf-100 type vrf table 1100" 1808 run_cmd "ip link set veth-outside master vrf-100" 1809 run_cmd "ip link set veth-inside netns $test-ns" 1810 run_cmd "ip link set veth-outside up" 1811 run_cmd "ip link set vrf-100 up" 1812 run_cmd "ip route add 10.1.1.1/32 dev veth-outside table 1100" 1813 run_cmd "ip netns exec $test-ns ip link set veth-inside up" 1814 run_cmd "ip netns exec $test-ns ip addr add 10.1.1.1/32 dev veth-inside" 1815 run_cmd "ip netns exec $test-ns ip route add 10.0.0.1/32 dev veth-inside" 1816 run_cmd "ip netns exec $test-ns ip route add default via 10.0.0.1" 1817 run_cmd "ip netns exec $test-ns ping 10.0.0.1 -c 1 -i 1" 1818 run_cmd "ip link delete vrf-100" 1819 1820 # if we do not hang test is a success 1821 log_test $? 0 "Cached route removed from VRF port device" 1822} 1823 1824ipv4_rt_dsfield() 1825{ 1826 echo 1827 echo "IPv4 route with dsfield tests" 1828 1829 run_cmd "$IP route flush 172.16.102.0/24" 1830 1831 # New routes should reject dsfield options that interfere with ECN 1832 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x01 via 172.16.101.2" 1833 log_test $? 2 "Reject route with dsfield 0x01" 1834 1835 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x02 via 172.16.101.2" 1836 log_test $? 2 "Reject route with dsfield 0x02" 1837 1838 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x03 via 172.16.101.2" 1839 log_test $? 2 "Reject route with dsfield 0x03" 1840 1841 # A generic route that doesn't take DSCP into account 1842 run_cmd "$IP route add 172.16.102.0/24 via 172.16.101.2" 1843 1844 # A more specific route for DSCP 0x10 1845 run_cmd "$IP route add 172.16.102.0/24 dsfield 0x10 via 172.16.103.2" 1846 1847 # DSCP 0x10 should match the specific route, no matter the ECN bits 1848 $IP route get fibmatch 172.16.102.1 dsfield 0x10 | \ 1849 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2" 1850 log_test $? 0 "IPv4 route with DSCP and ECN:Not-ECT" 1851 1852 $IP route get fibmatch 172.16.102.1 dsfield 0x11 | \ 1853 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2" 1854 log_test $? 0 "IPv4 route with DSCP and ECN:ECT(1)" 1855 1856 $IP route get fibmatch 172.16.102.1 dsfield 0x12 | \ 1857 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2" 1858 log_test $? 0 "IPv4 route with DSCP and ECN:ECT(0)" 1859 1860 $IP route get fibmatch 172.16.102.1 dsfield 0x13 | \ 1861 grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2" 1862 log_test $? 0 "IPv4 route with DSCP and ECN:CE" 1863 1864 # Unknown DSCP should match the generic route, no matter the ECN bits 1865 $IP route get fibmatch 172.16.102.1 dsfield 0x14 | \ 1866 grep -q "172.16.102.0/24 via 172.16.101.2" 1867 log_test $? 0 "IPv4 route with unknown DSCP and ECN:Not-ECT" 1868 1869 $IP route get fibmatch 172.16.102.1 dsfield 0x15 | \ 1870 grep -q "172.16.102.0/24 via 172.16.101.2" 1871 log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(1)" 1872 1873 $IP route get fibmatch 172.16.102.1 dsfield 0x16 | \ 1874 grep -q "172.16.102.0/24 via 172.16.101.2" 1875 log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(0)" 1876 1877 $IP route get fibmatch 172.16.102.1 dsfield 0x17 | \ 1878 grep -q "172.16.102.0/24 via 172.16.101.2" 1879 log_test $? 0 "IPv4 route with unknown DSCP and ECN:CE" 1880 1881 # Null DSCP should match the generic route, no matter the ECN bits 1882 $IP route get fibmatch 172.16.102.1 dsfield 0x00 | \ 1883 grep -q "172.16.102.0/24 via 172.16.101.2" 1884 log_test $? 0 "IPv4 route with no DSCP and ECN:Not-ECT" 1885 1886 $IP route get fibmatch 172.16.102.1 dsfield 0x01 | \ 1887 grep -q "172.16.102.0/24 via 172.16.101.2" 1888 log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(1)" 1889 1890 $IP route get fibmatch 172.16.102.1 dsfield 0x02 | \ 1891 grep -q "172.16.102.0/24 via 172.16.101.2" 1892 log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(0)" 1893 1894 $IP route get fibmatch 172.16.102.1 dsfield 0x03 | \ 1895 grep -q "172.16.102.0/24 via 172.16.101.2" 1896 log_test $? 0 "IPv4 route with no DSCP and ECN:CE" 1897} 1898 1899ipv4_route_test() 1900{ 1901 route_setup 1902 1903 ipv4_rt_add 1904 ipv4_rt_replace 1905 ipv4_local_rt_cache 1906 ipv4_rt_dsfield 1907 1908 route_cleanup 1909} 1910 1911ipv4_addr_metric_test() 1912{ 1913 local rc 1914 1915 echo 1916 echo "IPv4 prefix route tests" 1917 1918 ip_addr_metric_check || return 1 1919 1920 setup 1921 1922 set -e 1923 $IP li add dummy1 type dummy 1924 $IP li add dummy2 type dummy 1925 $IP li set dummy1 up 1926 $IP li set dummy2 up 1927 1928 # default entry is metric 256 1929 run_cmd "$IP addr add dev dummy1 172.16.104.1/24" 1930 run_cmd "$IP addr add dev dummy2 172.16.104.2/24" 1931 set +e 1932 1933 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" 1934 log_test $? 0 "Default metric" 1935 1936 set -e 1937 run_cmd "$IP addr flush dev dummy1" 1938 run_cmd "$IP addr add dev dummy1 172.16.104.1/24 metric 257" 1939 set +e 1940 1941 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" 1942 log_test $? 0 "User specified metric on first device" 1943 1944 set -e 1945 run_cmd "$IP addr flush dev dummy2" 1946 run_cmd "$IP addr add dev dummy2 172.16.104.2/24 metric 258" 1947 set +e 1948 1949 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" 1950 log_test $? 0 "User specified metric on second device" 1951 1952 run_cmd "$IP addr del dev dummy1 172.16.104.1/24 metric 257" 1953 rc=$? 1954 if [ $rc -eq 0 ]; then 1955 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 258" 1956 rc=$? 1957 fi 1958 log_test $rc 0 "Delete of address on first device" 1959 1960 run_cmd "$IP addr change dev dummy2 172.16.104.2/24 metric 259" 1961 rc=$? 1962 if [ $rc -eq 0 ]; then 1963 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259" 1964 rc=$? 1965 fi 1966 log_test $rc 0 "Modify metric of address" 1967 1968 # verify prefix route removed on down 1969 run_cmd "$IP li set dev dummy2 down" 1970 rc=$? 1971 if [ $rc -eq 0 ]; then 1972 out=$($IP ro ls match 172.16.104.0/24) 1973 check_expected "${out}" "" 1974 rc=$? 1975 fi 1976 log_test $rc 0 "Prefix route removed on link down" 1977 1978 # verify prefix route re-inserted with assigned metric 1979 run_cmd "$IP li set dev dummy2 up" 1980 rc=$? 1981 if [ $rc -eq 0 ]; then 1982 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259" 1983 rc=$? 1984 fi 1985 log_test $rc 0 "Prefix route with metric on link up" 1986 1987 # explicitly check for metric changes on edge scenarios 1988 run_cmd "$IP addr flush dev dummy2" 1989 run_cmd "$IP addr add dev dummy2 172.16.104.0/24 metric 259" 1990 run_cmd "$IP addr change dev dummy2 172.16.104.0/24 metric 260" 1991 rc=$? 1992 if [ $rc -eq 0 ]; then 1993 check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.0 metric 260" 1994 rc=$? 1995 fi 1996 log_test $rc 0 "Modify metric of .0/24 address" 1997 1998 run_cmd "$IP addr flush dev dummy2" 1999 run_cmd "$IP addr add dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 260" 2000 rc=$? 2001 if [ $rc -eq 0 ]; then 2002 check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 260" 2003 rc=$? 2004 fi 2005 log_test $rc 0 "Set metric of address with peer route" 2006 2007 run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.3 metric 261" 2008 rc=$? 2009 if [ $rc -eq 0 ]; then 2010 check_route "172.16.104.3 dev dummy2 proto kernel scope link src 172.16.104.1 metric 261" 2011 rc=$? 2012 fi 2013 log_test $rc 0 "Modify metric and peer address for peer route" 2014 2015 $IP li del dummy1 2016 $IP li del dummy2 2017 cleanup 2018} 2019 2020ipv4_route_metrics_test() 2021{ 2022 local rc 2023 2024 echo 2025 echo "IPv4 route add / append tests" 2026 2027 route_setup 2028 2029 run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 mtu 1400" 2030 rc=$? 2031 if [ $rc -eq 0 ]; then 2032 check_route "172.16.111.0/24 via 172.16.101.2 dev veth1 mtu 1400" 2033 rc=$? 2034 fi 2035 log_test $rc 0 "Single path route with mtu metric" 2036 2037 2038 run_cmd "$IP ro add 172.16.112.0/24 mtu 1400 nexthop via 172.16.101.2 nexthop via 172.16.103.2" 2039 rc=$? 2040 if [ $rc -eq 0 ]; then 2041 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" 2042 rc=$? 2043 fi 2044 log_test $rc 0 "Multipath route with mtu metric" 2045 2046 $IP ro add 172.16.104.0/24 via 172.16.101.2 mtu 1300 2047 run_cmd "ip netns exec $ns1 ping -w1 -c1 -s 1500 172.16.104.1" 2048 log_test $? 0 "Using route with mtu metric" 2049 2050 run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 congctl lock foo" 2051 log_test $? 2 "Invalid metric (fails metric_convert)" 2052 2053 route_cleanup 2054} 2055 2056ipv4_del_addr_test() 2057{ 2058 echo 2059 echo "IPv4 delete address route tests" 2060 2061 setup 2062 2063 set -e 2064 $IP li add dummy1 type dummy 2065 $IP li set dummy1 up 2066 $IP li add dummy2 type dummy 2067 $IP li set dummy2 up 2068 $IP li add red type vrf table 1111 2069 $IP li set red up 2070 $IP ro add vrf red unreachable default 2071 $IP li set dummy2 vrf red 2072 2073 $IP addr add dev dummy1 172.16.104.1/24 2074 $IP addr add dev dummy1 172.16.104.11/24 2075 $IP addr add dev dummy1 172.16.104.12/24 2076 $IP addr add dev dummy1 172.16.104.13/24 2077 $IP addr add dev dummy2 172.16.104.1/24 2078 $IP addr add dev dummy2 172.16.104.11/24 2079 $IP addr add dev dummy2 172.16.104.12/24 2080 $IP route add 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11 2081 $IP route add 172.16.106.0/24 dev lo src 172.16.104.12 2082 $IP route add table 0 172.16.107.0/24 via 172.16.104.2 src 172.16.104.13 2083 $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11 2084 $IP route add vrf red 172.16.106.0/24 dev lo src 172.16.104.12 2085 set +e 2086 2087 # removing address from device in vrf should only remove route from vrf table 2088 echo " Regular FIB info" 2089 2090 $IP addr del dev dummy2 172.16.104.11/24 2091 $IP ro ls vrf red | grep -q 172.16.105.0/24 2092 log_test $? 1 "Route removed from VRF when source address deleted" 2093 2094 $IP ro ls | grep -q 172.16.105.0/24 2095 log_test $? 0 "Route in default VRF not removed" 2096 2097 $IP addr add dev dummy2 172.16.104.11/24 2098 $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11 2099 2100 $IP addr del dev dummy1 172.16.104.11/24 2101 $IP ro ls | grep -q 172.16.105.0/24 2102 log_test $? 1 "Route removed in default VRF when source address deleted" 2103 2104 $IP ro ls vrf red | grep -q 172.16.105.0/24 2105 log_test $? 0 "Route in VRF is not removed by address delete" 2106 2107 # removing address from device in vrf should only remove route from vrf 2108 # table even when the associated fib info only differs in table ID 2109 echo " Identical FIB info with different table ID" 2110 2111 $IP addr del dev dummy2 172.16.104.12/24 2112 $IP ro ls vrf red | grep -q 172.16.106.0/24 2113 log_test $? 1 "Route removed from VRF when source address deleted" 2114 2115 $IP ro ls | grep -q 172.16.106.0/24 2116 log_test $? 0 "Route in default VRF not removed" 2117 2118 $IP addr add dev dummy2 172.16.104.12/24 2119 $IP route add vrf red 172.16.106.0/24 dev lo src 172.16.104.12 2120 2121 $IP addr del dev dummy1 172.16.104.12/24 2122 $IP ro ls | grep -q 172.16.106.0/24 2123 log_test $? 1 "Route removed in default VRF when source address deleted" 2124 2125 $IP ro ls vrf red | grep -q 172.16.106.0/24 2126 log_test $? 0 "Route in VRF is not removed by address delete" 2127 2128 # removing address from device in default vrf should remove route from 2129 # the default vrf even when route was inserted with a table ID of 0. 2130 echo " Table ID 0" 2131 2132 $IP addr del dev dummy1 172.16.104.13/24 2133 $IP ro ls | grep -q 172.16.107.0/24 2134 log_test $? 1 "Route removed in default VRF when source address deleted" 2135 2136 $IP li del dummy1 2137 $IP li del dummy2 2138 cleanup 2139} 2140 2141ipv6_del_addr_test() 2142{ 2143 echo 2144 echo "IPv6 delete address route tests" 2145 2146 setup 2147 2148 set -e 2149 for i in $(seq 6); do 2150 $IP li add dummy${i} up type dummy 2151 done 2152 2153 $IP li add red up type vrf table 1111 2154 $IP ro add vrf red unreachable default 2155 for i in $(seq 4 6); do 2156 $IP li set dummy${i} vrf red 2157 done 2158 2159 $IP addr add dev dummy1 fe80::1/128 2160 $IP addr add dev dummy1 2001:db8:101::1/64 2161 $IP addr add dev dummy1 2001:db8:101::10/64 2162 $IP addr add dev dummy1 2001:db8:101::11/64 2163 $IP addr add dev dummy1 2001:db8:101::12/64 2164 $IP addr add dev dummy1 2001:db8:101::13/64 2165 $IP addr add dev dummy1 2001:db8:101::14/64 2166 $IP addr add dev dummy1 2001:db8:101::15/64 2167 $IP addr add dev dummy2 fe80::1/128 2168 $IP addr add dev dummy2 2001:db8:101::1/64 2169 $IP addr add dev dummy2 2001:db8:101::11/64 2170 $IP addr add dev dummy3 fe80::1/128 2171 2172 $IP addr add dev dummy4 2001:db8:101::1/64 2173 $IP addr add dev dummy4 2001:db8:101::10/64 2174 $IP addr add dev dummy4 2001:db8:101::11/64 2175 $IP addr add dev dummy4 2001:db8:101::12/64 2176 $IP addr add dev dummy4 2001:db8:101::13/64 2177 $IP addr add dev dummy4 2001:db8:101::14/64 2178 $IP addr add dev dummy5 2001:db8:101::1/64 2179 $IP addr add dev dummy5 2001:db8:101::11/64 2180 2181 # Single device using src address 2182 $IP route add 2001:db8:110::/64 dev dummy3 src 2001:db8:101::10 2183 # Two devices with the same source address 2184 $IP route add 2001:db8:111::/64 dev dummy3 src 2001:db8:101::11 2185 # VRF with single device using src address 2186 $IP route add vrf red 2001:db8:110::/64 dev dummy6 src 2001:db8:101::10 2187 # VRF with two devices using src address 2188 $IP route add vrf red 2001:db8:111::/64 dev dummy6 src 2001:db8:101::11 2189 # src address and nexthop dev in same VRF 2190 $IP route add 2001:db8:112::/64 dev dummy3 src 2001:db8:101::12 2191 $IP route add vrf red 2001:db8:112::/64 dev dummy6 src 2001:db8:101::12 2192 # src address and nexthop device in different VRF 2193 $IP route add 2001:db8:113::/64 dev lo src 2001:db8:101::13 2194 $IP route add vrf red 2001:db8:113::/64 dev lo src 2001:db8:101::13 2195 # table ID 0 2196 $IP route add table 0 2001:db8:115::/64 via 2001:db8:101::2 src 2001:db8:101::15 2197 # Link local source route 2198 $IP route add 2001:db8:116::/64 dev dummy2 src fe80::1 2199 $IP route add 2001:db8:117::/64 dev dummy3 src fe80::1 2200 set +e 2201 2202 echo " Single device using src address" 2203 2204 $IP addr del dev dummy1 2001:db8:101::10/64 2205 $IP -6 route show | grep -q "src 2001:db8:101::10 " 2206 log_test $? 1 "Prefsrc removed when src address removed on other device" 2207 2208 echo " Two devices with the same source address" 2209 2210 $IP addr del dev dummy1 2001:db8:101::11/64 2211 $IP -6 route show | grep -q "src 2001:db8:101::11 " 2212 log_test $? 0 "Prefsrc not removed when src address exist on other device" 2213 2214 $IP addr del dev dummy2 2001:db8:101::11/64 2215 $IP -6 route show | grep -q "src 2001:db8:101::11 " 2216 log_test $? 1 "Prefsrc removed when src address removed on all devices" 2217 2218 echo " VRF with single device using src address" 2219 2220 $IP addr del dev dummy4 2001:db8:101::10/64 2221 $IP -6 route show vrf red | grep -q "src 2001:db8:101::10 " 2222 log_test $? 1 "Prefsrc removed when src address removed on other device" 2223 2224 echo " VRF with two devices using src address" 2225 2226 $IP addr del dev dummy4 2001:db8:101::11/64 2227 $IP -6 route show vrf red | grep -q "src 2001:db8:101::11 " 2228 log_test $? 0 "Prefsrc not removed when src address exist on other device" 2229 2230 $IP addr del dev dummy5 2001:db8:101::11/64 2231 $IP -6 route show vrf red | grep -q "src 2001:db8:101::11 " 2232 log_test $? 1 "Prefsrc removed when src address removed on all devices" 2233 2234 echo " src address and nexthop dev in same VRF" 2235 2236 $IP addr del dev dummy4 2001:db8:101::12/64 2237 $IP -6 route show vrf red | grep -q "src 2001:db8:101::12 " 2238 log_test $? 1 "Prefsrc removed from VRF when source address deleted" 2239 $IP -6 route show | grep -q " src 2001:db8:101::12 " 2240 log_test $? 0 "Prefsrc in default VRF not removed" 2241 2242 $IP addr add dev dummy4 2001:db8:101::12/64 2243 $IP route replace vrf red 2001:db8:112::/64 dev dummy6 src 2001:db8:101::12 2244 $IP addr del dev dummy1 2001:db8:101::12/64 2245 $IP -6 route show vrf red | grep -q "src 2001:db8:101::12 " 2246 log_test $? 0 "Prefsrc not removed from VRF when source address exist" 2247 $IP -6 route show | grep -q " src 2001:db8:101::12 " 2248 log_test $? 1 "Prefsrc in default VRF removed" 2249 2250 echo " src address and nexthop device in different VRF" 2251 2252 $IP addr del dev dummy4 2001:db8:101::13/64 2253 $IP -6 route show vrf red | grep -q "src 2001:db8:101::13 " 2254 log_test $? 0 "Prefsrc not removed from VRF when nexthop dev in diff VRF" 2255 $IP -6 route show | grep -q "src 2001:db8:101::13 " 2256 log_test $? 0 "Prefsrc not removed in default VRF" 2257 2258 $IP addr add dev dummy4 2001:db8:101::13/64 2259 $IP addr del dev dummy1 2001:db8:101::13/64 2260 $IP -6 route show vrf red | grep -q "src 2001:db8:101::13 " 2261 log_test $? 1 "Prefsrc removed from VRF when nexthop dev in diff VRF" 2262 $IP -6 route show | grep -q "src 2001:db8:101::13 " 2263 log_test $? 1 "Prefsrc removed in default VRF" 2264 2265 echo " Table ID 0" 2266 2267 $IP addr del dev dummy1 2001:db8:101::15/64 2268 $IP -6 route show | grep -q "src 2001:db8:101::15" 2269 log_test $? 1 "Prefsrc removed from default VRF when source address deleted" 2270 2271 echo " Link local source route" 2272 $IP addr del dev dummy1 fe80::1/128 2273 $IP -6 route show | grep -q "2001:db8:116::/64 dev dummy2 src fe80::1" 2274 log_test $? 0 "Prefsrc not removed when delete ll addr from other dev" 2275 $IP addr del dev dummy2 fe80::1/128 2276 $IP -6 route show | grep -q "2001:db8:116::/64 dev dummy2 src fe80::1" 2277 log_test $? 1 "Prefsrc removed when delete ll addr" 2278 $IP -6 route show | grep -q "2001:db8:117::/64 dev dummy3 src fe80::1" 2279 log_test $? 0 "Prefsrc not removed when delete ll addr from other dev" 2280 $IP addr add dev dummy1 fe80::1/128 2281 $IP addr del dev dummy3 fe80::1/128 2282 $IP -6 route show | grep -q "2001:db8:117::/64 dev dummy3 src fe80::1" 2283 log_test $? 1 "Prefsrc removed even ll addr still exist on other dev" 2284 2285 for i in $(seq 6); do 2286 $IP li del dummy${i} 2287 done 2288 cleanup 2289} 2290 2291ipv4_route_v6_gw_test() 2292{ 2293 local rc 2294 2295 echo 2296 echo "IPv4 route with IPv6 gateway tests" 2297 2298 route_setup 2299 sleep 2 2300 2301 # 2302 # single path route 2303 # 2304 run_cmd "$IP ro add 172.16.104.0/24 via inet6 2001:db8:101::2" 2305 rc=$? 2306 log_test $rc 0 "Single path route with IPv6 gateway" 2307 if [ $rc -eq 0 ]; then 2308 check_route "172.16.104.0/24 via inet6 2001:db8:101::2 dev veth1" 2309 fi 2310 2311 run_cmd "ip netns exec $ns1 ping -w1 -c1 172.16.104.1" 2312 log_test $rc 0 "Single path route with IPv6 gateway - ping" 2313 2314 run_cmd "$IP ro del 172.16.104.0/24 via inet6 2001:db8:101::2" 2315 rc=$? 2316 log_test $rc 0 "Single path route delete" 2317 if [ $rc -eq 0 ]; then 2318 check_route "172.16.112.0/24" 2319 fi 2320 2321 # 2322 # multipath - v6 then v4 2323 # 2324 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" 2325 rc=$? 2326 log_test $rc 0 "Multipath route add - v6 nexthop then v4" 2327 if [ $rc -eq 0 ]; then 2328 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" 2329 fi 2330 2331 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" 2332 log_test $? 2 " Multipath route delete - nexthops in wrong order" 2333 2334 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" 2335 log_test $? 0 " Multipath route delete exact match" 2336 2337 # 2338 # multipath - v4 then v6 2339 # 2340 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" 2341 rc=$? 2342 log_test $rc 0 "Multipath route add - v4 nexthop then v6" 2343 if [ $rc -eq 0 ]; then 2344 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" 2345 fi 2346 2347 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" 2348 log_test $? 2 " Multipath route delete - nexthops in wrong order" 2349 2350 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" 2351 log_test $? 0 " Multipath route delete exact match" 2352 2353 route_cleanup 2354} 2355 2356socat_check() 2357{ 2358 if [ ! -x "$(command -v socat)" ]; then 2359 echo "socat command not found. Skipping test" 2360 return 1 2361 fi 2362 2363 return 0 2364} 2365 2366iptables_check() 2367{ 2368 iptables -t mangle -L OUTPUT &> /dev/null 2369 if [ $? -ne 0 ]; then 2370 echo "iptables configuration not supported. Skipping test" 2371 return 1 2372 fi 2373 2374 return 0 2375} 2376 2377ip6tables_check() 2378{ 2379 ip6tables -t mangle -L OUTPUT &> /dev/null 2380 if [ $? -ne 0 ]; then 2381 echo "ip6tables configuration not supported. Skipping test" 2382 return 1 2383 fi 2384 2385 return 0 2386} 2387 2388ipv4_mangle_test() 2389{ 2390 local rc 2391 2392 echo 2393 echo "IPv4 mangling tests" 2394 2395 socat_check || return 1 2396 iptables_check || return 1 2397 2398 route_setup 2399 sleep 2 2400 2401 local tmp_file=$(mktemp) 2402 ip netns exec $ns2 socat UDP4-LISTEN:54321,fork $tmp_file & 2403 2404 # Add a FIB rule and a route that will direct our connection to the 2405 # listening server. 2406 $IP rule add pref 100 ipproto udp sport 12345 dport 54321 table 123 2407 $IP route add table 123 172.16.101.0/24 dev veth1 2408 2409 # Add an unreachable route to the main table that will block our 2410 # connection in case the FIB rule is not hit. 2411 $IP route add unreachable 172.16.101.2/32 2412 2413 run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=12345" 2414 log_test $? 0 " Connection with correct parameters" 2415 2416 run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=11111" 2417 log_test $? 1 " Connection with incorrect parameters" 2418 2419 # Add a mangling rule and make sure connection is still successful. 2420 $NS_EXEC iptables -t mangle -A OUTPUT -j MARK --set-mark 1 2421 2422 run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=12345" 2423 log_test $? 0 " Connection with correct parameters - mangling" 2424 2425 # Delete the mangling rule and make sure connection is still 2426 # successful. 2427 $NS_EXEC iptables -t mangle -D OUTPUT -j MARK --set-mark 1 2428 2429 run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=12345" 2430 log_test $? 0 " Connection with correct parameters - no mangling" 2431 2432 # Verify connections were indeed successful on server side. 2433 [[ $(cat $tmp_file | wc -l) -eq 3 ]] 2434 log_test $? 0 " Connection check - server side" 2435 2436 $IP route del unreachable 172.16.101.2/32 2437 $IP route del table 123 172.16.101.0/24 dev veth1 2438 $IP rule del pref 100 2439 2440 kill_process %% 2441 rm $tmp_file 2442 2443 route_cleanup 2444} 2445 2446ipv6_mangle_test() 2447{ 2448 local rc 2449 2450 echo 2451 echo "IPv6 mangling tests" 2452 2453 socat_check || return 1 2454 ip6tables_check || return 1 2455 2456 route_setup 2457 sleep 2 2458 2459 local tmp_file=$(mktemp) 2460 ip netns exec $ns2 socat UDP6-LISTEN:54321,fork $tmp_file & 2461 2462 # Add a FIB rule and a route that will direct our connection to the 2463 # listening server. 2464 $IP -6 rule add pref 100 ipproto udp sport 12345 dport 54321 table 123 2465 $IP -6 route add table 123 2001:db8:101::/64 dev veth1 2466 2467 # Add an unreachable route to the main table that will block our 2468 # connection in case the FIB rule is not hit. 2469 $IP -6 route add unreachable 2001:db8:101::2/128 2470 2471 run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=12345" 2472 log_test $? 0 " Connection with correct parameters" 2473 2474 run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=11111" 2475 log_test $? 1 " Connection with incorrect parameters" 2476 2477 # Add a mangling rule and make sure connection is still successful. 2478 $NS_EXEC ip6tables -t mangle -A OUTPUT -j MARK --set-mark 1 2479 2480 run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=12345" 2481 log_test $? 0 " Connection with correct parameters - mangling" 2482 2483 # Delete the mangling rule and make sure connection is still 2484 # successful. 2485 $NS_EXEC ip6tables -t mangle -D OUTPUT -j MARK --set-mark 1 2486 2487 run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=12345" 2488 log_test $? 0 " Connection with correct parameters - no mangling" 2489 2490 # Verify connections were indeed successful on server side. 2491 [[ $(cat $tmp_file | wc -l) -eq 3 ]] 2492 log_test $? 0 " Connection check - server side" 2493 2494 $IP -6 route del unreachable 2001:db8:101::2/128 2495 $IP -6 route del table 123 2001:db8:101::/64 dev veth1 2496 $IP -6 rule del pref 100 2497 2498 kill_process %% 2499 rm $tmp_file 2500 2501 route_cleanup 2502} 2503 2504ip_neigh_get_check() 2505{ 2506 ip neigh help 2>&1 | grep -q 'ip neigh get' 2507 if [ $? -ne 0 ]; then 2508 echo "iproute2 command does not support neigh get. Skipping test" 2509 return 1 2510 fi 2511 2512 return 0 2513} 2514 2515ipv4_bcast_neigh_test() 2516{ 2517 local rc 2518 2519 echo 2520 echo "IPv4 broadcast neighbour tests" 2521 2522 ip_neigh_get_check || return 1 2523 2524 setup 2525 2526 set -e 2527 run_cmd "$IP neigh add 192.0.2.111 lladdr 00:11:22:33:44:55 nud perm dev dummy0" 2528 run_cmd "$IP neigh add 192.0.2.255 lladdr 00:11:22:33:44:55 nud perm dev dummy0" 2529 2530 run_cmd "$IP neigh get 192.0.2.111 dev dummy0" 2531 run_cmd "$IP neigh get 192.0.2.255 dev dummy0" 2532 2533 run_cmd "$IP address add 192.0.2.1/24 broadcast 192.0.2.111 dev dummy0" 2534 2535 run_cmd "$IP neigh add 203.0.113.111 nud failed dev dummy0" 2536 run_cmd "$IP neigh add 203.0.113.255 nud failed dev dummy0" 2537 2538 run_cmd "$IP neigh get 203.0.113.111 dev dummy0" 2539 run_cmd "$IP neigh get 203.0.113.255 dev dummy0" 2540 2541 run_cmd "$IP address add 203.0.113.1/24 broadcast 203.0.113.111 dev dummy0" 2542 set +e 2543 2544 run_cmd "$IP neigh get 192.0.2.111 dev dummy0" 2545 log_test $? 0 "Resolved neighbour for broadcast address" 2546 2547 run_cmd "$IP neigh get 192.0.2.255 dev dummy0" 2548 log_test $? 0 "Resolved neighbour for network broadcast address" 2549 2550 run_cmd "$IP neigh get 203.0.113.111 dev dummy0" 2551 log_test $? 2 "Unresolved neighbour for broadcast address" 2552 2553 run_cmd "$IP neigh get 203.0.113.255 dev dummy0" 2554 log_test $? 2 "Unresolved neighbour for network broadcast address" 2555 2556 cleanup 2557} 2558 2559mpath_dep_check() 2560{ 2561 if [ ! -x "$(command -v mausezahn)" ]; then 2562 echo "mausezahn command not found. Skipping test" 2563 return 1 2564 fi 2565 2566 if [ ! -x "$(command -v jq)" ]; then 2567 echo "jq command not found. Skipping test" 2568 return 1 2569 fi 2570 2571 if [ ! -x "$(command -v bc)" ]; then 2572 echo "bc command not found. Skipping test" 2573 return 1 2574 fi 2575 2576 if [ ! -x "$(command -v perf)" ]; then 2577 echo "perf command not found. Skipping test" 2578 return 1 2579 fi 2580 2581 perf list fib:* | grep -q fib_table_lookup 2582 if [ $? -ne 0 ]; then 2583 echo "IPv4 FIB tracepoint not found. Skipping test" 2584 return 1 2585 fi 2586 2587 perf list fib6:* | grep -q fib6_table_lookup 2588 if [ $? -ne 0 ]; then 2589 echo "IPv6 FIB tracepoint not found. Skipping test" 2590 return 1 2591 fi 2592 2593 return 0 2594} 2595 2596link_stats_get() 2597{ 2598 local ns=$1; shift 2599 local dev=$1; shift 2600 local dir=$1; shift 2601 local stat=$1; shift 2602 2603 ip -n $ns -j -s link show dev $dev \ 2604 | jq '.[]["stats64"]["'$dir'"]["'$stat'"]' 2605} 2606 2607list_rcv_eval() 2608{ 2609 local file=$1; shift 2610 local expected=$1; shift 2611 2612 local count=$(tail -n 1 $file | jq '.["counter-value"] | tonumber | floor') 2613 local ratio=$(echo "scale=2; $count / $expected" | bc -l) 2614 local res=$(echo "$ratio >= 0.95" | bc) 2615 [[ $res -eq 1 ]] 2616 log_test $? 0 "Multipath route hit ratio ($ratio)" 2617} 2618 2619ipv4_mpath_list_test() 2620{ 2621 echo 2622 echo "IPv4 multipath list receive tests" 2623 2624 mpath_dep_check || return 1 2625 2626 route_setup 2627 2628 set -e 2629 run_cmd "ip netns exec $ns1 ethtool -K veth1 tcp-segmentation-offload off" 2630 2631 run_cmd "ip netns exec $ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\"" 2632 run_cmd "ip netns exec $ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\"" 2633 run_cmd "ip netns exec $ns2 ethtool -K veth2 generic-receive-offload on" 2634 run_cmd "ip -n $ns2 link add name nh1 up type dummy" 2635 run_cmd "ip -n $ns2 link add name nh2 up type dummy" 2636 run_cmd "ip -n $ns2 address add 172.16.201.1/24 dev nh1" 2637 run_cmd "ip -n $ns2 address add 172.16.202.1/24 dev nh2" 2638 run_cmd "ip -n $ns2 neigh add 172.16.201.2 lladdr 00:11:22:33:44:55 nud perm dev nh1" 2639 run_cmd "ip -n $ns2 neigh add 172.16.202.2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2" 2640 run_cmd "ip -n $ns2 route add 203.0.113.0/24 2641 nexthop via 172.16.201.2 nexthop via 172.16.202.2" 2642 run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.fib_multipath_hash_policy=1" 2643 set +e 2644 2645 local dmac=$(ip -n $ns2 -j link show dev veth2 | jq -r '.[]["address"]') 2646 local tmp_file=$(mktemp) 2647 local cmd="ip netns exec $ns1 mausezahn veth1 -a own -b $dmac 2648 -A 172.16.101.1 -B 203.0.113.1 -t udp 'sp=12345,dp=0-65535' -q" 2649 2650 # Packets forwarded in a list using a multipath route must not reuse a 2651 # cached result so that a flow always hits the same nexthop. In other 2652 # words, the FIB lookup tracepoint needs to be triggered for every 2653 # packet. 2654 local t0_rx_pkts=$(link_stats_get $ns2 veth2 rx packets) 2655 run_cmd "perf stat -a -e fib:fib_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd" 2656 local t1_rx_pkts=$(link_stats_get $ns2 veth2 rx packets) 2657 local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l) 2658 list_rcv_eval $tmp_file $diff 2659 2660 rm $tmp_file 2661 route_cleanup 2662} 2663 2664ipv6_mpath_list_test() 2665{ 2666 echo 2667 echo "IPv6 multipath list receive tests" 2668 2669 mpath_dep_check || return 1 2670 2671 route_setup 2672 2673 set -e 2674 run_cmd "ip netns exec $ns1 ethtool -K veth1 tcp-segmentation-offload off" 2675 2676 run_cmd "ip netns exec $ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\"" 2677 run_cmd "ip netns exec $ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\"" 2678 run_cmd "ip netns exec $ns2 ethtool -K veth2 generic-receive-offload on" 2679 run_cmd "ip -n $ns2 link add name nh1 up type dummy" 2680 run_cmd "ip -n $ns2 link add name nh2 up type dummy" 2681 run_cmd "ip -n $ns2 -6 address add 2001:db8:201::1/64 dev nh1" 2682 run_cmd "ip -n $ns2 -6 address add 2001:db8:202::1/64 dev nh2" 2683 run_cmd "ip -n $ns2 -6 neigh add 2001:db8:201::2 lladdr 00:11:22:33:44:55 nud perm dev nh1" 2684 run_cmd "ip -n $ns2 -6 neigh add 2001:db8:202::2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2" 2685 run_cmd "ip -n $ns2 -6 route add 2001:db8:301::/64 2686 nexthop via 2001:db8:201::2 nexthop via 2001:db8:202::2" 2687 run_cmd "ip netns exec $ns2 sysctl -qw net.ipv6.fib_multipath_hash_policy=1" 2688 set +e 2689 2690 local dmac=$(ip -n $ns2 -j link show dev veth2 | jq -r '.[]["address"]') 2691 local tmp_file=$(mktemp) 2692 local cmd="ip netns exec $ns1 mausezahn -6 veth1 -a own -b $dmac 2693 -A 2001:db8:101::1 -B 2001:db8:301::1 -t udp 'sp=12345,dp=0-65535' -q" 2694 2695 # Packets forwarded in a list using a multipath route must not reuse a 2696 # cached result so that a flow always hits the same nexthop. In other 2697 # words, the FIB lookup tracepoint needs to be triggered for every 2698 # packet. 2699 local t0_rx_pkts=$(link_stats_get $ns2 veth2 rx packets) 2700 run_cmd "perf stat -a -e fib6:fib6_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd" 2701 local t1_rx_pkts=$(link_stats_get $ns2 veth2 rx packets) 2702 local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l) 2703 list_rcv_eval $tmp_file $diff 2704 2705 rm $tmp_file 2706 route_cleanup 2707} 2708 2709tc_set_flower_counter__saddr_syn() { 2710 tc_set_flower_counter $1 $2 $3 "src_ip $4 ip_proto tcp tcp_flags 0x2" 2711} 2712 2713ip_mpath_balance_dep_check() 2714{ 2715 if [ ! -x "$(command -v socat)" ]; then 2716 echo "socat command not found. Skipping test" 2717 return 1 2718 fi 2719 2720 if [ ! -x "$(command -v jq)" ]; then 2721 echo "jq command not found. Skipping test" 2722 return 1 2723 fi 2724} 2725 2726ip_mpath_balance() { 2727 local -r ipver=$1 2728 local -r daddr=$2 2729 local -r num_conn=20 2730 2731 for i in $(seq 1 $num_conn); do 2732 ip netns exec $ns3 socat $ipver TCP-LISTEN:8000 STDIO >/dev/null & 2733 sleep 0.02 2734 echo -n a | ip netns exec $ns1 socat $ipver STDIO TCP:$daddr:8000 2735 done 2736 2737 local -r syn0="$(tc_get_flower_counter $ns1 veth1)" 2738 local -r syn1="$(tc_get_flower_counter $ns1 veth3)" 2739 local -r syns=$((syn0+syn1)) 2740 2741 [ "$VERBOSE" = "1" ] && echo "multipath: syns seen: ($syn0,$syn1)" 2742 2743 [[ $syns -ge $num_conn ]] && [[ $syn0 -gt 0 ]] && [[ $syn1 -gt 0 ]] 2744} 2745 2746ipv4_mpath_balance_test() 2747{ 2748 echo 2749 echo "IPv4 multipath load balance test" 2750 2751 ip_mpath_balance_dep_check || return 1 2752 forwarding_setup 2753 2754 $IP route add 172.16.105.1 \ 2755 nexthop via 172.16.101.2 \ 2756 nexthop via 172.16.103.2 2757 2758 ip netns exec $ns1 \ 2759 sysctl -q -w net.ipv4.fib_multipath_hash_policy=1 2760 2761 tc_set_flower_counter__saddr_syn $ns1 4 veth1 172.16.101.1 2762 tc_set_flower_counter__saddr_syn $ns1 4 veth3 172.16.103.1 2763 2764 ip_mpath_balance -4 172.16.105.1 2765 2766 log_test $? 0 "IPv4 multipath loadbalance" 2767 2768 forwarding_cleanup 2769} 2770 2771get_route_dev_src() 2772{ 2773 local pfx="$1" 2774 local src="$2" 2775 local out 2776 2777 if out=$($IP -j route get "$pfx" from "$src" | jq -re ".[0].dev"); then 2778 echo "$out" 2779 fi 2780} 2781 2782ipv4_mpath_preferred() 2783{ 2784 local src_ip=$1 2785 local pref_dev=$2 2786 local dev routes 2787 local route0=0 2788 local route1=0 2789 local pref_route=0 2790 num_routes=254 2791 2792 for i in $(seq 1 $num_routes) ; do 2793 dev=$(get_route_dev_src 172.16.105.$i $src_ip) 2794 if [ "$dev" = "$pref_dev" ]; then 2795 pref_route=$((pref_route+1)) 2796 elif [ "$dev" = "veth1" ]; then 2797 route0=$((route0+1)) 2798 elif [ "$dev" = "veth3" ]; then 2799 route1=$((route1+1)) 2800 fi 2801 done 2802 2803 routes=$((route0+route1)) 2804 2805 [ "$VERBOSE" = "1" ] && echo "multipath: routes seen: ($route0,$route1,$pref_route)" 2806 2807 if [ x"$pref_dev" = x"" ]; then 2808 [[ $routes -ge $num_routes ]] && [[ $route0 -gt 0 ]] && [[ $route1 -gt 0 ]] 2809 else 2810 [[ $pref_route -ge $num_routes ]] 2811 fi 2812 2813} 2814 2815ipv4_mpath_balance_preferred_test() 2816{ 2817 echo 2818 echo "IPv4 multipath load balance preferred route" 2819 2820 forwarding_setup 2821 2822 $IP route add 172.16.105.0/24 \ 2823 nexthop via 172.16.101.2 \ 2824 nexthop via 172.16.103.2 2825 2826 ipv4_mpath_preferred 172.16.101.1 veth1 2827 log_test $? 0 "IPv4 multipath loadbalance from veth1" 2828 2829 ipv4_mpath_preferred 172.16.103.1 veth3 2830 log_test $? 0 "IPv4 multipath loadbalance from veth3" 2831 2832 ipv4_mpath_preferred 198.51.100.1 2833 log_test $? 0 "IPv4 multipath loadbalance from dummy" 2834 2835 forwarding_cleanup 2836} 2837 2838ipv6_mpath_balance_test() 2839{ 2840 echo 2841 echo "IPv6 multipath load balance test" 2842 2843 ip_mpath_balance_dep_check || return 1 2844 forwarding_setup 2845 2846 $IP route add 2001:db8:105::1\ 2847 nexthop via 2001:db8:101::2 \ 2848 nexthop via 2001:db8:103::2 2849 2850 ip netns exec $ns1 \ 2851 sysctl -q -w net.ipv6.fib_multipath_hash_policy=1 2852 2853 tc_set_flower_counter__saddr_syn $ns1 6 veth1 2001:db8:101::1 2854 tc_set_flower_counter__saddr_syn $ns1 6 veth3 2001:db8:103::1 2855 2856 ip_mpath_balance -6 "[2001:db8:105::1]" 2857 2858 log_test $? 0 "IPv6 multipath loadbalance" 2859 2860 forwarding_cleanup 2861} 2862 2863################################################################################ 2864# usage 2865 2866usage() 2867{ 2868 cat <<EOF 2869usage: ${0##*/} OPTS 2870 2871 -t <test> Test(s) to run (default: all) 2872 (options: $TESTS) 2873 -p Pause on fail 2874 -P Pause after each test before cleanup 2875 -v verbose mode (show commands and output) 2876EOF 2877} 2878 2879################################################################################ 2880# main 2881 2882trap cleanup EXIT 2883 2884while getopts :t:pPhv o 2885do 2886 case $o in 2887 t) TESTS=$OPTARG;; 2888 p) PAUSE_ON_FAIL=yes;; 2889 P) PAUSE=yes;; 2890 v) VERBOSE=$(($VERBOSE + 1));; 2891 h) usage; exit 0;; 2892 *) usage; exit 1;; 2893 esac 2894done 2895 2896PEER_CMD="ip netns exec ${PEER_NS}" 2897 2898# make sure we don't pause twice 2899[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no 2900 2901if [ "$(id -u)" -ne 0 ];then 2902 echo "SKIP: Need root privileges" 2903 exit $ksft_skip; 2904fi 2905 2906if [ ! -x "$(command -v ip)" ]; then 2907 echo "SKIP: Could not run test without ip tool" 2908 exit $ksft_skip 2909fi 2910 2911ip route help 2>&1 | grep -q fibmatch 2912if [ $? -ne 0 ]; then 2913 echo "SKIP: iproute2 too old, missing fibmatch" 2914 exit $ksft_skip 2915fi 2916 2917# start clean 2918cleanup &> /dev/null 2919 2920for t in $TESTS 2921do 2922 case $t in 2923 fib_unreg_test|unregister) fib_unreg_test;; 2924 fib_down_test|down) fib_down_test;; 2925 fib_carrier_test|carrier) fib_carrier_test;; 2926 fib_rp_filter_test|rp_filter) fib_rp_filter_test;; 2927 fib_nexthop_test|nexthop) fib_nexthop_test;; 2928 fib_notify_test|ipv4_notify) fib_notify_test;; 2929 fib6_notify_test|ipv6_notify) fib6_notify_test;; 2930 fib_suppress_test|suppress) fib_suppress_test;; 2931 ipv6_route_test|ipv6_rt) ipv6_route_test;; 2932 ipv4_route_test|ipv4_rt) ipv4_route_test;; 2933 ipv6_addr_metric) ipv6_addr_metric_test;; 2934 ipv4_addr_metric) ipv4_addr_metric_test;; 2935 ipv4_del_addr) ipv4_del_addr_test;; 2936 ipv6_del_addr) ipv6_del_addr_test;; 2937 ipv6_route_metrics) ipv6_route_metrics_test;; 2938 ipv4_route_metrics) ipv4_route_metrics_test;; 2939 ipv4_route_v6_gw) ipv4_route_v6_gw_test;; 2940 ipv4_mangle) ipv4_mangle_test;; 2941 ipv6_mangle) ipv6_mangle_test;; 2942 ipv4_bcast_neigh) ipv4_bcast_neigh_test;; 2943 fib6_gc_test|ipv6_gc) fib6_gc_test;; 2944 ipv4_mpath_list) ipv4_mpath_list_test;; 2945 ipv6_mpath_list) ipv6_mpath_list_test;; 2946 ipv4_mpath_balance) ipv4_mpath_balance_test;; 2947 ipv6_mpath_balance) ipv6_mpath_balance_test;; 2948 ipv4_mpath_balance_preferred) ipv4_mpath_balance_preferred_test;; 2949 fib6_ra_to_static) fib6_ra_to_static;; 2950 2951 help) echo "Test names: $TESTS"; exit 0;; 2952 esac 2953done 2954 2955if [ "$TESTS" != "none" ]; then 2956 printf "\nTests passed: %3d\n" ${nsuccess} 2957 printf "Tests failed: %3d\n" ${nfail} 2958fi 2959 2960exit $ret 2961