t_route.sh revision 1.9 1 # $NetBSD: t_route.sh,v 1.9 2016/11/25 08:51:17 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 # non_subnet_gateway
29 SOCK_CLIENT=unix://commsock1
30 SOCK_GW=unix://commsock2
31 BUS=bus1
32
33 # command_get
34 SOCKSRC=unix://commsock1
35 SOCKFWD=unix://commsock2
36 SOCKDST=unix://commsock3
37 IP4SRC=10.0.1.2
38 IP4SRCGW=10.0.1.1
39 IP4DSTGW=10.0.2.1
40 IP4DST=10.0.2.2
41 IP4DST_BCAST=10.0.2.255
42 IP6SRC=fc00:0:0:1::2
43 IP6SRCGW=fc00:0:0:1::1
44 IP6DSTGW=fc00:0:0:2::1
45 IP6DST=fc00:0:0:2::2
46 BUS_SRCGW=bus1
47 BUS_DSTGW=bus2
48
49 DEBUG=${DEBUG:-false}
50 TIMEOUT=1
51 PING_OPTS="-n -c 1 -w $TIMEOUT"
52
53 atf_test_case route_non_subnet_gateway cleanup
54 route_non_subnet_gateway_head()
55 {
56
57 atf_set "descr" "tests of a gateway not on the local subnet"
58 atf_set "require.progs" "rump_server"
59 }
60
61 route_non_subnet_gateway_body()
62 {
63
64 rump_server_start $SOCK_CLIENT
65 rump_server_start $SOCK_GW
66
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
71
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
75
76 $DEBUG && rump.netstat -nr -f inet
77
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
83 $DEBUG && rump.netstat -nr -f inet
84
85 # Don't know a route to the gateway yet
86 atf_check -s not-exit:0 -o match:'100.0% packet loss' \
87 -e match:'No route to host' rump.ping $PING_OPTS 192.168.0.1
88
89 # Teach a route to the gateway
90 atf_check -s exit:0 -o match:'add net 192.168.0.1: gateway shmif0' \
91 rump.route add -net 192.168.0.1/32 -link -cloning -iface shmif0
92 atf_check -s exit:0 -o match:'add net default: gateway 192.168.0.1' \
93 rump.route add default -ifa 10.0.0.1 192.168.0.1
94
95 $DEBUG && rump.netstat -nr -f inet
96
97 # Be reachable to the gateway
98 atf_check -s exit:0 -o ignore rump.ping $PING_OPTS 192.168.0.1
99
100 rump_server_destroy_ifaces
101 }
102
103 route_non_subnet_gateway_cleanup()
104 {
105
106 $DEBUG && dump
107 cleanup
108 }
109
110 atf_test_case route_command_get cleanup
111 atf_test_case route_command_get6 cleanup
112 route_command_get_head()
113 {
114
115 atf_set "descr" "tests of route get command"
116 atf_set "require.progs" "rump_server"
117 }
118
119 route_command_get6_head()
120 {
121
122 atf_set "descr" "tests of route get command (IPv6)"
123 atf_set "require.progs" "rump_server"
124 }
125
126 setup_endpoint()
127 {
128 local sock=${1}
129 local addr=${2}
130 local bus=${3}
131 local mode=${4}
132 local gw=${5}
133
134 export RUMP_SERVER=${sock}
135 rump_server_add_iface $sock shmif0 $bus
136 if [ $mode = "ipv6" ]; then
137 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
138 atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
139 else
140 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
141 atf_check -s exit:0 -o ignore rump.route add default ${gw}
142 fi
143 atf_check -s exit:0 rump.ifconfig shmif0 up
144
145 if $DEBUG; then
146 rump.ifconfig shmif0
147 rump.netstat -nr
148 fi
149 }
150
151 setup_forwarder()
152 {
153 mode=${1}
154
155 rump_server_add_iface $SOCKFWD shmif0 $BUS_SRCGW
156 rump_server_add_iface $SOCKFWD shmif1 $BUS_DSTGW
157
158 export RUMP_SERVER=$SOCKFWD
159 if [ $mode = "ipv6" ]; then
160 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
161 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
162 else
163 atf_check -s exit:0 rump.ifconfig shmif0 inet ${IP4SRCGW} netmask 0xffffff00
164 atf_check -s exit:0 rump.ifconfig shmif1 inet ${IP4DSTGW} netmask 0xffffff00
165 fi
166
167 atf_check -s exit:0 rump.ifconfig shmif0 up
168 atf_check -s exit:0 rump.ifconfig shmif1 up
169
170 if $DEBUG; then
171 rump.netstat -nr
172 if [ $mode = "ipv6" ]; then
173 rump.sysctl net.inet6.ip6.forwarding
174 else
175 rump.sysctl net.inet.ip.forwarding
176 fi
177 fi
178 }
179
180 setup_forwarding()
181 {
182 export RUMP_SERVER=$SOCKFWD
183 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
184 }
185
186 setup_forwarding6()
187 {
188 export RUMP_SERVER=$SOCKFWD
189 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
190 }
191
192 setup()
193 {
194
195 rump_server_start $SOCKSRC
196 rump_server_start $SOCKFWD
197 rump_server_start $SOCKDST
198
199 setup_endpoint $SOCKSRC $IP4SRC $BUS_SRCGW ipv4 $IP4SRCGW
200 setup_endpoint $SOCKDST $IP4DST $BUS_DSTGW ipv4 $IP4DSTGW
201 setup_forwarder ipv4
202 }
203
204 setup6()
205 {
206
207 rump_server_start $SOCKSRC netinet6
208 rump_server_start $SOCKFWD netinet6
209 rump_server_start $SOCKDST netinet6
210
211 setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW ipv6 $IP6SRCGW
212 setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW ipv6 $IP6DSTGW
213 setup_forwarder ipv6
214 }
215
216 test_route_get()
217 {
218
219 export RUMP_SERVER=$SOCKSRC
220 $DEBUG && rump.netstat -nr -f inet
221 $DEBUG && rump.arp -n -a
222
223 # Make sure an ARP cache to the gateway doesn't exist
224 rump.arp -d $IP4SRCGW
225
226 # Local
227 cat >./expect <<-EOF
228 route to: 10.0.1.2
229 destination: 10.0.1.2
230 local addr: 10.0.1.2
231 interface: lo0
232 flags: <UP,HOST,DONE,LLINFO,LOCAL>
233 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
234 EOF
235 rump.route -n get $IP4SRC > ./output
236 $DEBUG && cat ./expect ./output
237 # XXX: omit the last line because expire is unstable on rump kernel.
238 sed -i '$d' ./output
239 atf_check -s exit:0 diff ./expect ./output
240
241 # Neighbor
242 cat >./expect <<-EOF
243 route to: 10.0.1.1
244 destination: 10.0.1.0
245 mask: 255.255.255.0
246 local addr: 10.0.1.2
247 interface: shmif0
248 flags: <UP,DONE,CONNECTED>
249 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
250 EOF
251 rump.route -n get $IP4SRCGW > ./output
252 $DEBUG && cat ./expect ./output
253 sed -i '$d' ./output
254 atf_check -s exit:0 diff ./expect ./output
255
256 # Remote host
257 cat >./expect <<-EOF
258 route to: 10.0.2.2
259 destination: default
260 mask: default
261 gateway: 10.0.1.1
262 local addr: 10.0.1.2
263 interface: shmif0
264 flags: <UP,GATEWAY,DONE,STATIC>
265 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
266 EOF
267 rump.route -n get $IP4DST > ./output
268 $DEBUG && cat ./expect ./output
269 sed -i '$d' ./output
270 atf_check -s exit:0 diff ./expect ./output
271
272 # Create a ARP cache
273 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
274
275 # Neighbor with a cache (no different from w/o cache)
276 cat >./expect <<-EOF
277 route to: 10.0.1.1
278 destination: 10.0.1.0
279 mask: 255.255.255.0
280 local addr: 10.0.1.2
281 interface: shmif0
282 flags: <UP,DONE,CONNECTED>
283 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
284 EOF
285 rump.route -n get $IP4SRCGW > ./output
286 $DEBUG && cat ./expect ./output
287 sed -i '$d' ./output
288 atf_check -s exit:0 diff ./expect ./output
289 }
290
291 test_route_get6()
292 {
293
294 export RUMP_SERVER=$SOCKSRC
295 $DEBUG && rump.netstat -nr -f inet
296 $DEBUG && rump.ndp -n -a
297
298 # Make sure an ARP cache to the gateway doesn't exist
299 rump.ndp -d $IP6SRCGW
300
301 # Local
302 cat >./expect <<-EOF
303 route to: fc00:0:0:1::2
304 destination: fc00:0:0:1::2
305 local addr: fc00:0:0:1::2
306 interface: lo0
307 flags: <UP,HOST,DONE,LLINFO,LOCAL>
308 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
309 EOF
310 rump.route -n get -inet6 $IP6SRC > ./output
311 $DEBUG && cat ./expect ./output
312 sed -i '$d' ./output
313 atf_check -s exit:0 diff ./expect ./output
314
315 # Neighbor
316 cat >./expect <<-EOF
317 route to: fc00:0:0:1::1
318 destination: fc00:0:0:1::
319 mask: ffff:ffff:ffff:ffff::
320 local addr: fc00:0:0:1::2
321 interface: shmif0
322 flags: <UP,DONE,CONNECTED>
323 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
324 EOF
325 rump.route -n get -inet6 $IP6SRCGW > ./output
326 $DEBUG && cat ./expect ./output
327 sed -i '$d' ./output
328 atf_check -s exit:0 diff ./expect ./output
329
330 # Remote host
331 cat >./expect <<-EOF
332 route to: fc00:0:0:2::2
333 destination: ::
334 mask: default
335 gateway: fc00:0:0:1::1
336 local addr: fc00:0:0:1::2
337 interface: shmif0
338 flags: <UP,GATEWAY,DONE,STATIC>
339 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
340 EOF
341 rump.route -n get -inet6 $IP6DST > ./output
342 $DEBUG && cat ./expect ./output
343 sed -i '$d' ./output
344 atf_check -s exit:0 diff ./expect ./output
345
346 # Create a NDP cache
347 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6SRCGW
348
349 # Neighbor with a cache (no different from w/o cache)
350 cat >./expect <<-EOF
351 route to: fc00:0:0:1::1
352 destination: fc00:0:0:1::
353 mask: ffff:ffff:ffff:ffff::
354 local addr: fc00:0:0:1::2
355 interface: shmif0
356 flags: <UP,DONE,CONNECTED>
357 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
358 EOF
359 rump.route -n get -inet6 $IP6SRCGW > ./output
360 $DEBUG && cat ./expect ./output
361 sed -i '$d' ./output
362 atf_check -s exit:0 diff ./expect ./output
363 }
364
365 route_command_get_body()
366 {
367
368 setup
369 setup_forwarding
370 test_route_get
371 rump_server_destroy_ifaces
372 }
373
374 route_command_get6_body()
375 {
376
377 setup6
378 setup_forwarding6
379 test_route_get6
380 rump_server_destroy_ifaces
381 }
382
383 route_command_get_cleanup()
384 {
385
386 $DEBUG && dump
387 cleanup
388 }
389
390 route_command_get6_cleanup()
391 {
392
393 $DEBUG && dump
394 cleanup
395 }
396
397 atf_init_test_cases()
398 {
399
400 atf_add_test_case route_non_subnet_gateway
401 atf_add_test_case route_command_get
402 atf_add_test_case route_command_get6
403 }
404