t_flags.sh revision 1.13 1 # $NetBSD: t_flags.sh,v 1.13 2016/11/24 09:05:17 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 netserver=\
29 "rump_server -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \
30 -lrumpnet_shmif"
31 SOCK_LOCAL=unix://commsock1
32 SOCK_PEER=unix://commsock2
33 SOCK_GW=unix://commsock3
34 BUS=bus1
35 BUS2=bus2
36
37 DEBUG=${DEBUG:-false}
38
39 setup_local()
40 {
41
42 atf_check -s exit:0 ${netserver} ${SOCK_LOCAL}
43
44 export RUMP_SERVER=$SOCK_LOCAL
45 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
46 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
47 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24
48 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
49
50 $DEBUG && rump.ifconfig
51 $DEBUG && rump.netstat -rn -f inet
52 }
53
54 setup_peer()
55 {
56
57 atf_check -s exit:0 ${netserver} ${SOCK_PEER}
58
59 export RUMP_SERVER=$SOCK_PEER
60 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
61 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
62 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24
63 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
64
65 $DEBUG && rump.ifconfig
66 $DEBUG && rump.netstat -rn -f inet
67 }
68
69 setup_gw()
70 {
71
72 atf_check -s exit:0 ${netserver} ${SOCK_GW}
73
74 export RUMP_SERVER=$SOCK_GW
75 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
76 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
77 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24
78 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
79
80 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 create
81 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 linkstr ${BUS2}
82 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24
83 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24
84 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up
85
86 # Wait until DAD completes (10 sec at most)
87 atf_check -s exit:0 -o ignore rump.ifconfig -w 10
88 atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative"
89
90 $DEBUG && rump.ifconfig
91 $DEBUG && rump.netstat -rn -f inet
92 }
93
94 teardown_gw()
95 {
96
97 env RUMP_SERVER=$SOCK_GW rump.halt
98 }
99
100 test_lo()
101 {
102
103 export RUMP_SERVER=$SOCK_LOCAL
104
105 # Up, Host, local
106 check_route_flags 127.0.0.1 UHl
107 }
108
109 test_connected()
110 {
111
112 export RUMP_SERVER=$SOCK_LOCAL
113
114 # Up, Host, LLINFO, local
115 check_route_flags 10.0.0.2 UHl
116
117 # Up, Cloning
118 check_route_flags 10.0.0/24 UC
119 }
120
121 test_default_gateway()
122 {
123
124 export RUMP_SERVER=$SOCK_LOCAL
125
126 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
127 $DEBUG && rump.netstat -rn -f inet
128
129 # Up, Gateway, Static
130 check_route_flags default UGS
131 }
132
133 test_static()
134 {
135
136 export RUMP_SERVER=$SOCK_LOCAL
137
138 # Static route to host
139 atf_check -s exit:0 -o ignore rump.route add 10.0.1.1 10.0.0.1
140 $DEBUG && rump.netstat -rn -f inet
141
142 # Up, Gateway, Host, Static
143 check_route_flags 10.0.1.1 UGHS
144
145 # Static route to network
146 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.1
147 $DEBUG && rump.netstat -rn -f inet
148
149 # Up, Gateway, Static
150 check_route_flags 10.0.2/24 UGS
151 }
152
153 test_blackhole()
154 {
155
156 export RUMP_SERVER=$SOCK_LOCAL
157
158 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
159
160 # Delete an existing route first
161 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
162
163 # Gateway must be lo0
164 atf_check -s exit:0 -o ignore \
165 rump.route add -net 10.0.0.0/24 127.0.0.1 -blackhole
166 $DEBUG && rump.netstat -rn -f inet
167
168 # Up, Gateway, Blackhole, Static
169 check_route_flags 10.0.0/24 UGBS
170
171 atf_check -s not-exit:0 -o match:'100.0% packet loss' \
172 rump.ping -n -w 1 -c 1 10.0.0.1
173 $DEBUG && rump.netstat -rn -f inet
174
175 # Shouldn't be created
176 check_route_no_entry 10.0.0.1
177 }
178
179 test_reject()
180 {
181
182 export RUMP_SERVER=$SOCK_LOCAL
183
184 # Delete an existing route first
185 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
186
187 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -reject
188 $DEBUG && rump.netstat -rn -f inet
189
190 # Up, Gateway, Reject, Static
191 check_route_flags 10.0.0/24 UGRS
192
193 atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
194 rump.ping -n -w 1 -c 1 10.0.0.1
195 $DEBUG && rump.netstat -rn -f inet
196
197 # Shouldn't be created
198 check_route_no_entry 10.0.0.1
199
200 # Gateway is lo0 (RTF_GATEWAY)
201
202 # Delete an existing route first
203 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
204
205 atf_check -s exit:0 -o ignore \
206 rump.route add -net 10.0.0.0/24 127.0.0.1 -reject
207 $DEBUG && rump.netstat -rn -f inet
208
209 # Up, Gateway, Reject, Static
210 check_route_flags 10.0.0/24 UGRS
211
212 atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
213 rump.ping -n -w 1 -c 1 10.0.0.1
214 $DEBUG && rump.netstat -rn -f inet
215
216 # Shouldn't be created
217 check_route_no_entry 10.0.0.1
218
219 # Gateway is lo0 (RTF_HOST)
220
221 # Delete an existing route first
222 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
223
224 atf_check -s exit:0 -o ignore \
225 rump.route add -host 10.0.0.1/24 127.0.0.1 -iface -reject
226 $DEBUG && rump.netstat -rn -f inet
227
228 # Up, Host, Reject, Static
229 check_route_flags 10.0.0.1 UHRS
230
231 atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
232 rump.ping -n -w 1 -c 1 10.0.0.1
233 $DEBUG && rump.netstat -rn -f inet
234
235 return 0
236 }
237
238 test_icmp_redirect()
239 {
240
241 ### Testing Dynamic flag ###
242
243 #
244 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
245 #
246 setup_gw
247
248 #
249 # Teach the peer that 10.0.2.* is behind 10.0.0.254
250 #
251 export RUMP_SERVER=$SOCK_PEER
252 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
253 # Up, Gateway, Static
254 check_route_flags 10.0.2/24 UGS
255
256 #
257 # Setup the default gateway to the peer, 10.0.0.1
258 #
259 export RUMP_SERVER=$SOCK_LOCAL
260 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
261 # Up, Gateway, Static
262 check_route_flags default UGS
263
264 # Try ping 10.0.2.1
265 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
266 $DEBUG && rump.netstat -rn -f inet
267
268 # Up, Gateway, Host, Dynamic
269 check_route_flags 10.0.2.1 UGHD
270 check_route_gw 10.0.2.1 10.0.0.254
271
272 export RUMP_SERVER=$SOCK_PEER
273 $DEBUG && rump.netstat -rn -f inet
274
275 ### Testing Modified flag ###
276
277 #
278 # Teach a wrong route to 10.0.2.2
279 #
280 export RUMP_SERVER=$SOCK_LOCAL
281 atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1
282 # Up, Gateway, Host, Static
283 check_route_flags 10.0.2.2 UGHS
284 check_route_gw 10.0.2.2 10.0.0.1
285
286 # Try ping 10.0.2.2
287 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2
288 $DEBUG && rump.netstat -rn -f inet
289
290 # Up, Gateway, Host, Modified, Static
291 check_route_flags 10.0.2.2 UGHMS
292 check_route_gw 10.0.2.2 10.0.0.254
293
294 teardown_gw
295 }
296
297 test_announce()
298 {
299 export RUMP_SERVER=$SOCK_LOCAL
300
301 # Delete an existing route first
302 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
303
304 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -proxy
305 $DEBUG && rump.netstat -rn -f inet
306
307 # Up, Gateway, Static, proxy
308 check_route_flags 10.0.0/24 UGSp
309
310 # TODO test its behavior
311 }
312
313 cleanup()
314 {
315 $DEBUG && /usr/bin/shmif_dumpbus -p - $BUS 2>/dev/null | \
316 /usr/sbin/tcpdump -n -e -r -
317 env RUMP_SERVER=$SOCK_LOCAL rump.halt
318 env RUMP_SERVER=$SOCK_PEER rump.halt
319 }
320
321 add_test()
322 {
323 local name=$1
324 local desc="$2"
325
326 atf_test_case "route_flags_${name}" cleanup
327 eval "route_flags_${name}_head() { \
328 atf_set \"descr\" \"${desc}\"; \
329 atf_set \"require.progs\" \"rump_server\"; \
330 }; \
331 route_flags_${name}_body() { \
332 setup_local; \
333 setup_peer; \
334 test_${name}; \
335 }; \
336 route_flags_${name}_cleanup() { \
337 cleanup; \
338 }"
339 atf_add_test_case "route_flags_${name}"
340 }
341
342 atf_init_test_cases()
343 {
344
345 add_test lo "Tests route flags: loop back interface"
346 add_test connected "Tests route flags: connected route"
347 add_test default_gateway "Tests route flags: default gateway"
348 add_test static "Tests route flags: static route"
349 add_test blackhole "Tests route flags: blackhole route"
350 add_test reject "Tests route flags: reject route"
351 add_test icmp_redirect "Tests route flags: icmp redirect"
352 add_test announce "Tests route flags: announce flag"
353 }
354