Home | History | Annotate | Line # | Download | only in route
t_flags6.sh revision 1.11
      1 #	$NetBSD: t_flags6.sh,v 1.11 2016/11/25 08:51:17 ozaki-r Exp $
      2 #
      3 # Copyright (c) 2016 Internet Initiative Japan 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 IP6_LOCAL=fc00::2
     35 IP6_PEER=fc00::1
     36 
     37 DEBUG=${DEBUG:-false}
     38 
     39 setup_local()
     40 {
     41 
     42 	rump_server_start $SOCK_LOCAL netinet6
     43 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
     44 
     45 	export RUMP_SERVER=$SOCK_LOCAL
     46 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $IP6_LOCAL
     47 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
     48 
     49 	$DEBUG && rump.ifconfig
     50 	$DEBUG && rump.netstat -rn -f inet6
     51 }
     52 
     53 setup_peer()
     54 {
     55 
     56 	rump_server_start $SOCK_PEER netinet6
     57 	rump_server_add_iface $SOCK_PEER shmif0 $BUS
     58 
     59 	export RUMP_SERVER=$SOCK_PEER
     60 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $IP6_PEER
     61 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
     62 
     63 	$DEBUG && rump.ifconfig
     64 	$DEBUG && rump.netstat -rn -f inet6
     65 }
     66 
     67 test_lo6()
     68 {
     69 
     70 	export RUMP_SERVER=$SOCK_LOCAL
     71 
     72 	# Up, Host, local
     73 	check_route_flags fe80::1 UHl
     74 
     75 	# Up, Host, local
     76 	check_route_flags ::1 UHl
     77 }
     78 
     79 test_connected6()
     80 {
     81 
     82 	export RUMP_SERVER=$SOCK_LOCAL
     83 
     84 	# Up, Host, local
     85 	check_route_flags $IP6_LOCAL UHl
     86 
     87 	# Up, Connected
     88 	check_route_flags fc00::/64 UC
     89 }
     90 
     91 test_default_gateway6()
     92 {
     93 
     94 	export RUMP_SERVER=$SOCK_LOCAL
     95 
     96 	atf_check -s exit:0 -o ignore rump.route add -inet6 default $IP6_PEER
     97 	$DEBUG && rump.netstat -rn -f inet6
     98 
     99 	# Up, Gateway, Static
    100 	check_route_flags default UGS
    101 }
    102 
    103 test_static6()
    104 {
    105 
    106 	export RUMP_SERVER=$SOCK_LOCAL
    107 
    108 	# Static route to host
    109 	atf_check -s exit:0 -o ignore \
    110 	    rump.route add -inet6 fc00::1:1 $IP6_PEER
    111 	$DEBUG && rump.netstat -rn -f inet6
    112 
    113 	# Up, Gateway, Host, Static
    114 	check_route_flags fc00::1:1 UGHS
    115 
    116 	# Static route to network
    117 	atf_check -s exit:0 -o ignore \
    118 	    rump.route add -inet6 -net fc00::/24 $IP6_PEER
    119 	$DEBUG && rump.netstat -rn -f inet6
    120 
    121 	# Up, Gateway, Static
    122 	check_route_flags fc00::/24 UGS
    123 }
    124 
    125 test_blackhole6()
    126 {
    127 
    128 	export RUMP_SERVER=$SOCK_LOCAL
    129 
    130 	atf_check -s exit:0 -o ignore rump.ping6 -n -X 1 -c 1 $IP6_PEER
    131 
    132 	# Delete an existing route first
    133 	atf_check -s exit:0 -o ignore \
    134 	    rump.route delete -inet6 -net fc00::/64
    135 
    136 	# Gateway must be lo0
    137 	atf_check -s exit:0 -o ignore \
    138 	    rump.route add -inet6 -net fc00::/64 ::1 -blackhole
    139 	$DEBUG && rump.netstat -rn -f inet6
    140 
    141 	# Up, Gateway, Blackhole, Static
    142 	check_route_flags fc00::/64 UGBS
    143 
    144 	atf_check -s not-exit:0 -o match:'100.0% packet loss' \
    145 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    146 	$DEBUG && rump.netstat -rn -f inet6
    147 
    148 	# Shouldn't be created
    149 	check_route_no_entry $IP6_PEER
    150 }
    151 
    152 test_reject6()
    153 {
    154 
    155 	export RUMP_SERVER=$SOCK_LOCAL
    156 
    157 	# Delete an existing route first
    158 	atf_check -s exit:0 -o ignore \
    159 	    rump.route delete -inet6 -net fc00::/64
    160 
    161 	atf_check -s exit:0 -o ignore \
    162 	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -reject
    163 	$DEBUG && rump.netstat -rn -f inet6
    164 
    165 	# Up, Gateway, Reject, Static
    166 	check_route_flags fc00::/64 UGRS
    167 
    168 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    169 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    170 	$DEBUG && rump.netstat -rn -f inet6
    171 
    172 	# Shouldn't be created
    173 	check_route_no_entry $IP6_PEER
    174 
    175 	# Gateway is lo0 (RTF_GATEWAY)
    176 
    177 	# Delete an existing route first
    178 	atf_check -s exit:0 -o ignore \
    179 	    rump.route delete -inet6 -net fc00::/64
    180 
    181 	atf_check -s exit:0 -o ignore \
    182 	    rump.route add -inet6 -net fc00::/64 ::1  -reject
    183 	$DEBUG && rump.netstat -rn -f inet6
    184 
    185 	# Up, Gateway, Reject, Static
    186 	check_route_flags fc00::/64 UGRS
    187 
    188 	atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
    189 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    190 	$DEBUG && rump.netstat -rn -f inet6
    191 
    192 	# Shouldn't be created
    193 	check_route_no_entry $IP6_PEER
    194 
    195 	# Gateway is lo0 (RTF_HOST)
    196 
    197 	# Delete an existing route first
    198 	atf_check -s exit:0 -o ignore \
    199 	    rump.route delete -inet6 -net fc00::/64
    200 
    201 	atf_check -s exit:0 -o ignore \
    202 	    rump.route add -inet6 -host fc00::/64 ::1 -iface -reject
    203 	$DEBUG && rump.netstat -rn -f inet6
    204 
    205 	# Up, Host, Reject, Static
    206 	check_route_flags fc00:: UHRS
    207 
    208 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    209 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    210 	$DEBUG && rump.netstat -rn -f inet6
    211 
    212 	return 0
    213 }
    214 
    215 test_announce6()
    216 {
    217 	export RUMP_SERVER=$SOCK_LOCAL
    218 
    219 	# Delete an existing route first
    220 	atf_check -s exit:0 -o ignore \
    221 	    rump.route delete -inet6 -net fc00::/64
    222 
    223 	atf_check -s exit:0 -o ignore \
    224 	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -proxy
    225 	$DEBUG && rump.netstat -rn -f inet6
    226 
    227 	# Up, Gateway, Static, proxy
    228 	check_route_flags fc00::/64 UGSp
    229 
    230 	# TODO test its behavior
    231 }
    232 
    233 add_test()
    234 {
    235 	local name=$1
    236 	local desc="$2"
    237 
    238 	atf_test_case "route_flags_${name}" cleanup
    239 	eval "route_flags_${name}_head() { \
    240 			atf_set \"descr\" \"${desc}\"; \
    241 			atf_set \"require.progs\" \"rump_server\"; \
    242 		}; \
    243 	    route_flags_${name}_body() { \
    244 			setup_local; \
    245 			setup_peer; \
    246 			test_${name}; \
    247 			rump_server_destroy_ifaces; \
    248 		}; \
    249 	    route_flags_${name}_cleanup() { \
    250 			$DEBUG && dump; \
    251 			cleanup; \
    252 		}"
    253 	atf_add_test_case "route_flags_${name}"
    254 }
    255 
    256 atf_init_test_cases()
    257 {
    258 
    259 	add_test lo6              "Tests route flags: loop back interface"
    260 	add_test connected6       "Tests route flags: connected route"
    261 	add_test default_gateway6 "Tests route flags: default gateway"
    262 	add_test static6          "Tests route flags: static route"
    263 	add_test blackhole6       "Tests route flags: blackhole route"
    264 	add_test reject6          "Tests route flags: reject route"
    265 	add_test announce6        "Tests route flags: announce flag"
    266 }
    267