initiator.sh revision 231858
1231858Sbz#!/bin/sh 2231858Sbz#- 3231858Sbz# Copyright (c) 2012 Cisco Systems, Inc. 4231858Sbz# All rights reserved. 5231858Sbz# 6231858Sbz# This software was developed by Bjoern Zeeb under contract to 7231858Sbz# Cisco Systems, Inc.. 8231858Sbz# 9231858Sbz# Redistribution and use in source and binary forms, with or without 10231858Sbz# modification, are permitted provided that the following conditions 11231858Sbz# are met: 12231858Sbz# 1. Redistributions of source code must retain the above copyright 13231858Sbz# notice, this list of conditions and the following disclaimer. 14231858Sbz# 2. Redistributions in binary form must reproduce the above copyright 15231858Sbz# notice, this list of conditions and the following disclaimer in the 16231858Sbz# documentation and/or other materials provided with the distribution. 17231858Sbz# 18231858Sbz# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19231858Sbz# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20231858Sbz# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21231858Sbz# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22231858Sbz# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23231858Sbz# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24231858Sbz# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25231858Sbz# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26231858Sbz# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27231858Sbz# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28231858Sbz# SUCH DAMAGE. 29231858Sbz# 30231858Sbz# $FreeBSD: head/tools/test/netfibs/initiator.sh 231858 2012-02-17 04:26:24Z bz $ 31231858Sbz# 32231858Sbz 33231858Sbz# We will use the RFC5180 (and Errata) benchmarking working group prefix 34231858Sbz# 2001:0002::/48 for testing. 35231858SbzPREFIX="2001:2:" 36231858Sbz 37231858Sbz# Set IFACE to the real interface you want to run the test on. 38231858Sbz: ${IFACE:=lo0} 39231858Sbz 40231858Sbz# Number of seconds to wait for peer node to synchronize for test. 41231858Sbz: ${WAITS:=120} 42231858Sbz 43231858Sbz# Control port we use to exchange messages between nodes to sync. tests, etc. 44231858Sbz: ${CTRLPORT:=6666} 45231858Sbz 46231858Sbz# Get the number of FIBs from the kernel. 47231858SbzRT_NUMFIBS=`sysctl -n net.fibs` 48231858Sbz 49231858SbzOURADDR="2001:2:ff00::1" 50231858SbzPEERADDR="2001:2:ff00::2" 51231858SbzPEERLINKLOCAL="" 52231858Sbz 53231858Sbz# By default all commands must succeed. Individual tests may disable this 54231858Sbz# temporary. 55231858Sbzset -e 56231858Sbz 57231858Sbz# Debug magic. 58231858Sbzcase "${DEBUG}" in 59231858Sbz42) set -x ;; 60231858Sbzesac 61231858Sbz 62231858Sbz 63231858Sbz 64231858Sbz# 65231858Sbz# Helper functions. 66231858Sbz# 67231858Sbzcheck_rc() 68231858Sbz{ 69231858Sbz local _rc _exp _testno _testname _msg _r 70231858Sbz _rc=$1 71231858Sbz _exp=$2 72231858Sbz _testno=$3 73231858Sbz _testname="$4" 74231858Sbz _msg="$5" 75231858Sbz 76231858Sbz _r="not ok" 77231858Sbz if test ${_rc} -eq ${_exp}; then 78231858Sbz _r="ok" 79231858Sbz fi 80231858Sbz echo "${_r} ${_testno} ${_testname} # ${_msg} ${_rc} ${_exp}" 81231858Sbz} 82231858Sbz 83231858Sbzprint_debug() 84231858Sbz{ 85231858Sbz local _msg 86231858Sbz _msg="$*" 87231858Sbz 88231858Sbz case ${DEBUG} in 89231858Sbz ''|0) ;; 90231858Sbz *) echo "DEBUG: ${_msg}" >&2 ;; 91231858Sbz esac 92231858Sbz} 93231858Sbz 94231858Sbzdie() 95231858Sbz{ 96231858Sbz local _msg 97231858Sbz _msg="$*" 98231858Sbz 99231858Sbz echo "ERROR: ${_msg}" >&2 100231858Sbz exit 1 101231858Sbz} 102231858Sbz 103231858Sbz# 104231858Sbz# Test functions. 105231858Sbz# 106231858Sbz 107231858Sbz# Make sure the local link-local and global addresses are reachable 108231858Sbz# from all FIBs. 109231858Sbzcheck_local_addr() 110231858Sbz{ 111231858Sbz local _l i testno 112231858Sbz 113231858Sbz print_debug "Setting up interface ${IFACE}" 114231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up 115231858Sbz _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'` 116231858Sbz 117231858Sbz # Let things settle. 118231858Sbz print_debug "Waiting 4 seconds for things to settle" 119231858Sbz sleep 4 120231858Sbz 121231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 122231858Sbz testno=1 123231858Sbz i=0 124231858Sbz set +e 125231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 126231858Sbz print_debug "Testing FIB ${i}" 127231858Sbz 128231858Sbz setfib -F${i} ping6 -n -c1 ${_l} > /dev/null 2>&1 129231858Sbz check_rc $? 0 ${testno} "check_local_addr_${i}_l" \ 130231858Sbz "FIB ${i} ${_l}" 131231858Sbz testno=$((testno + 1)) 132231858Sbz 133231858Sbz setfib -F${i} ping6 -n -c1 ${OURADDR} > /dev/null 2>&1 134231858Sbz check_rc $? 0 ${testno} "check_local_addr_${i}_a" \ 135231858Sbz "FIB ${i} ${OURADDR}" 136231858Sbz testno=$((testno + 1)) 137231858Sbz 138231858Sbz i=$((i + 1)) 139231858Sbz done 140231858Sbz set -e 141231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 -alias 142231858Sbz} 143231858Sbz 144231858Sbz 145231858Sbz# Cloned tun(4) devices behave differently on FIB 0 vs. FIB 1..n after creation 146231858Sbz# (they also do in IPv4). 147231858Sbzcheck_local_tun() 148231858Sbz{ 149231858Sbz local _l i testno IFACE _msg 150231858Sbz 151231858Sbz IFACE=tun42 152231858Sbz print_debug "Setting up interface ${IFACE}" 153231858Sbz ifconfig ${IFACE} create 154231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up 155231858Sbz _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'` 156231858Sbz 157231858Sbz # Let things settle. 158231858Sbz print_debug "Waiting 4 seconds for things to settle" 159231858Sbz sleep 4 160231858Sbz 161231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 162231858Sbz testno=1 163231858Sbz _msg="" 164231858Sbz i=0 165231858Sbz set +e 166231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 167231858Sbz print_debug "Testing FIB ${i}" 168231858Sbz if test ${i} -gt 0; then 169231858Sbz # Flag the well known behaviour as such. 170231858Sbz _msg="TODO " 171231858Sbz fi 172231858Sbz 173231858Sbz setfib -F${i} ping6 -n -c1 ${_l} > /dev/null 2>&1 174231858Sbz check_rc $? 0 ${testno} "check_local_addr_${i}_l" \ 175231858Sbz "${_msg}FIB ${i} ${_l}" 176231858Sbz testno=$((testno + 1)) 177231858Sbz 178231858Sbz setfib -F${i} ping6 -n -c1 ${OURADDR} > /dev/null 2>&1 179231858Sbz check_rc $? 0 ${testno} "check_local_addr_${i}_a" \ 180231858Sbz "${_msg}FIB ${i} ${OURADDR}" 181231858Sbz testno=$((testno + 1)) 182231858Sbz 183231858Sbz i=$((i + 1)) 184231858Sbz done 185231858Sbz set -e 186231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 -alias 187231858Sbz ifconfig ${IFACE} destroy 188231858Sbz} 189231858Sbz 190231858Sbzcheck_remote_up() 191231858Sbz{ 192231858Sbz local _l i testno 193231858Sbz 194231858Sbz print_debug "Setting up interface ${IFACE}" 195231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up 196231858Sbz _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'` 197231858Sbz 198231858Sbz # Let things settle. 199231858Sbz print_debug "Waiting 4 seconds for things to settle" 200231858Sbz sleep 4 201231858Sbz 202231858Sbz 203231858Sbz 204231858Sbz} 205231858Sbz 206231858Sbzsend_greeting() 207231858Sbz{ 208231858Sbz local _l _greeting _keyword _fib _fibs _linklocal 209231858Sbz 210231858Sbz print_debug "Setting up interface ${IFACE}" 211231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up 212231858Sbz _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'` 213231858Sbz 214231858Sbz # Let things settle. 215231858Sbz print_debug "Waiting 4 seconds for things to settle" 216231858Sbz sleep 4 217231858Sbz 218231858Sbz # Cleanup firewall and install rules to always allow NS/NA to succeed. 219231858Sbz # The latter is needed to allow indvidiual less specific later rules 220231858Sbz # from test cases to just disallow any IPv6 traffic on a matching FIB. 221231858Sbz ipfw -f flush > /dev/null 2>&1 222231858Sbz ipfw add 5 permit ipv6-icmp from any to any icmp6types 135,136 fib 0 \ 223231858Sbz via ${IFACE} out > /dev/null 2>&1 224231858Sbz 225231858Sbz set +e 226231858Sbz i=0 227231858Sbz rc=-1 228231858Sbz while test ${i} -lt ${WAITS} -a ${rc} -ne 0; do 229231858Sbz print_debug "Sending greeting #${i} to peer" 230231858Sbz _greeting=`echo "SETUP ${RT_NUMFIBS} ${_l}" | \ 231231858Sbz nc -6 -w 1 ${PEERADDR} ${CTRLPORT}` 232231858Sbz rc=$? 233231858Sbz i=$((i + 1)) 234231858Sbz # Might sleep longer in total but better than to DoS 235231858Sbz # and not get anywhere. 236231858Sbz sleep 1 237231858Sbz done 238231858Sbz set -e 239231858Sbz 240231858Sbz read _keyword _fibs _linklocal <<EOI 241231858Sbz${_greeting} 242231858SbzEOI 243231858Sbz print_debug "_keyword=${_keyword}" 244231858Sbz print_debug "_fibs=${_fibs}" 245231858Sbz print_debug "_linklocal=${_linklocal}" 246231858Sbz case ${_keyword} in 247231858Sbz SETUP) ;; 248231858Sbz *) die "Got invalid keyword in greeting: ${_greeting}" 249231858Sbz ;; 250231858Sbz esac 251231858Sbz if test ${_fibs} -ne ${RT_NUMFIBS}; then 252231858Sbz die "Number of FIBs not matching ours (${RT_NUMFIBS}) in" \ 253231858Sbz "greeting: ${_greeting}" 254231858Sbz fi 255231858Sbz PEERLINKLOCAL=${_linklocal} 256231858Sbz 257231858Sbz # Swap the zoneid to the local interface scope. 258231858Sbz PEERLINKLOCAL="${PEERLINKLOCAL%%\%*}%${IFACE}" 259231858Sbz 260231858Sbz print_debug "Successfully exchanged greeting. Peer at ${PEERLINKLOCAL}" 261231858Sbz} 262231858Sbz 263231858Sbzcleanup() 264231858Sbz{ 265231858Sbz 266231858Sbz # Cleanup ipfw. 267231858Sbz ipfw delete 5 > /dev/null 2>&1 268231858Sbz 269231858Sbz print_debug "Removing address from interface ${IFACE}" 270231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 -alias 271231858Sbz} 272231858Sbz 273231858Sbztesttx_icmp6() 274231858Sbz{ 275231858Sbz local _n _transfer i testno _txt _fibtxt _rc _ec _p 276231858Sbz _n="$1" 277231858Sbz _transfer=$2 278231858Sbz 279231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 280231858Sbz testno=1 281231858Sbz set +e 282231858Sbz i=0 283231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 284231858Sbz _txt="${_n}${i}" 285231858Sbz print_debug "Testing ${_txt}" 286231858Sbz _fibtxt=`echo "${_txt}" | hd -v | cut -b11-60 | tr -d ' \r\n'` 287231858Sbz 288231858Sbz eval _rc="\${rc_${i}_l}" 289231858Sbz setfib -F${i} ping6 -n -c1 -p ${_fibtxt} \ 290231858Sbz ${PEERLINKLOCAL} > /dev/null 2>&1 291231858Sbz _ec=$? 292231858Sbz # We need to normalize the exit code of ping6. 293231858Sbz case ${_ec} in 294231858Sbz 0) ;; 295231858Sbz *) _ec=1 ;; 296231858Sbz esac 297231858Sbz check_rc ${_ec} ${_rc} ${testno} "${_txt}_l" \ 298231858Sbz "FIB ${i} ${PEERLINKLOCAL}" 299231858Sbz testno=$((testno + 1)) 300231858Sbz 301231858Sbz # If doing multiple transfer networks, replace PEERADDR. 302231858Sbz _p="${PEERADDR}" 303231858Sbz case ${_transfer} in 304231858Sbz 1) PEERADDR=2001:2:${i}::2 ;; 305231858Sbz esac 306231858Sbz 307231858Sbz eval _rc="\${rc_${i}_a}" 308231858Sbz setfib -F${i} ping6 -n -c1 -p ${_fibtxt} ${PEERADDR} \ 309231858Sbz > /dev/null 2>&1 310231858Sbz _ec=$? 311231858Sbz # We need to normalize the exit code of ping6. 312231858Sbz case ${_ec} in 313231858Sbz 0) ;; 314231858Sbz *) _ec=1 ;; 315231858Sbz esac 316231858Sbz check_rc ${_ec} ${_rc} ${testno} "${_txt}_a" \ 317231858Sbz "FIB ${i} ${PEERADDR}" 318231858Sbz testno=$((testno + 1)) 319231858Sbz 320231858Sbz # Restore PEERADDR. 321231858Sbz PEERADDR="${_p}" 322231858Sbz 323231858Sbz i=$((i + 1)) 324231858Sbz done 325231858Sbz set -e 326231858Sbz} 327231858Sbz 328231858Sbznc_send_recv() 329231858Sbz{ 330231858Sbz local _fib _loops _msg _expreply _addr _port _opts i 331231858Sbz _fib=$1 332231858Sbz _loops=$2 333231858Sbz _msg="$3" 334231858Sbz _expreply="$4" 335231858Sbz _addr=$5 336231858Sbz _port=$6 337231858Sbz _opts="$7" 338231858Sbz 339231858Sbz i=0 340231858Sbz while test ${i} -lt ${_loops}; do 341231858Sbz i=$((i + 1)) 342231858Sbz case "${USE_SOSETFIB}" in 343231858Sbz 1) 344231858Sbz _reply=`echo "${_msg}" | \ 345231858Sbz nc -V ${_fib} ${_opts} ${_addr} ${_port}` 346231858Sbz ;; 347231858Sbz *) 348231858Sbz _reply=`echo "${_msg}" | \ 349231858Sbz setfib -F${_fib} nc ${_opts} ${_addr} ${_port}` 350231858Sbz ;; 351231858Sbz esac 352231858Sbz if test "${_reply}" != "${_expreply}"; then 353231858Sbz if test ${i} -lt ${_loops}; then 354231858Sbz sleep 1 355231858Sbz else 356231858Sbz # Must let caller decide how to handle the error. 357231858Sbz # die "Got invalid reply from peer." \ 358231858Sbz # "Expected '${_expreply}', got '${_reply}'" 359231858Sbz return 1 360231858Sbz fi 361231858Sbz else 362231858Sbz break 363231858Sbz fi 364231858Sbz done 365231858Sbz return 0 366231858Sbz} 367231858Sbz 368231858Sbztesttx_tcp_udp() 369231858Sbz{ 370231858Sbz local _n _o _f testno i _fibtxt 371231858Sbz _n="$1" 372231858Sbz _o="$2" 373231858Sbz _f="$3" 374231858Sbz 375231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 376231858Sbz testno=1 377231858Sbz i=0 378231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 379231858Sbz print_debug "Testing ${_f} ${i}" 380231858Sbz 381231858Sbz eval _rc="\${rc_${i}_l}" 382231858Sbz _fibtxt="${_n}_${i}_l ${_f} ${i} ${PEERLINKLOCAL}" 383231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_fibtxt}" ${PEERLINKLOCAL} \ 384231858Sbz ${CTRLPORT} "-6 ${_o} -w1" 385231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" 386231858Sbz testno=$((testno + 1)) 387231858Sbz 388231858Sbz eval _rc="\${rc_${i}_a}" 389231858Sbz _fibtxt="${_n}_${i}_a ${_f} ${i} ${PEERADDR}" 390231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_fibtxt}" ${PEERADDR} \ 391231858Sbz ${CTRLPORT} "-6 ${_o} -w1" 392231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" 393231858Sbz testno=$((testno + 1)) 394231858Sbz 395231858Sbz i=$((i + 1)) 396231858Sbz done 397231858Sbz} 398231858Sbz 399231858Sbz# setfib TCP|UDP/IPv6 test on link-local and global address of peer from all FIBs. 400231858Sbztesttx_ulp6_connected() 401231858Sbz{ 402231858Sbz local _fibtxt _reply _n _o _rc _fib _f _opts 403231858Sbz _n=$1 404231858Sbz _o="$2" 405231858Sbz _fib=$3 406231858Sbz 407231858Sbz case "${USE_SOSETFIB}" in 408231858Sbz 1) _f="SO_SETFIB" ;; 409231858Sbz *) _f="SETFIB" ;; 410231858Sbz esac 411231858Sbz 412231858Sbz if test "${_o}" == "-i" -a "${_f}" == "SO_SETFIB"; then 413231858Sbz print_debug "Skipping icmp6 tests for SO_SETFIB." 414231858Sbz return 0 415231858Sbz fi 416231858Sbz 417231858Sbz # Clear the neighbor table to get deterministic runs. 418231858Sbz ndp -cn > /dev/null 2>&1 419231858Sbz 420231858Sbz case "${_o}" in 421231858Sbz -i) _opts="" ;; # Use TCP for START/DONE. 422231858Sbz *) _opts="${_o}" ;; 423231858Sbz esac 424231858Sbz 425231858Sbz set +e 426231858Sbz # Let peer know that we are about to start. 427231858Sbz _msg="START ${_n}" 428231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 429231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 430231858Sbz case $? in 431231858Sbz 0) ;; 432231858Sbz *) die "Got invalid reply from peer." \ 433231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 434231858Sbz esac 435231858Sbz 436231858Sbz case "${_o}" in 437231858Sbz -i) testtx_icmp6 "${_n}" ;; 438231858Sbz *) testtx_tcp_udp "${_n}" "${_o}" "${_f}" ;; 439231858Sbz esac 440231858Sbz 441231858Sbz # Let peer know that we are done with this test to move to next. 442231858Sbz # This must immediately succeed. 443231858Sbz _msg="DONE ${_n}" 444231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 445231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 446231858Sbz case $? in 447231858Sbz 0) ;; 448231858Sbz *) die "Got invalid reply from peer." \ 449231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 450231858Sbz esac 451231858Sbz set -e 452231858Sbz 453231858Sbz print_debug "Successfully received status update '${_reply}'." 454231858Sbz} 455231858Sbz 456231858Sbz################################################################################ 457231858Sbz# 458231858Sbz# ping6|TCP/UDP connect link-local and global address of peer from all FIBs. 459231858Sbz# Default reachability test. 460231858Sbz# 461231858Sbztesttx_icmp6_connected() 462231858Sbz{ 463231858Sbz local i 464231858Sbz 465231858Sbz # Setup expected return values. 466231858Sbz i=0 467231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 468231858Sbz eval rc_${i}_l=0 469231858Sbz eval rc_${i}_a=0 470231858Sbz i=$((i + 1)) 471231858Sbz done 472231858Sbz 473231858Sbz testtx_ulp6_connected "testtx_icmp6_connected" "-i" 0 474231858Sbz} 475231858Sbz 476231858Sbztesttx_tcp6_connected() 477231858Sbz{ 478231858Sbz local i 479231858Sbz 480231858Sbz # Setup expected return values. 481231858Sbz i=0 482231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 483231858Sbz eval rc_${i}_l=0 484231858Sbz eval rc_${i}_a=0 485231858Sbz i=$((i + 1)) 486231858Sbz done 487231858Sbz 488231858Sbz testtx_ulp6_connected testtx_tcp6_connected "" 0 489231858Sbz} 490231858Sbz 491231858Sbztesttx_udp6_connected() 492231858Sbz{ 493231858Sbz local i 494231858Sbz 495231858Sbz # Setup expected return values. 496231858Sbz i=0 497231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 498231858Sbz eval rc_${i}_l=0 499231858Sbz eval rc_${i}_a=0 500231858Sbz i=$((i + 1)) 501231858Sbz done 502231858Sbz 503231858Sbz testtx_ulp6_connected testtx_udp6_connected "-u" 0 504231858Sbz} 505231858Sbz 506231858Sbz################################################################################ 507231858Sbz# 508231858Sbz# Use ipfw to return unreach messages for all but one FIB. Rotate over all. 509231858Sbz# Making sure error messages are properly returned. 510231858Sbz# 511231858Sbztesttx_ulp6_connected_blackhole() 512231858Sbz{ 513231858Sbz local _fib i _n _o 514231858Sbz _n="$1" 515231858Sbz _o="$2" 516231858Sbz 517231858Sbz _fib=0 518231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 519231858Sbz 520231858Sbz print_debug "${_n} ${_fib}" 521231858Sbz 522231858Sbz # Setup expected return values. 523231858Sbz i=0 524231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 525231858Sbz ipfw delete $((100 + i)) > /dev/null 2>&1 || true 526231858Sbz case ${i} in 527231858Sbz ${_fib}) 528231858Sbz eval rc_${i}_l=0 529231858Sbz eval rc_${i}_a=0 530231858Sbz ;; 531231858Sbz *) eval rc_${i}_l=1 532231858Sbz eval rc_${i}_a=1 533231858Sbz ipfw add $((100 + i)) unreach6 admin-prohib \ 534231858Sbz ip6 from any to any fib ${i} via ${IFACE} \ 535231858Sbz out > /dev/null 2>&1 536231858Sbz ;; 537231858Sbz esac 538231858Sbz i=$((i + 1)) 539231858Sbz done 540231858Sbz 541231858Sbz testtx_ulp6_connected "${_n}${_fib}" "${_o}" ${_fib} 542231858Sbz case ${DEBUG} in 543231858Sbz ''|0) ;; 544231858Sbz *) ipfw show ;; 545231858Sbz esac 546231858Sbz _fib=$((_fib + 1)) 547231858Sbz done 548231858Sbz _fib=0 549231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 550231858Sbz ipfw delete $((100 + _fib)) > /dev/null 2>&1 || true 551231858Sbz _fib=$((_fib + 1)) 552231858Sbz done 553231858Sbz} 554231858Sbz 555231858Sbztesttx_icmp6_connected_blackhole() 556231858Sbz{ 557231858Sbz 558231858Sbz testtx_ulp6_connected_blackhole \ 559231858Sbz "testtx_icmp6_connected_blackhole" "-i" 560231858Sbz} 561231858Sbz 562231858Sbztesttx_tcp6_connected_blackhole() 563231858Sbz{ 564231858Sbz 565231858Sbz testtx_ulp6_connected_blackhole \ 566231858Sbz "testtx_tcp6_connected_blackhole" "" 567231858Sbz} 568231858Sbz 569231858Sbztesttx_udp6_connected_blackhole() 570231858Sbz{ 571231858Sbz 572231858Sbz testtx_ulp6_connected_blackhole \ 573231858Sbz "testtx_udp6_connected_blackhole" "-u" 574231858Sbz} 575231858Sbz 576231858Sbz################################################################################ 577231858Sbz# 578231858Sbz# Setup a different transfer net on each FIB. Delete all but one connected 579231858Sbz# route in all FIBs (e.g. FIB 0 uses prefix 0, FIB 1 uses prefix 1 , ...). 580231858Sbz# 581231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 582231858Sbz# know about the prefix and thus cannot do proper source address lookups for 583231858Sbz# replying otherwise. Use ipfw. 584231858Sbz# 585231858Sbztesttx_ulp6_connected_transfernets() 586231858Sbz{ 587231858Sbz local _fib i _n _o _p 588231858Sbz _n="$1" 589231858Sbz _o="$2" 590231858Sbz 591231858Sbz # Setup transfer networks and firewall. 592231858Sbz ipfw delete 10 > /dev/null 2>&1 || true 593231858Sbz _fib=0 594231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 595231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias \ 596231858Sbz > /dev/null 2>&1 || true 597231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 alias 598231858Sbz ipfw add 10 setfib ${_fib} ipv6-icmp from 2001:2:${_fib}::/64 \ 599231858Sbz to any ip6 icmp6types 135,136 via ${IFACE} in \ 600231858Sbz > /dev/null 2>&1 601231858Sbz # Remove connected routes from all but matching FIB. 602231858Sbz i=0 603231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 604231858Sbz case ${i} in 605231858Sbz ${_fib});; 606231858Sbz *) setfib -F${i} route delete -inet6 \ 607231858Sbz -net 2001:2:${_fib}:: > /dev/null 2>&1 608231858Sbz ;; 609231858Sbz esac 610231858Sbz i=$((i + 1)) 611231858Sbz done 612231858Sbz _fib=$((_fib + 1)) 613231858Sbz done 614231858Sbz 615231858Sbz # Save PEERADDR 616231858Sbz _p=${PEERADDR} 617231858Sbz 618231858Sbz # Run tests. 619231858Sbz _fib=0 620231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 621231858Sbz PEERADDR=2001:2:${_fib}::2 622231858Sbz 623231858Sbz print_debug "${_n} ${_fib}" 624231858Sbz 625231858Sbz # Setup expected return values. 626231858Sbz i=0 627231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 628231858Sbz eval rc_${i}_l=0 629231858Sbz case ${i} in 630231858Sbz ${_fib}) 631231858Sbz eval rc_${i}_a=0 632231858Sbz ;; 633231858Sbz *) eval rc_${i}_a=1 634231858Sbz ;; 635231858Sbz esac 636231858Sbz i=$((i + 1)) 637231858Sbz done 638231858Sbz 639231858Sbz testtx_ulp6_connected "${_n}${_fib}" "${_o}" ${_fib} 640231858Sbz _fib=$((_fib + 1)) 641231858Sbz done 642231858Sbz 643231858Sbz # Restore PEERADDR 644231858Sbz PEERADDR=${_p} 645231858Sbz 646231858Sbz # Cleanup transfer networks and firewall. 647231858Sbz _fib=0 648231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 649231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias 650231858Sbz _fib=$((_fib + 1)) 651231858Sbz done 652231858Sbz ipfw delete 10 > /dev/null 2>&1 653231858Sbz} 654231858Sbz 655231858Sbztesttx_icmp6_connected_transfernets() 656231858Sbz{ 657231858Sbz 658231858Sbz testtx_ulp6_connected_transfernets \ 659231858Sbz "testtx_icmp6_connected_transfernets" "-i" 660231858Sbz} 661231858Sbz 662231858Sbztesttx_tcp6_connected_transfernets() 663231858Sbz{ 664231858Sbz 665231858Sbz testtx_ulp6_connected_transfernets \ 666231858Sbz "testtx_tcp6_connected_transfernets" "" 667231858Sbz} 668231858Sbz 669231858Sbztesttx_udp6_connected_transfernets() 670231858Sbz{ 671231858Sbz 672231858Sbz testtx_ulp6_connected_transfernets \ 673231858Sbz "testtx_udp6_connected_transfernets" "-u" 674231858Sbz} 675231858Sbz 676231858Sbz################################################################################ 677231858Sbz# 678231858Sbz# Setup a different transfernet on each FIB. Delete all but one connected 679231858Sbz# route in all FIBs (e.g. FIB 0 uses prefix 0, FIB 1 uses prefix 1 , ...). 680231858Sbz# 681231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 682231858Sbz# know about the prefix and thus cannot do proper source address lookups for 683231858Sbz# replying otherwise. Use ifconfig IFACE fib. 684231858Sbz# 685231858Sbztesttx_ulp6_connected_ifconfig_transfernets() 686231858Sbz{ 687231858Sbz local _fib i _n _o _p 688231858Sbz _n="$1" 689231858Sbz _o="$2" 690231858Sbz 691231858Sbz # Setup transfer networks. 692231858Sbz _fib=0 693231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 694231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias \ 695231858Sbz > /dev/null 2>&1 || true 696231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 alias 697231858Sbz # Remove connected routes from all but matching FIB. 698231858Sbz i=0 699231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 700231858Sbz case ${i} in 701231858Sbz ${_fib});; 702231858Sbz *) setfib -F${i} route delete -inet6 \ 703231858Sbz -net 2001:2:${_fib}:: > /dev/null 2>&1 704231858Sbz ;; 705231858Sbz esac 706231858Sbz i=$((i + 1)) 707231858Sbz done 708231858Sbz _fib=$((_fib + 1)) 709231858Sbz done 710231858Sbz 711231858Sbz # Save PEERADDR 712231858Sbz _p=${PEERADDR} 713231858Sbz 714231858Sbz # Run tests. 715231858Sbz _fib=0 716231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 717231858Sbz PEERADDR=2001:2:${_fib}::2 718231858Sbz 719231858Sbz print_debug "${_n} ${_fib}" 720231858Sbz 721231858Sbz # Setup expected return values. 722231858Sbz i=0 723231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 724231858Sbz eval rc_${i}_l=0 725231858Sbz case ${i} in 726231858Sbz ${_fib}) 727231858Sbz eval rc_${i}_a=0 728231858Sbz ;; 729231858Sbz *) eval rc_${i}_a=1 730231858Sbz ;; 731231858Sbz esac 732231858Sbz i=$((i + 1)) 733231858Sbz done 734231858Sbz 735231858Sbz ifconfig ${IFACE} fib ${_fib} 736231858Sbz 737231858Sbz testtx_ulp6_connected "${_n}${_fib}" "${_o}" ${_fib} 738231858Sbz _fib=$((_fib + 1)) 739231858Sbz done 740231858Sbz 741231858Sbz # Restore PEERADDR 742231858Sbz PEERADDR=${_p} 743231858Sbz 744231858Sbz # Cleanup transfer networks. 745231858Sbz _fib=0 746231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 747231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias 748231858Sbz _fib=$((_fib + 1)) 749231858Sbz done 750231858Sbz ifconfig ${IFACE} fib 0 751231858Sbz} 752231858Sbz 753231858Sbztesttx_icmp6_connected_ifconfig_transfernets() 754231858Sbz{ 755231858Sbz 756231858Sbz testtx_ulp6_connected_ifconfig_transfernets \ 757231858Sbz "testtx_icmp6_connected_ifconfig_transfernets" "-i" 758231858Sbz} 759231858Sbz 760231858Sbz 761231858Sbztesttx_tcp6_connected_ifconfig_transfernets() 762231858Sbz{ 763231858Sbz 764231858Sbz testtx_ulp6_connected_ifconfig_transfernets \ 765231858Sbz "testtx_tcp6_connected_ifconfig_transfernets" "" 766231858Sbz} 767231858Sbz 768231858Sbztesttx_udp6_connected_ifconfig_transfernets() 769231858Sbz{ 770231858Sbz 771231858Sbz testtx_ulp6_connected_ifconfig_transfernets \ 772231858Sbz "testtx_udp6_connected_ifconfig_transfernets" "-u" 773231858Sbz} 774231858Sbz 775231858Sbz################################################################################ 776231858Sbz# 777231858Sbz# Make destination reachable through the same default route in each FIB only. 778231858Sbz# Run standard reachability test. 779231858Sbz# 780231858Sbztesttx_ulp6_gateway() 781231858Sbz{ 782231858Sbz local _fib i _n _o _p 783231858Sbz _n="$1" 784231858Sbz _o="$2" 785231858Sbz 786231858Sbz # Setup default gateway and expected error codes. 787231858Sbz _fib=0 788231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 789231858Sbz setfib -F${_fib} route delete -inet6 -net default \ 790231858Sbz > /dev/null 2>&1 || true 791231858Sbz setfib -F${_fib} route add -inet6 -net default ${PEERADDR} \ 792231858Sbz > /dev/null 2>&1 793231858Sbz case "${_o}" in 794231858Sbz -i) eval rc_${_fib}_l=0 ;; # ICMPv6 will succeed 795231858Sbz *) eval rc_${_fib}_l=1 ;; 796231858Sbz esac 797231858Sbz eval rc_${_fib}_a=0 798231858Sbz _fib=$((_fib + 1)) 799231858Sbz done 800231858Sbz 801231858Sbz # Save PEERADDR 802231858Sbz _p=${PEERADDR} 803231858Sbz PEERADDR="2001:2:ff01::2" 804231858Sbz 805231858Sbz # Run tests. 806231858Sbz print_debug "${_n}" 807231858Sbz testtx_ulp6_connected "${_n}" "${_o}" 0 808231858Sbz 809231858Sbz # Restore PEERADDR 810231858Sbz PEERADDR=${_p} 811231858Sbz 812231858Sbz # Cleanup transfer networks. 813231858Sbz _fib=0 814231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 815231858Sbz setfib -F${_fib} route delete -inet6 -net default \ 816231858Sbz > /dev/null 2>&1 817231858Sbz _fib=$((_fib + 1)) 818231858Sbz done 819231858Sbz} 820231858Sbz 821231858Sbztesttx_icmp6_gateway() 822231858Sbz{ 823231858Sbz 824231858Sbz testtx_ulp6_gateway "testtx_icmp6_gateway" "-i" 825231858Sbz} 826231858Sbz 827231858Sbztesttx_tcp6_gateway() 828231858Sbz{ 829231858Sbz 830231858Sbz testtx_ulp6_gateway "testtx_tcp6_gateway" "" 831231858Sbz} 832231858Sbz 833231858Sbztesttx_udp6_gateway() 834231858Sbz{ 835231858Sbz 836231858Sbz testtx_ulp6_gateway "testtx_udp6_gateway" "-u" 837231858Sbz} 838231858Sbz 839231858Sbz################################################################################ 840231858Sbz# 841231858Sbz# Make destination reachable through a different default route in each FIB. 842231858Sbz# Generate a dedicated transfer network for that in each FIB. Delete all but 843231858Sbz# one connected route in all FIBs (e.g. FIB 0 uses prefix 0, ...). 844231858Sbz# 845231858Sbz# Have a default route present in each FIB all time. 846231858Sbz# 847231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 848231858Sbz# know about the prefix and thus cannot do proper source address lookups for 849231858Sbz# replying otherwise. Use ipfw. 850231858Sbz# 851231858Sbz# 852231858Sbztesttx_ulp6_transfernets_gateways() 853231858Sbz{ 854231858Sbz local _fib i _n _o _p 855231858Sbz _n="$1" 856231858Sbz _o="$2" 857231858Sbz 858231858Sbz # Setup transfer networks, default routes, and firewall. 859231858Sbz _fib=0 860231858Sbz ipfw delete 10 > /dev/null 2>&1 || true 861231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 862231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias \ 863231858Sbz > /dev/null 2>&1 || true 864231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 alias \ 865231858Sbz > /dev/null 2>&1 866231858Sbz ipfw add 10 setfib ${_fib} ipv6-icmp \ 867231858Sbz from 2001:2:${_fib}::/64 to any ip6 icmp6types 135,136 \ 868231858Sbz via ${IFACE} in > /dev/null 2>&1 869231858Sbz # Remove connected routes from all but matching FIB. 870231858Sbz i=0 871231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 872231858Sbz case ${i} in 873231858Sbz ${_fib});; 874231858Sbz *) setfib -F${i} route delete -inet6 \ 875231858Sbz -net 2001:2:${_fib}:: > /dev/null 2>&1 876231858Sbz ;; 877231858Sbz esac 878231858Sbz i=$((i + 1)) 879231858Sbz done 880231858Sbz # Add default route. 881231858Sbz setfib -F${_fib} route delete -inet6 -net default \ 882231858Sbz > /dev/null 2>&1 || true 883231858Sbz setfib -F${_fib} route add -inet6 -net default \ 884231858Sbz 2001:2:${_fib}::2 > /dev/null 2>&1 885231858Sbz _fib=$((_fib + 1)) 886231858Sbz done 887231858Sbz 888231858Sbz # Save PEERADDR 889231858Sbz _p=${PEERADDR} 890231858Sbz PEERADDR="2001:2:ff01::2" 891231858Sbz 892231858Sbz # Setup expected return values. 893231858Sbz i=0 894231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 895231858Sbz case "${_o}" in 896231858Sbz -i) eval rc_${i}_l=0 ;; # ICMPv6 will succeed 897231858Sbz *) eval rc_${i}_l=1 ;; 898231858Sbz esac 899231858Sbz eval rc_${i}_a=0 900231858Sbz i=$((i + 1)) 901231858Sbz done 902231858Sbz 903231858Sbz # Run tests. 904231858Sbz print_debug "${_n}" 905231858Sbz testtx_ulp6_connected "${_n}" "${_o}" 0 906231858Sbz 907231858Sbz # Restore PEERADDR 908231858Sbz PEERADDR=${_p} 909231858Sbz 910231858Sbz # Cleanup default routes, transfer networks, and firewall. 911231858Sbz _fib=0 912231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 913231858Sbz setfib -F${_fib} route delete -inet6 -net default \ 914231858Sbz > /dev/null 2>&1 915231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias \ 916231858Sbz > /dev/null 2>&1 917231858Sbz _fib=$((_fib + 1)) 918231858Sbz done 919231858Sbz ipfw delete 10 > /dev/null 2>&1 920231858Sbz} 921231858Sbz 922231858Sbztesttx_icmp6_transfernets_gateways() 923231858Sbz{ 924231858Sbz 925231858Sbz testtx_ulp6_transfernets_gateways \ 926231858Sbz "testtx_icmp6_transfernets_gateways" "-i" 927231858Sbz} 928231858Sbz 929231858Sbztesttx_tcp6_transfernets_gateways() 930231858Sbz{ 931231858Sbz 932231858Sbz testtx_ulp6_transfernets_gateways \ 933231858Sbz "testtx_tcp6_transfernets_gateways" "" 934231858Sbz} 935231858Sbz 936231858Sbztesttx_udp6_transfernets_gateways() 937231858Sbz{ 938231858Sbz 939231858Sbz testtx_ulp6_transfernets_gateways \ 940231858Sbz "testtx_udp6_transfernets_gateways" "-u" 941231858Sbz} 942231858Sbz 943231858Sbz################################################################################ 944231858Sbz# 945231858Sbz# Make destination reachable through a different default route in each FIB. 946231858Sbz# Generate a dedicated transfer network for that in each FIB. Delete all but 947231858Sbz# one connected route in all FIBs (e.g. FIB 0 uses prefix 0, ...). 948231858Sbz# 949231858Sbz# Only have a default route present in 1 FIB at a time. 950231858Sbz# 951231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 952231858Sbz# know about the prefix and thus cannot do proper source address lookups for 953231858Sbz# replying otherwise. Use ipfw. 954231858Sbz# 955231858Sbztesttx_ulp6_transfernets_gateway() 956231858Sbz{ 957231858Sbz local _fib i _n _o _p 958231858Sbz _n="$1" 959231858Sbz _o="$2" 960231858Sbz 961231858Sbz # Setup transfer networks, default routes, and firewall. 962231858Sbz _fib=0 963231858Sbz ipfw delete 10 > /dev/null 2>&1 || true 964231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 965231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias \ 966231858Sbz > /dev/null 2>&1 || true 967231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 alias \ 968231858Sbz > /dev/null 2>&1 969231858Sbz ipfw add 10 setfib ${_fib} ipv6-icmp \ 970231858Sbz from 2001:2:${_fib}::/64 to any ip6 icmp6types 135,136 \ 971231858Sbz via ${IFACE} in > /dev/null 2>&1 972231858Sbz # Remove connected routes from all but matching FIB. 973231858Sbz i=0 974231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 975231858Sbz case ${i} in 976231858Sbz ${_fib});; 977231858Sbz *) setfib -F${i} route delete -inet6 \ 978231858Sbz -net 2001:2:${_fib}:: > /dev/null 2>&1 979231858Sbz ;; 980231858Sbz esac 981231858Sbz i=$((i + 1)) 982231858Sbz done 983231858Sbz _fib=$((_fib + 1)) 984231858Sbz done 985231858Sbz 986231858Sbz # Save PEERADDR 987231858Sbz _p=${PEERADDR} 988231858Sbz PEERADDR="2001:2:ff01::2" 989231858Sbz 990231858Sbz # Run tests. 991231858Sbz _fib=0 992231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 993231858Sbz 994231858Sbz print_debug "${_n} ${_fib}" 995231858Sbz 996231858Sbz # Setup expected return values. 997231858Sbz i=0 998231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 999231858Sbz case "${_o}" in 1000231858Sbz -i) eval rc_${i}_l=0 ;; # ICMPv6 will succeed 1001231858Sbz *) eval rc_${i}_l=1 ;; 1002231858Sbz esac 1003231858Sbz case ${i} in 1004231858Sbz ${_fib}) 1005231858Sbz eval rc_${i}_a=0 1006231858Sbz ;; 1007231858Sbz *) eval rc_${i}_a=1 1008231858Sbz ;; 1009231858Sbz esac 1010231858Sbz i=$((i + 1)) 1011231858Sbz done 1012231858Sbz 1013231858Sbz # Add default route. 1014231858Sbz setfib -F${_fib} route delete -inet6 -net default \ 1015231858Sbz > /dev/null 2>&1 || true 1016231858Sbz setfib -F${_fib} route add -inet6 -net default \ 1017231858Sbz 2001:2:${_fib}::2 > /dev/null 2>&1 1018231858Sbz 1019231858Sbz testtx_ulp6_connected "${_n}${_fib}" "${_o}" ${_fib} 1020231858Sbz 1021231858Sbz # Delete default route again. 1022231858Sbz setfib -F${_fib} route delete -inet6 -net default \ 1023231858Sbz > /dev/null 2>&1 1024231858Sbz _fib=$((_fib + 1)) 1025231858Sbz done 1026231858Sbz 1027231858Sbz # Restore PEERADDR 1028231858Sbz PEERADDR=${_p} 1029231858Sbz 1030231858Sbz # Cleanup default routes, transfer networks, and firewall. 1031231858Sbz _fib=0 1032231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 1033231858Sbz setfib -F${_fib} route delete -inet6 -net default \ 1034231858Sbz > /dev/null 2>&1 1035231858Sbz ifconfig ${IFACE} inet6 2001:2:${_fib}::1/64 -alias \ 1036231858Sbz > /dev/null 2>&1 1037231858Sbz _fib=$((_fib + 1)) 1038231858Sbz done 1039231858Sbz ipfw delete 10 > /dev/null 2>&1 1040231858Sbz} 1041231858Sbz 1042231858Sbztesttx_icmp6_transfernets_gateway() 1043231858Sbz{ 1044231858Sbz 1045231858Sbz testtx_ulp6_transfernets_gateway \ 1046231858Sbz "testtx_icmp6_transfernets_gateway" "-i" 1047231858Sbz} 1048231858Sbz 1049231858Sbz 1050231858Sbztesttx_tcp6_transfernets_gateway() 1051231858Sbz{ 1052231858Sbz 1053231858Sbz testtx_ulp6_transfernets_gateway \ 1054231858Sbz "testtx_tcp6_transfernets_gateway" "" 1055231858Sbz} 1056231858Sbz 1057231858Sbztesttx_udp6_transfernets_gateway() 1058231858Sbz{ 1059231858Sbz 1060231858Sbz testtx_ulp6_transfernets_gateway \ 1061231858Sbz "testtx_udp6_transfernets_gateway" "-u" 1062231858Sbz} 1063231858Sbz 1064231858Sbz 1065231858Sbz################################################################################ 1066231858Sbz# 1067231858Sbz# RX tests (Remotely originated connections). The FIB tests happens on peer. 1068231858Sbz# 1069231858Sbz# # For IPFW, IFCONFIG 1070231858Sbz# # For each FIB 1071231858Sbz# # Send OOB well known to work START, wait for reflect 1072231858Sbz# # Send probe, wait for reply with FIB# or RST/ICMP6 unreach 1073231858Sbz# # (in case of ICMP6 use magic like ipfw count and OOB reply) 1074231858Sbz# # Send OOB well known to work DONE, wait for reflect 1075231858Sbz# # Compare real with expected results. 1076231858Sbz# 1077231858Sbztestrx_results() 1078231858Sbz{ 1079231858Sbz local _r _n _fib i count _instances _transfer _o 1080231858Sbz _fib="$1" 1081231858Sbz _n="$2" 1082231858Sbz _r="$3" 1083231858Sbz _instances=$4 1084231858Sbz _transfer=$5 1085231858Sbz _o="$6" 1086231858Sbz 1087231858Sbz print_debug "testrx_results ${_fib} ${_n} ${_r} ${_instances}" 1088231858Sbz 1089231858Sbz # Trim "RESULT " 1090231858Sbz _r=${_r#* } 1091231858Sbz 1092231858Sbz echo "1..${RT_NUMFIBS}" 1093231858Sbz while read i count; do 1094231858Sbz if test ${_instances} -gt 1; then 1095231858Sbz if test ${count} -gt 0; then 1096231858Sbz echo "ok ${i} ${_n}result_${i} #" \ 1097231858Sbz "FIB ${i} ${count} (tested)" 1098231858Sbz else 1099231858Sbz echo "not ok ${i} ${_n}result_${i} #" \ 1100231858Sbz "FIB ${i} ${count} (tested)" 1101231858Sbz fi 1102231858Sbz else 1103231858Sbz case ${i} in 1104231858Sbz ${_fib}) 1105231858Sbz if test ${count} -gt 0; then 1106231858Sbz echo "ok ${i} ${_n}result_${i} #" \ 1107231858Sbz "FIB ${i} ${count} (tested)" 1108231858Sbz else 1109231858Sbz echo "not ok ${i} ${_n}result_${i} #" \ 1110231858Sbz "FIB ${i} ${count} (tested)" 1111231858Sbz fi 1112231858Sbz ;; 1113231858Sbz *) if test ${count} -eq 0; then 1114231858Sbz echo "ok ${i} ${_n}result_${i} #" \ 1115231858Sbz "FIB ${i} ${count}" 1116231858Sbz else 1117231858Sbz echo "not ok ${i} ${_n}result_${i} #" \ 1118231858Sbz "FIB ${i} ${count}" 1119231858Sbz fi 1120231858Sbz ;; 1121231858Sbz esac 1122231858Sbz fi 1123231858Sbz i=$((i + 1)) 1124231858Sbz done <<EOI 1125231858Sbz`echo "${_r}" | tr ',' '\n'` 1126231858SbzEOI 1127231858Sbz 1128231858Sbz} 1129231858Sbz 1130231858Sbztestrx_tcp_udp() 1131231858Sbz{ 1132231858Sbz local _n _o _f testno i _fibtxt _instances _res _port _transfer _p 1133231858Sbz _n="$1" 1134231858Sbz _o="$2" 1135231858Sbz _f="$3" 1136231858Sbz _instances=$4 1137231858Sbz _transfer=$5 1138231858Sbz 1139231858Sbz # Unused so far. 1140231858Sbz : ${_instances:=1} 1141231858Sbz 1142231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 1143231858Sbz testno=1 1144231858Sbz i=0 1145231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1146231858Sbz print_debug "Testing ${_f} ${i}" 1147231858Sbz 1148231858Sbz # We are expecting the FIB number (only) to be returned. 1149231858Sbz eval _rc="\${rc_${i}_l}" 1150231858Sbz _fibtxt="${_n}_${i}_l ${_f} ${i} ${PEERLINKLOCAL}" 1151231858Sbz if test ${_instances} -gt 1; then 1152231858Sbz _res="FIB ${i}" 1153231858Sbz _port=$((CTRLPORT + 1000 + i)) 1154231858Sbz else 1155231858Sbz _res="${_fibtxt}" 1156231858Sbz _port=${CTRLPORT} 1157231858Sbz fi 1158231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_res}" ${PEERLINKLOCAL} \ 1159231858Sbz ${_port} "-6 ${_o} -w1" 1160231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" "${_reply}" 1161231858Sbz testno=$((testno + 1)) 1162231858Sbz 1163231858Sbz # If doing multiple transfer networks, replace PEERADDR. 1164231858Sbz _p="${PEERADDR}" 1165231858Sbz case ${_transfer} in 1166231858Sbz 1) PEERADDR=2001:2:${i}::2 ;; 1167231858Sbz esac 1168231858Sbz 1169231858Sbz eval _rc="\${rc_${i}_a}" 1170231858Sbz _fibtxt="${_n}_${i}_a ${_f} ${i} ${PEERADDR}" 1171231858Sbz if test ${_instances} -gt 1; then 1172231858Sbz _res="FIB ${i}" 1173231858Sbz _port=$((CTRLPORT + 1000 + i)) 1174231858Sbz else 1175231858Sbz _res="${_fibtxt}" 1176231858Sbz _port=${CTRLPORT} 1177231858Sbz fi 1178231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_res}" ${PEERADDR} \ 1179231858Sbz ${_port} "-6 ${_o} -w1" 1180231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" "${_reply}" 1181231858Sbz testno=$((testno + 1)) 1182231858Sbz 1183231858Sbz # Restore PEERADDR. 1184231858Sbz PEERADDR="${_p}" 1185231858Sbz 1186231858Sbz i=$((i + 1)) 1187231858Sbz done 1188231858Sbz} 1189231858Sbz 1190231858Sbz 1191231858Sbztestrx_setup_transfer_networks() 1192231858Sbz{ 1193231858Sbz local i 1194231858Sbz 1195231858Sbz i=0 1196231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1197231858Sbz ifconfig ${IFACE} inet6 2001:2:${i}::1/64 -alias \ 1198231858Sbz > /dev/null 2>&1 || true 1199231858Sbz ifconfig ${IFACE} inet6 2001:2:${i}::1/64 alias 1200231858Sbz i=$((i + 1)) 1201231858Sbz done 1202231858Sbz} 1203231858Sbz 1204231858Sbztestrx_cleanup_transfer_networks() 1205231858Sbz{ 1206231858Sbz local i 1207231858Sbz 1208231858Sbz i=0 1209231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1210231858Sbz ifconfig ${IFACE} inet6 2001:2:${i}::1/64 -alias \ 1211231858Sbz > /dev/null 2>&1 1212231858Sbz i=$((i + 1)) 1213231858Sbz done 1214231858Sbz} 1215231858Sbz 1216231858Sbz 1217231858Sbztestrx_run_test() 1218231858Sbz{ 1219231858Sbz local _n _t _fib _o _txt _msg i _reply _instances _destructive _transfer 1220231858Sbz _n="$1" 1221231858Sbz _t="$2" 1222231858Sbz _fib=$3 1223231858Sbz _o="$4" 1224231858Sbz _instances=$5 1225231858Sbz _detsructive=$6 1226231858Sbz _transfer=$7 1227231858Sbz 1228231858Sbz # Netcat options (for UDP basically). 1229231858Sbz case "${_o}" in 1230231858Sbz -i) _opts="" ;; # Use TCP for START/DONE. 1231231858Sbz *) _opts="${_o}" ;; 1232231858Sbz esac 1233231858Sbz 1234231858Sbz # Combined test case base name. 1235231858Sbz case ${USE_SOSETFIB} in 1236231858Sbz 0) _f="setfib" ;; 1237231858Sbz 1) _f="so_setfib" ;; 1238231858Sbz *) die "Unexpected value for SO_SETFIB: ${SO_SETFIB}" ;; 1239231858Sbz esac 1240231858Sbz _txt="${_n}_${_f}_${_t}_${_fib}_${_instances}_${_detsructive}_${_transfer}" 1241231858Sbz 1242231858Sbz print_debug "Starting test '${_txt}' (for ${_instances} instances)." 1243231858Sbz 1244231858Sbz case ${_transfer} in 1245231858Sbz 1) testrx_setup_transfer_networks ;; 1246231858Sbz esac 1247231858Sbz 1248231858Sbz # Let the other side a chance to get ready as well. 1249231858Sbz sleep 1 1250231858Sbz 1251231858Sbz set +e 1252231858Sbz # Let peer know that we are about to start. 1253231858Sbz _msg="START ${_txt}" 1254231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 1255231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 1256231858Sbz case $? in 1257231858Sbz 0) ;; 1258231858Sbz *) die "Got invalid reply from peer." \ 1259231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 1260231858Sbz esac 1261231858Sbz 1262231858Sbz # Let the other side a chance to get ready as well. 1263231858Sbz sleep 1 1264231858Sbz 1265231858Sbz # Send probe. 1266231858Sbz case "${_o}" in 1267231858Sbz -i) testtx_icmp6 "${_txt}_" ${_transfer} ;; 1268231858Sbz *) testrx_tcp_udp "${_txt}" "${_o}" "${_fib}" ${_instances} \ 1269231858Sbz ${_transfer} ;; 1270231858Sbz esac 1271231858Sbz 1272231858Sbz # Let peer know that we are done with this test to move to next. 1273231858Sbz # This must immediately succeed. 1274231858Sbz _msg="DONE ${_txt}" 1275231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 1276231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 1277231858Sbz case $? in 1278231858Sbz 0) ;; 1279231858Sbz *) die "Got invalid reply from peer." \ 1280231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 1281231858Sbz esac 1282231858Sbz 1283231858Sbz # Collect and validate the results. Always use TCP. 1284231858Sbz sleep 1 1285231858Sbz set +e 1286231858Sbz nc_send_recv ${_fib} 1 "RESULT REQUEST" "" ${PEERADDR} \ 1287231858Sbz ${CTRLPORT} "-6 -w1" 1288231858Sbz case "${_reply}" in 1289231858Sbz RESULT\ *) testrx_results ${_fib} "${_txt}_" "${_reply}" ${_instances} \ 1290231858Sbz ${_transfer} "${_o}" 1291231858Sbz ;; 1292231858Sbz *) die "Got invalid reply from peer." \ 1293231858Sbz "Expected 'RESULT ...', got '${_reply}'" ;; 1294231858Sbz esac 1295231858Sbz set -e 1296231858Sbz 1297231858Sbz case ${_transfer} in 1298231858Sbz 1) testrx_cleanup_transfer_networks ;; 1299231858Sbz esac 1300231858Sbz 1301231858Sbz print_debug "Successfully received status update '${_reply}'." 1302231858Sbz} 1303231858Sbz 1304231858Sbztestrx_main_setup_rc() 1305231858Sbz{ 1306231858Sbz local _n _t _fib _o _instances _destructive _transfer i 1307231858Sbz _n="$1" 1308231858Sbz _t="$2" 1309231858Sbz _fib=$3 1310231858Sbz _o="$4" 1311231858Sbz _instances=$5 1312231858Sbz _destructive=$6 1313231858Sbz _transfer=$7 1314231858Sbz 1315231858Sbz # Setup expected return values. 1316231858Sbz if test ${_destructive} -eq 0; then 1317231858Sbz i=0 1318231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1319231858Sbz eval rc_${i}_l=0 1320231858Sbz eval rc_${i}_a=0 1321231858Sbz i=$((i + 1)) 1322231858Sbz done 1323231858Sbz else 1324231858Sbz i=0 1325231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1326231858Sbz eval rc_${i}_l=0 1327231858Sbz case ${i} in 1328231858Sbz ${_fib}) eval rc_${i}_a=0 ;; 1329231858Sbz *) # ICMP6 cannot be distinguished and will 1330231858Sbz # always work in single transfer network. 1331231858Sbz case "${_o}" in 1332231858Sbz -i) case ${_transfer} in 1333231858Sbz 0) eval rc_${i}_a=0 ;; 1334231858Sbz 1) eval rc_${i}_a=1 ;; 1335231858Sbz esac 1336231858Sbz ;; 1337231858Sbz *) if test ${_instances} -eq 1 -a \ 1338231858Sbz ${_transfer} -eq 0; then 1339231858Sbz eval rc_${i}_a=0 1340231858Sbz else 1341231858Sbz eval rc_${i}_a=1 1342231858Sbz fi 1343231858Sbz ;; 1344231858Sbz esac 1345231858Sbz ;; 1346231858Sbz esac 1347231858Sbz i=$((i + 1)) 1348231858Sbz done 1349231858Sbz fi 1350231858Sbz 1351231858Sbz print_debug "${_n}_${t}_${_fib} ${_instances} ${_destructive}" \ 1352231858Sbz "${_transfer}" 1353231858Sbz testrx_run_test "${_n}" "${t}" ${_fib} "${_o}" ${_instances} \ 1354231858Sbz ${_destructive} ${_transfer} 1355231858Sbz} 1356231858Sbz 1357231858Sbztestrx_main() 1358231858Sbz{ 1359231858Sbz local _n _o s t _fib _instances _destructive _transfer 1360231858Sbz _n="$1" 1361231858Sbz _o="$2" 1362231858Sbz _instances=$3 1363231858Sbz 1364231858Sbz : ${_instances:=1} 1365231858Sbz 1366231858Sbz print_debug "${_n}" 1367231858Sbz for _transfer in 1 0; do 1368231858Sbz for _destructive in 0 1; do 1369231858Sbz for t in ipfw ifconfig; do 1370231858Sbz 1371231858Sbz print_debug "${_n}_${t}" 1372231858Sbz _fib=0 1373231858Sbz while test ${_fib} -lt ${RT_NUMFIBS}; do 1374231858Sbz 1375231858Sbz testrx_main_setup_rc "${_n}" "${t}" \ 1376231858Sbz ${_fib} "${_o}" ${_instances} \ 1377231858Sbz ${_destructive} ${_transfer} 1378231858Sbz 1379231858Sbz _fib=$((_fib + 1)) 1380231858Sbz done 1381231858Sbz done 1382231858Sbz done 1383231858Sbz done 1384231858Sbz} 1385231858Sbz 1386231858Sbz################################################################################ 1387231858Sbz# 1388231858Sbz# 1389231858Sbz# 1390231858Sbz 1391231858Sbztestrx_icmp6_same_addr_one_fib_a_time() 1392231858Sbz{ 1393231858Sbz 1394231858Sbz testrx_main \ 1395231858Sbz "testrx_icmp6_same_addr_one_fib_a_time" "-i" 1396231858Sbz} 1397231858Sbz 1398231858Sbztestrx_tcp6_same_addr_one_fib_a_time() 1399231858Sbz{ 1400231858Sbz 1401231858Sbz testrx_main \ 1402231858Sbz "testrx_tcp6_same_addr_one_fib_a_time" "" 1403231858Sbz} 1404231858Sbz 1405231858Sbz 1406231858Sbztestrx_udp6_same_addr_one_fib_a_time() 1407231858Sbz{ 1408231858Sbz 1409231858Sbz testrx_main \ 1410231858Sbz "testrx_udp6_same_addr_one_fib_a_time" "-u" 1411231858Sbz} 1412231858Sbz 1413231858Sbz 1414231858Sbz################################################################################ 1415231858Sbz 1416231858Sbztestrx_tcp6_same_addr_all_fibs_a_time() 1417231858Sbz{ 1418231858Sbz 1419231858Sbz testrx_main \ 1420231858Sbz "testrx_tcp6_same_addr_all_fibs_a_time" "" ${RT_NUMFIBS} 1421231858Sbz} 1422231858Sbz 1423231858Sbztestrx_udp6_same_addr_all_fibs_a_time() 1424231858Sbz{ 1425231858Sbz 1426231858Sbz testrx_main \ 1427231858Sbz "testrx_udp6_same_addr_all_fibs_a_time" "-u" ${RT_NUMFIBS} 1428231858Sbz} 1429231858Sbz 1430231858Sbz 1431231858Sbz################################################################################ 1432231858Sbz# 1433231858Sbz# Prereqs. 1434231858Sbz# 1435231858Sbzkldload ipfw > /dev/null 2>&1 || kldstat -v | grep -q ipfw 1436231858Sbz 1437231858Sbz# Reduce the time we wait in case of no reply to 2s. 1438231858Sbzsysctl net.inet.tcp.keepinit=2000 > /dev/null 2>&1 1439231858Sbz 1440231858Sbz################################################################################ 1441231858Sbz# 1442231858Sbz# Run tests. 1443231858Sbz# 1444231858Sbz 1445231858Sbz# 64 cases at 16 FIBs. 1446231858Sbzcheck_local_addr 1447231858Sbzcheck_local_tun 1448231858Sbz 1449231858Sbzsend_greeting 1450231858Sbz 1451231858Sbz# Initiator testing. 1452231858Sbzfor uso in 0 1; do 1453231858Sbz 1454231858Sbz USE_SOSETFIB=${uso} 1455231858Sbz 1456231858Sbz # Only run ICMP6 tests for the first loop. 1457231858Sbz # 160 cases at 16 FIBs. 1458231858Sbz test ${uso} -ne 0 || testtx_icmp6_connected && sleep 1 1459231858Sbz testtx_tcp6_connected && sleep 1 1460231858Sbz testtx_udp6_connected && sleep 1 1461231858Sbz 1462231858Sbz # 2560 cases at 16 FIBs. 1463231858Sbz test ${uso} -ne 0 || testtx_icmp6_connected_blackhole && sleep 1 1464231858Sbz testtx_tcp6_connected_blackhole && sleep 1 1465231858Sbz testtx_udp6_connected_blackhole && sleep 1 1466231858Sbz 1467231858Sbz # 2560 cases at 16 FIBs. 1468231858Sbz test ${uso} -ne 0 || testtx_icmp6_connected_transfernets && sleep 1 1469231858Sbz testtx_tcp6_connected_transfernets && sleep 1 1470231858Sbz testtx_udp6_connected_transfernets && sleep 1 1471231858Sbz 1472231858Sbz # 2560 cases at 16 FIBs. 1473231858Sbz test ${uso} -ne 0 || \ 1474231858Sbz testtx_icmp6_connected_ifconfig_transfernets && sleep 1 1475231858Sbz testtx_tcp6_connected_ifconfig_transfernets && sleep 1 1476231858Sbz testtx_udp6_connected_ifconfig_transfernets && sleep 1 1477231858Sbz 1478231858Sbz # 160 cases at 16 FIBs. 1479231858Sbz test ${uso} -ne 0 || testtx_icmp6_gateway && sleep 1 1480231858Sbz testtx_tcp6_gateway && sleep 1 1481231858Sbz testtx_udp6_gateway && sleep 1 1482231858Sbz 1483231858Sbz # 160 cases at 16 FIBs. 1484231858Sbz test ${uso} -ne 0 || testtx_icmp6_transfernets_gateways && sleep 1 1485231858Sbz testtx_tcp6_transfernets_gateways && sleep 1 1486231858Sbz testtx_udp6_transfernets_gateways && sleep 1 1487231858Sbz 1488231858Sbz # 2560 cases at 16 FIBs. 1489231858Sbz test ${uso} -ne 0 || testtx_icmp6_transfernets_gateway && sleep 1 1490231858Sbz testtx_tcp6_transfernets_gateway && sleep 1 1491231858Sbz testtx_udp6_transfernets_gateway && sleep 1 1492231858Sbzdone 1493231858Sbz 1494231858Sbz# Receiver testering. 1495231858Sbzfor uso in 0 1; do 1496231858Sbz 1497231858Sbz USE_SOSETFIB=${uso} 1498231858Sbz 1499231858Sbz # Only expect ICMP6 tests for the first loop. 1500231858Sbz # 6144 cases at 16 FIBs. 1501231858Sbz test ${uso} -ne 0 || testrx_icmp6_same_addr_one_fib_a_time && sleep 1 1502231858Sbz # 12288 cases at 16 FIBs. 1503231858Sbz testrx_tcp6_same_addr_one_fib_a_time && sleep 1 1504231858Sbz # 12288 cases at 16 FIBs. 1505231858Sbz testrx_udp6_same_addr_one_fib_a_time && sleep 1 1506231858Sbz 1507231858Sbz # 12288 cases at 16 FIBs. 1508231858Sbz testrx_tcp6_same_addr_all_fibs_a_time && sleep 1 1509231858Sbz # 12288 cases at 16 FIBs. 1510231858Sbz testrx_udp6_same_addr_all_fibs_a_time && sleep 1 1511231858Sbz 1512231858Sbzdone 1513231858Sbz 1514231858Sbzcleanup 1515231858Sbz 1516231858Sbz# end 1517