t_route.sh revision 1.4 1 # $NetBSD: t_route.sh,v 1.4 2016/04/04 07:37:08 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 RUMP_LIBS_IPV6="$RUMP_LIBS -lrumpnet_netinet6"
30
31 # non_subnet_gateway
32 SOCK_CLIENT=unix://commsock1
33 SOCK_GW=unix://commsock2
34 BUS=bus1
35
36 # command_get
37 SOCKSRC=unix://commsock1
38 SOCKFWD=unix://commsock2
39 SOCKDST=unix://commsock3
40 IP4SRC=10.0.1.2
41 IP4SRCGW=10.0.1.1
42 IP4DSTGW=10.0.2.1
43 IP4DST=10.0.2.2
44 IP4DST_BCAST=10.0.2.255
45 IP6SRC=fc00:0:0:1::2
46 IP6SRCGW=fc00:0:0:1::1
47 IP6DSTGW=fc00:0:0:2::1
48 IP6DST=fc00:0:0:2::2
49 BUS_SRCGW=bus1
50 BUS_DSTGW=bus2
51
52 DEBUG=false
53 TIMEOUT=1
54 PING_OPTS="-n -c 1 -w $TIMEOUT"
55
56 atf_test_case non_subnet_gateway cleanup
57 non_subnet_gateway_head()
58 {
59
60 atf_set "descr" "tests of a gateway not on the local subnet"
61 atf_set "require.progs" "rump_server"
62 }
63
64 non_subnet_gateway_body()
65 {
66
67 atf_check -s exit:0 rump_server ${RUMP_LIBS} ${SOCK_CLIENT}
68 atf_check -s exit:0 rump_server ${RUMP_LIBS} ${SOCK_GW}
69
70 export RUMP_SERVER=${SOCK_GW}
71
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
76
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
80
81 $DEBUG && rump.netstat -nr -f inet
82
83 export RUMP_SERVER=${SOCK_CLIENT}
84
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
89
90 $DEBUG && rump.netstat -nr -f inet
91
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
95
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
101
102 $DEBUG && rump.netstat -nr -f inet
103
104 # Be reachable to the gateway
105 atf_check -s exit:0 -o ignore rump.ping $PING_OPTS 192.168.0.1
106
107 unset RUMP_SERVER
108 }
109
110 non_subnet_gateway_cleanup()
111 {
112
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
116 }
117
118 atf_test_case command_get cleanup
119 atf_test_case command_get6 cleanup
120 command_get_head()
121 {
122
123 atf_set "descr" "tests of route get command"
124 atf_set "require.progs" "rump_server"
125 }
126
127 command_get6_head()
128 {
129
130 atf_set "descr" "tests of route get command (IPv6)"
131 atf_set "require.progs" "rump_server"
132 }
133
134 setup_endpoint()
135 {
136 local sock=${1}
137 local addr=${2}
138 local bus=${3}
139 local mode=${4}
140 local gw=${5}
141
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}
148 else
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}
151 fi
152 atf_check -s exit:0 rump.ifconfig shmif0 up
153
154 if $DEBUG; then
155 rump.ifconfig shmif0
156 rump.netstat -nr
157 fi
158 }
159
160 setup_forwarder()
161 {
162 mode=${1}
163
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
167
168 atf_check -s exit:0 rump.ifconfig shmif1 create
169 atf_check -s exit:0 rump.ifconfig shmif1 linkstr $BUS_DSTGW
170
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}
174 else
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
177 fi
178
179 atf_check -s exit:0 rump.ifconfig shmif0 up
180 atf_check -s exit:0 rump.ifconfig shmif1 up
181
182 if $DEBUG; then
183 rump.netstat -nr
184 if [ $mode = "ipv6" ]; then
185 rump.sysctl net.inet6.ip6.forwarding
186 else
187 rump.sysctl net.inet.ip.forwarding
188 fi
189 fi
190 }
191
192 setup_forwarding()
193 {
194 export RUMP_SERVER=$SOCKFWD
195 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
196 }
197
198 setup_forwarding6()
199 {
200 export RUMP_SERVER=$SOCKFWD
201 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
202 }
203
204 setup()
205 {
206
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
210
211 setup_endpoint $SOCKSRC $IP4SRC $BUS_SRCGW ipv4 $IP4SRCGW
212 setup_endpoint $SOCKDST $IP4DST $BUS_DSTGW ipv4 $IP4DSTGW
213 setup_forwarder ipv4
214 }
215
216 setup6()
217 {
218
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
222
223 setup_endpoint $SOCKSRC $IP6SRC $BUS_SRCGW ipv6 $IP6SRCGW
224 setup_endpoint $SOCKDST $IP6DST $BUS_DSTGW ipv6 $IP6DSTGW
225 setup_forwarder ipv6
226 }
227
228 test_route_get()
229 {
230
231 export RUMP_SERVER=$SOCKSRC
232 $DEBUG && rump.netstat -nr -f inet
233 $DEBUG && rump.arp -n -a
234
235 # Make sure an ARP cache to the gateway doesn't exist
236 rump.arp -d $IP4SRCGW
237
238 # Local
239 cat >./expect <<-EOF
240 route to: 10.0.1.2
241 destination: 10.0.1.2
242 local addr: 10.0.1.2
243 interface: lo0
244 flags: <UP,HOST,DONE,LLINFO,LOCAL>
245 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
246 0 0 0 0 0 0 0 0
247 EOF
248 rump.route -n get $IP4SRC > ./output
249 $DEBUG && cat ./expect ./output
250 atf_check -s exit:0 diff ./expect ./output
251
252 # Neighbor
253 cat >./expect <<-EOF
254 route to: 10.0.1.1
255 destination: 10.0.1.0
256 mask: 255.255.255.0
257 local addr: 10.0.1.2
258 interface: shmif0
259 flags: <UP,DONE,CONNECTED>
260 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
261 0 0 0 0 0 0 0 0
262 EOF
263 rump.route -n get $IP4SRCGW > ./output
264 $DEBUG && cat ./expect ./output
265 atf_check -s exit:0 diff ./expect ./output
266
267 # Remote host
268 cat >./expect <<-EOF
269 route to: 10.0.2.2
270 destination: default
271 mask: default
272 gateway: 10.0.1.1
273 local addr: 10.0.1.2
274 interface: shmif0
275 flags: <UP,GATEWAY,DONE,STATIC>
276 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
277 0 0 0 0 0 0 0 0
278 EOF
279 rump.route -n get $IP4DST > ./output
280 $DEBUG && cat ./expect ./output
281 atf_check -s exit:0 diff ./expect ./output
282
283 # Create a ARP cache
284 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
285
286 # Neighbor with a cache (no different from w/o cache)
287 cat >./expect <<-EOF
288 route to: 10.0.1.1
289 destination: 10.0.1.0
290 mask: 255.255.255.0
291 local addr: 10.0.1.2
292 interface: shmif0
293 flags: <UP,DONE,CONNECTED>
294 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
295 0 0 0 0 0 0 0 0
296 EOF
297 rump.route -n get $IP4SRCGW > ./output
298 $DEBUG && cat ./expect ./output
299 atf_check -s exit:0 diff ./expect ./output
300 }
301
302 test_route_get6()
303 {
304
305 export RUMP_SERVER=$SOCKSRC
306 $DEBUG && rump.netstat -nr -f inet
307 $DEBUG && rump.ndp -n -a
308
309 # Make sure an ARP cache to the gateway doesn't exist
310 rump.ndp -d $IP6SRCGW
311
312 # Local
313 cat >./expect <<-EOF
314 route to: fc00:0:0:1::2
315 destination: fc00:0:0:1::2
316 local addr: fc00:0:0:1::2
317 interface: lo0
318 flags: <UP,HOST,DONE,LLINFO,LOCAL>
319 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
320 0 0 0 0 0 0 0 0
321 EOF
322 rump.route -n get -inet6 $IP6SRC > ./output
323 $DEBUG && cat ./expect ./output
324 atf_check -s exit:0 diff ./expect ./output
325
326 # Neighbor
327 cat >./expect <<-EOF
328 route to: fc00:0:0:1::1
329 destination: fc00:0:0:1::
330 mask: ffff:ffff:ffff:ffff::
331 local addr: fc00:0:0:1::2
332 interface: shmif0
333 flags: <UP,DONE,CONNECTED>
334 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
335 0 0 0 0 0 0 0 0
336 EOF
337 rump.route -n get -inet6 $IP6SRCGW > ./output
338 $DEBUG && cat ./expect ./output
339 atf_check -s exit:0 diff ./expect ./output
340
341 # Remote host
342 cat >./expect <<-EOF
343 route to: fc00:0:0:2::2
344 destination: ::
345 mask: default
346 gateway: fc00:0:0:1::1
347 local addr: fc00:0:0:1::2
348 interface: shmif0
349 flags: <UP,GATEWAY,DONE,STATIC>
350 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
351 0 0 0 0 0 0 0 0
352 EOF
353 rump.route -n get -inet6 $IP6DST > ./output
354 $DEBUG && cat ./expect ./output
355 atf_check -s exit:0 diff ./expect ./output
356
357 # Create a NDP cache
358 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6SRCGW
359
360 # Neighbor with a cache (no different from w/o cache)
361 cat >./expect <<-EOF
362 route to: fc00:0:0:1::1
363 destination: fc00:0:0:1::
364 mask: ffff:ffff:ffff:ffff::
365 local addr: fc00:0:0:1::2
366 interface: shmif0
367 flags: <UP,DONE,CONNECTED>
368 recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
369 0 0 0 0 0 0 0 0
370 EOF
371 rump.route -n get -inet6 $IP6SRCGW > ./output
372 $DEBUG && cat ./expect ./output
373 atf_check -s exit:0 diff ./expect ./output
374 }
375
376 command_get_body()
377 {
378
379 setup
380 setup_forwarding
381 test_route_get
382 }
383
384 command_get6_body()
385 {
386
387 setup6
388 setup_forwarding6
389 test_route_get6
390 }
391
392 dump()
393 {
394
395 env RUMP_SERVER=$SOCKSRC rump.netstat -nr
396 env RUMP_SERVER=$SOCKFWD rump.netstat -nr
397 env RUMP_SERVER=$SOCKDST rump.netstat -nr
398
399 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
400 shmif_dumpbus -p - bus2 2>/dev/null| tcpdump -n -e -r -
401 }
402
403 cleanup()
404 {
405
406 env RUMP_SERVER=$SOCKSRC rump.halt
407 env RUMP_SERVER=$SOCKFWD rump.halt
408 env RUMP_SERVER=$SOCKDST rump.halt
409 }
410
411 command_get_cleanup()
412 {
413 $DEBUG && dump
414 cleanup
415 }
416
417 command_get6_cleanup()
418 {
419 dump
420 cleanup
421 }
422
423 atf_init_test_cases()
424 {
425
426 atf_add_test_case non_subnet_gateway
427 atf_add_test_case command_get
428 atf_add_test_case command_get6
429 }
430