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