t_ifconfig.sh revision 1.6 1 # $NetBSD: t_ifconfig.sh,v 1.6 2015/11/20 05:05:40 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 shmif0' rump.ifconfig -l
164 atf_check -s exit:0 -o match:'shmif0' rump.ifconfig -l -b
165 atf_check -s exit:0 -o ignore rump.ifconfig -l -d
166 atf_check -s exit:0 -o match:'lo0 shmif0' rump.ifconfig -l -s
167 atf_check -s exit:0 -o match:'lo0 shmif0' rump.ifconfig -l -u
168
169 # ifconfig -s interface
170 # -s interface exists with 0 / 1 if connected / disconnected
171 atf_check -s exit:0 -o empty rump.ifconfig -s lo0
172 atf_check -s exit:0 -o empty rump.ifconfig -s shmif0
173
174 # ifconfig -C
175 # -C shows all of the interface cloners available on the system
176 atf_check -s exit:0 -o match:'shmif lo carp' rump.ifconfig -C
177
178 unset RUMP_SERVER
179 }
180
181 options_cleanup()
182 {
183
184 env RUMP_SERVER=${RUMP_SERVER1} rump.halt
185 }
186
187
188 atf_test_case parameters cleanup
189 parameters_head()
190 {
191 atf_set "descr" "tests of interface parametors"
192 atf_set "require.progs" "rump_server"
193 }
194
195 parameters_body()
196 {
197 local interval=
198
199 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
200 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2}
201
202 export RUMP_SERVER=${RUMP_SERVER1}
203 atf_check -s exit:0 rump.ifconfig shmif0 create
204 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
205 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24
206 atf_check -s exit:0 rump.ifconfig shmif0 up
207 unset RUMP_SERVER
208
209 export RUMP_SERVER=${RUMP_SERVER2}
210 atf_check -s exit:0 rump.ifconfig shmif0 create
211 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
212 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.2/24
213 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.3/24 alias
214 atf_check -s exit:0 rump.ifconfig shmif0 up
215 unset RUMP_SERVER
216
217 export RUMP_SERVER=${RUMP_SERVER1}
218
219 # active
220 atf_check -s exit:0 rump.ifconfig shmif0 link b2:a0:75:00:00:01 active
221 atf_check -s exit:0 -o match:'address:.b2:a0:75:00:00:01' \
222 rump.ifconfig shmif0
223 # down, up
224 atf_check -s exit:0 rump.ifconfig shmif0 down
225 atf_check -s ignore -o ignore -e match:'down' rump.ping -c 1 \
226 -w $TIMEOUT -n 192.168.0.2
227 atf_check -s exit:0 rump.ifconfig shmif0 up
228 atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT -n 192.168.0.2
229
230 # alias
231 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 alias
232 atf_check -s exit:0 -o match:'alias 192.168.1.1' rump.ifconfig shmif0
233 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1/24 -alias
234 atf_check -s exit:0 -o not-match:'192.168.1.1' rump.ifconfig shmif0
235 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1
236 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2
237 atf_check -s exit:0 -o match:'fc00::1' rump.ifconfig shmif0 inet6
238 atf_check -s exit:0 -o match:'fc00::2' rump.ifconfig shmif0 inet6
239
240 # delete
241 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 alias
242 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.1.1 delete
243 atf_check -s exit:0 -o not-match:'192.168.1.1' rump.ifconfig shmif0 inet
244 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1 delete
245 atf_check -s exit:0 -o not-match:'192.168.0.1' rump.ifconfig shmif0 inet
246 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 delete
247 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 delete
248 atf_check -s exit:0 -o not-match:'fc00::1' rump.ifconfig shmif0 inet6
249 atf_check -s exit:0 -o not-match:'fc00::2' rump.ifconfig shmif0 inet6
250
251 atf_check -s exit:0 rump.ifconfig shmif0 inet 192.168.0.1/24
252
253 # arp
254 atf_check -s exit:0 rump.ifconfig shmif0 -arp
255 atf_check -s not-exit:0 -o ignore -e ignore \
256 rump.ping -c 1 -w $TIMEOUT -n 192.168.0.3
257 atf_check -s exit:0 -o not-match:'192.168.0.3' rump.arp -an
258
259 # netmask
260 atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 netmask 255.255.255.0 alias
261 atf_check -s exit:0 -o match:'172.16.0/24' rump.netstat -rn -f inet
262 atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 delete
263
264 # broadcast (does it not work?)
265 atf_check -s exit:0 rump.ifconfig shmif0 inet 172.16.0.1 \
266 broadcast 255.255.255.255 alias
267 atf_check -s exit:0 -o match:'broadcast 255.255.255.255' \
268 rump.ifconfig shmif0 inet
269
270 # metric (external only)
271 atf_check -s exit:0 rump.ifconfig shmif0 metric 10
272 atf_check -s exit:0 rump.ifconfig shmif0 metric 0
273
274 # prefixlen
275 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 prefixlen 70
276 atf_check -s exit:0 -o match:'fc00::/70' rump.netstat -rn -f inet6
277
278 # anycast
279 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2 anycast
280 atf_check -s exit:0 -o match:'fc00::2.+anycast' rump.ifconfig shmif0 inet6
281
282 # deprecated
283 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 deprecated
284 # Not deprecated immediately. Need to wait nd6_timer that does it is scheduled.
285 interval=$(sysctl -n net.inet6.icmp6.nd6_prune)
286 atf_check -s exit:0 sleep $((interval + 1))
287 atf_check -s exit:0 -o match:'fc00::3.+deprecated' rump.ifconfig shmif0 inet6
288 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 -deprecated
289 atf_check -s exit:0 -o not-match:'fc00::3.+deprecated' rump.ifconfig shmif0 inet6
290
291 # pltime
292 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::3 pltime 3
293 atf_check -s exit:0 -o not-match:'fc00::3.+deprecated' rump.ifconfig shmif0 inet6
294 atf_check -s exit:0 sleep 5
295 atf_check -s exit:0 -o match:'fc00::3.+deprecated' rump.ifconfig shmif0 inet6
296
297 # eui64
298 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00:1::0 eui64
299 atf_check -s exit:0 -o match:'fc00:1::' rump.ifconfig shmif0 inet6
300
301 unset RUMP_SERVER
302 }
303
304 parameters_cleanup()
305 {
306 env RUMP_SERVER=${RUMP_SERVER1} rump.halt
307 env RUMP_SERVER=${RUMP_SERVER2} rump.halt
308 }
309
310 atf_init_test_cases()
311 {
312
313 atf_add_test_case create_destroy
314 atf_add_test_case options
315 atf_add_test_case parameters
316 }
317