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