Home | History | Annotate | Line # | Download | only in route
t_flags6.sh revision 1.6
      1 #	$NetBSD: t_flags6.sh,v 1.6 2016/07/08 08:27:07 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 RUMP_OPTS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6"
     29 RUMP_OPTS="$RUMP_OPTS -lrumpnet_shmif"
     30 SOCK_LOCAL=unix://commsock1
     31 SOCK_PEER=unix://commsock2
     32 SOCK_GW=unix://commsock3
     33 BUS=bus1
     34 BUS2=bus2
     35 
     36 IP6_LOCAL=fc00::2
     37 IP6_PEER=fc00::1
     38 
     39 DEBUG=false
     40 
     41 setup_local()
     42 {
     43 
     44 	atf_check -s exit:0 rump_server ${RUMP_OPTS} ${SOCK_LOCAL}
     45 
     46 	export RUMP_SERVER=$SOCK_LOCAL
     47 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
     48 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
     49 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $IP6_LOCAL
     50 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
     51 
     52 	$DEBUG && rump.ifconfig
     53 	$DEBUG && rump.netstat -rn -f inet6
     54 }
     55 
     56 setup_peer()
     57 {
     58 
     59 	atf_check -s exit:0 rump_server ${RUMP_OPTS} ${SOCK_PEER}
     60 
     61 	export RUMP_SERVER=$SOCK_PEER
     62 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
     63 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
     64 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $IP6_PEER
     65 	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
     66 
     67 	$DEBUG && rump.ifconfig
     68 	$DEBUG && rump.netstat -rn -f inet6
     69 }
     70 
     71 check_entry_flags()
     72 {
     73 	local ip=$(echo $1 |sed 's/\./\\./g')
     74 	local flags=$2
     75 
     76 	atf_check -s exit:0 -o match:" $flags " -e ignore -x \
     77 	    "rump.netstat -rn -f inet6 | grep ^'$ip'"
     78 }
     79 
     80 check_entry_gw()
     81 {
     82 	local ip=$(echo $1 |sed 's/\./\\./g')
     83 	local gw=$2
     84 
     85 	atf_check -s exit:0 -o match:" $gw " -e ignore -x \
     86 	    "rump.netstat -rn -f inet6 | grep ^'$ip'"
     87 }
     88 
     89 check_entry_fail()
     90 {
     91 	ip=$(echo $1 |sed 's/\./\\./g')
     92 	flags=$2  # Not used currently
     93 
     94 	atf_check -s not-exit:0 -e ignore -x \
     95 	    "rump.netstat -rn -f inet6 | grep ^'$ip'"
     96 }
     97 
     98 test_lo6()
     99 {
    100 
    101 	export RUMP_SERVER=$SOCK_LOCAL
    102 
    103 	# Up, Host, local
    104 	check_entry_flags fe80::1 UHl
    105 
    106 	# Up, Host
    107 	check_entry_flags ::1 UH
    108 }
    109 
    110 test_connected6()
    111 {
    112 
    113 	export RUMP_SERVER=$SOCK_LOCAL
    114 
    115 	# Up, Host, local
    116 	check_entry_flags $IP6_LOCAL UHl
    117 
    118 	# Up, Connected
    119 	check_entry_flags fc00::/64 UC
    120 }
    121 
    122 test_default_gateway6()
    123 {
    124 
    125 	export RUMP_SERVER=$SOCK_LOCAL
    126 
    127 	atf_check -s exit:0 -o ignore rump.route add -inet6 default $IP6_PEER
    128 	$DEBUG && rump.netstat -rn -f inet6
    129 
    130 	# Up, Gateway, Static
    131 	check_entry_flags default UGS
    132 }
    133 
    134 test_static6()
    135 {
    136 
    137 	export RUMP_SERVER=$SOCK_LOCAL
    138 
    139 	# Static route to host
    140 	atf_check -s exit:0 -o ignore \
    141 	    rump.route add -inet6 fc00::1:1 $IP6_PEER
    142 	$DEBUG && rump.netstat -rn -f inet6
    143 
    144 	# Up, Gateway, Host, Static
    145 	check_entry_flags fc00::1:1 UGHS
    146 
    147 	# Static route to network
    148 	atf_check -s exit:0 -o ignore \
    149 	    rump.route add -inet6 -net fc00::/24 $IP6_PEER
    150 	$DEBUG && rump.netstat -rn -f inet6
    151 
    152 	# Up, Gateway, Static
    153 	check_entry_flags fc00::/24 UGS
    154 }
    155 
    156 test_blackhole6()
    157 {
    158 
    159 	export RUMP_SERVER=$SOCK_LOCAL
    160 
    161 	atf_check -s exit:0 -o ignore rump.ping6 -n -X 1 -c 1 $IP6_PEER
    162 
    163 	# Delete an existing route first
    164 	atf_check -s exit:0 -o ignore \
    165 	    rump.route delete -inet6 -net fc00::/64
    166 
    167 	# Gateway must be lo0
    168 	atf_check -s exit:0 -o ignore \
    169 	    rump.route add -inet6 -net fc00::/64 ::1 -blackhole
    170 	$DEBUG && rump.netstat -rn -f inet6
    171 
    172 	# Up, Gateway, Blackhole, Static
    173 	check_entry_flags fc00::/64 UGBS
    174 
    175 	atf_check -s not-exit:0 -o match:'100.0% packet loss' \
    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_entry_fail $IP6_PEER UH
    181 }
    182 
    183 test_reject6()
    184 {
    185 
    186 	export RUMP_SERVER=$SOCK_LOCAL
    187 
    188 	# Delete an existing route first
    189 	atf_check -s exit:0 -o ignore \
    190 	    rump.route delete -inet6 -net fc00::/64
    191 
    192 	atf_check -s exit:0 -o ignore \
    193 	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -reject
    194 	$DEBUG && rump.netstat -rn -f inet6
    195 
    196 	# Up, Gateway, Reject, Static
    197 	check_entry_flags fc00::/64 UGRS
    198 
    199 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    200 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    201 	$DEBUG && rump.netstat -rn -f inet6
    202 
    203 	# Shouldn't be created
    204 	check_entry_fail $IP6_PEER UH
    205 
    206 	# Gateway is lo0 (RTF_GATEWAY)
    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 -net fc00::/64 ::1  -reject
    214 	$DEBUG && rump.netstat -rn -f inet6
    215 
    216 	# Up, Gateway, Reject, Static
    217 	check_entry_flags fc00::/64 UGRS
    218 
    219 	atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
    220 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    221 	$DEBUG && rump.netstat -rn -f inet6
    222 
    223 	# Shouldn't be created
    224 	check_entry_fail $IP6_PEER UH
    225 
    226 	# Gateway is lo0 (RTF_HOST)
    227 
    228 	# Delete an existing route first
    229 	atf_check -s exit:0 -o ignore \
    230 	    rump.route delete -inet6 -net fc00::/64
    231 
    232 	atf_check -s exit:0 -o ignore \
    233 	    rump.route add -inet6 -host fc00::/64 ::1 -iface -reject
    234 	$DEBUG && rump.netstat -rn -f inet6
    235 
    236 	# Up, Host, Reject, Static
    237 	check_entry_flags fc00:: UHRS
    238 
    239 	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
    240 	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
    241 	$DEBUG && rump.netstat -rn -f inet6
    242 
    243 	return 0
    244 }
    245 
    246 test_announce6()
    247 {
    248 	export RUMP_SERVER=$SOCK_LOCAL
    249 
    250 	# Delete an existing route first
    251 	atf_check -s exit:0 -o ignore \
    252 	    rump.route delete -inet6 -net fc00::/64
    253 
    254 	atf_check -s exit:0 -o ignore \
    255 	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -proxy
    256 	$DEBUG && rump.netstat -rn -f inet6
    257 
    258 	# Up, Gateway, Static, proxy
    259 	check_entry_flags fc00::/64 UGSp
    260 
    261 	# TODO test its behavior
    262 }
    263 
    264 cleanup()
    265 {
    266 	$DEBUG && /usr/bin/shmif_dumpbus -p - $BUS 2>/dev/null | \
    267 	    /usr/sbin/tcpdump -n -e -r -
    268 	env RUMP_SERVER=$SOCK_LOCAL rump.halt
    269 	env RUMP_SERVER=$SOCK_PEER rump.halt
    270 }
    271 
    272 add_test()
    273 {
    274 	local name=$1
    275 	local desc="$2"
    276 
    277 	atf_test_case "route_flags_${name}" cleanup
    278 	eval "route_flags_${name}_head() { \
    279 			atf_set \"descr\" \"${desc}\"; \
    280 			atf_set \"require.progs\" \"rump_server\"; \
    281 		}; \
    282 	    route_flags_${name}_body() { \
    283 			setup_local; \
    284 			setup_peer; \
    285 			test_${name}; \
    286 		}; \
    287 	    route_flags_${name}_cleanup() { \
    288 			cleanup; \
    289 		}"
    290 	atf_add_test_case "route_flags_${name}"
    291 }
    292 
    293 atf_init_test_cases()
    294 {
    295 
    296 	add_test lo6              "Tests route flags: loop back interface"
    297 	add_test connected6       "Tests route flags: connected route"
    298 	add_test default_gateway6 "Tests route flags: default gateway"
    299 	add_test static6          "Tests route flags: static route"
    300 	add_test blackhole6       "Tests route flags: blackhole route"
    301 	add_test reject6          "Tests route flags: reject route"
    302 	add_test announce6        "Tests route flags: announce flag"
    303 }
    304