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