1 # $NetBSD: t_icmp_redirect.sh,v 1.6 2016/11/25 08:51:16 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 # Most codes are derived from tests/net/route/t_flags.sh
30 SOCK_LOCAL=unix://commsock1
31 SOCK_PEER=unix://commsock2
32 SOCK_GW=unix://commsock3
39 atf_test_case icmp_redirect_timeout cleanup
41 icmp_redirect_timeout_head()
44 atf_set "descr" "Tests for ICMP redirect timeout";
45 atf_set "require.progs" "rump_server";
51 rump_server_start $SOCK_LOCAL
52 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
54 export RUMP_SERVER=$SOCK_LOCAL
55 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24
56 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
58 atf_check -s exit:0 -o ignore rump.sysctl -w \
59 net.inet.icmp.redirtimeout=$REDIRECT_TIMEOUT
61 $DEBUG && rump.ifconfig
62 $DEBUG && rump.netstat -rn -f inet
68 rump_server_start $SOCK_PEER
69 rump_server_add_iface $SOCK_PEER shmif0 $BUS
71 export RUMP_SERVER=$SOCK_PEER
72 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24
73 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
75 $DEBUG && rump.ifconfig
76 $DEBUG && rump.netstat -rn -f inet
82 rump_server_start $SOCK_GW
83 rump_server_add_iface $SOCK_GW shmif0 $BUS
84 rump_server_add_iface $SOCK_GW shmif1 $BUS2
86 export RUMP_SERVER=$SOCK_GW
87 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24
88 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
90 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24
91 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24
92 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up
94 # Wait until DAD completes (10 sec at most)
95 atf_check -s exit:0 -o ignore rump.ifconfig -w 10
96 atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative"
98 $DEBUG && rump.ifconfig
99 $DEBUG && rump.netstat -rn -f inet
102 icmp_redirect_timeout_body()
105 $DEBUG && ulimit -c unlimited
110 ### Testing Dynamic flag ###
113 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
118 # Teach the peer that 10.0.2.* is behind 10.0.0.254
120 export RUMP_SERVER=$SOCK_PEER
121 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
122 # Up, Gateway, Static
123 check_route_flags 10.0.2/24 UGS
126 # Setup the default gateway to the peer, 10.0.0.1
128 export RUMP_SERVER=$SOCK_LOCAL
129 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
130 # Up, Gateway, Static
131 check_route_flags default UGS
134 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
135 $DEBUG && rump.netstat -rn -f inet
137 # Up, Gateway, Host, Dynamic
138 check_route_flags 10.0.2.1 UGHD
139 check_route_gw 10.0.2.1 10.0.0.254
141 atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2))
143 # The dynamic entry should be expired and removed
144 check_route_no_entry 10.0.2.1
146 export RUMP_SERVER=$SOCK_PEER
147 $DEBUG && rump.netstat -rn -f inet
149 rump_server_destroy_ifaces
152 icmp_redirect_timeout_cleanup()
159 atf_test_case icmp_redirect cleanup
164 atf_set "descr" "Tests for icmp redirect";
165 atf_set "require.progs" "rump_server";
170 atf_check -s exit:0 -o ignore rump.sysctl -w \
171 net.inet.ip.redirect=1
176 atf_check -s exit:0 -o ignore rump.sysctl -w \
177 net.inet.ip.redirect=0
183 $DEBUG && ulimit -c unlimited
189 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
194 # Teach the peer that 10.0.2.* is behind 10.0.0.254
196 export RUMP_SERVER=$SOCK_PEER
197 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
198 # Up, Gateway, Static
199 check_route_flags 10.0.2/24 UGS
202 # Setup the default gateway to the peer, 10.0.0.1
204 export RUMP_SERVER=$SOCK_LOCAL
205 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
206 # Up, Gateway, Static
207 check_route_flags default UGS
210 ### ICMP redirects are NOT sent by the peer ###
213 # Disable net.inet.ip.redirect
215 export RUMP_SERVER=$SOCK_PEER
219 export RUMP_SERVER=$SOCK_LOCAL
220 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
221 $DEBUG && rump.netstat -rn -f inet
223 # A direct route shouldn't be created
224 check_route_no_entry 10.0.2.1
227 ### ICMP redirects are sent by the peer ###
230 # Enable net.inet.ip.redirect
232 export RUMP_SERVER=$SOCK_PEER
236 export RUMP_SERVER=$SOCK_LOCAL
237 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
238 $DEBUG && rump.netstat -rn -f inet
240 # Up, Gateway, Host, Dynamic
241 check_route_flags 10.0.2.1 UGHD
242 check_route_gw 10.0.2.1 10.0.0.254
244 export RUMP_SERVER=$SOCK_PEER
245 $DEBUG && rump.netstat -rn -f inet
249 export RUMP_SERVER=$SOCK_LOCAL
250 atf_check -s exit:0 -o ignore rump.route delete 10.0.2.1
251 check_route_no_entry 10.0.2.1
254 ### ICMP redirects are NOT sent by the peer (again) ###
257 # Disable net.inet.ip.redirect
259 export RUMP_SERVER=$SOCK_PEER
263 export RUMP_SERVER=$SOCK_LOCAL
264 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
265 $DEBUG && rump.netstat -rn -f inet
267 # A direct route shouldn't be created
268 check_route_no_entry 10.0.2.1
270 rump_server_destroy_ifaces
273 icmp_redirect_cleanup()
280 atf_init_test_cases()
283 atf_add_test_case icmp_redirect
284 atf_add_test_case icmp_redirect_timeout