Home | History | Annotate | Line # | Download | only in if
t_ifconfig.sh revision 1.12
      1 # $NetBSD: t_ifconfig.sh,v 1.12 2016/09/14 16:18:31 christos 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 RUMP_FLAGS="${RUMP_FLAGS} -lrumpdev"
     34 
     35 TIMEOUT=3
     36 
     37 anycast="[Aa][Nn][Yy][Cc][Aa][Ss][Tt]"
     38 deprecated="[Dd][Ee][Pp][Rr][Ee][Cc][Aa][Tt][Ee][Dd]"
     39 
     40 atf_test_case ifconfig_create_destroy cleanup
     41 ifconfig_create_destroy_head()
     42 {
     43 
     44 	atf_set "descr" "tests of ifconfig create and destroy"
     45 	atf_set "require.progs" "rump_server"
     46 }
     47 
     48 ifconfig_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 
     75 ifconfig_create_destroy_cleanup()
     76 {
     77 
     78 	RUMP_SERVER=${RUMP_SERVER1} rump.halt
     79 }
     80 
     81 atf_test_case ifconfig_options cleanup
     82 ifconfig_options_head()
     83 {
     84 
     85 	atf_set "descr" "tests of ifconfig options"
     86 	atf_set "require.progs" "rump_server"
     87 }
     88 
     89 ifconfig_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 lo carp' rump.ifconfig -C
    185 
    186 	unset RUMP_SERVER
    187 }
    188 
    189 ifconfig_options_cleanup()
    190 {
    191 
    192 	env RUMP_SERVER=${RUMP_SERVER1} rump.halt
    193 }
    194 
    195 
    196 atf_test_case ifconfig_parameters cleanup
    197 ifconfig_parameters_head()
    198 {
    199 	atf_set "descr" "tests of interface parameters"
    200 	atf_set "require.progs" "rump_server"
    201 }
    202 
    203 ifconfig_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 ignore -o ignore -e match:'down' 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 -o ignore rump.ping -c 1 -w $TIMEOUT -n 192.168.0.2
    237 
    238 	# alias
    239 	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 alias
    240 	atf_check -s exit:0 -o match:'alias 192.168.1.1' rump.ifconfig shmif0
    241 	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 -alias
    242 	atf_check -s exit:0 -o not-match:'192.168.1.1' rump.ifconfig shmif0
    243 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1
    244 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2
    245 	atf_check -s exit:0 -o match:'fc00::1' rump.ifconfig shmif0 inet6
    246 	atf_check -s exit:0 -o match:'fc00::2' rump.ifconfig shmif0 inet6
    247 
    248 	# delete
    249 	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 alias
    250 	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 delete
    251 	atf_check -s exit:0 -o not-match:'192.168.1.1' rump.ifconfig shmif0 inet
    252 	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1 delete
    253 	atf_check -s exit:0 -o not-match:'192.168.0.1' rump.ifconfig shmif0 inet
    254 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 delete
    255 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 delete
    256 	atf_check -s exit:0 -o not-match:'fc00::1' rump.ifconfig shmif0 inet6
    257 	atf_check -s exit:0 -o not-match:'fc00::2' rump.ifconfig shmif0 inet6
    258 	# can delete inactive link
    259 	atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:02
    260 	atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:02 delete
    261 	# cannot delete active link
    262 	atf_check -s not-exit:0 -e match:'SIOCDLIFADDR: Device busy' \
    263 	    rump.ifconfig shmif0 link b2:a0:75:00:00:01 delete
    264 
    265 	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1/24
    266 
    267 	# arp
    268 	atf_check -s exit:0 rump.ifconfig shmif0 -arp
    269 	atf_check -s not-exit:0 -o ignore -e ignore \
    270 	    rump.ping -c 1 -w $TIMEOUT -n 192.168.0.3
    271 	atf_check -s exit:0 -o not-match:'192.168.0.3' rump.arp -an
    272 	# The entry shouldn't appear in the routing table anymore
    273 	atf_check -s exit:0 -o not-match:'192.168.0.3' rump.netstat -nr
    274 
    275 	# netmask
    276 	atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 netmask 255.255.255.0 alias
    277 	atf_check -s exit:0 -o match:'172.16.0/24' rump.netstat -rn -f inet
    278 	atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 delete
    279 
    280 	# broadcast (does it not work?)
    281 	atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 \
    282 	    broadcast 255.255.255.255 alias
    283 	atf_check -s exit:0 -o match:'broadcast 255.255.255.255' \
    284 	    rump.ifconfig shmif0 inet
    285 
    286 	# metric (external only)
    287 	atf_check -s exit:0 rump.ifconfig shmif0 metric 10
    288 	atf_check -s exit:0 rump.ifconfig shmif0 metric 0
    289 
    290 	# prefixlen
    291 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 prefixlen 70
    292 	atf_check -s exit:0 -o match:'fc00::/70' rump.netstat -rn -f inet6
    293 
    294 	# anycast
    295 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 anycast
    296 	atf_check -s exit:0 -o match:"fc00::2.+$anycast" rump.ifconfig shmif0 inet6
    297 
    298 	# deprecated
    299 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 deprecated
    300 	# Not deprecated immediately. Need to wait nd6_timer that does it is scheduled.
    301 	interval=$(sysctl -n net.inet6.icmp6.nd6_prune)
    302 	atf_check -s exit:0 sleep $((interval + 1))
    303 	atf_check -s exit:0 -o match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
    304 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 -deprecated
    305 	atf_check -s exit:0 -o not-match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
    306 
    307 	# pltime
    308 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 pltime 3
    309 	atf_check -s exit:0 -o not-match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
    310 	atf_check -s exit:0 sleep 5
    311 	atf_check -s exit:0 -o match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
    312 
    313 	# eui64
    314 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00:1::0 eui64
    315 	atf_check -s exit:0 -o match:'fc00:1::' rump.ifconfig shmif0 inet6
    316 
    317 	unset RUMP_SERVER
    318 }
    319 
    320 ifconfig_parameters_cleanup()
    321 {
    322 	env RUMP_SERVER=${RUMP_SERVER1} rump.halt
    323 	env RUMP_SERVER=${RUMP_SERVER2} rump.halt
    324 }
    325 
    326 atf_init_test_cases()
    327 {
    328 
    329 	atf_add_test_case ifconfig_create_destroy
    330 	atf_add_test_case ifconfig_options
    331 	atf_add_test_case ifconfig_parameters
    332 }
    333