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