1 # $NetBSD: t_icmp_redirect.sh,v 1.3 2016/08/10 22:17:44 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 # Most codes are derived from tests/net/route/t_flags.sh
31 "rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
32 SOCK_LOCAL=unix://commsock1
33 SOCK_PEER=unix://commsock2
34 SOCK_GW=unix://commsock3
41 atf_test_case icmp_redirect_timeout cleanup
43 icmp_redirect_timeout_head()
46 atf_set "descr" "Tests for ICMP redirect timeout";
47 atf_set "require.progs" "rump_server";
53 atf_check -s exit:0 ${netserver} ${SOCK_LOCAL}
55 export RUMP_SERVER=$SOCK_LOCAL
56 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
57 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
58 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.2/24
59 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
61 atf_check -s exit:0 -o ignore rump.sysctl -w \
62 net.inet.icmp.redirtimeout=$REDIRECT_TIMEOUT
64 $DEBUG && rump.ifconfig
65 $DEBUG && rump.netstat -rn -f inet
71 atf_check -s exit:0 ${netserver} ${SOCK_PEER}
73 export RUMP_SERVER=$SOCK_PEER
74 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
75 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
76 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.1/24
77 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
79 $DEBUG && rump.ifconfig
80 $DEBUG && rump.netstat -rn -f inet
86 atf_check -s exit:0 ${netserver} ${SOCK_GW}
88 export RUMP_SERVER=$SOCK_GW
89 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
90 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
91 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 10.0.0.254/24
92 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
94 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 create
95 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 linkstr ${BUS2}
96 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 10.0.2.1/24
97 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 alias 10.0.2.2/24
98 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up
100 # Wait until DAD completes (10 sec at most)
101 atf_check -s exit:0 -o ignore rump.ifconfig -w 10
102 atf_check -s not-exit:0 -x "rump.ifconfig shmif1 |grep -q tentative"
104 $DEBUG && rump.ifconfig
105 $DEBUG && rump.netstat -rn -f inet
111 env RUMP_SERVER=$SOCK_GW rump.halt
116 local ip=$(echo $1 |sed 's/\./\\./g')
119 atf_check -s exit:0 -o match:" $flags " -e ignore -x \
120 "rump.netstat -rn -f inet | grep ^'$ip'"
125 local ip=$(echo $1 |sed 's/\./\\./g')
128 atf_check -s exit:0 -o match:" $gw " -e ignore -x \
129 "rump.netstat -rn -f inet | grep ^'$ip'"
134 local ip=$(echo $1 |sed 's/\./\\./g')
135 local flags=$2 # Not used currently
137 atf_check -s not-exit:0 -e ignore -x \
138 "rump.netstat -rn -f inet | grep ^'$ip'"
141 icmp_redirect_timeout_body()
144 $DEBUG && ulimit -c unlimited
149 ### Testing Dynamic flag ###
152 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
157 # Teach the peer that 10.0.2.* is behind 10.0.0.254
159 export RUMP_SERVER=$SOCK_PEER
160 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
161 # Up, Gateway, Static
162 check_entry_flags 10.0.2/24 UGS
165 # Setup the default gateway to the peer, 10.0.0.1
167 export RUMP_SERVER=$SOCK_LOCAL
168 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
169 # Up, Gateway, Static
170 check_entry_flags default UGS
173 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
174 $DEBUG && rump.netstat -rn -f inet
176 # Up, Gateway, Host, Dynamic
177 check_entry_flags 10.0.2.1 UGHD
178 check_entry_gw 10.0.2.1 10.0.0.254
180 atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2))
182 # The dynamic entry should be expired and removed
183 check_entry_fail 10.0.2.1
185 export RUMP_SERVER=$SOCK_PEER
186 $DEBUG && rump.netstat -rn -f inet
194 shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r -
195 gdb -ex bt /usr/bin/rump_server rump_server.core
201 env RUMP_SERVER=$SOCK_LOCAL rump.halt
202 env RUMP_SERVER=$SOCK_PEER rump.halt
205 icmp_redirect_timeout_cleanup()
212 atf_test_case icmp_redirect cleanup
217 atf_set "descr" "Tests for icmp redirect";
218 atf_set "require.progs" "rump_server";
223 atf_check -s exit:0 -o ignore rump.sysctl -w \
224 net.inet.ip.redirect=1
229 atf_check -s exit:0 -o ignore rump.sysctl -w \
230 net.inet.ip.redirect=0
236 $DEBUG && ulimit -c unlimited
242 # Setup a gateway 10.0.0.254. 10.0.2.1 is behind it.
247 # Teach the peer that 10.0.2.* is behind 10.0.0.254
249 export RUMP_SERVER=$SOCK_PEER
250 atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254
251 # Up, Gateway, Static
252 check_entry_flags 10.0.2/24 UGS
255 # Setup the default gateway to the peer, 10.0.0.1
257 export RUMP_SERVER=$SOCK_LOCAL
258 atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
259 # Up, Gateway, Static
260 check_entry_flags default UGS
263 ### ICMP redirects are NOT sent by the peer ###
266 # Disable net.inet.ip.redirect
268 export RUMP_SERVER=$SOCK_PEER
272 export RUMP_SERVER=$SOCK_LOCAL
273 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
274 $DEBUG && rump.netstat -rn -f inet
276 # A direct route shouldn't be created
277 check_entry_fail 10.0.2.1
280 ### ICMP redirects are sent by the peer ###
283 # Enable net.inet.ip.redirect
285 export RUMP_SERVER=$SOCK_PEER
289 export RUMP_SERVER=$SOCK_LOCAL
290 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
291 $DEBUG && rump.netstat -rn -f inet
293 # Up, Gateway, Host, Dynamic
294 check_entry_flags 10.0.2.1 UGHD
295 check_entry_gw 10.0.2.1 10.0.0.254
297 export RUMP_SERVER=$SOCK_PEER
298 $DEBUG && rump.netstat -rn -f inet
302 export RUMP_SERVER=$SOCK_LOCAL
303 atf_check -s exit:0 -o ignore rump.route delete 10.0.2.1
304 check_entry_fail 10.0.2.1
307 ### ICMP redirects are NOT sent by the peer (again) ###
310 # Disable net.inet.ip.redirect
312 export RUMP_SERVER=$SOCK_PEER
316 export RUMP_SERVER=$SOCK_LOCAL
317 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1
318 $DEBUG && rump.netstat -rn -f inet
320 # A direct route shouldn't be created
321 check_entry_fail 10.0.2.1
327 icmp_redirect_cleanup()
334 atf_init_test_cases()
337 atf_add_test_case icmp_redirect
338 atf_add_test_case icmp_redirect_timeout