t_change.sh revision 1.14 1 # $NetBSD: t_change.sh,v 1.14 2019/05/13 17:55:09 bad Exp $
2 #
3 # Copyright (c) 2011 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 netserver=\
29 "rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
30 export RUMP_SERVER=unix://commsock
31
32 DEBUG=${DEBUG:-false}
33
34 route_cleanup_common()
35 {
36
37 $DEBUG && dump_kernel_stats unix://commsock
38 $DEBUG && extract_rump_server_core
39 env RUMP_SERVER=unix://commsock rump.halt
40 }
41
42 atf_test_case route_change_reject2blackhole cleanup
43 route_change_reject2blackhole_head()
44 {
45
46 atf_set "descr" "Change a reject route to blackhole"
47 atf_set "require.progs" "rump_server"
48 }
49
50 route_change_reject2blackhole_body()
51 {
52
53 atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
54
55 atf_check -s exit:0 -o ignore \
56 rump.route add 207.46.197.32 127.0.0.1 -reject
57 atf_check -s exit:0 -o match:UGHR -x \
58 "rump.route -n show -inet | grep ^207.46"
59 atf_check -s exit:0 -o ignore \
60 rump.route change 207.46.197.32 127.0.0.1 -blackhole
61 atf_check -s exit:0 -o match:' UGHBS ' -e ignore -x \
62 "rump.netstat -rn -f inet | grep ^207.46"
63 }
64
65 route_change_reject2blackhole_cleanup()
66 {
67
68 route_cleanup_common
69 }
70
71 atf_test_case route_change_gateway cleanup
72 route_change_gateway_head()
73 {
74
75 atf_set "descr" "Change the gateway of a route"
76 atf_set "require.progs" "rump_server"
77 }
78
79 route_change_gateway_body()
80 {
81
82 atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
83
84 atf_check -s exit:0 rump.ifconfig shmif0 create
85 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
86 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
87
88 atf_check -s exit:0 -o ignore \
89 rump.route add -net 192.168.0.0/24 10.0.0.1
90 atf_check -s exit:0 -o match:'10.0.0.1' -x \
91 "rump.route -n show -inet | grep ^192.168"
92 atf_check -s exit:0 -o ignore \
93 rump.route change -net 192.168.0.0/24 10.0.0.254
94 atf_check -s exit:0 -o match:'10.0.0.254' -x \
95 "rump.route -n show -inet | grep ^192.168"
96 }
97
98 route_change_gateway_cleanup()
99 {
100
101 route_cleanup_common
102 }
103
104 atf_test_case route_change_ifa cleanup
105 route_change_ifa_head()
106 {
107
108 atf_set "descr" "Change the ifa (local address) of a route"
109 atf_set "require.progs" "rump_server"
110 }
111
112 route_change_ifa_body()
113 {
114
115 atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
116
117 atf_check -s exit:0 rump.ifconfig shmif0 create
118 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
119 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24
120 atf_check -s exit:0 rump.ifconfig shmif0 alias 10.0.0.11/24
121 atf_check -s exit:0 rump.ifconfig shmif0 up
122
123 atf_check -s exit:0 -o ignore \
124 rump.route add -net 192.168.0.0/24 10.0.0.1
125 atf_check -s exit:0 -o match:'10.0.0.1' -x \
126 "rump.route -n show -inet | grep ^192.168"
127 $DEBUG && rump.route -n show -inet
128 cat >./expect <<-EOF
129 route to: 192.168.0.1
130 destination: 192.168.0.0
131 mask: 255.255.255.0
132 gateway: 10.0.0.1
133 local addr: 10.0.0.10
134 interface: shmif0
135 flags: 0x843<UP,GATEWAY,DONE,STATIC>
136 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
137 EOF
138 rump.route -n get 192.168.0.1 > ./output
139 $DEBUG && cat ./expect ./output
140 sed -i '$d' ./output
141 atf_check -s exit:0 diff ./expect ./output
142
143 # Change the local address of the route
144 atf_check -s exit:0 -o ignore \
145 rump.route change -net 192.168.0.0/24 10.0.0.1 -ifa 10.0.0.11
146 $DEBUG && rump.route -n show -inet
147 cat >./expect <<-EOF
148 route to: 192.168.0.1
149 destination: 192.168.0.0
150 mask: 255.255.255.0
151 gateway: 10.0.0.1
152 local addr: 10.0.0.11
153 interface: shmif0
154 flags: 0x843<UP,GATEWAY,DONE,STATIC>
155 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
156 EOF
157 rump.route -n get 192.168.0.1 > ./output
158 $DEBUG && cat ./expect ./output
159 sed -i '$d' ./output
160 atf_check -s exit:0 diff ./expect ./output
161 }
162
163 route_change_ifa_cleanup()
164 {
165
166 route_cleanup_common
167 }
168
169 atf_test_case route_change_ifp cleanup
170 route_change_ifp_head()
171 {
172
173 atf_set "descr" "Change a route based on an interface (ifp)"
174 atf_set "require.progs" "rump_server"
175 }
176
177 route_change_ifp_body()
178 {
179
180 atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
181
182 atf_check -s exit:0 rump.ifconfig shmif0 create
183 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
184 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
185
186 atf_check -s exit:0 rump.ifconfig shmif1 create
187 atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus
188 atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up
189
190 atf_check -s exit:0 -o ignore \
191 rump.route add -net 192.168.0.0/24 10.0.0.1
192 atf_check -s exit:0 -o match:'10.0.0.1' -x \
193 "rump.route -n show -inet | grep ^192.168"
194 $DEBUG && rump.route -n show -inet
195 cat >./expect <<-EOF
196 route to: 192.168.0.1
197 destination: 192.168.0.0
198 mask: 255.255.255.0
199 gateway: 10.0.0.1
200 local addr: 10.0.0.10
201 interface: shmif0
202 flags: 0x843<UP,GATEWAY,DONE,STATIC>
203 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
204 EOF
205 rump.route -n get 192.168.0.1 > ./output
206 $DEBUG && cat ./expect ./output
207 sed -i '$d' ./output
208 atf_check -s exit:0 diff ./expect ./output
209
210 # Change a route based on an interface
211 atf_check -s exit:0 -o ignore \
212 rump.route change -net 192.168.0.0/24 10.0.0.1 -ifp shmif1
213 $DEBUG && rump.route -n show -inet
214 cat >./expect <<-EOF
215 route to: 192.168.0.1
216 destination: 192.168.0.0
217 mask: 255.255.255.0
218 gateway: 10.0.0.1
219 local addr: 10.0.0.11
220 interface: shmif1
221 flags: 0x843<UP,GATEWAY,DONE,STATIC>
222 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
223 EOF
224 rump.route -n get 192.168.0.1 > ./output
225 $DEBUG && cat ./expect ./output
226 sed -i '$d' ./output
227 atf_check -s exit:0 diff ./expect ./output
228 }
229
230 route_change_ifp_cleanup()
231 {
232
233 route_cleanup_common
234 }
235
236 atf_test_case route_change_ifp_ifa cleanup
237 route_change_ifp_head()
238 {
239
240 atf_set "descr" "Change a route with -ifp and -ifa"
241 atf_set "require.progs" "rump_server"
242 }
243
244 route_change_ifp_ifa_body()
245 {
246
247 atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
248
249 atf_check -s exit:0 rump.ifconfig shmif0 create
250 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
251 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
252
253 atf_check -s exit:0 rump.ifconfig shmif1 create
254 atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus
255 atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up
256
257 atf_check -s exit:0 -o ignore \
258 rump.route add -net 192.168.0.0/24 10.0.0.1
259 atf_check -s exit:0 -o match:'10.0.0.1' -x \
260 "rump.route -n show -inet | grep ^192.168"
261 $DEBUG && rump.route -n show -inet
262 cat >./expect <<-EOF
263 route to: 192.168.0.1
264 destination: 192.168.0.0
265 mask: 255.255.255.0
266 gateway: 10.0.0.1
267 local addr: 10.0.0.10
268 interface: shmif0
269 flags: 0x843<UP,GATEWAY,DONE,STATIC>
270 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
271 EOF
272 rump.route -n get 192.168.0.1 > ./output
273 $DEBUG && cat ./expect ./output
274 sed -i '$d' ./output
275 atf_check -s exit:0 diff ./expect ./output
276
277 # Change a route with -ifa and -ifp
278 atf_check -s exit:0 -o ignore \
279 rump.route change -net 192.168.0.0/24 -ifa 10.0.0.1 -ifp shmif1
280 $DEBUG && rump.route -n show -inet
281 cat >./expect <<-EOF
282 route to: 192.168.0.1
283 destination: 192.168.0.0
284 mask: 255.255.255.0
285 gateway: 10.0.0.1
286 local addr: 10.0.0.11
287 interface: shmif1
288 flags: 0x843<UP,GATEWAY,DONE,STATIC>
289 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
290 EOF
291 rump.route -n get 192.168.0.1 > ./output
292 $DEBUG && cat ./expect ./output
293 sed -i '$d' ./output
294 atf_check -s exit:0 diff ./expect ./output
295 }
296
297 route_change_ifp_ifa_cleanup()
298 {
299
300 route_cleanup_common
301 }
302
303 atf_test_case route_change_flags cleanup
304 route_change_flags_head()
305 {
306
307 atf_set "descr" "Change flags of a route"
308 atf_set "require.progs" "rump_server"
309 }
310
311 route_change_flags_body()
312 {
313
314 atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
315
316 atf_check -s exit:0 rump.ifconfig shmif0 create
317 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
318 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
319
320 check_route 10.0.0/24 '' UC shmif0
321 # Set reject flag
322 atf_check -s exit:0 -o ignore \
323 rump.route change -net 10.0.0.0/24 -reject
324 check_route 10.0.0/24 '' URCS shmif0
325 # Clear reject flag
326 atf_check -s exit:0 -o ignore \
327 rump.route change -net 10.0.0.0/24 -noreject
328 check_route 10.0.0/24 '' UCS shmif0
329
330 # TODO other flags
331 }
332
333 route_change_flags_cleanup()
334 {
335
336 route_cleanup_common
337 }
338
339 atf_test_case route_change_default_flags cleanup
340 route_change_default_flags_head()
341 {
342
343 atf_set "descr" "Change flags of the default route"
344 atf_set "require.progs" "rump_server"
345 }
346
347 route_change_default_flags_body()
348 {
349
350 atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
351
352 atf_check -s exit:0 rump.ifconfig shmif0 create
353 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
354 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
355
356 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
357 check_route default 10.0.0.1 UGS shmif0
358 # Set reject flag
359 atf_check -s exit:0 -o ignore rump.route change default -reject
360 check_route default 10.0.0.1 UGRS shmif0
361 # Clear reject flag
362 atf_check -s exit:0 -o ignore rump.route change default -noreject
363 check_route default 10.0.0.1 UGS shmif0
364
365 # TODO other flags
366 }
367
368 route_change_default_flags_cleanup()
369 {
370
371 route_cleanup_common
372 }
373
374 atf_init_test_cases()
375 {
376
377 atf_add_test_case route_change_reject2blackhole
378 atf_add_test_case route_change_gateway
379 atf_add_test_case route_change_ifa
380 atf_add_test_case route_change_ifp
381 atf_add_test_case route_change_ifp_ifa
382 atf_add_test_case route_change_flags
383 atf_add_test_case route_change_default_flags
384 }
385