1# $NetBSD: t_icmp_redirect.sh,v 1.1 2015/08/31 06:16:08 ozaki-r Exp $ 2# 3# Copyright (c) 2015 The NetBSD Foundation, Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28# Most codes are derived from tests/net/route/t_flags.sh 29 30netserver=\ 31"rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif" 32SOCK_LOCAL=unix://commsock1 33SOCK_PEER=unix://commsock2 34SOCK_GW=unix://commsock3 35BUS=bus1 36BUS2=bus2 37REDIRECT_TIMEOUT=5 38 39DEBUG=false 40 41atf_test_case icmp_redirect_timeout cleanup 42 43icmp_redirect_timeout_head() 44{ 45 46 atf_set "descr" "Tests for ICMP redirect timeout"; 47 atf_set "require.progs" "rump_server"; 48} 49 50setup_local() 51{ 52 53 atf_check -s exit:0 ${netserver} ${SOCK_LOCAL} 54 55 export RUMP_SERVER=$SOCK_LOCAL 56 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 57 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 58 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24 59 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 60 61 atf_check -s exit:0 -o ignore rump.sysctl -w \ 62 net.inet.icmp.redirtimeout=$REDIRECT_TIMEOUT 63 64 $DEBUG && rump.ifconfig 65 $DEBUG && rump.netstat -rn -f inet 66} 67 68setup_peer() 69{ 70 71 atf_check -s exit:0 ${netserver} ${SOCK_PEER} 72 73 export RUMP_SERVER=$SOCK_PEER 74 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 75 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 76 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24 77 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 78 79 $DEBUG && rump.ifconfig 80 $DEBUG && rump.netstat -rn -f inet 81} 82 83setup_gw() 84{ 85 86 atf_check -s exit:0 ${netserver} ${SOCK_GW} 87 88 export RUMP_SERVER=$SOCK_GW 89 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 90 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 91 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24 92 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 93 94 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 create 95 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 linkstr ${BUS2} 96 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24 97 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24 98 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up 99 100 # Wait until DAD completes (10 sec at most) 101 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 102 atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative" 103 104 $DEBUG && rump.ifconfig 105 $DEBUG && rump.netstat -rn -f inet 106} 107 108teardown_gw() 109{ 110 111 env RUMP_SERVER=$SOCK_GW rump.halt 112} 113 114check_entry_flags() 115{ 116 local ip=$(echo $1 |sed 's/\./\\./g') 117 local flags=$2 118 119 atf_check -s exit:0 -o match:" $flags " -e ignore -x \ 120 "rump.netstat -rn -f inet | grep ^'$ip'" 121} 122 123check_entry_gw() 124{ 125 local ip=$(echo $1 |sed 's/\./\\./g') 126 local gw=$2 127 128 atf_check -s exit:0 -o match:" $gw " -e ignore -x \ 129 "rump.netstat -rn -f inet | grep ^'$ip'" 130} 131 132check_entry_fail() 133{ 134 local ip=$(echo $1 |sed 's/\./\\./g') 135 local flags=$2 # Not used currently 136 137 atf_check -s not-exit:0 -e ignore -x \ 138 "rump.netstat -rn -f inet | grep ^'$ip'" 139} 140 141icmp_redirect_timeout_body() 142{ 143 144 $DEBUG && ulimit -c unlimited 145 146 setup_local 147 setup_peer 148 149 ### Testing Dynamic flag ### 150 151 # 152 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it. 153 # 154 setup_gw 155 156 # 157 # Teach the peer that 10.0.2.* is behind 10.0.0.254 158 # 159 export RUMP_SERVER=$SOCK_PEER 160 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254 161 # Up, Gateway, Static 162 check_entry_flags 10.0.2/24 UGS 163 164 # 165 # Setup the default gateway to the peer, 10.0.0.1 166 # 167 export RUMP_SERVER=$SOCK_LOCAL 168 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1 169 # Up, Gateway, Static 170 check_entry_flags default UGS 171 172 # Try ping 10.0.2.1 173 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1 174 $DEBUG && rump.netstat -rn -f inet 175 176 # Up, Gateway, Host, Dynamic 177 check_entry_flags 10.0.2.1 UGHD 178 check_entry_gw 10.0.2.1 10.0.0.254 179 180 atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2)) 181 182 # The dynamic entry should be expired and removed 183 check_entry_fail 10.0.2.1 184 185 export RUMP_SERVER=$SOCK_PEER 186 $DEBUG && rump.netstat -rn -f inet 187 188 teardown_gw 189} 190 191dump() 192{ 193 194 shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r - 195 gdb -ex bt /usr/bin/rump_server rump_server.core 196} 197 198cleanup() 199{ 200 201 env RUMP_SERVER=$SOCK_LOCAL rump.halt 202 env RUMP_SERVER=$SOCK_PEER rump.halt 203} 204 205icmp_redirect_timeout_cleanup() 206{ 207 208 $DEBUG && dump 209 cleanup 210} 211 212atf_init_test_cases() 213{ 214 215 atf_add_test_case icmp_redirect_timeout 216} 217