t_l2tp.sh revision 1.3 1 # $NetBSD: t_l2tp.sh,v 1.3 2017/08/03 03:16:26 ozaki-r Exp $
2 #
3 # Copyright (c) 2017 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 LAC1SOCK=unix://commsock1
29 LAC2SOCK=unix://commsock2
30 CLIENT1SOCK=unix://commsock3
31 CLIENT2SOCK=unix://commsock4
32
33 WAN_LINK=bus0
34 LAC1_LAN_LINK=bus1
35 LAC2_LAN_LINK=bus2
36
37 LAC1_WANIP=10.0.0.1
38 LAC1_SESSION=1234
39 CLIENT1_LANIP=192.168.1.1
40 LAC2_WANIP=10.0.0.2
41 LAC2_SESSION=4321
42 CLIENT2_LANIP=192.168.1.2
43
44 LAC1_WANIP6=fc00::1
45 CLIENT1_LANIP6=fc00:1::1
46 LAC2_WANIP6=fc00::2
47 CLIENT2_LANIP6=fc00:1::2
48
49 TIMEOUT=5
50 DEBUG=${DEBUG:-false}
51
52 setup_lac()
53 {
54 sock=${1}
55 lanlink=${2}
56 wan=${3}
57 wan_mode=${4}
58
59
60 rump_server_add_iface ${sock} shmif0 ${lanlink}
61 rump_server_add_iface ${sock} shmif1 ${WAN_LINK}
62
63 export RUMP_SERVER=${sock}
64
65 if [ ${wan_mode} = "ipv6" ]; then
66 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${wan}
67 else
68 atf_check -s exit:0 rump.ifconfig shmif1 inet ${wan} netmask 0xff000000
69 fi
70 atf_check -s exit:0 rump.ifconfig shmif0 up
71 atf_check -s exit:0 rump.ifconfig shmif1 up
72
73 unset RUMP_SERVER
74 }
75
76 test_lac()
77 {
78 sock=${1}
79 wan=${2}
80 wan_mode=${3}
81
82 export RUMP_SERVER=${sock}
83
84 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
85 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
86 if [ ${wan_mode} = "ipv6" ]; then
87 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${wan}
88 else
89 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${wan}
90 fi
91
92 unset RUMP_SERVER
93 }
94
95 setup_client()
96 {
97 sock=${1}
98 lanlink=${2}
99 lan=${3}
100 lan_mode=${4}
101
102 rump_server_add_iface ${sock} shmif0 ${lanlink}
103
104 export RUMP_SERVER=${sock}
105 if [ ${lan_mode} = "ipv6" ]; then
106 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${lan}
107 else
108 atf_check -s exit:0 rump.ifconfig shmif0 inet ${lan} netmask 0xffffff00
109 fi
110 atf_check -s exit:0 rump.ifconfig shmif0 up
111
112 unset RUMP_SERVER
113 }
114
115 test_client()
116 {
117 sock=${1}
118 lan=${2}
119 lan_mode=${3}
120
121 export RUMP_SERVER=${sock}
122
123 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
124 if [ ${lan_mode} = "ipv6" ]; then
125 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${lan}
126 else
127 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${lan}
128 fi
129
130 unset RUMP_SERVER
131 }
132
133 setup()
134 {
135 lan_mode=${1}
136 wan_mode=${2}
137
138 rump_server_start $LAC1SOCK netinet6 bridge l2tp
139 rump_server_start $LAC2SOCK netinet6 bridge l2tp
140 rump_server_start $CLIENT1SOCK netinet6 bridge l2tp
141 rump_server_start $CLIENT2SOCK netinet6 bridge l2tp
142
143 client1_lan=""
144 client2_lan=""
145 if [ ${lan_mode} = "ipv6" ]; then
146 client1_lan=${CLIENT1_LANIP6}
147 client2_lan=${CLIENT2_LANIP6}
148 else
149 client1_lan=${CLIENT1_LANIP}
150 client2_lan=${CLIENT2_LANIP}
151 fi
152
153 if [ ${wan_mode} = "ipv6" ]; then
154 setup_lac $LAC1SOCK $LAC1_LAN_LINK $LAC1_WANIP6 ${wan_mode}
155 setup_lac $LAC2SOCK $LAC2_LAN_LINK $LAC2_WANIP6 ${wan_mode}
156 setup_client $CLIENT1SOCK $LAC1_LAN_LINK \
157 ${client1_lan} ${lan_mode}
158 setup_client $CLIENT2SOCK $LAC2_LAN_LINK \
159 ${client2_lan} ${lan_mode}
160 else
161 setup_lac $LAC1SOCK $LAC1_LAN_LINK $LAC1_WANIP ${wan_mode}
162 setup_lac $LAC2SOCK $LAC2_LAN_LINK $LAC2_WANIP ${wan_mode}
163 setup_client $CLIENT1SOCK $LAC1_LAN_LINK \
164 ${client1_lan} ${lan_mode}
165 setup_client $CLIENT2SOCK $LAC2_LAN_LINK \
166 ${client2_lan} ${lan_mode}
167 fi
168 }
169
170 test_setup()
171 {
172 lan_mode=${1}
173 wan_mode=${2}
174
175 client1_lan=""
176 client2_lan=""
177 if [ ${lan_mode} = "ipv6" ]; then
178 client1_lan=$CLIENT1_LANIP6
179 client2_lan=$CLIENT2_LANIP6
180 else
181 client1_lan=$CLIENT1_LANIP
182 client2_lan=$CLIENT2_LANIP
183 fi
184 if [ ${wan_mode} = "ipv6" ]; then
185 test_lac ${LAC1SOCK} $LAC1_WANIP6 ${wan_mode}
186 test_lac ${LAC2SOCK} $LAC2_WANIP6 ${wan_mode}
187 test_client ${CLIENT1SOCK} ${client1_lan} ${lan_mode}
188 test_client ${CLIENT2SOCK} ${client2_lan} ${lan_mode}
189 else
190 test_lac ${LAC1SOCK} $LAC1_WANIP ${wan_mode}
191 test_lac ${LAC2SOCK} $LAC2_WANIP ${wan_mode}
192 test_client ${CLIENT1SOCK} ${client1_lan} ${lan_mode}
193 test_client ${CLIENT2SOCK} ${client2_lan} ${lan_mode}
194 fi
195 }
196
197 setup_if_l2tp()
198 {
199 sock=${1}
200 src=${2}
201 dst=${3}
202 src_session=${4}
203 dst_session=${5}
204
205 export RUMP_SERVER=${sock}
206
207 atf_check -s exit:0 rump.ifconfig l2tp0 create
208 atf_check -s exit:0 rump.ifconfig l2tp0 tunnel ${src} ${dst}
209 atf_check -s exit:0 rump.ifconfig l2tp0 session ${src_session} ${dst_session}
210 atf_check -s exit:0 rump.ifconfig l2tp0 up
211
212 atf_check -s exit:0 rump.ifconfig bridge0 create
213 atf_check -s exit:0 rump.ifconfig bridge0 up
214 export LD_PRELOAD=/usr/lib/librumphijack.so
215 atf_check -s exit:0 brconfig bridge0 add shmif0
216 atf_check -s exit:0 brconfig bridge0 add l2tp0
217 unset LD_PRELOAD
218
219 $DEBUG && rump.ifconfig -v l2tp0
220 $DEBUG && rump.ifconfig -v bridge0
221
222 unset RUMP_SERVER
223 }
224
225 setup_tunnel()
226 {
227 wan_mode=${1}
228
229 src=""
230 dst=""
231 src_session=""
232 dst_session=""
233
234 if [ ${wan_mode} = "ipv6" ]; then
235 src=$LAC1_WANIP6
236 dst=$LAC2_WANIP6
237 else
238 src=$LAC1_WANIP
239 dst=$LAC2_WANIP
240 fi
241 src_session=${LAC1_SESSION}
242 dst_session=${LAC2_SESSION}
243 setup_if_l2tp $LAC1SOCK ${src} ${dst} ${src_session} ${dst_session}
244
245 if [ ${wan_mode} = "ipv6" ]; then
246 src=$LAC2_WANIP6
247 dst=$LAC1_WANIP6
248 else
249 src=$LAC2_WANIP
250 dst=$LAC1_WANIP
251 fi
252 src_session=${LAC2_SESSION}
253 dst_session=${LAC1_SESSION}
254 setup_if_l2tp $LAC2SOCK ${src} ${dst} ${src_session} ${dst_session}
255 }
256
257 test_setup_tunnel()
258 {
259 mode=${1}
260
261 if [ ${mode} = "ipv6" ]; then
262 lac1_wan=$LAC1_WANIP6
263 lac2_wan=$LAC2_WANIP6
264 else
265 lac1_wan=$LAC1_WANIP
266 lac2_wan=$LAC2_WANIP
267 fi
268 export RUMP_SERVER=$LAC1SOCK
269 atf_check -s exit:0 -o match:l2tp0 rump.ifconfig
270 if [ ${mode} = "ipv6" ]; then
271 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${lac2_wan}
272 else
273 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${lac2_wan}
274 fi
275
276 export RUMP_SERVER=$LAC2SOCK
277 atf_check -s exit:0 -o match:l2tp0 rump.ifconfig
278 if [ ${mode} = "ipv6" ]; then
279 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${lac1_wan}
280 else
281 atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w $TIMEOUT ${lac1_wan}
282 fi
283
284 unset RUMP_SERVER
285 }
286
287 teardown_tunnel()
288 {
289 export RUMP_SERVER=$LAC1SOCK
290 atf_check -s exit:0 rump.ifconfig bridge0 destroy
291 atf_check -s exit:0 rump.ifconfig l2tp0 deletetunnel
292 atf_check -s exit:0 rump.ifconfig l2tp0 destroy
293
294 export RUMP_SERVER=$LAC2SOCK
295 atf_check -s exit:0 rump.ifconfig bridge0 destroy
296 atf_check -s exit:0 rump.ifconfig l2tp0 deletetunnel
297 atf_check -s exit:0 rump.ifconfig l2tp0 destroy
298
299 unset RUMP_SERVER
300 }
301
302 test_ping_failure()
303 {
304 mode=$1
305
306 export RUMP_SERVER=$CLIENT1SOCK
307 if [ ${mode} = "ipv6" ]; then
308 atf_check -s not-exit:0 -o ignore -e ignore \
309 rump.ping6 -n -X $TIMEOUT -c 1 $CLIENT2_LANIP6
310 else
311 atf_check -s not-exit:0 -o ignore -e ignore \
312 rump.ping -n -w $TIMEOUT -c 1 $CLIENT2_LANIP
313 fi
314
315 export RUMP_SERVER=$CLIENT2SOCK
316 if [ ${mode} = "ipv6" ]; then
317 atf_check -s not-exit:0 -o ignore -e ignore \
318 rump.ping6 -n -X $TIMEOUT -c 1 $CLIENT1_LANIP6
319 else
320 atf_check -s not-exit:0 -o ignore -e ignore \
321 rump.ping -n -w $TIMEOUT -c 1 $CLIENT1_LANIP
322 fi
323
324 unset RUMP_SERVER
325 }
326
327 test_ping_success()
328 {
329 mode=$1
330
331 export RUMP_SERVER=$CLIENT1SOCK
332 if [ ${mode} = "ipv6" ]; then
333 # XXX
334 # rump.ping6 rarely fails with the message that
335 # "failed to get receiving hop limit".
336 # This is a known issue being analyzed.
337 atf_check -s exit:0 -o ignore \
338 rump.ping6 -n -X $TIMEOUT -c 1 $CLIENT2_LANIP6
339 else
340 atf_check -s exit:0 -o ignore \
341 rump.ping -n -w $TIMEOUT -c 1 $CLIENT2_LANIP
342 fi
343 export RUMP_SERVER=$LAC1SOCK
344 $DEBUG && rump.ifconfig -v l2tp0
345 $DEBUG && rump.ifconfig -v bridge0
346 $DEBUG && rump.ifconfig -v shmif0
347
348 export RUMP_SERVER=$CLIENT2SOCK
349 if [ ${mode} = "ipv6" ]; then
350 atf_check -s exit:0 -o ignore \
351 rump.ping6 -n -X $TIMEOUT -c 1 $CLIENT1_LANIP6
352 else
353 atf_check -s exit:0 -o ignore \
354 rump.ping -n -w $TIMEOUT -c 1 $CLIENT1_LANIP
355 fi
356 export RUMP_SERVER=$LAC2SOCK
357 $DEBUG && rump.ifconfig -v l2tp0
358 $DEBUG && rump.ifconfig -v bridge0
359 $DEBUG && rump.ifconfig -v shmif0
360
361 unset RUMP_SERVER
362 }
363
364 basic_setup()
365 {
366 lan_mode=$1
367 wan_mode=$2
368
369 setup ${lan_mode} ${wan_mode}
370 test_setup ${lan_mode} ${wan_mode}
371
372 # Enable once PR kern/49219 is fixed
373 #test_ping_failure
374
375 setup_tunnel ${wan_mode}
376 sleep 1
377 test_setup_tunnel ${wan_mode}
378 }
379
380 basic_test()
381 {
382 lan_mode=$1
383 wan_mode=$2 # not use
384
385 test_ping_success ${lan_mode}
386 }
387
388 basic_teardown()
389 {
390 lan_mode=$1
391 wan_mode=$2 # not use
392
393 teardown_tunnel
394 test_ping_failure ${lan_mode}
395 }
396
397 add_test()
398 {
399 category=$1
400 desc=$2
401 lan_mode=$3
402 wan_mode=$4
403
404 name="l2tp_${category}_${lan_mode}over${wan_mode}"
405 fulldesc="Does ${lan_mode} over ${wan_mode} if_l2tp ${desc}"
406
407 atf_test_case ${name} cleanup
408 eval "${name}_head() {
409 atf_set descr \"${fulldesc}\"
410 atf_set require.progs rump_server
411 }
412 ${name}_body() {
413 ${category}_setup ${lan_mode} ${wan_mode}
414 ${category}_test ${lan_mode} ${wan_mode}
415 ${category}_teardown ${lan_mode} ${wan_mode}
416 rump_server_destroy_ifaces
417 }
418 ${name}_cleanup() {
419 \$DEBUG && dump
420 cleanup
421 }"
422 atf_add_test_case ${name}
423 }
424
425 add_test_allproto()
426 {
427 category=$1
428 desc=$2
429
430 add_test ${category} "${desc}" ipv4 ipv4
431 add_test ${category} "${desc}" ipv4 ipv6
432 add_test ${category} "${desc}" ipv6 ipv4
433 add_test ${category} "${desc}" ipv6 ipv6
434 }
435
436 atf_init_test_cases()
437 {
438 add_test_allproto basic "basic tests"
439 # add_test_allproto recursive "recursive check tests"
440 }
441