1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# This test is for checking IPv4 and IPv6 FIB rules API 5 6source lib.sh 7ret=0 8PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no} 9 10RTABLE=100 11RTABLE_PEER=101 12RTABLE_VRF=102 13GW_IP4=192.51.100.2 14SRC_IP=192.51.100.3 15GW_IP6=2001:db8:1::2 16SRC_IP6=2001:db8:1::3 17 18DEV_ADDR=192.51.100.1 19DEV_ADDR6=2001:db8:1::1 20DEV=dummy0 21TESTS=" 22 fib_rule6 23 fib_rule4 24 fib_rule6_connect 25 fib_rule4_connect 26 fib_rule6_vrf 27 fib_rule4_vrf 28" 29 30SELFTEST_PATH="" 31 32log_test() 33{ 34 local rc=$1 35 local expected=$2 36 local msg="$3" 37 38 if [ ${rc} -eq ${expected} ]; then 39 nsuccess=$((nsuccess+1)) 40 printf " TEST: %-60s [ OK ]\n" "${msg}" 41 else 42 ret=1 43 nfail=$((nfail+1)) 44 printf " TEST: %-60s [FAIL]\n" "${msg}" 45 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then 46 echo 47 echo "hit enter to continue, 'q' to quit" 48 read a 49 [ "$a" = "q" ] && exit 1 50 fi 51 fi 52} 53 54setup() 55{ 56 set -e 57 setup_ns testns 58 IP="ip -netns $testns" 59 60 $IP link add dummy0 type dummy 61 $IP link set dev dummy0 up 62 $IP address add $DEV_ADDR/24 dev dummy0 63 $IP -6 address add $DEV_ADDR6/64 dev dummy0 64 65 set +e 66} 67 68cleanup() 69{ 70 $IP link del dev dummy0 &> /dev/null 71 cleanup_ns $testns 72} 73 74setup_peer() 75{ 76 set -e 77 78 setup_ns peerns 79 IP_PEER="ip -netns $peerns" 80 $IP_PEER link set dev lo up 81 82 ip link add name veth0 netns $testns type veth \ 83 peer name veth1 netns $peerns 84 $IP link set dev veth0 up 85 $IP_PEER link set dev veth1 up 86 87 $IP address add 192.0.2.10 peer 192.0.2.11/32 dev veth0 88 $IP_PEER address add 192.0.2.11 peer 192.0.2.10/32 dev veth1 89 90 $IP address add 2001:db8::10 peer 2001:db8::11/128 dev veth0 nodad 91 $IP_PEER address add 2001:db8::11 peer 2001:db8::10/128 dev veth1 nodad 92 93 $IP_PEER address add 198.51.100.11/32 dev lo 94 $IP route add table $RTABLE_PEER 198.51.100.11/32 via 192.0.2.11 95 96 $IP_PEER address add 2001:db8::1:11/128 dev lo 97 $IP route add table $RTABLE_PEER 2001:db8::1:11/128 via 2001:db8::11 98 99 set +e 100} 101 102cleanup_peer() 103{ 104 $IP link del dev veth0 105 ip netns del $peerns 106} 107 108setup_vrf() 109{ 110 $IP link add name vrf0 up type vrf table $RTABLE_VRF 111 $IP link set dev $DEV master vrf0 112} 113 114cleanup_vrf() 115{ 116 $IP link del dev vrf0 117} 118 119fib_check_iproute_support() 120{ 121 ip rule help 2>&1 | grep -q $1 122 if [ $? -ne 0 ]; then 123 echo "SKIP: iproute2 iprule too old, missing $1 match" 124 return 1 125 fi 126 127 ip route get help 2>&1 | grep -q $2 128 if [ $? -ne 0 ]; then 129 echo "SKIP: iproute2 get route too old, missing $2 match" 130 return 1 131 fi 132 133 return 0 134} 135 136fib_rule6_del() 137{ 138 $IP -6 rule del $1 139 log_test $? 0 "rule6 del $1" 140} 141 142fib_rule6_del_by_pref() 143{ 144 pref=$($IP -6 rule show $1 table $RTABLE | cut -d ":" -f 1) 145 $IP -6 rule del pref $pref 146} 147 148fib_rule6_test_match_n_redirect() 149{ 150 local match="$1" 151 local getmatch="$2" 152 local getnomatch="$3" 153 local description="$4" 154 local nomatch_description="$5" 155 156 $IP -6 rule add $match table $RTABLE 157 $IP -6 route get $GW_IP6 $getmatch | grep -q "table $RTABLE" 158 log_test $? 0 "rule6 check: $description" 159 160 $IP -6 route get $GW_IP6 $getnomatch 2>&1 | grep -q "table $RTABLE" 161 log_test $? 1 "rule6 check: $nomatch_description" 162 163 fib_rule6_del_by_pref "$match" 164 log_test $? 0 "rule6 del by pref: $description" 165} 166 167fib_rule6_test_reject() 168{ 169 local match="$1" 170 local rc 171 172 $IP -6 rule add $match table $RTABLE 2>/dev/null 173 rc=$? 174 log_test $rc 2 "rule6 check: $match" 175 176 if [ $rc -eq 0 ]; then 177 $IP -6 rule del $match table $RTABLE 178 fi 179} 180 181fib_rule6_test() 182{ 183 local ext_name=$1; shift 184 local getnomatch 185 local getmatch 186 local match 187 local cnt 188 189 echo 190 echo "IPv6 FIB rule tests $ext_name" 191 192 # setup the fib rule redirect route 193 $IP -6 route add table $RTABLE default via $GW_IP6 dev $DEV onlink 194 195 match="oif $DEV" 196 getnomatch="oif lo" 197 fib_rule6_test_match_n_redirect "$match" "$match" "$getnomatch" \ 198 "oif redirect to table" "oif no redirect to table" 199 200 match="from $SRC_IP6 iif $DEV" 201 getnomatch="from $SRC_IP6 iif lo" 202 fib_rule6_test_match_n_redirect "$match" "$match" "$getnomatch" \ 203 "iif redirect to table" "iif no redirect to table" 204 205 # Reject dsfield (tos) options which have ECN bits set 206 for cnt in $(seq 1 3); do 207 match="dsfield $cnt" 208 fib_rule6_test_reject "$match" 209 done 210 211 # Don't take ECN bits into account when matching on dsfield 212 match="tos 0x10" 213 for cnt in "0x10" "0x11" "0x12" "0x13"; do 214 # Using option 'tos' instead of 'dsfield' as old iproute2 215 # versions don't support 'dsfield' in ip rule show. 216 getmatch="tos $cnt" 217 getnomatch="tos 0x20" 218 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 219 "$getnomatch" "$getmatch redirect to table" \ 220 "$getnomatch no redirect to table" 221 done 222 223 # Re-test TOS matching, but with input routes since they are handled 224 # differently from output routes. 225 match="tos 0x10" 226 for cnt in "0x10" "0x11" "0x12" "0x13"; do 227 getmatch="tos $cnt" 228 getnomatch="tos 0x20" 229 fib_rule6_test_match_n_redirect "$match" \ 230 "from $SRC_IP6 iif $DEV $getmatch" \ 231 "from $SRC_IP6 iif $DEV $getnomatch" \ 232 "iif $getmatch redirect to table" \ 233 "iif $getnomatch no redirect to table" 234 done 235 236 match="fwmark 0x64" 237 getmatch="mark 0x64" 238 getnomatch="mark 0x63" 239 fib_rule6_test_match_n_redirect "$match" "$getmatch" "$getnomatch" \ 240 "fwmark redirect to table" "fwmark no redirect to table" 241 242 fib_check_iproute_support "uidrange" "uid" 243 if [ $? -eq 0 ]; then 244 match="uidrange 100-100" 245 getmatch="uid 100" 246 getnomatch="uid 101" 247 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 248 "$getnomatch" "uid redirect to table" \ 249 "uid no redirect to table" 250 fi 251 252 fib_check_iproute_support "sport" "sport" 253 if [ $? -eq 0 ]; then 254 match="sport 666 dport 777" 255 getnomatch="sport 667 dport 778" 256 fib_rule6_test_match_n_redirect "$match" "$match" \ 257 "$getnomatch" "sport and dport redirect to table" \ 258 "sport and dport no redirect to table" 259 fi 260 261 fib_check_iproute_support "ipproto" "ipproto" 262 if [ $? -eq 0 ]; then 263 match="ipproto tcp" 264 getnomatch="ipproto udp" 265 fib_rule6_test_match_n_redirect "$match" "$match" \ 266 "$getnomatch" "ipproto tcp match" "ipproto udp no match" 267 fi 268 269 fib_check_iproute_support "ipproto" "ipproto" 270 if [ $? -eq 0 ]; then 271 match="ipproto ipv6-icmp" 272 getnomatch="ipproto tcp" 273 fib_rule6_test_match_n_redirect "$match" "$match" \ 274 "$getnomatch" "ipproto ipv6-icmp match" \ 275 "ipproto ipv6-tcp no match" 276 fi 277 278 fib_check_iproute_support "dscp" "tos" 279 if [ $? -eq 0 ]; then 280 match="dscp 0x3f" 281 getmatch="tos 0xfc" 282 getnomatch="tos 0xf4" 283 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 284 "$getnomatch" "dscp redirect to table" \ 285 "dscp no redirect to table" 286 287 match="dscp 0x3f" 288 getmatch="from $SRC_IP6 iif $DEV tos 0xfc" 289 getnomatch="from $SRC_IP6 iif $DEV tos 0xf4" 290 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 291 "$getnomatch" "iif dscp redirect to table" \ 292 "iif dscp no redirect to table" 293 fi 294 295 fib_check_iproute_support "flowlabel" "flowlabel" 296 if [ $? -eq 0 ]; then 297 match="flowlabel 0xfffff" 298 getmatch="flowlabel 0xfffff" 299 getnomatch="flowlabel 0xf" 300 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 301 "$getnomatch" "flowlabel redirect to table" \ 302 "flowlabel no redirect to table" 303 304 match="flowlabel 0xfffff" 305 getmatch="from $SRC_IP6 iif $DEV flowlabel 0xfffff" 306 getnomatch="from $SRC_IP6 iif $DEV flowlabel 0xf" 307 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 308 "$getnomatch" "iif flowlabel redirect to table" \ 309 "iif flowlabel no redirect to table" 310 311 match="flowlabel 0x08000/0x08000" 312 getmatch="flowlabel 0xfffff" 313 getnomatch="flowlabel 0xf7fff" 314 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 315 "$getnomatch" "flowlabel masked redirect to table" \ 316 "flowlabel masked no redirect to table" 317 318 match="flowlabel 0x08000/0x08000" 319 getmatch="from $SRC_IP6 iif $DEV flowlabel 0xfffff" 320 getnomatch="from $SRC_IP6 iif $DEV flowlabel 0xf7fff" 321 fib_rule6_test_match_n_redirect "$match" "$getmatch" \ 322 "$getnomatch" "iif flowlabel masked redirect to table" \ 323 "iif flowlabel masked no redirect to table" 324 fi 325} 326 327fib_rule6_vrf_test() 328{ 329 setup_vrf 330 fib_rule6_test "- with VRF" 331 cleanup_vrf 332} 333 334# Verify that the IPV6_TCLASS option of UDPv6 and TCPv6 sockets is properly 335# taken into account when connecting the socket and when sending packets. 336fib_rule6_connect_test() 337{ 338 local dsfield 339 340 echo 341 echo "IPv6 FIB rule connect tests" 342 343 setup_peer 344 $IP -6 rule add dsfield 0x04 table $RTABLE_PEER 345 346 # Combine the base DS Field value (0x04) with all possible ECN values 347 # (Not-ECT: 0, ECT(1): 1, ECT(0): 2, CE: 3). 348 # The ECN bits shouldn't influence the result of the test. 349 for dsfield in 0x04 0x05 0x06 0x07; do 350 nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D \ 351 -Q "${dsfield}" -l 2001:db8::1:11 -r 2001:db8::1:11 352 log_test $? 0 "rule6 dsfield udp connect (dsfield ${dsfield})" 353 354 nettest -q -6 -B -t 5 -N $testns -O $peerns -Q "${dsfield}" \ 355 -l 2001:db8::1:11 -r 2001:db8::1:11 356 log_test $? 0 "rule6 dsfield tcp connect (dsfield ${dsfield})" 357 done 358 359 # Check that UDP and TCP connections fail when using a DS Field that 360 # does not match the previously configured FIB rule. 361 nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D \ 362 -Q 0x20 -l 2001:db8::1:11 -r 2001:db8::1:11 363 log_test $? 1 "rule6 dsfield udp no connect (dsfield 0x20)" 364 365 nettest -q -6 -B -t 5 -N $testns -O $peerns -Q 0x20 \ 366 -l 2001:db8::1:11 -r 2001:db8::1:11 367 log_test $? 1 "rule6 dsfield tcp no connect (dsfield 0x20)" 368 369 $IP -6 rule del dsfield 0x04 table $RTABLE_PEER 370 371 ip rule help 2>&1 | grep -q dscp 372 if [ $? -ne 0 ]; then 373 echo "SKIP: iproute2 iprule too old, missing dscp match" 374 cleanup_peer 375 return 376 fi 377 378 $IP -6 rule add dscp 0x3f table $RTABLE_PEER 379 380 nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D -Q 0xfc \ 381 -l 2001:db8::1:11 -r 2001:db8::1:11 382 log_test $? 0 "rule6 dscp udp connect" 383 384 nettest -q -6 -B -t 5 -N $testns -O $peerns -Q 0xfc \ 385 -l 2001:db8::1:11 -r 2001:db8::1:11 386 log_test $? 0 "rule6 dscp tcp connect" 387 388 nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D -Q 0xf4 \ 389 -l 2001:db8::1:11 -r 2001:db8::1:11 390 log_test $? 1 "rule6 dscp udp no connect" 391 392 nettest -q -6 -B -t 5 -N $testns -O $peerns -Q 0xf4 \ 393 -l 2001:db8::1:11 -r 2001:db8::1:11 394 log_test $? 1 "rule6 dscp tcp no connect" 395 396 $IP -6 rule del dscp 0x3f table $RTABLE_PEER 397 398 cleanup_peer 399} 400 401fib_rule4_del() 402{ 403 $IP rule del $1 404 log_test $? 0 "del $1" 405} 406 407fib_rule4_del_by_pref() 408{ 409 pref=$($IP rule show $1 table $RTABLE | cut -d ":" -f 1) 410 $IP rule del pref $pref 411} 412 413fib_rule4_test_match_n_redirect() 414{ 415 local match="$1" 416 local getmatch="$2" 417 local getnomatch="$3" 418 local description="$4" 419 local nomatch_description="$5" 420 421 $IP rule add $match table $RTABLE 422 $IP route get $GW_IP4 $getmatch | grep -q "table $RTABLE" 423 log_test $? 0 "rule4 check: $description" 424 425 $IP route get $GW_IP4 $getnomatch 2>&1 | grep -q "table $RTABLE" 426 log_test $? 1 "rule4 check: $nomatch_description" 427 428 fib_rule4_del_by_pref "$match" 429 log_test $? 0 "rule4 del by pref: $description" 430} 431 432fib_rule4_test_reject() 433{ 434 local match="$1" 435 local rc 436 437 $IP rule add $match table $RTABLE 2>/dev/null 438 rc=$? 439 log_test $rc 2 "rule4 check: $match" 440 441 if [ $rc -eq 0 ]; then 442 $IP rule del $match table $RTABLE 443 fi 444} 445 446fib_rule4_test() 447{ 448 local ext_name=$1; shift 449 local getnomatch 450 local getmatch 451 local match 452 local cnt 453 454 echo 455 echo "IPv4 FIB rule tests $ext_name" 456 457 # setup the fib rule redirect route 458 $IP route add table $RTABLE default via $GW_IP4 dev $DEV onlink 459 460 match="oif $DEV" 461 getnomatch="oif lo" 462 fib_rule4_test_match_n_redirect "$match" "$match" "$getnomatch" \ 463 "oif redirect to table" "oif no redirect to table" 464 465 # Enable forwarding and disable rp_filter as all the addresses are in 466 # the same subnet and egress device == ingress device. 467 ip netns exec $testns sysctl -qw net.ipv4.ip_forward=1 468 ip netns exec $testns sysctl -qw net.ipv4.conf.$DEV.rp_filter=0 469 match="from $SRC_IP iif $DEV" 470 getnomatch="from $SRC_IP iif lo" 471 fib_rule4_test_match_n_redirect "$match" "$match" "$getnomatch" \ 472 "iif redirect to table" "iif no redirect to table" 473 474 # Reject dsfield (tos) options which have ECN bits set 475 for cnt in $(seq 1 3); do 476 match="dsfield $cnt" 477 fib_rule4_test_reject "$match" 478 done 479 480 # Don't take ECN bits into account when matching on dsfield 481 match="tos 0x10" 482 for cnt in "0x10" "0x11" "0x12" "0x13"; do 483 # Using option 'tos' instead of 'dsfield' as old iproute2 484 # versions don't support 'dsfield' in ip rule show. 485 getmatch="tos $cnt" 486 getnomatch="tos 0x20" 487 fib_rule4_test_match_n_redirect "$match" "$getmatch" \ 488 "$getnomatch" "$getmatch redirect to table" \ 489 "$getnomatch no redirect to table" 490 done 491 492 # Re-test TOS matching, but with input routes since they are handled 493 # differently from output routes. 494 match="tos 0x10" 495 for cnt in "0x10" "0x11" "0x12" "0x13"; do 496 getmatch="tos $cnt" 497 getnomatch="tos 0x20" 498 fib_rule4_test_match_n_redirect "$match" \ 499 "from $SRC_IP iif $DEV $getmatch" \ 500 "from $SRC_IP iif $DEV $getnomatch" \ 501 "iif $getmatch redirect to table" \ 502 "iif $getnomatch no redirect to table" 503 done 504 505 match="fwmark 0x64" 506 getmatch="mark 0x64" 507 getnomatch="mark 0x63" 508 fib_rule4_test_match_n_redirect "$match" "$getmatch" "$getnomatch" \ 509 "fwmark redirect to table" "fwmark no redirect to table" 510 511 fib_check_iproute_support "uidrange" "uid" 512 if [ $? -eq 0 ]; then 513 match="uidrange 100-100" 514 getmatch="uid 100" 515 getnomatch="uid 101" 516 fib_rule4_test_match_n_redirect "$match" "$getmatch" \ 517 "$getnomatch" "uid redirect to table" \ 518 "uid no redirect to table" 519 fi 520 521 fib_check_iproute_support "sport" "sport" 522 if [ $? -eq 0 ]; then 523 match="sport 666 dport 777" 524 getnomatch="sport 667 dport 778" 525 fib_rule4_test_match_n_redirect "$match" "$match" \ 526 "$getnomatch" "sport and dport redirect to table" \ 527 "sport and dport no redirect to table" 528 fi 529 530 fib_check_iproute_support "ipproto" "ipproto" 531 if [ $? -eq 0 ]; then 532 match="ipproto tcp" 533 getnomatch="ipproto udp" 534 fib_rule4_test_match_n_redirect "$match" "$match" \ 535 "$getnomatch" "ipproto tcp match" \ 536 "ipproto udp no match" 537 fi 538 539 fib_check_iproute_support "ipproto" "ipproto" 540 if [ $? -eq 0 ]; then 541 match="ipproto icmp" 542 getnomatch="ipproto tcp" 543 fib_rule4_test_match_n_redirect "$match" "$match" \ 544 "$getnomatch" "ipproto icmp match" \ 545 "ipproto tcp no match" 546 fi 547 548 fib_check_iproute_support "dscp" "tos" 549 if [ $? -eq 0 ]; then 550 match="dscp 0x3f" 551 getmatch="tos 0xfc" 552 getnomatch="tos 0xf4" 553 fib_rule4_test_match_n_redirect "$match" "$getmatch" \ 554 "$getnomatch" "dscp redirect to table" \ 555 "dscp no redirect to table" 556 557 match="dscp 0x3f" 558 getmatch="from $SRC_IP iif $DEV tos 0xfc" 559 getnomatch="from $SRC_IP iif $DEV tos 0xf4" 560 fib_rule4_test_match_n_redirect "$match" "$getmatch" \ 561 "$getnomatch" "iif dscp redirect to table" \ 562 "iif dscp no redirect to table" 563 fi 564} 565 566fib_rule4_vrf_test() 567{ 568 setup_vrf 569 fib_rule4_test "- with VRF" 570 cleanup_vrf 571} 572 573# Verify that the IP_TOS option of UDPv4 and TCPv4 sockets is properly taken 574# into account when connecting the socket and when sending packets. 575fib_rule4_connect_test() 576{ 577 local dsfield 578 579 echo 580 echo "IPv4 FIB rule connect tests" 581 582 setup_peer 583 $IP -4 rule add dsfield 0x04 table $RTABLE_PEER 584 585 # Combine the base DS Field value (0x04) with all possible ECN values 586 # (Not-ECT: 0, ECT(1): 1, ECT(0): 2, CE: 3). 587 # The ECN bits shouldn't influence the result of the test. 588 for dsfield in 0x04 0x05 0x06 0x07; do 589 nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q "${dsfield}" \ 590 -l 198.51.100.11 -r 198.51.100.11 591 log_test $? 0 "rule4 dsfield udp connect (dsfield ${dsfield})" 592 593 nettest -q -B -t 5 -N $testns -O $peerns -Q "${dsfield}" \ 594 -l 198.51.100.11 -r 198.51.100.11 595 log_test $? 0 "rule4 dsfield tcp connect (dsfield ${dsfield})" 596 done 597 598 # Check that UDP and TCP connections fail when using a DS Field that 599 # does not match the previously configured FIB rule. 600 nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q 0x20 \ 601 -l 198.51.100.11 -r 198.51.100.11 602 log_test $? 1 "rule4 dsfield udp no connect (dsfield 0x20)" 603 604 nettest -q -B -t 5 -N $testns -O $peerns -Q 0x20 \ 605 -l 198.51.100.11 -r 198.51.100.11 606 log_test $? 1 "rule4 dsfield tcp no connect (dsfield 0x20)" 607 608 $IP -4 rule del dsfield 0x04 table $RTABLE_PEER 609 610 ip rule help 2>&1 | grep -q dscp 611 if [ $? -ne 0 ]; then 612 echo "SKIP: iproute2 iprule too old, missing dscp match" 613 cleanup_peer 614 return 615 fi 616 617 $IP -4 rule add dscp 0x3f table $RTABLE_PEER 618 619 nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q 0xfc \ 620 -l 198.51.100.11 -r 198.51.100.11 621 log_test $? 0 "rule4 dscp udp connect" 622 623 nettest -q -B -t 5 -N $testns -O $peerns -Q 0xfc \ 624 -l 198.51.100.11 -r 198.51.100.11 625 log_test $? 0 "rule4 dscp tcp connect" 626 627 nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q 0xf4 \ 628 -l 198.51.100.11 -r 198.51.100.11 629 log_test $? 1 "rule4 dscp udp no connect" 630 631 nettest -q -B -t 5 -N $testns -O $peerns -Q 0xf4 \ 632 -l 198.51.100.11 -r 198.51.100.11 633 log_test $? 1 "rule4 dscp tcp no connect" 634 635 $IP -4 rule del dscp 0x3f table $RTABLE_PEER 636 637 cleanup_peer 638} 639################################################################################ 640# usage 641 642usage() 643{ 644 cat <<EOF 645usage: ${0##*/} OPTS 646 647 -t <test> Test(s) to run (default: all) 648 (options: $TESTS) 649EOF 650} 651 652################################################################################ 653# main 654 655while getopts ":t:h" opt; do 656 case $opt in 657 t) TESTS=$OPTARG;; 658 h) usage; exit 0;; 659 *) usage; exit 1;; 660 esac 661done 662 663if [ "$(id -u)" -ne 0 ];then 664 echo "SKIP: Need root privileges" 665 exit $ksft_skip 666fi 667 668if [ ! -x "$(command -v ip)" ]; then 669 echo "SKIP: Could not run test without ip tool" 670 exit $ksft_skip 671fi 672 673check_gen_prog "nettest" 674 675# start clean 676cleanup &> /dev/null 677setup 678for t in $TESTS 679do 680 case $t in 681 fib_rule6_test|fib_rule6) fib_rule6_test;; 682 fib_rule4_test|fib_rule4) fib_rule4_test;; 683 fib_rule6_connect_test|fib_rule6_connect) fib_rule6_connect_test;; 684 fib_rule4_connect_test|fib_rule4_connect) fib_rule4_connect_test;; 685 fib_rule6_vrf_test|fib_rule6_vrf) fib_rule6_vrf_test;; 686 fib_rule4_vrf_test|fib_rule4_vrf) fib_rule4_vrf_test;; 687 688 help) echo "Test names: $TESTS"; exit 0;; 689 690 esac 691done 692cleanup 693 694if [ "$TESTS" != "none" ]; then 695 printf "\nTests passed: %3d\n" ${nsuccess} 696 printf "Tests failed: %3d\n" ${nfail} 697fi 698 699exit $ret 700