1 # $NetBSD: t_tun.sh,v 1.4 2016/11/07 05:25:37 ozaki-r Exp $
3 # Copyright (c) 2016 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 RUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6"
29 RUMP_FLAGS="$RUMP_FLAGS -lrumpnet_shmif -lrumpnet_tun -lrumpdev"
32 SOCK_LOCAL=unix://commsock1
33 SOCK_REMOTE=unix://commsock2
39 atf_test_case tun_create_destroy cleanup
40 tun_create_destroy_head()
43 atf_set "descr" "tests of creation and deletion of tun interface"
44 atf_set "require.progs" "rump_server"
47 tun_create_destroy_body()
50 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
52 export RUMP_SERVER=${SOCK_LOCAL}
54 atf_check -s exit:0 rump.ifconfig tun0 create
55 atf_check -s exit:0 rump.ifconfig tun0 up
56 atf_check -s exit:0 rump.ifconfig tun0 down
57 atf_check -s exit:0 rump.ifconfig tun0 destroy
60 tun_create_destroy_cleanup()
63 RUMP_SERVER=${SOCK_LOCAL} rump.halt
66 atf_test_case tun_setup cleanup
70 atf_set "descr" "tests of setting up a tunnel"
71 atf_set "require.progs" "rump_server"
76 local ip=$(echo $1 |sed 's/\./\\./g')
81 atf_check -s exit:0 -o match:" $flags " -e ignore -x \
82 "rump.netstat -rn -f inet | grep ^'$ip'"
83 atf_check -s exit:0 -o match:" $gw " -e ignore -x \
84 "rump.netstat -rn -f inet | grep ^'$ip'"
85 atf_check -s exit:0 -o match:" $iface" -e ignore -x \
86 "rump.netstat -rn -f inet | grep ^'$ip'"
92 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
93 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_REMOTE}
95 export RUMP_SERVER=${SOCK_LOCAL}
97 atf_check -s exit:0 rump.ifconfig shmif0 create
98 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
99 atf_check -s exit:0 rump.ifconfig shmif0 ${IP_LOCAL}/24 up
100 atf_check -s exit:0 rump.ifconfig -w 10
102 export RUMP_SERVER=${SOCK_REMOTE}
104 atf_check -s exit:0 rump.ifconfig shmif0 create
105 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
106 atf_check -s exit:0 rump.ifconfig shmif0 ${IP_REMOTE}/24 up
107 atf_check -s exit:0 rump.ifconfig -w 10
109 export RUMP_SERVER=${SOCK_LOCAL}
110 atf_check -s exit:0 rump.ifconfig tun0 create
111 atf_check -s exit:0 rump.ifconfig tun0 ${IP_LOCAL} ${IP_REMOTE} up
112 atf_check -s exit:0 \
113 -o match:"inet ${IP_LOCAL}/32 -> ${IP_REMOTE}" rump.ifconfig tun0
114 $DEBUG && rump.netstat -nr -f inet
115 check_route_entry ${IP_REMOTE} ${IP_LOCAL} UH tun0
117 export RUMP_SERVER=${SOCK_REMOTE}
118 atf_check -s exit:0 rump.ifconfig tun0 create
119 atf_check -s exit:0 rump.ifconfig tun0 ${IP_REMOTE} ${IP_LOCAL} up
120 atf_check -s exit:0 \
121 -o match:"inet ${IP_REMOTE}/32 -> ${IP_LOCAL}" rump.ifconfig tun0
122 $DEBUG && rump.netstat -nr -f inet
123 check_route_entry ${IP_LOCAL} ${IP_REMOTE} UH tun0
129 RUMP_SERVER=${SOCK_LOCAL} rump.halt
130 RUMP_SERVER=${SOCK_REMOTE} rump.halt
133 atf_init_test_cases()
136 atf_add_test_case tun_create_destroy
137 atf_add_test_case tun_setup