etc/protocols - sync with NetBSD-8
[minix.git] / tests / net / route / t_flags.sh
blobbd664737f6773416c30a75c655f133d99a1f22e1
1 # $NetBSD: t_flags.sh,v 1.3 2015/06/01 01:36:30 ozaki-r Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
4 # All rights reserved.
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.
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 netserver=\
29 "rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
30 SOCK_LOCAL=unix://commsock1
31 SOCK_PEER=unix://commsock2
32 SOCK_GW=unix://commsock3
33 BUS=bus1
34 BUS2=bus2
36 DEBUG=false
38 setup_local()
41 atf_check -s exit:0 ${netserver} ${SOCK_LOCAL}
43 export RUMP_SERVER=$SOCK_LOCAL
44 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
45 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
46 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24
47 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
49 $DEBUG && rump.ifconfig
50 $DEBUG && rump.netstat -rn -f inet
53 setup_peer()
56 atf_check -s exit:0 ${netserver} ${SOCK_PEER}
58 export RUMP_SERVER=$SOCK_PEER
59 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
60 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
61 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24
62 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
64 $DEBUG && rump.ifconfig
65 $DEBUG && rump.netstat -rn -f inet
68 setup_gw()
71 atf_check -s exit:0 ${netserver} ${SOCK_GW}
73 export RUMP_SERVER=$SOCK_GW
74 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
75 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
76 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24
77 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
79 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 create
80 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 linkstr ${BUS2}
81 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24
82 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24
83 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up
85 # Wait until DAD completes (10 sec at most)
86 atf_check -s exit:0 -o ignore rump.ifconfig -w 10
87 atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative"
89 $DEBUG && rump.ifconfig
90 $DEBUG && rump.netstat -rn -f inet
93 teardown_gw()
96 env RUMP_SERVER=$SOCK_GW rump.halt
99 check_entry_flags()
101 local ip=$(echo $1 |sed 's/\./\\./g')
102 local flags=$2
104 atf_check -s exit:0 -o match:" $flags " -e ignore -x \
105 "rump.netstat -rn -f inet | grep ^'$ip'"
108 check_entry_gw()
110 local ip=$(echo $1 |sed 's/\./\\./g')
111 local gw=$2
113 atf_check -s exit:0 -o match:" $gw " -e ignore -x \
114 "rump.netstat -rn -f inet | grep ^'$ip'"
117 check_entry_fail()
119 ip=$(echo $1 |sed 's/\./\\./g')
120 flags=$2 # Not used currently
122 atf_check -s not-exit:0 -e ignore -x \
123 "rump.netstat -rn -f inet | grep ^'$ip'"
126 test_lo()
129 export RUMP_SERVER=$SOCK_LOCAL
131 # Up, Host, local
132 check_entry_flags 127.0.0.1 UHl
135 test_connected()
138 export RUMP_SERVER=$SOCK_LOCAL
140 # Up, Host, LLINFO, local
141 check_entry_flags 10.0.0.2 UHLl
143 # Up, Cloning
144 check_entry_flags 10.0.0/24 UC
147 test_cloned()
150 export RUMP_SERVER=$SOCK_LOCAL
152 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
153 $DEBUG && rump.netstat -rn -f inet
155 # Up, Host, LLINFO, cloned
156 check_entry_flags 10.0.0.1 UHLc
159 test_default_gateway()
162 export RUMP_SERVER=$SOCK_LOCAL
164 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
165 $DEBUG && rump.netstat -rn -f inet
167 # Up, Gateway, Static
168 check_entry_flags default UGS
171 test_static()
174 export RUMP_SERVER=$SOCK_LOCAL
176 # Static route to host
177 atf_check -s exit:0 -o ignore rump.route add 10.0.1.1 10.0.0.1
178 $DEBUG && rump.netstat -rn -f inet
180 # Up, Gateway, Host, Static
181 check_entry_flags 10.0.1.1 UGHS
183 # Static route to network
184 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.1
185 $DEBUG && rump.netstat -rn -f inet
187 # Up, Gateway, Static
188 check_entry_flags 10.0.2/24 UGS
191 test_route_flush()
194 export RUMP_SERVER=$SOCK_LOCAL
196 # Reusing other tests to create routes
197 test_cloned_route
198 test_default_gateway
199 test_static_route
201 atf_check -s exit:0 -o ignore rump.route flush
202 $DEBUG && rump.netstat -rn -f inet
204 # Should remain
205 check_entry_flags 127.0.0.1 UHl
206 check_entry_flags 10.0.0/24 UC
208 # Shouldn't remain
209 check_entry_fail default UGS
210 check_entry_fail 10.0.1.1 UGHS
211 check_entry_fail 10.0.2/24 UGS
212 # Should it remain?
213 check_entry_fail 10.0.0.2 UHLl
216 test_blackhole()
219 export RUMP_SERVER=$SOCK_LOCAL
221 # Delete an existing route first
222 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
224 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -blackhole
225 $DEBUG && rump.netstat -rn -f inet
227 # Up, Gateway, Blackhole, Static
228 check_entry_flags 10.0.0/24 UGBS
230 atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
231 rump.ping -n -w 1 -c 1 10.0.0.1
232 $DEBUG && rump.netstat -rn -f inet
234 # Shouldn't be created
235 check_entry_fail 10.0.0.1 UHLc
238 test_reject()
241 export RUMP_SERVER=$SOCK_LOCAL
243 # Delete an existing route first
244 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
246 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -reject
247 $DEBUG && rump.netstat -rn -f inet
249 # Up, Gateway, Reject, Static
250 check_entry_flags 10.0.0/24 UGRS
252 atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
253 rump.ping -n -w 1 -c 1 10.0.0.1
254 $DEBUG && rump.netstat -rn -f inet
256 # Shouldn't be created
257 check_entry_fail 10.0.0.1 UHLc
260 test_icmp_redirect()
263 ### Testing Dynamic flag ###
266 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
268 setup_gw
271 # Teach the peer that 10.0.2.* is behind 10.0.0.254
273 export RUMP_SERVER=$SOCK_PEER
274 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
275 # Up, Gateway, Static
276 check_entry_flags 10.0.2/24 UGS
279 # Setup the default gateway to the peer, 10.0.0.1
281 export RUMP_SERVER=$SOCK_LOCAL
282 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
283 # Up, Gateway, Static
284 check_entry_flags default UGS
286 # Try ping 10.0.2.1
287 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
288 $DEBUG && rump.netstat -rn -f inet
290 # Up, Gateway, Host, Dynamic
291 check_entry_flags 10.0.2.1 UGHD
292 check_entry_gw 10.0.2.1 10.0.0.254
294 export RUMP_SERVER=$SOCK_PEER
295 $DEBUG && rump.netstat -rn -f inet
297 ### Testing Modified flag ###
300 # Teach a wrong route to 10.0.2.2
302 export RUMP_SERVER=$SOCK_LOCAL
303 atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1
304 # Up, Gateway, Host, Static
305 check_entry_flags 10.0.2.2 UGHS
306 check_entry_gw 10.0.2.2 10.0.0.1
308 # Try ping 10.0.2.2
309 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2
310 $DEBUG && rump.netstat -rn -f inet
312 # Up, Gateway, Host, Modified, Static
313 check_entry_flags 10.0.2.2 UGHMS
314 check_entry_gw 10.0.2.2 10.0.0.254
316 teardown_gw
319 test_announce()
321 export RUMP_SERVER=$SOCK_LOCAL
323 # Delete an existing route first
324 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
326 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -proxy
327 $DEBUG && rump.netstat -rn -f inet
329 # Up, Gateway, Static, proxy
330 check_entry_flags 10.0.0/24 UGSp
332 # TODO test its behavior
335 test_xresolve_rtm()
337 local ip=$1
338 local rtm=$2
339 local pid=
341 rump.route -n monitor > ./mon.log &
342 pid=$!
344 # Give route monitor a chance to setup a routing socket
345 sleep 1
347 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $ip
348 $DEBUG && rump.netstat -rn -f inet
350 # Give route monitor a chance to output a routing message
351 sleep 1
352 cat ./mon.log
354 atf_check -s exit:0 grep -q $rtm ./mon.log
356 kill $pid
359 test_xresolve()
362 export RUMP_SERVER=$SOCK_LOCAL
364 # For a normal route, a RTM_ADD message is emitted on a route cloning
365 test_xresolve_rtm 10.0.0.1 RTM_ADD
366 # Up, Host, LLINFO, cloned
367 check_entry_flags 10.0.0.1 UHLc
369 # Delete an existing route first
370 atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
371 # Create a connected route with XRESOLVE flag for the interface
372 atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.2 \
373 -interface -xresolve
374 $DEBUG && rump.netstat -rn -f inet
376 # Up, Cloning, Xresolve, Static
377 check_entry_flags 10.0.0/24 UCXS
379 # If XRESOLVE flag is set, a RTM_RESOLVE message is emitted
380 test_xresolve_rtm 10.0.0.1 RTM_RESOLVE
381 # Up, Host, Xresolve, LLINFO, cloned
382 check_entry_flags 10.0.0.1 UHXLc
385 cleanup()
387 $DEBUG && /usr/bin/shmif_dumpbus -p - $BUS 2>/dev/null | \
388 /usr/sbin/tcpdump -n -e -r -
389 env RUMP_SERVER=$SOCK_LOCAL rump.halt
390 env RUMP_SERVER=$SOCK_PEER rump.halt
393 add_test()
395 local name=$1
396 local desc="$2"
398 atf_test_case "route_flags_${name}" cleanup
399 eval "route_flags_${name}_head() { \
400 atf_set \"descr\" \"${desc}\"; \
401 atf_set \"require.progs\" \"rump_server\"; \
402 }; \
403 route_flags_${name}_body() { \
404 setup_local; \
405 setup_peer; \
406 test_${name}; \
407 }; \
408 route_flags_${name}_cleanup() { \
409 cleanup; \
411 atf_add_test_case "route_flags_${name}"
414 atf_init_test_cases()
417 add_test lo "Tests route flags: loop back interface"
418 add_test connected "Tests route flags: connected route"
419 add_test cloned "Tests route flags: cloned route"
420 add_test default_gateway "Tests route flags: default gateway"
421 add_test static "Tests route flags: static route"
422 add_test blackhole "Tests route flags: blackhole route"
423 add_test reject "Tests route flags: reject route"
424 add_test icmp_redirect "Tests route flags: icmp redirect"
425 add_test announce "Tests route flags: announce flag"
426 add_test xresolve "Tests route flags: xresolve flag"