1*0a6a1f1dSLionel Sambuc# $NetBSD: t_flags.sh,v 1.3 2015/06/01 01:36:30 ozaki-r Exp $ 2*0a6a1f1dSLionel Sambuc# 3*0a6a1f1dSLionel Sambuc# Copyright (c) 2015 The NetBSD Foundation, Inc. 4*0a6a1f1dSLionel Sambuc# All rights reserved. 5*0a6a1f1dSLionel Sambuc# 6*0a6a1f1dSLionel Sambuc# Redistribution and use in source and binary forms, with or without 7*0a6a1f1dSLionel Sambuc# modification, are permitted provided that the following conditions 8*0a6a1f1dSLionel Sambuc# are met: 9*0a6a1f1dSLionel Sambuc# 1. Redistributions of source code must retain the above copyright 10*0a6a1f1dSLionel Sambuc# notice, this list of conditions and the following disclaimer. 11*0a6a1f1dSLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 12*0a6a1f1dSLionel Sambuc# notice, this list of conditions and the following disclaimer in the 13*0a6a1f1dSLionel Sambuc# documentation and/or other materials provided with the distribution. 14*0a6a1f1dSLionel Sambuc# 15*0a6a1f1dSLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16*0a6a1f1dSLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17*0a6a1f1dSLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18*0a6a1f1dSLionel Sambuc# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19*0a6a1f1dSLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*0a6a1f1dSLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*0a6a1f1dSLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*0a6a1f1dSLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*0a6a1f1dSLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*0a6a1f1dSLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*0a6a1f1dSLionel Sambuc# POSSIBILITY OF SUCH DAMAGE. 26*0a6a1f1dSLionel Sambuc# 27*0a6a1f1dSLionel Sambuc 28*0a6a1f1dSLionel Sambucnetserver=\ 29*0a6a1f1dSLionel Sambuc"rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif" 30*0a6a1f1dSLionel SambucSOCK_LOCAL=unix://commsock1 31*0a6a1f1dSLionel SambucSOCK_PEER=unix://commsock2 32*0a6a1f1dSLionel SambucSOCK_GW=unix://commsock3 33*0a6a1f1dSLionel SambucBUS=bus1 34*0a6a1f1dSLionel SambucBUS2=bus2 35*0a6a1f1dSLionel Sambuc 36*0a6a1f1dSLionel SambucDEBUG=false 37*0a6a1f1dSLionel Sambuc 38*0a6a1f1dSLionel Sambucsetup_local() 39*0a6a1f1dSLionel Sambuc{ 40*0a6a1f1dSLionel Sambuc 41*0a6a1f1dSLionel Sambuc atf_check -s exit:0 ${netserver} ${SOCK_LOCAL} 42*0a6a1f1dSLionel Sambuc 43*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 44*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 45*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 46*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24 47*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 48*0a6a1f1dSLionel Sambuc 49*0a6a1f1dSLionel Sambuc $DEBUG && rump.ifconfig 50*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 51*0a6a1f1dSLionel Sambuc} 52*0a6a1f1dSLionel Sambuc 53*0a6a1f1dSLionel Sambucsetup_peer() 54*0a6a1f1dSLionel Sambuc{ 55*0a6a1f1dSLionel Sambuc 56*0a6a1f1dSLionel Sambuc atf_check -s exit:0 ${netserver} ${SOCK_PEER} 57*0a6a1f1dSLionel Sambuc 58*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_PEER 59*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 60*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 61*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24 62*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 63*0a6a1f1dSLionel Sambuc 64*0a6a1f1dSLionel Sambuc $DEBUG && rump.ifconfig 65*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 66*0a6a1f1dSLionel Sambuc} 67*0a6a1f1dSLionel Sambuc 68*0a6a1f1dSLionel Sambucsetup_gw() 69*0a6a1f1dSLionel Sambuc{ 70*0a6a1f1dSLionel Sambuc 71*0a6a1f1dSLionel Sambuc atf_check -s exit:0 ${netserver} ${SOCK_GW} 72*0a6a1f1dSLionel Sambuc 73*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_GW 74*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 75*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 76*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24 77*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 78*0a6a1f1dSLionel Sambuc 79*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif1 create 80*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif1 linkstr ${BUS2} 81*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24 82*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24 83*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up 84*0a6a1f1dSLionel Sambuc 85*0a6a1f1dSLionel Sambuc # Wait until DAD completes (10 sec at most) 86*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ifconfig -w 10 87*0a6a1f1dSLionel Sambuc atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative" 88*0a6a1f1dSLionel Sambuc 89*0a6a1f1dSLionel Sambuc $DEBUG && rump.ifconfig 90*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 91*0a6a1f1dSLionel Sambuc} 92*0a6a1f1dSLionel Sambuc 93*0a6a1f1dSLionel Sambucteardown_gw() 94*0a6a1f1dSLionel Sambuc{ 95*0a6a1f1dSLionel Sambuc 96*0a6a1f1dSLionel Sambuc env RUMP_SERVER=$SOCK_GW rump.halt 97*0a6a1f1dSLionel Sambuc} 98*0a6a1f1dSLionel Sambuc 99*0a6a1f1dSLionel Sambuccheck_entry_flags() 100*0a6a1f1dSLionel Sambuc{ 101*0a6a1f1dSLionel Sambuc local ip=$(echo $1 |sed 's/\./\\./g') 102*0a6a1f1dSLionel Sambuc local flags=$2 103*0a6a1f1dSLionel Sambuc 104*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o match:" $flags " -e ignore -x \ 105*0a6a1f1dSLionel Sambuc "rump.netstat -rn -f inet | grep ^'$ip'" 106*0a6a1f1dSLionel Sambuc} 107*0a6a1f1dSLionel Sambuc 108*0a6a1f1dSLionel Sambuccheck_entry_gw() 109*0a6a1f1dSLionel Sambuc{ 110*0a6a1f1dSLionel Sambuc local ip=$(echo $1 |sed 's/\./\\./g') 111*0a6a1f1dSLionel Sambuc local gw=$2 112*0a6a1f1dSLionel Sambuc 113*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o match:" $gw " -e ignore -x \ 114*0a6a1f1dSLionel Sambuc "rump.netstat -rn -f inet | grep ^'$ip'" 115*0a6a1f1dSLionel Sambuc} 116*0a6a1f1dSLionel Sambuc 117*0a6a1f1dSLionel Sambuccheck_entry_fail() 118*0a6a1f1dSLionel Sambuc{ 119*0a6a1f1dSLionel Sambuc ip=$(echo $1 |sed 's/\./\\./g') 120*0a6a1f1dSLionel Sambuc flags=$2 # Not used currently 121*0a6a1f1dSLionel Sambuc 122*0a6a1f1dSLionel Sambuc atf_check -s not-exit:0 -e ignore -x \ 123*0a6a1f1dSLionel Sambuc "rump.netstat -rn -f inet | grep ^'$ip'" 124*0a6a1f1dSLionel Sambuc} 125*0a6a1f1dSLionel Sambuc 126*0a6a1f1dSLionel Sambuctest_lo() 127*0a6a1f1dSLionel Sambuc{ 128*0a6a1f1dSLionel Sambuc 129*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 130*0a6a1f1dSLionel Sambuc 131*0a6a1f1dSLionel Sambuc # Up, Host, local 132*0a6a1f1dSLionel Sambuc check_entry_flags 127.0.0.1 UHl 133*0a6a1f1dSLionel Sambuc} 134*0a6a1f1dSLionel Sambuc 135*0a6a1f1dSLionel Sambuctest_connected() 136*0a6a1f1dSLionel Sambuc{ 137*0a6a1f1dSLionel Sambuc 138*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 139*0a6a1f1dSLionel Sambuc 140*0a6a1f1dSLionel Sambuc # Up, Host, LLINFO, local 141*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0.2 UHLl 142*0a6a1f1dSLionel Sambuc 143*0a6a1f1dSLionel Sambuc # Up, Cloning 144*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0/24 UC 145*0a6a1f1dSLionel Sambuc} 146*0a6a1f1dSLionel Sambuc 147*0a6a1f1dSLionel Sambuctest_cloned() 148*0a6a1f1dSLionel Sambuc{ 149*0a6a1f1dSLionel Sambuc 150*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 151*0a6a1f1dSLionel Sambuc 152*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1 153*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 154*0a6a1f1dSLionel Sambuc 155*0a6a1f1dSLionel Sambuc # Up, Host, LLINFO, cloned 156*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0.1 UHLc 157*0a6a1f1dSLionel Sambuc} 158*0a6a1f1dSLionel Sambuc 159*0a6a1f1dSLionel Sambuctest_default_gateway() 160*0a6a1f1dSLionel Sambuc{ 161*0a6a1f1dSLionel Sambuc 162*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 163*0a6a1f1dSLionel Sambuc 164*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1 165*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 166*0a6a1f1dSLionel Sambuc 167*0a6a1f1dSLionel Sambuc # Up, Gateway, Static 168*0a6a1f1dSLionel Sambuc check_entry_flags default UGS 169*0a6a1f1dSLionel Sambuc} 170*0a6a1f1dSLionel Sambuc 171*0a6a1f1dSLionel Sambuctest_static() 172*0a6a1f1dSLionel Sambuc{ 173*0a6a1f1dSLionel Sambuc 174*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 175*0a6a1f1dSLionel Sambuc 176*0a6a1f1dSLionel Sambuc # Static route to host 177*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add 10.0.1.1 10.0.0.1 178*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 179*0a6a1f1dSLionel Sambuc 180*0a6a1f1dSLionel Sambuc # Up, Gateway, Host, Static 181*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.1.1 UGHS 182*0a6a1f1dSLionel Sambuc 183*0a6a1f1dSLionel Sambuc # Static route to network 184*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.1 185*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 186*0a6a1f1dSLionel Sambuc 187*0a6a1f1dSLionel Sambuc # Up, Gateway, Static 188*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.2/24 UGS 189*0a6a1f1dSLionel Sambuc} 190*0a6a1f1dSLionel Sambuc 191*0a6a1f1dSLionel Sambuctest_route_flush() 192*0a6a1f1dSLionel Sambuc{ 193*0a6a1f1dSLionel Sambuc 194*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 195*0a6a1f1dSLionel Sambuc 196*0a6a1f1dSLionel Sambuc # Reusing other tests to create routes 197*0a6a1f1dSLionel Sambuc test_cloned_route 198*0a6a1f1dSLionel Sambuc test_default_gateway 199*0a6a1f1dSLionel Sambuc test_static_route 200*0a6a1f1dSLionel Sambuc 201*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route flush 202*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 203*0a6a1f1dSLionel Sambuc 204*0a6a1f1dSLionel Sambuc # Should remain 205*0a6a1f1dSLionel Sambuc check_entry_flags 127.0.0.1 UHl 206*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0/24 UC 207*0a6a1f1dSLionel Sambuc 208*0a6a1f1dSLionel Sambuc # Shouldn't remain 209*0a6a1f1dSLionel Sambuc check_entry_fail default UGS 210*0a6a1f1dSLionel Sambuc check_entry_fail 10.0.1.1 UGHS 211*0a6a1f1dSLionel Sambuc check_entry_fail 10.0.2/24 UGS 212*0a6a1f1dSLionel Sambuc # Should it remain? 213*0a6a1f1dSLionel Sambuc check_entry_fail 10.0.0.2 UHLl 214*0a6a1f1dSLionel Sambuc} 215*0a6a1f1dSLionel Sambuc 216*0a6a1f1dSLionel Sambuctest_blackhole() 217*0a6a1f1dSLionel Sambuc{ 218*0a6a1f1dSLionel Sambuc 219*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 220*0a6a1f1dSLionel Sambuc 221*0a6a1f1dSLionel Sambuc # Delete an existing route first 222*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24 223*0a6a1f1dSLionel Sambuc 224*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -blackhole 225*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 226*0a6a1f1dSLionel Sambuc 227*0a6a1f1dSLionel Sambuc # Up, Gateway, Blackhole, Static 228*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0/24 UGBS 229*0a6a1f1dSLionel Sambuc 230*0a6a1f1dSLionel Sambuc atf_check -s not-exit:0 -o ignore -e match:'No route to host' \ 231*0a6a1f1dSLionel Sambuc rump.ping -n -w 1 -c 1 10.0.0.1 232*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 233*0a6a1f1dSLionel Sambuc 234*0a6a1f1dSLionel Sambuc # Shouldn't be created 235*0a6a1f1dSLionel Sambuc check_entry_fail 10.0.0.1 UHLc 236*0a6a1f1dSLionel Sambuc} 237*0a6a1f1dSLionel Sambuc 238*0a6a1f1dSLionel Sambuctest_reject() 239*0a6a1f1dSLionel Sambuc{ 240*0a6a1f1dSLionel Sambuc 241*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 242*0a6a1f1dSLionel Sambuc 243*0a6a1f1dSLionel Sambuc # Delete an existing route first 244*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24 245*0a6a1f1dSLionel Sambuc 246*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -reject 247*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 248*0a6a1f1dSLionel Sambuc 249*0a6a1f1dSLionel Sambuc # Up, Gateway, Reject, Static 250*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0/24 UGRS 251*0a6a1f1dSLionel Sambuc 252*0a6a1f1dSLionel Sambuc atf_check -s not-exit:0 -o ignore -e match:'No route to host' \ 253*0a6a1f1dSLionel Sambuc rump.ping -n -w 1 -c 1 10.0.0.1 254*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 255*0a6a1f1dSLionel Sambuc 256*0a6a1f1dSLionel Sambuc # Shouldn't be created 257*0a6a1f1dSLionel Sambuc check_entry_fail 10.0.0.1 UHLc 258*0a6a1f1dSLionel Sambuc} 259*0a6a1f1dSLionel Sambuc 260*0a6a1f1dSLionel Sambuctest_icmp_redirect() 261*0a6a1f1dSLionel Sambuc{ 262*0a6a1f1dSLionel Sambuc 263*0a6a1f1dSLionel Sambuc ### Testing Dynamic flag ### 264*0a6a1f1dSLionel Sambuc 265*0a6a1f1dSLionel Sambuc # 266*0a6a1f1dSLionel Sambuc # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it. 267*0a6a1f1dSLionel Sambuc # 268*0a6a1f1dSLionel Sambuc setup_gw 269*0a6a1f1dSLionel Sambuc 270*0a6a1f1dSLionel Sambuc # 271*0a6a1f1dSLionel Sambuc # Teach the peer that 10.0.2.* is behind 10.0.0.254 272*0a6a1f1dSLionel Sambuc # 273*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_PEER 274*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254 275*0a6a1f1dSLionel Sambuc # Up, Gateway, Static 276*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.2/24 UGS 277*0a6a1f1dSLionel Sambuc 278*0a6a1f1dSLionel Sambuc # 279*0a6a1f1dSLionel Sambuc # Setup the default gateway to the peer, 10.0.0.1 280*0a6a1f1dSLionel Sambuc # 281*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 282*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1 283*0a6a1f1dSLionel Sambuc # Up, Gateway, Static 284*0a6a1f1dSLionel Sambuc check_entry_flags default UGS 285*0a6a1f1dSLionel Sambuc 286*0a6a1f1dSLionel Sambuc # Try ping 10.0.2.1 287*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1 288*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 289*0a6a1f1dSLionel Sambuc 290*0a6a1f1dSLionel Sambuc # Up, Gateway, Host, Dynamic 291*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.2.1 UGHD 292*0a6a1f1dSLionel Sambuc check_entry_gw 10.0.2.1 10.0.0.254 293*0a6a1f1dSLionel Sambuc 294*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_PEER 295*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 296*0a6a1f1dSLionel Sambuc 297*0a6a1f1dSLionel Sambuc ### Testing Modified flag ### 298*0a6a1f1dSLionel Sambuc 299*0a6a1f1dSLionel Sambuc # 300*0a6a1f1dSLionel Sambuc # Teach a wrong route to 10.0.2.2 301*0a6a1f1dSLionel Sambuc # 302*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 303*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1 304*0a6a1f1dSLionel Sambuc # Up, Gateway, Host, Static 305*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.2.2 UGHS 306*0a6a1f1dSLionel Sambuc check_entry_gw 10.0.2.2 10.0.0.1 307*0a6a1f1dSLionel Sambuc 308*0a6a1f1dSLionel Sambuc # Try ping 10.0.2.2 309*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2 310*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 311*0a6a1f1dSLionel Sambuc 312*0a6a1f1dSLionel Sambuc # Up, Gateway, Host, Modified, Static 313*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.2.2 UGHMS 314*0a6a1f1dSLionel Sambuc check_entry_gw 10.0.2.2 10.0.0.254 315*0a6a1f1dSLionel Sambuc 316*0a6a1f1dSLionel Sambuc teardown_gw 317*0a6a1f1dSLionel Sambuc} 318*0a6a1f1dSLionel Sambuc 319*0a6a1f1dSLionel Sambuctest_announce() 320*0a6a1f1dSLionel Sambuc{ 321*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 322*0a6a1f1dSLionel Sambuc 323*0a6a1f1dSLionel Sambuc # Delete an existing route first 324*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24 325*0a6a1f1dSLionel Sambuc 326*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -proxy 327*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 328*0a6a1f1dSLionel Sambuc 329*0a6a1f1dSLionel Sambuc # Up, Gateway, Static, proxy 330*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0/24 UGSp 331*0a6a1f1dSLionel Sambuc 332*0a6a1f1dSLionel Sambuc # TODO test its behavior 333*0a6a1f1dSLionel Sambuc} 334*0a6a1f1dSLionel Sambuc 335*0a6a1f1dSLionel Sambuctest_xresolve_rtm() 336*0a6a1f1dSLionel Sambuc{ 337*0a6a1f1dSLionel Sambuc local ip=$1 338*0a6a1f1dSLionel Sambuc local rtm=$2 339*0a6a1f1dSLionel Sambuc local pid= 340*0a6a1f1dSLionel Sambuc 341*0a6a1f1dSLionel Sambuc rump.route -n monitor > ./mon.log & 342*0a6a1f1dSLionel Sambuc pid=$! 343*0a6a1f1dSLionel Sambuc 344*0a6a1f1dSLionel Sambuc # Give route monitor a chance to setup a routing socket 345*0a6a1f1dSLionel Sambuc sleep 1 346*0a6a1f1dSLionel Sambuc 347*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $ip 348*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 349*0a6a1f1dSLionel Sambuc 350*0a6a1f1dSLionel Sambuc # Give route monitor a chance to output a routing message 351*0a6a1f1dSLionel Sambuc sleep 1 352*0a6a1f1dSLionel Sambuc cat ./mon.log 353*0a6a1f1dSLionel Sambuc 354*0a6a1f1dSLionel Sambuc atf_check -s exit:0 grep -q $rtm ./mon.log 355*0a6a1f1dSLionel Sambuc 356*0a6a1f1dSLionel Sambuc kill $pid 357*0a6a1f1dSLionel Sambuc} 358*0a6a1f1dSLionel Sambuc 359*0a6a1f1dSLionel Sambuctest_xresolve() 360*0a6a1f1dSLionel Sambuc{ 361*0a6a1f1dSLionel Sambuc 362*0a6a1f1dSLionel Sambuc export RUMP_SERVER=$SOCK_LOCAL 363*0a6a1f1dSLionel Sambuc 364*0a6a1f1dSLionel Sambuc # For a normal route, a RTM_ADD message is emitted on a route cloning 365*0a6a1f1dSLionel Sambuc test_xresolve_rtm 10.0.0.1 RTM_ADD 366*0a6a1f1dSLionel Sambuc # Up, Host, LLINFO, cloned 367*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0.1 UHLc 368*0a6a1f1dSLionel Sambuc 369*0a6a1f1dSLionel Sambuc # Delete an existing route first 370*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24 371*0a6a1f1dSLionel Sambuc # Create a connected route with XRESOLVE flag for the interface 372*0a6a1f1dSLionel Sambuc atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.2 \ 373*0a6a1f1dSLionel Sambuc -interface -xresolve 374*0a6a1f1dSLionel Sambuc $DEBUG && rump.netstat -rn -f inet 375*0a6a1f1dSLionel Sambuc 376*0a6a1f1dSLionel Sambuc # Up, Cloning, Xresolve, Static 377*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0/24 UCXS 378*0a6a1f1dSLionel Sambuc 379*0a6a1f1dSLionel Sambuc # If XRESOLVE flag is set, a RTM_RESOLVE message is emitted 380*0a6a1f1dSLionel Sambuc test_xresolve_rtm 10.0.0.1 RTM_RESOLVE 381*0a6a1f1dSLionel Sambuc # Up, Host, Xresolve, LLINFO, cloned 382*0a6a1f1dSLionel Sambuc check_entry_flags 10.0.0.1 UHXLc 383*0a6a1f1dSLionel Sambuc} 384*0a6a1f1dSLionel Sambuc 385*0a6a1f1dSLionel Sambuccleanup() 386*0a6a1f1dSLionel Sambuc{ 387*0a6a1f1dSLionel Sambuc $DEBUG && /usr/bin/shmif_dumpbus -p - $BUS 2>/dev/null | \ 388*0a6a1f1dSLionel Sambuc /usr/sbin/tcpdump -n -e -r - 389*0a6a1f1dSLionel Sambuc env RUMP_SERVER=$SOCK_LOCAL rump.halt 390*0a6a1f1dSLionel Sambuc env RUMP_SERVER=$SOCK_PEER rump.halt 391*0a6a1f1dSLionel Sambuc} 392*0a6a1f1dSLionel Sambuc 393*0a6a1f1dSLionel Sambucadd_test() 394*0a6a1f1dSLionel Sambuc{ 395*0a6a1f1dSLionel Sambuc local name=$1 396*0a6a1f1dSLionel Sambuc local desc="$2" 397*0a6a1f1dSLionel Sambuc 398*0a6a1f1dSLionel Sambuc atf_test_case "route_flags_${name}" cleanup 399*0a6a1f1dSLionel Sambuc eval "route_flags_${name}_head() { \ 400*0a6a1f1dSLionel Sambuc atf_set \"descr\" \"${desc}\"; \ 401*0a6a1f1dSLionel Sambuc atf_set \"require.progs\" \"rump_server\"; \ 402*0a6a1f1dSLionel Sambuc }; \ 403*0a6a1f1dSLionel Sambuc route_flags_${name}_body() { \ 404*0a6a1f1dSLionel Sambuc setup_local; \ 405*0a6a1f1dSLionel Sambuc setup_peer; \ 406*0a6a1f1dSLionel Sambuc test_${name}; \ 407*0a6a1f1dSLionel Sambuc }; \ 408*0a6a1f1dSLionel Sambuc route_flags_${name}_cleanup() { \ 409*0a6a1f1dSLionel Sambuc cleanup; \ 410*0a6a1f1dSLionel Sambuc }" 411*0a6a1f1dSLionel Sambuc atf_add_test_case "route_flags_${name}" 412*0a6a1f1dSLionel Sambuc} 413*0a6a1f1dSLionel Sambuc 414*0a6a1f1dSLionel Sambucatf_init_test_cases() 415*0a6a1f1dSLionel Sambuc{ 416*0a6a1f1dSLionel Sambuc 417*0a6a1f1dSLionel Sambuc add_test lo "Tests route flags: loop back interface" 418*0a6a1f1dSLionel Sambuc add_test connected "Tests route flags: connected route" 419*0a6a1f1dSLionel Sambuc add_test cloned "Tests route flags: cloned route" 420*0a6a1f1dSLionel Sambuc add_test default_gateway "Tests route flags: default gateway" 421*0a6a1f1dSLionel Sambuc add_test static "Tests route flags: static route" 422*0a6a1f1dSLionel Sambuc add_test blackhole "Tests route flags: blackhole route" 423*0a6a1f1dSLionel Sambuc add_test reject "Tests route flags: reject route" 424*0a6a1f1dSLionel Sambuc add_test icmp_redirect "Tests route flags: icmp redirect" 425*0a6a1f1dSLionel Sambuc add_test announce "Tests route flags: announce flag" 426*0a6a1f1dSLionel Sambuc add_test xresolve "Tests route flags: xresolve flag" 427*0a6a1f1dSLionel Sambuc} 428