t_ipv6address.sh revision 313498
1#	$NetBSD: t_ipv6address.sh,v 1.7 2016/08/10 21:33:52 kre 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
27SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
28SERVER6="$SERVER -lrumpnet_netinet6"
29
30SOCKSRC=unix://commsock1
31SOCKFWD=unix://commsock2
32SOCKDST=unix://commsock3
33IP6SRCNW=fc00:1::0/64
34IP6SRC=fc00:1::1
35IP6DSTNW=fc00:2::0/64
36IP6DST=fc00:2::1
37IP6FWD0=fc00:3::1
38BUS1=bus1
39BUS2=bus2
40BUSSRC=bus_src
41BUSDST=bus_dst
42
43DEBUG=true
44TIMEOUT=3
45
46atf_test_case linklocal cleanup
47atf_test_case linklocal_ops cleanup
48
49setup()
50{
51	atf_check -s exit:0 ${SERVER6} ${SOCKSRC}
52	atf_check -s exit:0 ${SERVER6} ${SOCKFWD}
53	atf_check -s exit:0 ${SERVER6} ${SOCKDST}
54
55	export RUMP_SERVER=${SOCKSRC}
56	atf_check -s exit:0 rump.ifconfig shmif0 create
57	atf_check -s exit:0 rump.ifconfig shmif1 create
58	unset RUMP_SERVER
59
60	export RUMP_SERVER=${SOCKDST}
61	atf_check -s exit:0 rump.ifconfig shmif0 create
62	atf_check -s exit:0 rump.ifconfig shmif1 create
63	unset RUMP_SERVER
64
65	export RUMP_SERVER=${SOCKFWD}
66	atf_check -s exit:0 rump.ifconfig shmif0 create
67	atf_check -s exit:0 rump.ifconfig shmif1 create
68	atf_check -s exit:0 -o match:"0 -> 1" rump.sysctl \
69	    -w net.inet6.ip6.forwarding=1
70	unset RUMP_SERVER
71
72	setup_ifcfg
73
74	export RUMP_SERVER=${SOCKSRC}
75	$DEBUG && rump.ifconfig
76	$DEBUG && rump.netstat -rn -f inet6
77	unset RUMP_SERVER
78
79	export RUMP_SERVER=${SOCKDST}
80	$DEBUG && rump.ifconfig
81	$DEBUG && rump.netstat -rn -f inet6
82	unset RUMP_SERVER
83
84	export RUMP_SERVER=${SOCKFWD}
85	$DEBUG && rump.ifconfig
86	$DEBUG && rump.netstat -rn -f inet6
87	unset RUMP_SERVER
88}
89setup_ifcfg()
90{
91	export RUMP_SERVER=${SOCKSRC}
92	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1}
93	atf_check -s exit:0 rump.ifconfig shmif0 up
94	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUSSRC}
95	atf_check -s exit:0 rump.ifconfig shmif1 up
96	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
97	unset RUMP_SERVER
98
99	export RUMP_SERVER=${SOCKDST}
100	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS2}
101	atf_check -s exit:0 rump.ifconfig shmif0 up
102	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUSDST}
103	atf_check -s exit:0 rump.ifconfig shmif1 up
104	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
105	unset RUMP_SERVER
106
107	export RUMP_SERVER=${SOCKFWD}
108	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1}
109	atf_check -s exit:0 rump.ifconfig shmif0 up
110
111	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUS2}
112	atf_check -s exit:0 rump.ifconfig shmif1 up
113	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
114	unset RUMP_SERVER
115}
116
117setup_route()
118{
119	local tmp_rump_server=$RUMP_SERVER
120
121	local src_if0_lladdr=`get_lladdr ${SOCKSRC} shmif0`
122	local dst_if0_lladdr=`get_lladdr ${SOCKDST} shmif0`
123	local fwd_if0_lladdr=`get_lladdr ${SOCKFWD} shmif0`
124	local fwd_if1_lladdr=`get_lladdr ${SOCKFWD} shmif1`
125
126	export RUMP_SERVER=${SOCKSRC}
127	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 default \
128	    ${fwd_if0_lladdr}%shmif0
129	atf_check -s exit:0 -o match:"add net default:" rump.route add -inet6 default \
130	    ${fwd_if0_lladdr}%shmif0
131	atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6SRC}
132	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
133	$DEBUG && rump.netstat -rn -f inet6
134	unset RUMP_SERVER
135
136	export RUMP_SERVER=${SOCKDST}
137	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 default \
138	    ${fwd_if1_lladdr}%shmif0
139	atf_check -s exit:0 -o match:"add net default:" rump.route add -inet6 default \
140	    ${fwd_if1_lladdr}%shmif0
141	atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DST}
142	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
143	$DEBUG && rump.netstat -rn -f inet6
144	unset RUMP_SERVER
145
146	export RUMP_SERVER=${SOCKFWD}
147	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 ${IP6SRCNW} \
148	    ${src_if0_lladdr}%shmif0
149	atf_check -s exit:0 -o match:"add net" rump.route add -inet6 ${IP6SRCNW} \
150	    ${src_if0_lladdr}%shmif0
151
152	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 ${IP6DSTNW} \
153	    ${dst_if0_lladdr}%shmif1
154	atf_check -s exit:0 -o match:"add net" rump.route add -inet6 ${IP6DSTNW} \
155	    ${dst_if0_lladdr}%shmif1
156	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
157	$DEBUG && rump.netstat -rn -f inet6
158	unset RUMP_SERVER
159
160	export RUMP_SERVER=$tmp_rump_server
161}
162
163cleanup_bus()
164{
165	local tmp_rump_server=$RUMP_SERVER
166
167	$DEBUG && dump_bus
168
169	export RUMP_SERVER=${SOCKSRC}
170	atf_check -s exit:0 rump.ifconfig shmif0 down
171	atf_check -s exit:0 rump.ifconfig shmif0 -linkstr
172	atf_check -s exit:0 rump.ifconfig shmif1 down
173	atf_check -s exit:0 rump.ifconfig shmif1 -linkstr
174	unset RUMP_SERVER
175
176	export RUMP_SERVER=${SOCKDST}
177	atf_check -s exit:0 rump.ifconfig shmif0 down
178	atf_check -s exit:0 rump.ifconfig shmif0 -linkstr
179	atf_check -s exit:0 rump.ifconfig shmif1 down
180	atf_check -s exit:0 rump.ifconfig shmif1 -linkstr
181	unset RUMP_SERVER
182
183	export RUMP_SERVER=${SOCKFWD}
184	atf_check -s exit:0 rump.ifconfig shmif0 down
185	atf_check -s exit:0 rump.ifconfig shmif0 -linkstr
186	atf_check -s exit:0 rump.ifconfig shmif1 down
187	atf_check -s exit:0 rump.ifconfig shmif1 -linkstr
188	unset RUMP_SERVER
189
190	atf_check -s exit:0 rm ${BUSSRC}
191	atf_check -s exit:0 rm ${BUSDST}
192	atf_check -s exit:0 rm ${BUS1}
193	atf_check -s exit:0 rm ${BUS2}
194
195	setup_ifcfg
196
197	export RUMP_SERVER=$tmp_rump_server
198}
199
200
201get_lladdr()
202{
203	export RUMP_SERVER=${1}
204	rump.ifconfig ${2} inet6 | grep "fe80" \
205	    | awk '{print $2}' | sed -e "s/%$2//g"
206	unset RUMP_SERVER
207
208	return 0
209}
210
211cleanup_rump_servers()
212{
213
214	env RUMP_SERVER=${SOCKSRC} rump.halt
215	env RUMP_SERVER=${SOCKDST} rump.halt
216	env RUMP_SERVER=${SOCKFWD} rump.halt
217}
218
219dump_bus()
220{
221
222	shmif_dumpbus -p - ${BUSSRC} 2>/dev/null| tcpdump -n -e -r -
223	shmif_dumpbus -p - ${BUSDST} 2>/dev/null| tcpdump -n -e -r -
224	shmif_dumpbus -p - ${BUS1} 2>/dev/null| tcpdump -n -e -r -
225	shmif_dumpbus -p - ${BUS2} 2>/dev/null| tcpdump -n -e -r -
226}
227
228dump()
229{
230
231	export RUMP_SERVER=${SOCKSRC}
232	rump.ndp -n -a
233	rump.netstat -nr -f inet6
234	export RUMP_SERVER=${SOCKDST}
235	rump.ndp -n -a
236	rump.netstat -nr -f inet6
237	export RUMP_SERVER=${SOCKFWD}
238	rump.ndp -n -a
239	rump.netstat -nr -f inet6
240	unset RUMP_SERVER
241}
242
243linklocal_head()
244{
245	atf_set "descr" "Test for bassically function of the IPv6 linklocal address"
246	atf_set "require.progs" "rump_server rump.route rump.ifconfig rump.ping6"
247}
248
249linklocal_body()
250{
251	setup
252
253	local src_if0_lladdr=`get_lladdr ${SOCKSRC} shmif0`
254	local src_if1_lladdr=`get_lladdr ${SOCKSRC} shmif1`
255	local dst_if0_lladdr=`get_lladdr ${SOCKDST} shmif0`
256	local fwd_if0_lladdr=`get_lladdr ${SOCKFWD} shmif0`
257	local fwd_if1_lladdr=`get_lladdr ${SOCKFWD} shmif1`
258
259	export RUMP_SERVER=${SOCKSRC}
260	$DEBUG && rump.ifconfig
261	$DEBUG && rump.netstat -rn -f inet6
262
263	# link local address to link local address
264
265	atf_check -s not-exit:0 -e match:"No route to host" \
266	    rump.ping6 -c 1 -X $TIMEOUT -n ${fwd_if0_lladdr}
267
268	atf_check -s exit:0 -o match:"0.0% packet loss" \
269	    rump.ping6 -c 1 -X $TIMEOUT -n ${fwd_if0_lladdr}%shmif0
270
271	atf_check -s ignore -o empty -e ignore \
272	    -x "shmif_dumpbus -p - ${BUSSRC} | tcpdump -r - -n -p icmp6"
273	atf_check -s ignore -o not-empty -e ignore \
274	    -x "shmif_dumpbus -p - ${BUS1} | tcpdump -r - -n -p icmp6"
275
276	cleanup_bus
277
278	atf_check -s not-exit:0 -o ignore -e ignore \
279	    rump.ping6 -c 1 -X $TIMEOUT -n -S ${src_if1_lladdr}%shmif1 \
280	    ${fwd_if0_lladdr}%shmif0
281	atf_check -s ignore -o not-match:"${src_if1_lladdr}" -e ignore \
282	    -x "shmif_dumpbus -p - ${BUS1} | tcpdump -r - -n -p icmp6"
283	$DEBUG && shmif_dumpbus -p - ${BUS1} | tcpdump -r - -n -p icmp6
284	unset RUMP_SERVER
285
286	# link local address to host address
287	export RUMP_SERVER=${SOCKFWD}
288	atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6FWD0}
289	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
290	unset RUMP_SERVER
291
292	export RUMP_SERVER=${SOCKSRC}
293	atf_check -s exit:0 -o match:"add net default:" rump.route add -inet6 default \
294	    ${fwd_if0_lladdr}%shmif0
295	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
296
297	$DEBUG && rump.ifconfig shmif0
298	$DEBUG && dump
299
300	export RUMP_SERVER=${SOCKSRC}
301	atf_check -s exit:0 -o match:"0.0% packet loss" \
302	    rump.ping6 -c 1 -X $TIMEOUT -n -S ${src_if0_lladdr}%shmif0 ${IP6FWD0}
303	unset RUMP_SERVER
304
305	export RUMP_SERVER=${SOCKFWD}
306	# host address to link local address
307	atf_check -s exit:0 -o match:"0.0% packet loss" \
308	    rump.ping6 -c 1 -X $TIMEOUT -n ${src_if0_lladdr}%shmif0
309	atf_check -s not-exit:0 -o match:"100.0% packet loss" \
310	    rump.ping6 -c 1 -X $TIMEOUT -n ${src_if1_lladdr}%shmif0
311
312	atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6FWD0} delete
313
314	unset RUMP_SERVER
315
316	# forwarding with link local address
317	setup_route
318
319	export RUMP_SERVER=${SOCKSRC}
320	atf_check -s exit:0 -o match:"0.0% packet loss" rump.ping6 -c 1 \
321	    -X $TIMEOUT -n -S ${IP6SRC} ${IP6DST}
322
323	cleanup_bus
324	$DEBUG && rump.ifconfig shmif0
325	atf_check -s not-exit:0 -o match:"100.0% packet loss" rump.ping6 -c 1 \
326	    -X $TIMEOUT -n -S ${src_if0_lladdr}%shmif0 ${IP6DST}
327	atf_check -s ignore -o not-match:"${src_if0_lladdr}" -e ignore \
328	    -x "shmif_dumpbus -p - ${BUS2} | tcpdump -r - -n -p icmp6"
329
330	cleanup_bus
331	atf_check -s not-exit:0 -o match:"100.0% packet loss" rump.ping6 -c 1 \
332	    -X $TIMEOUT -n -S ${IP6SRC} ${dst_if0_lladdr}%shmif0
333	atf_check -s ignore -o not-empty -e ignore \
334	    -x "shmif_dumpbus -p - ${BUS2} | tcpdump -r - -n -p icmp6"
335
336	unset RUMP_SERVER
337
338}
339
340linklocal_cleanup()
341{
342
343	$DEBUG && dump
344	$DEBUG && dump_bus
345	cleanup_rump_servers
346}
347
348linklocal_ops_head()
349{
350
351	atf_set "descr" "Test for various operations to IPv6 linklocal addresses"
352	atf_set "require.progs" "rump_server rump.route rump.ndp"
353}
354
355linklocal_ops_body()
356{
357	local src_if0_lladdr=
358
359	setup
360
361	src_if0_lladdr=`get_lladdr ${SOCKSRC} shmif0`
362
363	export RUMP_SERVER=${SOCKSRC}
364
365	# route get
366	atf_check -s exit:0 -o match:"${src_if0_lladdr}" \
367	    rump.route get -inet6 ${src_if0_lladdr}%shmif0
368
369	# route get without an interface name (zone index)
370	atf_check -s not-exit:0 -e match:"not in table" \
371	    rump.route get -inet6 ${src_if0_lladdr}
372
373	# ndp
374	atf_check -s exit:0 -o match:"${src_if0_lladdr}" \
375	    rump.ndp -n ${src_if0_lladdr}%shmif0
376
377	# ndp without an interface name (zone index)
378	atf_check -s not-exit:0 -o ignore -e match:"no entry" \
379	    rump.ndp -n ${src_if0_lladdr}
380}
381
382
383linklocal_ops_cleanup()
384{
385
386	cleanup_rump_servers
387}
388
389atf_init_test_cases()
390{
391
392	atf_add_test_case linklocal
393	atf_add_test_case linklocal_ops
394}
395