3 # Copyright (c) 2012 Cisco Systems, Inc.
6 # This software was developed by Bjoern Zeeb under contract to
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # We will use the RFC5180 (and Errata) benchmarking working group prefix
34 # 2001:0002::/48 for testing.
37 # Set IFACE to the real interface you want to run the test on.
40 # Number of seconds to wait for peer node to synchronize for test.
43 # Control port we use to exchange messages between nodes to sync. tests, etc.
46 # Get the number of FIBs from the kernel.
47 RT_NUMFIBS=`sysctl -n net.fibs`
49 OURADDR="2001:2:ff00::1"
50 PEERADDR="2001:2:ff00::2"
53 # By default all commands must succeed. Individual tests may disable this
69 local _rc _exp _testno _testname _msg _r
77 if test ${_rc} -eq ${_exp}; then
80 echo "${_r} ${_testno} ${_testname} # ${_msg} ${_rc} ${_exp}"
90 *) echo "DEBUG: ${_msg}" >&2 ;;
99 echo "ERROR: ${_msg}" >&2
107 # Make sure the local link-local and global addresses are reachable
113 print_debug "Setting up interface ${IFACE}"
114 ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up
115 _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'`
118 print_debug "Waiting 4 seconds for things to settle"
121 printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}`
125 while test ${i} -lt ${RT_NUMFIBS}; do
126 print_debug "Testing FIB ${i}"
128 setfib -F${i} ping6 -n -c1 ${_l} > /dev/null 2>&1
129 check_rc $? 0 ${testno} "check_local_addr_${i}_l" \
131 testno=$((testno + 1))
133 setfib -F${i} ping6 -n -c1 ${OURADDR} > /dev/null 2>&1
134 check_rc $? 0 ${testno} "check_local_addr_${i}_a" \
135 "FIB ${i} ${OURADDR}"
136 testno=$((testno + 1))
141 ifconfig ${IFACE} inet6 ${OURADDR}/64 -alias
145 # Cloned tun(4) devices behave differently on FIB 0 vs. FIB 1..n after creation
146 # (they also do in IPv4).
149 local _l i testno IFACE _msg
152 print_debug "Setting up interface ${IFACE}"
153 ifconfig ${IFACE} create
154 ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up
155 _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'`
158 print_debug "Waiting 4 seconds for things to settle"
161 printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}`
166 while test ${i} -lt ${RT_NUMFIBS}; do
167 print_debug "Testing FIB ${i}"
168 if test ${i} -gt 0; then
169 # Flag the well known behaviour as such.
173 setfib -F${i} ping6 -n -c1 ${_l} > /dev/null 2>&1
174 check_rc $? 0 ${testno} "check_local_addr_${i}_l" \
175 "${_msg}FIB ${i} ${_l}"
176 testno=$((testno + 1))
178 setfib -F${i} ping6 -n -c1 ${OURADDR} > /dev/null 2>&1
179 check_rc $? 0 ${testno} "check_local_addr_${i}_a" \
180 "${_msg}FIB ${i} ${OURADDR}"
181 testno=$((testno + 1))
186 ifconfig ${IFACE} inet6 ${OURADDR}/64 -alias
187 ifconfig ${IFACE} destroy
194 print_debug "Setting up interface ${IFACE}"
195 ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up
196 _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'`
199 print_debug "Waiting 4 seconds for things to settle"
208 local _l _greeting _keyword _fib _fibs _linklocal
210 print_debug "Setting up interface ${IFACE}"
211 ifconfig ${IFACE} inet6 ${OURADDR}/64 alias up
212 _l=`ifconfig ${IFACE} | awk '/inet6 fe80:/ { print $2 }'`
215 print_debug "Waiting 4 seconds for things to settle"
218 # Cleanup firewall and install rules to always allow NS/NA to succeed.
219 # The latter is needed to allow indvidiual less specific later rules
220 # from test cases to just disallow any IPv6 traffic on a matching FIB.
221 ipfw -f flush > /dev/null 2>&1
222 ipfw add 65000 permit ip from any to any > /dev/null 2>&1
223 ipfw add 5 permit ipv6-icmp from any to any icmp6types 135,136 fib 0 \
224 via ${IFACE} out > /dev/null 2>&1
229 while test ${i} -lt ${WAITS} -a ${rc} -ne 0; do
230 print_debug "Sending greeting #${i} to peer"
231 _greeting=`echo "SETUP ${RT_NUMFIBS} ${_l}" | \
232 nc -6 -w 1 ${PEERADDR} ${CTRLPORT}`
235 # Might sleep longer in total but better than to DoS
236 # and not get anywhere.
241 read _keyword _fibs _linklocal <<EOI
244 print_debug "_keyword=${_keyword}"
245 print_debug "_fibs=${_fibs}"
246 print_debug "_linklocal=${_linklocal}"
249 *) die "Got invalid keyword in greeting: ${_greeting}"
252 if test ${_fibs} -ne ${RT_NUMFIBS}; then
253 die "Number of FIBs not matching ours (${RT_NUMFIBS}) in" \
254 "greeting: ${_greeting}"
256 PEERLINKLOCAL=${_linklocal}
258 # Swap the zoneid to the local interface scope.
259 PEERLINKLOCAL=${PEERLINKLOCAL%%\%*}"%${IFACE}"
261 print_debug "Successfully exchanged greeting. Peer at ${PEERLINKLOCAL}"
268 ipfw delete 5 > /dev/null 2>&1
270 print_debug "Removing address from interface ${IFACE}"
271 ifconfig ${IFACE} inet6 ${OURADDR}/64 -alias
276 local _n _transfer i testno _txt _fibtxt _rc _ec _p
280 printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}`
284 while test ${i} -lt ${RT_NUMFIBS}; do
286 print_debug "Testing ${_txt}"
287 _fibtxt=`echo "${_txt}" | hd -v | cut -b11-60 | tr -d ' \r\n'`
289 eval _rc="\${rc_${i}_l}"
290 setfib -F${i} ping6 -n -c1 -p ${_fibtxt} \
291 ${PEERLINKLOCAL} > /dev/null 2>&1
293 # We need to normalize the exit code of ping6.
298 check_rc ${_ec} ${_rc} ${testno} "${_txt}_l" \
299 "FIB ${i} ${PEERLINKLOCAL}"
300 testno=$((testno + 1))
302 # If doing multiple transfer networks, replace PEERADDR.
305 1) PEERADDR=2001:2:${i}::2 ;;
308 eval _rc="\${rc_${i}_a}"
309 setfib -F${i} ping6 -n -c1 -p ${_fibtxt} ${PEERADDR} \
312 # We need to normalize the exit code of ping6.
317 check_rc ${_ec} ${_rc} ${testno} "${_txt}_a" \
318 "FIB ${i} ${PEERADDR}"
319 testno=$((testno + 1))
331 local _fib _loops _msg _expreply _addr _port _opts i
341 while test ${i} -lt ${_loops}; do
343 case "${USE_SOSETFIB}" in
345 _reply=`echo "${_msg}" | \
346 nc -V ${_fib} ${_opts} ${_addr} ${_port}`
349 _reply=`echo "${_msg}" | \
350 setfib -F${_fib} nc ${_opts} ${_addr} ${_port}`
353 if test "${_reply}" != "${_expreply}"; then
354 if test ${i} -lt ${_loops}; then
357 # Must let caller decide how to handle the error.
358 # die "Got invalid reply from peer." \
359 # "Expected '${_expreply}', got '${_reply}'"
371 local _n _o _f testno i _fibtxt
376 printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}`
379 while test ${i} -lt ${RT_NUMFIBS}; do
380 print_debug "Testing ${_f} ${i}"
382 eval _rc="\${rc_${i}_l}"
383 _fibtxt="${_n}_${i}_l ${_f} ${i} ${PEERLINKLOCAL}"
384 nc_send_recv ${i} 1 "${_fibtxt}" "${_fibtxt}" ${PEERLINKLOCAL} \
385 ${CTRLPORT} "-6 ${_o} -w1"
386 check_rc $? ${_rc} ${testno} "${_fibtxt}"
387 testno=$((testno + 1))
389 eval _rc="\${rc_${i}_a}"
390 _fibtxt="${_n}_${i}_a ${_f} ${i} ${PEERADDR}"
391 nc_send_recv ${i} 1 "${_fibtxt}" "${_fibtxt}" ${PEERADDR} \
392 ${CTRLPORT} "-6 ${_o} -w1"
393 check_rc $? ${_rc} ${testno} "${_fibtxt}"
394 testno=$((testno + 1))
400 # setfib TCP|UDP/IPv6 test on link-local and global address of peer from all FIBs.
401 testtx_ulp6_connected()
403 local _fibtxt _reply _n _o _rc _fib _f _opts
408 case "${USE_SOSETFIB}" in
413 if test "${_o}" = "-i" -a "${_f}" = "SO_SETFIB"; then
414 print_debug "Skipping icmp6 tests for SO_SETFIB."
418 # Clear the neighbor table to get deterministic runs.
419 ndp -cn > /dev/null 2>&1
422 -i) _opts="" ;; # Use TCP for START/DONE.
427 # Let peer know that we are about to start.
429 nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \
430 ${CTRLPORT} "-6 ${_opts} -w1"
433 *) die "Got invalid reply from peer." \
434 "Expected '${_msg}', got '${_reply}'" ;;
438 -i) testtx_icmp6 "${_n}" ;;
439 *) testtx_tcp_udp "${_n}" "${_o}" "${_f}" ;;
442 # Let peer know that we are done with this test to move to next.
443 # This must immediately succeed.
445 nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \
446 ${CTRLPORT} "-6 ${_opts} -w1"
449 *) die "Got invalid reply from peer." \
450 "Expected '${_msg}', got '${_reply}'" ;;
454 print_debug "Successfully received status update '${_reply}'."
457 ################################################################################
459 # ping6|TCP/UDP connect link-local and global address of peer from all FIBs.
460 # Default reachability test.
462 testtx_icmp6_connected()
466 # Setup expected return values.
468 while test ${i} -lt ${RT_NUMFIBS}; do
474 testtx_ulp6_connected "testtx_icmp6_connected" "-i" 0
477 testtx_tcp6_connected()
481 # Setup expected return values.
483 while test ${i} -lt ${RT_NUMFIBS}; do
489 testtx_ulp6_connected testtx_tcp6_connected "" 0
492 testtx_udp6_connected()
496 # Setup expected return values.
498 while test ${i} -lt ${RT_NUMFIBS}; do
504 testtx_ulp6_connected testtx_udp6_connected "-u" 0
507 ################################################################################
509 # Use ipfw to return unreach messages for all but one FIB. Rotate over all.
510 # Making sure error messages are properly returned.
512 testtx_ulp6_connected_blackhole()
519 while test ${fib} -lt ${RT_NUMFIBS}; do
521 print_debug "${_n} ${fib}"
523 # Setup expected return values.
525 while test ${i} -lt ${RT_NUMFIBS}; do
526 ipfw delete $((100 + i)) > /dev/null 2>&1 || true
534 ipfw add $((100 + i)) unreach6 admin-prohib \
535 ip6 from any to any fib ${i} via ${IFACE} \
542 testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib}
550 while test ${fib} -lt ${RT_NUMFIBS}; do
551 ipfw delete $((100 + fib)) > /dev/null 2>&1 || true
556 testtx_icmp6_connected_blackhole()
559 testtx_ulp6_connected_blackhole \
560 "testtx_icmp6_connected_blackhole" "-i"
563 testtx_tcp6_connected_blackhole()
566 testtx_ulp6_connected_blackhole \
567 "testtx_tcp6_connected_blackhole" ""
570 testtx_udp6_connected_blackhole()
573 testtx_ulp6_connected_blackhole \
574 "testtx_udp6_connected_blackhole" "-u"
577 ################################################################################
579 # Setup a different transfer net on each FIB. Delete all but one connected
580 # route in all FIBs (e.g. FIB 0 uses prefix 0, FIB 1 uses prefix 1 , ...).
582 # Need to tag NS/NA incoming to the right FIB given the default FIB does not
583 # know about the prefix and thus cannot do proper source address lookups for
584 # replying otherwise. Use ipfw.
586 testtx_ulp6_connected_transfernets()
592 # Setup transfer networks and firewall.
593 ipfw delete 10 > /dev/null 2>&1 || true
595 while test ${fib} -lt ${RT_NUMFIBS}; do
596 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \
597 > /dev/null 2>&1 || true
598 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias
599 ipfw add 10 setfib ${fib} ipv6-icmp from 2001:2:${fib}::/64 \
600 to any ip6 icmp6types 135,136 via ${IFACE} in \
602 # Remove connected routes from all but matching FIB.
604 while test ${i} -lt ${RT_NUMFIBS}; do
607 *) setfib -F${i} route delete -inet6 \
608 -net 2001:2:${fib}:: > /dev/null 2>&1
621 while test ${fib} -lt ${RT_NUMFIBS}; do
622 PEERADDR=2001:2:${fib}::2
624 print_debug "${_n} ${fib}"
626 # Setup expected return values.
628 while test ${i} -lt ${RT_NUMFIBS}; do
640 testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib}
647 # Cleanup transfer networks and firewall.
649 while test ${fib} -lt ${RT_NUMFIBS}; do
650 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias
653 ipfw delete 10 > /dev/null 2>&1
656 testtx_icmp6_connected_transfernets()
659 testtx_ulp6_connected_transfernets \
660 "testtx_icmp6_connected_transfernets" "-i"
663 testtx_tcp6_connected_transfernets()
666 testtx_ulp6_connected_transfernets \
667 "testtx_tcp6_connected_transfernets" ""
670 testtx_udp6_connected_transfernets()
673 testtx_ulp6_connected_transfernets \
674 "testtx_udp6_connected_transfernets" "-u"
677 ################################################################################
679 # Setup a different transfernet on each FIB. Delete all but one connected
680 # route in all FIBs (e.g. FIB 0 uses prefix 0, FIB 1 uses prefix 1 , ...).
682 # Need to tag NS/NA incoming to the right FIB given the default FIB does not
683 # know about the prefix and thus cannot do proper source address lookups for
684 # replying otherwise. Use ifconfig IFACE fib.
686 testtx_ulp6_connected_ifconfig_transfernets()
692 # Setup transfer networks.
694 while test ${fib} -lt ${RT_NUMFIBS}; do
695 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \
696 > /dev/null 2>&1 || true
697 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias
698 # Remove connected routes from all but matching FIB.
700 while test ${i} -lt ${RT_NUMFIBS}; do
703 *) setfib -F${i} route delete -inet6 \
704 -net 2001:2:${fib}:: > /dev/null 2>&1
717 while test ${fib} -lt ${RT_NUMFIBS}; do
718 PEERADDR=2001:2:${fib}::2
720 print_debug "${_n} ${fib}"
722 # Setup expected return values.
724 while test ${i} -lt ${RT_NUMFIBS}; do
736 ifconfig ${IFACE} fib ${fib}
738 testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib}
745 # Cleanup transfer networks.
747 while test ${fib} -lt ${RT_NUMFIBS}; do
748 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias
751 ifconfig ${IFACE} fib 0
754 testtx_icmp6_connected_ifconfig_transfernets()
757 testtx_ulp6_connected_ifconfig_transfernets \
758 "testtx_icmp6_connected_ifconfig_transfernets" "-i"
762 testtx_tcp6_connected_ifconfig_transfernets()
765 testtx_ulp6_connected_ifconfig_transfernets \
766 "testtx_tcp6_connected_ifconfig_transfernets" ""
769 testtx_udp6_connected_ifconfig_transfernets()
772 testtx_ulp6_connected_ifconfig_transfernets \
773 "testtx_udp6_connected_ifconfig_transfernets" "-u"
776 ################################################################################
778 # Make destination reachable through the same default route in each FIB only.
779 # Run standard reachability test.
781 testtx_ulp6_gateway()
787 # Setup default gateway and expected error codes.
789 while test ${fib} -lt ${RT_NUMFIBS}; do
790 setfib -F${fib} route delete -inet6 -net default \
791 > /dev/null 2>&1 || true
792 setfib -F${fib} route add -inet6 -net default ${PEERADDR} \
795 -i) eval rc_${fib}_l=0 ;; # ICMPv6 will succeed
796 *) eval rc_${fib}_l=1 ;;
804 PEERADDR="2001:2:ff01::2"
808 testtx_ulp6_connected "${_n}" "${_o}" 0
813 # Cleanup transfer networks.
815 while test ${fib} -lt ${RT_NUMFIBS}; do
816 setfib -F${fib} route delete -inet6 -net default \
822 testtx_icmp6_gateway()
825 testtx_ulp6_gateway "testtx_icmp6_gateway" "-i"
828 testtx_tcp6_gateway()
831 testtx_ulp6_gateway "testtx_tcp6_gateway" ""
834 testtx_udp6_gateway()
837 testtx_ulp6_gateway "testtx_udp6_gateway" "-u"
840 ################################################################################
842 # Make destination reachable through a different default route in each FIB.
843 # Generate a dedicated transfer network for that in each FIB. Delete all but
844 # one connected route in all FIBs (e.g. FIB 0 uses prefix 0, ...).
846 # Have a default route present in each FIB all time.
848 # Need to tag NS/NA incoming to the right FIB given the default FIB does not
849 # know about the prefix and thus cannot do proper source address lookups for
850 # replying otherwise. Use ipfw.
853 testtx_ulp6_transfernets_gateways()
859 # Setup transfer networks, default routes, and firewall.
861 ipfw delete 10 > /dev/null 2>&1 || true
862 while test ${fib} -lt ${RT_NUMFIBS}; do
863 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \
864 > /dev/null 2>&1 || true
865 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias \
867 ipfw add 10 setfib ${fib} ipv6-icmp \
868 from 2001:2:${fib}::/64 to any ip6 icmp6types 135,136 \
869 via ${IFACE} in > /dev/null 2>&1
870 # Remove connected routes from all but matching FIB.
872 while test ${i} -lt ${RT_NUMFIBS}; do
875 *) setfib -F${i} route delete -inet6 \
876 -net 2001:2:${fib}:: > /dev/null 2>&1
882 setfib -F${fib} route delete -inet6 -net default \
883 > /dev/null 2>&1 || true
884 setfib -F${fib} route add -inet6 -net default \
885 2001:2:${fib}::2 > /dev/null 2>&1
891 PEERADDR="2001:2:ff01::2"
893 # Setup expected return values.
895 while test ${i} -lt ${RT_NUMFIBS}; do
897 -i) eval rc_${i}_l=0 ;; # ICMPv6 will succeed
898 *) eval rc_${i}_l=1 ;;
906 testtx_ulp6_connected "${_n}" "${_o}" 0
911 # Cleanup default routes, transfer networks, and firewall.
913 while test ${fib} -lt ${RT_NUMFIBS}; do
914 setfib -F${fib} route delete -inet6 -net default \
916 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \
920 ipfw delete 10 > /dev/null 2>&1
923 testtx_icmp6_transfernets_gateways()
926 testtx_ulp6_transfernets_gateways \
927 "testtx_icmp6_transfernets_gateways" "-i"
930 testtx_tcp6_transfernets_gateways()
933 testtx_ulp6_transfernets_gateways \
934 "testtx_tcp6_transfernets_gateways" ""
937 testtx_udp6_transfernets_gateways()
940 testtx_ulp6_transfernets_gateways \
941 "testtx_udp6_transfernets_gateways" "-u"
944 ################################################################################
946 # Make destination reachable through a different default route in each FIB.
947 # Generate a dedicated transfer network for that in each FIB. Delete all but
948 # one connected route in all FIBs (e.g. FIB 0 uses prefix 0, ...).
950 # Only have a default route present in 1 FIB at a time.
952 # Need to tag NS/NA incoming to the right FIB given the default FIB does not
953 # know about the prefix and thus cannot do proper source address lookups for
954 # replying otherwise. Use ipfw.
956 testtx_ulp6_transfernets_gateway()
962 # Setup transfer networks, default routes, and firewall.
964 ipfw delete 10 > /dev/null 2>&1 || true
965 while test ${fib} -lt ${RT_NUMFIBS}; do
966 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \
967 > /dev/null 2>&1 || true
968 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 alias \
970 ipfw add 10 setfib ${fib} ipv6-icmp \
971 from 2001:2:${fib}::/64 to any ip6 icmp6types 135,136 \
972 via ${IFACE} in > /dev/null 2>&1
973 # Remove connected routes from all but matching FIB.
975 while test ${i} -lt ${RT_NUMFIBS}; do
978 *) setfib -F${i} route delete -inet6 \
979 -net 2001:2:${fib}:: > /dev/null 2>&1
989 PEERADDR="2001:2:ff01::2"
993 while test ${fib} -lt ${RT_NUMFIBS}; do
995 print_debug "${_n} ${fib}"
997 # Setup expected return values.
999 while test ${i} -lt ${RT_NUMFIBS}; do
1001 -i) eval rc_${i}_l=0 ;; # ICMPv6 will succeed
1002 *) eval rc_${i}_l=1 ;;
1014 # Add default route.
1015 setfib -F${fib} route delete -inet6 -net default \
1016 > /dev/null 2>&1 || true
1017 setfib -F${fib} route add -inet6 -net default \
1018 2001:2:${fib}::2 > /dev/null 2>&1
1020 testtx_ulp6_connected "${_n}${fib}" "${_o}" ${fib}
1022 # Delete default route again.
1023 setfib -F${fib} route delete -inet6 -net default \
1031 # Cleanup default routes, transfer networks, and firewall.
1033 while test ${fib} -lt ${RT_NUMFIBS}; do
1034 setfib -F${fib} route delete -inet6 -net default \
1036 ifconfig ${IFACE} inet6 2001:2:${fib}::1/64 -alias \
1040 ipfw delete 10 > /dev/null 2>&1
1043 testtx_icmp6_transfernets_gateway()
1046 testtx_ulp6_transfernets_gateway \
1047 "testtx_icmp6_transfernets_gateway" "-i"
1051 testtx_tcp6_transfernets_gateway()
1054 testtx_ulp6_transfernets_gateway \
1055 "testtx_tcp6_transfernets_gateway" ""
1058 testtx_udp6_transfernets_gateway()
1061 testtx_ulp6_transfernets_gateway \
1062 "testtx_udp6_transfernets_gateway" "-u"
1066 ################################################################################
1068 # RX tests (Remotely originated connections). The FIB tests happens on peer.
1070 # # For IPFW, IFCONFIG
1072 # # Send OOB well known to work START, wait for reflect
1073 # # Send probe, wait for reply with FIB# or RST/ICMP6 unreach
1074 # # (in case of ICMP6 use magic like ipfw count and OOB reply)
1075 # # Send OOB well known to work DONE, wait for reflect
1076 # # Compare real with expected results.
1080 local _r _n _fib i count _instances _transfer _o
1088 print_debug "testrx_results ${_fib} ${_n} ${_r} ${_instances}"
1093 echo "1..${RT_NUMFIBS}"
1094 while read i count; do
1095 if test ${_instances} -gt 1; then
1096 if test ${count} -gt 0; then
1097 echo "ok ${i} ${_n}result_${i} #" \
1098 "FIB ${i} ${count} (tested)"
1100 echo "not ok ${i} ${_n}result_${i} #" \
1101 "FIB ${i} ${count} (tested)"
1106 if test ${count} -gt 0; then
1107 echo "ok ${i} ${_n}result_${i} #" \
1108 "FIB ${i} ${count} (tested)"
1110 echo "not ok ${i} ${_n}result_${i} #" \
1111 "FIB ${i} ${count} (tested)"
1114 *) if test ${count} -eq 0; then
1115 echo "ok ${i} ${_n}result_${i} #" \
1118 echo "not ok ${i} ${_n}result_${i} #" \
1126 `echo "${_r}" | tr ',' '\n'`
1133 local _n _o _f testno i _fibtxt _instances _res _port _transfer _p
1143 printf "1..%d\n" `expr 2 \* ${RT_NUMFIBS}`
1146 while test ${i} -lt ${RT_NUMFIBS}; do
1147 print_debug "Testing ${_f} ${i}"
1149 # We are expecting the FIB number (only) to be returned.
1150 eval _rc="\${rc_${i}_l}"
1151 _fibtxt="${_n}_${i}_l ${_f} ${i} ${PEERLINKLOCAL}"
1152 if test ${_instances} -gt 1; then
1154 _port=$((CTRLPORT + 1000 + i))
1159 nc_send_recv ${i} 1 "${_fibtxt}" "${_res}" ${PEERLINKLOCAL} \
1160 ${_port} "-6 ${_o} -w1"
1161 check_rc $? ${_rc} ${testno} "${_fibtxt}" "${_reply}"
1162 testno=$((testno + 1))
1164 # If doing multiple transfer networks, replace PEERADDR.
1166 case ${_transfer} in
1167 1) PEERADDR=2001:2:${i}::2 ;;
1170 eval _rc="\${rc_${i}_a}"
1171 _fibtxt="${_n}_${i}_a ${_f} ${i} ${PEERADDR}"
1172 if test ${_instances} -gt 1; then
1174 _port=$((CTRLPORT + 1000 + i))
1179 nc_send_recv ${i} 1 "${_fibtxt}" "${_res}" ${PEERADDR} \
1180 ${_port} "-6 ${_o} -w1"
1181 check_rc $? ${_rc} ${testno} "${_fibtxt}" "${_reply}"
1182 testno=$((testno + 1))
1192 testrx_setup_transfer_networks()
1197 while test ${i} -lt ${RT_NUMFIBS}; do
1198 ifconfig ${IFACE} inet6 2001:2:${i}::1/64 -alias \
1199 > /dev/null 2>&1 || true
1200 ifconfig ${IFACE} inet6 2001:2:${i}::1/64 alias
1205 testrx_cleanup_transfer_networks()
1210 while test ${i} -lt ${RT_NUMFIBS}; do
1211 ifconfig ${IFACE} inet6 2001:2:${i}::1/64 -alias \
1220 local _n _t _fib _o _txt _msg i _reply _instances _destructive _transfer
1229 # Netcat options (for UDP basically).
1231 -i) _opts="" ;; # Use TCP for START/DONE.
1235 # Combined test case base name.
1236 case ${USE_SOSETFIB} in
1238 1) _f="so_setfib" ;;
1239 *) die "Unexpected value for SO_SETFIB: ${SO_SETFIB}" ;;
1241 _txt="${_n}_${_f}_${_t}_${_fib}_${_instances}_${_detsructive}_${_transfer}"
1243 print_debug "Starting test '${_txt}' (for ${_instances} instances)."
1245 case ${_transfer} in
1246 1) testrx_setup_transfer_networks ;;
1249 # Let the other side a chance to get ready as well.
1253 # Let peer know that we are about to start.
1254 _msg="START ${_txt}"
1255 nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \
1256 ${CTRLPORT} "-6 ${_opts} -w1"
1259 *) die "Got invalid reply from peer." \
1260 "Expected '${_msg}', got '${_reply}'" ;;
1263 # Let the other side a chance to get ready as well.
1268 -i) testtx_icmp6 "${_txt}_" ${_transfer} ;;
1269 *) testrx_tcp_udp "${_txt}" "${_o}" "${_fib}" ${_instances} \
1273 # Let peer know that we are done with this test to move to next.
1274 # This must immediately succeed.
1276 nc_send_recv ${_fib} ${WAITS} "${_msg}" "${_msg}" ${PEERADDR} \
1277 ${CTRLPORT} "-6 ${_opts} -w1"
1280 *) die "Got invalid reply from peer." \
1281 "Expected '${_msg}', got '${_reply}'" ;;
1284 # Collect and validate the results. Always use TCP.
1287 nc_send_recv ${_fib} 1 "RESULT REQUEST" "" ${PEERADDR} \
1288 ${CTRLPORT} "-6 -w1"
1290 RESULT\ *) testrx_results ${_fib} "${_txt}_" "${_reply}" ${_instances} \
1291 ${_transfer} "${_o}"
1293 *) die "Got invalid reply from peer." \
1294 "Expected 'RESULT ...', got '${_reply}'" ;;
1298 case ${_transfer} in
1299 1) testrx_cleanup_transfer_networks ;;
1302 print_debug "Successfully received status update '${_reply}'."
1305 testrx_main_setup_rc()
1307 local _n _t _fib _o _instances _destructive _transfer i
1316 # Setup expected return values.
1317 if test ${_destructive} -eq 0; then
1319 while test ${i} -lt ${RT_NUMFIBS}; do
1326 while test ${i} -lt ${RT_NUMFIBS}; do
1329 ${_fib}) eval rc_${i}_a=0 ;;
1330 *) # ICMP6 cannot be distinguished and will
1331 # always work in single transfer network.
1333 -i) case ${_transfer} in
1334 0) eval rc_${i}_a=0 ;;
1335 1) eval rc_${i}_a=1 ;;
1338 *) if test ${_instances} -eq 1 -a \
1339 ${_transfer} -eq 0; then
1352 print_debug "${_n}_${t}_${_fib} ${_instances} ${_destructive}" \
1354 testrx_run_test "${_n}" "${t}" ${_fib} "${_o}" ${_instances} \
1355 ${_destructive} ${_transfer}
1360 local _n _o s t fib _instances _destructive _transfer
1368 for _transfer in 1 0; do
1369 for _destructive in 0 1; do
1370 for t in ipfw ifconfig; do
1372 print_debug "${_n}_${t}"
1374 while test ${fib} -lt ${RT_NUMFIBS}; do
1376 testrx_main_setup_rc "${_n}" "${t}" \
1377 ${fib} "${_o}" ${_instances} \
1378 ${_destructive} ${_transfer}
1387 ################################################################################
1392 testrx_icmp6_same_addr_one_fib_a_time()
1396 "testrx_icmp6_same_addr_one_fib_a_time" "-i"
1399 testrx_tcp6_same_addr_one_fib_a_time()
1403 "testrx_tcp6_same_addr_one_fib_a_time" ""
1407 testrx_udp6_same_addr_one_fib_a_time()
1411 "testrx_udp6_same_addr_one_fib_a_time" "-u"
1415 ################################################################################
1417 testrx_tcp6_same_addr_all_fibs_a_time()
1421 "testrx_tcp6_same_addr_all_fibs_a_time" "" ${RT_NUMFIBS}
1424 testrx_udp6_same_addr_all_fibs_a_time()
1428 "testrx_udp6_same_addr_all_fibs_a_time" "-u" ${RT_NUMFIBS}
1432 ################################################################################
1436 if test `sysctl -n security.jail.jailed` -eq 0; then
1437 kldload ipfw > /dev/null 2>&1 || kldstat -v | grep -q ipfw
1439 # Reduce the time we wait in case of no reply to 2s.
1440 sysctl net.inet.tcp.keepinit=2000 > /dev/null 2>&1
1442 ipfw -f flush > /dev/null 2>&1 || die "please load ipfw in base system"
1443 ipfw add 65000 permit ip from any to any > /dev/null 2>&1
1445 ################################################################################
1450 # 64 cases at 16 FIBs.
1456 # Initiator testing.
1461 # Only run ICMP6 tests for the first loop.
1462 # 160 cases at 16 FIBs.
1463 test ${uso} -ne 0 || testtx_icmp6_connected && sleep 1
1464 testtx_tcp6_connected && sleep 1
1465 testtx_udp6_connected && sleep 1
1467 # 2560 cases at 16 FIBs.
1468 test ${uso} -ne 0 || testtx_icmp6_connected_blackhole && sleep 1
1469 testtx_tcp6_connected_blackhole && sleep 1
1470 testtx_udp6_connected_blackhole && sleep 1
1472 # 2560 cases at 16 FIBs.
1473 test ${uso} -ne 0 || testtx_icmp6_connected_transfernets && sleep 1
1474 testtx_tcp6_connected_transfernets && sleep 1
1475 testtx_udp6_connected_transfernets && sleep 1
1477 # 2560 cases at 16 FIBs.
1478 test ${uso} -ne 0 || \
1479 testtx_icmp6_connected_ifconfig_transfernets && sleep 1
1480 testtx_tcp6_connected_ifconfig_transfernets && sleep 1
1481 testtx_udp6_connected_ifconfig_transfernets && sleep 1
1483 # 160 cases at 16 FIBs.
1484 test ${uso} -ne 0 || testtx_icmp6_gateway && sleep 1
1485 testtx_tcp6_gateway && sleep 1
1486 testtx_udp6_gateway && sleep 1
1488 # 160 cases at 16 FIBs.
1489 test ${uso} -ne 0 || testtx_icmp6_transfernets_gateways && sleep 1
1490 testtx_tcp6_transfernets_gateways && sleep 1
1491 testtx_udp6_transfernets_gateways && sleep 1
1493 # 2560 cases at 16 FIBs.
1494 test ${uso} -ne 0 || testtx_icmp6_transfernets_gateway && sleep 1
1495 testtx_tcp6_transfernets_gateway && sleep 1
1496 testtx_udp6_transfernets_gateway && sleep 1
1504 # Only expect ICMP6 tests for the first loop.
1505 # 6144 cases at 16 FIBs.
1506 test ${uso} -ne 0 || testrx_icmp6_same_addr_one_fib_a_time && sleep 1
1507 # 12288 cases at 16 FIBs.
1508 testrx_tcp6_same_addr_one_fib_a_time && sleep 1
1509 # 12288 cases at 16 FIBs.
1510 testrx_udp6_same_addr_one_fib_a_time && sleep 1
1512 # 12288 cases at 16 FIBs.
1513 testrx_tcp6_same_addr_all_fibs_a_time && sleep 1
1514 # 12288 cases at 16 FIBs.
1515 testrx_udp6_same_addr_all_fibs_a_time && sleep 1