t_route.sh revision 1.1 1 # $NetBSD: t_route.sh,v 1.1 2016/01/29 04:15:46 ozaki-r Exp $
2 #
3 # Copyright (c) 2016 Internet Initiative Japan Inc.
4 # All rights reserved.
5 #
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.
14 #
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.
26 #
27
28 RUMP_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
29 SOCK_CLIENT=unix://commsock1
30 SOCK_GW=unix://commsock2
31 BUS=bus1
32
33 DEBUG=false
34 TIMEOUT=1
35 PING_OPTS="-n -c 1 -w $TIMEOUT"
36
37 atf_test_case non_subnet_gateway cleanup
38 non_subnet_gateway_head()
39 {
40
41 atf_set "descr" "tests of a gateway not on the local subnet"
42 atf_set "require.progs" "rump_server"
43 }
44
45 non_subnet_gateway_body()
46 {
47
48 atf_check -s exit:0 rump_server ${RUMP_LIBS} ${SOCK_CLIENT}
49 atf_check -s exit:0 rump_server ${RUMP_LIBS} ${SOCK_GW}
50
51 export RUMP_SERVER=${SOCK_GW}
52
53 atf_check -s exit:0 rump.ifconfig shmif0 create
54 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
55 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1
56 atf_check -s exit:0 rump.ifconfig shmif0 up
57
58 # The gateway knows the client
59 atf_check -s exit:0 -o match:'add net 10.0.0.1: gateway shmif0' \
60 rump.route add -net 10.0.0.1/32 -link -cloning -iface shmif0
61
62 $DEBUG && rump.netstat -nr -f inet
63
64 export RUMP_SERVER=${SOCK_CLIENT}
65
66 atf_check -s exit:0 rump.ifconfig shmif0 create
67 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
68 atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.1/32
69 atf_check -s exit:0 rump.ifconfig shmif0 up
70
71 $DEBUG && rump.netstat -nr -f inet
72
73 # Don't know a route to the gateway yet
74 atf_check -s not-exit:0 -o match:'100.0% packet loss' \
75 -e match:'No route to host' rump.ping $PING_OPTS 192.168.0.1
76
77 # Teach a route to the gateway
78 atf_check -s exit:0 -o match:'add net 192.168.0.1: gateway shmif0' \
79 rump.route add -net 192.168.0.1/32 -link -cloning -iface shmif0
80 atf_check -s exit:0 -o match:'add net default: gateway 192.168.0.1' \
81 rump.route add default -ifa 10.0.0.1 192.168.0.1
82
83 $DEBUG && rump.netstat -nr -f inet
84
85 # Be reachable to the gateway
86 atf_check -s exit:0 -o ignore rump.ping $PING_OPTS 192.168.0.1
87
88 unset RUMP_SERVER
89 }
90
91 non_subnet_gateway_cleanup()
92 {
93
94 $DEBUG && shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r -
95 env RUMP_SERVER=$SOCK_CLIENT rump.halt
96 env RUMP_SERVER=$SOCK_GW rump.halt
97 }
98
99 atf_init_test_cases()
100 {
101
102 atf_add_test_case non_subnet_gateway
103 }
104