summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/net/if_gif/t_gif.sh
blob: b804d7b21cc44c5a8f85126da2b9f2cc9eaa9eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
#	$NetBSD: t_gif.sh,v 1.5 2016/08/10 08:29:20 ozaki-r Exp $
#
# Copyright (c) 2015 Internet Initiative Japan Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

server="rump_server -v -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \
		    -lrumpnet_netinet6 -lrumpnet_shmif -lrumpnet_gif"
HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"

SOCK1=unix://commsock1 # for ROUTER1
SOCK2=unix://commsock2 # for ROUTER2
ROUTER1_LANIP=192.168.1.1
ROUTER1_LANNET=192.168.1.0/24
ROUTER1_WANIP=10.0.0.1
ROUTER1_GIFIP=172.16.1.1
ROUTER1_WANIP_DUMMY=10.0.0.11
ROUTER1_GIFIP_DUMMY=172.16.11.1
ROUTER1_GIFIP_RECURSIVE1=172.16.101.1
ROUTER1_GIFIP_RECURSIVE2=172.16.201.1
ROUTER2_LANIP=192.168.2.1
ROUTER2_LANNET=192.168.2.0/24
ROUTER2_WANIP=10.0.0.2
ROUTER2_GIFIP=172.16.2.1
ROUTER2_WANIP_DUMMY=10.0.0.12
ROUTER2_GIFIP_DUMMY=172.16.12.1
ROUTER2_GIFIP_RECURSIVE1=172.16.102.1
ROUTER2_GIFIP_RECURSIVE2=172.16.202.1

ROUTER1_LANIP6=fc00:1::1
ROUTER1_LANNET6=fc00:1::/64
ROUTER1_WANIP6=fc00::1
ROUTER1_GIFIP6=fc00:3::1
ROUTER1_WANIP6_DUMMY=fc00::11
ROUTER1_GIFIP6_DUMMY=fc00:13::1
ROUTER1_GIFIP6_RECURSIVE1=fc00:103::1
ROUTER1_GIFIP6_RECURSIVE2=fc00:203::1
ROUTER2_LANIP6=fc00:2::1
ROUTER2_LANNET6=fc00:2::/64
ROUTER2_WANIP6=fc00::2
ROUTER2_GIFIP6=fc00:4::1
ROUTER2_WANIP6_DUMMY=fc00::12
ROUTER2_GIFIP6_DUMMY=fc00:14::1
ROUTER2_GIFIP6_RECURSIVE1=fc00:104::1
ROUTER2_GIFIP6_RECURSIVE2=fc00:204::1

TIMEOUT=5

setup_router()
{
	sock=${1}
	lan=${2}
	lan_mode=${3}
	wan=${4}
	wan_mode=${5}

	export RUMP_SERVER=${sock}
	atf_check -s exit:0 rump.ifconfig shmif0 create
	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus0
	if [ ${lan_mode} = "ipv6" ]; then
		atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${lan}
	else
		atf_check -s exit:0 rump.ifconfig shmif0 inet ${lan} netmask 0xffffff00
	fi
	atf_check -s exit:0 rump.ifconfig shmif0 up
	rump.ifconfig shmif0

	atf_check -s exit:0 rump.ifconfig shmif1 create
	atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus1
	if [ ${wan_mode} = "ipv6" ]; then
		atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${wan}
	else
		atf_check -s exit:0 rump.ifconfig shmif1 inet ${wan} netmask 0xff000000
	fi
	atf_check -s exit:0 rump.ifconfig shmif1 up
	rump.ifconfig shmif1
}

test_router()
{
	sock=${1}
	lan=${2}
	lan_mode=${3}
	wan=${4}
	wan_mode=${5}

	export RUMP_SERVER=${sock}
	atf_check -s exit:0 -o match:shmif0 rump.ifconfig
	if [ ${lan_mode} = "ipv6" ]; then
		atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${lan}
	else
		atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${lan}
	fi

	atf_check -s exit:0 -o match:shmif1 rump.ifconfig
	if [ ${wan_mode} = "ipv6" ]; then
		atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${wan}
	else
		atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${wan}
	fi
}

