Home | History | Annotate | Line # | Download | only in route
t_change.sh revision 1.7
      1 #	$NetBSD: t_change.sh,v 1.7 2016/07/21 02:02:30 ozaki-r Exp $
      2 #
      3 # Copyright (c) 2011 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 netserver=\
     29 "rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
     30 export RUMP_SERVER=unix://commsock
     31 
     32 DEBUG=false
     33 
     34 atf_test_case route_change_reject2blackhole cleanup
     35 route_change_reject2blackhole_head()
     36 {
     37 
     38 	atf_set "descr" "Change a reject route to blackhole"
     39 	atf_set "require.progs" "rump_server"
     40 }
     41 
     42 route_change_reject2blackhole_body()
     43 {
     44 
     45 	atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
     46 
     47 	atf_check -s exit:0 -o ignore \
     48 	    rump.route add 207.46.197.32 127.0.0.1 -reject
     49 	atf_check -s exit:0 -o match:UGHR -x \
     50 	    "rump.route -n show -inet | grep ^207.46"
     51 	atf_check -s exit:0 -o ignore \
     52 	    rump.route change 207.46.197.32 127.0.0.1 -blackhole
     53 	atf_check -s exit:0 -o match:' UGHBS ' -e ignore -x \
     54 	    "rump.netstat -rn -f inet | grep ^207.46"
     55 }
     56 
     57 route_change_reject2blackhole_cleanup()
     58 {
     59 
     60 	env RUMP_SERVER=unix://commsock rump.halt
     61 }
     62 
     63 atf_test_case route_change_gateway cleanup
     64 route_change_gateway_head()
     65 {
     66 
     67 	atf_set "descr" "Change the gateway of a route"
     68 	atf_set "require.progs" "rump_server"
     69 }
     70 
     71 route_change_gateway_body()
     72 {
     73 
     74 	atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
     75 
     76 	atf_check -s exit:0 rump.ifconfig shmif0 create
     77 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
     78 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
     79 
     80 	atf_check -s exit:0 -o ignore \
     81 	    rump.route add -net 192.168.0.0/24 10.0.0.1
     82 	atf_check -s exit:0 -o match:'10.0.0.1' -x \
     83 	    "rump.route -n show -inet | grep ^192.168"
     84 	atf_check -s exit:0 -o ignore \
     85 	    rump.route change -net 192.168.0.0/24 10.0.0.254
     86 	atf_check -s exit:0 -o match:'10.0.0.254' -x \
     87 	    "rump.route -n show -inet | grep ^192.168"
     88 }
     89 
     90 route_change_gateway_cleanup()
     91 {
     92 
     93 	env RUMP_SERVER=unix://commsock rump.halt
     94 }
     95 
     96 atf_test_case route_change_ifa cleanup
     97 route_change_ifa_head()
     98 {
     99 
    100 	atf_set "descr" "Change the ifa (local address) of a route"
    101 	atf_set "require.progs" "rump_server"
    102 }
    103 
    104 route_change_ifa_body()
    105 {
    106 
    107 	atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
    108 
    109 	atf_check -s exit:0 rump.ifconfig shmif0 create
    110 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
    111 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24
    112 	atf_check -s exit:0 rump.ifconfig shmif0 alias 10.0.0.11/24
    113 	atf_check -s exit:0 rump.ifconfig shmif0 up
    114 
    115 	atf_check -s exit:0 -o ignore \
    116 	    rump.route add -net 192.168.0.0/24 10.0.0.1
    117 	atf_check -s exit:0 -o match:'10.0.0.1' -x \
    118 	    "rump.route -n show -inet | grep ^192.168"
    119 	$DEBUG && rump.route -n show -inet
    120 	cat >./expect <<-EOF
    121    route to: 192.168.0.1
    122 destination: 192.168.0.0
    123        mask: 255.255.255.0
    124     gateway: 10.0.0.1
    125  local addr: 10.0.0.10
    126   interface: shmif0
    127       flags: <UP,GATEWAY,DONE,STATIC>
    128  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
    129 	EOF
    130 	rump.route -n get 192.168.0.1 > ./output
    131 	$DEBUG && cat ./expect ./output
    132 	sed -i '$d' ./output
    133 	atf_check -s exit:0 diff ./expect ./output
    134 
    135 	# Change the local address of the route
    136 	atf_check -s exit:0 -o ignore \
    137 	    rump.route change -net 192.168.0.0/24 10.0.0.1 -ifa 10.0.0.11
    138 	$DEBUG && rump.route -n show -inet
    139 	cat >./expect <<-EOF
    140    route to: 192.168.0.1
    141 destination: 192.168.0.0
    142        mask: 255.255.255.0
    143     gateway: 10.0.0.1
    144  local addr: 10.0.0.11
    145   interface: shmif0
    146       flags: <UP,GATEWAY,DONE,STATIC>
    147  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
    148 	EOF
    149 	rump.route -n get 192.168.0.1 > ./output
    150 	$DEBUG && cat ./expect ./output
    151 	sed -i '$d' ./output
    152 	atf_check -s exit:0 diff ./expect ./output
    153 }
    154 
    155 route_change_ifa_cleanup()
    156 {
    157 
    158 	env RUMP_SERVER=unix://commsock rump.halt
    159 }
    160 
    161 atf_test_case route_change_ifp cleanup
    162 route_change_ifp_head()
    163 {
    164 
    165 	atf_set "descr" "Change a route based on an interface (ifp)"
    166 	atf_set "require.progs" "rump_server"
    167 }
    168 
    169 route_change_ifp_body()
    170 {
    171 
    172 	atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
    173 
    174 	atf_check -s exit:0 rump.ifconfig shmif0 create
    175 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
    176 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
    177 
    178 	atf_check -s exit:0 rump.ifconfig shmif1 create
    179 	atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus
    180 	atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up
    181 
    182 	atf_check -s exit:0 -o ignore \
    183 	    rump.route add -net 192.168.0.0/24 10.0.0.1
    184 	atf_check -s exit:0 -o match:'10.0.0.1' -x \
    185 	    "rump.route -n show -inet | grep ^192.168"
    186 	$DEBUG && rump.route -n show -inet
    187 	cat >./expect <<-EOF
    188    route to: 192.168.0.1
    189 destination: 192.168.0.0
    190        mask: 255.255.255.0
    191     gateway: 10.0.0.1
    192  local addr: 10.0.0.10
    193   interface: shmif0
    194       flags: <UP,GATEWAY,DONE,STATIC>
    195  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
    196 	EOF
    197 	rump.route -n get 192.168.0.1 > ./output
    198 	$DEBUG && cat ./expect ./output
    199 	sed -i '$d' ./output
    200 	atf_check -s exit:0 diff ./expect ./output
    201 
    202 	# Change a route based on an interface
    203 	atf_check -s exit:0 -o ignore \
    204 	    rump.route change -net 192.168.0.0/24 10.0.0.1 -ifp shmif1
    205 	$DEBUG && rump.route -n show -inet
    206 	cat >./expect <<-EOF
    207    route to: 192.168.0.1
    208 destination: 192.168.0.0
    209        mask: 255.255.255.0
    210     gateway: 10.0.0.1
    211  local addr: 10.0.0.11
    212   interface: shmif1
    213       flags: <UP,GATEWAY,DONE,STATIC>
    214  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
    215 	EOF
    216 	rump.route -n get 192.168.0.1 > ./output
    217 	$DEBUG && cat ./expect ./output
    218 	sed -i '$d' ./output
    219 	atf_check -s exit:0 diff ./expect ./output
    220 }
    221 
    222 route_change_ifp_cleanup()
    223 {
    224 
    225 	env RUMP_SERVER=unix://commsock rump.halt
    226 }
    227 
    228 atf_test_case route_change_ifp_ifa cleanup
    229 route_change_ifp_head()
    230 {
    231 
    232 	atf_set "descr" "Change a route with -ifp and -ifa"
    233 	atf_set "require.progs" "rump_server"
    234 }
    235 
    236 route_change_ifp_ifa_body()
    237 {
    238 
    239 	atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
    240 
    241 	atf_check -s exit:0 rump.ifconfig shmif0 create
    242 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
    243 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
    244 
    245 	atf_check -s exit:0 rump.ifconfig shmif1 create
    246 	atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus
    247 	atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up
    248 
    249 	atf_check -s exit:0 -o ignore \
    250 	    rump.route add -net 192.168.0.0/24 10.0.0.1
    251 	atf_check -s exit:0 -o match:'10.0.0.1' -x \
    252 	    "rump.route -n show -inet | grep ^192.168"
    253 	$DEBUG && rump.route -n show -inet
    254 	cat >./expect <<-EOF
    255    route to: 192.168.0.1
    256 destination: 192.168.0.0
    257        mask: 255.255.255.0
    258     gateway: 10.0.0.1
    259  local addr: 10.0.0.10
    260   interface: shmif0
    261       flags: <UP,GATEWAY,DONE,STATIC>
    262  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
    263 	EOF
    264 	rump.route -n get 192.168.0.1 > ./output
    265 	$DEBUG && cat ./expect ./output
    266 	sed -i '$d' ./output
    267 	atf_check -s exit:0 diff ./expect ./output
    268 
    269 	# Change a route with -ifa and -ifp
    270 	atf_check -s exit:0 -o ignore \
    271 	    rump.route change -net 192.168.0.0/24 -ifa 10.0.0.1 -ifp shmif1
    272 	$DEBUG && rump.route -n show -inet
    273 	cat >./expect <<-EOF
    274    route to: 192.168.0.1
    275 destination: 192.168.0.0
    276        mask: 255.255.255.0
    277     gateway: 10.0.0.1
    278  local addr: 10.0.0.11
    279   interface: shmif1
    280       flags: <UP,GATEWAY,DONE,STATIC>
    281  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
    282 	EOF
    283 	rump.route -n get 192.168.0.1 > ./output
    284 	$DEBUG && cat ./expect ./output
    285 	sed -i '$d' ./output
    286 	atf_check -s exit:0 diff ./expect ./output
    287 }
    288 
    289 route_change_ifp_ifa_cleanup()
    290 {
    291 
    292 	env RUMP_SERVER=unix://commsock rump.halt
    293 }
    294 
    295 atf_init_test_cases()
    296 {
    297 
    298 	atf_add_test_case route_change_reject2blackhole
    299 	atf_add_test_case route_change_gateway
    300 	atf_add_test_case route_change_ifa
    301 	atf_add_test_case route_change_ifp
    302 	atf_add_test_case route_change_ifp_ifa
    303 }
    304