t_ra.sh revision 1.7
1# $NetBSD: t_ra.sh,v 1.7 2016/12/14 07:37:26 ozaki-r 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# 27 28RUMPSRV=unix://r1 29RUMPCLI=unix://r2 30IP6SRV=fc00:1::1 31IP6CLI=fc00:2::2 32PIDFILE=/var/run/rump.rtadvd.pid 33CONFIG=./rtadvd.conf 34DEBUG=${DEBUG:-true} 35 36setup_shmif0() 37{ 38 local sock=$1 39 local IP6ADDR=$2 40 41 rump_server_add_iface $sock shmif0 bus1 42 43 export RUMP_SERVER=$sock 44 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6ADDR} 45 atf_check -s exit:0 rump.ifconfig shmif0 up 46 47 $DEBUG && rump.ifconfig 48} 49 50wait_term() 51{ 52 local PIDFILE=${1} 53 shift 54 55 while [ -f ${PIDFILE} ] 56 do 57 sleep 0.2 58 done 59 60 return 0 61} 62 63create_rtadvdconfig() 64{ 65 66 cat << _EOF > ${CONFIG} 67shmif0:\ 68 :mtu#1300:maxinterval#4:mininterval#3: 69_EOF 70} 71 72dump_entries() 73{ 74 75 echo ndp -n -a 76 rump.ndp -n -a 77 echo ndp -p 78 rump.ndp -p 79 echo ndp -r 80 rump.ndp -r 81} 82 83atf_test_case ra_basic cleanup 84ra_basic_head() 85{ 86 87 atf_set "descr" "Tests for basic functions of router advaertisement(RA)" 88 atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig" 89} 90 91ra_basic_body() 92{ 93 94 rump_server_fs_start $RUMPSRV netinet6 95 rump_server_start $RUMPCLI netinet6 96 97 setup_shmif0 ${RUMPSRV} ${IP6SRV} 98 export RUMP_SERVER=${RUMPSRV} 99 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.forwarding=1 100 export LD_PRELOAD=/usr/lib/librumphijack.so 101 atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd 102 unset LD_PRELOAD 103 unset RUMP_SERVER 104 105 setup_shmif0 ${RUMPCLI} ${IP6CLI} 106 export RUMP_SERVER=${RUMPCLI} 107 $DEBUG && rump.ndp -n -a 108 atf_check -s exit:0 -o match:'= 0' rump.sysctl net.inet6.ip6.accept_rtadv 109 unset RUMP_SERVER 110 111 create_rtadvdconfig 112 113 export RUMP_SERVER=${RUMPSRV} 114 atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0 115 atf_check -s exit:0 sleep 3 116 atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE} 117 unset RUMP_SERVER 118 119 export RUMP_SERVER=${RUMPCLI} 120 atf_check -s exit:0 -o empty rump.ndp -r 121 atf_check -s exit:0 -o not-match:'advertised' rump.ndp -p 122 atf_check -s exit:0 -o match:'linkmtu=0' rump.ndp -n -i shmif0 123 atf_check -s exit:0 -o not-match:'S R' rump.ndp -n -a 124 atf_check -s exit:0 -o not-match:'fc00:1:' rump.ndp -n -a 125 atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6 126 unset RUMP_SERVER 127 128 atf_check -s exit:0 kill -TERM `cat ${PIDFILE}` 129 wait_term ${PIDFILE} 130 131 export RUMP_SERVER=${RUMPCLI} 132 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1 133 unset RUMP_SERVER 134 135 export RUMP_SERVER=${RUMPSRV} 136 atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0 137 atf_check -s exit:0 sleep 3 138 atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE} 139 unset RUMP_SERVER 140 141 export RUMP_SERVER=${RUMPCLI} 142 $DEBUG && rump.ndp -n -a 143 $DEBUG && rump.ndp -r 144 atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r 145 atf_check -s exit:0 -o match:'advertised' rump.ndp -p 146 atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0 147 atf_check -s exit:0 -o match:'23h59m..s S R' rump.ndp -n -a 148 atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a 149 atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6 150 unset RUMP_SERVER 151 152 atf_check -s exit:0 kill -TERM `cat ${PIDFILE}` 153 wait_term ${PIDFILE} 154 155 rump_server_destroy_ifaces 156} 157 158ra_basic_cleanup() 159{ 160 161 if [ -f ${PIDFILE} ]; then 162 kill -TERM `cat ${PIDFILE}` 163 wait_term ${PIDFILE} 164 fi 165 166 $DEBUG && dump 167 cleanup 168} 169 170atf_test_case ra_flush_prefix_entries cleanup 171ra_flush_prefix_entries_head() 172{ 173 174 atf_set "descr" "Tests for flushing prefixes (ndp -P)" 175 atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig" 176} 177 178ra_flush_prefix_entries_body() 179{ 180 181 rump_server_fs_start $RUMPSRV netinet6 182 rump_server_start $RUMPCLI netinet6 183 184 setup_shmif0 ${RUMPSRV} ${IP6SRV} 185 setup_shmif0 ${RUMPCLI} ${IP6CLI} 186 187 export RUMP_SERVER=${RUMPSRV} 188 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.forwarding=1 189 export LD_PRELOAD=/usr/lib/librumphijack.so 190 atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd 191 unset LD_PRELOAD 192 unset RUMP_SERVER 193 194 create_rtadvdconfig 195 196 export RUMP_SERVER=${RUMPCLI} 197 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1 198 unset RUMP_SERVER 199 200 export RUMP_SERVER=${RUMPSRV} 201 atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0 202 atf_check -s exit:0 sleep 3 203 atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE} 204 unset RUMP_SERVER 205 206 export RUMP_SERVER=${RUMPCLI} 207 $DEBUG && dump_entries 208 atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r 209 atf_check -s exit:0 -o match:'advertised' rump.ndp -p 210 atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0 211 atf_check -s exit:0 -o match:'23h59m..s S R' rump.ndp -n -a 212 atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a 213 atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6 214 215 # Flush all the entries in the prefix list 216 atf_check -s exit:0 rump.ndp -P 217 218 $DEBUG && dump_entries 219 atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r 220 atf_check -s exit:0 -o empty rump.ndp -p 221 atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0 222 atf_check -s exit:0 -o match:'23h59m..s S R' rump.ndp -n -a 223 atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a 224 atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6 225 unset RUMP_SERVER 226 227 atf_check -s exit:0 kill -TERM `cat ${PIDFILE}` 228 wait_term ${PIDFILE} 229 230 rump_server_destroy_ifaces 231} 232 233ra_flush_prefix_entries_cleanup() 234{ 235 236 if [ -f ${PIDFILE} ]; then 237 kill -TERM `cat ${PIDFILE}` 238 wait_term ${PIDFILE} 239 fi 240 241 $DEBUG && dump 242 cleanup 243} 244 245atf_test_case ra_flush_defrouter_entries cleanup 246ra_flush_defrouter_entries_head() 247{ 248 249 atf_set "descr" "Tests for flushing default routers (ndp -R)" 250 atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig" 251} 252 253ra_flush_defrouter_entries_body() 254{ 255 256 rump_server_fs_start $RUMPSRV netinet6 257 rump_server_start $RUMPCLI netinet6 258 259 setup_shmif0 ${RUMPSRV} ${IP6SRV} 260 setup_shmif0 ${RUMPCLI} ${IP6CLI} 261 262 export RUMP_SERVER=${RUMPSRV} 263 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.forwarding=1 264 export LD_PRELOAD=/usr/lib/librumphijack.so 265 atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd 266 unset LD_PRELOAD 267 unset RUMP_SERVER 268 269 create_rtadvdconfig 270 271 export RUMP_SERVER=${RUMPCLI} 272 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1 273 unset RUMP_SERVER 274 275 export RUMP_SERVER=${RUMPSRV} 276 atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0 277 atf_check -s exit:0 sleep 3 278 atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE} 279 unset RUMP_SERVER 280 281 export RUMP_SERVER=${RUMPCLI} 282 $DEBUG && dump_entries 283 atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r 284 atf_check -s exit:0 -o match:'advertised' rump.ndp -p 285 atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0 286 atf_check -s exit:0 -o match:'23h59m..s S R' rump.ndp -n -a 287 atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a 288 atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6 289 290 # Flush all the entries in the default router list 291 atf_check -s exit:0 rump.ndp -R 292 293 $DEBUG && dump_entries 294 atf_check -s exit:0 -o empty rump.ndp -r 295 atf_check -s exit:0 -o match:'No advertising router' rump.ndp -p 296 atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0 297 atf_check -s exit:0 -o match:'23h59m..s S R' rump.ndp -n -a 298 atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a 299 atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6 300 unset RUMP_SERVER 301 302 atf_check -s exit:0 kill -TERM `cat ${PIDFILE}` 303 wait_term ${PIDFILE} 304 305 rump_server_destroy_ifaces 306} 307 308ra_flush_defrouter_entries_cleanup() 309{ 310 311 if [ -f ${PIDFILE} ]; then 312 kill -TERM `cat ${PIDFILE}` 313 wait_term ${PIDFILE} 314 fi 315 316 $DEBUG && dump 317 cleanup 318} 319 320atf_init_test_cases() 321{ 322 323 atf_add_test_case ra_basic 324 atf_add_test_case ra_flush_prefix_entries 325 atf_add_test_case ra_flush_defrouter_entries 326} 327