setup()
{
	inner=${1}
	outer=${2}

	atf_check -s exit:0 ${server} $SOCK1
	atf_check -s exit:0 ${server} $SOCK2

	router1_lan=""
	router1_lan_mode=""
	router2_lan=""
	router2_lan_mode=""
	if [ ${inner} = "ipv6" ]; then
		router1_lan=$ROUTER1_LANIP6
		router1_lan_mode="ipv6"
		router2_lan=$ROUTER2_LANIP6
		router2_lan_mode="ipv6"
	else
		router1_lan=$ROUTER1_LANIP
		router1_lan_mode="ipv4"
		router2_lan=$ROUTER2_LANIP
		router2_lan_mode="ipv4"
	fi

	if [ ${outer} = "ipv6" ]; then
		setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
			$ROUTER1_WANIP6 ipv6
		setup_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
			$ROUTER2_WANIP6 ipv6
	else
		setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
			$ROUTER1_WANIP ipv4
		setup_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
			$ROUTER2_WANIP ipv4
	fi
}

test_setup()
{
	inner=${1}
	outer=${2}

	router1_lan=""
	router1_lan_mode=""
	router2_lan=""
	router2_lan_mode=""
	if [ ${inner} = "ipv6" ]; then
		router1_lan=$ROUTER1_LANIP6
		router1_lan_mode="ipv6"
		router2_lan=$ROUTER2_LANIP6
		router2_lan_mode="ipv6"
	else
		router1_lan=$ROUTER1_LANIP
		router1_lan_mode="ipv4"
		router2_lan=$ROUTER2_LANIP
		router2_lan_mode="ipv4"
	fi
	if [ ${outer} = "ipv6" ]; then
		test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
			$ROUTER1_WANIP6 ipv6
		test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
			$ROUTER2_WANIP6 ipv6
	else
		test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
			$ROUTER1_WANIP ipv4
		test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
			$ROUTER2_WANIP ipv4
	fi
}

setup_if_gif()
{
	sock=${1}
	addr=${2}
	remote=${3}
	inner=${4}
	src=${5}
	dst=${6}
	peernet=${7}

	export RUMP_SERVER=${sock}
	atf_check -s exit:0 rump.ifconfig gif0 create
	atf_check -s exit:0 rump.ifconfig gif0 tunnel ${src} ${dst}
	if [ ${inner} = "ipv6" ]; then
		atf_check -s exit:0 rump.ifconfig gif0 inet6 ${addr}/128 ${remote}
		atf_check -s exit:0 -o ignore rump.route add -inet6 ${peernet} ${addr}
	else
		atf_check -s exit:0 rump.ifconfig gif0 inet ${addr}/32 ${remote}
		atf_check -s exit:0 -o ignore rump.route add -inet ${peernet} ${addr}
	fi

	rump.ifconfig gif0
	rump.route -nL show
}

setup_tunnel()
{
	inner=${1}
	outer=${2}

	addr=""
	remote=""
	src=""
	dst=""
	peernet=""

	if [ ${inner} = "ipv6" ]; then
		addr=$ROUTER1_GIFIP6
		remote=$ROUTER2_GIFIP6
		peernet=$ROUTER2_LANNET6
	else
		addr=$ROUTER1_GIFIP
		remote=$ROUTER2_GIFIP
		peernet=$ROUTER2_LANNET
	fi
	if [ ${outer} = "ipv6" ]; then
		src=$ROUTER1_WANIP6
		dst=$ROUTER2_WANIP6
	else
		src=$ROUTER1_WANIP
		dst=$ROUTER2_WANIP
	fi
	setup_if_gif $SOCK1 ${addr} ${remote} ${inner} \
		     ${src} ${dst} ${peernet}

	if [ $inner = "ipv6" ]; then
		addr=$ROUTER2_GIFIP6
		remote=$ROUTER1_GIFIP6
		peernet=$ROUTER1_LANNET6
	else
		addr=$ROUTER2_GIFIP
		remote=$ROUTER1_GIFIP
		peernet=$ROUTER1_LANNET
	fi
	if [ $outer = "ipv6" ]; then
		src=$ROUTER2_WANIP6
		dst=$ROUTER1_WANIP6
	else
		src=$ROUTER2_WANIP
		dst=$ROUTER1_WANIP
	fi
	setup_if_gif $SOCK2 ${addr} ${remote} ${inner} \
		     ${src} ${dst} ${peernet}
}

