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