1 # $NetBSD: t_flags6.sh,v 1.7 2016/08/10 23:00:39 roy Exp $
3 # Copyright (c) 2016 Internet Initiative Japan Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
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
45 atf_check -s exit:0 rump_server ${RUMP_OPTS} ${SOCK_LOCAL}
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
53 $DEBUG && rump.ifconfig
54 $DEBUG && rump.netstat -rn -f inet6
60 atf_check -s exit:0 rump_server ${RUMP_OPTS} ${SOCK_PEER}
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
68 $DEBUG && rump.ifconfig
69 $DEBUG && rump.netstat -rn -f inet6
74 local ip=$(echo $1 |sed 's/\./\\./g')
77 atf_check -s exit:0 -o match:" $flags " -e ignore -x \
78 "rump.netstat -rn -f inet6 | grep ^'$ip'"
83 local ip=$(echo $1 |sed 's/\./\\./g')
86 atf_check -s exit:0 -o match:" $gw " -e ignore -x \
87 "rump.netstat -rn -f inet6 | grep ^'$ip'"
92 ip=$(echo $1 |sed 's/\./\\./g')
93 flags=$2 # Not used currently
95 atf_check -s not-exit:0 -e ignore -x \
96 "rump.netstat -rn -f inet6 | grep ^'$ip'"
102 export RUMP_SERVER=$SOCK_LOCAL
105 check_entry_flags fe80::1 UHl
108 check_entry_flags ::1 UH
114 export RUMP_SERVER=$SOCK_LOCAL
117 check_entry_flags $IP6_LOCAL UHl
120 check_entry_flags fc00::/64 UC
123 test_default_gateway6()
126 export RUMP_SERVER=$SOCK_LOCAL
128 atf_check -s exit:0 -o ignore rump.route add -inet6 default $IP6_PEER
129 $DEBUG && rump.netstat -rn -f inet6
131 # Up, Gateway, Static
132 check_entry_flags default UGS
138 export RUMP_SERVER=$SOCK_LOCAL
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
145 # Up, Gateway, Host, Static
146 check_entry_flags fc00::1:1 UGHS
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
153 # Up, Gateway, Static
154 check_entry_flags fc00::/24 UGS
160 export RUMP_SERVER=$SOCK_LOCAL
162 atf_check -s exit:0 -o ignore rump.ping6 -n -X 1 -c 1 $IP6_PEER
164 # Delete an existing route first
165 atf_check -s exit:0 -o ignore \
166 rump.route delete -inet6 -net fc00::/64
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
173 # Up, Gateway, Blackhole, Static
174 check_entry_flags fc00::/64 UGBS
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
180 # Shouldn't be created
181 check_entry_fail $IP6_PEER UH
187 export RUMP_SERVER=$SOCK_LOCAL
189 # Delete an existing route first
190 atf_check -s exit:0 -o ignore \
191 rump.route delete -inet6 -net fc00::/64
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
197 # Up, Gateway, Reject, Static
198 check_entry_flags fc00::/64 UGRS
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
204 # Shouldn't be created
205 check_entry_fail $IP6_PEER UH
207 # Gateway is lo0 (RTF_GATEWAY)
209 # Delete an existing route first
210 atf_check -s exit:0 -o ignore \
211 rump.route delete -inet6 -net fc00::/64
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
217 # Up, Gateway, Reject, Static
218 check_entry_flags fc00::/64 UGRS
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
224 # Shouldn't be created
225 check_entry_fail $IP6_PEER UH
227 # Gateway is lo0 (RTF_HOST)
229 # Delete an existing route first
230 atf_check -s exit:0 -o ignore \
231 rump.route delete -inet6 -net fc00::/64
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
237 # Up, Host, Reject, Static
238 check_entry_flags fc00:: UHRS
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
249 export RUMP_SERVER=$SOCK_LOCAL
251 # Delete an existing route first
252 atf_check -s exit:0 -o ignore \
253 rump.route delete -inet6 -net fc00::/64
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
259 # Up, Gateway, Static, proxy
260 check_entry_flags fc00::/64 UGSp
262 # TODO test its behavior
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
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\"; \
283 route_flags_${name}_body() { \
288 route_flags_${name}_cleanup() { \
291 atf_add_test_case "route_flags_${name}"
294 atf_init_test_cases()
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"