xref: /freebsd/contrib/netbsd-tests/net/if_gif/t_gif.sh (revision 3fc36ee018bb836bd1796067cf4ef8683f166ebc)
1#	$NetBSD: t_gif.sh,v 1.5 2016/08/10 08:29:20 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
28server="rump_server -v -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \
29		    -lrumpnet_netinet6 -lrumpnet_shmif -lrumpnet_gif"
30HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
31
32SOCK1=unix://commsock1 # for ROUTER1
33SOCK2=unix://commsock2 # for ROUTER2
34ROUTER1_LANIP=192.168.1.1
35ROUTER1_LANNET=192.168.1.0/24
36ROUTER1_WANIP=10.0.0.1
37ROUTER1_GIFIP=172.16.1.1
38ROUTER1_WANIP_DUMMY=10.0.0.11
39ROUTER1_GIFIP_DUMMY=172.16.11.1
40ROUTER1_GIFIP_RECURSIVE1=172.16.101.1
41ROUTER1_GIFIP_RECURSIVE2=172.16.201.1
42ROUTER2_LANIP=192.168.2.1
43ROUTER2_LANNET=192.168.2.0/24
44ROUTER2_WANIP=10.0.0.2
45ROUTER2_GIFIP=172.16.2.1
46ROUTER2_WANIP_DUMMY=10.0.0.12
47ROUTER2_GIFIP_DUMMY=172.16.12.1
48ROUTER2_GIFIP_RECURSIVE1=172.16.102.1
49ROUTER2_GIFIP_RECURSIVE2=172.16.202.1
50
51ROUTER1_LANIP6=fc00:1::1
52ROUTER1_LANNET6=fc00:1::/64
53ROUTER1_WANIP6=fc00::1
54ROUTER1_GIFIP6=fc00:3::1
55ROUTER1_WANIP6_DUMMY=fc00::11
56ROUTER1_GIFIP6_DUMMY=fc00:13::1
57ROUTER1_GIFIP6_RECURSIVE1=fc00:103::1
58ROUTER1_GIFIP6_RECURSIVE2=fc00:203::1
59ROUTER2_LANIP6=fc00:2::1
60ROUTER2_LANNET6=fc00:2::/64
61ROUTER2_WANIP6=fc00::2
62ROUTER2_GIFIP6=fc00:4::1
63ROUTER2_WANIP6_DUMMY=fc00::12
64ROUTER2_GIFIP6_DUMMY=fc00:14::1
65ROUTER2_GIFIP6_RECURSIVE1=fc00:104::1
66ROUTER2_GIFIP6_RECURSIVE2=fc00:204::1
67
68TIMEOUT=5
69
70setup_router()
71{
72	sock=${1}
73	lan=${2}
74	lan_mode=${3}
75	wan=${4}
76	wan_mode=${5}
77
78	export RUMP_SERVER=${sock}
79	atf_check -s exit:0 rump.ifconfig shmif0 create
80	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus0
81	if [ ${lan_mode} = "ipv6" ]; then
82		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${lan}
83	else
84		atf_check -s exit:0 rump.ifconfig shmif0 inet ${lan} netmask 0xffffff00
85	fi
86	atf_check -s exit:0 rump.ifconfig shmif0 up
87	rump.ifconfig shmif0
88
89	atf_check -s exit:0 rump.ifconfig shmif1 create
90	atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus1
91	if [ ${wan_mode} = "ipv6" ]; then
92		atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${wan}
93	else
94		atf_check -s exit:0 rump.ifconfig shmif1 inet ${wan} netmask 0xff000000
95	fi
96	atf_check -s exit:0 rump.ifconfig shmif1 up
97	rump.ifconfig shmif1
98}
99
100test_router()
101{
102	sock=${1}
103	lan=${2}
104	lan_mode=${3}
105	wan=${4}
106	wan_mode=${5}
107
108	export RUMP_SERVER=${sock}
109	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
110	if [ ${lan_mode} = "ipv6" ]; then
111		atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${lan}
112	else
113		atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${lan}
114	fi
115
116	atf_check -s exit:0 -o match:shmif1 rump.ifconfig
117	if [ ${wan_mode} = "ipv6" ]; then
118		atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${wan}
119	else
120		atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${wan}
121	fi
122}
123
124setup()
125{
126	inner=${1}
127	outer=${2}
128
129	atf_check -s exit:0 ${server} $SOCK1
130	atf_check -s exit:0 ${server} $SOCK2
131
132	router1_lan=""
133	router1_lan_mode=""
134	router2_lan=""
135	router2_lan_mode=""
136	if [ ${inner} = "ipv6" ]; then
137		router1_lan=$ROUTER1_LANIP6
138		router1_lan_mode="ipv6"
139		router2_lan=$ROUTER2_LANIP6
140		router2_lan_mode="ipv6"
141	else
142		router1_lan=$ROUTER1_LANIP
143		router1_lan_mode="ipv4"
144		router2_lan=$ROUTER2_LANIP
145		router2_lan_mode="ipv4"
146	fi
147
148	if [ ${outer} = "ipv6" ]; then
149		setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
150			$ROUTER1_WANIP6 ipv6
151		setup_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
152			$ROUTER2_WANIP6 ipv6
153	else
154		setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
155			$ROUTER1_WANIP ipv4
156		setup_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
157			$ROUTER2_WANIP ipv4
158	fi
159}
160
161test_setup()
162{
163	inner=${1}
164	outer=${2}
165
166	router1_lan=""
167	router1_lan_mode=""
168	router2_lan=""
169	router2_lan_mode=""
170	if [ ${inner} = "ipv6" ]; then
171		router1_lan=$ROUTER1_LANIP6
172		router1_lan_mode="ipv6"
173		router2_lan=$ROUTER2_LANIP6
174		router2_lan_mode="ipv6"
175	else
176		router1_lan=$ROUTER1_LANIP
177		router1_lan_mode="ipv4"
178		router2_lan=$ROUTER2_LANIP
179		router2_lan_mode="ipv4"
180	fi
181	if [ ${outer} = "ipv6" ]; then
182		test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
183			$ROUTER1_WANIP6 ipv6
184		test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
185			$ROUTER2_WANIP6 ipv6
186	else
187		test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
188			$ROUTER1_WANIP ipv4
189		test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
190			$ROUTER2_WANIP ipv4
191	fi
192}
193
194setup_if_gif()
195{
196	sock=${1}
197	addr=${2}
198	remote=${3}
199	inner=${4}
200	src=${5}
201	dst=${6}
202	peernet=${7}
203
204	export RUMP_SERVER=${sock}
205	atf_check -s exit:0 rump.ifconfig gif0 create
206	atf_check -s exit:0 rump.ifconfig gif0 tunnel ${src} ${dst}
207	if [ ${inner} = "ipv6" ]; then
208		atf_check -s exit:0 rump.ifconfig gif0 inet6 ${addr}/128 ${remote}
209		atf_check -s exit:0 -o ignore rump.route add -inet6 ${peernet} ${addr}
210	else
211		atf_check -s exit:0 rump.ifconfig gif0 inet ${addr}/32 ${remote}
212		atf_check -s exit:0 -o ignore rump.route add -inet ${peernet} ${addr}
213	fi
214
215	rump.ifconfig gif0
216	rump.route -nL show
217}
218
219setup_tunnel()
220{
221	inner=${1}
222	outer=${2}
223
224	addr=""
225	remote=""
226	src=""
227	dst=""
228	peernet=""
229
230	if [ ${inner} = "ipv6" ]; then
231		addr=$ROUTER1_GIFIP6
232		remote=$ROUTER2_GIFIP6
233		peernet=$ROUTER2_LANNET6
234	else
235		addr=$ROUTER1_GIFIP
236		remote=$ROUTER2_GIFIP
237		peernet=$ROUTER2_LANNET
238	fi
239	if [ ${outer} = "ipv6" ]; then
240		src=$ROUTER1_WANIP6
241		dst=$ROUTER2_WANIP6
242	else
243		src=$ROUTER1_WANIP
244		dst=$ROUTER2_WANIP
245	fi
246	setup_if_gif $SOCK1 ${addr} ${remote} ${inner} \
247		     ${src} ${dst} ${peernet}
248
249	if [ $inner = "ipv6" ]; then
250		addr=$ROUTER2_GIFIP6
251		remote=$ROUTER1_GIFIP6
252		peernet=$ROUTER1_LANNET6
253	else
254		addr=$ROUTER2_GIFIP
255		remote=$ROUTER1_GIFIP
256		peernet=$ROUTER1_LANNET
257	fi
258	if [ $outer = "ipv6" ]; then
259		src=$ROUTER2_WANIP6
260		dst=$ROUTER1_WANIP6
261	else
262		src=$ROUTER2_WANIP
263		dst=$ROUTER1_WANIP
264	fi
265	setup_if_gif $SOCK2 ${addr} ${remote} ${inner} \
266		     ${src} ${dst} ${peernet}
267}
268
269test_setup_tunnel()
270{
271	mode=${1}
272
273	peernet=""
274	opt=""
275	if [ ${mode} = "ipv6" ]; then
276		peernet=$ROUTER2_LANNET6
277		opt="-inet6"
278	else
279		peernet=$ROUTER2_LANNET
280		opt="-inet"
281	fi
282	export RUMP_SERVER=$SOCK1
283	atf_check -s exit:0 -o match:gif0 rump.ifconfig
284	atf_check -s exit:0 -o match:gif0 rump.route -nL get ${opt} ${peernet}
285
286	if [ ${mode} = "ipv6" ]; then
287		peernet=$ROUTER1_LANNET6
288		opt="-inet6"
289	else
290		peernet=$ROUTER1_LANNET
291		opt="-inet"
292	fi
293	export RUMP_SERVER=$SOCK2
294	atf_check -s exit:0 -o match:gif0 rump.ifconfig
295	atf_check -s exit:0 -o match:gif0 rump.route -nL get ${opt} ${peernet}
296}
297
298teardown_tunnel()
299{
300	export RUMP_SERVER=$SOCK1
301	atf_check -s exit:0 rump.ifconfig gif0 deletetunnel
302	atf_check -s exit:0 rump.ifconfig gif0 destroy
303
304	export RUMP_SERVER=$SOCK2
305	atf_check -s exit:0 rump.ifconfig gif0 deletetunnel
306	atf_check -s exit:0 rump.ifconfig gif0 destroy
307}
308
309setup_dummy_if_gif()
310{
311	sock=${1}
312	addr=${2}
313	remote=${3}
314	inner=${4}
315	src=${5}
316	dst=${6}
317
318	export RUMP_SERVER=${sock}
319	atf_check -s exit:0 rump.ifconfig gif1 create
320	atf_check -s exit:0 rump.ifconfig gif1 tunnel ${src} ${dst}
321	if [ ${inner} = "ipv6" ]; then
322		atf_check -s exit:0 rump.ifconfig gif1 inet6 ${addr}/128 ${remote}
323	else
324		atf_check -s exit:0 rump.ifconfig gif1 inet ${addr}/32 ${remote}
325	fi
326
327	rump.ifconfig gif1
328}
329
330setup_dummy_tunnel()
331{
332	inner=${1}
333	outer=${2}
334
335	addr=""
336	remote=""
337	src=""
338	dst=""
339
340	if [ ${inner} = "ipv6" ]; then
341		addr=$ROUTER1_GIFIP6_DUMMY
342		remote=$ROUTER2_GIFIP6_DUMMY
343	else
344		addr=$ROUTER1_GIFIP_DUMMY
345		remote=$ROUTER2_GIFIP_DUMMY
346	fi
347	if [ ${outer} = "ipv6" ]; then
348		src=$ROUTER1_WANIP6_DUMMY
349		dst=$ROUTER2_WANIP6_DUMMY
350	else
351		src=$ROUTER1_WANIP_DUMMY
352		dst=$ROUTER2_WANIP_DUMMY
353	fi
354	setup_dummy_if_gif $SOCK1 ${addr} ${remote} ${inner} \
355			   ${src} ${dst}
356
357	if [ $inner = "ipv6" ]; then
358		addr=$ROUTER2_GIFIP6_DUMMY
359		remote=$ROUTER1_GIFIP6_DUMMY
360	else
361		addr=$ROUTER2_GIFIP_DUMMY
362		remote=$ROUTER1_GIFIP_DUMMY
363	fi
364	if [ $outer = "ipv6" ]; then
365		src=$ROUTER2_WANIP6_DUMMY
366		dst=$ROUTER1_WANIP6_DUMMY
367	else
368		src=$ROUTER2_WANIP_DUMMY
369		dst=$ROUTER1_WANIP_DUMMY
370	fi
371	setup_dummy_if_gif $SOCK2 ${addr} ${remote} ${inner} \
372			   ${src} ${dst}
373}
374
375test_setup_dummy_tunnel()
376{
377	export RUMP_SERVER=$SOCK1
378	atf_check -s exit:0 -o match:gif1 rump.ifconfig
379
380	export RUMP_SERVER=$SOCK2
381	atf_check -s exit:0 -o match:gif1 rump.ifconfig
382}
383
384teardown_dummy_tunnel()
385{
386	export RUMP_SERVER=$SOCK1
387	atf_check -s exit:0 rump.ifconfig gif1 deletetunnel
388	atf_check -s exit:0 rump.ifconfig gif1 destroy
389
390	export RUMP_SERVER=$SOCK2
391	atf_check -s exit:0 rump.ifconfig gif1 deletetunnel
392	atf_check -s exit:0 rump.ifconfig gif1 destroy
393}
394
395setup_recursive_if_gif()
396{
397	sock=${1}
398	gif=${2}
399	addr=${3}
400	remote=${4}
401	inner=${5}
402	src=${6}
403	dst=${7}
404
405	export RUMP_SERVER=${sock}
406	atf_check -s exit:0 rump.ifconfig ${gif} create
407	atf_check -s exit:0 rump.ifconfig ${gif} tunnel ${src} ${dst}
408	if [ ${inner} = "ipv6" ]; then
409		atf_check -s exit:0 rump.ifconfig ${gif} inet6 ${addr}/128 ${remote}
410	else
411		atf_check -s exit:0 rump.ifconfig ${gif} inet ${addr}/32 ${remote}
412	fi
413
414	rump.ifconfig ${gif}
415}
416
417# test in ROUTER1 only
418setup_recursive_tunnels()
419{
420	mode=${1}
421
422	addr=""
423	remote=""
424	src=""
425	dst=""
426
427	if [ ${mode} = "ipv6" ]; then
428		addr=$ROUTER1_GIFIP6_RECURSIVE1
429		remote=$ROUTER2_GIFIP6_RECURSIVE1
430		src=$ROUTER1_GIFIP6
431		dst=$ROUTER2_GIFIP6
432	else
433		addr=$ROUTER1_GIFIP_RECURSIVE1
434		remote=$ROUTER2_GIFIP_RECURSIVE1
435		src=$ROUTER1_GIFIP
436		dst=$ROUTER2_GIFIP
437	fi
438	setup_recursive_if_gif $SOCK1 gif1 ${addr} ${remote} ${mode} \
439		      ${src} ${dst}
440
441	if [ ${mode} = "ipv6" ]; then
442		addr=$ROUTER1_GIFIP6_RECURSIVE2
443		remote=$ROUTER2_GIFIP6_RECURSIVE2
444		src=$ROUTER1_GIFIP6_RECURSIVE1
445		dst=$ROUTER2_GIFIP6_RECURSIVE1
446	else
447		addr=$ROUTER1_GIFIP_RECURSIVE2
448		remote=$ROUTER2_GIFIP_RECURSIVE2
449		src=$ROUTER1_GIFIP_RECURSIVE1
450		dst=$ROUTER2_GIFIP_RECURSIVE1
451	fi
452	setup_recursive_if_gif $SOCK1 gif2 ${addr} ${remote} ${mode} \
453		      ${src} ${dst}
454}
455
456# test in router1 only
457test_recursive_check()
458{
459	mode=$1
460
461	export RUMP_SERVER=$SOCK1
462	if [ ${mode} = "ipv6" ]; then
463		atf_check -s not-exit:0 -o ignore -e ignore \
464			rump.ping6 -n -X $TIMEOUT -c 1 $ROUTER2_GIFIP6_RECURSIVE2
465	else
466		atf_check -s not-exit:0 -o ignore -e ignore \
467			rump.ping -n -w $TIMEOUT -c 1 $ROUTER2_GIFIP_RECURSIVE2
468	fi
469
470	atf_check -o match:'gif0: recursively called too many times' \
471		-x "$HIJACKING dmesg"
472
473	$HIJACKING dmesg
474}
475
476teardown_recursive_tunnels()
477{
478	export RUMP_SERVER=$SOCK1
479	atf_check -s exit:0 rump.ifconfig gif1 deletetunnel
480	atf_check -s exit:0 rump.ifconfig gif1 destroy
481	atf_check -s exit:0 rump.ifconfig gif2 deletetunnel
482	atf_check -s exit:0 rump.ifconfig gif2 destroy
483}
484
485cleanup()
486{
487	env RUMP_SERVER=$SOCK1 rump.halt
488	env RUMP_SERVER=$SOCK2 rump.halt
489}
490
491dump_bus()
492{
493	/usr/bin/shmif_dumpbus -p - bus0 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
494	/usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
495}
496
497test_ping_failure()
498{
499	mode=$1
500
501	export RUMP_SERVER=$SOCK1
502	if [ ${mode} = "ipv6" ]; then
503		atf_check -s not-exit:0 -o ignore -e ignore \
504			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER1_LANIP6 \
505			$ROUTER2_LANIP6
506	else
507		atf_check -s not-exit:0 -o ignore -e ignore \
508			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
509			$ROUTER2_LANIP
510	fi
511
512	export RUMP_SERVER=$SOCK2
513	if [ ${mode} = "ipv6" ]; then
514		atf_check -s not-exit:0 -o ignore -e ignore \
515			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER2_LANIP6 \
516			$ROUTER1_LANIP6
517	else
518		atf_check -s not-exit:0 -o ignore -e ignore \
519			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
520			$ROUTER2_LANIP
521	fi
522}
523
524test_ping_success()
525{
526	mode=$1
527
528	export RUMP_SERVER=$SOCK1
529	rump.ifconfig -v gif0
530	if [ ${mode} = "ipv6" ]; then
531		# XXX
532		# rump.ping6 rarely fails with the message that
533		# "failed to get receiving hop limit".
534		# This is a known issue being analyzed.
535		atf_check -s exit:0 -o ignore \
536			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER1_LANIP6 \
537			$ROUTER2_LANIP6
538	else
539		atf_check -s exit:0 -o ignore \
540			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
541			$ROUTER2_LANIP
542	fi
543	rump.ifconfig -v gif0
544
545	export RUMP_SERVER=$SOCK2
546	rump.ifconfig -v gif0
547	if [ ${mode} = "ipv6" ]; then
548		atf_check -s exit:0 -o ignore \
549			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER2_LANIP6 \
550			$ROUTER1_LANIP6
551	else
552		atf_check -s exit:0 -o ignore \
553			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER2_LANIP \
554			$ROUTER1_LANIP
555	fi
556	rump.ifconfig -v gif0
557}
558
559test_change_tunnel_duplicate()
560{
561	mode=$1
562
563	newsrc=""
564	newdst=""
565	if [ ${mode} = "ipv6" ]; then
566		newsrc=$ROUTER1_WANIP6_DUMMY
567		newdst=$ROUTER2_WANIP6_DUMMY
568	else
569		newsrc=$ROUTER1_WANIP_DUMMY
570		newdst=$ROUTER2_WANIP_DUMMY
571	fi
572	export RUMP_SERVER=$SOCK1
573	rump.ifconfig -v gif0
574	rump.ifconfig -v gif1
575	atf_check -s exit:0 -e match:SIOCSLIFPHYADDR \
576		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
577	rump.ifconfig -v gif0
578	rump.ifconfig -v gif1
579
580	if [ ${mode} = "ipv6" ]; then
581		newsrc=$ROUTER2_WANIP6_DUMMY
582		newdst=$ROUTER1_WANIP6_DUMMY
583	else
584		newsrc=$ROUTER2_WANIP_DUMMY
585		newdst=$ROUTER1_WANIP_DUMMY
586	fi
587	export RUMP_SERVER=$SOCK2
588	rump.ifconfig -v gif0
589	rump.ifconfig -v gif1
590	atf_check -s exit:0 -e match:SIOCSLIFPHYADDR \
591		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
592	rump.ifconfig -v gif0
593	rump.ifconfig -v gif1
594}
595
596test_change_tunnel_success()
597{
598	mode=$1
599
600	newsrc=""
601	newdst=""
602	if [ ${mode} = "ipv6" ]; then
603		newsrc=$ROUTER1_WANIP6_DUMMY
604		newdst=$ROUTER2_WANIP6_DUMMY
605	else
606		newsrc=$ROUTER1_WANIP_DUMMY
607		newdst=$ROUTER2_WANIP_DUMMY
608	fi
609	export RUMP_SERVER=$SOCK1
610	rump.ifconfig -v gif0
611	atf_check -s exit:0 \
612		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
613	rump.ifconfig -v gif0
614
615	if [ ${mode} = "ipv6" ]; then
616		newsrc=$ROUTER2_WANIP6_DUMMY
617		newdst=$ROUTER1_WANIP6_DUMMY
618	else
619		newsrc=$ROUTER2_WANIP_DUMMY
620		newdst=$ROUTER1_WANIP_DUMMY
621	fi
622	export RUMP_SERVER=$SOCK2
623	rump.ifconfig -v gif0
624	atf_check -s exit:0 \
625		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
626	rump.ifconfig -v gif0
627}
628
629basic_setup()
630{
631	inner=$1
632	outer=$2
633
634	setup ${inner} ${outer}
635	test_setup ${inner} ${outer}
636
637	# Enable once PR kern/49219 is fixed
638	#test_ping_failure
639
640	setup_tunnel ${inner} ${outer}
641	sleep 1
642	test_setup_tunnel ${inner}
643}
644
645basic_test()
646{
647	inner=$1
648	outer=$2 # not use
649
650	test_ping_success ${inner}
651}
652
653basic_teardown()
654{
655	inner=$1
656	outer=$2 # not use
657
658	teardown_tunnel
659	test_ping_failure ${inner}
660}
661
662ioctl_setup()
663{
664	inner=$1
665	outer=$2
666
667	setup ${inner} ${outer}
668	test_setup ${inner} ${outer}
669
670	# Enable once PR kern/49219 is fixed
671	#test_ping_failure
672
673	setup_tunnel ${inner} ${outer}
674	setup_dummy_tunnel ${inner} ${outer}
675	sleep 1
676	test_setup_tunnel ${inner}
677}
678
679ioctl_test()
680{
681	inner=$1
682	outer=$2
683
684	test_ping_success ${inner}
685
686	test_change_tunnel_duplicate ${outer}
687
688	teardown_dummy_tunnel
689	test_change_tunnel_success ${outer}
690}
691
692ioctl_teardown()
693{
694	inner=$1
695	outer=$2 # not use
696
697	teardown_tunnel
698	test_ping_failure ${inner}
699}
700
701recursive_setup()
702{
703	inner=$1
704	outer=$2
705
706	setup ${inner} ${outer}
707	test_setup ${inner} ${outer}
708
709	# Enable once PR kern/49219 is fixed
710	#test_ping_failure
711
712	setup_tunnel ${inner} ${outer}
713	setup_recursive_tunnels ${inner}
714	sleep 1
715	test_setup_tunnel ${inner}
716}
717
718recursive_test()
719{
720	inner=$1
721	outer=$2 # not use
722
723	test_recursive_check ${inner}
724}
725
726recursive_teardown()
727{
728	inner=$1 # not use
729	outer=$2 # not use
730
731	teardown_recursive_tunnels
732	teardown_tunnel
733}
734
735add_test()
736{
737	category=$1
738	desc=$2
739	inner=$3
740	outer=$4
741
742	name="${category}${inner}over${outer}"
743	fulldesc="Does ${inner} over ${outer} if_gif ${desc}"
744
745	atf_test_case ${name} cleanup
746	eval "${name}_head() { \
747			atf_set \"descr\" \"${fulldesc}\"; \
748			atf_set \"require.progs\" \"rump_server\"; \
749		}; \
750	    ${name}_body() { \
751			${category}_setup ${inner} ${outer}; \
752			${category}_test ${inner} ${outer}; \
753			${category}_teardown ${inner} ${outer}; \
754	    }; \
755	    ${name}_cleanup() { \
756			dump_bus; \
757			cleanup; \
758		}"
759	atf_add_test_case ${name}
760}
761
762add_test_allproto()
763{
764	category=$1
765	desc=$2
766
767	add_test ${category} "${desc}" ipv4 ipv4
768	add_test ${category} "${desc}" ipv4 ipv6
769	add_test ${category} "${desc}" ipv6 ipv4
770	add_test ${category} "${desc}" ipv6 ipv6
771}
772
773atf_init_test_cases()
774{
775	add_test_allproto basic "basic tests"
776	add_test_allproto ioctl "ioctl tests"
777	add_test_allproto recursive "recursive check tests"
778}
779