test_setup_tunnel()
{
	mode=${1}

	peernet=""
	opt=""
	if [ ${mode} = "ipv6" ]; then
		peernet=$ROUTER2_LANNET6
		opt="-inet6"
	else
		peernet=$ROUTER2_LANNET
		opt="-inet"
	fi
	export RUMP_SERVER=$SOCK1
	atf_check -s exit:0 -o match:gif0 rump.ifconfig
	atf_check -s exit:0 -o match:gif0 rump.route -nL get ${opt} ${peernet}

	if [ ${mode} = "ipv6" ]; then
		peernet=$ROUTER1_LANNET6
		opt="-inet6"
	else
		peernet=$ROUTER1_LANNET
		opt="-inet"
	fi
	export RUMP_SERVER=$SOCK2
	atf_check -s exit:0 -o match:gif0 rump.ifconfig
	atf_check -s exit:0 -o match:gif0 rump.route -nL get ${opt} ${peernet}
}

teardown_tunnel()
{
	export RUMP_SERVER=$SOCK1
	atf_check -s exit:0 rump.ifconfig gif0 deletetunnel
	atf_check -s exit:0 rump.ifconfig gif0 destroy

	export RUMP_SERVER=$SOCK2
	atf_check -s exit:0 rump.ifconfig gif0 deletetunnel
	atf_check -s exit:0 rump.ifconfig gif0 destroy
}

setup_dummy_if_gif()
{
	sock=${1}
	addr=${2}
	remote=${3}
	inner=${4}
	src=${5}
	dst=${6}

	export RUMP_SERVER=${sock}
	atf_check -s exit:0 rump.ifconfig gif1 create
	atf_check -s exit:0 rump.ifconfig gif1 tunnel ${src} ${dst}
	if [ ${inner} = "ipv6" ]; then
		atf_check -s exit:0 rump.ifconfig gif1 inet6 ${addr}/128 ${remote}
	else
		atf_check -s exit:0 rump.ifconfig gif1 inet ${addr}/32 ${remote}
	fi

	rump.ifconfig gif1
}

setup_dummy_tunnel()
{
	inner=${1}
	outer=${2}

	addr=""
	remote=""
	src=""
	dst=""

	if [ ${inner} = "ipv6" ]; then
		addr=$ROUTER1_GIFIP6_DUMMY
		remote=$ROUTER2_GIFIP6_DUMMY
	else
		addr=$ROUTER1_GIFIP_DUMMY
		remote=$ROUTER2_GIFIP_DUMMY
	fi
	if [ ${outer} = "ipv6" ]; then
		src=$ROUTER1_WANIP6_DUMMY
		dst=$ROUTER2_WANIP6_DUMMY
	else
		src=$ROUTER1_WANIP_DUMMY
		dst=$ROUTER2_WANIP_DUMMY
	fi
	setup_dummy_if_gif $SOCK1 ${addr} ${remote} ${inner} \
			   ${src} ${dst}

	if [ $inner = "ipv6" ]; then
		addr=$ROUTER2_GIFIP6_DUMMY
		remote=$ROUTER1_GIFIP6_DUMMY
	else
		addr=$ROUTER2_GIFIP_DUMMY
		remote=$ROUTER1_GIFIP_DUMMY
	fi
	if [ $outer = "ipv6" ]; then
		src=$ROUTER2_WANIP6_DUMMY
		dst=$ROUTER1_WANIP6_DUMMY
	else
		src=$ROUTER2_WANIP_DUMMY
		dst=$ROUTER1_WANIP_DUMMY
	fi
	setup_dummy_if_gif $SOCK2 ${addr} ${remote} ${inner} \
			   ${src} ${dst}
}

