1 # $NetBSD: t_icmp6_redirect.sh,v 1.7 2016/11/25 08:51:16 ozaki-r Exp $
3 # Copyright (c) 2015 Internet Initiative Japan 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 SOCK_LOCAL=unix://commsock1
29 SOCK_PEER=unix://commsock2
30 SOCK_GW1=unix://commsock3
31 SOCK_GW2=unix://commsock4
37 IP6IF0_LOCAL=fc00:1::2
47 atf_test_case icmp6_redirect_basic cleanup
49 icmp6_redirect_basic_head()
52 atf_set "descr" "Test for the basically function of the ICMP6 redirect"
53 atf_set "require.progs" "rump_server rump.route rump.ping rump.ifconfig"
56 icmp6_redirect_basic_body()
62 rump_server_start $SOCK_LOCAL netinet6
63 rump_server_start $SOCK_PEER netinet6
64 rump_server_start $SOCK_GW1 netinet6
65 rump_server_start $SOCK_GW2 netinet6
70 # Setup gateway #1 (real gateway)
71 export RUMP_SERVER=${SOCK_GW1}
72 rump_server_add_iface $SOCK_GW1 shmif0 $BUS1
73 rump_server_add_iface $SOCK_GW1 shmif1 $BUS2
75 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW1}
76 atf_check -s exit:0 rump.ifconfig shmif0 up
77 atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6IF1_GW1}
78 atf_check -s exit:0 rump.ifconfig shmif1 up
80 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \
81 net.inet6.ip6.forwarding=1
84 gw1_lladdr0=`get_linklocal_addr ${SOCK_GW1} shmif0`
85 gw1_lladdr1=`get_linklocal_addr ${SOCK_GW1} shmif1`
87 # Setup a peer behind gateway #1
88 export RUMP_SERVER=${SOCK_PEER}
89 rump_server_add_iface $SOCK_PEER shmif0 $BUS2
90 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_PEER}
91 atf_check -s exit:0 rump.ifconfig shmif0 up
92 atf_check -s exit:0 -o ignore rump.route add \
93 -inet6 default ${gw1_lladdr1}%shmif0
96 # Setup gateway #2 (fake gateway)
97 export RUMP_SERVER=${SOCK_GW2}
98 rump_server_add_iface $SOCK_GW2 shmif0 $BUS1
99 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_GW2}
100 atf_check -s exit:0 rump.ifconfig shmif0 up
102 atf_check -s exit:0 -o ignore rump.route add \
103 -inet6 ${IP6BUS2} ${gw1_lladdr0}%shmif0
104 atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \
105 net.inet6.ip6.forwarding=1
108 gw2_lladdr0=`get_linklocal_addr ${SOCK_GW2} shmif0`
110 export RUMP_SERVER=${SOCK_LOCAL}
111 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS1
112 atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6IF0_LOCAL}
113 atf_check -s exit:0 rump.ifconfig shmif0 up
115 # Teach the fake gateway as the default gateway
116 atf_check -s exit:0 -o ignore rump.route add \
117 -inet6 default ${gw2_lladdr0}%shmif0
118 $DEBUG && rump.route get -inet6 ${IP6IF0_PEER}
120 atf_check -s exit:0 -o ignore rump.sysctl -w \
121 net.inet6.icmp6.redirtimeout=$REDIRECT_TIMEOUT
126 atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n ${IP6IF0_PEER}
127 $DEBUG && rump.route show -inet6
128 # Check if a created route is correctly redirected to gateway #1
129 atf_check -s exit:0 -o match:"gateway: ${gw1_lladdr0}" rump.route get \
130 -inet6 ${IP6IF0_PEER}
132 atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2))
133 $DEBUG && rump.route show -inet6
134 # Check if the created route is expired
135 atf_check -s exit:0 -o not-match:"gateway: ${gw1_lladdr0}" rump.route get \
136 -inet6 ${IP6IF0_PEER}
138 rump_server_destroy_ifaces
141 icmp6_redirect_basic_cleanup()
148 atf_init_test_cases()
151 atf_add_test_case icmp6_redirect_basic