1 # $NetBSD: t_gif.sh,v 1.5 2016/08/10 08:29:20 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 server="rump_server -v -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \
29 -lrumpnet_netinet6 -lrumpnet_shmif -lrumpnet_gif"
30 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
32 SOCK1=unix://commsock1 # for ROUTER1
33 SOCK2=unix://commsock2 # for ROUTER2
34 ROUTER1_LANIP=192.168.1.1
35 ROUTER1_LANNET=192.168.1.0/24
36 ROUTER1_WANIP=10.0.0.1
37 ROUTER1_GIFIP=172.16.1.1
38 ROUTER1_WANIP_DUMMY=10.0.0.11
39 ROUTER1_GIFIP_DUMMY=172.16.11.1
40 ROUTER1_GIFIP_RECURSIVE1=172.16.101.1
41 ROUTER1_GIFIP_RECURSIVE2=172.16.201.1
42 ROUTER2_LANIP=192.168.2.1
43 ROUTER2_LANNET=192.168.2.0/24
44 ROUTER2_WANIP=10.0.0.2
45 ROUTER2_GIFIP=172.16.2.1
46 ROUTER2_WANIP_DUMMY=10.0.0.12
47 ROUTER2_GIFIP_DUMMY=172.16.12.1
48 ROUTER2_GIFIP_RECURSIVE1=172.16.102.1
49 ROUTER2_GIFIP_RECURSIVE2=172.16.202.1
51 ROUTER1_LANIP6=fc00:1::1
52 ROUTER1_LANNET6=fc00:1::/64
53 ROUTER1_WANIP6=fc00::1
54 ROUTER1_GIFIP6=fc00:3::1
55 ROUTER1_WANIP6_DUMMY=fc00::11
56 ROUTER1_GIFIP6_DUMMY=fc00:13::1
57 ROUTER1_GIFIP6_RECURSIVE1=fc00:103::1
58 ROUTER1_GIFIP6_RECURSIVE2=fc00:203::1
59 ROUTER2_LANIP6=fc00:2::1
60 ROUTER2_LANNET6=fc00:2::/64
61 ROUTER2_WANIP6=fc00::2
62 ROUTER2_GIFIP6=fc00:4::1
63 ROUTER2_WANIP6_DUMMY=fc00::12
64 ROUTER2_GIFIP6_DUMMY=fc00:14::1
65 ROUTER2_GIFIP6_RECURSIVE1=fc00:104::1
66 ROUTER2_GIFIP6_RECURSIVE2=fc00:204::1
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}
84 atf_check -s exit:0 rump.ifconfig shmif0 inet ${lan} netmask 0xffffff00
86 atf_check -s exit:0 rump.ifconfig shmif0 up
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}
94 atf_check -s exit:0 rump.ifconfig shmif1 inet ${wan} netmask 0xff000000
96 atf_check -s exit:0 rump.ifconfig shmif1 up
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}
113 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${lan}
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}
120 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${wan}
129 atf_check -s exit:0 ${server} $SOCK1
130 atf_check -s exit:0 ${server} $SOCK2
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"
142 router1_lan=$ROUTER1_LANIP
143 router1_lan_mode="ipv4"
144 router2_lan=$ROUTER2_LANIP
145 router2_lan_mode="ipv4"
148 if [ ${outer} = "ipv6" ]; then
149 setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
151 setup_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
154 setup_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
156 setup_router $SOCK2 ${router2_lan} ${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"
176 router1_lan=$ROUTER1_LANIP
177 router1_lan_mode="ipv4"
178 router2_lan=$ROUTER2_LANIP
179 router2_lan_mode="ipv4"
181 if [ ${outer} = "ipv6" ]; then
182 test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
184 test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
187 test_router $SOCK1 ${router1_lan} ${router1_lan_mode} \
189 test_router $SOCK2 ${router2_lan} ${router2_lan_mode} \
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}
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}
230 if [ ${inner} = "ipv6" ]; then
232 remote=$ROUTER2_GIFIP6
233 peernet=$ROUTER2_LANNET6
236 remote=$ROUTER2_GIFIP
237 peernet=$ROUTER2_LANNET
239 if [ ${outer} = "ipv6" ]; then
246 setup_if_gif $SOCK1 ${addr} ${remote} ${inner} \
247 ${src} ${dst} ${peernet}
249 if [ $inner = "ipv6" ]; then
251 remote=$ROUTER1_GIFIP6
252 peernet=$ROUTER1_LANNET6
255 remote=$ROUTER1_GIFIP
256 peernet=$ROUTER1_LANNET
258 if [ $outer = "ipv6" ]; then
265 setup_if_gif $SOCK2 ${addr} ${remote} ${inner} \
266 ${src} ${dst} ${peernet}
275 if [ ${mode} = "ipv6" ]; then
276 peernet=$ROUTER2_LANNET6
279 peernet=$ROUTER2_LANNET
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}
286 if [ ${mode} = "ipv6" ]; then
287 peernet=$ROUTER1_LANNET6
290 peernet=$ROUTER1_LANNET
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}
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
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
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}
324 atf_check -s exit:0 rump.ifconfig gif1 inet ${addr}/32 ${remote}
340 if [ ${inner} = "ipv6" ]; then
341 addr=$ROUTER1_GIFIP6_DUMMY
342 remote=$ROUTER2_GIFIP6_DUMMY
344 addr=$ROUTER1_GIFIP_DUMMY
345 remote=$ROUTER2_GIFIP_DUMMY
347 if [ ${outer} = "ipv6" ]; then
348 src=$ROUTER1_WANIP6_DUMMY
349 dst=$ROUTER2_WANIP6_DUMMY
351 src=$ROUTER1_WANIP_DUMMY
352 dst=$ROUTER2_WANIP_DUMMY
354 setup_dummy_if_gif $SOCK1 ${addr} ${remote} ${inner} \
357 if [ $inner = "ipv6" ]; then
358 addr=$ROUTER2_GIFIP6_DUMMY
359 remote=$ROUTER1_GIFIP6_DUMMY
361 addr=$ROUTER2_GIFIP_DUMMY
362 remote=$ROUTER1_GIFIP_DUMMY
364 if [ $outer = "ipv6" ]; then
365 src=$ROUTER2_WANIP6_DUMMY
366 dst=$ROUTER1_WANIP6_DUMMY
368 src=$ROUTER2_WANIP_DUMMY
369 dst=$ROUTER1_WANIP_DUMMY
371 setup_dummy_if_gif $SOCK2 ${addr} ${remote} ${inner} \
375 test_setup_dummy_tunnel()
377 export RUMP_SERVER=$SOCK1
378 atf_check -s exit:0 -o match:gif1 rump.ifconfig
380 export RUMP_SERVER=$SOCK2
381 atf_check -s exit:0 -o match:gif1 rump.ifconfig
384 teardown_dummy_tunnel()
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
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
395 setup_recursive_if_gif()
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}
411 atf_check -s exit:0 rump.ifconfig ${gif} inet ${addr}/32 ${remote}
417 # test in ROUTER1 only
418 setup_recursive_tunnels()
427 if [ ${mode} = "ipv6" ]; then
428 addr=$ROUTER1_GIFIP6_RECURSIVE1
429 remote=$ROUTER2_GIFIP6_RECURSIVE1
433 addr=$ROUTER1_GIFIP_RECURSIVE1
434 remote=$ROUTER2_GIFIP_RECURSIVE1
438 setup_recursive_if_gif $SOCK1 gif1 ${addr} ${remote} ${mode} \
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
447 addr=$ROUTER1_GIFIP_RECURSIVE2
448 remote=$ROUTER2_GIFIP_RECURSIVE2
449 src=$ROUTER1_GIFIP_RECURSIVE1
450 dst=$ROUTER2_GIFIP_RECURSIVE1
452 setup_recursive_if_gif $SOCK1 gif2 ${addr} ${remote} ${mode} \
456 # test in router1 only
457 test_recursive_check()
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
466 atf_check -s not-exit:0 -o ignore -e ignore \
467 rump.ping -n -w $TIMEOUT -c 1 $ROUTER2_GIFIP_RECURSIVE2
470 atf_check -o match:'gif0: recursively called too many times' \
471 -x "$HIJACKING dmesg"
476 teardown_recursive_tunnels()
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
487 env RUMP_SERVER=$SOCK1 rump.halt
488 env RUMP_SERVER=$SOCK2 rump.halt
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 -
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 \
507 atf_check -s not-exit:0 -o ignore -e ignore \
508 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
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 \
518 atf_check -s not-exit:0 -o ignore -e ignore \
519 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
528 export RUMP_SERVER=$SOCK1
529 rump.ifconfig -v gif0
530 if [ ${mode} = "ipv6" ]; then
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 \
539 atf_check -s exit:0 -o ignore \
540 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER1_LANIP \
543 rump.ifconfig -v gif0
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 \
552 atf_check -s exit:0 -o ignore \
553 rump.ping -n -w $TIMEOUT -c 1 -I $ROUTER2_LANIP \
556 rump.ifconfig -v gif0
559 test_change_tunnel_duplicate()
565 if [ ${mode} = "ipv6" ]; then
566 newsrc=$ROUTER1_WANIP6_DUMMY
567 newdst=$ROUTER2_WANIP6_DUMMY
569 newsrc=$ROUTER1_WANIP_DUMMY
570 newdst=$ROUTER2_WANIP_DUMMY
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
580 if [ ${mode} = "ipv6" ]; then
581 newsrc=$ROUTER2_WANIP6_DUMMY
582 newdst=$ROUTER1_WANIP6_DUMMY
584 newsrc=$ROUTER2_WANIP_DUMMY
585 newdst=$ROUTER1_WANIP_DUMMY
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
596 test_change_tunnel_success()
602 if [ ${mode} = "ipv6" ]; then
603 newsrc=$ROUTER1_WANIP6_DUMMY
604 newdst=$ROUTER2_WANIP6_DUMMY
606 newsrc=$ROUTER1_WANIP_DUMMY
607 newdst=$ROUTER2_WANIP_DUMMY
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
615 if [ ${mode} = "ipv6" ]; then
616 newsrc=$ROUTER2_WANIP6_DUMMY
617 newdst=$ROUTER1_WANIP6_DUMMY
619 newsrc=$ROUTER2_WANIP_DUMMY
620 newdst=$ROUTER1_WANIP_DUMMY
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
634 setup ${inner} ${outer}
635 test_setup ${inner} ${outer}
637 # Enable once PR kern/49219 is fixed
640 setup_tunnel ${inner} ${outer}
642 test_setup_tunnel ${inner}
650 test_ping_success ${inner}
659 test_ping_failure ${inner}
667 setup ${inner} ${outer}
668 test_setup ${inner} ${outer}
670 # Enable once PR kern/49219 is fixed
673 setup_tunnel ${inner} ${outer}
674 setup_dummy_tunnel ${inner} ${outer}
676 test_setup_tunnel ${inner}
684 test_ping_success ${inner}
686 test_change_tunnel_duplicate ${outer}
688 teardown_dummy_tunnel
689 test_change_tunnel_success ${outer}
698 test_ping_failure ${inner}
706 setup ${inner} ${outer}
707 test_setup ${inner} ${outer}
709 # Enable once PR kern/49219 is fixed
712 setup_tunnel ${inner} ${outer}
713 setup_recursive_tunnels ${inner}
715 test_setup_tunnel ${inner}
723 test_recursive_check ${inner}
731 teardown_recursive_tunnels
742 name="${category}${inner}over${outer}"
743 fulldesc="Does ${inner} over ${outer} if_gif ${desc}"
745 atf_test_case ${name} cleanup
746 eval "${name}_head() { \
747 atf_set \"descr\" \"${fulldesc}\"; \
748 atf_set \"require.progs\" \"rump_server\"; \
751 ${category}_setup ${inner} ${outer}; \
752 ${category}_test ${inner} ${outer}; \
753 ${category}_teardown ${inner} ${outer}; \
755 ${name}_cleanup() { \
759 atf_add_test_case ${name}
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
773 atf_init_test_cases()
775 add_test_allproto basic "basic tests"
776 add_test_allproto ioctl "ioctl tests"
777 add_test_allproto recursive "recursive check tests"