]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/netbsd-tests/net/icmp/t_icmp6_redirect.sh
MFV r337216: 7263 deeply nested nvlist can overflow stack
[FreeBSD/FreeBSD.git] / contrib / netbsd-tests / net / icmp / t_icmp6_redirect.sh
1 #       $NetBSD: t_icmp6_redirect.sh,v 1.7 2016/11/25 08:51:16 ozaki-r Exp $
2 #
3 # Copyright (c) 2015 Internet Initiative Japan Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
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.
14 #
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.
26 #
27
28 SOCK_LOCAL=unix://commsock1
29 SOCK_PEER=unix://commsock2
30 SOCK_GW1=unix://commsock3
31 SOCK_GW2=unix://commsock4
32
33 BUS1=bus1
34 BUS2=bus2
35 IP6BUS1=fc00:1::/64
36 IP6BUS2=fc00:2::/64
37 IP6IF0_LOCAL=fc00:1::2
38 IP6IF0_PEER=fc00:2::2
39 IP6IF0_GW1=fc00:1::1
40 IP6IF1_GW1=fc00:2::1
41 IP6IF0_GW2=fc00:1::3
42
43 REDIRECT_TIMEOUT=5
44
45 DEBUG=${DEBUG:-true}
46
47 atf_test_case icmp6_redirect_basic cleanup
48
49 icmp6_redirect_basic_head()
50 {
51
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"
54 }
55
56 icmp6_redirect_basic_body()
57 {
58         local gw1_lladdr0=
59         local gw1_lladdr1=
60         local gw2_lladdr0=
61
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
66
67         #
68         # Setup
69         #
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
74
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
79
80         atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w \
81             net.inet6.ip6.forwarding=1
82         unset RUMP_SERVER
83
84         gw1_lladdr0=`get_linklocal_addr ${SOCK_GW1} shmif0`
85         gw1_lladdr1=`get_linklocal_addr ${SOCK_GW1} shmif1`
86
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
94         unset RUMP_SERVER
95
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
101
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
106         unset RUMP_SERVER
107
108         gw2_lladdr0=`get_linklocal_addr ${SOCK_GW2} shmif0`
109
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
114
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}
119
120         atf_check -s exit:0 -o ignore rump.sysctl -w \
121             net.inet6.icmp6.redirtimeout=$REDIRECT_TIMEOUT
122
123         #
124         # Tests
125         #
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}
131
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}
137
138         rump_server_destroy_ifaces
139 }
140
141 icmp6_redirect_basic_cleanup()
142 {
143
144         $DEBUG && dump
145         cleanup
146 }
147
148 atf_init_test_cases()
149 {
150
151         atf_add_test_case icmp6_redirect_basic
152 }