t_ipsec_l2tp.sh revision 1.3 1 1.3 ozaki # $NetBSD: t_ipsec_l2tp.sh,v 1.3 2017/05/09 04:25:28 ozaki-r Exp $
2 1.1 ozaki #
3 1.1 ozaki # Copyright (c) 2017 Internet Initiative Japan Inc.
4 1.1 ozaki # All rights reserved.
5 1.1 ozaki #
6 1.1 ozaki # Redistribution and use in source and binary forms, with or without
7 1.1 ozaki # modification, are permitted provided that the following conditions
8 1.1 ozaki # are met:
9 1.1 ozaki # 1. Redistributions of source code must retain the above copyright
10 1.1 ozaki # notice, this list of conditions and the following disclaimer.
11 1.1 ozaki # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 ozaki # notice, this list of conditions and the following disclaimer in the
13 1.1 ozaki # documentation and/or other materials provided with the distribution.
14 1.1 ozaki #
15 1.1 ozaki # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 ozaki # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 ozaki # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 ozaki # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 ozaki # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 ozaki # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 ozaki # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 ozaki # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 ozaki # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 ozaki # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 ozaki # POSSIBILITY OF SUCH DAMAGE.
26 1.1 ozaki #
27 1.1 ozaki
28 1.1 ozaki SOCK_LOCAL=unix://ipsec_l2tp_local
29 1.1 ozaki SOCK_TUN_LOCAL=unix://ipsec_l2tp_tunel_local
30 1.1 ozaki SOCK_TUN_REMOTE=unix://ipsec_l2tp_tunnel_remote
31 1.1 ozaki SOCK_REMOTE=unix://ipsec_l2tp_remote
32 1.1 ozaki BUS_LOCAL=./bus_ipsec_local
33 1.1 ozaki BUS_TUNNEL=./bus_ipsec_tunnel
34 1.1 ozaki BUS_REMOTE=./bus_ipsec_remote
35 1.1 ozaki
36 1.1 ozaki DEBUG=${DEBUG:-false}
37 1.1 ozaki
38 1.1 ozaki make_l2tp_pktstr()
39 1.1 ozaki {
40 1.1 ozaki local src=$1
41 1.1 ozaki local dst=$2
42 1.1 ozaki local proto=$3
43 1.1 ozaki local ipproto=$4
44 1.2 ozaki local mode=$5
45 1.1 ozaki local proto_cap= proto_str=
46 1.1 ozaki
47 1.1 ozaki if [ $proto = esp ]; then
48 1.1 ozaki proto_cap=ESP
49 1.1 ozaki else
50 1.1 ozaki proto_cap=AH
51 1.1 ozaki if [ $ipproto = ipv4 ]; then
52 1.2 ozaki if [ $mode = tunnel ]; then
53 1.2 ozaki proto_str="ip-proto-115 102 \(ipip-proto-4\)"
54 1.2 ozaki else
55 1.2 ozaki proto_str="ip-proto-115 102"
56 1.2 ozaki fi
57 1.1 ozaki else
58 1.1 ozaki proto_str="ip-proto-115"
59 1.1 ozaki fi
60 1.1 ozaki fi
61 1.1 ozaki
62 1.1 ozaki echo "$src > $dst: $proto_cap.+$proto_str"
63 1.1 ozaki }
64 1.1 ozaki
65 1.1 ozaki test_ipsec4_l2tp()
66 1.1 ozaki {
67 1.2 ozaki local mode=$1
68 1.2 ozaki local proto=$2
69 1.2 ozaki local algo=$3
70 1.1 ozaki local ip_local=10.0.0.1
71 1.2 ozaki local ip_gwlo_tun=20.0.0.1
72 1.2 ozaki local ip_gwre_tun=20.0.0.2
73 1.1 ozaki local ip_remote=10.0.0.2
74 1.1 ozaki local subnet_local=20.0.0.0
75 1.1 ozaki local subnet_remote=20.0.0.0
76 1.1 ozaki local keylen=$(get_one_valid_keylen $algo)
77 1.1 ozaki local key=$(generate_key $keylen)
78 1.1 ozaki local tmpfile=./tmp
79 1.1 ozaki local outfile=./out
80 1.1 ozaki local opt= str=
81 1.1 ozaki
82 1.1 ozaki if [ $proto = esp ]; then
83 1.1 ozaki opt=-E
84 1.1 ozaki else
85 1.1 ozaki opt=-A
86 1.1 ozaki fi
87 1.1 ozaki
88 1.1 ozaki # See https://www.netbsd.org/docs/network/ipsec/#sample_vpn
89 1.1 ozaki rump_server_crypto_start $SOCK_LOCAL
90 1.1 ozaki rump_server_crypto_start $SOCK_TUN_LOCAL netipsec l2tp bridge
91 1.1 ozaki rump_server_crypto_start $SOCK_TUN_REMOTE netipsec l2tp bridge
92 1.1 ozaki rump_server_crypto_start $SOCK_REMOTE
93 1.1 ozaki rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_LOCAL
94 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif0 $BUS_LOCAL
95 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif1 $BUS_TUNNEL
96 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif0 $BUS_REMOTE
97 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif1 $BUS_TUNNEL
98 1.1 ozaki rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_REMOTE
99 1.1 ozaki
100 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
101 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 $ip_local/24
102 1.1 ozaki
103 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
104 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 up
105 1.2 ozaki atf_check -s exit:0 rump.ifconfig shmif1 $ip_gwlo_tun/24
106 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 create
107 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 \
108 1.2 ozaki tunnel $ip_gwlo_tun $ip_gwre_tun
109 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 session 1234 4321
110 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 up
111 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 create
112 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 up
113 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add l2tp0
114 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add shmif0
115 1.1 ozaki
116 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
117 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 up
118 1.2 ozaki atf_check -s exit:0 rump.ifconfig shmif1 $ip_gwre_tun/24
119 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 create
120 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 \
121 1.2 ozaki tunnel $ip_gwre_tun $ip_gwlo_tun
122 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 session 4321 1234
123 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 up
124 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 create
125 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 up
126 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add l2tp0
127 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add shmif0
128 1.1 ozaki
129 1.1 ozaki export RUMP_SERVER=$SOCK_REMOTE
130 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 $ip_remote/24
131 1.1 ozaki # Run ifconfig -w 10 just once for optimization
132 1.1 ozaki atf_check -s exit:0 rump.ifconfig -w 10
133 1.1 ozaki
134 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
135 1.1 ozaki
136 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
137 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping -c 1 -n -w 3 $ip_remote
138 1.1 ozaki
139 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
140 1.1 ozaki atf_check -s exit:0 \
141 1.2 ozaki -o match:"$ip_gwlo_tun > $ip_gwre_tun: +ip-proto-115" \
142 1.1 ozaki cat $outfile
143 1.1 ozaki atf_check -s exit:0 \
144 1.2 ozaki -o match:"$ip_gwre_tun > $ip_gwlo_tun: +ip-proto-115" \
145 1.1 ozaki cat $outfile
146 1.1 ozaki
147 1.2 ozaki if [ $mode = tunnel ]; then
148 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
149 1.2 ozaki # from https://www.netbsd.org/docs/network/ipsec/
150 1.2 ozaki cat > $tmpfile <<-EOF
151 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
152 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
153 1.2 ozaki spdadd $subnet_local/24 $subnet_remote/24 any -P out ipsec
154 1.2 ozaki $proto/tunnel/$ip_gwlo_tun-$ip_gwre_tun/require;
155 1.2 ozaki spdadd $subnet_remote/24 $subnet_local/24 any -P in ipsec
156 1.2 ozaki $proto/tunnel/$ip_gwre_tun-$ip_gwlo_tun/require;
157 1.2 ozaki EOF
158 1.2 ozaki $DEBUG && cat $tmpfile
159 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
160 1.2 ozaki
161 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
162 1.2 ozaki cat > $tmpfile <<-EOF
163 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
164 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
165 1.2 ozaki spdadd $subnet_remote/24 $subnet_local/24 any -P out ipsec
166 1.2 ozaki $proto/tunnel/$ip_gwre_tun-$ip_gwlo_tun/require;
167 1.2 ozaki spdadd $subnet_local/24 $subnet_remote/24 any -P in ipsec
168 1.2 ozaki $proto/tunnel/$ip_gwlo_tun-$ip_gwre_tun/require;
169 1.2 ozaki EOF
170 1.2 ozaki $DEBUG && cat $tmpfile
171 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
172 1.2 ozaki else # transport mode
173 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
174 1.2 ozaki # from https://www.netbsd.org/docs/network/ipsec/
175 1.2 ozaki cat > $tmpfile <<-EOF
176 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
177 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
178 1.2 ozaki spdadd $ip_gwlo_tun/32 $ip_gwre_tun/32 any -P out ipsec
179 1.2 ozaki $proto/transport//require;
180 1.2 ozaki spdadd $ip_gwre_tun/32 $ip_gwlo_tun/32 any -P in ipsec
181 1.2 ozaki $proto/transport//require;
182 1.2 ozaki EOF
183 1.2 ozaki $DEBUG && cat $tmpfile
184 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
185 1.2 ozaki
186 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
187 1.2 ozaki cat > $tmpfile <<-EOF
188 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
189 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
190 1.2 ozaki spdadd $ip_gwre_tun/32 $ip_gwlo_tun/32 any -P out ipsec
191 1.2 ozaki $proto/transport//require;
192 1.2 ozaki spdadd $ip_gwlo_tun/32 $ip_gwre_tun/32 any -P in ipsec
193 1.2 ozaki $proto/transport//require;
194 1.2 ozaki EOF
195 1.2 ozaki $DEBUG && cat $tmpfile
196 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
197 1.2 ozaki fi
198 1.2 ozaki
199 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
200 1.1 ozaki $DEBUG && $HIJACKING setkey -D
201 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwlo_tun $ip_gwre_tun" \
202 1.1 ozaki $HIJACKING setkey -D
203 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwre_tun $ip_gwlo_tun" \
204 1.1 ozaki $HIJACKING setkey -D
205 1.1 ozaki # TODO: more detail checks
206 1.1 ozaki
207 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
208 1.1 ozaki $DEBUG && $HIJACKING setkey -D
209 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwlo_tun $ip_gwre_tun" \
210 1.1 ozaki $HIJACKING setkey -D
211 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwre_tun $ip_gwlo_tun" \
212 1.1 ozaki $HIJACKING setkey -D
213 1.1 ozaki # TODO: more detail checks
214 1.1 ozaki
215 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
216 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping -c 1 -n -w 3 $ip_remote
217 1.1 ozaki
218 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
219 1.2 ozaki str=$(make_l2tp_pktstr $ip_gwlo_tun $ip_gwre_tun $proto ipv4 $mode)
220 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
221 1.2 ozaki str=$(make_l2tp_pktstr $ip_gwre_tun $ip_gwlo_tun $proto ipv4 $mode)
222 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
223 1.3 ozaki
224 1.3 ozaki test_flush_entries $SOCK_TUN_LOCAL
225 1.3 ozaki test_flush_entries $SOCK_TUN_REMOTE
226 1.1 ozaki }
227 1.1 ozaki
228 1.1 ozaki test_ipsec6_l2tp()
229 1.1 ozaki {
230 1.2 ozaki local mode=$1
231 1.2 ozaki local proto=$2
232 1.2 ozaki local algo=$3
233 1.1 ozaki local ip_local=fd00::1
234 1.2 ozaki local ip_gwlo_tun=fc00::1
235 1.2 ozaki local ip_gwre_tun=fc00::2
236 1.1 ozaki local ip_remote=fd00::2
237 1.1 ozaki local subnet_local=fc00::
238 1.1 ozaki local subnet_remote=fc00::
239 1.1 ozaki local keylen=$(get_one_valid_keylen $algo)
240 1.1 ozaki local key=$(generate_key $keylen)
241 1.1 ozaki local tmpfile=./tmp
242 1.1 ozaki local outfile=./out
243 1.1 ozaki local opt= str=
244 1.1 ozaki
245 1.1 ozaki if [ $proto = esp ]; then
246 1.1 ozaki opt=-E
247 1.1 ozaki else
248 1.1 ozaki opt=-A
249 1.1 ozaki fi
250 1.1 ozaki
251 1.1 ozaki rump_server_crypto_start $SOCK_LOCAL netinet6
252 1.1 ozaki rump_server_crypto_start $SOCK_TUN_LOCAL netipsec netinet6 l2tp bridge
253 1.1 ozaki rump_server_crypto_start $SOCK_TUN_REMOTE netipsec netinet6 l2tp bridge
254 1.1 ozaki rump_server_crypto_start $SOCK_REMOTE netinet6
255 1.1 ozaki rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_LOCAL
256 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif0 $BUS_LOCAL
257 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif1 $BUS_TUNNEL
258 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif0 $BUS_REMOTE
259 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif1 $BUS_TUNNEL
260 1.1 ozaki rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_REMOTE
261 1.1 ozaki
262 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
263 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_local/64
264 1.1 ozaki
265 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
266 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 up
267 1.2 ozaki atf_check -s exit:0 rump.ifconfig shmif1 inet6 $ip_gwlo_tun/64
268 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 create
269 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 \
270 1.2 ozaki tunnel $ip_gwlo_tun $ip_gwre_tun
271 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 session 1234 4321
272 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 up
273 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 create
274 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 up
275 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add l2tp0
276 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add shmif0
277 1.1 ozaki
278 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
279 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 up
280 1.2 ozaki atf_check -s exit:0 rump.ifconfig shmif1 inet6 $ip_gwre_tun/64
281 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 create
282 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 \
283 1.2 ozaki tunnel $ip_gwre_tun $ip_gwlo_tun
284 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 session 4321 1234
285 1.1 ozaki atf_check -s exit:0 rump.ifconfig l2tp0 up
286 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 create
287 1.1 ozaki atf_check -s exit:0 rump.ifconfig bridge0 up
288 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add l2tp0
289 1.1 ozaki atf_check -s exit:0 $HIJACKING brconfig bridge0 add shmif0
290 1.1 ozaki
291 1.1 ozaki export RUMP_SERVER=$SOCK_REMOTE
292 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_remote
293 1.1 ozaki # Run ifconfig -w 10 just once for optimization
294 1.1 ozaki atf_check -s exit:0 rump.ifconfig -w 10
295 1.1 ozaki
296 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
297 1.1 ozaki
298 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
299 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n -X 3 $ip_remote
300 1.1 ozaki
301 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
302 1.1 ozaki atf_check -s exit:0 \
303 1.2 ozaki -o match:"$ip_gwlo_tun > $ip_gwre_tun: +ip-proto-115" \
304 1.1 ozaki cat $outfile
305 1.1 ozaki atf_check -s exit:0 \
306 1.2 ozaki -o match:"$ip_gwre_tun > $ip_gwlo_tun: +ip-proto-115" \
307 1.1 ozaki cat $outfile
308 1.1 ozaki
309 1.2 ozaki if [ $mode = tunnel ]; then
310 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
311 1.2 ozaki # from https://www.netbsd.org/docs/network/ipsec/
312 1.2 ozaki cat > $tmpfile <<-EOF
313 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
314 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
315 1.2 ozaki spdadd $subnet_local/64 $subnet_remote/64 any -P out ipsec
316 1.2 ozaki $proto/tunnel/$ip_gwlo_tun-$ip_gwre_tun/require;
317 1.2 ozaki spdadd $subnet_remote/64 $subnet_local/64 any -P in ipsec
318 1.2 ozaki $proto/tunnel/$ip_gwre_tun-$ip_gwlo_tun/require;
319 1.2 ozaki EOF
320 1.2 ozaki $DEBUG && cat $tmpfile
321 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
322 1.2 ozaki $DEBUG && $HIJACKING setkey -D
323 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwlo_tun $ip_gwre_tun" \
324 1.2 ozaki $HIJACKING setkey -D
325 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwre_tun $ip_gwlo_tun" \
326 1.2 ozaki $HIJACKING setkey -D
327 1.2 ozaki # TODO: more detail checks
328 1.2 ozaki
329 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
330 1.2 ozaki cat > $tmpfile <<-EOF
331 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
332 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
333 1.2 ozaki spdadd $subnet_remote/64 $subnet_local/64 any -P out ipsec
334 1.2 ozaki $proto/tunnel/$ip_gwre_tun-$ip_gwlo_tun/require;
335 1.2 ozaki spdadd $subnet_local/64 $subnet_remote/64 any -P in ipsec
336 1.2 ozaki $proto/tunnel/$ip_gwlo_tun-$ip_gwre_tun/require;
337 1.2 ozaki EOF
338 1.2 ozaki $DEBUG && cat $tmpfile
339 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
340 1.2 ozaki $DEBUG && $HIJACKING setkey -D
341 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwlo_tun $ip_gwre_tun" \
342 1.2 ozaki $HIJACKING setkey -D
343 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwre_tun $ip_gwlo_tun" \
344 1.2 ozaki $HIJACKING setkey -D
345 1.2 ozaki # TODO: more detail checks
346 1.2 ozaki else # transport mode
347 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
348 1.2 ozaki # from https://www.netbsd.org/docs/network/ipsec/
349 1.2 ozaki cat > $tmpfile <<-EOF
350 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
351 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
352 1.2 ozaki spdadd $ip_gwlo_tun/128 $ip_gwre_tun/128 any -P out ipsec
353 1.2 ozaki $proto/transport//require;
354 1.2 ozaki spdadd $ip_gwre_tun/128 $ip_gwlo_tun/128 any -P in ipsec
355 1.2 ozaki $proto/transport//require;
356 1.2 ozaki EOF
357 1.2 ozaki $DEBUG && cat $tmpfile
358 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
359 1.2 ozaki $DEBUG && $HIJACKING setkey -D
360 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwlo_tun $ip_gwre_tun" \
361 1.2 ozaki $HIJACKING setkey -D
362 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwre_tun $ip_gwlo_tun" \
363 1.2 ozaki $HIJACKING setkey -D
364 1.2 ozaki # TODO: more detail checks
365 1.2 ozaki
366 1.2 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
367 1.2 ozaki cat > $tmpfile <<-EOF
368 1.2 ozaki add $ip_gwlo_tun $ip_gwre_tun $proto 10000 $opt $algo $key;
369 1.2 ozaki add $ip_gwre_tun $ip_gwlo_tun $proto 10001 $opt $algo $key;
370 1.2 ozaki spdadd $ip_gwre_tun/128 $ip_gwlo_tun/128 any -P out ipsec
371 1.2 ozaki $proto/transport//require;
372 1.2 ozaki spdadd $ip_gwlo_tun/128 $ip_gwre_tun/128 any -P in ipsec
373 1.2 ozaki $proto/transport//require;
374 1.2 ozaki EOF
375 1.2 ozaki $DEBUG && cat $tmpfile
376 1.2 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
377 1.2 ozaki $DEBUG && $HIJACKING setkey -D
378 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwlo_tun $ip_gwre_tun" \
379 1.2 ozaki $HIJACKING setkey -D
380 1.2 ozaki atf_check -s exit:0 -o match:"$ip_gwre_tun $ip_gwlo_tun" \
381 1.2 ozaki $HIJACKING setkey -D
382 1.2 ozaki # TODO: more detail checks
383 1.2 ozaki fi
384 1.1 ozaki
385 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
386 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n -X 3 $ip_remote
387 1.1 ozaki
388 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
389 1.2 ozaki str=$(make_l2tp_pktstr $ip_gwlo_tun $ip_gwre_tun $proto ipv6 $mode)
390 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
391 1.2 ozaki str=$(make_l2tp_pktstr $ip_gwre_tun $ip_gwlo_tun $proto ipv6 $mode)
392 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
393 1.3 ozaki
394 1.3 ozaki test_flush_entries $SOCK_TUN_LOCAL
395 1.3 ozaki test_flush_entries $SOCK_TUN_REMOTE
396 1.1 ozaki }
397 1.1 ozaki
398 1.1 ozaki test_ipsec_l2tp_common()
399 1.1 ozaki {
400 1.1 ozaki local ipproto=$1
401 1.2 ozaki local mode=$2
402 1.2 ozaki local proto=$3
403 1.2 ozaki local algo=$4
404 1.1 ozaki
405 1.1 ozaki if [ $ipproto = ipv4 ]; then
406 1.2 ozaki test_ipsec4_l2tp $mode $proto $algo
407 1.1 ozaki else
408 1.2 ozaki test_ipsec6_l2tp $mode $proto $algo
409 1.1 ozaki fi
410 1.1 ozaki }
411 1.1 ozaki
412 1.1 ozaki add_test_ipsec_l2tp()
413 1.1 ozaki {
414 1.1 ozaki local ipproto=$1
415 1.2 ozaki local mode=$2
416 1.2 ozaki local proto=$3
417 1.2 ozaki local algo=$4
418 1.1 ozaki local _algo=$(echo $algo | sed 's/-//g')
419 1.1 ozaki local name= desc=
420 1.1 ozaki
421 1.2 ozaki name="ipsec_l2tp_${ipproto}_${mode}_${proto}_${_algo}"
422 1.2 ozaki desc="Tests of l2tp/IPsec ($ipproto) ${mode} mode with $proto ($algo)"
423 1.1 ozaki
424 1.1 ozaki atf_test_case ${name} cleanup
425 1.1 ozaki eval " \
426 1.1 ozaki ${name}_head() { \
427 1.1 ozaki atf_set \"descr\" \"$desc\"; \
428 1.1 ozaki atf_set \"require.progs\" \"rump_server\" \"setkey\"; \
429 1.1 ozaki }; \
430 1.1 ozaki ${name}_body() { \
431 1.2 ozaki test_ipsec_l2tp_common $ipproto $mode $proto $algo; \
432 1.1 ozaki rump_server_destroy_ifaces; \
433 1.1 ozaki }; \
434 1.1 ozaki ${name}_cleanup() { \
435 1.1 ozaki $DEBUG && dump; \
436 1.1 ozaki cleanup; \
437 1.1 ozaki } \
438 1.1 ozaki "
439 1.1 ozaki atf_add_test_case ${name}
440 1.1 ozaki }
441 1.1 ozaki
442 1.1 ozaki atf_init_test_cases()
443 1.1 ozaki {
444 1.1 ozaki local algo=
445 1.1 ozaki
446 1.1 ozaki for algo in $ESP_ENCRYPTION_ALGORITHMS_MINIMUM; do
447 1.2 ozaki add_test_ipsec_l2tp ipv4 tunnel esp $algo
448 1.2 ozaki add_test_ipsec_l2tp ipv6 tunnel esp $algo
449 1.2 ozaki add_test_ipsec_l2tp ipv4 transport esp $algo
450 1.2 ozaki add_test_ipsec_l2tp ipv6 transport esp $algo
451 1.1 ozaki done
452 1.1 ozaki
453 1.1 ozaki for algo in $AH_AUTHENTICATION_ALGORITHMS_MINIMUM; do
454 1.2 ozaki add_test_ipsec_l2tp ipv4 tunnel ah $algo
455 1.2 ozaki add_test_ipsec_l2tp ipv6 tunnel ah $algo
456 1.2 ozaki add_test_ipsec_l2tp ipv4 transport ah $algo
457 1.2 ozaki add_test_ipsec_l2tp ipv6 transport ah $algo
458 1.1 ozaki done
459 1.1 ozaki }
460