1 # $NetBSD: t_forwarding.sh,v 1.15 2016/08/10 21:33:52 kre Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, 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 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
29 inet6server="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_shmif -lrumpdev"
31 SOCKSRC=unix://commsock1
32 SOCKFWD=unix://commsock2
33 SOCKDST=unix://commsock3
38 IP4DST_BCAST=10.0.2.255
40 IP6SRCGW=fc00:0:0:1::1
41 IP6DSTGW=fc00:0:0:2::1
49 atf_test_case ipforwarding_v4 cleanup
50 atf_test_case ipforwarding_v6 cleanup
51 atf_test_case ipforwarding_fastforward_v4 cleanup
52 atf_test_case ipforwarding_fastforward_v6 cleanup
53 atf_test_case ipforwarding_misc cleanup
55 ipforwarding_v4_head()
57 atf_set "descr" "Does IPv4 forwarding tests"
58 atf_set "require.progs" "rump_server"
61 ipforwarding_v6_head()
63 atf_set "descr" "Does IPv6 forwarding tests"
64 atf_set "require.progs" "rump_server"
67 ipforwarding_misc_head()
69 atf_set "descr" "Does IPv4 forwarding tests"
70 atf_set "require.progs" "rump_server"
81 export RUMP_SERVER=${sock}
82 atf_check -s exit:0 rump.ifconfig shmif0 create
83 atf_check -s exit:0 rump.ifconfig shmif0 linkstr ${bus}
84 if [ $mode = "ipv6" ]; then
85 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
86 atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
88 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
89 atf_check -s exit:0 -o ignore rump.route add default ${gw}
91 atf_check -s exit:0 rump.ifconfig shmif0 up
106 export RUMP_SERVER=${sock}
107 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
108 if [ $mode = "ipv6" ]; then
109 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${addr}
111 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr}
119 export RUMP_SERVER=$SOCKFWD
120 atf_check -s exit:0 rump.ifconfig shmif0 create
121 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
123 atf_check -s exit:0 rump.ifconfig shmif1 create
124 atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus2
126 if [ $mode = "ipv6" ]; then
127 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
128 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
130 atf_check -s exit:0 rump.ifconfig shmif0 inet ${IP4SRCGW} netmask 0xffffff00
131 atf_check -s exit:0 rump.ifconfig shmif1 inet ${IP4DSTGW} netmask 0xffffff00
134 atf_check -s exit:0 rump.ifconfig shmif0 up
135 atf_check -s exit:0 rump.ifconfig shmif1 up
139 if [ $mode = "ipv6" ]; then
140 rump.sysctl net.inet6.ip6.forwarding
142 rump.sysctl net.inet.ip.forwarding
149 atf_check -s exit:0 ${inetserver} $SOCKSRC
150 atf_check -s exit:0 ${inetserver} $SOCKFWD
151 atf_check -s exit:0 ${inetserver} $SOCKDST
153 setup_endpoint $SOCKSRC $IP4SRC bus1 ipv4 $IP4SRCGW
154 setup_endpoint $SOCKDST $IP4DST bus2 ipv4 $IP4DSTGW
160 atf_check -s exit:0 ${inet6server} $SOCKSRC
161 atf_check -s exit:0 ${inet6server} $SOCKFWD
162 atf_check -s exit:0 ${inet6server} $SOCKDST
164 setup_endpoint $SOCKSRC $IP6SRC bus1 ipv6 $IP6SRCGW
165 setup_endpoint $SOCKDST $IP6DST bus2 ipv6 $IP6DSTGW
173 export RUMP_SERVER=$SOCKDST
176 # start bozo in daemon mode
177 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
178 /usr/libexec/httpd -P $HTTPD_PID -i $ip -b -s $(pwd)
180 $DEBUG && rump.netstat -a
187 export RUMP_SERVER=$SOCKFWD
188 atf_check -s exit:0 rump.arp -d -a
190 export RUMP_SERVER=$SOCKSRC
193 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
194 ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
199 test_endpoint $SOCKSRC $IP4SRC bus1 ipv4
200 test_endpoint $SOCKDST $IP4DST bus2 ipv4
202 export RUMP_SERVER=$SOCKFWD
203 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
204 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
206 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${IP4SRCGW}
207 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${IP4DSTGW}
212 test_endpoint $SOCKSRC $IP6SRC bus1 ipv6
213 test_endpoint $SOCKDST $IP6DST bus2 ipv6
215 export RUMP_SERVER=$SOCKFWD
216 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
217 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
219 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${IP6SRCGW}
220 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${IP6DSTGW}
225 export RUMP_SERVER=$SOCKFWD
226 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
231 export RUMP_SERVER=$SOCKFWD
232 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
235 setup_directed_broadcast()
237 export RUMP_SERVER=$SOCKFWD
238 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.directed-broadcast=1
241 setup_icmp_bmcastecho()
243 export RUMP_SERVER=$SOCKDST
244 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.icmp.bmcastecho=1
247 teardown_forwarding()
249 export RUMP_SERVER=$SOCKFWD
250 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=0
253 teardown_forwarding6()
255 export RUMP_SERVER=$SOCKFWD
256 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=0
259 teardown_directed_broadcast()
261 export RUMP_SERVER=$SOCKFWD
262 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.directed-broadcast=0
265 teardown_icmp_bmcastecho()
267 export RUMP_SERVER=$SOCKDST
268 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.icmp.bmcastecho=0
271 teardown_interfaces()
273 export RUMP_SERVER=$SOCKSRC
274 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 destroy
276 export RUMP_SERVER=$SOCKFWD
277 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 destroy
278 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 destroy
280 export RUMP_SERVER=$SOCKDST
281 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 destroy
284 test_setup_forwarding()
286 export RUMP_SERVER=$SOCKFWD
287 atf_check -s exit:0 -o match:"net.inet.ip.forwarding = 1" \
288 rump.sysctl net.inet.ip.forwarding
290 test_setup_forwarding6()
292 export RUMP_SERVER=$SOCKFWD
293 atf_check -s exit:0 -o match:"net.inet6.ip6.forwarding = 1" \
294 rump.sysctl net.inet6.ip6.forwarding
297 test_teardown_forwarding()
299 export RUMP_SERVER=$SOCKFWD
300 atf_check -s exit:0 -o match:"net.inet.ip.forwarding = 0" \
301 rump.sysctl net.inet.ip.forwarding
303 test_teardown_forwarding6()
305 export RUMP_SERVER=$SOCKFWD
306 atf_check -s exit:0 -o match:"net.inet6.ip6.forwarding = 0" \
307 rump.sysctl net.inet6.ip6.forwarding
312 env RUMP_SERVER=$SOCKSRC rump.halt
313 env RUMP_SERVER=$SOCKFWD rump.halt
314 env RUMP_SERVER=$SOCKDST rump.halt
320 if [ -f $HTTPD_PID ]; then
321 kill -9 "$(cat $HTTPD_PID)"
329 env RUMP_SERVER=$SOCKSRC rump.netstat -nr
330 env RUMP_SERVER=$SOCKFWD rump.netstat -nr
331 env RUMP_SERVER=$SOCKDST rump.netstat -nr
333 /usr/bin/shmif_dumpbus -p - bus1 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
334 /usr/bin/shmif_dumpbus -p - bus2 2>/dev/null| /usr/sbin/tcpdump -n -e -r -
339 export RUMP_SERVER=$SOCKSRC
340 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST
341 export RUMP_SERVER=$SOCKDST
342 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRC
347 export RUMP_SERVER=$SOCKSRC
348 $DEBUG && rump.ifconfig -v shmif0
349 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
350 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST
351 $DEBUG && rump.ifconfig -v shmif0
353 export RUMP_SERVER=$SOCKDST
354 $DEBUG && rump.ifconfig -v shmif0
355 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DSTGW
356 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRC
357 $DEBUG && rump.ifconfig -v shmif0
362 export RUMP_SERVER=$SOCKSRC
363 $DEBUG && rump.ifconfig -v shmif0
364 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 -T 1 $IP4SRCGW
365 atf_check -s not-exit:0 -o match:'Time To Live exceeded' \
366 rump.ping -v -n -w $TIMEOUT -c 1 -T 1 $IP4DST
367 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 -T 2 $IP4DST
368 $DEBUG && rump.ifconfig -v shmif0
375 export RUMP_SERVER=$SOCKSRC
376 $DEBUG && rump.ifconfig -v shmif0
378 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=1
380 atf_check -s not-exit:0 -e match:'timed out' \
381 env LD_PRELOAD=/usr/lib/librumphijack.so \
382 ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
385 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=2
387 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
388 ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
390 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=64
391 $DEBUG && rump.ifconfig -v shmif0
394 test_directed_broadcast()
396 setup_icmp_bmcastecho
398 setup_directed_broadcast
399 export RUMP_SERVER=$SOCKSRC
400 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST_BCAST
402 teardown_directed_broadcast
403 export RUMP_SERVER=$SOCKSRC
404 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST_BCAST
406 teardown_icmp_bmcastecho
411 export RUMP_SERVER=$SOCKSRC
412 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6DST
413 export RUMP_SERVER=$SOCKDST
414 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6SRC
419 export RUMP_SERVER=$SOCKSRC
420 $DEBUG && rump.ifconfig -v shmif0
421 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6SRCGW
422 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6DST
423 $DEBUG && rump.ifconfig -v shmif0
425 export RUMP_SERVER=$SOCKDST
426 $DEBUG && rump.ifconfig -v shmif0
427 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6DSTGW
428 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6SRC
429 $DEBUG && rump.ifconfig -v shmif0
434 export RUMP_SERVER=$SOCKSRC
435 $DEBUG && rump.ifconfig -v shmif0
436 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -h 1 -X $TIMEOUT $IP6SRCGW
437 atf_check -s not-exit:0 -o match:'Time to live exceeded' \
438 rump.ping6 -v -n -c 1 -h 1 -X $TIMEOUT $IP6DST
439 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -h 2 -X $TIMEOUT $IP6DST
440 $DEBUG && rump.ifconfig -v shmif0
443 ipforwarding_v4_body()
449 test_setup_forwarding
453 test_teardown_forwarding
459 ipforwarding_v6_body()
465 test_setup_forwarding6
470 test_teardown_forwarding6
476 ipforwarding_fastforward_v4_body()
482 test_setup_forwarding
485 test_http_get $IP4DST
490 ipforwarding_fastforward_v6_body()
496 test_setup_forwarding6
499 test_http_get "[$IP6DST]"
504 ipforwarding_misc_body()
510 test_setup_forwarding
514 test_directed_broadcast
517 test_sysctl_ttl $IP4DST
523 ipforwarding_v4_cleanup()
529 ipforwarding_v6_cleanup()
535 ipforwarding_fastforward_v4_cleanup()
542 ipforwarding_fastforward_v6_cleanup()
549 ipforwarding_misc_cleanup()
556 atf_init_test_cases()
558 atf_add_test_case ipforwarding_v4
559 atf_add_test_case ipforwarding_v6
560 atf_add_test_case ipforwarding_fastforward_v4
561 atf_add_test_case ipforwarding_fastforward_v6
562 atf_add_test_case ipforwarding_misc