Home | History | Annotate | Line # | Download | only in route
      1 #	$NetBSD: t_flags6.sh,v 1.16 2017/08/03 03:16:27 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 	# Should be removed too
    138 	atf_check -s not-exit:0 -o ignore -e match:'no entry' \
    139 	    rump.ndp -n $IP6_PEER
    140 
    141 	# Gateway must be lo0
    142 	atf_check -s exit:0 -o ignore \
    143 	    rump.route add -inet6 -net fc00::/64 ::1 -blackhole
    144 	$DEBUG && rump.netstat -rn -f inet6
    145 
    146 	# Up, Gateway, Blackhole, Static
    147 	check_route_flags fc00::/64 UGBS
    148 
    149 	atf_check -s not-exit:0 -o match:'100.0% packet loss' \
    150 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    151 	$DEBUG && rump.netstat -rn -f inet6
    152 
    153 	# Shouldn't be created
    154 	check_route_no_entry $IP6_PEER
    155 	atf_check -s not-exit:0 -o ignore -e match:'no entry' \
    156 	    rump.ndp -n $IP6_PEER
    157 }
    158 
    159 test_reject6()
    160 {
    161 
    162 	export RUMP_SERVER=$SOCK_LOCAL
    163 
    164 	# Delete an existing route first
    165 	atf_check -s exit:0 -o ignore \
    166 	    rump.route delete -inet6 -net fc00::/64
    167 
    168 	atf_check -s exit:0 -o ignore \
    169 	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -reject
    170 	$DEBUG && rump.netstat -rn -f inet6
    171 
    172 	# Up, Gateway, Reject, Static
    173 	check_route_flags fc00::/64 UGRS
    174 
    175 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    176 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    177 	$DEBUG && rump.netstat -rn -f inet6
    178 
    179 	# Shouldn't be created
    180 	check_route_no_entry $IP6_PEER
    181 	atf_check -s not-exit:0 -o ignore -e match:'no entry' \
    182 	    rump.ndp -n $IP6_PEER
    183 
    184 	# Gateway is lo0 (RTF_GATEWAY)
    185 
    186 	# Delete an existing route first
    187 	atf_check -s exit:0 -o ignore \
    188 	    rump.route delete -inet6 -net fc00::/64
    189 
    190 	atf_check -s exit:0 -o ignore \
    191 	    rump.route add -inet6 -net fc00::/64 ::1  -reject
    192 	$DEBUG && rump.netstat -rn -f inet6
    193 
    194 	# Up, Gateway, Reject, Static
    195 	check_route_flags fc00::/64 UGRS
    196 
    197 	atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
    198 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    199 	$DEBUG && rump.netstat -rn -f inet6
    200 
    201 	# Shouldn't be created
    202 	check_route_no_entry $IP6_PEER
    203 	atf_check -s not-exit:0 -o ignore -e match:'no entry' \
    204 	    rump.ndp -n $IP6_PEER
    205 
    206 	# Gateway is lo0 (RTF_HOST)
    207 
    208 	# Delete an existing route first
    209 	atf_check -s exit:0 -o ignore \
    210 	    rump.route delete -inet6 -net fc00::/64
    211 
    212 	atf_check -s exit:0 -o ignore \
    213 	    rump.route add -inet6 -host fc00::/64 ::1 -iface -reject
    214 	$DEBUG && rump.netstat -rn -f inet6
    215 
    216 	# Up, Host, Reject, Static
    217 	check_route_flags fc00:: UHRS
    218 
    219 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    220 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    221 	$DEBUG && rump.netstat -rn -f inet6
    222 
    223 	return 0
    224 }
    225 
    226 test_announce6()
    227 {
    228 	export RUMP_SERVER=$SOCK_LOCAL
    229 
    230 	# Delete an existing route first
    231 	atf_check -s exit:0 -o ignore \
    232 	    rump.route delete -inet6 -net fc00::/64
    233 
    234 	atf_check -s exit:0 -o ignore \
    235 	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -proxy
    236 	$DEBUG && rump.netstat -rn -f inet6
    237 
    238 	# Up, Gateway, Static, proxy
    239 	check_route_flags fc00::/64 UGSp
    240 
    241 	# TODO test its behavior
    242 }
    243 
    244 test_llinfo6()
    245 {
    246 	local peer_macaddr=
    247 
    248 	peer_macaddr=$(get_macaddr $SOCK_PEER shmif0)
    249 
    250 	export RUMP_SERVER=$SOCK_LOCAL
    251 
    252 	atf_check -s exit:0 -o ignore rump.ping6 -n -X 1 -c 1 $IP6_PEER
    253 
    254 	# Up, Host, LLINFO
    255 	check_route $IP6_PEER $peer_macaddr UHL shmif0
    256 }
    257 
    258 add_test()
    259 {
    260 	local name=$1
    261 	local desc="$2"
    262 
    263 	atf_test_case "route_flags_${name}" cleanup
    264 	eval "route_flags_${name}_head() {
    265 			atf_set descr \"${desc}\"
    266 			atf_set require.progs rump_server
    267 		}
    268 	    route_flags_${name}_body() {
    269 			setup_local
    270 			setup_peer
    271 			test_${name}
    272 			rump_server_destroy_ifaces
    273 		}
    274 	    route_flags_${name}_cleanup() {
    275 			\$DEBUG && dump
    276 			cleanup
    277 		}"
    278 	atf_add_test_case "route_flags_${name}"
    279 }
    280 
    281 atf_init_test_cases()
    282 {
    283 
    284 	add_test lo6              "Tests route flags: loop back interface"
    285 	add_test connected6       "Tests route flags: connected route"
    286 	add_test default_gateway6 "Tests route flags: default gateway"
    287 	add_test static6          "Tests route flags: static route"
    288 	add_test blackhole6       "Tests route flags: blackhole route"
    289 	add_test reject6          "Tests route flags: reject route"
    290 	add_test announce6        "Tests route flags: announce flag"
    291 	add_test llinfo6          "Tests route flags: announce llinfo"
    292 }
    293