t_ra.sh revision 1.8
1#	$NetBSD: t_ra.sh,v 1.8 2016/12/16 03:14:23 ozaki-r Exp $
2#
3# Copyright (c) 2015 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
28RUMPSRV=unix://r1
29RUMPCLI=unix://r2
30IP6SRV=fc00:1::1
31IP6CLI=fc00:2::2
32PIDFILE=/var/run/rump.rtadvd.pid
33CONFIG=./rtadvd.conf
34DEBUG=${DEBUG:-true}
35
36setup_shmif0()
37{
38	local sock=$1
39	local IP6ADDR=$2
40
41	rump_server_add_iface $sock shmif0 bus1
42
43	export RUMP_SERVER=$sock
44	atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6ADDR}
45	atf_check -s exit:0 rump.ifconfig shmif0 up
46	atf_check -s exit:0 rump.ifconfig -w 10
47
48	$DEBUG && rump.ifconfig
49}
50
51wait_term()
52{
53	local PIDFILE=${1}
54	shift
55
56	while [ -f ${PIDFILE} ]
57	do
58		sleep 0.2
59	done
60
61	return 0
62}
63
64create_rtadvdconfig()
65{
66
67	cat << _EOF > ${CONFIG}
68shmif0:\
69	:mtu#1300:maxinterval#4:mininterval#3:
70_EOF
71}
72
73dump_entries()
74{
75
76	echo ndp -n -a
77	rump.ndp -n -a
78	echo ndp -p
79	rump.ndp -p
80	echo ndp -r
81	rump.ndp -r
82}
83
84atf_test_case ra_basic cleanup
85ra_basic_head()
86{
87
88	atf_set "descr" "Tests for basic functions of router advaertisement(RA)"
89	atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig"
90}
91
92ra_basic_body()
93{
94
95	rump_server_fs_start $RUMPSRV netinet6
96	rump_server_start $RUMPCLI netinet6
97
98	setup_shmif0 ${RUMPSRV} ${IP6SRV}
99	export RUMP_SERVER=${RUMPSRV}
100	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.forwarding=1
101	export LD_PRELOAD=/usr/lib/librumphijack.so
102	atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd
103	unset LD_PRELOAD
104	unset RUMP_SERVER
105
106	setup_shmif0 ${RUMPCLI} ${IP6CLI}
107	export RUMP_SERVER=${RUMPCLI}
108	$DEBUG && rump.ndp -n -a
109	atf_check -s exit:0 -o match:'= 0' rump.sysctl net.inet6.ip6.accept_rtadv
110	unset RUMP_SERVER
111
112	create_rtadvdconfig
113
114	export RUMP_SERVER=${RUMPSRV}
115	atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0
116	atf_check -s exit:0 sleep 3
117	atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE}
118	unset RUMP_SERVER
119
120	export RUMP_SERVER=${RUMPCLI}
121	atf_check -s exit:0 -o empty rump.ndp -r
122	atf_check -s exit:0 -o not-match:'advertised' rump.ndp -p
123	atf_check -s exit:0 -o match:'linkmtu=0' rump.ndp -n -i shmif0
124	atf_check -s exit:0 -o not-match:'S R' rump.ndp -n -a
125	atf_check -s exit:0 -o not-match:'fc00:1:' rump.ndp -n -a
126	atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6
127	unset RUMP_SERVER
128
129	atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
130	wait_term ${PIDFILE}
131
132	export RUMP_SERVER=${RUMPCLI}
133	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1
134	unset RUMP_SERVER
135
136	export RUMP_SERVER=${RUMPSRV}
137	atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0
138	atf_check -s exit:0 sleep 3
139	atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE}
140	unset RUMP_SERVER
141
142	export RUMP_SERVER=${RUMPCLI}
143	$DEBUG && rump.ndp -n -a
144	$DEBUG && rump.ndp -r
145	atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r
146	atf_check -s exit:0 -o match:'advertised' rump.ndp -p
147	atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0
148	atf_check -s exit:0 -o match:'(23h59m|1d0h0m)..s S R' rump.ndp -n -a
149	atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a
150	atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6
151	unset RUMP_SERVER
152
153	atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
154	wait_term ${PIDFILE}
155
156	rump_server_destroy_ifaces
157}
158
159ra_basic_cleanup()
160{
161
162	if [ -f ${PIDFILE} ]; then
163		kill -TERM `cat ${PIDFILE}`
164		wait_term ${PIDFILE}
165	fi
166
167	$DEBUG && dump
168	cleanup
169}
170
171atf_test_case ra_flush_prefix_entries cleanup
172ra_flush_prefix_entries_head()
173{
174
175	atf_set "descr" "Tests for flushing prefixes (ndp -P)"
176	atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig"
177}
178
179ra_flush_prefix_entries_body()
180{
181
182	rump_server_fs_start $RUMPSRV netinet6
183	rump_server_start $RUMPCLI netinet6
184
185	setup_shmif0 ${RUMPSRV} ${IP6SRV}
186	setup_shmif0 ${RUMPCLI} ${IP6CLI}
187
188	export RUMP_SERVER=${RUMPSRV}
189	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.forwarding=1
190	export LD_PRELOAD=/usr/lib/librumphijack.so
191	atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd
192	unset LD_PRELOAD
193	unset RUMP_SERVER
194
195	create_rtadvdconfig
196
197	export RUMP_SERVER=${RUMPCLI}
198	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1
199	unset RUMP_SERVER
200
201	export RUMP_SERVER=${RUMPSRV}
202	atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0
203	atf_check -s exit:0 sleep 3
204	atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE}
205	unset RUMP_SERVER
206
207	export RUMP_SERVER=${RUMPCLI}
208	$DEBUG && dump_entries
209	atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r
210	atf_check -s exit:0 -o match:'advertised' rump.ndp -p
211	atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0
212	atf_check -s exit:0 -o match:'(23h59m|1d0h0m)..s S R' rump.ndp -n -a
213	atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a
214	atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6
215
216	# Terminate rtadvd to prevent new RA messages from coming
217	# Note that ifconfig down; kill -TERM doesn't work
218	kill -KILL `cat ${PIDFILE}`
219
220	# Flush all the entries in the prefix list
221	atf_check -s exit:0 rump.ndp -P
222
223	$DEBUG && dump_entries
224	atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r
225	atf_check -s exit:0 -o empty rump.ndp -p
226	atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0
227	atf_check -s exit:0 -o match:'(23h59m|1d0h0m)..s S R' rump.ndp -n -a
228	atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a
229	atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6
230	unset RUMP_SERVER
231
232	rump_server_destroy_ifaces
233}
234
235ra_flush_prefix_entries_cleanup()
236{
237
238	$DEBUG && dump
239	cleanup
240}
241
242atf_test_case ra_flush_defrouter_entries cleanup
243ra_flush_defrouter_entries_head()
244{
245
246	atf_set "descr" "Tests for flushing default routers (ndp -R)"
247	atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig"
248}
249
250ra_flush_defrouter_entries_body()
251{
252
253	rump_server_fs_start $RUMPSRV netinet6
254	rump_server_start $RUMPCLI netinet6
255
256	setup_shmif0 ${RUMPSRV} ${IP6SRV}
257	setup_shmif0 ${RUMPCLI} ${IP6CLI}
258
259	export RUMP_SERVER=${RUMPSRV}
260	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.forwarding=1
261	export LD_PRELOAD=/usr/lib/librumphijack.so
262	atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd
263	unset LD_PRELOAD
264	unset RUMP_SERVER
265
266	create_rtadvdconfig
267
268	export RUMP_SERVER=${RUMPCLI}
269	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1
270	unset RUMP_SERVER
271
272	export RUMP_SERVER=${RUMPSRV}
273	atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0
274	atf_check -s exit:0 sleep 3
275	atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE}
276	unset RUMP_SERVER
277
278	export RUMP_SERVER=${RUMPCLI}
279	$DEBUG && dump_entries
280	atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r
281	atf_check -s exit:0 -o match:'advertised' rump.ndp -p
282	atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0
283	atf_check -s exit:0 -o match:'(23h59m|1d0h0m)..s S R' rump.ndp -n -a
284	atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a
285	atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6
286
287	# Terminate rtadvd to prevent new RA messages from coming
288	# Note that ifconfig down; kill -TERM doesn't work
289	kill -KILL `cat ${PIDFILE}`
290
291	# Flush all the entries in the default router list
292	atf_check -s exit:0 rump.ndp -R
293
294	$DEBUG && dump_entries
295	atf_check -s exit:0 -o empty rump.ndp -r
296	atf_check -s exit:0 -o match:'No advertising router' rump.ndp -p
297	atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0
298	atf_check -s exit:0 -o match:'(23h59m|1d0h0m)..s S R' rump.ndp -n -a
299	atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a
300	atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6
301	unset RUMP_SERVER
302
303	rump_server_destroy_ifaces
304}
305
306ra_flush_defrouter_entries_cleanup()
307{
308
309	$DEBUG && dump
310	cleanup
311}
312
313atf_init_test_cases()
314{
315
316	atf_add_test_case ra_basic
317	atf_add_test_case ra_flush_prefix_entries
318	atf_add_test_case ra_flush_defrouter_entries
319}
320