test_setup_dummy_tunnel()
{
	export RUMP_SERVER=$SOCK1
	atf_check -s exit:0 -o match:gif1 rump.ifconfig

	export RUMP_SERVER=$SOCK2
	atf_check -s exit:0 -o match:gif1 rump.ifconfig
}

teardown_dummy_tunnel()
{
	export RUMP_SERVER=$SOCK1
	atf_check -s exit:0 rump.ifconfig gif1 deletetunnel
	atf_check -s exit:0 rump.ifconfig gif1 destroy

	export RUMP_SERVER=$SOCK2
	atf_check -s exit:0 rump.ifconfig gif1 deletetunnel
	atf_check -s exit:0 rump.ifconfig gif1 destroy
}

setup_recursive_if_gif()
{
	sock=${1}
	gif=${2}
	addr=${3}
	remote=${4}
	inner=${5}
	src=${6}
	dst=${7}

	export RUMP_SERVER=${sock}
	atf_check -s exit:0 rump.ifconfig ${gif} create
	atf_check -s exit:0 rump.ifconfig ${gif} tunnel ${src} ${dst}
	if [ ${inner} = "ipv6" ]; then
		atf_check -s exit:0 rump.ifconfig ${gif} inet6 ${addr}/128 ${remote}
	else
		atf_check -s exit:0 rump.ifconfig ${gif} inet ${addr}/32 ${remote}
	fi

	rump.ifconfig ${gif}
}

# test in ROUTER1 only
setup_recursive_tunnels()
{
	mode=${1}

	addr=""
	remote=""
	src=""
	dst=""

	if [ ${mode} = "ipv6" ]; then
		addr=$ROUTER1_GIFIP6_RECURSIVE1
		remote=$ROUTER2_GIFIP6_RECURSIVE1
		src=$ROUTER1_GIFIP6
		dst=$ROUTER2_GIFIP6
	else
		addr=$ROUTER1_GIFIP_RECURSIVE1
		remote=$ROUTER2_GIFIP_RECURSIVE1
		src=$ROUTER1_GIFIP
		dst=$ROUTER2_GIFIP
	fi
	setup_recursive_if_gif $SOCK1 gif1 ${addr} ${remote} ${mode} \
		      ${src} ${dst}

	if [ ${mode} = "ipv6" ]; then
		addr=$ROUTER1_GIFIP6_RECURSIVE2
		remote=$ROUTER2_GIFIP6_RECURSIVE2
		src=$ROUTER1_GIFIP6_RECURSIVE1
		dst=$ROUTER2_GIFIP6_RECURSIVE1
	else
		addr=$ROUTER1_GIFIP_RECURSIVE2
		remote=$ROUTER2_GIFIP_RECURSIVE2
		src=$ROUTER1_GIFIP_RECURSIVE1
		dst=$ROUTER2_GIFIP_RECURSIVE1
	fi
	setup_recursive_if_gif $SOCK1 gif2 ${addr} ${remote} ${mode} \
		      ${src} ${dst}
}

# test in router1 only
test_recursive_check()
{
	mode=$1

	export RUMP_SERVER=$SOCK1
	if [ ${mode} = "ipv6" ]; then
		atf_check -s not-exit:0 -o ignore -e ignore \
			rump.ping6 -n -X $TIMEOUT -c 1 $ROUTER2_GIFIP6_RECURSIVE2
	else
		atf_check -s not-exit:0 -o ignore -e ignore \
			rump.ping -n -w $TIMEOUT -c 1 $ROUTER2_GIFIP_RECURSIVE2
	fi

	atf_check -o match:'gif0: recursively called too many times' \
		-x "$HIJACKING dmesg"

	$HIJACKING dmesg
}

