1 # $NetBSD: t_flags.sh,v 1.11 2016/08/10 23:00:39 roy 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.
29 "rump_server -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \
31 SOCK_LOCAL=unix://commsock1
32 SOCK_PEER=unix://commsock2
33 SOCK_GW=unix://commsock3
42 atf_check -s exit:0 ${netserver} ${SOCK_LOCAL}
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
50 $DEBUG && rump.ifconfig
51 $DEBUG && rump.netstat -rn -f inet
57 atf_check -s exit:0 ${netserver} ${SOCK_PEER}
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
65 $DEBUG && rump.ifconfig
66 $DEBUG && rump.netstat -rn -f inet
72 atf_check -s exit:0 ${netserver} ${SOCK_GW}
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
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
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"
90 $DEBUG && rump.ifconfig
91 $DEBUG && rump.netstat -rn -f inet
97 env RUMP_SERVER=$SOCK_GW rump.halt
102 local ip=$(echo $1 |sed 's/\./\\./g')
105 atf_check -s exit:0 -o match:" $flags " -e ignore -x \
106 "rump.netstat -rn -f inet | grep ^'$ip'"
111 local ip=$(echo $1 |sed 's/\./\\./g')
114 atf_check -s exit:0 -o match:" $gw " -e ignore -x \
115 "rump.netstat -rn -f inet | grep ^'$ip'"
120 ip=$(echo $1 |sed 's/\./\\./g')
121 flags=$2 # Not used currently
123 atf_check -s not-exit:0 -e ignore -x \
124 "rump.netstat -rn -f inet | grep ^'$ip'"
130 export RUMP_SERVER=$SOCK_LOCAL
133 check_entry_flags 127.0.0.1 UHl
139 export RUMP_SERVER=$SOCK_LOCAL
141 # Up, Host, LLINFO, local
142 check_entry_flags 10.0.0.2 UHl
145 check_entry_flags 10.0.0/24 UC
148 test_default_gateway()
151 export RUMP_SERVER=$SOCK_LOCAL
153 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
154 $DEBUG && rump.netstat -rn -f inet
156 # Up, Gateway, Static
157 check_entry_flags default UGS
163 export RUMP_SERVER=$SOCK_LOCAL
165 # Static route to host
166 atf_check -s exit:0 -o ignore rump.route add 10.0.1.1 10.0.0.1
167 $DEBUG && rump.netstat -rn -f inet
169 # Up, Gateway, Host, Static
170 check_entry_flags 10.0.1.1 UGHS
172 # Static route to network
173 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.1
174 $DEBUG && rump.netstat -rn -f inet
176 # Up, Gateway, Static
177 check_entry_flags 10.0.2/24 UGS
183 export RUMP_SERVER=$SOCK_LOCAL
185 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
187 # Delete an existing route first
188 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
190 # Gateway must be lo0
191 atf_check -s exit:0 -o ignore \
192 rump.route add -net 10.0.0.0/24 127.0.0.1 -blackhole
193 $DEBUG && rump.netstat -rn -f inet
195 # Up, Gateway, Blackhole, Static
196 check_entry_flags 10.0.0/24 UGBS
198 atf_check -s not-exit:0 -o match:'100.0% packet loss' \
199 rump.ping -n -w 1 -c 1 10.0.0.1
200 $DEBUG && rump.netstat -rn -f inet
202 # Shouldn't be created
203 check_entry_fail 10.0.0.1 UH
209 export RUMP_SERVER=$SOCK_LOCAL
211 # Delete an existing route first
212 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
214 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -reject
215 $DEBUG && rump.netstat -rn -f inet
217 # Up, Gateway, Reject, Static
218 check_entry_flags 10.0.0/24 UGRS
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
224 # Shouldn't be created
225 check_entry_fail 10.0.0.1 UH
227 # Gateway is lo0 (RTF_GATEWAY)
229 # Delete an existing route first
230 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
232 atf_check -s exit:0 -o ignore \
233 rump.route add -net 10.0.0.0/24 127.0.0.1 -reject
234 $DEBUG && rump.netstat -rn -f inet
236 # Up, Gateway, Reject, Static
237 check_entry_flags 10.0.0/24 UGRS
239 atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
240 rump.ping -n -w 1 -c 1 10.0.0.1
241 $DEBUG && rump.netstat -rn -f inet
243 # Shouldn't be created
244 check_entry_fail 10.0.0.1 UH
246 # Gateway is lo0 (RTF_HOST)
248 # Delete an existing route first
249 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
251 atf_check -s exit:0 -o ignore \
252 rump.route add -host 10.0.0.1/24 127.0.0.1 -iface -reject
253 $DEBUG && rump.netstat -rn -f inet
255 # Up, Host, Reject, Static
256 check_entry_flags 10.0.0.1 UHRS
258 atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
259 rump.ping -n -w 1 -c 1 10.0.0.1
260 $DEBUG && rump.netstat -rn -f inet
268 ### Testing Dynamic flag ###
271 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
276 # Teach the peer that 10.0.2.* is behind 10.0.0.254
278 export RUMP_SERVER=$SOCK_PEER
279 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
280 # Up, Gateway, Static
281 check_entry_flags 10.0.2/24 UGS
284 # Setup the default gateway to the peer, 10.0.0.1
286 export RUMP_SERVER=$SOCK_LOCAL
287 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
288 # Up, Gateway, Static
289 check_entry_flags default UGS
292 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
293 $DEBUG && rump.netstat -rn -f inet
295 # Up, Gateway, Host, Dynamic
296 check_entry_flags 10.0.2.1 UGHD
297 check_entry_gw 10.0.2.1 10.0.0.254
299 export RUMP_SERVER=$SOCK_PEER
300 $DEBUG && rump.netstat -rn -f inet
302 ### Testing Modified flag ###
305 # Teach a wrong route to 10.0.2.2
307 export RUMP_SERVER=$SOCK_LOCAL
308 atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1
309 # Up, Gateway, Host, Static
310 check_entry_flags 10.0.2.2 UGHS
311 check_entry_gw 10.0.2.2 10.0.0.1
314 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2
315 $DEBUG && rump.netstat -rn -f inet
317 # Up, Gateway, Host, Modified, Static
318 check_entry_flags 10.0.2.2 UGHMS
319 check_entry_gw 10.0.2.2 10.0.0.254
326 export RUMP_SERVER=$SOCK_LOCAL
328 # Delete an existing route first
329 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
331 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -proxy
332 $DEBUG && rump.netstat -rn -f inet
334 # Up, Gateway, Static, proxy
335 check_entry_flags 10.0.0/24 UGSp
337 # TODO test its behavior
342 $DEBUG && /usr/bin/shmif_dumpbus -p - $BUS 2>/dev/null | \
343 /usr/sbin/tcpdump -n -e -r -
344 env RUMP_SERVER=$SOCK_LOCAL rump.halt
345 env RUMP_SERVER=$SOCK_PEER rump.halt
353 atf_test_case "route_flags_${name}" cleanup
354 eval "route_flags_${name}_head() { \
355 atf_set \"descr\" \"${desc}\"; \
356 atf_set \"require.progs\" \"rump_server\"; \
358 route_flags_${name}_body() { \
363 route_flags_${name}_cleanup() { \
366 atf_add_test_case "route_flags_${name}"
369 atf_init_test_cases()
372 add_test lo "Tests route flags: loop back interface"
373 add_test connected "Tests route flags: connected route"
374 add_test default_gateway "Tests route flags: default gateway"
375 add_test static "Tests route flags: static route"
376 add_test blackhole "Tests route flags: blackhole route"
377 add_test reject "Tests route flags: reject route"
378 add_test icmp_redirect "Tests route flags: icmp redirect"
379 add_test announce "Tests route flags: announce flag"