1 # $NetBSD: t_gif.sh,v 1.9 2016/12/21 09:46:39 ozaki-r Exp $
3 # Copyright (c) 2015 Internet Initiative Japan Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
28 SOCK1=unix://commsock1 # for ROUTER1
29 SOCK2=unix://commsock2 # for ROUTER2
30 ROUTER1_LANIP=192.168.1.1
31 ROUTER1_LANNET=192.168.1.0/24
32 ROUTER1_WANIP=10.0.0.1
33 ROUTER1_GIFIP=172.16.1.1
34 ROUTER1_WANIP_DUMMY=10.0.0.11
35 ROUTER1_GIFIP_DUMMY=172.16.11.1
36 ROUTER1_GIFIP_RECURSIVE1=172.16.101.1
37 ROUTER1_GIFIP_RECURSIVE2=172.16.201.1
38 ROUTER2_LANIP=192.168.2.1
39 ROUTER2_LANNET=192.168.2.0/24
40 ROUTER2_WANIP=10.0.0.2
41 ROUTER2_GIFIP=172.16.2.1
42 ROUTER2_WANIP_DUMMY=10.0.0.12
43 ROUTER2_GIFIP_DUMMY=172.16.12.1
44 ROUTER2_GIFIP_RECURSIVE1=172.16.102.1
45 ROUTER2_GIFIP_RECURSIVE2=172.16.202.1
47 ROUTER1_LANIP6=fc00:1::1
48 ROUTER1_LANNET6=fc00:1::/64
49 ROUTER1_WANIP6=fc00::1
50 ROUTER1_GIFIP6=fc00:3::1
51 ROUTER1_WANIP6_DUMMY=fc00::11
52 ROUTER1_GIFIP6_DUMMY=fc00:13::1
53 ROUTER1_GIFIP6_RECURSIVE1=fc00:103::1
54 ROUTER1_GIFIP6_RECURSIVE2=fc00:203::1
55 ROUTER2_LANIP6=fc00:2::1
56 ROUTER2_LANNET6=fc00:2::/64
57 ROUTER2_WANIP6=fc00::2
58 ROUTER2_GIFIP6=fc00:4::1
59 ROUTER2_WANIP6_DUMMY=fc00::12
60 ROUTER2_GIFIP6_DUMMY=fc00:14::1
61 ROUTER2_GIFIP6_RECURSIVE1=fc00:104::1
62 ROUTER2_GIFIP6_RECURSIVE2=fc00:204::1
75 rump_server_add_iface $sock shmif0 bus0
76 rump_server_add_iface $sock shmif1 bus1
78 export RUMP_SERVER=${sock}
79 if [ ${lan_mode} = "ipv6" ]; then
80 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${lan}
82 atf_check -s exit:0 rump.ifconfig shmif0 inet ${lan} netmask 0xffffff00
84 atf_check -s exit:0 rump.ifconfig shmif0 up
87 if [ ${wan_mode} = "ipv6" ]; then
88 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${wan}
90 atf_check -s exit:0 rump.ifconfig shmif1 inet ${wan} netmask 0xff000000
92 atf_check -s exit:0 rump.ifconfig shmif1 up
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}
109 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${lan}
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}
116 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${wan}
125 rump_server_start $SOCK1 netinet6 gif
126 rump_server_start $SOCK2 netinet6 gif
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"
138 router1_lan=$ROUTER1_LANIP
139 router1_lan_mode="ipv4"
140 router2_lan=$ROUTER2_LANIP
141 router2_lan_mode="ipv4"
144 if [ ${outer} = "ipv6" ]; then
145 setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
147 setup_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
150 setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
152 setup_router $SOCK2 ${router2_lan} ${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"
172 router1_lan=$ROUTER1_LANIP
173 router1_lan_mode="ipv4"
174 router2_lan=$ROUTER2_LANIP
175 router2_lan_mode="ipv4"
177 if [ ${outer} = "ipv6" ]; then
178 test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
180 test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
183 test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
185 test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
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}
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}
226 if [ ${inner} = "ipv6" ]; then
228 remote=$ROUTER2_GIFIP6
229 peernet=$ROUTER2_LANNET6
232 remote=$ROUTER2_GIFIP
233 peernet=$ROUTER2_LANNET
235 if [ ${outer} = "ipv6" ]; then
242 setup_if_gif $SOCK1 ${addr} ${remote} ${inner} \
243 ${src} ${dst} ${peernet}
245 if [ $inner = "ipv6" ]; then
247 remote=$ROUTER1_GIFIP6
248 peernet=$ROUTER1_LANNET6
251 remote=$ROUTER1_GIFIP
252 peernet=$ROUTER1_LANNET
254 if [ $outer = "ipv6" ]; then
261 setup_if_gif $SOCK2 ${addr} ${remote} ${inner} \
262 ${src} ${dst} ${peernet}
271 if [ ${mode} = "ipv6" ]; then
272 peernet=$ROUTER2_LANNET6
275 peernet=$ROUTER2_LANNET
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}
282 if [ ${mode} = "ipv6" ]; then
283 peernet=$ROUTER1_LANNET6
286 peernet=$ROUTER1_LANNET
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}
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
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
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}
320 atf_check -s exit:0 rump.ifconfig gif1 inet ${addr}/32 ${remote}
336 if [ ${inner} = "ipv6" ]; then
337 addr=$ROUTER1_GIFIP6_DUMMY
338 remote=$ROUTER2_GIFIP6_DUMMY
340 addr=$ROUTER1_GIFIP_DUMMY
341 remote=$ROUTER2_GIFIP_DUMMY
343 if [ ${outer} = "ipv6" ]; then
344 src=$ROUTER1_WANIP6_DUMMY
345 dst=$ROUTER2_WANIP6_DUMMY
347 src=$ROUTER1_WANIP_DUMMY
348 dst=$ROUTER2_WANIP_DUMMY
350 setup_dummy_if_gif $SOCK1 ${addr} ${remote} ${inner} \
353 if [ $inner = "ipv6" ]; then
354 addr=$ROUTER2_GIFIP6_DUMMY
355 remote=$ROUTER1_GIFIP6_DUMMY
357 addr=$ROUTER2_GIFIP_DUMMY
358 remote=$ROUTER1_GIFIP_DUMMY
360 if [ $outer = "ipv6" ]; then
361 src=$ROUTER2_WANIP6_DUMMY
362 dst=$ROUTER1_WANIP6_DUMMY
364 src=$ROUTER2_WANIP_DUMMY
365 dst=$ROUTER1_WANIP_DUMMY
367 setup_dummy_if_gif $SOCK2 ${addr} ${remote} ${inner} \
371 test_setup_dummy_tunnel()
373 export RUMP_SERVER=$SOCK1
374 atf_check -s exit:0 -o match:gif1 rump.ifconfig
376 export RUMP_SERVER=$SOCK2
377 atf_check -s exit:0 -o match:gif1 rump.ifconfig
380 teardown_dummy_tunnel()
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
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
391 setup_recursive_if_gif()
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}
407 atf_check -s exit:0 rump.ifconfig ${gif} inet ${addr}/32 ${remote}
413 # test in ROUTER1 only
414 setup_recursive_tunnels()
423 if [ ${mode} = "ipv6" ]; then
424 addr=$ROUTER1_GIFIP6_RECURSIVE1
425 remote=$ROUTER2_GIFIP6_RECURSIVE1
429 addr=$ROUTER1_GIFIP_RECURSIVE1
430 remote=$ROUTER2_GIFIP_RECURSIVE1
434 setup_recursive_if_gif $SOCK1 gif1 ${addr} ${remote} ${mode} \
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
443 addr=$ROUTER1_GIFIP_RECURSIVE2
444 remote=$ROUTER2_GIFIP_RECURSIVE2
445 src=$ROUTER1_GIFIP_RECURSIVE1
446 dst=$ROUTER2_GIFIP_RECURSIVE1
448 setup_recursive_if_gif $SOCK1 gif2 ${addr} ${remote} ${mode} \
452 # test in router1 only
453 test_recursive_check()
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
462 atf_check -s not-exit:0 -o ignore -e ignore \
463 rump.ping -n -w $TIMEOUT -c 1 $ROUTER2_GIFIP_RECURSIVE2
466 atf_check -o match:'gif0: recursively called too many times' \
467 -x "$HIJACKING dmesg"
472 teardown_recursive_tunnels()
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
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 \
491 atf_check -s not-exit:0 -o ignore -e ignore \
492 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
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 \
502 atf_check -s not-exit:0 -o ignore -e ignore \
503 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
512 export RUMP_SERVER=$SOCK1
513 rump.ifconfig -v gif0
514 if [ ${mode} = "ipv6" ]; then
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 \
523 atf_check -s exit:0 -o ignore \
524 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
527 rump.ifconfig -v gif0
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 \
536 atf_check -s exit:0 -o ignore \
537 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER2_LANIP \
540 rump.ifconfig -v gif0
543 test_change_tunnel_duplicate()
549 if [ ${mode} = "ipv6" ]; then
550 newsrc=$ROUTER1_WANIP6_DUMMY
551 newdst=$ROUTER2_WANIP6_DUMMY
553 newsrc=$ROUTER1_WANIP_DUMMY
554 newdst=$ROUTER2_WANIP_DUMMY
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
564 if [ ${mode} = "ipv6" ]; then
565 newsrc=$ROUTER2_WANIP6_DUMMY
566 newdst=$ROUTER1_WANIP6_DUMMY
568 newsrc=$ROUTER2_WANIP_DUMMY
569 newdst=$ROUTER1_WANIP_DUMMY
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
580 test_change_tunnel_success()
586 if [ ${mode} = "ipv6" ]; then
587 newsrc=$ROUTER1_WANIP6_DUMMY
588 newdst=$ROUTER2_WANIP6_DUMMY
590 newsrc=$ROUTER1_WANIP_DUMMY
591 newdst=$ROUTER2_WANIP_DUMMY
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
599 if [ ${mode} = "ipv6" ]; then
600 newsrc=$ROUTER2_WANIP6_DUMMY
601 newdst=$ROUTER1_WANIP6_DUMMY
603 newsrc=$ROUTER2_WANIP_DUMMY
604 newdst=$ROUTER1_WANIP_DUMMY
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
618 setup ${inner} ${outer}
619 test_setup ${inner} ${outer}
621 # Enable once PR kern/49219 is fixed
624 setup_tunnel ${inner} ${outer}
626 test_setup_tunnel ${inner}
634 test_ping_success ${inner}
643 test_ping_failure ${inner}
651 setup ${inner} ${outer}
652 test_setup ${inner} ${outer}
654 # Enable once PR kern/49219 is fixed
657 setup_tunnel ${inner} ${outer}
658 setup_dummy_tunnel ${inner} ${outer}
660 test_setup_tunnel ${inner}
668 test_ping_success ${inner}
670 test_change_tunnel_duplicate ${outer}
672 teardown_dummy_tunnel
673 test_change_tunnel_success ${outer}
682 test_ping_failure ${inner}
690 setup ${inner} ${outer}
691 test_setup ${inner} ${outer}
693 # Enable once PR kern/49219 is fixed
696 setup_tunnel ${inner} ${outer}
697 setup_recursive_tunnels ${inner}
699 test_setup_tunnel ${inner}
707 test_recursive_check ${inner}
715 teardown_recursive_tunnels
726 name="gif_${category}_${inner}over${outer}"
727 fulldesc="Does ${inner} over ${outer} if_gif ${desc}"
729 atf_test_case ${name} cleanup
730 eval "${name}_head() { \
731 atf_set \"descr\" \"${fulldesc}\"; \
732 atf_set \"require.progs\" \"rump_server\"; \
735 ${category}_setup ${inner} ${outer}; \
736 ${category}_test ${inner} ${outer}; \
737 ${category}_teardown ${inner} ${outer}; \
738 rump_server_destroy_ifaces; \
740 ${name}_cleanup() { \
744 atf_add_test_case ${name}
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
758 atf_init_test_cases()
760 add_test_allproto basic "basic tests"
761 add_test_allproto ioctl "ioctl tests"
762 add_test_allproto recursive "recursive check tests"