t_icmp6_redirect.sh revision 313498
1# $NetBSD: t_icmp6_redirect.sh,v 1.2 2016/08/10 22:17:44 kre Exp $ 2# 3# Copyright (c) 2015 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# 27netserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_shmif" 28netserver="${netserver} -lrumpnet_netinet -lrumpnet_netinet6 -lrumpdev" 29 30SOCK_LOCAL=unix://commsock1 31SOCK_PEER=unix://commsock2 32SOCK_GW1=unix://commsock3 33SOCK_GW2=unix://commsock4 34 35BUS1=bus1 36BUS2=bus2 37IP6BUS1=fc00:1::/64 38IP6BUS2=fc00:2::/64 39IP6IF0_LOCAL=fc00:1::2 40IP6IF0_PEER=fc00:2::2 41IP6IF0_GW1=fc00:1::1 42IP6IF1_GW1=fc00:2::1 43IP6IF0_GW2=fc00:1::3 44 45REDIRECT_TIMEOUT=5 46 47DEBUG=true 48 49get_lladdr() 50{ 51 52 export RUMP_SERVER=${1} 53 rump.ifconfig ${2} inet6 | awk "/fe80/ {sub(/%$2/, \"\"); print \$2;}" 54 unset RUMP_SERVER 55 56 return 0 57} 58 59atf_test_case basic cleanup 60 61basic_head() 62{ 63 64 atf_set "descr" "Test for the basically function of the ICMP6 redirect" 65 atf_set "require.progs" "rump_server rump.route rump.ping rump.ifconfig" 66} 67 68basic_body() 69{ 70 local gw1_lladdr0= 71 local gw1_lladdr1= 72 local gw2_lladdr0= 73 74 atf_check -s exit:0 ${netserver} ${SOCK_LOCAL} 75 atf_check -s exit:0 ${netserver} ${SOCK_PEER} 76 atf_check -s exit:0 ${netserver} ${SOCK_GW1} 77 atf_check -s exit:0 ${netserver} ${SOCK_GW2} 78 79 # 80 # Setup 81 # 82 # Setup gateway #1 (real gateway) 83 export RUMP_SERVER=${SOCK_GW1} 84 atf_check -s exit:0 rump.ifconfig shmif0 create 85 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 86 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW1} 87 atf_check -s exit:0 rump.ifconfig shmif0 up 88 89 atf_check -s exit:0 rump.ifconfig shmif1 create 90 atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUS2} 91 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6IF1_GW1} 92 atf_check -s exit:0 rump.ifconfig shmif1 up 93 94 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \ 95 net.inet6.ip6.forwarding=1 96 unset RUMP_SERVER 97 98 gw1_lladdr0=`get_lladdr ${SOCK_GW1} shmif0` 99 gw1_lladdr1=`get_lladdr ${SOCK_GW1} shmif1` 100 101 # Setup a peer behind gateway #1 102 export RUMP_SERVER=${SOCK_PEER} 103 atf_check -s exit:0 rump.ifconfig shmif0 create 104 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS2} 105 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_PEER} 106 atf_check -s exit:0 rump.ifconfig shmif0 up 107 atf_check -s exit:0 -o ignore rump.route add \ 108 -inet6 default ${gw1_lladdr1}%shmif0 109 unset RUMP_SERVER 110 111 # Setup gateway #2 (fake gateway) 112 export RUMP_SERVER=${SOCK_GW2} 113 atf_check -s exit:0 rump.ifconfig shmif0 create 114 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 115 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW2} 116 atf_check -s exit:0 rump.ifconfig shmif0 up 117 118 atf_check -s exit:0 -o ignore rump.route add \ 119 -inet6 ${IP6BUS2} ${gw1_lladdr0}%shmif0 120 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \ 121 net.inet6.ip6.forwarding=1 122 unset RUMP_SERVER 123 124 gw2_lladdr0=`get_lladdr ${SOCK_GW2} shmif0` 125 126 export RUMP_SERVER=${SOCK_LOCAL} 127 atf_check -s exit:0 rump.ifconfig shmif0 create 128 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 129 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_LOCAL} 130 atf_check -s exit:0 rump.ifconfig shmif0 up 131 132 # Teach the fake gateway as the default gateway 133 atf_check -s exit:0 -o ignore rump.route add \ 134 -inet6 default ${gw2_lladdr0}%shmif0 135 $DEBUG && rump.route get -inet6 ${IP6IF0_PEER} 136 137 atf_check -s exit:0 -o ignore rump.sysctl -w \ 138 net.inet6.icmp6.redirtimeout=$REDIRECT_TIMEOUT 139 140 # 141 # Tests 142 # 143 atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n ${IP6IF0_PEER} 144 $DEBUG && rump.route show -inet6 145 # Check if a created route is correctly redirected to gateway #1 146 atf_check -s exit:0 -o match:"gateway: ${gw1_lladdr0}" rump.route get \ 147 -inet6 ${IP6IF0_PEER} 148 149 atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2)) 150 $DEBUG && rump.route show -inet6 151 # Check if the created route is expired 152 atf_check -s exit:0 -o not-match:"gateway: ${gw1_lladdr0}" rump.route get \ 153 -inet6 ${IP6IF0_PEER} 154 155 unset RUMP_SERVER 156} 157 158basic_cleanup() 159{ 160 161 env RUMP_SERVER=$SOCK_LOCAL rump.halt 162 env RUMP_SERVER=$SOCK_PEER rump.halt 163 env RUMP_SERVER=$SOCK_GW1 rump.halt 164 env RUMP_SERVER=$SOCK_GW2 rump.halt 165} 166 167atf_init_test_cases() 168{ 169 170 atf_add_test_case basic 171} 172