]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/net/if_tun/t_tun.sh
MFC r314450,r313439:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / net / if_tun / t_tun.sh
1 #       $NetBSD: t_tun.sh,v 1.4 2016/11/07 05:25:37 ozaki-r Exp $
2 #
3 # Copyright (c) 2016 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
28 RUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6"
29 RUMP_FLAGS="$RUMP_FLAGS -lrumpnet_shmif -lrumpnet_tun -lrumpdev"
30
31 BUS=bus
32 SOCK_LOCAL=unix://commsock1
33 SOCK_REMOTE=unix://commsock2
34 IP_LOCAL=10.0.0.1
35 IP_REMOTE=10.0.0.2
36
37 DEBUG=${DEBUG:-true}
38
39 atf_test_case tun_create_destroy cleanup
40 tun_create_destroy_head()
41 {
42
43         atf_set "descr" "tests of creation and deletion of tun interface"
44         atf_set "require.progs" "rump_server"
45 }
46
47 tun_create_destroy_body()
48 {
49
50         atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
51
52         export RUMP_SERVER=${SOCK_LOCAL}
53
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
58 }
59
60 tun_create_destroy_cleanup()
61 {
62
63         RUMP_SERVER=${SOCK_LOCAL} rump.halt
64 }
65
66 atf_test_case tun_setup cleanup
67 tun_setup_head()
68 {
69
70         atf_set "descr" "tests of setting up a tunnel"
71         atf_set "require.progs" "rump_server"
72 }
73
74 check_route_entry()
75 {
76         local ip=$(echo $1 |sed 's/\./\\./g')
77         local gw=$2
78         local flags=$3
79         local iface=$4
80
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'"
87 }
88
89 tun_setup_body()
90 {
91
92         atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
93         atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_REMOTE}
94
95         export RUMP_SERVER=${SOCK_LOCAL}
96
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
101
102         export RUMP_SERVER=${SOCK_REMOTE}
103
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
108
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
116
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
124 }
125
126 tun_setup_cleanup()
127 {
128
129         RUMP_SERVER=${SOCK_LOCAL} rump.halt
130         RUMP_SERVER=${SOCK_REMOTE} rump.halt
131 }
132
133 atf_init_test_cases()
134 {
135
136         atf_add_test_case tun_create_destroy
137         atf_add_test_case tun_setup
138 }