xref: /netbsd-src/tests/net/if/t_ifconfig.sh (revision 2e0bf311b34bf9507e08ee74157213840e9994d3)
1*2e0bf311Sandvar# $NetBSD: t_ifconfig.sh,v 1.22 2021/08/17 22:00:33 andvar Exp $
25fbfc689Sozaki-r#
35fbfc689Sozaki-r# Copyright (c) 2015 The NetBSD Foundation, Inc.
45fbfc689Sozaki-r# All rights reserved.
55fbfc689Sozaki-r#
65fbfc689Sozaki-r# Redistribution and use in source and binary forms, with or without
75fbfc689Sozaki-r# modification, are permitted provided that the following conditions
85fbfc689Sozaki-r# are met:
95fbfc689Sozaki-r# 1. Redistributions of source code must retain the above copyright
105fbfc689Sozaki-r#    notice, this list of conditions and the following disclaimer.
115fbfc689Sozaki-r# 2. Redistributions in binary form must reproduce the above copyright
125fbfc689Sozaki-r#    notice, this list of conditions and the following disclaimer in the
135fbfc689Sozaki-r#    documentation and/or other materials provided with the distribution.
145fbfc689Sozaki-r#
155fbfc689Sozaki-r# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
165fbfc689Sozaki-r# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
175fbfc689Sozaki-r# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
185fbfc689Sozaki-r# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
195fbfc689Sozaki-r# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
205fbfc689Sozaki-r# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
215fbfc689Sozaki-r# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
225fbfc689Sozaki-r# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
235fbfc689Sozaki-r# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
245fbfc689Sozaki-r# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
255fbfc689Sozaki-r# POSSIBILITY OF SUCH DAMAGE.
265fbfc689Sozaki-r#
275fbfc689Sozaki-r
285fbfc689Sozaki-rRUMP_SERVER1=unix://./r1
29a6c88293Sozaki-rRUMP_SERVER2=unix://./r2
305fbfc689Sozaki-r
315fbfc689Sozaki-rRUMP_FLAGS=\
325fbfc689Sozaki-r"-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_shmif"
3348e354a3SbadRUMP_FLAGS="${RUMP_FLAGS}"
345fbfc689Sozaki-r
35911c3d16Sozaki-rTIMEOUT=3
36911c3d16Sozaki-r
375642b8b6Schristosanycast="[Aa][Nn][Yy][Cc][Aa][Ss][Tt]"
385642b8b6Schristosdeprecated="[Dd][Ee][Pp][Rr][Ee][Cc][Aa][Tt][Ee][Dd]"
395642b8b6Schristos
40f91dfc92Sozaki-ratf_test_case ifconfig_create_destroy cleanup
41f91dfc92Sozaki-rifconfig_create_destroy_head()
425fbfc689Sozaki-r{
435fbfc689Sozaki-r
445fbfc689Sozaki-r	atf_set "descr" "tests of ifconfig create and destroy"
455fbfc689Sozaki-r	atf_set "require.progs" "rump_server"
465fbfc689Sozaki-r}
475fbfc689Sozaki-r
48f91dfc92Sozaki-rifconfig_create_destroy_body()
495fbfc689Sozaki-r{
505fbfc689Sozaki-r	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
515fbfc689Sozaki-r
525fbfc689Sozaki-r	export RUMP_SERVER=${RUMP_SERVER1}
535fbfc689Sozaki-r
545fbfc689Sozaki-r	# Create and destroy (no address)
555fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 create
565fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 destroy
575fbfc689Sozaki-r
585fbfc689Sozaki-r	# Create and destroy (with an IPv4 address)
595fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 create
605fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
615fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24
625fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 up
635fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 destroy
645fbfc689Sozaki-r
655fbfc689Sozaki-r	# Create and destroy (with an IPv6 address)
665fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 create
675fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
685fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1
695fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 up
705fbfc689Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 destroy
715fbfc689Sozaki-r
72bce11250Sozaki-r	# Check if ifconfig (ioctl) works after a failure of ifconfig destroy
73bce11250Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig lo0
74bce11250Sozaki-r	atf_check -s not-exit:0 -e ignore rump.ifconfig lo0 destroy
75bce11250Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig lo0
76bce11250Sozaki-r
775fbfc689Sozaki-r	unset RUMP_SERVER
785fbfc689Sozaki-r}
795fbfc689Sozaki-r
80f91dfc92Sozaki-rifconfig_create_destroy_cleanup()
815fbfc689Sozaki-r{
825fbfc689Sozaki-r
835fbfc689Sozaki-r	RUMP_SERVER=${RUMP_SERVER1} rump.halt
845fbfc689Sozaki-r}
855fbfc689Sozaki-r
86f91dfc92Sozaki-ratf_test_case ifconfig_options cleanup
87f91dfc92Sozaki-rifconfig_options_head()
88933f94aaSozaki-r{
89933f94aaSozaki-r
90933f94aaSozaki-r	atf_set "descr" "tests of ifconfig options"
91933f94aaSozaki-r	atf_set "require.progs" "rump_server"
92933f94aaSozaki-r}
93933f94aaSozaki-r
94f91dfc92Sozaki-rifconfig_options_body()
95933f94aaSozaki-r{
96933f94aaSozaki-r
97933f94aaSozaki-r	export RUMP_SERVER=${RUMP_SERVER1}
98933f94aaSozaki-r	atf_check -s exit:0 rump_server $RUMP_FLAGS $RUMP_SERVER1
99933f94aaSozaki-r
100933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
101933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr bus1
102933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet 10.0.0.1/24
103933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 fc00::1/64
104933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
105933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
106933f94aaSozaki-r	$DEBUG && rump.ifconfig shmif0
107933f94aaSozaki-r
108933f94aaSozaki-r	# ifconfig [-N] interface address_family
109933f94aaSozaki-r	#   -N resolves hostnames
110933f94aaSozaki-r	atf_check -s exit:0 -o match:'inet 127.0.0.1' rump.ifconfig lo0 inet
111933f94aaSozaki-r	atf_check -s exit:0 -o match:'inet localhost' rump.ifconfig -N lo0 inet
112933f94aaSozaki-r	atf_check -s exit:0 -o match:'inet6 ::1' rump.ifconfig lo0 inet6
113933f94aaSozaki-r	atf_check -s exit:0 -o match:'inet6 localhost' rump.ifconfig -N lo0 inet6
114933f94aaSozaki-r	atf_check -s not-exit:0 -e match:'not supported' rump.ifconfig lo0 atalk
115933f94aaSozaki-r	atf_check -s not-exit:0 -e match:'not supported' rump.ifconfig -N lo0 atalk
116933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig lo0 link
117933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -N lo0 link
118933f94aaSozaki-r
119933f94aaSozaki-r	# ifconfig [-hLmNvz] interface
120933f94aaSozaki-r	#   -h -v shows statistics in human readable format
121933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -h -v lo0
122933f94aaSozaki-r	#   -L shows IPv6 lifetime
123933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 fc00::2 \
124933f94aaSozaki-r	    pltime 100
125933f94aaSozaki-r	$DEBUG && rump.ifconfig -L shmif0
126933f94aaSozaki-r	atf_check -s exit:0 -o match:'pltime' rump.ifconfig -L shmif0
127933f94aaSozaki-r	atf_check -s exit:0 -o match:'vltime' rump.ifconfig -L shmif0
128933f94aaSozaki-r	#   -m shows all of the supported media (not supported in shmif)
129933f94aaSozaki-r	$DEBUG && rump.ifconfig -m shmif0
130933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -m shmif0
131933f94aaSozaki-r	atf_check -s exit:0 -o match:'localhost' rump.ifconfig -N lo0
132933f94aaSozaki-r	atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -v lo0
133911c3d16Sozaki-r	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT localhost
134933f94aaSozaki-r	#   -z clears and shows statistics at that point
135933f94aaSozaki-r	atf_check -s exit:0 -o match:'2 packets' rump.ifconfig -z lo0
136933f94aaSozaki-r	atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -v lo0
137933f94aaSozaki-r
138933f94aaSozaki-r	# ifconfig -a [-bdhLNmsuvz]
139933f94aaSozaki-r	#   -a shows all interfaces in the system
140933f94aaSozaki-r	$DEBUG && rump.ifconfig -a
141933f94aaSozaki-r	atf_check -s exit:0 -o match:'shmif0' -o match:'lo0' rump.ifconfig -a
142933f94aaSozaki-r	#   -a -b shows only broadcast interfaces
143933f94aaSozaki-r	atf_check -s exit:0 -o match:'shmif0' -o not-match:'lo0' rump.ifconfig -a -b
144933f94aaSozaki-r	#   -a -d shows only down interfaces
145933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 down
146933f94aaSozaki-r	atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -a -d
147933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
148933f94aaSozaki-r	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig -a -d
149933f94aaSozaki-r	atf_check -s exit:0 -o match:'pltime' rump.ifconfig -a -L
150933f94aaSozaki-r	atf_check -s exit:0 -o match:'vltime' rump.ifconfig -a -L
151933f94aaSozaki-r	atf_check -s exit:0 -o match:'localhost' rump.ifconfig -a -N
152933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -a -m
153933f94aaSozaki-r	#   -a -s shows only interfaces connected to a network
154933f94aaSozaki-r	#   (shmif is always connected)
155933f94aaSozaki-r	$DEBUG && rump.ifconfig -a -s
156933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -a -s
157933f94aaSozaki-r	#   -a -u shows only up interfaces
158933f94aaSozaki-r	atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -a -u
159933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 down
160933f94aaSozaki-r	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig -a -u
161933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
162933f94aaSozaki-r	atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -a -v
163911c3d16Sozaki-r	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT localhost
164c656a96fSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 down
165933f94aaSozaki-r	atf_check -s exit:0 -o match:'2 packets' rump.ifconfig -a -z
166933f94aaSozaki-r	atf_check -s exit:0 -o not-match:'2 packets' rump.ifconfig -a -v
167c656a96fSozaki-r	atf_check -s exit:0 -o match:'0 packets' rump.ifconfig -a -v
168c656a96fSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
169933f94aaSozaki-r
170933f94aaSozaki-r	# ifconfig -l [-bdsu]
171*2e0bf311Sandvar	#   -l shows only interface names
172b7e089f6Sozaki-r	atf_check -s exit:0 -o match:'lo0' rump.ifconfig -l
173b7e089f6Sozaki-r	atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l
174933f94aaSozaki-r	atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l -b
175b7e089f6Sozaki-r	atf_check -s exit:0 -o not-match:'lo0' rump.ifconfig -l -b
176933f94aaSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -l -d
177b7e089f6Sozaki-r	atf_check -s exit:0 -o match:'lo0' rump.ifconfig -l -s
178b7e089f6Sozaki-r	atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l -s
179b7e089f6Sozaki-r	atf_check -s exit:0 -o match:'lo0' rump.ifconfig -l -u
180b7e089f6Sozaki-r	atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l -u
181933f94aaSozaki-r
182933f94aaSozaki-r	# ifconfig -s interface
183933f94aaSozaki-r	#   -s interface exists with 0 / 1 if connected / disconnected
184933f94aaSozaki-r	atf_check -s exit:0 -o empty rump.ifconfig -s lo0
185933f94aaSozaki-r	atf_check -s exit:0 -o empty rump.ifconfig -s shmif0
186933f94aaSozaki-r
187933f94aaSozaki-r	# ifconfig -C
188933f94aaSozaki-r	#   -C shows all of the interface cloners available on the system
189ac86ae25Sozaki-r	atf_check -s exit:0 -o match:'shmif carp lo' rump.ifconfig -C
190933f94aaSozaki-r
191933f94aaSozaki-r	unset RUMP_SERVER
192933f94aaSozaki-r}
193933f94aaSozaki-r
194f91dfc92Sozaki-rifconfig_options_cleanup()
195933f94aaSozaki-r{
196933f94aaSozaki-r
197933f94aaSozaki-r	env RUMP_SERVER=${RUMP_SERVER1} rump.halt
198933f94aaSozaki-r}
199933f94aaSozaki-r
200a6c88293Sozaki-r
201f91dfc92Sozaki-ratf_test_case ifconfig_parameters cleanup
202f91dfc92Sozaki-rifconfig_parameters_head()
203a6c88293Sozaki-r{
204f91dfc92Sozaki-r	atf_set "descr" "tests of interface parameters"
205a6c88293Sozaki-r	atf_set "require.progs" "rump_server"
206a6c88293Sozaki-r}
207a6c88293Sozaki-r
208f91dfc92Sozaki-rifconfig_parameters_body()
209a6c88293Sozaki-r{
2103eb98963Sozaki-r	local interval=
2113eb98963Sozaki-r
212a6c88293Sozaki-r	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
213a6c88293Sozaki-r	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2}
214a6c88293Sozaki-r
215a6c88293Sozaki-r	export RUMP_SERVER=${RUMP_SERVER1}
216a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 create
217a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
218a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24
219a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 up
220a6c88293Sozaki-r	unset RUMP_SERVER
221a6c88293Sozaki-r
222a6c88293Sozaki-r	export RUMP_SERVER=${RUMP_SERVER2}
223a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 create
224a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
225a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.2/24
226a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.3/24 alias
227a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 up
228a6c88293Sozaki-r	unset RUMP_SERVER
229a6c88293Sozaki-r
230a6c88293Sozaki-r	export RUMP_SERVER=${RUMP_SERVER1}
231a6c88293Sozaki-r
232a6c88293Sozaki-r	# active
233a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:01 active
234a6c88293Sozaki-r	atf_check -s exit:0 -o match:'address:.b2:a0:75:00:00:01' \
235a6c88293Sozaki-r	    rump.ifconfig shmif0
236a6c88293Sozaki-r	# down, up
237a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 down
2381b0c0c88Skre	atf_check -s not-exit:0 -o ignore -e ignore rump.ping -c 1 \
239911c3d16Sozaki-r	    -w $TIMEOUT -n 192.168.0.2
240a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 up
241d1f35c1aSroy	atf_check -s exit:0 rump.ifconfig -w 10
242911c3d16Sozaki-r	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT -n 192.168.0.2
243a6c88293Sozaki-r
244a6c88293Sozaki-r	# alias
245a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 alias
246d1f35c1aSroy	atf_check -s exit:0 -o match:'192.168.1.1/24' rump.ifconfig shmif0
247a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 -alias
248d1f35c1aSroy	atf_check -s exit:0 -o not-match:'192.168.1.1/24' rump.ifconfig shmif0
249a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1
250a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2
251a6c88293Sozaki-r	atf_check -s exit:0 -o match:'fc00::1' rump.ifconfig shmif0 inet6
252a6c88293Sozaki-r	atf_check -s exit:0 -o match:'fc00::2' rump.ifconfig shmif0 inet6
253a6c88293Sozaki-r
254a6c88293Sozaki-r	# delete
255a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 alias
256a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 delete
257a6c88293Sozaki-r	atf_check -s exit:0 -o not-match:'192.168.1.1' rump.ifconfig shmif0 inet
258a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1 delete
259a6c88293Sozaki-r	atf_check -s exit:0 -o not-match:'192.168.0.1' rump.ifconfig shmif0 inet
260a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 delete
261a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 delete
262a6c88293Sozaki-r	atf_check -s exit:0 -o not-match:'fc00::1' rump.ifconfig shmif0 inet6
263a6c88293Sozaki-r	atf_check -s exit:0 -o not-match:'fc00::2' rump.ifconfig shmif0 inet6
2642640ddb6Sozaki-r	# can delete inactive link
2652640ddb6Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:02
2662640ddb6Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:02 delete
2672640ddb6Sozaki-r	# cannot delete active link
2682640ddb6Sozaki-r	atf_check -s not-exit:0 -e match:'SIOCDLIFADDR: Device busy' \
2692640ddb6Sozaki-r	    rump.ifconfig shmif0 link b2:a0:75:00:00:01 delete
270a6c88293Sozaki-r
271a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1/24
272a6c88293Sozaki-r
273a6c88293Sozaki-r	# arp
274a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 -arp
275a6c88293Sozaki-r	atf_check -s not-exit:0 -o ignore -e ignore \
276911c3d16Sozaki-r	    rump.ping -c 1 -w $TIMEOUT -n 192.168.0.3
277a6c88293Sozaki-r	atf_check -s exit:0 -o not-match:'192.168.0.3' rump.arp -an
27809973b35Sozaki-r	# The entry shouldn't appear in the routing table anymore
27909973b35Sozaki-r	atf_check -s exit:0 -o not-match:'192.168.0.3' rump.netstat -nr
280a6c88293Sozaki-r
281a6c88293Sozaki-r	# netmask
282a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 netmask 255.255.255.0 alias
283a6c88293Sozaki-r	atf_check -s exit:0 -o match:'172.16.0/24' rump.netstat -rn -f inet
284a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 delete
285a6c88293Sozaki-r
286a6c88293Sozaki-r	# broadcast (does it not work?)
287a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 \
288a6c88293Sozaki-r	    broadcast 255.255.255.255 alias
289a6c88293Sozaki-r	atf_check -s exit:0 -o match:'broadcast 255.255.255.255' \
290a6c88293Sozaki-r	    rump.ifconfig shmif0 inet
291a6c88293Sozaki-r
292a6c88293Sozaki-r	# metric (external only)
293a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 metric 10
294a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 metric 0
295a6c88293Sozaki-r
296a6c88293Sozaki-r	# prefixlen
297a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 prefixlen 70
298a6c88293Sozaki-r	atf_check -s exit:0 -o match:'fc00::/70' rump.netstat -rn -f inet6
299a6c88293Sozaki-r
300a6c88293Sozaki-r	# anycast
301a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 anycast
3025642b8b6Schristos	atf_check -s exit:0 -o match:"fc00::2.+$anycast" rump.ifconfig shmif0 inet6
303a6c88293Sozaki-r
304a6c88293Sozaki-r	# deprecated
305a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 deprecated
3063eb98963Sozaki-r	# Not deprecated immediately. Need to wait nd6_timer that does it is scheduled.
3073eb98963Sozaki-r	interval=$(sysctl -n net.inet6.icmp6.nd6_prune)
3083eb98963Sozaki-r	atf_check -s exit:0 sleep $((interval + 1))
3095642b8b6Schristos	atf_check -s exit:0 -o match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
310a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 -deprecated
3115642b8b6Schristos	atf_check -s exit:0 -o not-match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
312a6c88293Sozaki-r
313a6c88293Sozaki-r	# pltime
314a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 pltime 3
3155642b8b6Schristos	atf_check -s exit:0 -o not-match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
316a6c88293Sozaki-r	atf_check -s exit:0 sleep 5
3175642b8b6Schristos	atf_check -s exit:0 -o match:"fc00::3.+$deprecated" rump.ifconfig shmif0 inet6
318a6c88293Sozaki-r
319a6c88293Sozaki-r	# eui64
320a6c88293Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00:1::0 eui64
321a6c88293Sozaki-r	atf_check -s exit:0 -o match:'fc00:1::' rump.ifconfig shmif0 inet6
322a6c88293Sozaki-r
323a6c88293Sozaki-r	unset RUMP_SERVER
324a6c88293Sozaki-r}
325a6c88293Sozaki-r
326f91dfc92Sozaki-rifconfig_parameters_cleanup()
327a6c88293Sozaki-r{
328a6c88293Sozaki-r	env RUMP_SERVER=${RUMP_SERVER1} rump.halt
329a6c88293Sozaki-r	env RUMP_SERVER=${RUMP_SERVER2} rump.halt
330a6c88293Sozaki-r}
331a6c88293Sozaki-r
33238a46009Sozaki-rifconfig_up_down_common()
33338a46009Sozaki-r{
33438a46009Sozaki-r	local family=$1
33538a46009Sozaki-r	local ip=$2
33638a46009Sozaki-r
33738a46009Sozaki-r	if [ $family = inet6 ]; then
33838a46009Sozaki-r		rump_server_start $RUMP_SERVER1 netinet6
33938a46009Sozaki-r	else
34038a46009Sozaki-r		rump_server_start $RUMP_SERVER1
34138a46009Sozaki-r	fi
34238a46009Sozaki-r	rump_server_add_iface $RUMP_SERVER1 shmif0 bus1
34338a46009Sozaki-r
34438a46009Sozaki-r	export RUMP_SERVER=$RUMP_SERVER1
34538a46009Sozaki-r	rump.ifconfig shmif0
34638a46009Sozaki-r
34738a46009Sozaki-r	# Set the same number of trials to make the following test
34838a46009Sozaki-r	# work for both IPv4 and IPv6
34938a46009Sozaki-r	if [ $family = inet6 ]; then
35038a46009Sozaki-r		atf_check -s exit:0 -o ignore \
351edc02e28Sozaki-r		    rump.sysctl -w net.inet6.ip6.dad_count=5
35238a46009Sozaki-r	else
35338a46009Sozaki-r		atf_check -s exit:0 -o ignore \
354edc02e28Sozaki-r		    rump.sysctl -w net.inet.ip.dad_count=5
35538a46009Sozaki-r	fi
35638a46009Sozaki-r
35738a46009Sozaki-r	#
35838a46009Sozaki-r	# Assign an address and up the interface at once
35938a46009Sozaki-r	#
36038a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 $family $ip/24 up
36138a46009Sozaki-r	# UP
36238a46009Sozaki-r	atf_check -s exit:0 \
36338a46009Sozaki-r	    -o match:'shmif0.*UP.*RUNNING' rump.ifconfig shmif0
36438a46009Sozaki-r	# The address is TENTATIVE
36538a46009Sozaki-r	atf_check -s exit:0 \
36638a46009Sozaki-r	    -o match:"$ip.*TENTATIVE" rump.ifconfig shmif0
36738a46009Sozaki-r	# Waiting for DAD completion
36838a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig -w 10
36938a46009Sozaki-r	# The address left TENTATIVE
37038a46009Sozaki-r	atf_check -s exit:0 \
37138a46009Sozaki-r	    -o not-match:"$ip.*TENTATIVE" rump.ifconfig shmif0
37238a46009Sozaki-r
37338a46009Sozaki-r	#
37438a46009Sozaki-r	# ifconfig down
37538a46009Sozaki-r	#
37638a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 down
37738a46009Sozaki-r	atf_check -s exit:0 \
37838a46009Sozaki-r	    -o not-match:'shmif0.*UP.*RUNNING' rump.ifconfig shmif0
37938a46009Sozaki-r	# The address becomes DETATCHED
38038a46009Sozaki-r	atf_check -s exit:0 \
38138a46009Sozaki-r	    -o match:"$ip.*DETACHED" rump.ifconfig shmif0
38238a46009Sozaki-r	# ifconfig up
38338a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 up
38438a46009Sozaki-r	# The address becomes TENTATIVE
38538a46009Sozaki-r	atf_check -s exit:0 \
38638a46009Sozaki-r	    -o match:"$ip.*TENTATIVE" rump.ifconfig shmif0
38738a46009Sozaki-r	# Waiting for DAD completion
38838a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig -w 10
38938a46009Sozaki-r	# The address left TENTATIVE
39038a46009Sozaki-r	atf_check -s exit:0 \
39138a46009Sozaki-r	    -o not-match:"$ip.*TENTATIVE" rump.ifconfig shmif0
39238a46009Sozaki-r
39338a46009Sozaki-r	# Clean up
39438a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 $family $ip delete
39538a46009Sozaki-r
39638a46009Sozaki-r	#
39738a46009Sozaki-r	# Assign an address
39838a46009Sozaki-r	#
39938a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig shmif0 $family $ip/24
40038a46009Sozaki-r	# UP automatically
40138a46009Sozaki-r	atf_check -s exit:0 \
40238a46009Sozaki-r	    -o match:'shmif0.*UP.*RUNNING' rump.ifconfig shmif0
40338a46009Sozaki-r	# Need some delay
40438a46009Sozaki-r	sleep 1
40538a46009Sozaki-r	# The IP becomes TENTATIVE
40638a46009Sozaki-r	atf_check -s exit:0 \
40738a46009Sozaki-r	    -o match:"$ip.*TENTATIVE" rump.ifconfig shmif0
40838a46009Sozaki-r	# Waiting for DAD completion
40938a46009Sozaki-r	atf_check -s exit:0 rump.ifconfig -w 10
41038a46009Sozaki-r	# The address left TENTATIVE
41138a46009Sozaki-r	atf_check -s exit:0 \
41238a46009Sozaki-r	    -o not-match:"$ip.*TENTATIVE" rump.ifconfig shmif0
41338a46009Sozaki-r
41438a46009Sozaki-r	rump_server_destroy_ifaces
41538a46009Sozaki-r}
41638a46009Sozaki-r
41738a46009Sozaki-ratf_test_case ifconfig_up_down_ipv4 cleanup
41838a46009Sozaki-rifconfig_up_down_ipv4_head()
41938a46009Sozaki-r{
42038a46009Sozaki-r	atf_set "descr" "tests of interface up/down (IPv4)"
42138a46009Sozaki-r	atf_set "require.progs" "rump_server"
42238a46009Sozaki-r}
42338a46009Sozaki-r
42438a46009Sozaki-rifconfig_up_down_ipv4_body()
42538a46009Sozaki-r{
42638a46009Sozaki-r
42738a46009Sozaki-r	ifconfig_up_down_common inet 10.0.0.1
42838a46009Sozaki-r}
42938a46009Sozaki-r
43038a46009Sozaki-rifconfig_up_down_ipv4_cleanup()
43138a46009Sozaki-r{
43238a46009Sozaki-r
43338a46009Sozaki-r	$DEBUG && dump
43438a46009Sozaki-r	cleanup
43538a46009Sozaki-r}
43638a46009Sozaki-r
43738a46009Sozaki-ratf_test_case ifconfig_up_down_ipv6 cleanup
43838a46009Sozaki-rifconfig_up_down_ipv6_head()
43938a46009Sozaki-r{
44038a46009Sozaki-r	atf_set "descr" "tests of interface up/down (IPv6)"
44138a46009Sozaki-r	atf_set "require.progs" "rump_server"
44238a46009Sozaki-r}
44338a46009Sozaki-r
44438a46009Sozaki-rifconfig_up_down_ipv6_body()
44538a46009Sozaki-r{
44638a46009Sozaki-r
44738a46009Sozaki-r	ifconfig_up_down_common inet6 fc00::1
44838a46009Sozaki-r}
44938a46009Sozaki-r
45038a46009Sozaki-rifconfig_up_down_ipv6_cleanup()
45138a46009Sozaki-r{
45238a46009Sozaki-r
45338a46009Sozaki-r	$DEBUG && dump
45438a46009Sozaki-r	cleanup
45538a46009Sozaki-r}
45638a46009Sozaki-r
457bb335adbSozaki-ratf_test_case ifconfig_number cleanup
458bb335adbSozaki-rifconfig_number_head()
459bb335adbSozaki-r{
460bb335adbSozaki-r	atf_set "descr" "tests of passing a number (if_index) to ifconfig"
461bb335adbSozaki-r	atf_set "require.progs" "rump_server"
462bb335adbSozaki-r}
463bb335adbSozaki-r
464bb335adbSozaki-rifconfig_number_body()
465bb335adbSozaki-r{
466bb335adbSozaki-r
467bb335adbSozaki-r	rump_server_start $RUMP_SERVER1
468bb335adbSozaki-r	rump_server_add_iface $RUMP_SERVER1 shmif0 bus1
469bb335adbSozaki-r
470bb335adbSozaki-r	export RUMP_SERVER=$RUMP_SERVER1
471bb335adbSozaki-r	atf_check -s not-exit:0 -e match:'Device not configured' rump.ifconfig 0
472bb335adbSozaki-r	atf_check -s exit:0 rump.ifconfig 1 # lo0
473bb335adbSozaki-r	atf_check -s exit:0 rump.ifconfig 2 # shmif0
474bb335adbSozaki-r	atf_check -s not-exit:0 -e match:'Device not configured' rump.ifconfig 3
475bb335adbSozaki-r
476bb335adbSozaki-r	rump_server_destroy_ifaces
477bb335adbSozaki-r}
478bb335adbSozaki-r
479bb335adbSozaki-rifconfig_number_cleanup()
480bb335adbSozaki-r{
481bb335adbSozaki-r
482bb335adbSozaki-r	$DEBUG && dump
483bb335adbSozaki-r	cleanup
484bb335adbSozaki-r}
485bb335adbSozaki-r
48624bc91d9Sozaki-ratf_test_case ifconfig_description cleanup
48724bc91d9Sozaki-rifconfig_description_head()
48824bc91d9Sozaki-r{
48924bc91d9Sozaki-r	atf_set "descr" "tests of setting and unsetting interface description"
49024bc91d9Sozaki-r	atf_set "require.progs" "rump_server"
49124bc91d9Sozaki-r}
49224bc91d9Sozaki-r
49324bc91d9Sozaki-rifconfig_description_body()
49424bc91d9Sozaki-r{
49524bc91d9Sozaki-r
49624bc91d9Sozaki-r	rump_server_start $RUMP_SERVER1
49724bc91d9Sozaki-r
49824bc91d9Sozaki-r	export RUMP_SERVER=$RUMP_SERVER1
49924bc91d9Sozaki-r	for descr in description descr; do
50024bc91d9Sozaki-r		atf_check -s exit:0 rump.ifconfig lo0 $descr DESCRIPTION-TEST
50124bc91d9Sozaki-r		atf_check -s exit:0 -o match:"DESCRIPTION-TEST" rump.ifconfig lo0
50224bc91d9Sozaki-r		atf_check -s exit:0 rump.ifconfig lo0 $descr DESCRIPTION-TEST-MODIFIED
50324bc91d9Sozaki-r		atf_check -s exit:0 -o match:"DESCRIPTION-TEST-MODIFIED" rump.ifconfig lo0
50424bc91d9Sozaki-r		atf_check -s exit:0 rump.ifconfig lo0 -$descr
50524bc91d9Sozaki-r		atf_check -s exit:0 -o not-match:'DESCRIPTION-TEST-MODIFIED' rump.ifconfig lo0
50624bc91d9Sozaki-r
50724bc91d9Sozaki-r		atf_check -s exit:0 rump.ifconfig lo0 $descr `printf "%063d" 0`
50824bc91d9Sozaki-r		atf_check -s not-exit:0 -e match:"description too long" rump.ifconfig lo0 $descr `printf "%064d" 0`
50924bc91d9Sozaki-r		atf_check -s exit:0 rump.ifconfig lo0 $descr ""
51024bc91d9Sozaki-r	done
51124bc91d9Sozaki-r}
51224bc91d9Sozaki-r
51324bc91d9Sozaki-rifconfig_description_cleanup()
51424bc91d9Sozaki-r{
51524bc91d9Sozaki-r
51624bc91d9Sozaki-r	$DEBUG && dump
51724bc91d9Sozaki-r	cleanup
51824bc91d9Sozaki-r}
51924bc91d9Sozaki-r
5205fbfc689Sozaki-ratf_init_test_cases()
5215fbfc689Sozaki-r{
5225fbfc689Sozaki-r
523f91dfc92Sozaki-r	atf_add_test_case ifconfig_create_destroy
524f91dfc92Sozaki-r	atf_add_test_case ifconfig_options
525f91dfc92Sozaki-r	atf_add_test_case ifconfig_parameters
52638a46009Sozaki-r	atf_add_test_case ifconfig_up_down_ipv4
52738a46009Sozaki-r	atf_add_test_case ifconfig_up_down_ipv6
528bb335adbSozaki-r	atf_add_test_case ifconfig_number
52924bc91d9Sozaki-r	atf_add_test_case ifconfig_description
5305fbfc689Sozaki-r}
531