xref: /freebsd/contrib/netbsd-tests/net/route/t_flags6.sh (revision d370fd1cd8fc69e87dc63f4f4a82e5a8b4956c93)
1*cdebaff8SEnji Cooper#	$NetBSD: t_flags6.sh,v 1.12 2016/12/21 02:46:08 ozaki-r Exp $
2640235e2SEnji Cooper#
3640235e2SEnji Cooper# Copyright (c) 2016 Internet Initiative Japan Inc.
4640235e2SEnji Cooper# All rights reserved.
5640235e2SEnji Cooper#
6640235e2SEnji Cooper# Redistribution and use in source and binary forms, with or without
7640235e2SEnji Cooper# modification, are permitted provided that the following conditions
8640235e2SEnji Cooper# are met:
9640235e2SEnji Cooper# 1. Redistributions of source code must retain the above copyright
10640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer.
11640235e2SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
12640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
13640235e2SEnji Cooper#    documentation and/or other materials provided with the distribution.
14640235e2SEnji Cooper#
15640235e2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16640235e2SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17640235e2SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18640235e2SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19640235e2SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20640235e2SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21640235e2SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22640235e2SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23640235e2SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24640235e2SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25640235e2SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
26640235e2SEnji Cooper#
27640235e2SEnji Cooper
28640235e2SEnji CooperSOCK_LOCAL=unix://commsock1
29640235e2SEnji CooperSOCK_PEER=unix://commsock2
30640235e2SEnji CooperSOCK_GW=unix://commsock3
31640235e2SEnji CooperBUS=bus1
32640235e2SEnji CooperBUS2=bus2
33640235e2SEnji Cooper
34640235e2SEnji CooperIP6_LOCAL=fc00::2
35640235e2SEnji CooperIP6_PEER=fc00::1
36640235e2SEnji Cooper
37*cdebaff8SEnji CooperDEBUG=${DEBUG:-false}
38640235e2SEnji Cooper
39640235e2SEnji Coopersetup_local()
40640235e2SEnji Cooper{
41640235e2SEnji Cooper
42*cdebaff8SEnji Cooper	rump_server_start $SOCK_LOCAL netinet6
43*cdebaff8SEnji Cooper	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
44640235e2SEnji Cooper
45640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
46640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $IP6_LOCAL
47640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
48*cdebaff8SEnji Cooper	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
49640235e2SEnji Cooper
50640235e2SEnji Cooper	$DEBUG && rump.ifconfig
51640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
52640235e2SEnji Cooper}
53640235e2SEnji Cooper
54640235e2SEnji Coopersetup_peer()
55640235e2SEnji Cooper{
56640235e2SEnji Cooper
57*cdebaff8SEnji Cooper	rump_server_start $SOCK_PEER netinet6
58*cdebaff8SEnji Cooper	rump_server_add_iface $SOCK_PEER shmif0 $BUS
59640235e2SEnji Cooper
60640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_PEER
61640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $IP6_PEER
62640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
63*cdebaff8SEnji Cooper	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
64640235e2SEnji Cooper
65640235e2SEnji Cooper	$DEBUG && rump.ifconfig
66640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
67640235e2SEnji Cooper}
68640235e2SEnji Cooper
69640235e2SEnji Coopertest_lo6()
70640235e2SEnji Cooper{
71640235e2SEnji Cooper
72640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
73640235e2SEnji Cooper
74640235e2SEnji Cooper	# Up, Host, local
75*cdebaff8SEnji Cooper	check_route_flags fe80::1 UHl
76640235e2SEnji Cooper
77*cdebaff8SEnji Cooper	# Up, Host, local
78*cdebaff8SEnji Cooper	check_route_flags ::1 UHl
79640235e2SEnji Cooper}
80640235e2SEnji Cooper
81640235e2SEnji Coopertest_connected6()
82640235e2SEnji Cooper{
83640235e2SEnji Cooper
84640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
85640235e2SEnji Cooper
86640235e2SEnji Cooper	# Up, Host, local
87*cdebaff8SEnji Cooper	check_route_flags $IP6_LOCAL UHl
88640235e2SEnji Cooper
89640235e2SEnji Cooper	# Up, Connected
90*cdebaff8SEnji Cooper	check_route_flags fc00::/64 UC
91640235e2SEnji Cooper}
92640235e2SEnji Cooper
93640235e2SEnji Coopertest_default_gateway6()
94640235e2SEnji Cooper{
95640235e2SEnji Cooper
96640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
97640235e2SEnji Cooper
98640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.route add -inet6 default $IP6_PEER
99640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
100640235e2SEnji Cooper
101640235e2SEnji Cooper	# Up, Gateway, Static
102*cdebaff8SEnji Cooper	check_route_flags default UGS
103640235e2SEnji Cooper}
104640235e2SEnji Cooper
105640235e2SEnji Coopertest_static6()
106640235e2SEnji Cooper{
107640235e2SEnji Cooper
108640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
109640235e2SEnji Cooper
110640235e2SEnji Cooper	# Static route to host
111640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
112640235e2SEnji Cooper	    rump.route add -inet6 fc00::1:1 $IP6_PEER
113640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
114640235e2SEnji Cooper
115640235e2SEnji Cooper	# Up, Gateway, Host, Static
116*cdebaff8SEnji Cooper	check_route_flags fc00::1:1 UGHS
117640235e2SEnji Cooper
118640235e2SEnji Cooper	# Static route to network
119640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
120640235e2SEnji Cooper	    rump.route add -inet6 -net fc00::/24 $IP6_PEER
121640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
122640235e2SEnji Cooper
123640235e2SEnji Cooper	# Up, Gateway, Static
124*cdebaff8SEnji Cooper	check_route_flags fc00::/24 UGS
125640235e2SEnji Cooper}
126640235e2SEnji Cooper
127640235e2SEnji Coopertest_blackhole6()
128640235e2SEnji Cooper{
129640235e2SEnji Cooper
130640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
131640235e2SEnji Cooper
132640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.ping6 -n -X 1 -c 1 $IP6_PEER
133640235e2SEnji Cooper
134640235e2SEnji Cooper	# Delete an existing route first
135640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
136640235e2SEnji Cooper	    rump.route delete -inet6 -net fc00::/64
137640235e2SEnji Cooper
138640235e2SEnji Cooper	# Gateway must be lo0
139640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
140640235e2SEnji Cooper	    rump.route add -inet6 -net fc00::/64 ::1 -blackhole
141640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
142640235e2SEnji Cooper
143640235e2SEnji Cooper	# Up, Gateway, Blackhole, Static
144*cdebaff8SEnji Cooper	check_route_flags fc00::/64 UGBS
145640235e2SEnji Cooper
146640235e2SEnji Cooper	atf_check -s not-exit:0 -o match:'100.0% packet loss' \
147640235e2SEnji Cooper	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
148640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
149640235e2SEnji Cooper
150640235e2SEnji Cooper	# Shouldn't be created
151*cdebaff8SEnji Cooper	check_route_no_entry $IP6_PEER
152640235e2SEnji Cooper}
153640235e2SEnji Cooper
154640235e2SEnji Coopertest_reject6()
155640235e2SEnji Cooper{
156640235e2SEnji Cooper
157640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
158640235e2SEnji Cooper
159640235e2SEnji Cooper	# Delete an existing route first
160640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
161640235e2SEnji Cooper	    rump.route delete -inet6 -net fc00::/64
162640235e2SEnji Cooper
163640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
164640235e2SEnji Cooper	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -reject
165640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
166640235e2SEnji Cooper
167640235e2SEnji Cooper	# Up, Gateway, Reject, Static
168*cdebaff8SEnji Cooper	check_route_flags fc00::/64 UGRS
169640235e2SEnji Cooper
170640235e2SEnji Cooper	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
171640235e2SEnji Cooper	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
172640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
173640235e2SEnji Cooper
174640235e2SEnji Cooper	# Shouldn't be created
175*cdebaff8SEnji Cooper	check_route_no_entry $IP6_PEER
176640235e2SEnji Cooper
177640235e2SEnji Cooper	# Gateway is lo0 (RTF_GATEWAY)
178640235e2SEnji Cooper
179640235e2SEnji Cooper	# Delete an existing route first
180640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
181640235e2SEnji Cooper	    rump.route delete -inet6 -net fc00::/64
182640235e2SEnji Cooper
183640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
184640235e2SEnji Cooper	    rump.route add -inet6 -net fc00::/64 ::1  -reject
185640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
186640235e2SEnji Cooper
187640235e2SEnji Cooper	# Up, Gateway, Reject, Static
188*cdebaff8SEnji Cooper	check_route_flags fc00::/64 UGRS
189640235e2SEnji Cooper
190640235e2SEnji Cooper	atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
191640235e2SEnji Cooper	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
192640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
193640235e2SEnji Cooper
194640235e2SEnji Cooper	# Shouldn't be created
195*cdebaff8SEnji Cooper	check_route_no_entry $IP6_PEER
196640235e2SEnji Cooper
197640235e2SEnji Cooper	# Gateway is lo0 (RTF_HOST)
198640235e2SEnji Cooper
199640235e2SEnji Cooper	# Delete an existing route first
200640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
201640235e2SEnji Cooper	    rump.route delete -inet6 -net fc00::/64
202640235e2SEnji Cooper
203640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
204640235e2SEnji Cooper	    rump.route add -inet6 -host fc00::/64 ::1 -iface -reject
205640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
206640235e2SEnji Cooper
207640235e2SEnji Cooper	# Up, Host, Reject, Static
208*cdebaff8SEnji Cooper	check_route_flags fc00:: UHRS
209640235e2SEnji Cooper
210640235e2SEnji Cooper	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
211640235e2SEnji Cooper	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
212640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
213640235e2SEnji Cooper
214640235e2SEnji Cooper	return 0
215640235e2SEnji Cooper}
216640235e2SEnji Cooper
217640235e2SEnji Coopertest_announce6()
218640235e2SEnji Cooper{
219640235e2SEnji Cooper	export RUMP_SERVER=$SOCK_LOCAL
220640235e2SEnji Cooper
221640235e2SEnji Cooper	# Delete an existing route first
222640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
223640235e2SEnji Cooper	    rump.route delete -inet6 -net fc00::/64
224640235e2SEnji Cooper
225640235e2SEnji Cooper	atf_check -s exit:0 -o ignore \
226640235e2SEnji Cooper	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -proxy
227640235e2SEnji Cooper	$DEBUG && rump.netstat -rn -f inet6
228640235e2SEnji Cooper
229640235e2SEnji Cooper	# Up, Gateway, Static, proxy
230*cdebaff8SEnji Cooper	check_route_flags fc00::/64 UGSp
231640235e2SEnji Cooper
232640235e2SEnji Cooper	# TODO test its behavior
233640235e2SEnji Cooper}
234640235e2SEnji Cooper
235640235e2SEnji Cooperadd_test()
236640235e2SEnji Cooper{
237640235e2SEnji Cooper	local name=$1
238640235e2SEnji Cooper	local desc="$2"
239640235e2SEnji Cooper
240640235e2SEnji Cooper	atf_test_case "route_flags_${name}" cleanup
241640235e2SEnji Cooper	eval "route_flags_${name}_head() { \
242640235e2SEnji Cooper			atf_set \"descr\" \"${desc}\"; \
243640235e2SEnji Cooper			atf_set \"require.progs\" \"rump_server\"; \
244640235e2SEnji Cooper		}; \
245640235e2SEnji Cooper	    route_flags_${name}_body() { \
246640235e2SEnji Cooper			setup_local; \
247640235e2SEnji Cooper			setup_peer; \
248640235e2SEnji Cooper			test_${name}; \
249*cdebaff8SEnji Cooper			rump_server_destroy_ifaces; \
250640235e2SEnji Cooper		}; \
251640235e2SEnji Cooper	    route_flags_${name}_cleanup() { \
252*cdebaff8SEnji Cooper			$DEBUG && dump; \
253640235e2SEnji Cooper			cleanup; \
254640235e2SEnji Cooper		}"
255640235e2SEnji Cooper	atf_add_test_case "route_flags_${name}"
256640235e2SEnji Cooper}
257640235e2SEnji Cooper
258640235e2SEnji Cooperatf_init_test_cases()
259640235e2SEnji Cooper{
260640235e2SEnji Cooper
261640235e2SEnji Cooper	add_test lo6              "Tests route flags: loop back interface"
262640235e2SEnji Cooper	add_test connected6       "Tests route flags: connected route"
263640235e2SEnji Cooper	add_test default_gateway6 "Tests route flags: default gateway"
264640235e2SEnji Cooper	add_test static6          "Tests route flags: static route"
265640235e2SEnji Cooper	add_test blackhole6       "Tests route flags: blackhole route"
266640235e2SEnji Cooper	add_test reject6          "Tests route flags: reject route"
267640235e2SEnji Cooper	add_test announce6        "Tests route flags: announce flag"
268640235e2SEnji Cooper}
269