teardown_recursive_tunnels()
{
	export RUMP_SERVER=$SOCK1
	atf_check -s exit:0 rump.ifconfig gif1 deletetunnel
	atf_check -s exit:0 rump.ifconfig gif1 destroy
	atf_check -s exit:0 rump.ifconfig gif2 deletetunnel
	atf_check -s exit:0 rump.ifconfig gif2 destroy
}

cleanup()
{
	env RUMP_SERVER=$SOCK1 rump.halt
	env RUMP_SERVER=$SOCK2 rump.halt
}

dump_bus()
{
	/usr/bin/shmif_dumpbus -p - bus0 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
	/usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
}

test_ping_failure()
{
	mode=$1

	export RUMP_SERVER=$SOCK1
	if [ ${mode} = "ipv6" ]; then
		atf_check -s not-exit:0 -o ignore -e ignore \
			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER1_LANIP6 \
			$ROUTER2_LANIP6
	else
		atf_check -s not-exit:0 -o ignore -e ignore \
			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
			$ROUTER2_LANIP
	fi

	export RUMP_SERVER=$SOCK2
	if [ ${mode} = "ipv6" ]; then
		atf_check -s not-exit:0 -o ignore -e ignore \
			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER2_LANIP6 \
			$ROUTER1_LANIP6
	else
		atf_check -s not-exit:0 -o ignore -e ignore \
			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
			$ROUTER2_LANIP
	fi
}

test_ping_success()
{
	mode=$1

	export RUMP_SERVER=$SOCK1
	rump.ifconfig -v gif0
	if [ ${mode} = "ipv6" ]; then
		# XXX
		# rump.ping6 rarely fails with the message that
		# "failed to get receiving hop limit".
		# This is a known issue being analyzed.
		atf_check -s exit:0 -o ignore \
			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER1_LANIP6 \
			$ROUTER2_LANIP6
	else
		atf_check -s exit:0 -o ignore \
			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
			$ROUTER2_LANIP
	fi
	rump.ifconfig -v gif0

	export RUMP_SERVER=$SOCK2
	rump.ifconfig -v gif0
	if [ ${mode} = "ipv6" ]; then
		atf_check -s exit:0 -o ignore \
			rump.ping6 -n -X $TIMEOUT -c 1 -S $ROUTER2_LANIP6 \
			$ROUTER1_LANIP6
	else
		atf_check -s exit:0 -o ignore \
			rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER2_LANIP \
			$ROUTER1_LANIP
	fi
	rump.ifconfig -v gif0
}

test_change_tunnel_duplicate()
{
	mode=$1

	newsrc=""
	newdst=""
	if [ ${mode} = "ipv6" ]; then
		newsrc=$ROUTER1_WANIP6_DUMMY
		newdst=$ROUTER2_WANIP6_DUMMY
	else
		newsrc=$ROUTER1_WANIP_DUMMY
		newdst=$ROUTER2_WANIP_DUMMY
	fi
	export RUMP_SERVER=$SOCK1
	rump.ifconfig -v gif0
	rump.ifconfig -v gif1
	atf_check -s exit:0 -e match:SIOCSLIFPHYADDR \
		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
	rump.ifconfig -v gif0
	rump.ifconfig -v gif1

	if [ ${mode} = "ipv6" ]; then
		newsrc=$ROUTER2_WANIP6_DUMMY
		newdst=$ROUTER1_WANIP6_DUMMY
	else
		newsrc=$ROUTER2_WANIP_DUMMY
		newdst=$ROUTER1_WANIP_DUMMY
	fi
	export RUMP_SERVER=$SOCK2
	rump.ifconfig -v gif0
	rump.ifconfig -v gif1
	atf_check -s exit:0 -e match:SIOCSLIFPHYADDR \
		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
	rump.ifconfig -v gif0
	rump.ifconfig -v gif1
}

