1 # $NetBSD: t_forwarding.sh,v 1.19 2016/11/25 08:51:17 ozaki-r 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 SOCKSRC=unix://commsock1
29 SOCKFWD=unix://commsock2
30 SOCKDST=unix://commsock3
35 IP4DST_BCAST=10.0.2.255
37 IP6SRCGW=fc00:0:0:1::1
38 IP6DSTGW=fc00:0:0:2::1
45 atf_test_case ipforwarding_v4 cleanup
46 atf_test_case ipforwarding_v6 cleanup
47 atf_test_case ipforwarding_fastforward_v4 cleanup
48 atf_test_case ipforwarding_fastforward_v6 cleanup
49 atf_test_case ipforwarding_misc cleanup
51 ipforwarding_v4_head()
53 atf_set "descr" "Does IPv4 forwarding tests"
54 atf_set "require.progs" "rump_server"
57 ipforwarding_v6_head()
59 atf_set "descr" "Does IPv6 forwarding tests"
60 atf_set "require.progs" "rump_server"
63 ipforwarding_fastforward_v4_head()
65 atf_set "descr" "Tests for IPv4 fastforward"
66 atf_set "require.progs" "rump_server"
69 ipforwarding_fastforward_v6_head()
71 atf_set "descr" "Tests for IPv6 fastfoward"
72 atf_set "require.progs" "rump_server"
75 ipforwarding_misc_head()
77 atf_set "descr" "Does IPv4 forwarding tests"
78 atf_set "require.progs" "rump_server"
89 rump_server_add_iface $sock shmif0 $bus
91 export RUMP_SERVER=${sock}
92 if [ $mode = "ipv6" ]; then
93 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${addr}
94 atf_check -s exit:0 -o ignore rump.route add -inet6 default ${gw}
96 atf_check -s exit:0 rump.ifconfig shmif0 inet ${addr} netmask 0xffffff00
97 atf_check -s exit:0 -o ignore rump.route add default ${gw}
99 atf_check -s exit:0 rump.ifconfig shmif0 up
114 export RUMP_SERVER=${sock}
115 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
116 if [ $mode = "ipv6" ]; then
117 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${addr}
119 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${addr}
127 rump_server_add_iface $SOCKFWD shmif0 bus1
128 rump_server_add_iface $SOCKFWD shmif1 bus2
130 export RUMP_SERVER=$SOCKFWD
132 if [ $mode = "ipv6" ]; then
133 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6SRCGW}
134 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DSTGW}
136 atf_check -s exit:0 rump.ifconfig shmif0 inet ${IP4SRCGW} netmask 0xffffff00
137 atf_check -s exit:0 rump.ifconfig shmif1 inet ${IP4DSTGW} netmask 0xffffff00
140 atf_check -s exit:0 rump.ifconfig shmif0 up
141 atf_check -s exit:0 rump.ifconfig shmif1 up
145 if [ $mode = "ipv6" ]; then
146 rump.sysctl net.inet6.ip6.forwarding
148 rump.sysctl net.inet.ip.forwarding
155 rump_server_start $SOCKSRC
156 rump_server_start $SOCKFWD
157 rump_server_start $SOCKDST
159 setup_endpoint $SOCKSRC $IP4SRC bus1 ipv4 $IP4SRCGW
160 setup_endpoint $SOCKDST $IP4DST bus2 ipv4 $IP4DSTGW
166 rump_server_start $SOCKSRC netinet6
167 rump_server_start $SOCKFWD netinet6
168 rump_server_start $SOCKDST netinet6
170 setup_endpoint $SOCKSRC $IP6SRC bus1 ipv6 $IP6SRCGW
171 setup_endpoint $SOCKDST $IP6DST bus2 ipv6 $IP6DSTGW
179 export RUMP_SERVER=$SOCKFWD
180 atf_check -s exit:0 rump.arp -d -a
182 export RUMP_SERVER=$SOCKSRC
185 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
186 ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
191 test_endpoint $SOCKSRC $IP4SRC bus1 ipv4
192 test_endpoint $SOCKDST $IP4DST bus2 ipv4
194 export RUMP_SERVER=$SOCKFWD
195 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
196 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
198 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${IP4SRCGW}
199 atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 ${IP4DSTGW}
204 test_endpoint $SOCKSRC $IP6SRC bus1 ipv6
205 test_endpoint $SOCKDST $IP6DST bus2 ipv6
207 export RUMP_SERVER=$SOCKFWD
208 atf_check -s exit:0 -o match:shmif0 rump.ifconfig
209 atf_check -s exit:0 -o match:shmif1 rump.ifconfig
211 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${IP6SRCGW}
212 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT ${IP6DSTGW}
217 export RUMP_SERVER=$SOCKFWD
218 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
223 export RUMP_SERVER=$SOCKFWD
224 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=1
227 setup_directed_broadcast()
229 export RUMP_SERVER=$SOCKFWD
230 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.directed-broadcast=1
233 setup_icmp_bmcastecho()
235 export RUMP_SERVER=$SOCKDST
236 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.icmp.bmcastecho=1
239 teardown_forwarding()
241 export RUMP_SERVER=$SOCKFWD
242 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=0
245 teardown_forwarding6()
247 export RUMP_SERVER=$SOCKFWD
248 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet6.ip6.forwarding=0
251 teardown_directed_broadcast()
253 export RUMP_SERVER=$SOCKFWD
254 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.directed-broadcast=0
257 teardown_icmp_bmcastecho()
259 export RUMP_SERVER=$SOCKDST
260 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.icmp.bmcastecho=0
263 teardown_interfaces()
266 rump_server_destroy_ifaces
269 test_setup_forwarding()
271 export RUMP_SERVER=$SOCKFWD
272 atf_check -s exit:0 -o match:"net.inet.ip.forwarding = 1" \
273 rump.sysctl net.inet.ip.forwarding
275 test_setup_forwarding6()
277 export RUMP_SERVER=$SOCKFWD
278 atf_check -s exit:0 -o match:"net.inet6.ip6.forwarding = 1" \
279 rump.sysctl net.inet6.ip6.forwarding
282 test_teardown_forwarding()
284 export RUMP_SERVER=$SOCKFWD
285 atf_check -s exit:0 -o match:"net.inet.ip.forwarding = 0" \
286 rump.sysctl net.inet.ip.forwarding
288 test_teardown_forwarding6()
290 export RUMP_SERVER=$SOCKFWD
291 atf_check -s exit:0 -o match:"net.inet6.ip6.forwarding = 0" \
292 rump.sysctl net.inet6.ip6.forwarding
297 export RUMP_SERVER=$SOCKSRC
298 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST
299 export RUMP_SERVER=$SOCKDST
300 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRC
305 export RUMP_SERVER=$SOCKSRC
306 $DEBUG && rump.ifconfig -v shmif0
307 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRCGW
308 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST
309 $DEBUG && rump.ifconfig -v shmif0
311 export RUMP_SERVER=$SOCKDST
312 $DEBUG && rump.ifconfig -v shmif0
313 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DSTGW
314 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4SRC
315 $DEBUG && rump.ifconfig -v shmif0
320 export RUMP_SERVER=$SOCKSRC
321 $DEBUG && rump.ifconfig -v shmif0
322 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 -T 1 $IP4SRCGW
323 atf_check -s not-exit:0 -o match:'Time To Live exceeded' \
324 rump.ping -v -n -w $TIMEOUT -c 1 -T 1 $IP4DST
325 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 -T 2 $IP4DST
326 $DEBUG && rump.ifconfig -v shmif0
333 export RUMP_SERVER=$SOCKSRC
334 $DEBUG && rump.ifconfig -v shmif0
336 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=1
338 atf_check -s not-exit:0 -e match:'timed out' \
339 env LD_PRELOAD=/usr/lib/librumphijack.so \
340 ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
343 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=2
345 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \
346 ftp -q $TIMEOUT -o out http://$ip/$HTML_FILE
348 atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.ttl=64
349 $DEBUG && rump.ifconfig -v shmif0
352 test_directed_broadcast()
354 setup_icmp_bmcastecho
356 setup_directed_broadcast
357 export RUMP_SERVER=$SOCKSRC
358 atf_check -s exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST_BCAST
360 teardown_directed_broadcast
361 export RUMP_SERVER=$SOCKSRC
362 atf_check -s not-exit:0 -o ignore rump.ping -q -n -w $TIMEOUT -c 1 $IP4DST_BCAST
364 teardown_icmp_bmcastecho
369 export RUMP_SERVER=$SOCKSRC
370 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6DST
371 export RUMP_SERVER=$SOCKDST
372 atf_check -s not-exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6SRC
377 export RUMP_SERVER=$SOCKSRC
378 $DEBUG && rump.ifconfig -v shmif0
379 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6SRCGW
380 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6DST
381 $DEBUG && rump.ifconfig -v shmif0
383 export RUMP_SERVER=$SOCKDST
384 $DEBUG && rump.ifconfig -v shmif0
385 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6DSTGW
386 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -X $TIMEOUT $IP6SRC
387 $DEBUG && rump.ifconfig -v shmif0
392 export RUMP_SERVER=$SOCKSRC
393 $DEBUG && rump.ifconfig -v shmif0
394 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -h 1 -X $TIMEOUT $IP6SRCGW
395 atf_check -s not-exit:0 -o match:'Time to live exceeded' \
396 rump.ping6 -v -n -c 1 -h 1 -X $TIMEOUT $IP6DST
397 atf_check -s exit:0 -o ignore rump.ping6 -q -n -c 1 -h 2 -X $TIMEOUT $IP6DST
398 $DEBUG && rump.ifconfig -v shmif0
401 ipforwarding_v4_body()
407 test_setup_forwarding
411 test_teardown_forwarding
417 ipforwarding_v6_body()
423 test_setup_forwarding6
428 test_teardown_forwarding6
434 ipforwarding_fastforward_v4_body()
440 test_setup_forwarding
443 start_httpd $SOCKDST $IP4DST
444 $DEBUG && rump.netstat -a
446 test_http_get $IP4DST
451 ipforwarding_fastforward_v6_body()
457 test_setup_forwarding6
460 start_httpd $SOCKDST $IP6DST
461 $DEBUG && rump.netstat -a
463 test_http_get "[$IP6DST]"
468 ipforwarding_misc_body()
474 test_setup_forwarding
478 test_directed_broadcast
481 start_httpd $SOCKDST $IP4DST
482 $DEBUG && rump.netstat -a
484 test_sysctl_ttl $IP4DST
490 ipforwarding_v4_cleanup()
496 ipforwarding_v6_cleanup()
502 ipforwarding_fastforward_v4_cleanup()
509 ipforwarding_fastforward_v6_cleanup()
516 ipforwarding_misc_cleanup()
523 atf_init_test_cases()
525 atf_add_test_case ipforwarding_v4
526 atf_add_test_case ipforwarding_v6
527 atf_add_test_case ipforwarding_fastforward_v4
528 atf_add_test_case ipforwarding_fastforward_v6
529 atf_add_test_case ipforwarding_misc