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