test_change_tunnel_success()
{
	mode=$1

	newsrc=""
	newdst=""
	if [ ${mode} = "ipv6" ]; then
		newsrc=$ROUTER1_WANIP6_DUMMY
		newdst=$ROUTER2_WANIP6_DUMMY
	else
		newsrc=$ROUTER1_WANIP_DUMMY
		newdst=$ROUTER2_WANIP_DUMMY
	fi
	export RUMP_SERVER=$SOCK1
	rump.ifconfig -v gif0
	atf_check -s exit:0 \
		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
	rump.ifconfig -v gif0

	if [ ${mode} = "ipv6" ]; then
		newsrc=$ROUTER2_WANIP6_DUMMY
		newdst=$ROUTER1_WANIP6_DUMMY
	else
		newsrc=$ROUTER2_WANIP_DUMMY
		newdst=$ROUTER1_WANIP_DUMMY
	fi
	export RUMP_SERVER=$SOCK2
	rump.ifconfig -v gif0
	atf_check -s exit:0 \
		rump.ifconfig gif0 tunnel ${newsrc} ${newdst}
	rump.ifconfig -v gif0
}

basic_setup()
{
	inner=$1
	outer=$2

	setup ${inner} ${outer}
	test_setup ${inner} ${outer}

	# Enable once PR kern/49219 is fixed
	#test_ping_failure

	setup_tunnel ${inner} ${outer}
	sleep 1
	test_setup_tunnel ${inner}
}

basic_test()
{
	inner=$1
	outer=$2 # not use

	test_ping_success ${inner}
}

basic_teardown()
{
	inner=$1
	outer=$2 # not use

	teardown_tunnel
	test_ping_failure ${inner}
}

ioctl_setup()
{
	inner=$1
	outer=$2

	setup ${inner} ${outer}
	test_setup ${inner} ${outer}

	# Enable once PR kern/49219 is fixed
	#test_ping_failure

	setup_tunnel ${inner} ${outer}
	setup_dummy_tunnel ${inner} ${outer}
	sleep 1
	test_setup_tunnel ${inner}
}

ioctl_test()
{
	inner=$1
	outer=$2

	test_ping_success ${inner}

	test_change_tunnel_duplicate ${outer}

	teardown_dummy_tunnel
	test_change_tunnel_success ${outer}
}

ioctl_teardown()
{
	inner=$1
	outer=$2 # not use

	teardown_tunnel
	test_ping_failure ${inner}
}

recursive_setup()
{
	inner=$1
	outer=$2

	setup ${inner} ${outer}
	test_setup ${inner} ${outer}

	# Enable once PR kern/49219 is fixed
	#test_ping_failure

	setup_tunnel ${inner} ${outer}
	setup_recursive_tunnels ${inner}
	sleep 1
	test_setup_tunnel ${inner}
}

recursive_test()
{
	inner=$1
	outer=$2 # not use

	test_recursive_check ${inner}
}

recursive_teardown()
{
	inner=$1 # not use
	outer=$2 # not use

	teardown_recursive_tunnels
	teardown_tunnel
}

add_test()
{
	category=$1
	desc=$2
	inner=$3
	outer=$4

	name="${category}${inner}over${outer}"
	fulldesc="Does ${inner} over ${outer} if_gif ${desc}"

	atf_test_case ${name} cleanup
	eval "${name}_head() { \
			atf_set \"descr\" \"${fulldesc}\"; \
			atf_set \"require.progs\" \"rump_server\"; \
		}; \
	    ${name}_body() { \
			${category}_setup ${inner} ${outer}; \
			${category}_test ${inner} ${outer}; \
			${category}_teardown ${inner} ${outer}; \
	    }; \
	    ${name}_cleanup() { \
			dump_bus; \
			cleanup; \
		}"
	atf_add_test_case ${name}
}

add_test_allproto()
{
	category=$1
	desc=$2

	add_test ${category} "${desc}" ipv4 ipv4
	add_test ${category} "${desc}" ipv4 ipv6
	add_test ${category} "${desc}" ipv6 ipv4
	add_test ${category} "${desc}" ipv6 ipv6
}

atf_init_test_cases()
{
	add_test_allproto basic "basic tests"
	add_test_allproto ioctl "ioctl tests"
	add_test_allproto recursive "recursive check tests"
}
OpenPOWER on IntegriCloud