]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/net/route/t_route.sh
MFC r305358,r305449,r305451,r306367,r306397,r309474:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / net / route / t_route.sh
1 #       $NetBSD: t_route.sh,v 1.7 2016/08/10 23:00:39 roy 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="-lrumpdev -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 route_non_subnet_gateway cleanup
57 route_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 route_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 route_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 route_command_get cleanup
119 atf_test_case route_command_get6 cleanup
120 route_command_get_head()
121 {
122
123         atf_set "descr" "tests of route get command"
124         atf_set "require.progs" "rump_server"
125 }
126
127 route_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         EOF
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.
250         sed -i '$d' ./output
251         atf_check -s exit:0 diff ./expect ./output
252
253         # Neighbor
254         cat >./expect <<-EOF
255    route to: 10.0.1.1
256 destination: 10.0.1.0
257        mask: 255.255.255.0
258  local addr: 10.0.1.2
259   interface: shmif0
260       flags: <UP,DONE,CONNECTED>
261  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
262         EOF
263         rump.route -n get $IP4SRCGW > ./output
264         $DEBUG && cat ./expect ./output
265         sed -i '$d' ./output
266         atf_check -s exit:0 diff ./expect ./output
267
268         # Remote host
269         cat >./expect <<-EOF
270    route to: 10.0.2.2
271 destination: default
272        mask: default
273     gateway: 10.0.1.1
274  local addr: 10.0.1.2
275   interface: shmif0
276       flags: <UP,GATEWAY,DONE,STATIC>
277  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
278         EOF
279         rump.route -n get $IP4DST > ./output
280         $DEBUG && cat ./expect ./output
281         sed -i '$d' ./output
282         atf_check -s exit:0 diff ./expect ./output
283
284         # Create a ARP cache
285         atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
286
287         # Neighbor with a cache (no different from w/o cache)
288         cat >./expect <<-EOF
289    route to: 10.0.1.1
290 destination: 10.0.1.0
291        mask: 255.255.255.0
292  local addr: 10.0.1.2
293   interface: shmif0
294       flags: <UP,DONE,CONNECTED>
295  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
296         EOF
297         rump.route -n get $IP4SRCGW > ./output
298         $DEBUG && cat ./expect ./output
299         sed -i '$d' ./output
300         atf_check -s exit:0 diff ./expect ./output
301 }
302
303 test_route_get6()
304 {
305
306         export RUMP_SERVER=$SOCKSRC
307         $DEBUG && rump.netstat -nr -f inet
308         $DEBUG && rump.ndp -n -a
309
310         # Make sure an ARP cache to the gateway doesn't exist
311         rump.ndp -d $IP6SRCGW
312
313         # Local
314         cat >./expect <<-EOF
315    route to: fc00:0:0:1::2
316 destination: fc00:0:0:1::2
317  local addr: fc00:0:0:1::2
318   interface: lo0
319       flags: <UP,HOST,DONE,LLINFO,LOCAL>
320  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
321         EOF
322         rump.route -n get -inet6 $IP6SRC > ./output
323         $DEBUG && cat ./expect ./output
324         sed -i '$d' ./output
325         atf_check -s exit:0 diff ./expect ./output
326
327         # Neighbor
328         cat >./expect <<-EOF
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
333   interface: shmif0
334       flags: <UP,DONE,CONNECTED>
335  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
336         EOF
337         rump.route -n get -inet6 $IP6SRCGW > ./output
338         $DEBUG && cat ./expect ./output
339         sed -i '$d' ./output
340         atf_check -s exit:0 diff ./expect ./output
341
342         # Remote host
343         cat >./expect <<-EOF
344    route to: fc00:0:0:2::2
345 destination: ::
346        mask: default
347     gateway: fc00:0:0:1::1
348  local addr: fc00:0:0:1::2
349   interface: shmif0
350       flags: <UP,GATEWAY,DONE,STATIC>
351  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
352         EOF
353         rump.route -n get -inet6 $IP6DST > ./output
354         $DEBUG && cat ./expect ./output
355         sed -i '$d' ./output
356         atf_check -s exit:0 diff ./expect ./output
357
358         # Create a NDP cache
359         atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6SRCGW
360
361         # Neighbor with a cache (no different from w/o cache)
362         cat >./expect <<-EOF
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
367   interface: shmif0
368       flags: <UP,DONE,CONNECTED>
369  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
370         EOF
371         rump.route -n get -inet6 $IP6SRCGW > ./output
372         $DEBUG && cat ./expect ./output
373         sed -i '$d' ./output
374         atf_check -s exit:0 diff ./expect ./output
375 }
376
377 route_command_get_body()
378 {
379
380         setup
381         setup_forwarding
382         test_route_get
383 }
384
385 route_command_get6_body()
386 {
387
388         setup6
389         setup_forwarding6
390         test_route_get6
391 }
392
393 dump()
394 {
395
396         env RUMP_SERVER=$SOCKSRC rump.netstat -nr
397         env RUMP_SERVER=$SOCKFWD rump.netstat -nr
398         env RUMP_SERVER=$SOCKDST rump.netstat -nr
399
400         shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
401         shmif_dumpbus -p - bus2 2>/dev/null| tcpdump -n -e -r -
402 }
403
404 cleanup()
405 {
406
407         env RUMP_SERVER=$SOCKSRC rump.halt
408         env RUMP_SERVER=$SOCKFWD rump.halt
409         env RUMP_SERVER=$SOCKDST rump.halt
410 }
411
412 route_command_get_cleanup()
413 {
414         $DEBUG && dump
415         cleanup
416 }
417
418 route_command_get6_cleanup()
419 {
420         dump
421         cleanup
422 }
423
424 atf_init_test_cases()
425 {
426
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
430 }