Home | History | Annotate | Line # | Download | only in route
      1 #	$NetBSD: t_flags.sh,v 1.20 2017/08/03 03:16:27 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 SOCK_LOCAL=unix://commsock1
     29 SOCK_PEER=unix://commsock2
     30 SOCK_GW=unix://commsock3
     31 BUS=bus1
     32 BUS2=bus2
     33 
     34 DEBUG=${DEBUG:-false}
     35 
     36 setup_local()
     37 {
     38 
     39 	rump_server_start $SOCK_LOCAL
     40 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
     41 
     42 	export RUMP_SERVER=$SOCK_LOCAL
     43 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24
     44 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
     45 	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
     46 
     47 	$DEBUG && rump.ifconfig
     48 	$DEBUG && rump.netstat -rn -f inet
     49 }
     50 
     51 setup_peer()
     52 {
     53 
     54 	rump_server_start $SOCK_PEER
     55 	rump_server_add_iface $SOCK_PEER shmif0 $BUS
     56 
     57 	export RUMP_SERVER=$SOCK_PEER
     58 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24
     59 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
     60 	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
     61 
     62 	$DEBUG && rump.ifconfig
     63 	$DEBUG && rump.netstat -rn -f inet
     64 }
     65 
     66 setup_gw()
     67 {
     68 
     69 	rump_server_start $SOCK_GW
     70 	rump_server_add_iface $SOCK_GW shmif0 $BUS
     71 	rump_server_add_iface $SOCK_GW shmif1 $BUS2
     72 
     73 	export RUMP_SERVER=$SOCK_GW
     74 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24
     75 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
     76 
     77 	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24
     78 	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24
     79 	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up
     80 
     81 	# Wait until DAD completes (10 sec at most)
     82 	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
     83 	atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative"
     84 
     85 	$DEBUG && rump.ifconfig
     86 	$DEBUG && rump.netstat -rn -f inet
     87 }
     88 
     89 test_lo()
     90 {
     91 
     92 	export RUMP_SERVER=$SOCK_LOCAL
     93 
     94 	# Up, Host, local
     95 	check_route_flags 127.0.0.1 UHl
     96 }
     97 
     98 test_connected()
     99 {
    100 
    101 	export RUMP_SERVER=$SOCK_LOCAL
    102 
    103 	# Up, Host, local
    104 	check_route_flags 10.0.0.2 UHl
    105 
    106 	# Up, Cloning
    107 	check_route_flags 10.0.0/24 UC
    108 }
    109 
    110 test_default_gateway()
    111 {
    112 
    113 	export RUMP_SERVER=$SOCK_LOCAL
    114 
    115 	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
    116 	$DEBUG && rump.netstat -rn -f inet
    117 
    118 	# Up, Gateway, Static
    119 	check_route_flags default UGS
    120 }
    121 
    122 test_static()
    123 {
    124 
    125 	export RUMP_SERVER=$SOCK_LOCAL
    126 
    127 	# Static route to host
    128 	atf_check -s exit:0 -o ignore rump.route add 10.0.1.1 10.0.0.1
    129 	$DEBUG && rump.netstat -rn -f inet
    130 
    131 	# Up, Gateway, Host, Static
    132 	check_route_flags 10.0.1.1 UGHS
    133 
    134 	# Static route to network
    135 	atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.1
    136 	$DEBUG && rump.netstat -rn -f inet
    137 
    138 	# Up, Gateway, Static
    139 	check_route_flags 10.0.2/24 UGS
    140 }
    141 
    142 test_blackhole()
    143 {
    144 
    145 	export RUMP_SERVER=$SOCK_LOCAL
    146 
    147 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
    148 
    149 	# Delete an existing route first
    150 	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
    151 	# Should be removed too
    152 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
    153 
    154 	# Gateway must be lo0
    155 	atf_check -s exit:0 -o ignore \
    156 	    rump.route add -net 10.0.0.0/24 127.0.0.1 -blackhole
    157 	$DEBUG && rump.netstat -rn -f inet
    158 
    159 	# Up, Gateway, Blackhole, Static
    160 	check_route_flags 10.0.0/24 UGBS
    161 
    162 	atf_check -s not-exit:0 -o match:'100.0% packet loss' \
    163 	    rump.ping -n -w 1 -c 1 10.0.0.1
    164 	$DEBUG && rump.netstat -rn -f inet
    165 
    166 	# Shouldn't be created
    167 	check_route_no_entry 10.0.0.1
    168 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
    169 }
    170 
    171 test_reject()
    172 {
    173 
    174 	export RUMP_SERVER=$SOCK_LOCAL
    175 
    176 	# Delete an existing route first
    177 	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
    178 
    179 	atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -reject
    180 	$DEBUG && rump.netstat -rn -f inet
    181 
    182 	# Up, Gateway, Reject, Static
    183 	check_route_flags 10.0.0/24 UGRS
    184 
    185 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    186 	    rump.ping -n -w 1 -c 1 10.0.0.1
    187 	$DEBUG && rump.netstat -rn -f inet
    188 
    189 	# Shouldn't be created
    190 	check_route_no_entry 10.0.0.1
    191 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
    192 
    193 	# Gateway is lo0 (RTF_GATEWAY)
    194 
    195 	# Delete an existing route first
    196 	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
    197 
    198 	atf_check -s exit:0 -o ignore \
    199 	    rump.route add -net 10.0.0.0/24 127.0.0.1 -reject
    200 	$DEBUG && rump.netstat -rn -f inet
    201 
    202 	# Up, Gateway, Reject, Static
    203 	check_route_flags 10.0.0/24 UGRS
    204 
    205 	atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
    206 	    rump.ping -n -w 1 -c 1 10.0.0.1
    207 	$DEBUG && rump.netstat -rn -f inet
    208 
    209 	# Shouldn't be created
    210 	check_route_no_entry 10.0.0.1
    211 	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
    212 
    213 	# Gateway is lo0 (RTF_HOST)
    214 
    215 	# Delete an existing route first
    216 	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
    217 
    218 	atf_check -s exit:0 -o ignore \
    219 	    rump.route add -host 10.0.0.1/24 127.0.0.1 -iface -reject
    220 	$DEBUG && rump.netstat -rn -f inet
    221 
    222 	# Up, Host, Reject, Static
    223 	check_route_flags 10.0.0.1 UHRS
    224 
    225 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    226 	    rump.ping -n -w 1 -c 1 10.0.0.1
    227 	$DEBUG && rump.netstat -rn -f inet
    228 
    229 	return 0
    230 }
    231 
    232 test_icmp_redirect()
    233 {
    234 
    235 	### Testing Dynamic flag ###
    236 
    237 	#
    238 	# Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
    239 	#
    240 	setup_gw
    241 
    242 	#
    243 	# Teach the peer that 10.0.2.* is behind 10.0.0.254
    244 	#
    245 	export RUMP_SERVER=$SOCK_PEER
    246 	atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
    247 	# Up, Gateway, Static
    248 	check_route_flags 10.0.2/24 UGS
    249 
    250 	#
    251 	# Setup the default gateway to the peer, 10.0.0.1
    252 	#
    253 	export RUMP_SERVER=$SOCK_LOCAL
    254 	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
    255 	# Up, Gateway, Static
    256 	check_route_flags default UGS
    257 
    258 	# Try ping 10.0.2.1
    259 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
    260 	$DEBUG && rump.netstat -rn -f inet
    261 
    262 	# Up, Gateway, Host, Dynamic
    263 	check_route_flags 10.0.2.1 UGHD
    264 	check_route_gw 10.0.2.1 10.0.0.254
    265 
    266 	export RUMP_SERVER=$SOCK_PEER
    267 	$DEBUG && rump.netstat -rn -f inet
    268 
    269 	### Testing Modified flag ###
    270 
    271 	#
    272 	# Teach a wrong route to 10.0.2.2
    273 	#
    274 	export RUMP_SERVER=$SOCK_LOCAL
    275 	atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1
    276 	# Up, Gateway, Host, Static
    277 	check_route_flags 10.0.2.2 UGHS
    278 	check_route_gw 10.0.2.2 10.0.0.1
    279 
    280 	# Try ping 10.0.2.2
    281 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2
    282 	$DEBUG && rump.netstat -rn -f inet
    283 
    284 	# Up, Gateway, Host, Modified, Static
    285 	check_route_flags 10.0.2.2 UGHMS
    286 	check_route_gw 10.0.2.2 10.0.0.254
    287 }
    288 
    289 test_announce()
    290 {
    291 	export RUMP_SERVER=$SOCK_LOCAL
    292 
    293 	# Delete an existing route first
    294 	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
    295 
    296 	atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -proxy
    297 	$DEBUG && rump.netstat -rn -f inet
    298 
    299 	# Up, Gateway, Static, proxy
    300 	check_route_flags 10.0.0/24 UGSp
    301 
    302 	# TODO test its behavior
    303 }
    304 
    305 test_llinfo()
    306 {
    307 	local peer_macaddr=
    308 
    309 	peer_macaddr=$(get_macaddr $SOCK_PEER shmif0)
    310 
    311 	export RUMP_SERVER=$SOCK_LOCAL
    312 
    313 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
    314 
    315 	# Up, Host, LLINFO
    316 	check_route 10.0.0.1 $peer_macaddr UHL shmif0
    317 }
    318 
    319 add_test()
    320 {
    321 	local name=$1
    322 	local desc="$2"
    323 
    324 	atf_test_case "route_flags_${name}" cleanup
    325 	eval "route_flags_${name}_head() {
    326 			atf_set descr \"${desc}\"
    327 			atf_set require.progs rump_server
    328 		}
    329 	    route_flags_${name}_body() {
    330 			setup_local
    331 			setup_peer
    332 			test_${name}
    333 			rump_server_destroy_ifaces
    334 		}
    335 	    route_flags_${name}_cleanup() {
    336 			\$DEBUG && dump
    337 			cleanup
    338 		}"
    339 	atf_add_test_case "route_flags_${name}"
    340 }
    341 
    342 atf_init_test_cases()
    343 {
    344 
    345 	add_test lo              "Tests route flags: loop back interface"
    346 	add_test connected       "Tests route flags: connected route"
    347 	add_test default_gateway "Tests route flags: default gateway"
    348 	add_test static          "Tests route flags: static route"
    349 	add_test blackhole       "Tests route flags: blackhole route"
    350 	add_test reject          "Tests route flags: reject route"
    351 	add_test icmp_redirect   "Tests route flags: icmp redirect"
    352 	add_test announce        "Tests route flags: announce flag"
    353 	add_test llinfo          "Tests route flags: ARP caches"
    354 }
    355