initiator.sh revision 232114
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 232114 2012-02-24 14:13:06Z 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 222232114Sbz ipfw add 65000 permit ip from any to any > /dev/null 2>&1 223231858Sbz ipfw add 5 permit ipv6-icmp from any to any icmp6types 135,136 fib 0 \ 224231858Sbz via ${IFACE} out > /dev/null 2>&1 225231858Sbz 226231858Sbz set +e 227231858Sbz i=0 228231858Sbz rc=-1 229231858Sbz while test ${i} -lt ${WAITS} -a ${rc} -ne 0; do 230231858Sbz print_debug "Sending greeting #${i} to peer" 231231858Sbz _greeting=`echo "SETUP ${RT_NUMFIBS} ${_l}" | \ 232231858Sbz nc -6 -w 1 ${PEERADDR} ${CTRLPORT}` 233231858Sbz rc=$? 234231858Sbz i=$((i + 1)) 235231858Sbz # Might sleep longer in total but better than to DoS 236231858Sbz # and not get anywhere. 237231858Sbz sleep 1 238231858Sbz done 239231858Sbz set -e 240231858Sbz 241231858Sbz read _keyword _fibs _linklocal <<EOI 242231858Sbz${_greeting} 243231858SbzEOI 244231858Sbz print_debug "_keyword=${_keyword}" 245231858Sbz print_debug "_fibs=${_fibs}" 246231858Sbz print_debug "_linklocal=${_linklocal}" 247231858Sbz case ${_keyword} in 248231858Sbz SETUP) ;; 249231858Sbz *) die "Got invalid keyword in greeting: ${_greeting}" 250231858Sbz ;; 251231858Sbz esac 252231858Sbz if test ${_fibs} -ne ${RT_NUMFIBS}; then 253231858Sbz die "Number of FIBs not matching ours (${RT_NUMFIBS}) in" \ 254231858Sbz "greeting: ${_greeting}" 255231858Sbz fi 256231858Sbz PEERLINKLOCAL=${_linklocal} 257231858Sbz 258231858Sbz # Swap the zoneid to the local interface scope. 259232114Sbz PEERLINKLOCAL=${PEERLINKLOCAL%%\%*}"%${IFACE}" 260231858Sbz 261231858Sbz print_debug "Successfully exchanged greeting. Peer at ${PEERLINKLOCAL}" 262231858Sbz} 263231858Sbz 264231858Sbzcleanup() 265231858Sbz{ 266231858Sbz 267231858Sbz # Cleanup ipfw. 268231858Sbz ipfw delete 5 > /dev/null 2>&1 269231858Sbz 270231858Sbz print_debug "Removing address from interface ${IFACE}" 271231858Sbz ifconfig ${IFACE} inet6 ${OURADDR}/64 -alias 272231858Sbz} 273231858Sbz 274231858Sbztesttx_icmp6() 275231858Sbz{ 276231858Sbz local _n _transfer i testno _txt _fibtxt _rc _ec _p 277231858Sbz _n="$1" 278231858Sbz _transfer=$2 279231858Sbz 280231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 281231858Sbz testno=1 282231858Sbz set +e 283231858Sbz i=0 284231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 285231858Sbz _txt="${_n}${i}" 286231858Sbz print_debug "Testing ${_txt}" 287231858Sbz _fibtxt=`echo "${_txt}" | hd -v | cut -b11-60 | tr -d ' \r\n'` 288231858Sbz 289231858Sbz eval _rc="\${rc_${i}_l}" 290231858Sbz setfib -F${i} ping6 -n -c1 -p ${_fibtxt} \ 291231858Sbz ${PEERLINKLOCAL} > /dev/null 2>&1 292231858Sbz _ec=$? 293231858Sbz # We need to normalize the exit code of ping6. 294231858Sbz case ${_ec} in 295231858Sbz 0) ;; 296231858Sbz *) _ec=1 ;; 297231858Sbz esac 298231858Sbz check_rc ${_ec} ${_rc} ${testno} "${_txt}_l" \ 299231858Sbz "FIB ${i} ${PEERLINKLOCAL}" 300231858Sbz testno=$((testno + 1)) 301231858Sbz 302231858Sbz # If doing multiple transfer networks, replace PEERADDR. 303231858Sbz _p="${PEERADDR}" 304231858Sbz case ${_transfer} in 305231858Sbz 1) PEERADDR=2001:2:${i}::2 ;; 306231858Sbz esac 307231858Sbz 308231858Sbz eval _rc="\${rc_${i}_a}" 309231858Sbz setfib -F${i} ping6 -n -c1 -p ${_fibtxt} ${PEERADDR} \ 310231858Sbz > /dev/null 2>&1 311231858Sbz _ec=$? 312231858Sbz # We need to normalize the exit code of ping6. 313231858Sbz case ${_ec} in 314231858Sbz 0) ;; 315231858Sbz *) _ec=1 ;; 316231858Sbz esac 317231858Sbz check_rc ${_ec} ${_rc} ${testno} "${_txt}_a" \ 318231858Sbz "FIB ${i} ${PEERADDR}" 319231858Sbz testno=$((testno + 1)) 320231858Sbz 321231858Sbz # Restore PEERADDR. 322231858Sbz PEERADDR="${_p}" 323231858Sbz 324231858Sbz i=$((i + 1)) 325231858Sbz done 326231858Sbz set -e 327231858Sbz} 328231858Sbz 329231858Sbznc_send_recv() 330231858Sbz{ 331231858Sbz local _fib _loops _msg _expreply _addr _port _opts i 332231858Sbz _fib=$1 333231858Sbz _loops=$2 334231858Sbz _msg="$3" 335231858Sbz _expreply="$4" 336231858Sbz _addr=$5 337231858Sbz _port=$6 338231858Sbz _opts="$7" 339231858Sbz 340231858Sbz i=0 341231858Sbz while test ${i} -lt ${_loops}; do 342231858Sbz i=$((i + 1)) 343231858Sbz case "${USE_SOSETFIB}" in 344231858Sbz 1) 345231858Sbz _reply=`echo "${_msg}" | \ 346231858Sbz nc -V ${_fib} ${_opts} ${_addr} ${_port}` 347231858Sbz ;; 348231858Sbz *) 349231858Sbz _reply=`echo "${_msg}" | \ 350231858Sbz setfib -F${_fib} nc ${_opts} ${_addr} ${_port}` 351231858Sbz ;; 352231858Sbz esac 353231858Sbz if test "${_reply}" != "${_expreply}"; then 354231858Sbz if test ${i} -lt ${_loops}; then 355231858Sbz sleep 1 356231858Sbz else 357231858Sbz # Must let caller decide how to handle the error. 358231858Sbz # die "Got invalid reply from peer." \ 359231858Sbz # "Expected '${_expreply}', got '${_reply}'" 360231858Sbz return 1 361231858Sbz fi 362231858Sbz else 363231858Sbz break 364231858Sbz fi 365231858Sbz done 366231858Sbz return 0 367231858Sbz} 368231858Sbz 369231858Sbztesttx_tcp_udp() 370231858Sbz{ 371231858Sbz local _n _o _f testno i _fibtxt 372231858Sbz _n="$1" 373231858Sbz _o="$2" 374231858Sbz _f="$3" 375231858Sbz 376231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 377231858Sbz testno=1 378231858Sbz i=0 379231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 380231858Sbz print_debug "Testing ${_f} ${i}" 381231858Sbz 382231858Sbz eval _rc="\${rc_${i}_l}" 383231858Sbz _fibtxt="${_n}_${i}_l ${_f} ${i} ${PEERLINKLOCAL}" 384231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_fibtxt}" ${PEERLINKLOCAL} \ 385231858Sbz ${CTRLPORT} "-6 ${_o} -w1" 386231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" 387231858Sbz testno=$((testno + 1)) 388231858Sbz 389231858Sbz eval _rc="\${rc_${i}_a}" 390231858Sbz _fibtxt="${_n}_${i}_a ${_f} ${i} ${PEERADDR}" 391231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_fibtxt}" ${PEERADDR} \ 392231858Sbz ${CTRLPORT} "-6 ${_o} -w1" 393231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" 394231858Sbz testno=$((testno + 1)) 395231858Sbz 396231858Sbz i=$((i + 1)) 397231858Sbz done 398231858Sbz} 399231858Sbz 400231858Sbz# setfib TCP|UDP/IPv6 test on link-local and global address of peer from all FIBs. 401231858Sbztesttx_ulp6_connected() 402231858Sbz{ 403231858Sbz local _fibtxt _reply _n _o _rc _fib _f _opts 404231858Sbz _n=$1 405231858Sbz _o="$2" 406231858Sbz _fib=$3 407231858Sbz 408231858Sbz case "${USE_SOSETFIB}" in 409231858Sbz 1) _f="SO_SETFIB" ;; 410231858Sbz *) _f="SETFIB" ;; 411231858Sbz esac 412231858Sbz 413231858Sbz if test "${_o}" == "-i" -a "${_f}" == "SO_SETFIB"; then 414231858Sbz print_debug "Skipping icmp6 tests for SO_SETFIB." 415231858Sbz return 0 416231858Sbz fi 417231858Sbz 418231858Sbz # Clear the neighbor table to get deterministic runs. 419231858Sbz ndp -cn > /dev/null 2>&1 420231858Sbz 421231858Sbz case "${_o}" in 422231858Sbz -i) _opts="" ;; # Use TCP for START/DONE. 423231858Sbz *) _opts="${_o}" ;; 424231858Sbz esac 425231858Sbz 426231858Sbz set +e 427231858Sbz # Let peer know that we are about to start. 428231858Sbz _msg="START ${_n}" 429231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 430231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 431231858Sbz case $? in 432231858Sbz 0) ;; 433231858Sbz *) die "Got invalid reply from peer." \ 434231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 435231858Sbz esac 436231858Sbz 437231858Sbz case "${_o}" in 438231858Sbz -i) testtx_icmp6 "${_n}" ;; 439231858Sbz *) testtx_tcp_udp "${_n}" "${_o}" "${_f}" ;; 440231858Sbz esac 441231858Sbz 442231858Sbz # Let peer know that we are done with this test to move to next. 443231858Sbz # This must immediately succeed. 444231858Sbz _msg="DONE ${_n}" 445231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 446231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 447231858Sbz case $? in 448231858Sbz 0) ;; 449231858Sbz *) die "Got invalid reply from peer." \ 450231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 451231858Sbz esac 452231858Sbz set -e 453231858Sbz 454231858Sbz print_debug "Successfully received status update '${_reply}'." 455231858Sbz} 456231858Sbz 457231858Sbz################################################################################ 458231858Sbz# 459231858Sbz# ping6|TCP/UDP connect link-local and global address of peer from all FIBs. 460231858Sbz# Default reachability test. 461231858Sbz# 462231858Sbztesttx_icmp6_connected() 463231858Sbz{ 464231858Sbz local i 465231858Sbz 466231858Sbz # Setup expected return values. 467231858Sbz i=0 468231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 469231858Sbz eval rc_${i}_l=0 470231858Sbz eval rc_${i}_a=0 471231858Sbz i=$((i + 1)) 472231858Sbz done 473231858Sbz 474231858Sbz testtx_ulp6_connected "testtx_icmp6_connected" "-i" 0 475231858Sbz} 476231858Sbz 477231858Sbztesttx_tcp6_connected() 478231858Sbz{ 479231858Sbz local i 480231858Sbz 481231858Sbz # Setup expected return values. 482231858Sbz i=0 483231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 484231858Sbz eval rc_${i}_l=0 485231858Sbz eval rc_${i}_a=0 486231858Sbz i=$((i + 1)) 487231858Sbz done 488231858Sbz 489231858Sbz testtx_ulp6_connected testtx_tcp6_connected "" 0 490231858Sbz} 491231858Sbz 492231858Sbztesttx_udp6_connected() 493231858Sbz{ 494231858Sbz local i 495231858Sbz 496231858Sbz # Setup expected return values. 497231858Sbz i=0 498231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 499231858Sbz eval rc_${i}_l=0 500231858Sbz eval rc_${i}_a=0 501231858Sbz i=$((i + 1)) 502231858Sbz done 503231858Sbz 504231858Sbz testtx_ulp6_connected testtx_udp6_connected "-u" 0 505231858Sbz} 506231858Sbz 507231858Sbz################################################################################ 508231858Sbz# 509231858Sbz# Use ipfw to return unreach messages for all but one FIB. Rotate over all. 510231858Sbz# Making sure error messages are properly returned. 511231858Sbz# 512231858Sbztesttx_ulp6_connected_blackhole() 513231858Sbz{ 514232114Sbz local fib i _n _o 515231858Sbz _n="$1" 516231858Sbz _o="$2" 517231858Sbz 518232114Sbz fib=0 519232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 520231858Sbz 521232114Sbz print_debug "${_n} ${fib}" 522231858Sbz 523231858Sbz # Setup expected return values. 524231858Sbz i=0 525231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 526231858Sbz ipfw delete $((100 + i)) > /dev/null 2>&1 || true 527231858Sbz case ${i} in 528232114Sbz ${fib}) 529231858Sbz eval rc_${i}_l=0 530231858Sbz eval rc_${i}_a=0 531231858Sbz ;; 532231858Sbz *) eval rc_${i}_l=1 533231858Sbz eval rc_${i}_a=1 534231858Sbz ipfw add $((100 + i)) unreach6 admin-prohib \ 535231858Sbz ip6 from any to any fib ${i} via ${IFACE} \ 536231858Sbz out > /dev/null 2>&1 537231858Sbz ;; 538231858Sbz esac 539231858Sbz i=$((i + 1)) 540231858Sbz done 541231858Sbz 542232114Sbz testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib} 543231858Sbz case ${DEBUG} in 544231858Sbz ''|0) ;; 545231858Sbz *) ipfw show ;; 546231858Sbz esac 547232114Sbz fib=$((fib + 1)) 548231858Sbz done 549232114Sbz fib=0 550232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 551232114Sbz ipfw delete $((100 + fib)) > /dev/null 2>&1 || true 552232114Sbz fib=$((fib + 1)) 553231858Sbz done 554231858Sbz} 555231858Sbz 556231858Sbztesttx_icmp6_connected_blackhole() 557231858Sbz{ 558231858Sbz 559231858Sbz testtx_ulp6_connected_blackhole \ 560231858Sbz "testtx_icmp6_connected_blackhole" "-i" 561231858Sbz} 562231858Sbz 563231858Sbztesttx_tcp6_connected_blackhole() 564231858Sbz{ 565231858Sbz 566231858Sbz testtx_ulp6_connected_blackhole \ 567231858Sbz "testtx_tcp6_connected_blackhole" "" 568231858Sbz} 569231858Sbz 570231858Sbztesttx_udp6_connected_blackhole() 571231858Sbz{ 572231858Sbz 573231858Sbz testtx_ulp6_connected_blackhole \ 574231858Sbz "testtx_udp6_connected_blackhole" "-u" 575231858Sbz} 576231858Sbz 577231858Sbz################################################################################ 578231858Sbz# 579231858Sbz# Setup a different transfer net on each FIB. Delete all but one connected 580231858Sbz# route in all FIBs (e.g. FIB 0 uses prefix 0, FIB 1 uses prefix 1 , ...). 581231858Sbz# 582231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 583231858Sbz# know about the prefix and thus cannot do proper source address lookups for 584231858Sbz# replying otherwise. Use ipfw. 585231858Sbz# 586231858Sbztesttx_ulp6_connected_transfernets() 587231858Sbz{ 588232114Sbz local fib i _n _o _p 589231858Sbz _n="$1" 590231858Sbz _o="$2" 591231858Sbz 592231858Sbz # Setup transfer networks and firewall. 593231858Sbz ipfw delete 10 > /dev/null 2>&1 || true 594232114Sbz fib=0 595232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 596232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \ 597231858Sbz > /dev/null 2>&1 || true 598232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias 599232114Sbz ipfw add 10 setfib ${fib} ipv6-icmp from 2001:2:${fib}::/64 \ 600231858Sbz to any ip6 icmp6types 135,136 via ${IFACE} in \ 601231858Sbz > /dev/null 2>&1 602231858Sbz # Remove connected routes from all but matching FIB. 603231858Sbz i=0 604231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 605231858Sbz case ${i} in 606232114Sbz ${fib});; 607231858Sbz *) setfib -F${i} route delete -inet6 \ 608232114Sbz -net 2001:2:${fib}:: > /dev/null 2>&1 609231858Sbz ;; 610231858Sbz esac 611231858Sbz i=$((i + 1)) 612231858Sbz done 613232114Sbz fib=$((fib + 1)) 614231858Sbz done 615231858Sbz 616231858Sbz # Save PEERADDR 617231858Sbz _p=${PEERADDR} 618231858Sbz 619231858Sbz # Run tests. 620232114Sbz fib=0 621232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 622232114Sbz PEERADDR=2001:2:${fib}::2 623231858Sbz 624232114Sbz print_debug "${_n} ${fib}" 625231858Sbz 626231858Sbz # Setup expected return values. 627231858Sbz i=0 628231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 629231858Sbz eval rc_${i}_l=0 630231858Sbz case ${i} in 631232114Sbz ${fib}) 632231858Sbz eval rc_${i}_a=0 633231858Sbz ;; 634231858Sbz *) eval rc_${i}_a=1 635231858Sbz ;; 636231858Sbz esac 637231858Sbz i=$((i + 1)) 638231858Sbz done 639231858Sbz 640232114Sbz testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib} 641232114Sbz fib=$((fib + 1)) 642231858Sbz done 643231858Sbz 644231858Sbz # Restore PEERADDR 645231858Sbz PEERADDR=${_p} 646231858Sbz 647231858Sbz # Cleanup transfer networks and firewall. 648232114Sbz fib=0 649232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 650232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias 651232114Sbz fib=$((fib + 1)) 652231858Sbz done 653231858Sbz ipfw delete 10 > /dev/null 2>&1 654231858Sbz} 655231858Sbz 656231858Sbztesttx_icmp6_connected_transfernets() 657231858Sbz{ 658231858Sbz 659231858Sbz testtx_ulp6_connected_transfernets \ 660231858Sbz "testtx_icmp6_connected_transfernets" "-i" 661231858Sbz} 662231858Sbz 663231858Sbztesttx_tcp6_connected_transfernets() 664231858Sbz{ 665231858Sbz 666231858Sbz testtx_ulp6_connected_transfernets \ 667231858Sbz "testtx_tcp6_connected_transfernets" "" 668231858Sbz} 669231858Sbz 670231858Sbztesttx_udp6_connected_transfernets() 671231858Sbz{ 672231858Sbz 673231858Sbz testtx_ulp6_connected_transfernets \ 674231858Sbz "testtx_udp6_connected_transfernets" "-u" 675231858Sbz} 676231858Sbz 677231858Sbz################################################################################ 678231858Sbz# 679231858Sbz# Setup a different transfernet on each FIB. Delete all but one connected 680231858Sbz# route in all FIBs (e.g. FIB 0 uses prefix 0, FIB 1 uses prefix 1 , ...). 681231858Sbz# 682231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 683231858Sbz# know about the prefix and thus cannot do proper source address lookups for 684231858Sbz# replying otherwise. Use ifconfig IFACE fib. 685231858Sbz# 686231858Sbztesttx_ulp6_connected_ifconfig_transfernets() 687231858Sbz{ 688232114Sbz local fib i _n _o _p 689231858Sbz _n="$1" 690231858Sbz _o="$2" 691231858Sbz 692231858Sbz # Setup transfer networks. 693232114Sbz fib=0 694232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 695232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \ 696231858Sbz > /dev/null 2>&1 || true 697232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias 698231858Sbz # Remove connected routes from all but matching FIB. 699231858Sbz i=0 700231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 701231858Sbz case ${i} in 702232114Sbz ${fib});; 703231858Sbz *) setfib -F${i} route delete -inet6 \ 704232114Sbz -net 2001:2:${fib}:: > /dev/null 2>&1 705231858Sbz ;; 706231858Sbz esac 707231858Sbz i=$((i + 1)) 708231858Sbz done 709232114Sbz fib=$((fib + 1)) 710231858Sbz done 711231858Sbz 712231858Sbz # Save PEERADDR 713231858Sbz _p=${PEERADDR} 714231858Sbz 715231858Sbz # Run tests. 716232114Sbz fib=0 717232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 718232114Sbz PEERADDR=2001:2:${fib}::2 719231858Sbz 720232114Sbz print_debug "${_n} ${fib}" 721231858Sbz 722231858Sbz # Setup expected return values. 723231858Sbz i=0 724231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 725231858Sbz eval rc_${i}_l=0 726231858Sbz case ${i} in 727232114Sbz ${fib}) 728231858Sbz eval rc_${i}_a=0 729231858Sbz ;; 730231858Sbz *) eval rc_${i}_a=1 731231858Sbz ;; 732231858Sbz esac 733231858Sbz i=$((i + 1)) 734231858Sbz done 735231858Sbz 736232114Sbz ifconfig ${IFACE} fib ${fib} 737231858Sbz 738232114Sbz testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib} 739232114Sbz fib=$((fib + 1)) 740231858Sbz done 741231858Sbz 742231858Sbz # Restore PEERADDR 743231858Sbz PEERADDR=${_p} 744231858Sbz 745231858Sbz # Cleanup transfer networks. 746232114Sbz fib=0 747232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 748232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias 749232114Sbz fib=$((fib + 1)) 750231858Sbz done 751231858Sbz ifconfig ${IFACE} fib 0 752231858Sbz} 753231858Sbz 754231858Sbztesttx_icmp6_connected_ifconfig_transfernets() 755231858Sbz{ 756231858Sbz 757231858Sbz testtx_ulp6_connected_ifconfig_transfernets \ 758231858Sbz "testtx_icmp6_connected_ifconfig_transfernets" "-i" 759231858Sbz} 760231858Sbz 761231858Sbz 762231858Sbztesttx_tcp6_connected_ifconfig_transfernets() 763231858Sbz{ 764231858Sbz 765231858Sbz testtx_ulp6_connected_ifconfig_transfernets \ 766231858Sbz "testtx_tcp6_connected_ifconfig_transfernets" "" 767231858Sbz} 768231858Sbz 769231858Sbztesttx_udp6_connected_ifconfig_transfernets() 770231858Sbz{ 771231858Sbz 772231858Sbz testtx_ulp6_connected_ifconfig_transfernets \ 773231858Sbz "testtx_udp6_connected_ifconfig_transfernets" "-u" 774231858Sbz} 775231858Sbz 776231858Sbz################################################################################ 777231858Sbz# 778231858Sbz# Make destination reachable through the same default route in each FIB only. 779231858Sbz# Run standard reachability test. 780231858Sbz# 781231858Sbztesttx_ulp6_gateway() 782231858Sbz{ 783232114Sbz local fib i _n _o _p 784231858Sbz _n="$1" 785231858Sbz _o="$2" 786231858Sbz 787231858Sbz # Setup default gateway and expected error codes. 788232114Sbz fib=0 789232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 790232114Sbz setfib -F${fib} route delete -inet6 -net default \ 791231858Sbz > /dev/null 2>&1 || true 792232114Sbz setfib -F${fib} route add -inet6 -net default ${PEERADDR} \ 793231858Sbz > /dev/null 2>&1 794231858Sbz case "${_o}" in 795232114Sbz -i) eval rc_${fib}_l=0 ;; # ICMPv6 will succeed 796232114Sbz *) eval rc_${fib}_l=1 ;; 797231858Sbz esac 798232114Sbz eval rc_${fib}_a=0 799232114Sbz fib=$((fib + 1)) 800231858Sbz done 801231858Sbz 802231858Sbz # Save PEERADDR 803231858Sbz _p=${PEERADDR} 804231858Sbz PEERADDR="2001:2:ff01::2" 805231858Sbz 806231858Sbz # Run tests. 807231858Sbz print_debug "${_n}" 808231858Sbz testtx_ulp6_connected "${_n}" "${_o}" 0 809231858Sbz 810231858Sbz # Restore PEERADDR 811231858Sbz PEERADDR=${_p} 812231858Sbz 813231858Sbz # Cleanup transfer networks. 814232114Sbz fib=0 815232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 816232114Sbz setfib -F${fib} route delete -inet6 -net default \ 817231858Sbz > /dev/null 2>&1 818232114Sbz fib=$((fib + 1)) 819231858Sbz done 820231858Sbz} 821231858Sbz 822231858Sbztesttx_icmp6_gateway() 823231858Sbz{ 824231858Sbz 825231858Sbz testtx_ulp6_gateway "testtx_icmp6_gateway" "-i" 826231858Sbz} 827231858Sbz 828231858Sbztesttx_tcp6_gateway() 829231858Sbz{ 830231858Sbz 831231858Sbz testtx_ulp6_gateway "testtx_tcp6_gateway" "" 832231858Sbz} 833231858Sbz 834231858Sbztesttx_udp6_gateway() 835231858Sbz{ 836231858Sbz 837231858Sbz testtx_ulp6_gateway "testtx_udp6_gateway" "-u" 838231858Sbz} 839231858Sbz 840231858Sbz################################################################################ 841231858Sbz# 842231858Sbz# Make destination reachable through a different default route in each FIB. 843231858Sbz# Generate a dedicated transfer network for that in each FIB. Delete all but 844231858Sbz# one connected route in all FIBs (e.g. FIB 0 uses prefix 0, ...). 845231858Sbz# 846231858Sbz# Have a default route present in each FIB all time. 847231858Sbz# 848231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 849231858Sbz# know about the prefix and thus cannot do proper source address lookups for 850231858Sbz# replying otherwise. Use ipfw. 851231858Sbz# 852231858Sbz# 853231858Sbztesttx_ulp6_transfernets_gateways() 854231858Sbz{ 855232114Sbz local fib i _n _o _p 856231858Sbz _n="$1" 857231858Sbz _o="$2" 858231858Sbz 859231858Sbz # Setup transfer networks, default routes, and firewall. 860232114Sbz fib=0 861231858Sbz ipfw delete 10 > /dev/null 2>&1 || true 862232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 863232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \ 864231858Sbz > /dev/null 2>&1 || true 865232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias \ 866231858Sbz > /dev/null 2>&1 867232114Sbz ipfw add 10 setfib ${fib} ipv6-icmp \ 868232114Sbz from 2001:2:${fib}::/64 to any ip6 icmp6types 135,136 \ 869231858Sbz via ${IFACE} in > /dev/null 2>&1 870231858Sbz # Remove connected routes from all but matching FIB. 871231858Sbz i=0 872231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 873231858Sbz case ${i} in 874232114Sbz ${fib});; 875231858Sbz *) setfib -F${i} route delete -inet6 \ 876232114Sbz -net 2001:2:${fib}:: > /dev/null 2>&1 877231858Sbz ;; 878231858Sbz esac 879231858Sbz i=$((i + 1)) 880231858Sbz done 881231858Sbz # Add default route. 882232114Sbz setfib -F${fib} route delete -inet6 -net default \ 883231858Sbz > /dev/null 2>&1 || true 884232114Sbz setfib -F${fib} route add -inet6 -net default \ 885232114Sbz 2001:2:${fib}::2 > /dev/null 2>&1 886232114Sbz fib=$((fib + 1)) 887231858Sbz done 888231858Sbz 889231858Sbz # Save PEERADDR 890231858Sbz _p=${PEERADDR} 891231858Sbz PEERADDR="2001:2:ff01::2" 892231858Sbz 893231858Sbz # Setup expected return values. 894231858Sbz i=0 895231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 896231858Sbz case "${_o}" in 897231858Sbz -i) eval rc_${i}_l=0 ;; # ICMPv6 will succeed 898231858Sbz *) eval rc_${i}_l=1 ;; 899231858Sbz esac 900231858Sbz eval rc_${i}_a=0 901231858Sbz i=$((i + 1)) 902231858Sbz done 903231858Sbz 904231858Sbz # Run tests. 905231858Sbz print_debug "${_n}" 906231858Sbz testtx_ulp6_connected "${_n}" "${_o}" 0 907231858Sbz 908231858Sbz # Restore PEERADDR 909231858Sbz PEERADDR=${_p} 910231858Sbz 911231858Sbz # Cleanup default routes, transfer networks, and firewall. 912232114Sbz fib=0 913232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 914232114Sbz setfib -F${fib} route delete -inet6 -net default \ 915231858Sbz > /dev/null 2>&1 916232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \ 917231858Sbz > /dev/null 2>&1 918232114Sbz fib=$((fib + 1)) 919231858Sbz done 920231858Sbz ipfw delete 10 > /dev/null 2>&1 921231858Sbz} 922231858Sbz 923231858Sbztesttx_icmp6_transfernets_gateways() 924231858Sbz{ 925231858Sbz 926231858Sbz testtx_ulp6_transfernets_gateways \ 927231858Sbz "testtx_icmp6_transfernets_gateways" "-i" 928231858Sbz} 929231858Sbz 930231858Sbztesttx_tcp6_transfernets_gateways() 931231858Sbz{ 932231858Sbz 933231858Sbz testtx_ulp6_transfernets_gateways \ 934231858Sbz "testtx_tcp6_transfernets_gateways" "" 935231858Sbz} 936231858Sbz 937231858Sbztesttx_udp6_transfernets_gateways() 938231858Sbz{ 939231858Sbz 940231858Sbz testtx_ulp6_transfernets_gateways \ 941231858Sbz "testtx_udp6_transfernets_gateways" "-u" 942231858Sbz} 943231858Sbz 944231858Sbz################################################################################ 945231858Sbz# 946231858Sbz# Make destination reachable through a different default route in each FIB. 947231858Sbz# Generate a dedicated transfer network for that in each FIB. Delete all but 948231858Sbz# one connected route in all FIBs (e.g. FIB 0 uses prefix 0, ...). 949231858Sbz# 950231858Sbz# Only have a default route present in 1 FIB at a time. 951231858Sbz# 952231858Sbz# Need to tag NS/NA incoming to the right FIB given the default FIB does not 953231858Sbz# know about the prefix and thus cannot do proper source address lookups for 954231858Sbz# replying otherwise. Use ipfw. 955231858Sbz# 956231858Sbztesttx_ulp6_transfernets_gateway() 957231858Sbz{ 958232114Sbz local fib i _n _o _p 959231858Sbz _n="$1" 960231858Sbz _o="$2" 961231858Sbz 962231858Sbz # Setup transfer networks, default routes, and firewall. 963232114Sbz fib=0 964231858Sbz ipfw delete 10 > /dev/null 2>&1 || true 965232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 966232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \ 967231858Sbz > /dev/null 2>&1 || true 968232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias \ 969231858Sbz > /dev/null 2>&1 970232114Sbz ipfw add 10 setfib ${fib} ipv6-icmp \ 971232114Sbz from 2001:2:${fib}::/64 to any ip6 icmp6types 135,136 \ 972231858Sbz via ${IFACE} in > /dev/null 2>&1 973231858Sbz # Remove connected routes from all but matching FIB. 974231858Sbz i=0 975231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 976231858Sbz case ${i} in 977232114Sbz ${fib});; 978231858Sbz *) setfib -F${i} route delete -inet6 \ 979232114Sbz -net 2001:2:${fib}:: > /dev/null 2>&1 980231858Sbz ;; 981231858Sbz esac 982231858Sbz i=$((i + 1)) 983231858Sbz done 984232114Sbz fib=$((fib + 1)) 985231858Sbz done 986231858Sbz 987231858Sbz # Save PEERADDR 988231858Sbz _p=${PEERADDR} 989231858Sbz PEERADDR="2001:2:ff01::2" 990231858Sbz 991231858Sbz # Run tests. 992232114Sbz fib=0 993232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 994231858Sbz 995232114Sbz print_debug "${_n} ${fib}" 996231858Sbz 997231858Sbz # Setup expected return values. 998231858Sbz i=0 999231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1000231858Sbz case "${_o}" in 1001231858Sbz -i) eval rc_${i}_l=0 ;; # ICMPv6 will succeed 1002231858Sbz *) eval rc_${i}_l=1 ;; 1003231858Sbz esac 1004231858Sbz case ${i} in 1005232114Sbz ${fib}) 1006231858Sbz eval rc_${i}_a=0 1007231858Sbz ;; 1008231858Sbz *) eval rc_${i}_a=1 1009231858Sbz ;; 1010231858Sbz esac 1011231858Sbz i=$((i + 1)) 1012231858Sbz done 1013231858Sbz 1014231858Sbz # Add default route. 1015232114Sbz setfib -F${fib} route delete -inet6 -net default \ 1016231858Sbz > /dev/null 2>&1 || true 1017232114Sbz setfib -F${fib} route add -inet6 -net default \ 1018232114Sbz 2001:2:${fib}::2 > /dev/null 2>&1 1019231858Sbz 1020232114Sbz testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib} 1021231858Sbz 1022231858Sbz # Delete default route again. 1023232114Sbz setfib -F${fib} route delete -inet6 -net default \ 1024231858Sbz > /dev/null 2>&1 1025232114Sbz fib=$((fib + 1)) 1026231858Sbz done 1027231858Sbz 1028231858Sbz # Restore PEERADDR 1029231858Sbz PEERADDR=${_p} 1030231858Sbz 1031231858Sbz # Cleanup default routes, transfer networks, and firewall. 1032232114Sbz fib=0 1033232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 1034232114Sbz setfib -F${fib} route delete -inet6 -net default \ 1035231858Sbz > /dev/null 2>&1 1036232114Sbz ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \ 1037231858Sbz > /dev/null 2>&1 1038232114Sbz fib=$((fib + 1)) 1039231858Sbz done 1040231858Sbz ipfw delete 10 > /dev/null 2>&1 1041231858Sbz} 1042231858Sbz 1043231858Sbztesttx_icmp6_transfernets_gateway() 1044231858Sbz{ 1045231858Sbz 1046231858Sbz testtx_ulp6_transfernets_gateway \ 1047231858Sbz "testtx_icmp6_transfernets_gateway" "-i" 1048231858Sbz} 1049231858Sbz 1050231858Sbz 1051231858Sbztesttx_tcp6_transfernets_gateway() 1052231858Sbz{ 1053231858Sbz 1054231858Sbz testtx_ulp6_transfernets_gateway \ 1055231858Sbz "testtx_tcp6_transfernets_gateway" "" 1056231858Sbz} 1057231858Sbz 1058231858Sbztesttx_udp6_transfernets_gateway() 1059231858Sbz{ 1060231858Sbz 1061231858Sbz testtx_ulp6_transfernets_gateway \ 1062231858Sbz "testtx_udp6_transfernets_gateway" "-u" 1063231858Sbz} 1064231858Sbz 1065231858Sbz 1066231858Sbz################################################################################ 1067231858Sbz# 1068231858Sbz# RX tests (Remotely originated connections). The FIB tests happens on peer. 1069231858Sbz# 1070231858Sbz# # For IPFW, IFCONFIG 1071231858Sbz# # For each FIB 1072231858Sbz# # Send OOB well known to work START, wait for reflect 1073231858Sbz# # Send probe, wait for reply with FIB# or RST/ICMP6 unreach 1074231858Sbz# # (in case of ICMP6 use magic like ipfw count and OOB reply) 1075231858Sbz# # Send OOB well known to work DONE, wait for reflect 1076231858Sbz# # Compare real with expected results. 1077231858Sbz# 1078231858Sbztestrx_results() 1079231858Sbz{ 1080231858Sbz local _r _n _fib i count _instances _transfer _o 1081231858Sbz _fib="$1" 1082231858Sbz _n="$2" 1083231858Sbz _r="$3" 1084231858Sbz _instances=$4 1085231858Sbz _transfer=$5 1086231858Sbz _o="$6" 1087231858Sbz 1088231858Sbz print_debug "testrx_results ${_fib} ${_n} ${_r} ${_instances}" 1089231858Sbz 1090231858Sbz # Trim "RESULT " 1091231858Sbz _r=${_r#* } 1092231858Sbz 1093231858Sbz echo "1..${RT_NUMFIBS}" 1094231858Sbz while read i count; do 1095231858Sbz if test ${_instances} -gt 1; then 1096231858Sbz if test ${count} -gt 0; then 1097231858Sbz echo "ok ${i} ${_n}result_${i} #" \ 1098231858Sbz "FIB ${i} ${count} (tested)" 1099231858Sbz else 1100231858Sbz echo "not ok ${i} ${_n}result_${i} #" \ 1101231858Sbz "FIB ${i} ${count} (tested)" 1102231858Sbz fi 1103231858Sbz else 1104231858Sbz case ${i} in 1105231858Sbz ${_fib}) 1106231858Sbz if test ${count} -gt 0; then 1107231858Sbz echo "ok ${i} ${_n}result_${i} #" \ 1108231858Sbz "FIB ${i} ${count} (tested)" 1109231858Sbz else 1110231858Sbz echo "not ok ${i} ${_n}result_${i} #" \ 1111231858Sbz "FIB ${i} ${count} (tested)" 1112231858Sbz fi 1113231858Sbz ;; 1114231858Sbz *) if test ${count} -eq 0; then 1115231858Sbz echo "ok ${i} ${_n}result_${i} #" \ 1116231858Sbz "FIB ${i} ${count}" 1117231858Sbz else 1118231858Sbz echo "not ok ${i} ${_n}result_${i} #" \ 1119231858Sbz "FIB ${i} ${count}" 1120231858Sbz fi 1121231858Sbz ;; 1122231858Sbz esac 1123231858Sbz fi 1124231858Sbz i=$((i + 1)) 1125231858Sbz done <<EOI 1126231858Sbz`echo "${_r}" | tr ',' '\n'` 1127231858SbzEOI 1128231858Sbz 1129231858Sbz} 1130231858Sbz 1131231858Sbztestrx_tcp_udp() 1132231858Sbz{ 1133231858Sbz local _n _o _f testno i _fibtxt _instances _res _port _transfer _p 1134231858Sbz _n="$1" 1135231858Sbz _o="$2" 1136231858Sbz _f="$3" 1137231858Sbz _instances=$4 1138231858Sbz _transfer=$5 1139231858Sbz 1140231858Sbz # Unused so far. 1141231858Sbz : ${_instances:=1} 1142231858Sbz 1143231858Sbz printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}` 1144231858Sbz testno=1 1145231858Sbz i=0 1146231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1147231858Sbz print_debug "Testing ${_f} ${i}" 1148231858Sbz 1149231858Sbz # We are expecting the FIB number (only) to be returned. 1150231858Sbz eval _rc="\${rc_${i}_l}" 1151231858Sbz _fibtxt="${_n}_${i}_l ${_f} ${i} ${PEERLINKLOCAL}" 1152231858Sbz if test ${_instances} -gt 1; then 1153231858Sbz _res="FIB ${i}" 1154231858Sbz _port=$((CTRLPORT + 1000 + i)) 1155231858Sbz else 1156231858Sbz _res="${_fibtxt}" 1157231858Sbz _port=${CTRLPORT} 1158231858Sbz fi 1159231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_res}" ${PEERLINKLOCAL} \ 1160231858Sbz ${_port} "-6 ${_o} -w1" 1161231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" "${_reply}" 1162231858Sbz testno=$((testno + 1)) 1163231858Sbz 1164231858Sbz # If doing multiple transfer networks, replace PEERADDR. 1165231858Sbz _p="${PEERADDR}" 1166231858Sbz case ${_transfer} in 1167231858Sbz 1) PEERADDR=2001:2:${i}::2 ;; 1168231858Sbz esac 1169231858Sbz 1170231858Sbz eval _rc="\${rc_${i}_a}" 1171231858Sbz _fibtxt="${_n}_${i}_a ${_f} ${i} ${PEERADDR}" 1172231858Sbz if test ${_instances} -gt 1; then 1173231858Sbz _res="FIB ${i}" 1174231858Sbz _port=$((CTRLPORT + 1000 + i)) 1175231858Sbz else 1176231858Sbz _res="${_fibtxt}" 1177231858Sbz _port=${CTRLPORT} 1178231858Sbz fi 1179231858Sbz nc_send_recv ${i} 1 "${_fibtxt}" "${_res}" ${PEERADDR} \ 1180231858Sbz ${_port} "-6 ${_o} -w1" 1181231858Sbz check_rc $? ${_rc} ${testno} "${_fibtxt}" "${_reply}" 1182231858Sbz testno=$((testno + 1)) 1183231858Sbz 1184231858Sbz # Restore PEERADDR. 1185231858Sbz PEERADDR="${_p}" 1186231858Sbz 1187231858Sbz i=$((i + 1)) 1188231858Sbz done 1189231858Sbz} 1190231858Sbz 1191231858Sbz 1192231858Sbztestrx_setup_transfer_networks() 1193231858Sbz{ 1194231858Sbz local i 1195231858Sbz 1196231858Sbz i=0 1197231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1198231858Sbz ifconfig ${IFACE} inet6 2001:2:${i}::1/64 -alias \ 1199231858Sbz > /dev/null 2>&1 || true 1200231858Sbz ifconfig ${IFACE} inet6 2001:2:${i}::1/64 alias 1201231858Sbz i=$((i + 1)) 1202231858Sbz done 1203231858Sbz} 1204231858Sbz 1205231858Sbztestrx_cleanup_transfer_networks() 1206231858Sbz{ 1207231858Sbz local i 1208231858Sbz 1209231858Sbz i=0 1210231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1211231858Sbz ifconfig ${IFACE} inet6 2001:2:${i}::1/64 -alias \ 1212231858Sbz > /dev/null 2>&1 1213231858Sbz i=$((i + 1)) 1214231858Sbz done 1215231858Sbz} 1216231858Sbz 1217231858Sbz 1218231858Sbztestrx_run_test() 1219231858Sbz{ 1220231858Sbz local _n _t _fib _o _txt _msg i _reply _instances _destructive _transfer 1221231858Sbz _n="$1" 1222231858Sbz _t="$2" 1223231858Sbz _fib=$3 1224231858Sbz _o="$4" 1225231858Sbz _instances=$5 1226231858Sbz _detsructive=$6 1227231858Sbz _transfer=$7 1228231858Sbz 1229231858Sbz # Netcat options (for UDP basically). 1230231858Sbz case "${_o}" in 1231231858Sbz -i) _opts="" ;; # Use TCP for START/DONE. 1232231858Sbz *) _opts="${_o}" ;; 1233231858Sbz esac 1234231858Sbz 1235231858Sbz # Combined test case base name. 1236231858Sbz case ${USE_SOSETFIB} in 1237231858Sbz 0) _f="setfib" ;; 1238231858Sbz 1) _f="so_setfib" ;; 1239231858Sbz *) die "Unexpected value for SO_SETFIB: ${SO_SETFIB}" ;; 1240231858Sbz esac 1241231858Sbz _txt="${_n}_${_f}_${_t}_${_fib}_${_instances}_${_detsructive}_${_transfer}" 1242231858Sbz 1243231858Sbz print_debug "Starting test '${_txt}' (for ${_instances} instances)." 1244231858Sbz 1245231858Sbz case ${_transfer} in 1246231858Sbz 1) testrx_setup_transfer_networks ;; 1247231858Sbz esac 1248231858Sbz 1249231858Sbz # Let the other side a chance to get ready as well. 1250231858Sbz sleep 1 1251231858Sbz 1252231858Sbz set +e 1253231858Sbz # Let peer know that we are about to start. 1254231858Sbz _msg="START ${_txt}" 1255231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 1256231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 1257231858Sbz case $? in 1258231858Sbz 0) ;; 1259231858Sbz *) die "Got invalid reply from peer." \ 1260231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 1261231858Sbz esac 1262231858Sbz 1263231858Sbz # Let the other side a chance to get ready as well. 1264231858Sbz sleep 1 1265231858Sbz 1266231858Sbz # Send probe. 1267231858Sbz case "${_o}" in 1268231858Sbz -i) testtx_icmp6 "${_txt}_" ${_transfer} ;; 1269231858Sbz *) testrx_tcp_udp "${_txt}" "${_o}" "${_fib}" ${_instances} \ 1270231858Sbz ${_transfer} ;; 1271231858Sbz esac 1272231858Sbz 1273231858Sbz # Let peer know that we are done with this test to move to next. 1274231858Sbz # This must immediately succeed. 1275231858Sbz _msg="DONE ${_txt}" 1276231858Sbz nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \ 1277231858Sbz ${CTRLPORT} "-6 ${_opts} -w1" 1278231858Sbz case $? in 1279231858Sbz 0) ;; 1280231858Sbz *) die "Got invalid reply from peer." \ 1281231858Sbz "Expected '${_msg}', got '${_reply}'" ;; 1282231858Sbz esac 1283231858Sbz 1284231858Sbz # Collect and validate the results. Always use TCP. 1285231858Sbz sleep 1 1286231858Sbz set +e 1287231858Sbz nc_send_recv ${_fib} 1 "RESULT REQUEST" "" ${PEERADDR} \ 1288231858Sbz ${CTRLPORT} "-6 -w1" 1289231858Sbz case "${_reply}" in 1290231858Sbz RESULT\ *) testrx_results ${_fib} "${_txt}_" "${_reply}" ${_instances} \ 1291231858Sbz ${_transfer} "${_o}" 1292231858Sbz ;; 1293231858Sbz *) die "Got invalid reply from peer." \ 1294231858Sbz "Expected 'RESULT ...', got '${_reply}'" ;; 1295231858Sbz esac 1296231858Sbz set -e 1297231858Sbz 1298231858Sbz case ${_transfer} in 1299231858Sbz 1) testrx_cleanup_transfer_networks ;; 1300231858Sbz esac 1301231858Sbz 1302231858Sbz print_debug "Successfully received status update '${_reply}'." 1303231858Sbz} 1304231858Sbz 1305231858Sbztestrx_main_setup_rc() 1306231858Sbz{ 1307231858Sbz local _n _t _fib _o _instances _destructive _transfer i 1308231858Sbz _n="$1" 1309231858Sbz _t="$2" 1310231858Sbz _fib=$3 1311231858Sbz _o="$4" 1312231858Sbz _instances=$5 1313231858Sbz _destructive=$6 1314231858Sbz _transfer=$7 1315231858Sbz 1316231858Sbz # Setup expected return values. 1317231858Sbz if test ${_destructive} -eq 0; then 1318231858Sbz i=0 1319231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1320231858Sbz eval rc_${i}_l=0 1321231858Sbz eval rc_${i}_a=0 1322231858Sbz i=$((i + 1)) 1323231858Sbz done 1324231858Sbz else 1325231858Sbz i=0 1326231858Sbz while test ${i} -lt ${RT_NUMFIBS}; do 1327231858Sbz eval rc_${i}_l=0 1328231858Sbz case ${i} in 1329231858Sbz ${_fib}) eval rc_${i}_a=0 ;; 1330231858Sbz *) # ICMP6 cannot be distinguished and will 1331231858Sbz # always work in single transfer network. 1332231858Sbz case "${_o}" in 1333231858Sbz -i) case ${_transfer} in 1334231858Sbz 0) eval rc_${i}_a=0 ;; 1335231858Sbz 1) eval rc_${i}_a=1 ;; 1336231858Sbz esac 1337231858Sbz ;; 1338231858Sbz *) if test ${_instances} -eq 1 -a \ 1339231858Sbz ${_transfer} -eq 0; then 1340231858Sbz eval rc_${i}_a=0 1341231858Sbz else 1342231858Sbz eval rc_${i}_a=1 1343231858Sbz fi 1344231858Sbz ;; 1345231858Sbz esac 1346231858Sbz ;; 1347231858Sbz esac 1348231858Sbz i=$((i + 1)) 1349231858Sbz done 1350231858Sbz fi 1351231858Sbz 1352231858Sbz print_debug "${_n}_${t}_${_fib} ${_instances} ${_destructive}" \ 1353231858Sbz "${_transfer}" 1354231858Sbz testrx_run_test "${_n}" "${t}" ${_fib} "${_o}" ${_instances} \ 1355231858Sbz ${_destructive} ${_transfer} 1356231858Sbz} 1357231858Sbz 1358231858Sbztestrx_main() 1359231858Sbz{ 1360232114Sbz local _n _o s t fib _instances _destructive _transfer 1361231858Sbz _n="$1" 1362231858Sbz _o="$2" 1363231858Sbz _instances=$3 1364231858Sbz 1365231858Sbz : ${_instances:=1} 1366231858Sbz 1367231858Sbz print_debug "${_n}" 1368231858Sbz for _transfer in 1 0; do 1369231858Sbz for _destructive in 0 1; do 1370231858Sbz for t in ipfw ifconfig; do 1371231858Sbz 1372231858Sbz print_debug "${_n}_${t}" 1373232114Sbz fib=0 1374232114Sbz while test ${fib} -lt ${RT_NUMFIBS}; do 1375231858Sbz 1376231858Sbz testrx_main_setup_rc "${_n}" "${t}" \ 1377232114Sbz ${fib} "${_o}" ${_instances} \ 1378231858Sbz ${_destructive} ${_transfer} 1379231858Sbz 1380232114Sbz fib=$((fib + 1)) 1381231858Sbz done 1382231858Sbz done 1383231858Sbz done 1384231858Sbz done 1385231858Sbz} 1386231858Sbz 1387231858Sbz################################################################################ 1388231858Sbz# 1389231858Sbz# 1390231858Sbz# 1391231858Sbz 1392231858Sbztestrx_icmp6_same_addr_one_fib_a_time() 1393231858Sbz{ 1394231858Sbz 1395231858Sbz testrx_main \ 1396231858Sbz "testrx_icmp6_same_addr_one_fib_a_time" "-i" 1397231858Sbz} 1398231858Sbz 1399231858Sbztestrx_tcp6_same_addr_one_fib_a_time() 1400231858Sbz{ 1401231858Sbz 1402231858Sbz testrx_main \ 1403231858Sbz "testrx_tcp6_same_addr_one_fib_a_time" "" 1404231858Sbz} 1405231858Sbz 1406231858Sbz 1407231858Sbztestrx_udp6_same_addr_one_fib_a_time() 1408231858Sbz{ 1409231858Sbz 1410231858Sbz testrx_main \ 1411231858Sbz "testrx_udp6_same_addr_one_fib_a_time" "-u" 1412231858Sbz} 1413231858Sbz 1414231858Sbz 1415231858Sbz################################################################################ 1416231858Sbz 1417231858Sbztestrx_tcp6_same_addr_all_fibs_a_time() 1418231858Sbz{ 1419231858Sbz 1420231858Sbz testrx_main \ 1421231858Sbz "testrx_tcp6_same_addr_all_fibs_a_time" "" ${RT_NUMFIBS} 1422231858Sbz} 1423231858Sbz 1424231858Sbztestrx_udp6_same_addr_all_fibs_a_time() 1425231858Sbz{ 1426231858Sbz 1427231858Sbz testrx_main \ 1428231858Sbz "testrx_udp6_same_addr_all_fibs_a_time" "-u" ${RT_NUMFIBS} 1429231858Sbz} 1430231858Sbz 1431231858Sbz 1432231858Sbz################################################################################ 1433231858Sbz# 1434231858Sbz# Prereqs. 1435231858Sbz# 1436232114Sbzif test `sysctl -n security.jail.jailed` -eq 0; then 1437232114Sbz kldload ipfw > /dev/null 2>&1 || kldstat -v | grep -q ipfw 1438231858Sbz 1439232114Sbz # Reduce the time we wait in case of no reply to 2s. 1440232114Sbz sysctl net.inet.tcp.keepinit=2000 > /dev/null 2>&1 1441232114Sbzfi 1442232114Sbzipfw -f flush > /dev/null 2>&1 || die "please load ipfw in base system" 1443232114Sbzipfw add 65000 permit ip from any to any > /dev/null 2>&1 1444231858Sbz 1445231858Sbz################################################################################ 1446231858Sbz# 1447231858Sbz# Run tests. 1448231858Sbz# 1449231858Sbz 1450231858Sbz# 64 cases at 16 FIBs. 1451231858Sbzcheck_local_addr 1452231858Sbzcheck_local_tun 1453231858Sbz 1454231858Sbzsend_greeting 1455231858Sbz 1456231858Sbz# Initiator testing. 1457231858Sbzfor uso in 0 1; do 1458231858Sbz 1459231858Sbz USE_SOSETFIB=${uso} 1460231858Sbz 1461231858Sbz # Only run ICMP6 tests for the first loop. 1462231858Sbz # 160 cases at 16 FIBs. 1463231858Sbz test ${uso} -ne 0 || testtx_icmp6_connected && sleep 1 1464231858Sbz testtx_tcp6_connected && sleep 1 1465231858Sbz testtx_udp6_connected && sleep 1 1466231858Sbz 1467231858Sbz # 2560 cases at 16 FIBs. 1468231858Sbz test ${uso} -ne 0 || testtx_icmp6_connected_blackhole && sleep 1 1469231858Sbz testtx_tcp6_connected_blackhole && sleep 1 1470231858Sbz testtx_udp6_connected_blackhole && sleep 1 1471231858Sbz 1472231858Sbz # 2560 cases at 16 FIBs. 1473231858Sbz test ${uso} -ne 0 || testtx_icmp6_connected_transfernets && sleep 1 1474231858Sbz testtx_tcp6_connected_transfernets && sleep 1 1475231858Sbz testtx_udp6_connected_transfernets && sleep 1 1476231858Sbz 1477231858Sbz # 2560 cases at 16 FIBs. 1478231858Sbz test ${uso} -ne 0 || \ 1479231858Sbz testtx_icmp6_connected_ifconfig_transfernets && sleep 1 1480231858Sbz testtx_tcp6_connected_ifconfig_transfernets && sleep 1 1481231858Sbz testtx_udp6_connected_ifconfig_transfernets && sleep 1 1482231858Sbz 1483231858Sbz # 160 cases at 16 FIBs. 1484231858Sbz test ${uso} -ne 0 || testtx_icmp6_gateway && sleep 1 1485231858Sbz testtx_tcp6_gateway && sleep 1 1486231858Sbz testtx_udp6_gateway && sleep 1 1487231858Sbz 1488231858Sbz # 160 cases at 16 FIBs. 1489231858Sbz test ${uso} -ne 0 || testtx_icmp6_transfernets_gateways && sleep 1 1490231858Sbz testtx_tcp6_transfernets_gateways && sleep 1 1491231858Sbz testtx_udp6_transfernets_gateways && sleep 1 1492231858Sbz 1493231858Sbz # 2560 cases at 16 FIBs. 1494231858Sbz test ${uso} -ne 0 || testtx_icmp6_transfernets_gateway && sleep 1 1495231858Sbz testtx_tcp6_transfernets_gateway && sleep 1 1496231858Sbz testtx_udp6_transfernets_gateway && sleep 1 1497231858Sbzdone 1498231858Sbz 1499232114Sbz# Receiver testing. 1500231858Sbzfor uso in 0 1; do 1501231858Sbz 1502231858Sbz USE_SOSETFIB=${uso} 1503231858Sbz 1504231858Sbz # Only expect ICMP6 tests for the first loop. 1505231858Sbz # 6144 cases at 16 FIBs. 1506231858Sbz test ${uso} -ne 0 || testrx_icmp6_same_addr_one_fib_a_time && sleep 1 1507231858Sbz # 12288 cases at 16 FIBs. 1508231858Sbz testrx_tcp6_same_addr_one_fib_a_time && sleep 1 1509231858Sbz # 12288 cases at 16 FIBs. 1510231858Sbz testrx_udp6_same_addr_one_fib_a_time && sleep 1 1511231858Sbz 1512231858Sbz # 12288 cases at 16 FIBs. 1513231858Sbz testrx_tcp6_same_addr_all_fibs_a_time && sleep 1 1514231858Sbz # 12288 cases at 16 FIBs. 1515231858Sbz testrx_udp6_same_addr_all_fibs_a_time && sleep 1 1516231858Sbz 1517231858Sbzdone 1518231858Sbz 1519231858Sbzcleanup 1520231858Sbz 1521231858Sbz# end 1522