1 # $NetBSD: t_route.sh,v 1.7 2016/08/10 23:00:39 roy 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.
28 RUMP_LIBS="-lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
29 RUMP_LIBS_IPV6="$RUMP_LIBS -lrumpnet_netinet6"
32 SOCK_CLIENT=unix://commsock1
33 SOCK_GW=unix://commsock2
37 SOCKSRC=unix://commsock1
38 SOCKFWD=unix://commsock2
39 SOCKDST=unix://commsock3
44 IP4DST_BCAST=10.0.2.255
46 IP6SRCGW=fc00:0:0:1::1
47 IP6DSTGW=fc00:0:0:2::1
54 PING_OPTS="-n -c 1 -w $TIMEOUT"
56 atf_test_case route_non_subnet_gateway cleanup
57 route_non_subnet_gateway_head()
60 atf_set "descr" "tests of a gateway not on the local subnet"
61 atf_set "require.progs" "rump_server"
64 route_non_subnet_gateway_body()
67 atf_check -s exit:0 rump_server ${RUMP_LIBS} ${SOCK_CLIENT}
68 atf_check -s exit:0 rump_server ${RUMP_LIBS} ${SOCK_GW}
70 export RUMP_SERVER=${SOCK_GW}
72 atf_check -s exit:0 rump.ifconfig shmif0 create
73 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
74 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1
75 atf_check -s exit:0 rump.ifconfig shmif0 up
77 # The gateway knows the client
78 atf_check -s exit:0 -o match:'add net 10.0.0.1: gateway shmif0' \
79 rump.route add -net 10.0.0.1/32 -link -cloning -iface shmif0
81 $DEBUG && rump.netstat -nr -f inet
83 export RUMP_SERVER=${SOCK_CLIENT}
85 atf_check -s exit:0 rump.ifconfig shmif0 create
86 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
87 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.1/32
88 atf_check -s exit:0 rump.ifconfig shmif0 up
90 $DEBUG && rump.netstat -nr -f inet
92 # Don't know a route to the gateway yet
93 atf_check -s not-exit:0 -o match:'100.0% packet loss' \
94 -e match:'No route to host' rump.ping $PING_OPTS 192.168.0.1
96 # Teach a route to the gateway
97 atf_check -s exit:0 -o match:'add net 192.168.0.1: gateway shmif0' \
98 rump.route add -net 192.168.0.1/32 -link -cloning -iface shmif0
99 atf_check -s exit:0 -o match:'add net default: gateway 192.168.0.1' \
100 rump.route add default -ifa 10.0.0.1 192.168.0.1
102 $DEBUG && rump.netstat -nr -f inet
104 # Be reachable to the gateway
105 atf_check -s exit:0 -o ignore rump.ping $PING_OPTS 192.168.0.1
110 route_non_subnet_gateway_cleanup()
113 $DEBUG && shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r -
114 env RUMP_SERVER=$SOCK_CLIENT rump.halt
115 env RUMP_SERVER=$SOCK_GW rump.halt
118 atf_test_case route_command_get cleanup
119 atf_test_case route_command_get6 cleanup
120 route_command_get_head()
123 atf_set "descr" "tests of route get command"
124 atf_set "require.progs" "rump_server"
127 route_command_get6_head()
130 atf_set "descr" "tests of route get command (IPv6)"
131 atf_set "require.progs" "rump_server"
142 export RUMP_SERVER=${sock}
143 atf_check -s exit:0 rump.ifconfig shmif0 create
144 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
145 if [ $mode = "ipv6" ]; then
146 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
147 atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
149 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
150 atf_check -s exit:0 -o ignore rump.route add default ${gw}
152 atf_check -s exit:0 rump.ifconfig shmif0 up
164 export RUMP_SERVER=$SOCKFWD
165 atf_check -s exit:0 rump.ifconfig shmif0 create
166 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS_SRCGW
168 atf_check -s exit:0 rump.ifconfig shmif1 create
169 atf_check -s exit:0 rump.ifconfig shmif1 linkstr $BUS_DSTGW
171 if [ $mode = "ipv6" ]; then
172 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
173 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
175 atf_check -s exit:0 rump.ifconfig shmif0 inet ${IP4SRCGW} netmask 0xffffff00
176 atf_check -s exit:0 rump.ifconfig shmif1 inet ${IP4DSTGW} netmask 0xffffff00
179 atf_check -s exit:0 rump.ifconfig shmif0 up
180 atf_check -s exit:0 rump.ifconfig shmif1 up
184 if [ $mode = "ipv6" ]; then
185 rump.sysctl net.inet6.ip6.forwarding
187 rump.sysctl net.inet.ip.forwarding
194 export RUMP_SERVER=$SOCKFWD
195 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
200 export RUMP_SERVER=$SOCKFWD
201 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
207 atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKSRC
208 atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKFWD
209 atf_check -s exit:0 rump_server $RUMP_LIBS $SOCKDST
211 setup_endpoint $SOCKSRC $IP4SRC $BUS_SRCGW ipv4 $IP4SRCGW
212 setup_endpoint $SOCKDST $IP4DST $BUS_DSTGW ipv4 $IP4DSTGW
219 atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKSRC
220 atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKFWD
221 atf_check -s exit:0 rump_server $RUMP_LIBS_IPV6 $SOCKDST
223 setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW ipv6 $IP6SRCGW
224 setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW ipv6 $IP6DSTGW
231 export RUMP_SERVER=$SOCKSRC
232 $DEBUG && rump.netstat -nr -f inet
233 $DEBUG && rump.arp -n -a
235 # Make sure an ARP cache to the gateway doesn't exist
236 rump.arp -d $IP4SRCGW
241 destination: 10.0.1.2
244 flags: <UP,HOST,DONE,LLINFO,LOCAL>
245 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
247 rump.route -n get $IP4SRC > ./output
248 $DEBUG && cat ./expect ./output
249 # XXX: omit the last line because expire is unstable on rump kernel.
251 atf_check -s exit:0 diff ./expect ./output
256 destination: 10.0.1.0
260 flags: <UP,DONE,CONNECTED>
261 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
263 rump.route -n get $IP4SRCGW > ./output
264 $DEBUG && cat ./expect ./output
266 atf_check -s exit:0 diff ./expect ./output
276 flags: <UP,GATEWAY,DONE,STATIC>
277 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
279 rump.route -n get $IP4DST > ./output
280 $DEBUG && cat ./expect ./output
282 atf_check -s exit:0 diff ./expect ./output
285 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
287 # Neighbor with a cache (no different from w/o cache)
290 destination: 10.0.1.0
294 flags: <UP,DONE,CONNECTED>
295 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
297 rump.route -n get $IP4SRCGW > ./output
298 $DEBUG && cat ./expect ./output
300 atf_check -s exit:0 diff ./expect ./output
306 export RUMP_SERVER=$SOCKSRC
307 $DEBUG && rump.netstat -nr -f inet
308 $DEBUG && rump.ndp -n -a
310 # Make sure an ARP cache to the gateway doesn't exist
311 rump.ndp -d $IP6SRCGW
315 route to: fc00:0:0:1::2
316 destination: fc00:0:0:1::2
317 local addr: fc00:0:0:1::2
319 flags: <UP,HOST,DONE,LLINFO,LOCAL>
320 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
322 rump.route -n get -inet6 $IP6SRC > ./output
323 $DEBUG && cat ./expect ./output
325 atf_check -s exit:0 diff ./expect ./output
329 route to: fc00:0:0:1::1
330 destination: fc00:0:0:1::
331 mask: ffff:ffff:ffff:ffff::
332 local addr: fc00:0:0:1::2
334 flags: <UP,DONE,CONNECTED>
335 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
337 rump.route -n get -inet6 $IP6SRCGW > ./output
338 $DEBUG && cat ./expect ./output
340 atf_check -s exit:0 diff ./expect ./output
344 route to: fc00:0:0:2::2
347 gateway: fc00:0:0:1::1
348 local addr: fc00:0:0:1::2
350 flags: <UP,GATEWAY,DONE,STATIC>
351 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
353 rump.route -n get -inet6 $IP6DST > ./output
354 $DEBUG && cat ./expect ./output
356 atf_check -s exit:0 diff ./expect ./output
359 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6SRCGW
361 # Neighbor with a cache (no different from w/o cache)
363 route to: fc00:0:0:1::1
364 destination: fc00:0:0:1::
365 mask: ffff:ffff:ffff:ffff::
366 local addr: fc00:0:0:1::2
368 flags: <UP,DONE,CONNECTED>
369 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
371 rump.route -n get -inet6 $IP6SRCGW > ./output
372 $DEBUG && cat ./expect ./output
374 atf_check -s exit:0 diff ./expect ./output
377 route_command_get_body()
385 route_command_get6_body()
396 env RUMP_SERVER=$SOCKSRC rump.netstat -nr
397 env RUMP_SERVER=$SOCKFWD rump.netstat -nr
398 env RUMP_SERVER=$SOCKDST rump.netstat -nr
400 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
401 shmif_dumpbus -p - bus2 2>/dev/null| tcpdump -n -e -r -
407 env RUMP_SERVER=$SOCKSRC rump.halt
408 env RUMP_SERVER=$SOCKFWD rump.halt
409 env RUMP_SERVER=$SOCKDST rump.halt
412 route_command_get_cleanup()
418 route_command_get6_cleanup()
424 atf_init_test_cases()
427 atf_add_test_case route_non_subnet_gateway
428 atf_add_test_case route_command_get
429 atf_add_test_case route_command_get6