xref: /freebsd/contrib/netbsd-tests/net/route/t_flags6.sh (revision a2aef24aa3c8458e4036735dd6928b4ef77294e5)
1#	$NetBSD: t_flags6.sh,v 1.12 2016/12/21 02:46:08 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
28SOCK_LOCAL=unix://commsock1
29SOCK_PEER=unix://commsock2
30SOCK_GW=unix://commsock3
31BUS=bus1
32BUS2=bus2
33
34IP6_LOCAL=fc00::2
35IP6_PEER=fc00::1
36
37DEBUG=${DEBUG:-false}
38
39setup_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
54setup_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
69test_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
81test_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
93test_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
105test_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
127test_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
138	# Gateway must be lo0
139	atf_check -s exit:0 -o ignore \
140	    rump.route add -inet6 -net fc00::/64 ::1 -blackhole
141	$DEBUG && rump.netstat -rn -f inet6
142
143	# Up, Gateway, Blackhole, Static
144	check_route_flags fc00::/64 UGBS
145
146	atf_check -s not-exit:0 -o match:'100.0% packet loss' \
147	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
148	$DEBUG && rump.netstat -rn -f inet6
149
150	# Shouldn't be created
151	check_route_no_entry $IP6_PEER
152}
153
154test_reject6()
155{
156
157	export RUMP_SERVER=$SOCK_LOCAL
158
159	# Delete an existing route first
160	atf_check -s exit:0 -o ignore \
161	    rump.route delete -inet6 -net fc00::/64
162
163	atf_check -s exit:0 -o ignore \
164	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -reject
165	$DEBUG && rump.netstat -rn -f inet6
166
167	# Up, Gateway, Reject, Static
168	check_route_flags fc00::/64 UGRS
169
170	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
171	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
172	$DEBUG && rump.netstat -rn -f inet6
173
174	# Shouldn't be created
175	check_route_no_entry $IP6_PEER
176
177	# Gateway is lo0 (RTF_GATEWAY)
178
179	# Delete an existing route first
180	atf_check -s exit:0 -o ignore \
181	    rump.route delete -inet6 -net fc00::/64
182
183	atf_check -s exit:0 -o ignore \
184	    rump.route add -inet6 -net fc00::/64 ::1  -reject
185	$DEBUG && rump.netstat -rn -f inet6
186
187	# Up, Gateway, Reject, Static
188	check_route_flags fc00::/64 UGRS
189
190	atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
191	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
192	$DEBUG && rump.netstat -rn -f inet6
193
194	# Shouldn't be created
195	check_route_no_entry $IP6_PEER
196
197	# Gateway is lo0 (RTF_HOST)
198
199	# Delete an existing route first
200	atf_check -s exit:0 -o ignore \
201	    rump.route delete -inet6 -net fc00::/64
202
203	atf_check -s exit:0 -o ignore \
204	    rump.route add -inet6 -host fc00::/64 ::1 -iface -reject
205	$DEBUG && rump.netstat -rn -f inet6
206
207	# Up, Host, Reject, Static
208	check_route_flags fc00:: UHRS
209
210	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
211	    rump.ping6 -n -X 1 -c 1 $IP6_PEER
212	$DEBUG && rump.netstat -rn -f inet6
213
214	return 0
215}
216
217test_announce6()
218{
219	export RUMP_SERVER=$SOCK_LOCAL
220
221	# Delete an existing route first
222	atf_check -s exit:0 -o ignore \
223	    rump.route delete -inet6 -net fc00::/64
224
225	atf_check -s exit:0 -o ignore \
226	    rump.route add -inet6 -net fc00::/64 $IP6_PEER -proxy
227	$DEBUG && rump.netstat -rn -f inet6
228
229	# Up, Gateway, Static, proxy
230	check_route_flags fc00::/64 UGSp
231
232	# TODO test its behavior
233}
234
235add_test()
236{
237	local name=$1
238	local desc="$2"
239
240	atf_test_case "route_flags_${name}" cleanup
241	eval "route_flags_${name}_head() { \
242			atf_set \"descr\" \"${desc}\"; \
243			atf_set \"require.progs\" \"rump_server\"; \
244		}; \
245	    route_flags_${name}_body() { \
246			setup_local; \
247			setup_peer; \
248			test_${name}; \
249			rump_server_destroy_ifaces; \
250		}; \
251	    route_flags_${name}_cleanup() { \
252			$DEBUG && dump; \
253			cleanup; \
254		}"
255	atf_add_test_case "route_flags_${name}"
256}
257
258atf_init_test_cases()
259{
260
261	add_test lo6              "Tests route flags: loop back interface"
262	add_test connected6       "Tests route flags: connected route"
263	add_test default_gateway6 "Tests route flags: default gateway"
264	add_test static6          "Tests route flags: static route"
265	add_test blackhole6       "Tests route flags: blackhole route"
266	add_test reject6          "Tests route flags: reject route"
267	add_test announce6        "Tests route flags: announce flag"
268}
269