1# $NetBSD: t_ndp.sh,v 1.6 2015/08/18 00:58:35 ozaki-r Exp $ 2# 3# Copyright (c) 2015 The NetBSD Foundation, 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 28inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet" 29inetserver="$inetserver -lrumpnet_netinet6 -lrumpnet_shmif" 30HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes" 31 32SOCKSRC=unix://commsock1 33SOCKDST=unix://commsock2 34IP6SRC=fc00::1 35IP6DST=fc00::2 36 37DEBUG=true 38TIMEOUT=1 39 40atf_test_case cache_expiration cleanup 41atf_test_case command cleanup 42atf_test_case cache_overwriting cleanup 43 44cache_expiration_head() 45{ 46 atf_set "descr" "Tests for NDP cache expiration" 47 atf_set "require.progs" "rump_server" 48} 49 50command_head() 51{ 52 atf_set "descr" "Tests for commands of ndp(8)" 53 atf_set "require.progs" "rump_server" 54} 55 56cache_overwriting_head() 57{ 58 atf_set "descr" "Tests for behavior of overwriting NDP caches" 59 atf_set "require.progs" "rump_server" 60} 61 62setup_dst_server() 63{ 64 export RUMP_SERVER=$SOCKDST 65 atf_check -s exit:0 rump.ifconfig shmif0 create 66 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1 67 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6DST 68 atf_check -s exit:0 rump.ifconfig shmif0 up 69 atf_check -s exit:0 rump.ifconfig -w 10 70 71 $DEBUG && rump.ifconfig shmif0 72 $DEBUG && rump.ndp -n -a 73} 74 75setup_src_server() 76{ 77 $DEBUG && ulimit -c unlimited 78 export RUMP_SERVER=$SOCKSRC 79 80 # Setup an interface 81 atf_check -s exit:0 rump.ifconfig shmif0 create 82 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1 83 atf_check -s exit:0 rump.ifconfig shmif0 inet6 $IP6SRC 84 atf_check -s exit:0 rump.ifconfig shmif0 up 85 atf_check -s exit:0 rump.ifconfig -w 10 86 87 # Sanity check 88 $DEBUG && rump.ifconfig shmif0 89 $DEBUG && rump.ndp -n -a 90 atf_check -s exit:0 -o ignore rump.ndp -n $IP6SRC 91 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST 92} 93 94get_timeout() 95{ 96 local timeout=$(env RUMP_SERVER=$SOCKSRC rump.ndp -n $IP6DST |grep $IP6DST|awk '{print $4;}') 97 timeout=${timeout%s} 98 echo $timeout 99} 100 101cache_expiration_body() 102{ 103 atf_check -s exit:0 ${inetserver} $SOCKSRC 104 atf_check -s exit:0 ${inetserver} $SOCKDST 105 106 setup_dst_server 107 setup_src_server 108 109 # 110 # Check if a cache is expired expectedly 111 # 112 export RUMP_SERVER=$SOCKSRC 113 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST 114 115 $DEBUG && rump.ndp -n -a 116 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC 117 # Should be cached 118 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST 119 120 timeout=$(get_timeout $IP6DST) 121 122 atf_check -s exit:0 sleep $(($timeout + 1)) 123 124 $DEBUG && rump.ndp -n -a 125 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6SRC 126 # Expired but remains until GC sweaps it (1 day) 127 atf_check -s exit:0 -o match:'(1d0h0m|23h59m)' rump.ndp -n $IP6DST 128} 129 130ifdown_dst_server() 131{ 132 export RUMP_SERVER=$SOCKDST 133 atf_check -s exit:0 rump.ifconfig shmif0 down 134 export RUMP_SERVER=$SOCKSRC 135} 136 137command_body() 138{ 139 atf_check -s exit:0 ${inetserver} $SOCKSRC 140 atf_check -s exit:0 ${inetserver} $SOCKDST 141 142 setup_dst_server 143 setup_src_server 144 145 export RUMP_SERVER=$SOCKSRC 146 147 # Add and delete a static entry 148 $DEBUG && rump.ndp -n -a 149 atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 150 $DEBUG && rump.ndp -n -a 151 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::10 152 atf_check -s exit:0 -o match:'deleted' rump.ndp -d fc00::10 153 $DEBUG && rump.ndp -n -a 154 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n fc00::10 155 156 # Add multiple entries via a file (XXX not implemented) 157 #cat - > ./list <<-EOF 158 #fc00::11 b2:a0:20:00:00:11 159 #fc00::12 b2:a0:20:00:00:12 160 #fc00::13 b2:a0:20:00:00:13 161 #fc00::14 b2:a0:20:00:00:14 162 #fc00::15 b2:a0:20:00:00:15 163 #EOF 164 #$DEBUG && rump.ndp -n -a 165 #atf_check -s exit:0 -o ignore rump.ndp -f ./list 166 #$DEBUG && rump.ndp -n -a 167 168 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST 169 atf_check -s exit:0 -o ignore rump.ndp -s fc00::11 b2:a0:20:00:00:11 170 atf_check -s exit:0 -o ignore rump.ndp -s fc00::12 b2:a0:20:00:00:12 171 172 atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n $IP6DST 173 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::11 174 atf_check -s exit:0 -o match:'permanent' rump.ndp -n fc00::12 175 176 # Test ndp -a 177 atf_check -s exit:0 -o match:'fc00::11' rump.ndp -n -a 178 atf_check -s exit:0 -o match:'fc00::12' rump.ndp -n -a 179 180 # Ensure no packet upsets the src server 181 ifdown_dst_server 182 183 # Flush all entries (-c) 184 $DEBUG && rump.ndp -n -a 185 atf_check -s exit:0 -o ignore rump.ndp -c 186 atf_check -s not-exit:0 -o ignore -e ignore rump.ndp -n $IP6DST 187 # Only the static caches are not deleted 188 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::11 189 atf_check -s exit:0 -o ignore -e ignore rump.ndp -n fc00::12 190 191 # Test temp option (XXX it doesn't work; expire time isn't set) 192 $DEBUG && rump.ndp -n -a 193 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp 194 rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp 195 $DEBUG && rump.ndp -n -a 196 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10 197 198 return 0 199} 200 201cache_overwriting_body() 202{ 203 atf_check -s exit:0 ${inetserver} $SOCKSRC 204 atf_check -s exit:0 ${inetserver} $SOCKDST 205 206 setup_dst_server 207 setup_src_server 208 209 export RUMP_SERVER=$SOCKSRC 210 211 # Cannot overwrite a permanent cache 212 atf_check -s not-exit:0 -e ignore rump.ndp -s $IP6SRC b2:a0:20:00:00:ff 213 $DEBUG && rump.ndp -n -a 214 215 atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6DST 216 $DEBUG && rump.ndp -n -a 217 # Can overwrite a dynamic cache 218 atf_check -s exit:0 -o ignore rump.ndp -s $IP6DST b2:a0:20:00:00:00 219 $DEBUG && rump.ndp -n -a 220 atf_check -s exit:0 -o match:'permanent' rump.ndp -n $IP6DST 221 222 # Test temp option (XXX it doesn't work; expire time isn't set) 223 #atf_check -s exit:0 -o ignore rump.ndp -s fc00::10 b2:a0:20:00:00:10 temp 224 #$DEBUG && rump.ndp -n -a 225 #atf_check -s exit:0 -o not-match:'permanent' rump.ndp -n fc00::10 226 # Cannot overwrite a temp cache 227 #atf_check -s not-exit:0 -e ignore rump.ndp -s fc00::10 b2:a0:20:00:00:ff 228 #$DEBUG && rump.ndp -n -a 229 230 return 0 231} 232 233cleanup() 234{ 235 env RUMP_SERVER=$SOCKSRC rump.halt 236 env RUMP_SERVER=$SOCKDST rump.halt 237} 238 239dump_src() 240{ 241 export RUMP_SERVER=$SOCKSRC 242 rump.netstat -nr 243 rump.ndp -n -a 244 rump.ifconfig 245 $HIJACKING dmesg 246} 247 248dump_dst() 249{ 250 export RUMP_SERVER=$SOCKDST 251 rump.netstat -nr 252 rump.ndp -n -a 253 rump.ifconfig 254 $HIJACKING dmesg 255} 256 257dump() 258{ 259 dump_src 260 dump_dst 261 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - 262 $DEBUG && gdb -ex bt /usr/bin/rump_server rump_server.core 263 $DEBUG && gdb -ex bt /usr/sbin/rump.ndp rump.ndp.core 264} 265 266cache_expiration_cleanup() 267{ 268 $DEBUG && dump 269 cleanup 270} 271 272command_cleanup() 273{ 274 $DEBUG && dump 275 cleanup 276} 277 278cache_overwriting_cleanup() 279{ 280 $DEBUG && dump 281 cleanup 282} 283 284atf_init_test_cases() 285{ 286 atf_add_test_case cache_expiration 287 atf_add_test_case command 288 atf_add_test_case cache_overwriting 289} 290