1313680Sngie# $NetBSD: t_change.sh,v 1.9 2016/11/07 05:25:37 ozaki-r Exp $ 2272343Sngie# 3272343Sngie# Copyright (c) 2011 The NetBSD Foundation, Inc. 4272343Sngie# All rights reserved. 5272343Sngie# 6272343Sngie# Redistribution and use in source and binary forms, with or without 7272343Sngie# modification, are permitted provided that the following conditions 8272343Sngie# are met: 9272343Sngie# 1. Redistributions of source code must retain the above copyright 10272343Sngie# notice, this list of conditions and the following disclaimer. 11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright 12272343Sngie# notice, this list of conditions and the following disclaimer in the 13272343Sngie# documentation and/or other materials provided with the distribution. 14272343Sngie# 15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18272343Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25272343Sngie# POSSIBILITY OF SUCH DAMAGE. 26272343Sngie# 27272343Sngie 28272343Sngienetserver=\ 29309466Sngie"rump_server -lrumpdev -lrumpnet -lrumpnet_net \ 30309466Sngie -lrumpnet_netinet -lrumpnet_shmif" 31272343Sngieexport RUMP_SERVER=unix://commsock 32272343Sngie 33313680SngieDEBUG=${DEBUG:-false} 34309466Sngie 35309466Sngieatf_test_case route_change_reject2blackhole cleanup 36309466Sngieroute_change_reject2blackhole_head() 37272343Sngie{ 38272343Sngie 39272343Sngie atf_set "descr" "Change a reject route to blackhole" 40272343Sngie atf_set "require.progs" "rump_server" 41272343Sngie} 42272343Sngie 43309466Sngieroute_change_reject2blackhole_body() 44272343Sngie{ 45272343Sngie 46272343Sngie atf_check -s exit:0 ${netserver} ${RUMP_SERVER} 47272343Sngie 48272343Sngie atf_check -s exit:0 -o ignore \ 49272343Sngie rump.route add 207.46.197.32 127.0.0.1 -reject 50272343Sngie atf_check -s exit:0 -o match:UGHR -x \ 51272343Sngie "rump.route -n show -inet | grep ^207.46" 52272343Sngie atf_check -s exit:0 -o ignore \ 53272343Sngie rump.route change 207.46.197.32 127.0.0.1 -blackhole 54272343Sngie atf_check -s exit:0 -o match:' UGHBS ' -e ignore -x \ 55309466Sngie "rump.netstat -rn -f inet | grep ^207.46" 56272343Sngie} 57272343Sngie 58309466Sngieroute_change_reject2blackhole_cleanup() 59272343Sngie{ 60272343Sngie 61272343Sngie env RUMP_SERVER=unix://commsock rump.halt 62272343Sngie} 63272343Sngie 64309466Sngieatf_test_case route_change_gateway cleanup 65309466Sngieroute_change_gateway_head() 66309466Sngie{ 67309466Sngie 68309466Sngie atf_set "descr" "Change the gateway of a route" 69309466Sngie atf_set "require.progs" "rump_server" 70309466Sngie} 71309466Sngie 72309466Sngieroute_change_gateway_body() 73309466Sngie{ 74309466Sngie 75309466Sngie atf_check -s exit:0 ${netserver} ${RUMP_SERVER} 76309466Sngie 77309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 78309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus 79309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up 80309466Sngie 81309466Sngie atf_check -s exit:0 -o ignore \ 82309466Sngie rump.route add -net 192.168.0.0/24 10.0.0.1 83309466Sngie atf_check -s exit:0 -o match:'10.0.0.1' -x \ 84309466Sngie "rump.route -n show -inet | grep ^192.168" 85309466Sngie atf_check -s exit:0 -o ignore \ 86309466Sngie rump.route change -net 192.168.0.0/24 10.0.0.254 87309466Sngie atf_check -s exit:0 -o match:'10.0.0.254' -x \ 88309466Sngie "rump.route -n show -inet | grep ^192.168" 89309466Sngie} 90309466Sngie 91309466Sngieroute_change_gateway_cleanup() 92309466Sngie{ 93309466Sngie 94309466Sngie env RUMP_SERVER=unix://commsock rump.halt 95309466Sngie} 96309466Sngie 97309466Sngieatf_test_case route_change_ifa cleanup 98309466Sngieroute_change_ifa_head() 99309466Sngie{ 100309466Sngie 101309466Sngie atf_set "descr" "Change the ifa (local address) of a route" 102309466Sngie atf_set "require.progs" "rump_server" 103309466Sngie} 104309466Sngie 105309466Sngieroute_change_ifa_body() 106309466Sngie{ 107309466Sngie 108309466Sngie atf_check -s exit:0 ${netserver} ${RUMP_SERVER} 109309466Sngie 110309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 111309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus 112309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 113309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 alias 10.0.0.11/24 114309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 115309466Sngie 116309466Sngie atf_check -s exit:0 -o ignore \ 117309466Sngie rump.route add -net 192.168.0.0/24 10.0.0.1 118309466Sngie atf_check -s exit:0 -o match:'10.0.0.1' -x \ 119309466Sngie "rump.route -n show -inet | grep ^192.168" 120309466Sngie $DEBUG && rump.route -n show -inet 121309466Sngie cat >./expect <<-EOF 122309466Sngie route to: 192.168.0.1 123309466Sngiedestination: 192.168.0.0 124309466Sngie mask: 255.255.255.0 125309466Sngie gateway: 10.0.0.1 126309466Sngie local addr: 10.0.0.10 127309466Sngie interface: shmif0 128309466Sngie flags: <UP,GATEWAY,DONE,STATIC> 129309466Sngie recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 130309466Sngie EOF 131309466Sngie rump.route -n get 192.168.0.1 > ./output 132309466Sngie $DEBUG && cat ./expect ./output 133309466Sngie sed -i '$d' ./output 134309466Sngie atf_check -s exit:0 diff ./expect ./output 135309466Sngie 136309466Sngie # Change the local address of the route 137309466Sngie atf_check -s exit:0 -o ignore \ 138309466Sngie rump.route change -net 192.168.0.0/24 10.0.0.1 -ifa 10.0.0.11 139309466Sngie $DEBUG && rump.route -n show -inet 140309466Sngie cat >./expect <<-EOF 141309466Sngie route to: 192.168.0.1 142309466Sngiedestination: 192.168.0.0 143309466Sngie mask: 255.255.255.0 144309466Sngie gateway: 10.0.0.1 145309466Sngie local addr: 10.0.0.11 146309466Sngie interface: shmif0 147309466Sngie flags: <UP,GATEWAY,DONE,STATIC> 148309466Sngie recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 149309466Sngie EOF 150309466Sngie rump.route -n get 192.168.0.1 > ./output 151309466Sngie $DEBUG && cat ./expect ./output 152309466Sngie sed -i '$d' ./output 153309466Sngie atf_check -s exit:0 diff ./expect ./output 154309466Sngie} 155309466Sngie 156309466Sngieroute_change_ifa_cleanup() 157309466Sngie{ 158309466Sngie 159309466Sngie env RUMP_SERVER=unix://commsock rump.halt 160309466Sngie} 161309466Sngie 162309466Sngieatf_test_case route_change_ifp cleanup 163309466Sngieroute_change_ifp_head() 164309466Sngie{ 165309466Sngie 166309466Sngie atf_set "descr" "Change a route based on an interface (ifp)" 167309466Sngie atf_set "require.progs" "rump_server" 168309466Sngie} 169309466Sngie 170309466Sngieroute_change_ifp_body() 171309466Sngie{ 172309466Sngie 173309466Sngie atf_check -s exit:0 ${netserver} ${RUMP_SERVER} 174309466Sngie 175309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 176309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus 177309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up 178309466Sngie 179309466Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 180309466Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus 181309466Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up 182309466Sngie 183309466Sngie atf_check -s exit:0 -o ignore \ 184309466Sngie rump.route add -net 192.168.0.0/24 10.0.0.1 185309466Sngie atf_check -s exit:0 -o match:'10.0.0.1' -x \ 186309466Sngie "rump.route -n show -inet | grep ^192.168" 187309466Sngie $DEBUG && rump.route -n show -inet 188309466Sngie cat >./expect <<-EOF 189309466Sngie route to: 192.168.0.1 190309466Sngiedestination: 192.168.0.0 191309466Sngie mask: 255.255.255.0 192309466Sngie gateway: 10.0.0.1 193309466Sngie local addr: 10.0.0.10 194309466Sngie interface: shmif0 195309466Sngie flags: <UP,GATEWAY,DONE,STATIC> 196309466Sngie recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 197309466Sngie EOF 198309466Sngie rump.route -n get 192.168.0.1 > ./output 199309466Sngie $DEBUG && cat ./expect ./output 200309466Sngie sed -i '$d' ./output 201309466Sngie atf_check -s exit:0 diff ./expect ./output 202309466Sngie 203309466Sngie # Change a route based on an interface 204309466Sngie atf_check -s exit:0 -o ignore \ 205309466Sngie rump.route change -net 192.168.0.0/24 10.0.0.1 -ifp shmif1 206309466Sngie $DEBUG && rump.route -n show -inet 207309466Sngie cat >./expect <<-EOF 208309466Sngie route to: 192.168.0.1 209309466Sngiedestination: 192.168.0.0 210309466Sngie mask: 255.255.255.0 211309466Sngie gateway: 10.0.0.1 212309466Sngie local addr: 10.0.0.11 213309466Sngie interface: shmif1 214309466Sngie flags: <UP,GATEWAY,DONE,STATIC> 215309466Sngie recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 216309466Sngie EOF 217309466Sngie rump.route -n get 192.168.0.1 > ./output 218309466Sngie $DEBUG && cat ./expect ./output 219309466Sngie sed -i '$d' ./output 220309466Sngie atf_check -s exit:0 diff ./expect ./output 221309466Sngie} 222309466Sngie 223309466Sngieroute_change_ifp_cleanup() 224309466Sngie{ 225309466Sngie 226309466Sngie env RUMP_SERVER=unix://commsock rump.halt 227309466Sngie} 228309466Sngie 229309466Sngieatf_test_case route_change_ifp_ifa cleanup 230309466Sngieroute_change_ifp_head() 231309466Sngie{ 232309466Sngie 233309466Sngie atf_set "descr" "Change a route with -ifp and -ifa" 234309466Sngie atf_set "require.progs" "rump_server" 235309466Sngie} 236309466Sngie 237309466Sngieroute_change_ifp_ifa_body() 238309466Sngie{ 239309466Sngie 240309466Sngie atf_check -s exit:0 ${netserver} ${RUMP_SERVER} 241309466Sngie 242309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 243309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus 244309466Sngie atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up 245309466Sngie 246309466Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 247309466Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus 248309466Sngie atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up 249309466Sngie 250309466Sngie atf_check -s exit:0 -o ignore \ 251309466Sngie rump.route add -net 192.168.0.0/24 10.0.0.1 252309466Sngie atf_check -s exit:0 -o match:'10.0.0.1' -x \ 253309466Sngie "rump.route -n show -inet | grep ^192.168" 254309466Sngie $DEBUG && rump.route -n show -inet 255309466Sngie cat >./expect <<-EOF 256309466Sngie route to: 192.168.0.1 257309466Sngiedestination: 192.168.0.0 258309466Sngie mask: 255.255.255.0 259309466Sngie gateway: 10.0.0.1 260309466Sngie local addr: 10.0.0.10 261309466Sngie interface: shmif0 262309466Sngie flags: <UP,GATEWAY,DONE,STATIC> 263309466Sngie recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 264309466Sngie EOF 265309466Sngie rump.route -n get 192.168.0.1 > ./output 266309466Sngie $DEBUG && cat ./expect ./output 267309466Sngie sed -i '$d' ./output 268309466Sngie atf_check -s exit:0 diff ./expect ./output 269309466Sngie 270309466Sngie # Change a route with -ifa and -ifp 271309466Sngie atf_check -s exit:0 -o ignore \ 272309466Sngie rump.route change -net 192.168.0.0/24 -ifa 10.0.0.1 -ifp shmif1 273309466Sngie $DEBUG && rump.route -n show -inet 274309466Sngie cat >./expect <<-EOF 275309466Sngie route to: 192.168.0.1 276309466Sngiedestination: 192.168.0.0 277309466Sngie mask: 255.255.255.0 278309466Sngie gateway: 10.0.0.1 279309466Sngie local addr: 10.0.0.11 280309466Sngie interface: shmif1 281309466Sngie flags: <UP,GATEWAY,DONE,STATIC> 282309466Sngie recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 283309466Sngie EOF 284309466Sngie rump.route -n get 192.168.0.1 > ./output 285309466Sngie $DEBUG && cat ./expect ./output 286309466Sngie sed -i '$d' ./output 287309466Sngie atf_check -s exit:0 diff ./expect ./output 288309466Sngie} 289309466Sngie 290309466Sngieroute_change_ifp_ifa_cleanup() 291309466Sngie{ 292309466Sngie 293309466Sngie env RUMP_SERVER=unix://commsock rump.halt 294309466Sngie} 295309466Sngie 296272343Sngieatf_init_test_cases() 297272343Sngie{ 298272343Sngie 299309466Sngie atf_add_test_case route_change_reject2blackhole 300309466Sngie atf_add_test_case route_change_gateway 301309466Sngie atf_add_test_case route_change_ifa 302309466Sngie atf_add_test_case route_change_ifp 303309466Sngie atf_add_test_case route_change_ifp_ifa 304272343Sngie} 305