1 # $NetBSD: t_flags.sh,v 1.15 2016/12/21 02:46:08 ozaki-r Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
28 SOCK_LOCAL=unix://commsock1
29 SOCK_PEER=unix://commsock2
30 SOCK_GW=unix://commsock3
39 rump_server_start $SOCK_LOCAL
40 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
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
47 $DEBUG && rump.ifconfig
48 $DEBUG && rump.netstat -rn -f inet
54 rump_server_start $SOCK_PEER
55 rump_server_add_iface $SOCK_PEER shmif0 $BUS
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
62 $DEBUG && rump.ifconfig
63 $DEBUG && rump.netstat -rn -f inet
69 rump_server_start $SOCK_GW
70 rump_server_add_iface $SOCK_GW shmif0 $BUS
71 rump_server_add_iface $SOCK_GW shmif1 $BUS2
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
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
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"
85 $DEBUG && rump.ifconfig
86 $DEBUG && rump.netstat -rn -f inet
92 export RUMP_SERVER=$SOCK_LOCAL
95 check_route_flags 127.0.0.1 UHl
101 export RUMP_SERVER=$SOCK_LOCAL
103 # Up, Host, LLINFO, local
104 check_route_flags 10.0.0.2 UHl
107 check_route_flags 10.0.0/24 UC
110 test_default_gateway()
113 export RUMP_SERVER=$SOCK_LOCAL
115 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
116 $DEBUG && rump.netstat -rn -f inet
118 # Up, Gateway, Static
119 check_route_flags default UGS
125 export RUMP_SERVER=$SOCK_LOCAL
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
131 # Up, Gateway, Host, Static
132 check_route_flags 10.0.1.1 UGHS
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
138 # Up, Gateway, Static
139 check_route_flags 10.0.2/24 UGS
145 export RUMP_SERVER=$SOCK_LOCAL
147 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
149 # Delete an existing route first
150 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
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
157 # Up, Gateway, Blackhole, Static
158 check_route_flags 10.0.0/24 UGBS
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
164 # Shouldn't be created
165 check_route_no_entry 10.0.0.1
171 export RUMP_SERVER=$SOCK_LOCAL
173 # Delete an existing route first
174 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
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
179 # Up, Gateway, Reject, Static
180 check_route_flags 10.0.0/24 UGRS
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
186 # Shouldn't be created
187 check_route_no_entry 10.0.0.1
189 # Gateway is lo0 (RTF_GATEWAY)
191 # Delete an existing route first
192 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
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
198 # Up, Gateway, Reject, Static
199 check_route_flags 10.0.0/24 UGRS
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
205 # Shouldn't be created
206 check_route_no_entry 10.0.0.1
208 # Gateway is lo0 (RTF_HOST)
210 # Delete an existing route first
211 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
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
217 # Up, Host, Reject, Static
218 check_route_flags 10.0.0.1 UHRS
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
230 ### Testing Dynamic flag ###
233 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
238 # Teach the peer that 10.0.2.* is behind 10.0.0.254
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
246 # Setup the default gateway to the peer, 10.0.0.1
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
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
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
261 export RUMP_SERVER=$SOCK_PEER
262 $DEBUG && rump.netstat -rn -f inet
264 ### Testing Modified flag ###
267 # Teach a wrong route to 10.0.2.2
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
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
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
286 export RUMP_SERVER=$SOCK_LOCAL
288 # Delete an existing route first
289 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
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
294 # Up, Gateway, Static, proxy
295 check_route_flags 10.0.0/24 UGSp
297 # TODO test its behavior
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\"; \
310 route_flags_${name}_body() { \
314 rump_server_destroy_ifaces; \
316 route_flags_${name}_cleanup() { \
320 atf_add_test_case "route_flags_${name}"
323 atf_init_test_cases()
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"