1 # $NetBSD: t_route.sh,v 1.10 2016/12/21 02:46:08 ozaki-r Exp $
3 # Copyright (c) 2016 Internet Initiative Japan 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 SOCK_CLIENT=unix://commsock1
30 SOCK_GW=unix://commsock2
34 SOCKSRC=unix://commsock1
35 SOCKFWD=unix://commsock2
36 SOCKDST=unix://commsock3
41 IP4DST_BCAST=10.0.2.255
43 IP6SRCGW=fc00:0:0:1::1
44 IP6DSTGW=fc00:0:0:2::1
51 PING_OPTS="-n -c 1 -w $TIMEOUT"
53 atf_test_case route_non_subnet_gateway cleanup
54 route_non_subnet_gateway_head()
57 atf_set "descr" "tests of a gateway not on the local subnet"
58 atf_set "require.progs" "rump_server"
61 route_non_subnet_gateway_body()
64 rump_server_start $SOCK_CLIENT
65 rump_server_start $SOCK_GW
67 export RUMP_SERVER=${SOCK_GW}
68 rump_server_add_iface $SOCK_GW shmif0 $BUS
69 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1
70 atf_check -s exit:0 rump.ifconfig shmif0 up
72 # The gateway knows the client
73 atf_check -s exit:0 -o match:'add net 10.0.0.1: gateway shmif0' \
74 rump.route add -net 10.0.0.1/32 -link -cloning -iface shmif0
76 $DEBUG && rump.netstat -nr -f inet
78 export RUMP_SERVER=${SOCK_CLIENT}
79 rump_server_add_iface $SOCK_CLIENT shmif0 $BUS
80 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.1/32
81 atf_check -s exit:0 rump.ifconfig shmif0 up
82 atf_check -s exit:0 rump.ifconfig -w 10
84 $DEBUG && rump.netstat -nr -f inet
86 # Don't know a route to the gateway yet
87 atf_check -s not-exit:0 -o match:'100.0% packet loss' \
88 -e match:'No route to host' rump.ping $PING_OPTS 192.168.0.1
90 # Teach a route to the gateway
91 atf_check -s exit:0 -o match:'add net 192.168.0.1: gateway shmif0' \
92 rump.route add -net 192.168.0.1/32 -link -cloning -iface shmif0
93 atf_check -s exit:0 -o match:'add net default: gateway 192.168.0.1' \
94 rump.route add default -ifa 10.0.0.1 192.168.0.1
96 $DEBUG && rump.netstat -nr -f inet
98 # Be reachable to the gateway
99 atf_check -s exit:0 -o ignore rump.ping $PING_OPTS 192.168.0.1
101 rump_server_destroy_ifaces
104 route_non_subnet_gateway_cleanup()
111 atf_test_case route_command_get cleanup
112 atf_test_case route_command_get6 cleanup
113 route_command_get_head()
116 atf_set "descr" "tests of route get command"
117 atf_set "require.progs" "rump_server"
120 route_command_get6_head()
123 atf_set "descr" "tests of route get command (IPv6)"
124 atf_set "require.progs" "rump_server"
135 export RUMP_SERVER=${sock}
136 rump_server_add_iface $sock shmif0 $bus
137 if [ $mode = "ipv6" ]; then
138 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
139 atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
141 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
142 atf_check -s exit:0 -o ignore rump.route add default ${gw}
144 atf_check -s exit:0 rump.ifconfig shmif0 up
145 atf_check -s exit:0 rump.ifconfig -w 10
157 rump_server_add_iface $SOCKFWD shmif0 $BUS_SRCGW
158 rump_server_add_iface $SOCKFWD shmif1 $BUS_DSTGW
160 export RUMP_SERVER=$SOCKFWD
161 if [ $mode = "ipv6" ]; then
162 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
163 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
165 atf_check -s exit:0 rump.ifconfig shmif0 inet ${IP4SRCGW} netmask 0xffffff00
166 atf_check -s exit:0 rump.ifconfig shmif1 inet ${IP4DSTGW} netmask 0xffffff00
169 atf_check -s exit:0 rump.ifconfig shmif0 up
170 atf_check -s exit:0 rump.ifconfig shmif1 up
171 atf_check -s exit:0 rump.ifconfig -w 10
175 if [ $mode = "ipv6" ]; then
176 rump.sysctl net.inet6.ip6.forwarding
178 rump.sysctl net.inet.ip.forwarding
185 export RUMP_SERVER=$SOCKFWD
186 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
191 export RUMP_SERVER=$SOCKFWD
192 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
198 rump_server_start $SOCKSRC
199 rump_server_start $SOCKFWD
200 rump_server_start $SOCKDST
202 setup_endpoint $SOCKSRC $IP4SRC $BUS_SRCGW ipv4 $IP4SRCGW
203 setup_endpoint $SOCKDST $IP4DST $BUS_DSTGW ipv4 $IP4DSTGW
210 rump_server_start $SOCKSRC netinet6
211 rump_server_start $SOCKFWD netinet6
212 rump_server_start $SOCKDST netinet6
214 setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW ipv6 $IP6SRCGW
215 setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW ipv6 $IP6DSTGW
222 export RUMP_SERVER=$SOCKSRC
223 $DEBUG && rump.netstat -nr -f inet
224 $DEBUG && rump.arp -n -a
226 # Make sure an ARP cache to the gateway doesn't exist
227 rump.arp -d $IP4SRCGW
232 destination: 10.0.1.2
235 flags: <UP,HOST,DONE,LLINFO,LOCAL>
236 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
238 rump.route -n get $IP4SRC > ./output
239 $DEBUG && cat ./expect ./output
240 # XXX: omit the last line because expire is unstable on rump kernel.
242 atf_check -s exit:0 diff ./expect ./output
247 destination: 10.0.1.0
251 flags: <UP,DONE,CONNECTED>
252 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
254 rump.route -n get $IP4SRCGW > ./output
255 $DEBUG && cat ./expect ./output
257 atf_check -s exit:0 diff ./expect ./output
267 flags: <UP,GATEWAY,DONE,STATIC>
268 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
270 rump.route -n get $IP4DST > ./output
271 $DEBUG && cat ./expect ./output
273 atf_check -s exit:0 diff ./expect ./output
276 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
278 # Neighbor with a cache (no different from w/o cache)
281 destination: 10.0.1.0
285 flags: <UP,DONE,CONNECTED>
286 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
288 rump.route -n get $IP4SRCGW > ./output
289 $DEBUG && cat ./expect ./output
291 atf_check -s exit:0 diff ./expect ./output
297 export RUMP_SERVER=$SOCKSRC
298 $DEBUG && rump.netstat -nr -f inet
299 $DEBUG && rump.ndp -n -a
301 # Make sure an ARP cache to the gateway doesn't exist
302 rump.ndp -d $IP6SRCGW
306 route to: fc00:0:0:1::2
307 destination: fc00:0:0:1::2
308 local addr: fc00:0:0:1::2
310 flags: <UP,HOST,DONE,LLINFO,LOCAL>
311 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
313 rump.route -n get -inet6 $IP6SRC > ./output
314 $DEBUG && cat ./expect ./output
316 atf_check -s exit:0 diff ./expect ./output
320 route to: fc00:0:0:1::1
321 destination: fc00:0:0:1::
322 mask: ffff:ffff:ffff:ffff::
323 local addr: fc00:0:0:1::2
325 flags: <UP,DONE,CONNECTED>
326 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
328 rump.route -n get -inet6 $IP6SRCGW > ./output
329 $DEBUG && cat ./expect ./output
331 atf_check -s exit:0 diff ./expect ./output
335 route to: fc00:0:0:2::2
338 gateway: fc00:0:0:1::1
339 local addr: fc00:0:0:1::2
341 flags: <UP,GATEWAY,DONE,STATIC>
342 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
344 rump.route -n get -inet6 $IP6DST > ./output
345 $DEBUG && cat ./expect ./output
347 atf_check -s exit:0 diff ./expect ./output
350 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6SRCGW
352 # Neighbor with a cache (no different from w/o cache)
354 route to: fc00:0:0:1::1
355 destination: fc00:0:0:1::
356 mask: ffff:ffff:ffff:ffff::
357 local addr: fc00:0:0:1::2
359 flags: <UP,DONE,CONNECTED>
360 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
362 rump.route -n get -inet6 $IP6SRCGW > ./output
363 $DEBUG && cat ./expect ./output
365 atf_check -s exit:0 diff ./expect ./output
368 route_command_get_body()
374 rump_server_destroy_ifaces
377 route_command_get6_body()
383 rump_server_destroy_ifaces
386 route_command_get_cleanup()
393 route_command_get6_cleanup()
400 atf_init_test_cases()
403 atf_add_test_case route_non_subnet_gateway
404 atf_add_test_case route_command_get
405 atf_add_test_case route_command_get6