xref: /netbsd-src/tests/net/route/t_flags.sh (revision 3f30ca4e9f4d8db1147cd69b679114b037c6e370)
1*3f30ca4eSozaki-r#	$NetBSD: t_flags.sh,v 1.20 2017/08/03 03:16:27 ozaki-r Exp $
22754f594Sozaki-r#
32754f594Sozaki-r# Copyright (c) 2015 The NetBSD Foundation, Inc.
42754f594Sozaki-r# All rights reserved.
52754f594Sozaki-r#
62754f594Sozaki-r# Redistribution and use in source and binary forms, with or without
72754f594Sozaki-r# modification, are permitted provided that the following conditions
82754f594Sozaki-r# are met:
92754f594Sozaki-r# 1. Redistributions of source code must retain the above copyright
102754f594Sozaki-r#    notice, this list of conditions and the following disclaimer.
112754f594Sozaki-r# 2. Redistributions in binary form must reproduce the above copyright
122754f594Sozaki-r#    notice, this list of conditions and the following disclaimer in the
132754f594Sozaki-r#    documentation and/or other materials provided with the distribution.
142754f594Sozaki-r#
152754f594Sozaki-r# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
162754f594Sozaki-r# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
172754f594Sozaki-r# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
182754f594Sozaki-r# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
192754f594Sozaki-r# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
202754f594Sozaki-r# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
212754f594Sozaki-r# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
222754f594Sozaki-r# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
232754f594Sozaki-r# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
242754f594Sozaki-r# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
252754f594Sozaki-r# POSSIBILITY OF SUCH DAMAGE.
262754f594Sozaki-r#
272754f594Sozaki-r
282754f594Sozaki-rSOCK_LOCAL=unix://commsock1
292754f594Sozaki-rSOCK_PEER=unix://commsock2
302754f594Sozaki-rSOCK_GW=unix://commsock3
312754f594Sozaki-rBUS=bus1
322754f594Sozaki-rBUS2=bus2
332754f594Sozaki-r
341c189061Sozaki-rDEBUG=${DEBUG:-false}
352754f594Sozaki-r
362754f594Sozaki-rsetup_local()
372754f594Sozaki-r{
382754f594Sozaki-r
395a83ceeaSozaki-r	rump_server_start $SOCK_LOCAL
405a83ceeaSozaki-r	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
412754f594Sozaki-r
422754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
432754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24
442754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
45ad4db0ebSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
462754f594Sozaki-r
472754f594Sozaki-r	$DEBUG && rump.ifconfig
482754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
492754f594Sozaki-r}
502754f594Sozaki-r
512754f594Sozaki-rsetup_peer()
522754f594Sozaki-r{
532754f594Sozaki-r
545a83ceeaSozaki-r	rump_server_start $SOCK_PEER
555a83ceeaSozaki-r	rump_server_add_iface $SOCK_PEER shmif0 $BUS
562754f594Sozaki-r
572754f594Sozaki-r	export RUMP_SERVER=$SOCK_PEER
582754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24
592754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
60ad4db0ebSozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
612754f594Sozaki-r
622754f594Sozaki-r	$DEBUG && rump.ifconfig
632754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
642754f594Sozaki-r}
652754f594Sozaki-r
662754f594Sozaki-rsetup_gw()
672754f594Sozaki-r{
682754f594Sozaki-r
695a83ceeaSozaki-r	rump_server_start $SOCK_GW
705a83ceeaSozaki-r	rump_server_add_iface $SOCK_GW shmif0 $BUS
715a83ceeaSozaki-r	rump_server_add_iface $SOCK_GW shmif1 $BUS2
722754f594Sozaki-r
732754f594Sozaki-r	export RUMP_SERVER=$SOCK_GW
742754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24
752754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
762754f594Sozaki-r
772754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24
782754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24
792754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up
802754f594Sozaki-r
812754f594Sozaki-r	# Wait until DAD completes (10 sec at most)
822754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
832754f594Sozaki-r	atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative"
842754f594Sozaki-r
852754f594Sozaki-r	$DEBUG && rump.ifconfig
862754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
872754f594Sozaki-r}
882754f594Sozaki-r
89bdcbfcd1Sozaki-rtest_lo()
902754f594Sozaki-r{
912754f594Sozaki-r
922754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
932754f594Sozaki-r
942754f594Sozaki-r	# Up, Host, local
95927b18c9Sozaki-r	check_route_flags 127.0.0.1 UHl
962754f594Sozaki-r}
972754f594Sozaki-r
98bdcbfcd1Sozaki-rtest_connected()
992754f594Sozaki-r{
1002754f594Sozaki-r
1012754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
1022754f594Sozaki-r
103d15c5ed0Sozaki-r	# Up, Host, local
104927b18c9Sozaki-r	check_route_flags 10.0.0.2 UHl
1052754f594Sozaki-r
1062754f594Sozaki-r	# Up, Cloning
107927b18c9Sozaki-r	check_route_flags 10.0.0/24 UC
1082754f594Sozaki-r}
1092754f594Sozaki-r
110bdcbfcd1Sozaki-rtest_default_gateway()
1112754f594Sozaki-r{
1122754f594Sozaki-r
1132754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
1142754f594Sozaki-r
1152754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
1162754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
1172754f594Sozaki-r
1182754f594Sozaki-r	# Up, Gateway, Static
119927b18c9Sozaki-r	check_route_flags default UGS
1202754f594Sozaki-r}
1212754f594Sozaki-r
122bdcbfcd1Sozaki-rtest_static()
1232754f594Sozaki-r{
1242754f594Sozaki-r
1252754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
1262754f594Sozaki-r
1272754f594Sozaki-r	# Static route to host
1282754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add 10.0.1.1 10.0.0.1
1292754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
1302754f594Sozaki-r
1312754f594Sozaki-r	# Up, Gateway, Host, Static
132927b18c9Sozaki-r	check_route_flags 10.0.1.1 UGHS
1332754f594Sozaki-r
1342754f594Sozaki-r	# Static route to network
1352754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.1
1362754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
1372754f594Sozaki-r
1382754f594Sozaki-r	# Up, Gateway, Static
139927b18c9Sozaki-r	check_route_flags 10.0.2/24 UGS
1402754f594Sozaki-r}
1412754f594Sozaki-r
142bdcbfcd1Sozaki-rtest_blackhole()
1432754f594Sozaki-r{
1442754f594Sozaki-r
1452754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
1462754f594Sozaki-r
147e53ad407Sozaki-r	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
148e53ad407Sozaki-r
1492754f594Sozaki-r	# Delete an existing route first
1502754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
1513cd98890Sozaki-r	# Should be removed too
1523cd98890Sozaki-r	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
1532754f594Sozaki-r
154e53ad407Sozaki-r	# Gateway must be lo0
155e53ad407Sozaki-r	atf_check -s exit:0 -o ignore \
156e53ad407Sozaki-r	    rump.route add -net 10.0.0.0/24 127.0.0.1 -blackhole
1572754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
1582754f594Sozaki-r
1592754f594Sozaki-r	# Up, Gateway, Blackhole, Static
160927b18c9Sozaki-r	check_route_flags 10.0.0/24 UGBS
1612754f594Sozaki-r
162e53ad407Sozaki-r	atf_check -s not-exit:0 -o match:'100.0% packet loss' \
1632754f594Sozaki-r	    rump.ping -n -w 1 -c 1 10.0.0.1
1642754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
1652754f594Sozaki-r
1662754f594Sozaki-r	# Shouldn't be created
167927b18c9Sozaki-r	check_route_no_entry 10.0.0.1
1687eee4dbaSozaki-r	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
1692754f594Sozaki-r}
1702754f594Sozaki-r
171bdcbfcd1Sozaki-rtest_reject()
1722754f594Sozaki-r{
1732754f594Sozaki-r
1742754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
1752754f594Sozaki-r
1762754f594Sozaki-r	# Delete an existing route first
1772754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
1782754f594Sozaki-r
1792754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -reject
1802754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
1812754f594Sozaki-r
1822754f594Sozaki-r	# Up, Gateway, Reject, Static
183927b18c9Sozaki-r	check_route_flags 10.0.0/24 UGRS
1842754f594Sozaki-r
1852754f594Sozaki-r	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
1862754f594Sozaki-r	    rump.ping -n -w 1 -c 1 10.0.0.1
1872754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
1882754f594Sozaki-r
1892754f594Sozaki-r	# Shouldn't be created
190927b18c9Sozaki-r	check_route_no_entry 10.0.0.1
1917eee4dbaSozaki-r	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
1920ba9b345Sozaki-r
1934b837129Sozaki-r	# Gateway is lo0 (RTF_GATEWAY)
1940ba9b345Sozaki-r
1950ba9b345Sozaki-r	# Delete an existing route first
1960ba9b345Sozaki-r	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
1970ba9b345Sozaki-r
1980ba9b345Sozaki-r	atf_check -s exit:0 -o ignore \
1990ba9b345Sozaki-r	    rump.route add -net 10.0.0.0/24 127.0.0.1 -reject
2000ba9b345Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2010ba9b345Sozaki-r
2020ba9b345Sozaki-r	# Up, Gateway, Reject, Static
203927b18c9Sozaki-r	check_route_flags 10.0.0/24 UGRS
2040ba9b345Sozaki-r
2050ba9b345Sozaki-r	atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \
2060ba9b345Sozaki-r	    rump.ping -n -w 1 -c 1 10.0.0.1
2070ba9b345Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2080ba9b345Sozaki-r
2090ba9b345Sozaki-r	# Shouldn't be created
210927b18c9Sozaki-r	check_route_no_entry 10.0.0.1
2117eee4dbaSozaki-r	atf_check -s not-exit:0 -e match:'no entry' rump.arp -n 10.0.0.1
2124b837129Sozaki-r
2134b837129Sozaki-r	# Gateway is lo0 (RTF_HOST)
2144b837129Sozaki-r
2154b837129Sozaki-r	# Delete an existing route first
2164b837129Sozaki-r	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
2174b837129Sozaki-r
2184b837129Sozaki-r	atf_check -s exit:0 -o ignore \
2194b837129Sozaki-r	    rump.route add -host 10.0.0.1/24 127.0.0.1 -iface -reject
2204b837129Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2214b837129Sozaki-r
2224b837129Sozaki-r	# Up, Host, Reject, Static
223927b18c9Sozaki-r	check_route_flags 10.0.0.1 UHRS
2244b837129Sozaki-r
2254b837129Sozaki-r	atf_check -s not-exit:0 -o ignore -e match:'No route to host' \
2264b837129Sozaki-r	    rump.ping -n -w 1 -c 1 10.0.0.1
2274b837129Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2288bb2f299Sozaki-r
2298bb2f299Sozaki-r	return 0
2302754f594Sozaki-r}
2312754f594Sozaki-r
232bdcbfcd1Sozaki-rtest_icmp_redirect()
2332754f594Sozaki-r{
2342754f594Sozaki-r
2352754f594Sozaki-r	### Testing Dynamic flag ###
2362754f594Sozaki-r
2372754f594Sozaki-r	#
2382754f594Sozaki-r	# Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
2392754f594Sozaki-r	#
2402754f594Sozaki-r	setup_gw
2412754f594Sozaki-r
2422754f594Sozaki-r	#
2432754f594Sozaki-r	# Teach the peer that 10.0.2.* is behind 10.0.0.254
2442754f594Sozaki-r	#
2452754f594Sozaki-r	export RUMP_SERVER=$SOCK_PEER
2462754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
2472754f594Sozaki-r	# Up, Gateway, Static
248927b18c9Sozaki-r	check_route_flags 10.0.2/24 UGS
2492754f594Sozaki-r
2502754f594Sozaki-r	#
2512754f594Sozaki-r	# Setup the default gateway to the peer, 10.0.0.1
2522754f594Sozaki-r	#
2532754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
2542754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
2552754f594Sozaki-r	# Up, Gateway, Static
256927b18c9Sozaki-r	check_route_flags default UGS
2572754f594Sozaki-r
2582754f594Sozaki-r	# Try ping 10.0.2.1
2592754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
2602754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2612754f594Sozaki-r
2622754f594Sozaki-r	# Up, Gateway, Host, Dynamic
263927b18c9Sozaki-r	check_route_flags 10.0.2.1 UGHD
264927b18c9Sozaki-r	check_route_gw 10.0.2.1 10.0.0.254
2652754f594Sozaki-r
2662754f594Sozaki-r	export RUMP_SERVER=$SOCK_PEER
2672754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2682754f594Sozaki-r
2692754f594Sozaki-r	### Testing Modified flag ###
2702754f594Sozaki-r
2712754f594Sozaki-r	#
2722754f594Sozaki-r	# Teach a wrong route to 10.0.2.2
2732754f594Sozaki-r	#
2742754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
2752754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1
2762754f594Sozaki-r	# Up, Gateway, Host, Static
277927b18c9Sozaki-r	check_route_flags 10.0.2.2 UGHS
278927b18c9Sozaki-r	check_route_gw 10.0.2.2 10.0.0.1
2792754f594Sozaki-r
2802754f594Sozaki-r	# Try ping 10.0.2.2
2812754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2
2822754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2832754f594Sozaki-r
2842754f594Sozaki-r	# Up, Gateway, Host, Modified, Static
285927b18c9Sozaki-r	check_route_flags 10.0.2.2 UGHMS
286927b18c9Sozaki-r	check_route_gw 10.0.2.2 10.0.0.254
2872754f594Sozaki-r}
2882754f594Sozaki-r
289bdcbfcd1Sozaki-rtest_announce()
2902754f594Sozaki-r{
2912754f594Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
2922754f594Sozaki-r
2932754f594Sozaki-r	# Delete an existing route first
2942754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route delete -net 10.0.0.0/24
2952754f594Sozaki-r
2962754f594Sozaki-r	atf_check -s exit:0 -o ignore rump.route add -net 10.0.0.0/24 10.0.0.1 -proxy
2972754f594Sozaki-r	$DEBUG && rump.netstat -rn -f inet
2982754f594Sozaki-r
2992754f594Sozaki-r	# Up, Gateway, Static, proxy
300927b18c9Sozaki-r	check_route_flags 10.0.0/24 UGSp
3012754f594Sozaki-r
3022754f594Sozaki-r	# TODO test its behavior
3032754f594Sozaki-r}
3042754f594Sozaki-r
305da803ed7Sozaki-rtest_llinfo()
306da803ed7Sozaki-r{
307da803ed7Sozaki-r	local peer_macaddr=
308da803ed7Sozaki-r
309da803ed7Sozaki-r	peer_macaddr=$(get_macaddr $SOCK_PEER shmif0)
310da803ed7Sozaki-r
311da803ed7Sozaki-r	export RUMP_SERVER=$SOCK_LOCAL
312da803ed7Sozaki-r
313da803ed7Sozaki-r	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.0.1
314da803ed7Sozaki-r
315da803ed7Sozaki-r	# Up, Host, LLINFO
316da803ed7Sozaki-r	check_route 10.0.0.1 $peer_macaddr UHL shmif0
317da803ed7Sozaki-r}
318da803ed7Sozaki-r
3192754f594Sozaki-radd_test()
3202754f594Sozaki-r{
3212754f594Sozaki-r	local name=$1
3222754f594Sozaki-r	local desc="$2"
3232754f594Sozaki-r
3242754f594Sozaki-r	atf_test_case "route_flags_${name}" cleanup
325*3f30ca4eSozaki-r	eval "route_flags_${name}_head() {
326*3f30ca4eSozaki-r			atf_set descr \"${desc}\"
327*3f30ca4eSozaki-r			atf_set require.progs rump_server
328*3f30ca4eSozaki-r		}
329*3f30ca4eSozaki-r	    route_flags_${name}_body() {
330*3f30ca4eSozaki-r			setup_local
331*3f30ca4eSozaki-r			setup_peer
332*3f30ca4eSozaki-r			test_${name}
333*3f30ca4eSozaki-r			rump_server_destroy_ifaces
334*3f30ca4eSozaki-r		}
335*3f30ca4eSozaki-r	    route_flags_${name}_cleanup() {
336*3f30ca4eSozaki-r			\$DEBUG && dump
337*3f30ca4eSozaki-r			cleanup
3382754f594Sozaki-r		}"
3392754f594Sozaki-r	atf_add_test_case "route_flags_${name}"
3402754f594Sozaki-r}
3412754f594Sozaki-r
3422754f594Sozaki-ratf_init_test_cases()
3432754f594Sozaki-r{
3442754f594Sozaki-r
345bdcbfcd1Sozaki-r	add_test lo              "Tests route flags: loop back interface"
346bdcbfcd1Sozaki-r	add_test connected       "Tests route flags: connected route"
347bdcbfcd1Sozaki-r	add_test default_gateway "Tests route flags: default gateway"
348bdcbfcd1Sozaki-r	add_test static          "Tests route flags: static route"
349bdcbfcd1Sozaki-r	add_test blackhole       "Tests route flags: blackhole route"
350bdcbfcd1Sozaki-r	add_test reject          "Tests route flags: reject route"
351bdcbfcd1Sozaki-r	add_test icmp_redirect   "Tests route flags: icmp redirect"
352bdcbfcd1Sozaki-r	add_test announce        "Tests route flags: announce flag"
353da803ed7Sozaki-r	add_test llinfo          "Tests route flags: ARP caches"
3542754f594Sozaki-r}
355