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