t_tap.sh revision 1.11
1#	$NetBSD: t_tap.sh,v 1.11 2020/09/30 14:43:15 roy 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
28SOCK_LOCAL=unix://commsock1
29SOCK_REMOTE=unix://commsock2
30BUS=bus1
31IP4_LOCAL=10.0.0.1
32IP4_TAP=10.0.0.2
33IP4_REMOTE=10.0.0.3
34IP6_LOCAL=fc00::1
35IP6_TAP=fc00::2
36IP6_REMOTE=fc00::3
37TAP_PID=./.__tap.pid
38
39DEBUG=${DEBUG:-false}
40TIMEOUT=1
41
42atf_test_case tap_create_destroy cleanup
43tap_create_destroy_head()
44{
45
46	atf_set "descr" "tests of creation and deletion of tap interface"
47	atf_set "require.progs" "rump_server"
48}
49
50tap_create_destroy_body()
51{
52
53	rump_server_fs_start $SOCK_LOCAL netinet6 tap
54
55	test_create_destroy_common $SOCK_LOCAL tap0 true
56}
57
58tap_create_destroy_cleanup()
59{
60
61	$DEBUG && dump
62	cleanup
63}
64
65atf_test_case tap_stand_alone cleanup
66tap_create_destroy_head()
67{
68
69	atf_set "descr" "tests of alone tap interface"
70	atf_set "require.progs" "rump_server"
71}
72
73tap_stand_alone_body()
74{
75
76	rump_server_fs_start $SOCK_LOCAL netinet6 tap
77	rump_server_fs_start $SOCK_REMOTE netinet6 tap
78
79	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
80	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
81
82	export RUMP_SERVER=${SOCK_LOCAL}
83	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_LOCAL
84	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_LOCAL
85	atf_check -s exit:0 rump.ifconfig shmif0 up
86	atf_check -s exit:0 rump.ifconfig -w 10
87
88	export RUMP_SERVER=${SOCK_REMOTE}
89
90	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_REMOTE
91	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_REMOTE
92	atf_check -s exit:0 rump.ifconfig shmif0 up
93	atf_check -s exit:0 rump.ifconfig -w 10
94
95	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_LOCAL
96	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_LOCAL
97
98	export RUMP_SERVER=${SOCK_LOCAL}
99	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_LOCAL delete
100	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_LOCAL delete
101	rump_server_add_iface $SOCK_LOCAL tap0
102	atf_check -s exit:0 rump.ifconfig tap0 $IP4_TAP
103	atf_check -s exit:0 rump.ifconfig tap0 inet6 $IP6_TAP
104	atf_check -s exit:0 rump.ifconfig tap0 up
105	atf_check -s exit:0 rump.ifconfig -w 10
106
107	export RUMP_SERVER=${SOCK_REMOTE}
108	# Cannot reach to an alone tap
109	atf_check -s not-exit:0 -o ignore -e ignore \
110	    rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
111	atf_check -s not-exit:0 -o ignore -e ignore \
112	    rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
113
114	rump_server_destroy_ifaces
115}
116
117tap_stand_alone_cleanup()
118{
119
120	$DEBUG && dump
121	cleanup
122}
123
124atf_test_case tap_bridged cleanup
125tap_bridged_head()
126{
127
128	atf_set "descr" "tests of alone tap interface"
129	atf_set "require.progs" "rump_server"
130}
131
132tap_bridged_body()
133{
134	local src="$(atf_get_srcdir)"
135
136	rump_server_fs_start $SOCK_LOCAL netinet6 tap bridge
137	rump_server_fs_start $SOCK_REMOTE netinet6 tap
138
139	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
140	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
141
142	export RUMP_SERVER=${SOCK_LOCAL}
143
144	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_LOCAL
145	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_LOCAL
146	atf_check -s exit:0 rump.ifconfig shmif0 up
147	rump_server_add_iface $SOCK_LOCAL tap0
148	atf_check -s exit:0 rump.ifconfig tap0 $IP4_TAP
149	atf_check -s exit:0 rump.ifconfig tap0 inet6 $IP6_TAP
150	atf_check -s exit:0 rump.ifconfig tap0 up
151
152	rump_server_add_iface $SOCK_LOCAL bridge0
153	atf_check -s exit:0 rump.ifconfig bridge0 up
154	export LD_PRELOAD=/usr/lib/librumphijack.so
155	atf_check -s exit:0 brconfig bridge0 add shmif0
156	atf_check -s exit:0 brconfig bridge0 add tap0
157	unset LD_PRELOAD
158
159	atf_check -s exit:0 rump.ifconfig -w 10
160
161	export RUMP_SERVER=${SOCK_REMOTE}
162
163	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_REMOTE
164	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6_REMOTE
165	atf_check -s exit:0 rump.ifconfig shmif0 up
166	atf_check -s exit:0 rump.ifconfig -w 10
167
168	# shmif0 on the server bridge is active, we expect this to work
169	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_LOCAL
170	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_LOCAL
171
172	# The tap is not open, we expect this to fail
173	atf_check -s not-exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
174	atf_check -s not-exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
175
176	# Open the tap on the server
177	export RUMP_SERVER=${SOCK_LOCAL}
178	atf_check -s exit:0 "$src"/rump_open_tap /dev/tap0 $TAP_PID
179	atf_check -s exit:0 rump.ifconfig -w 10
180
181	# Now we can ping the tap address
182	export RUMP_SERVER=${SOCK_LOCAL}
183	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
184	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
185
186	rump_server_destroy_ifaces
187}
188
189tap_bridged_cleanup()
190{
191
192        if [ -f $TAP_PID ]; then
193		kill -9 $(cat $TAP_PID)
194		rm -f $TAP_PID
195		sleep 1
196	fi
197	$DEBUG && dump
198	cleanup
199}
200
201atf_init_test_cases()
202{
203
204	atf_add_test_case tap_create_destroy
205	atf_add_test_case tap_stand_alone
206	atf_add_test_case tap_bridged
207}
208