]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/net/route/t_flags.sh
MFC r311925,r311968,r311969,r312008:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / net / route / t_flags.sh
1 #       $NetBSD: t_flags.sh,v 1.15 2016/12/21 02:46:08 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, LLINFO, 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 }
167
168 test_reject()
169 {
170
171         export RUMP_SERVER=$SOCK_LOCAL
172
173         # Delete an existing route first
174         atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
175
176         atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -reject
177         $DEBUG && rump.netstat -rn -f inet
178
179         # Up, Gateway, Reject, Static
180         check_route_flags 10.0.0/24 UGRS
181
182         atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
183             rump.ping -n -w 1 -c 1 10.0.0.1
184         $DEBUG && rump.netstat -rn -f inet
185
186         # Shouldn't be created
187         check_route_no_entry 10.0.0.1
188
189         # Gateway is lo0 (RTF_GATEWAY)
190
191         # Delete an existing route first
192         atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
193
194         atf_check -s exit:0 -o ignore \
195             rump.route add -net 10.0.0.0/24 127.0.0.1 -reject
196         $DEBUG && rump.netstat -rn -f inet
197
198         # Up, Gateway, Reject, Static
199         check_route_flags 10.0.0/24 UGRS
200
201         atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
202             rump.ping -n -w 1 -c 1 10.0.0.1
203         $DEBUG && rump.netstat -rn -f inet
204
205         # Shouldn't be created
206         check_route_no_entry 10.0.0.1
207
208         # Gateway is lo0 (RTF_HOST)
209
210         # Delete an existing route first
211         atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
212
213         atf_check -s exit:0 -o ignore \
214             rump.route add -host 10.0.0.1/24 127.0.0.1 -iface -reject
215         $DEBUG && rump.netstat -rn -f inet
216
217         # Up, Host, Reject, Static
218         check_route_flags 10.0.0.1 UHRS
219
220         atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
221             rump.ping -n -w 1 -c 1 10.0.0.1
222         $DEBUG && rump.netstat -rn -f inet
223
224         return 0
225 }
226
227 test_icmp_redirect()
228 {
229
230         ### Testing Dynamic flag ###
231
232         #
233         # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
234         #
235         setup_gw
236
237         #
238         # Teach the peer that 10.0.2.* is behind 10.0.0.254
239         #
240         export RUMP_SERVER=$SOCK_PEER
241         atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
242         # Up, Gateway, Static
243         check_route_flags 10.0.2/24 UGS
244
245         #
246         # Setup the default gateway to the peer, 10.0.0.1
247         #
248         export RUMP_SERVER=$SOCK_LOCAL
249         atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
250         # Up, Gateway, Static
251         check_route_flags default UGS
252
253         # Try ping 10.0.2.1
254         atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
255         $DEBUG && rump.netstat -rn -f inet
256
257         # Up, Gateway, Host, Dynamic
258         check_route_flags 10.0.2.1 UGHD
259         check_route_gw 10.0.2.1 10.0.0.254
260
261         export RUMP_SERVER=$SOCK_PEER
262         $DEBUG && rump.netstat -rn -f inet
263
264         ### Testing Modified flag ###
265
266         #
267         # Teach a wrong route to 10.0.2.2
268         #
269         export RUMP_SERVER=$SOCK_LOCAL
270         atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1
271         # Up, Gateway, Host, Static
272         check_route_flags 10.0.2.2 UGHS
273         check_route_gw 10.0.2.2 10.0.0.1
274
275         # Try ping 10.0.2.2
276         atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2
277         $DEBUG && rump.netstat -rn -f inet
278
279         # Up, Gateway, Host, Modified, Static
280         check_route_flags 10.0.2.2 UGHMS
281         check_route_gw 10.0.2.2 10.0.0.254
282 }
283
284 test_announce()
285 {
286         export RUMP_SERVER=$SOCK_LOCAL
287
288         # Delete an existing route first
289         atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
290
291         atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -proxy
292         $DEBUG && rump.netstat -rn -f inet
293
294         # Up, Gateway, Static, proxy
295         check_route_flags 10.0.0/24 UGSp
296
297         # TODO test its behavior
298 }
299
300 add_test()
301 {
302         local name=$1
303         local desc="$2"
304
305         atf_test_case "route_flags_${name}" cleanup
306         eval "route_flags_${name}_head() { \
307                         atf_set \"descr\" \"${desc}\"; \
308                         atf_set \"require.progs\" \"rump_server\"; \
309                 }; \
310             route_flags_${name}_body() { \
311                         setup_local; \
312                         setup_peer; \
313                         test_${name}; \
314                         rump_server_destroy_ifaces; \
315                 }; \
316             route_flags_${name}_cleanup() { \
317                         $DEBUG && dump; \
318                         cleanup; \
319                 }"
320         atf_add_test_case "route_flags_${name}"
321 }
322
323 atf_init_test_cases()
324 {
325
326         add_test lo              "Tests route flags: loop back interface"
327         add_test connected       "Tests route flags: connected route"
328         add_test default_gateway "Tests route flags: default gateway"
329         add_test static          "Tests route flags: static route"
330         add_test blackhole       "Tests route flags: blackhole route"
331         add_test reject          "Tests route flags: reject route"
332         add_test icmp_redirect   "Tests route flags: icmp redirect"
333         add_test announce        "Tests route flags: announce flag"
334 }