1313535Sngie# $NetBSD: t_icmp6_redirect.sh,v 1.7 2016/11/25 08:51:16 ozaki-r Exp $ 2303980Sngie# 3303980Sngie# Copyright (c) 2015 Internet Initiative Japan Inc. 4303980Sngie# All rights reserved. 5303980Sngie# 6303980Sngie# Redistribution and use in source and binary forms, with or without 7303980Sngie# modification, are permitted provided that the following conditions 8303980Sngie# are met: 9303980Sngie# 1. Redistributions of source code must retain the above copyright 10303980Sngie# notice, this list of conditions and the following disclaimer. 11303980Sngie# 2. Redistributions in binary form must reproduce the above copyright 12303980Sngie# notice, this list of conditions and the following disclaimer in the 13303980Sngie# documentation and/or other materials provided with the distribution. 14303980Sngie# 15303980Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16303980Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17303980Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18303980Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19303980Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20303980Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21303980Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22303980Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23303980Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24303980Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25303980Sngie# POSSIBILITY OF SUCH DAMAGE. 26303980Sngie# 27303980Sngie 28303980SngieSOCK_LOCAL=unix://commsock1 29303980SngieSOCK_PEER=unix://commsock2 30303980SngieSOCK_GW1=unix://commsock3 31303980SngieSOCK_GW2=unix://commsock4 32303980Sngie 33303980SngieBUS1=bus1 34303980SngieBUS2=bus2 35303980SngieIP6BUS1=fc00:1::/64 36303980SngieIP6BUS2=fc00:2::/64 37303980SngieIP6IF0_LOCAL=fc00:1::2 38303980SngieIP6IF0_PEER=fc00:2::2 39303980SngieIP6IF0_GW1=fc00:1::1 40303980SngieIP6IF1_GW1=fc00:2::1 41303980SngieIP6IF0_GW2=fc00:1::3 42303980Sngie 43303980SngieREDIRECT_TIMEOUT=5 44303980Sngie 45313535SngieDEBUG=${DEBUG:-true} 46303980Sngie 47313535Sngieatf_test_case icmp6_redirect_basic cleanup 48303980Sngie 49313535Sngieicmp6_redirect_basic_head() 50303980Sngie{ 51303980Sngie 52303980Sngie atf_set "descr" "Test for the basically function of the ICMP6 redirect" 53303980Sngie atf_set "require.progs" "rump_server rump.route rump.ping rump.ifconfig" 54303980Sngie} 55303980Sngie 56313535Sngieicmp6_redirect_basic_body() 57303980Sngie{ 58303980Sngie local gw1_lladdr0= 59303980Sngie local gw1_lladdr1= 60303980Sngie local gw2_lladdr0= 61303980Sngie 62313535Sngie rump_server_start $SOCK_LOCAL netinet6 63313535Sngie rump_server_start $SOCK_PEER netinet6 64313535Sngie rump_server_start $SOCK_GW1 netinet6 65313535Sngie rump_server_start $SOCK_GW2 netinet6 66303980Sngie 67303980Sngie # 68303980Sngie # Setup 69303980Sngie # 70303980Sngie # Setup gateway #1 (real gateway) 71303980Sngie export RUMP_SERVER=${SOCK_GW1} 72313535Sngie rump_server_add_iface $SOCK_GW1 shmif0 $BUS1 73313535Sngie rump_server_add_iface $SOCK_GW1 shmif1 $BUS2 74313535Sngie 75303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW1} 76303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 77303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6IF1_GW1} 78303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 up 79303980Sngie 80303980Sngie atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \ 81303980Sngie net.inet6.ip6.forwarding=1 82303980Sngie unset RUMP_SERVER 83303980Sngie 84313535Sngie gw1_lladdr0=`get_linklocal_addr ${SOCK_GW1} shmif0` 85313535Sngie gw1_lladdr1=`get_linklocal_addr ${SOCK_GW1} shmif1` 86303980Sngie 87303980Sngie # Setup a peer behind gateway #1 88303980Sngie export RUMP_SERVER=${SOCK_PEER} 89313535Sngie rump_server_add_iface $SOCK_PEER shmif0 $BUS2 90303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_PEER} 91303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 92303980Sngie atf_check -s exit:0 -o ignore rump.route add \ 93303980Sngie -inet6 default ${gw1_lladdr1}%shmif0 94303980Sngie unset RUMP_SERVER 95303980Sngie 96303980Sngie # Setup gateway #2 (fake gateway) 97303980Sngie export RUMP_SERVER=${SOCK_GW2} 98313535Sngie rump_server_add_iface $SOCK_GW2 shmif0 $BUS1 99303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW2} 100303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 101303980Sngie 102303980Sngie atf_check -s exit:0 -o ignore rump.route add \ 103303980Sngie -inet6 ${IP6BUS2} ${gw1_lladdr0}%shmif0 104303980Sngie atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \ 105303980Sngie net.inet6.ip6.forwarding=1 106303980Sngie unset RUMP_SERVER 107303980Sngie 108313535Sngie gw2_lladdr0=`get_linklocal_addr ${SOCK_GW2} shmif0` 109303980Sngie 110303980Sngie export RUMP_SERVER=${SOCK_LOCAL} 111313535Sngie rump_server_add_iface $SOCK_LOCAL shmif0 $BUS1 112303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_LOCAL} 113303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 114303980Sngie 115303980Sngie # Teach the fake gateway as the default gateway 116303980Sngie atf_check -s exit:0 -o ignore rump.route add \ 117303980Sngie -inet6 default ${gw2_lladdr0}%shmif0 118303980Sngie $DEBUG && rump.route get -inet6 ${IP6IF0_PEER} 119303980Sngie 120303980Sngie atf_check -s exit:0 -o ignore rump.sysctl -w \ 121303980Sngie net.inet6.icmp6.redirtimeout=$REDIRECT_TIMEOUT 122303980Sngie 123303980Sngie # 124303980Sngie # Tests 125303980Sngie # 126303980Sngie atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n ${IP6IF0_PEER} 127303980Sngie $DEBUG && rump.route show -inet6 128303980Sngie # Check if a created route is correctly redirected to gateway #1 129303980Sngie atf_check -s exit:0 -o match:"gateway: ${gw1_lladdr0}" rump.route get \ 130303980Sngie -inet6 ${IP6IF0_PEER} 131303980Sngie 132303980Sngie atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2)) 133303980Sngie $DEBUG && rump.route show -inet6 134303980Sngie # Check if the created route is expired 135303980Sngie atf_check -s exit:0 -o not-match:"gateway: ${gw1_lladdr0}" rump.route get \ 136303980Sngie -inet6 ${IP6IF0_PEER} 137303980Sngie 138313535Sngie rump_server_destroy_ifaces 139303980Sngie} 140303980Sngie 141313535Sngieicmp6_redirect_basic_cleanup() 142303980Sngie{ 143303980Sngie 144313535Sngie $DEBUG && dump 145313535Sngie cleanup 146303980Sngie} 147303980Sngie 148303980Sngieatf_init_test_cases() 149303980Sngie{ 150303980Sngie 151313535Sngie atf_add_test_case icmp6_redirect_basic 152303980Sngie} 153