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