t_icmp6_redirect.sh revision 303980
1303980Sngie# $NetBSD: t_icmp6_redirect.sh,v 1.2 2016/08/10 22:17:44 kre 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# 27303980Sngienetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_shmif" 28303980Sngienetserver="${netserver} -lrumpnet_netinet -lrumpnet_netinet6 -lrumpdev" 29303980Sngie 30303980SngieSOCK_LOCAL=unix://commsock1 31303980SngieSOCK_PEER=unix://commsock2 32303980SngieSOCK_GW1=unix://commsock3 33303980SngieSOCK_GW2=unix://commsock4 34303980Sngie 35303980SngieBUS1=bus1 36303980SngieBUS2=bus2 37303980SngieIP6BUS1=fc00:1::/64 38303980SngieIP6BUS2=fc00:2::/64 39303980SngieIP6IF0_LOCAL=fc00:1::2 40303980SngieIP6IF0_PEER=fc00:2::2 41303980SngieIP6IF0_GW1=fc00:1::1 42303980SngieIP6IF1_GW1=fc00:2::1 43303980SngieIP6IF0_GW2=fc00:1::3 44303980Sngie 45303980SngieREDIRECT_TIMEOUT=5 46303980Sngie 47303980SngieDEBUG=true 48303980Sngie 49303980Sngieget_lladdr() 50303980Sngie{ 51303980Sngie 52303980Sngie export RUMP_SERVER=${1} 53303980Sngie rump.ifconfig ${2} inet6 | awk "/fe80/ {sub(/%$2/, \"\"); print \$2;}" 54303980Sngie unset RUMP_SERVER 55303980Sngie 56303980Sngie return 0 57303980Sngie} 58303980Sngie 59303980Sngieatf_test_case basic cleanup 60303980Sngie 61303980Sngiebasic_head() 62303980Sngie{ 63303980Sngie 64303980Sngie atf_set "descr" "Test for the basically function of the ICMP6 redirect" 65303980Sngie atf_set "require.progs" "rump_server rump.route rump.ping rump.ifconfig" 66303980Sngie} 67303980Sngie 68303980Sngiebasic_body() 69303980Sngie{ 70303980Sngie local gw1_lladdr0= 71303980Sngie local gw1_lladdr1= 72303980Sngie local gw2_lladdr0= 73303980Sngie 74303980Sngie atf_check -s exit:0 ${netserver} ${SOCK_LOCAL} 75303980Sngie atf_check -s exit:0 ${netserver} ${SOCK_PEER} 76303980Sngie atf_check -s exit:0 ${netserver} ${SOCK_GW1} 77303980Sngie atf_check -s exit:0 ${netserver} ${SOCK_GW2} 78303980Sngie 79303980Sngie # 80303980Sngie # Setup 81303980Sngie # 82303980Sngie # Setup gateway #1 (real gateway) 83303980Sngie export RUMP_SERVER=${SOCK_GW1} 84303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 85303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 86303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW1} 87303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 88303980Sngie 89303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 create 90303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUS2} 91303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6IF1_GW1} 92303980Sngie atf_check -s exit:0 rump.ifconfig shmif1 up 93303980Sngie 94303980Sngie atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \ 95303980Sngie net.inet6.ip6.forwarding=1 96303980Sngie unset RUMP_SERVER 97303980Sngie 98303980Sngie gw1_lladdr0=`get_lladdr ${SOCK_GW1} shmif0` 99303980Sngie gw1_lladdr1=`get_lladdr ${SOCK_GW1} shmif1` 100303980Sngie 101303980Sngie # Setup a peer behind gateway #1 102303980Sngie export RUMP_SERVER=${SOCK_PEER} 103303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 104303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS2} 105303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_PEER} 106303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 107303980Sngie atf_check -s exit:0 -o ignore rump.route add \ 108303980Sngie -inet6 default ${gw1_lladdr1}%shmif0 109303980Sngie unset RUMP_SERVER 110303980Sngie 111303980Sngie # Setup gateway #2 (fake gateway) 112303980Sngie export RUMP_SERVER=${SOCK_GW2} 113303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 114303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 115303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW2} 116303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 117303980Sngie 118303980Sngie atf_check -s exit:0 -o ignore rump.route add \ 119303980Sngie -inet6 ${IP6BUS2} ${gw1_lladdr0}%shmif0 120303980Sngie atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \ 121303980Sngie net.inet6.ip6.forwarding=1 122303980Sngie unset RUMP_SERVER 123303980Sngie 124303980Sngie gw2_lladdr0=`get_lladdr ${SOCK_GW2} shmif0` 125303980Sngie 126303980Sngie export RUMP_SERVER=${SOCK_LOCAL} 127303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 create 128303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 129303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_LOCAL} 130303980Sngie atf_check -s exit:0 rump.ifconfig shmif0 up 131303980Sngie 132303980Sngie # Teach the fake gateway as the default gateway 133303980Sngie atf_check -s exit:0 -o ignore rump.route add \ 134303980Sngie -inet6 default ${gw2_lladdr0}%shmif0 135303980Sngie $DEBUG && rump.route get -inet6 ${IP6IF0_PEER} 136303980Sngie 137303980Sngie atf_check -s exit:0 -o ignore rump.sysctl -w \ 138303980Sngie net.inet6.icmp6.redirtimeout=$REDIRECT_TIMEOUT 139303980Sngie 140303980Sngie # 141303980Sngie # Tests 142303980Sngie # 143303980Sngie atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n ${IP6IF0_PEER} 144303980Sngie $DEBUG && rump.route show -inet6 145303980Sngie # Check if a created route is correctly redirected to gateway #1 146303980Sngie atf_check -s exit:0 -o match:"gateway: ${gw1_lladdr0}" rump.route get \ 147303980Sngie -inet6 ${IP6IF0_PEER} 148303980Sngie 149303980Sngie atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2)) 150303980Sngie $DEBUG && rump.route show -inet6 151303980Sngie # Check if the created route is expired 152303980Sngie atf_check -s exit:0 -o not-match:"gateway: ${gw1_lladdr0}" rump.route get \ 153303980Sngie -inet6 ${IP6IF0_PEER} 154303980Sngie 155303980Sngie unset RUMP_SERVER 156303980Sngie} 157303980Sngie 158303980Sngiebasic_cleanup() 159303980Sngie{ 160303980Sngie 161303980Sngie env RUMP_SERVER=$SOCK_LOCAL rump.halt 162303980Sngie env RUMP_SERVER=$SOCK_PEER rump.halt 163303980Sngie env RUMP_SERVER=$SOCK_GW1 rump.halt 164303980Sngie env RUMP_SERVER=$SOCK_GW2 rump.halt 165303980Sngie} 166303980Sngie 167303980Sngieatf_init_test_cases() 168303980Sngie{ 169303980Sngie 170303980Sngie atf_add_test_case basic 171303980Sngie} 172