1 # $NetBSD: t_ipv6address.sh,v 1.16 2019/08/26 07:41:50 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 SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet" 28 SERVER="${SERVER} -lrumpnet_shmif" 29 SERVER6="${SERVER} -lrumpnet_netinet6" 30 31 SOCKSRC=unix://commsock1 32 SOCKFWD=unix://commsock2 33 SOCKDST=unix://commsock3 34 IP6SRCNW=fc00:1::0/64 35 IP6SRC=fc00:1::1 36 IP6DSTNW=fc00:2::0/64 37 IP6DST=fc00:2::1 38 IP6FWD0=fc00:3::1 39 BUS1=bus1 40 BUS2=bus2 41 BUSSRC=bus_src 42 BUSDST=bus_dst 43 44 DEBUG=${DEBUG:-false} 45 TIMEOUT=3 46 47 atf_test_case linklocal cleanup 48 atf_test_case linklocal_ops cleanup 49 50 setup() 51 { 52 atf_check -s exit:0 ${SERVER6} ${SOCKSRC} 53 atf_check -s exit:0 ${SERVER6} ${SOCKFWD} 54 atf_check -s exit:0 ${SERVER6} ${SOCKDST} 55 56 export RUMP_SERVER=${SOCKSRC} 57 atf_check -s exit:0 rump.ifconfig shmif0 create 58 atf_check -s exit:0 rump.ifconfig shmif1 create 59 unset RUMP_SERVER 60 61 export RUMP_SERVER=${SOCKDST} 62 atf_check -s exit:0 rump.ifconfig shmif0 create 63 atf_check -s exit:0 rump.ifconfig shmif1 create 64 unset RUMP_SERVER 65 66 export RUMP_SERVER=${SOCKFWD} 67 atf_check -s exit:0 rump.ifconfig shmif0 create 68 atf_check -s exit:0 rump.ifconfig shmif1 create 69 atf_check -s exit:0 -o match:"0 -> 1" rump.sysctl \ 70 -w net.inet6.ip6.forwarding=1 71 unset RUMP_SERVER 72 73 setup_ifcfg 74 75 export RUMP_SERVER=${SOCKSRC} 76 $DEBUG && rump.ifconfig 77 $DEBUG && rump.netstat -rn -f inet6 78 unset RUMP_SERVER 79 80 export RUMP_SERVER=${SOCKDST} 81 $DEBUG && rump.ifconfig 82 $DEBUG && rump.netstat -rn -f inet6 83 unset RUMP_SERVER 84 85 export RUMP_SERVER=${SOCKFWD} 86 $DEBUG && rump.ifconfig 87 $DEBUG && rump.netstat -rn -f inet6 88 unset RUMP_SERVER 89 } 90 setup_ifcfg() 91 { 92 export RUMP_SERVER=${SOCKSRC} 93 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 94 atf_check -s exit:0 rump.ifconfig shmif0 up 95 atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUSSRC} 96 atf_check -s exit:0 rump.ifconfig shmif1 up 97 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 98 unset RUMP_SERVER 99 100 export RUMP_SERVER=${SOCKDST} 101 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS2} 102 atf_check -s exit:0 rump.ifconfig shmif0 up 103 atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUSDST} 104 atf_check -s exit:0 rump.ifconfig shmif1 up 105 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 106 unset RUMP_SERVER 107 108 export RUMP_SERVER=${SOCKFWD} 109 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${BUS1} 110 atf_check -s exit:0 rump.ifconfig shmif0 up 111 112 atf_check -s exit:0 rump.ifconfig shmif1 linkstr ${BUS2} 113 atf_check -s exit:0 rump.ifconfig shmif1 up 114 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 115 unset RUMP_SERVER 116 } 117 118 setup_route() 119 { 120 local tmp_rump_server=$RUMP_SERVER 121 122 local src_if0_lladdr=`get_linklocal_addr ${SOCKSRC} shmif0` 123 local dst_if0_lladdr=`get_linklocal_addr ${SOCKDST} shmif0` 124 local fwd_if0_lladdr=`get_linklocal_addr ${SOCKFWD} shmif0` 125 local fwd_if1_lladdr=`get_linklocal_addr ${SOCKFWD} shmif1` 126 127 export RUMP_SERVER=${SOCKSRC} 128 atf_check -s ignore -o ignore -e ignore \ 129 rump.route delete -inet6 default ${fwd_if0_lladdr}%shmif0 130 atf_check -s exit:0 -o match:"add net default:" \ 131 rump.route add -inet6 default ${fwd_if0_lladdr}%shmif0 132 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6SRC} 133 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 134 $DEBUG && rump.netstat -rn -f inet6 135 unset RUMP_SERVER 136 137 export RUMP_SERVER=${SOCKDST} 138 atf_check -s ignore -o ignore -e ignore \ 139 rump.route delete -inet6 default ${fwd_if1_lladdr}%shmif0 140 atf_check -s exit:0 -o match:"add net default:" \ 141 rump.route add -inet6 default ${fwd_if1_lladdr}%shmif0 142 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DST} 143 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 144 $DEBUG && rump.netstat -rn -f inet6 145 unset RUMP_SERVER 146 147 export RUMP_SERVER=${SOCKFWD} 148 atf_check -s ignore -o ignore -e ignore \ 149 rump.route delete -inet6 ${IP6SRCNW} ${src_if0_lladdr}%shmif0 150 atf_check -s exit:0 -o match:"add net" \ 151 rump.route add -inet6 ${IP6SRCNW} ${src_if0_lladdr}%shmif0 152 153 atf_check -s ignore -o ignore -e ignore \ 154 rump.route delete -inet6 ${IP6DSTNW} ${dst_if0_lladdr}%shmif1 155 atf_check -s exit:0 -o match:"add net" \ 156 rump.route add -inet6 ${IP6DSTNW} ${dst_if0_lladdr}%shmif1 157 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 158 $DEBUG && rump.netstat -rn -f inet6 159 unset RUMP_SERVER 160 161 export RUMP_SERVER=$tmp_rump_server 162 } 163 164 cleanup_bus() 165 { 166 local tmp_rump_server=$RUMP_SERVER 167 168 $DEBUG && dump_bus 169 170 export RUMP_SERVER=${SOCKSRC} 171 atf_check -s exit:0 rump.ifconfig shmif0 down 172 atf_check -s exit:0 rump.ifconfig shmif0 -linkstr 173 atf_check -s exit:0 rump.ifconfig shmif1 down 174 atf_check -s exit:0 rump.ifconfig shmif1 -linkstr 175 unset RUMP_SERVER 176 177 export RUMP_SERVER=${SOCKDST} 178 atf_check -s exit:0 rump.ifconfig shmif0 down 179 atf_check -s exit:0 rump.ifconfig shmif0 -linkstr 180 atf_check -s exit:0 rump.ifconfig shmif1 down 181 atf_check -s exit:0 rump.ifconfig shmif1 -linkstr 182 unset RUMP_SERVER 183 184 export RUMP_SERVER=${SOCKFWD} 185 atf_check -s exit:0 rump.ifconfig shmif0 down 186 atf_check -s exit:0 rump.ifconfig shmif0 -linkstr 187 atf_check -s exit:0 rump.ifconfig shmif1 down 188 atf_check -s exit:0 rump.ifconfig shmif1 -linkstr 189 unset RUMP_SERVER 190 191 atf_check -s exit:0 rm ${BUSSRC} 192 atf_check -s exit:0 rm ${BUSDST} 193 atf_check -s exit:0 rm ${BUS1} 194 atf_check -s exit:0 rm ${BUS2} 195 196 setup_ifcfg 197 198 export RUMP_SERVER=$tmp_rump_server 199 } 200 201 cleanup_rump_servers() 202 { 203 204 env RUMP_SERVER=${SOCKSRC} rump.halt 205 env RUMP_SERVER=${SOCKDST} rump.halt 206 env RUMP_SERVER=${SOCKFWD} rump.halt 207 } 208 209 dump_bus() 210 { 211 212 shmif_dumpbus -p - ${BUSSRC} 2>/dev/null| tcpdump -n -e -r - 213 shmif_dumpbus -p - ${BUSDST} 2>/dev/null| tcpdump -n -e -r - 214 shmif_dumpbus -p - ${BUS1} 2>/dev/null| tcpdump -n -e -r - 215 shmif_dumpbus -p - ${BUS2} 2>/dev/null| tcpdump -n -e -r - 216 } 217 218 _dump() 219 { 220 221 export RUMP_SERVER=${SOCKSRC} 222 rump.ndp -n -a 223 rump.netstat -nr -f inet6 224 export RUMP_SERVER=${SOCKDST} 225 rump.ndp -n -a 226 rump.netstat -nr -f inet6 227 export RUMP_SERVER=${SOCKFWD} 228 rump.ndp -n -a 229 rump.netstat -nr -f inet6 230 unset RUMP_SERVER 231 } 232 233 linklocal_head() 234 { 235 atf_set "descr" \ 236 "Test for bassically function of the IPv6 linklocal address" 237 atf_set "require.progs" \ 238 "rump_server rump.route rump.ifconfig rump.ping6" 239 } 240 241 linklocal_body() 242 { 243 setup 244 245 local src_if0_lladdr=`get_linklocal_addr ${SOCKSRC} shmif0` 246 local src_if1_lladdr=`get_linklocal_addr ${SOCKSRC} shmif1` 247 local dst_if0_lladdr=`get_linklocal_addr ${SOCKDST} shmif0` 248 local fwd_if0_lladdr=`get_linklocal_addr ${SOCKFWD} shmif0` 249 local fwd_if1_lladdr=`get_linklocal_addr ${SOCKFWD} shmif1` 250 local lladdr=fe80::2 251 252 export RUMP_SERVER=${SOCKSRC} 253 $DEBUG && rump.ifconfig 254 $DEBUG && rump.netstat -rn -f inet6 255 256 # link local address to link local address 257 258 atf_check -s not-exit:0 -e match:"No route to host" \ 259 rump.ping6 -c 1 -X $TIMEOUT -n ${fwd_if0_lladdr} 260 261 atf_check -s exit:0 -o match:"0.0% packet loss" \ 262 rump.ping6 -c 1 -X $TIMEOUT -n ${fwd_if0_lladdr}%shmif0 263 264 atf_check -s ignore -o empty -e ignore \ 265 -x "shmif_dumpbus -p - ${BUSSRC} | tcpdump -r - -n -p icmp6" 266 atf_check -s ignore -o not-empty -e ignore \ 267 -x "shmif_dumpbus -p - ${BUS1} | tcpdump -r - -n -p icmp6" 268 269 cleanup_bus 270 271 atf_check -s not-exit:0 -o ignore -e ignore \ 272 rump.ping6 -c 1 -X $TIMEOUT -n -S ${src_if1_lladdr}%shmif1 \ 273 ${fwd_if0_lladdr}%shmif0 274 atf_check -s ignore -o not-match:"${src_if1_lladdr}" -e ignore \ 275 -x "shmif_dumpbus -p - ${BUS1} | tcpdump -r - -n -p icmp6" 276 $DEBUG && shmif_dumpbus -p - ${BUS1} | tcpdump -r - -n -p icmp6 277 unset RUMP_SERVER 278 279 # link local address to host address 280 export RUMP_SERVER=${SOCKFWD} 281 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6FWD0} 282 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 283 unset RUMP_SERVER 284 285 export RUMP_SERVER=${SOCKSRC} 286 atf_check -s exit:0 -o match:"add net default:" \ 287 rump.route add -inet6 default ${fwd_if0_lladdr}%shmif0 288 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 289 290 $DEBUG && rump.ifconfig shmif0 291 $DEBUG && _dump 292 293 export RUMP_SERVER=${SOCKSRC} 294 atf_check -s exit:0 -o match:"0.0% packet loss" \ 295 rump.ping6 -c 1 -X $TIMEOUT -n -S ${src_if0_lladdr}%shmif0 ${IP6FWD0} 296 unset RUMP_SERVER 297 298 export RUMP_SERVER=${SOCKFWD} 299 # host address to link local address 300 atf_check -s exit:0 -o match:"0.0% packet loss" \ 301 rump.ping6 -c 1 -X $TIMEOUT -n ${src_if0_lladdr}%shmif0 302 atf_check -s not-exit:0 -o match:"100.0% packet loss" \ 303 rump.ping6 -c 1 -X $TIMEOUT -n ${src_if1_lladdr}%shmif0 304 305 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6FWD0} delete 306 307 unset RUMP_SERVER 308 309 # forwarding with link local address 310 setup_route 311 312 export RUMP_SERVER=${SOCKSRC} 313 atf_check -s exit:0 -o match:"0.0% packet loss" rump.ping6 -c 1 \ 314 -X $TIMEOUT -n -S ${IP6SRC} ${IP6DST} 315 316 cleanup_bus 317 $DEBUG && rump.ifconfig shmif0 318 atf_check -s not-exit:0 -o match:"100.0% packet loss" rump.ping6 -c 1 \ 319 -X $TIMEOUT -n -S ${src_if0_lladdr}%shmif0 ${IP6DST} 320 atf_check -s ignore -o not-match:"${src_if0_lladdr}" -e ignore \ 321 -x "shmif_dumpbus -p - ${BUS2} | tcpdump -r - -n -p icmp6" 322 323 cleanup_bus 324 atf_check -s not-exit:0 -o match:"100.0% packet loss" rump.ping6 -c 1 \ 325 -X $TIMEOUT -n -S ${IP6SRC} ${dst_if0_lladdr}%shmif0 326 atf_check -s ignore -o not-empty -e ignore \ 327 -x "shmif_dumpbus -p - ${BUS2} | tcpdump -r - -n -p icmp6" 328 329 # Setting a link-local address with a scope ID 330 # XXX need $HIJACKING for some reasons 331 cleanup_bus 332 export RUMP_SERVER=${SOCKFWD} 333 $DEBUG && rump.ifconfig shmif0 334 atf_check -s exit:0 $HIJACKING rump.ifconfig shmif0 inet6 $lladdr%shmif0/64 335 export RUMP_SERVER=${SOCKSRC} 336 atf_check -s exit:0 -o match:"0.0% packet loss" rump.ping6 -c 1 \ 337 -X $TIMEOUT -n $lladdr 338 export RUMP_SERVER=${SOCKDST} 339 atf_check -s not-exit:0 -o match:"100.0% packet loss" rump.ping6 -c 1 \ 340 -X $TIMEOUT -n $lladdr 341 342 unset RUMP_SERVER 343 344 } 345 346 linklocal_cleanup() 347 { 348 349 $DEBUG && _dump 350 $DEBUG && dump_bus 351 cleanup_rump_servers 352 } 353 354 linklocal_ops_head() 355 { 356 357 atf_set "descr" \ 358 "Test for various operations to IPv6 linklocal addresses" 359 atf_set "require.progs" "rump_server rump.route rump.ndp" 360 } 361 362 linklocal_ops_body() 363 { 364 local src_if0_lladdr= 365 366 setup 367 368 src_if0_lladdr=`get_linklocal_addr ${SOCKSRC} shmif0` 369 370 export RUMP_SERVER=${SOCKSRC} 371 372 # route get 373 atf_check -s exit:0 -o match:"${src_if0_lladdr}" \ 374 rump.route get -inet6 ${src_if0_lladdr}%shmif0 375 376 # route get without an interface name (zone index) 377 atf_check -s not-exit:0 -e match:"not in table" \ 378 rump.route get -inet6 ${src_if0_lladdr} 379 380 # ndp 381 atf_check -s not-exit:0 -o ignore -e match:'no entry' \ 382 rump.ndp -n ${src_if0_lladdr}%shmif0 383 384 # ndp without an interface name (zone index) 385 atf_check -s not-exit:0 -o ignore -e match:"no entry" \ 386 rump.ndp -n ${src_if0_lladdr} 387 } 388 389 390 linklocal_ops_cleanup() 391 { 392 393 cleanup_rump_servers 394 } 395 396 atf_init_test_cases() 397 { 398 399 atf_add_test_case linklocal 400 atf_add_test_case linklocal_ops 401 } 402