1# $NetBSD: t_ifconfig.sh,v 1.15 2017/01/20 08:35:33 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 28RUMP_SERVER1=unix://./r1 29RUMP_SERVER2=unix://./r2 30 31RUMP_FLAGS=\ 32"-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_shmif" 33RUMP_FLAGS="${RUMP_FLAGS} -lrumpdev" 34 35TIMEOUT=3 36 37anycast="[Aa][Nn][Yy][Cc][Aa][Ss][Tt]" 38deprecated="[Dd][Ee][Pp][Rr][Ee][Cc][Aa][Tt][Ee][Dd]" 39 40atf_test_case ifconfig_create_destroy cleanup 41ifconfig_create_destroy_head() 42{ 43 44 atf_set "descr" "tests of ifconfig create and destroy" 45 atf_set "require.progs" "rump_server" 46} 47 48ifconfig_create_destroy_body() 49{ 50 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1} 51 52 export RUMP_SERVER=${RUMP_SERVER1} 53 54 # Create and destroy (no address) 55 atf_check -s exit:0 rump.ifconfig shmif0 create 56 atf_check -s exit:0 rump.ifconfig shmif0 destroy 57 58 # Create and destroy (with an IPv4 address) 59 atf_check -s exit:0 rump.ifconfig shmif0 create 60 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 61 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24 62 atf_check -s exit:0 rump.ifconfig shmif0 up 63 atf_check -s exit:0 rump.ifconfig shmif0 destroy 64 65 # Create and destroy (with an IPv6 address) 66 atf_check -s exit:0 rump.ifconfig shmif0 create 67 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 68 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 69 atf_check -s exit:0 rump.ifconfig shmif0 up 70 atf_check -s exit:0 rump.ifconfig shmif0 destroy 71 72 unset RUMP_SERVER 73} 74 75ifconfig_create_destroy_cleanup() 76{ 77 78 RUMP_SERVER=${RUMP_SERVER1} rump.halt 79} 80 81atf_test_case ifconfig_options cleanup 82ifconfig_options_head() 83{ 84 85 atf_set "descr" "tests of ifconfig options" 86 atf_set "require.progs" "rump_server" 87} 88 89ifconfig_options_body() 90{ 91 92 export RUMP_SERVER=${RUMP_SERVER1} 93 atf_check -s exit:0 rump_server $RUMP_FLAGS $RUMP_SERVER1 94 95 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 96 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr bus1 97 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet 10.0.0.1/24 98 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 fc00::1/64 99 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 100 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 101 $DEBUG && rump.ifconfig shmif0 102 103 # ifconfig [-N] interface address_family 104 # -N resolves hostnames 105 atf_check -s exit:0 -o match:'inet 127.0.0.1' rump.ifconfig lo0 inet 106 atf_check -s exit:0 -o match:'inet localhost' rump.ifconfig -N lo0 inet 107 atf_check -s exit:0 -o match:'inet6 ::1' rump.ifconfig lo0 inet6 108 atf_check -s exit:0 -o match:'inet6 localhost' rump.ifconfig -N lo0 inet6 109 atf_check -s not-exit:0 -e match:'not supported' rump.ifconfig lo0 atalk 110 atf_check -s not-exit:0 -e match:'not supported' rump.ifconfig -N lo0 atalk 111 atf_check -s exit:0 -o ignore rump.ifconfig lo0 link 112 atf_check -s exit:0 -o ignore rump.ifconfig -N lo0 link 113 114 # ifconfig [-hLmNvz] interface 115 # -h -v shows statistics in human readable format 116 atf_check -s exit:0 -o ignore rump.ifconfig -h -v lo0 117 # -L shows IPv6 lifetime 118 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 fc00::2 \ 119 pltime 100 120 $DEBUG && rump.ifconfig -L shmif0 121 atf_check -s exit:0 -o match:'pltime' rump.ifconfig -L shmif0 122 atf_check -s exit:0 -o match:'vltime' rump.ifconfig -L shmif0 123 # -m shows all of the supported media (not supported in shmif) 124 $DEBUG && rump.ifconfig -m shmif0 125 atf_check -s exit:0 -o ignore rump.ifconfig -m shmif0 126 atf_check -s exit:0 -o match:'localhost' rump.ifconfig -N lo0 127 atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -v lo0 128 atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT localhost 129 # -z clears and shows statistics at that point 130 atf_check -s exit:0 -o match:'2 packets' rump.ifconfig -z lo0 131 atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -v lo0 132 133 # ifconfig -a [-bdhLNmsuvz] 134 # -a shows all interfaces in the system 135 $DEBUG && rump.ifconfig -a 136 atf_check -s exit:0 -o match:'shmif0' -o match:'lo0' rump.ifconfig -a 137 # -a -b shows only broadcast interfaces 138 atf_check -s exit:0 -o match:'shmif0' -o not-match:'lo0' rump.ifconfig -a -b 139 # -a -d shows only down interfaces 140 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 down 141 atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -a -d 142 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 143 atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig -a -d 144 atf_check -s exit:0 -o match:'pltime' rump.ifconfig -a -L 145 atf_check -s exit:0 -o match:'vltime' rump.ifconfig -a -L 146 atf_check -s exit:0 -o match:'localhost' rump.ifconfig -a -N 147 atf_check -s exit:0 -o ignore rump.ifconfig -a -m 148 # -a -s shows only interfaces connected to a network 149 # (shmif is always connected) 150 $DEBUG && rump.ifconfig -a -s 151 atf_check -s exit:0 -o ignore rump.ifconfig -a -s 152 # -a -u shows only up interfaces 153 atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -a -u 154 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 down 155 atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig -a -u 156 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 157 atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -a -v 158 atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT localhost 159 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 down 160 atf_check -s exit:0 -o match:'2 packets' rump.ifconfig -a -z 161 atf_check -s exit:0 -o not-match:'2 packets' rump.ifconfig -a -v 162 atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -a -v 163 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 164 165 # ifconfig -l [-bdsu] 166 # -l shows only inteface names 167 atf_check -s exit:0 -o match:'lo0' rump.ifconfig -l 168 atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l 169 atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l -b 170 atf_check -s exit:0 -o not-match:'lo0' rump.ifconfig -l -b 171 atf_check -s exit:0 -o ignore rump.ifconfig -l -d 172 atf_check -s exit:0 -o match:'lo0' rump.ifconfig -l -s 173 atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l -s 174 atf_check -s exit:0 -o match:'lo0' rump.ifconfig -l -u 175 atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l -u 176 177 # ifconfig -s interface 178 # -s interface exists with 0 / 1 if connected / disconnected 179 atf_check -s exit:0 -o empty rump.ifconfig -s lo0 180 atf_check -s exit:0 -o empty rump.ifconfig -s shmif0 181 182 # ifconfig -C 183 # -C shows all of the interface cloners available on the system 184 atf_check -s exit:0 -o match:'shmif carp lo' rump.ifconfig -C 185 186 unset RUMP_SERVER 187} 188 189ifconfig_options_cleanup() 190{ 191 192 env RUMP_SERVER=${RUMP_SERVER1} rump.halt 193} 194 195 196atf_test_case ifconfig_parameters cleanup 197ifconfig_parameters_head() 198{ 199 atf_set "descr" "tests of interface parameters" 200 atf_set "require.progs" "rump_server" 201} 202 203ifconfig_parameters_body() 204{ 205 local interval= 206 207 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1} 208 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2} 209 210 export RUMP_SERVER=${RUMP_SERVER1} 211 atf_check -s exit:0 rump.ifconfig shmif0 create 212 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 213 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24 214 atf_check -s exit:0 rump.ifconfig shmif0 up 215 unset RUMP_SERVER 216 217 export RUMP_SERVER=${RUMP_SERVER2} 218 atf_check -s exit:0 rump.ifconfig shmif0 create 219 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 220 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.2/24 221 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.3/24 alias 222 atf_check -s exit:0 rump.ifconfig shmif0 up 223 unset RUMP_SERVER 224 225 export RUMP_SERVER=${RUMP_SERVER1} 226 227 # active 228 atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:01 active 229 atf_check -s exit:0 -o match:'address:.b2:a0:75:00:00:01' \ 230 rump.ifconfig shmif0 231 # down, up 232 atf_check -s exit:0 rump.ifconfig shmif0 down 233 atf_check -s not-exit:0 -o ignore -e ignore rump.ping -c 1 \ 234 -w $TIMEOUT -n 192.168.0.2 235 atf_check -s exit:0 rump.ifconfig shmif0 up 236 atf_check -s exit:0 rump.ifconfig -w 10 237 atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT -n 192.168.0.2 238 239 # alias 240 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 alias 241 atf_check -s exit:0 -o match:'192.168.1.1/24' rump.ifconfig shmif0 242 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 -alias 243 atf_check -s exit:0 -o not-match:'192.168.1.1/24' rump.ifconfig shmif0 244 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 245 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 246 atf_check -s exit:0 -o match:'fc00::1' rump.ifconfig shmif0 inet6 247 atf_check -s exit:0 -o match:'fc00::2' rump.ifconfig shmif0 inet6 248 249 # delete 250 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 alias 251 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 delete 252 atf_check -s exit:0 -o not-match:'192.168.1.1' rump.ifconfig shmif0 inet 253 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1 delete 254 atf_check -s exit:0 -o not-match:'192.168.0.1' rump.ifconfig shmif0 inet 255 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 delete 256 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 delete 257 atf_check -s exit:0 -o not-match:'fc00::1' rump.ifconfig shmif0 inet6 258 atf_check -s exit:0 -o not-match:'fc00::2' rump.ifconfig shmif0 inet6 259 # can delete inactive link 260 atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:02 261 atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:02 delete 262 # cannot delete active link 263 atf_check -s not-exit:0 -e match:'SIOCDLIFADDR: Device busy' \ 264 rump.ifconfig shmif0 link b2:a0:75:00:00:01 delete 265 266 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1/24 267 268 # arp 269 atf_check -s exit:0 rump.ifconfig shmif0 -arp 270 atf_check -s not-exit:0 -o ignore -e ignore \ 271 rump.ping -c 1 -w $TIMEOUT -n 192.168.0.3 272 atf_check -s exit:0 -o not-match:'192.168.0.3' rump.arp -an 273 # The entry shouldn't appear in the routing table anymore 274 atf_check -s exit:0 -o not-match:'192.168.0.3' rump.netstat -nr 275 276 # netmask 277 atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 netmask 255.255.255.0 alias 278 atf_check -s exit:0 -o match:'172.16.0/24' rump.netstat -rn -f inet 279 atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 delete 280 281 # broadcast (does it not work?) 282 atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 \ 283 broadcast 255.255.255.255 alias 284 atf_check -s exit:0 -o match:'broadcast 255.255.255.255' \ 285 rump.ifconfig shmif0 inet 286 287 # metric (external only) 288 atf_check -s exit:0 rump.ifconfig shmif0 metric 10 289 atf_check -s exit:0 rump.ifconfig shmif0 metric 0 290 291 # prefixlen 292 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 prefixlen 70 293 atf_check -s exit:0 -o match:'fc00::/70' rump.netstat -rn -f inet6 294 295 # anycast 296 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 anycast 297 atf_check -s exit:0 -o match:"fc00::2.+$anycast" rump.ifconfig shmif0 inet6 298 299 # deprecated 300 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 deprecated 301 # Not deprecated immediately. Need to wait nd6_timer that does it is scheduled. 302 interval=$(sysctl -n net.inet6.icmp6.nd6_prune) 303 atf_check -s exit:0 sleep $((interval + 1)) 304 atf_check -s exit:0 -o match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6 305 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 -deprecated 306 atf_check -s exit:0 -o not-match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6 307 308 # pltime 309 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 pltime 3 310 atf_check -s exit:0 -o not-match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6 311 atf_check -s exit:0 sleep 5 312 atf_check -s exit:0 -o match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6 313 314 # eui64 315 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00:1::0 eui64 316 atf_check -s exit:0 -o match:'fc00:1::' rump.ifconfig shmif0 inet6 317 318 unset RUMP_SERVER 319} 320 321ifconfig_parameters_cleanup() 322{ 323 env RUMP_SERVER=${RUMP_SERVER1} rump.halt 324 env RUMP_SERVER=${RUMP_SERVER2} rump.halt 325} 326 327atf_init_test_cases() 328{ 329 330 atf_add_test_case ifconfig_create_destroy 331 atf_add_test_case ifconfig_options 332 atf_add_test_case ifconfig_parameters 333} 334