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