t_ipsec_gif.sh revision 1.1 1 1.1 ozaki # $NetBSD: t_ipsec_gif.sh,v 1.1 2017/04/27 06:52:45 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_gif_local
29 1.1 ozaki SOCK_TUN_LOCAL=unix://ipsec_gif_tunel_local
30 1.1 ozaki SOCK_TUN_REMOTE=unix://ipsec_gif_tunnel_remote
31 1.1 ozaki SOCK_REMOTE=unix://ipsec_gif_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_gif_pktstr()
39 1.1 ozaki {
40 1.1 ozaki local src=$1
41 1.1 ozaki local dst=$2
42 1.1 ozaki local src_inner=$3
43 1.1 ozaki local dst_inner=$4
44 1.1 ozaki local proto=$5
45 1.1 ozaki local ipproto=$6
46 1.1 ozaki local proto_cap= inner_str=
47 1.1 ozaki
48 1.1 ozaki if [ $proto = esp ]; then
49 1.1 ozaki proto_cap=ESP
50 1.1 ozaki else
51 1.1 ozaki proto_cap=AH
52 1.1 ozaki if [ $ipproto = ipv4 ]; then
53 1.1 ozaki inner_str="$src_inner > $dst_inner:.+\(ipip-proto-4\)"
54 1.1 ozaki else
55 1.1 ozaki inner_str="$src_inner > $dst_inner"
56 1.1 ozaki fi
57 1.1 ozaki fi
58 1.1 ozaki
59 1.1 ozaki echo "$src > $dst: $proto_cap.+$inner_str"
60 1.1 ozaki }
61 1.1 ozaki
62 1.1 ozaki test_ipsec4_gif()
63 1.1 ozaki {
64 1.1 ozaki local proto=$1
65 1.1 ozaki local algo=$2
66 1.1 ozaki local ip_local=10.0.1.2
67 1.1 ozaki local ip_gw_local=10.0.1.1
68 1.1 ozaki local ip_gw_local_tun=20.0.0.1
69 1.1 ozaki local ip_gw_local_gif=20.1.0.1
70 1.1 ozaki local ip_gw_remote_gif=20.1.0.2
71 1.1 ozaki local ip_gw_remote_tun=20.0.0.2
72 1.1 ozaki local ip_gw_remote=10.0.2.1
73 1.1 ozaki local ip_remote=10.0.2.2
74 1.1 ozaki local subnet_local=10.0.1.0
75 1.1 ozaki local subnet_remote=10.0.2.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 rump_server_crypto_start $SOCK_LOCAL
89 1.1 ozaki rump_server_crypto_start $SOCK_TUN_LOCAL netipsec gif
90 1.1 ozaki rump_server_crypto_start $SOCK_TUN_REMOTE netipsec gif
91 1.1 ozaki rump_server_crypto_start $SOCK_REMOTE
92 1.1 ozaki rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_LOCAL
93 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif0 $BUS_LOCAL
94 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif1 $BUS_TUNNEL
95 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif0 $BUS_REMOTE
96 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif1 $BUS_TUNNEL
97 1.1 ozaki rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_REMOTE
98 1.1 ozaki
99 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
100 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 $ip_local/24
101 1.1 ozaki atf_check -s exit:0 -o ignore \
102 1.1 ozaki rump.route -n add -net $subnet_remote $ip_gw_local
103 1.1 ozaki
104 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
105 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 $ip_gw_local/24
106 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif1 $ip_gw_local_tun/24
107 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 create
108 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
109 1.1 ozaki tunnel $ip_gw_local_tun $ip_gw_remote_tun
110 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
111 1.1 ozaki inet $ip_gw_local_gif/32 $ip_gw_remote_gif
112 1.1 ozaki atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=1
113 1.1 ozaki atf_check -s exit:0 -o ignore \
114 1.1 ozaki rump.route -n add -net $subnet_remote $ip_gw_remote_gif
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 $ip_gw_remote/24
118 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif1 $ip_gw_remote_tun/24
119 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 create
120 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
121 1.1 ozaki tunnel $ip_gw_remote_tun $ip_gw_local_tun
122 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
123 1.1 ozaki inet $ip_gw_remote_gif/32 $ip_gw_local_gif
124 1.1 ozaki atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=1
125 1.1 ozaki atf_check -s exit:0 -o ignore \
126 1.1 ozaki rump.route -n add -net $subnet_local $ip_gw_local_gif
127 1.1 ozaki
128 1.1 ozaki export RUMP_SERVER=$SOCK_REMOTE
129 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 $ip_remote/24
130 1.1 ozaki # Run ifconfig -w 10 just once for optimization
131 1.1 ozaki atf_check -s exit:0 rump.ifconfig -w 10
132 1.1 ozaki atf_check -s exit:0 -o ignore \
133 1.1 ozaki rump.route -n add -net $subnet_local $ip_gw_remote
134 1.1 ozaki
135 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
136 1.1 ozaki
137 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
138 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping -c 1 -n -w 3 $ip_remote
139 1.1 ozaki
140 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
141 1.1 ozaki str="$ip_gw_local_tun > $ip_gw_remote_tun:"
142 1.1 ozaki str="$str $ip_local > $ip_remote: ICMP echo request,"
143 1.1 ozaki str="$str .+ \(ipip-proto-4\)"
144 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
145 1.1 ozaki str="$ip_gw_remote_tun > $ip_gw_local_tun:"
146 1.1 ozaki str="$str $ip_remote > $ip_local: ICMP echo reply,"
147 1.1 ozaki str="$str .+ \(ipip-proto-4\)"
148 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
149 1.1 ozaki
150 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
151 1.1 ozaki # from https://www.netbsd.org/docs/network/ipsec/
152 1.1 ozaki cat > $tmpfile <<-EOF
153 1.1 ozaki add $ip_gw_local_tun $ip_gw_remote_tun $proto 10000 $opt $algo $key;
154 1.1 ozaki add $ip_gw_remote_tun $ip_gw_local_tun $proto 10001 $opt $algo $key;
155 1.1 ozaki spdadd $subnet_local/24 $subnet_remote/24 any -P out ipsec
156 1.1 ozaki $proto/tunnel/$ip_gw_local_tun-$ip_gw_remote_tun/require;
157 1.1 ozaki spdadd $subnet_remote/24 $subnet_local/24 any -P in ipsec
158 1.1 ozaki $proto/tunnel/$ip_gw_remote_tun-$ip_gw_local_tun/require;
159 1.1 ozaki EOF
160 1.1 ozaki $DEBUG && cat $tmpfile
161 1.1 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
162 1.1 ozaki $DEBUG && $HIJACKING setkey -D
163 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_local_tun $ip_gw_remote_tun" \
164 1.1 ozaki $HIJACKING setkey -D
165 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_remote_tun $ip_gw_local_tun" \
166 1.1 ozaki $HIJACKING setkey -D
167 1.1 ozaki # TODO: more detail checks
168 1.1 ozaki
169 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
170 1.1 ozaki cat > $tmpfile <<-EOF
171 1.1 ozaki add $ip_gw_local_tun $ip_gw_remote_tun $proto 10000 $opt $algo $key;
172 1.1 ozaki add $ip_gw_remote_tun $ip_gw_local_tun $proto 10001 $opt $algo $key;
173 1.1 ozaki spdadd $subnet_remote/24 $subnet_local/24 any -P out ipsec
174 1.1 ozaki $proto/tunnel/$ip_gw_remote_tun-$ip_gw_local_tun/require;
175 1.1 ozaki spdadd $subnet_local/24 $subnet_remote/24 any -P in ipsec
176 1.1 ozaki $proto/tunnel/$ip_gw_local_tun-$ip_gw_remote_tun/require;
177 1.1 ozaki EOF
178 1.1 ozaki $DEBUG && cat $tmpfile
179 1.1 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
180 1.1 ozaki $DEBUG && $HIJACKING setkey -D
181 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_local_tun $ip_gw_remote_tun" \
182 1.1 ozaki $HIJACKING setkey -D
183 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_remote_tun $ip_gw_local_tun" \
184 1.1 ozaki $HIJACKING setkey -D
185 1.1 ozaki # TODO: more detail checks
186 1.1 ozaki
187 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
188 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping -c 1 -n -w 3 $ip_remote
189 1.1 ozaki
190 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
191 1.1 ozaki str=$(make_gif_pktstr $ip_gw_local_tun $ip_gw_remote_tun \
192 1.1 ozaki $ip_local $ip_remote $proto ipv4)
193 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
194 1.1 ozaki str=$(make_gif_pktstr $ip_gw_remote_tun $ip_gw_local_tun \
195 1.1 ozaki $ip_remote $ip_local $proto ipv4)
196 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
197 1.1 ozaki }
198 1.1 ozaki
199 1.1 ozaki test_ipsec6_gif()
200 1.1 ozaki {
201 1.1 ozaki local proto=$1
202 1.1 ozaki local algo=$2
203 1.1 ozaki local ip_local=fd00:1::2
204 1.1 ozaki local ip_gw_local=fd00:1::1
205 1.1 ozaki local ip_gw_local_tun=fc00::1
206 1.1 ozaki local ip_gw_local_gif=fc01::1
207 1.1 ozaki local ip_gw_remote_gif=fc01::2
208 1.1 ozaki local ip_gw_remote_tun=fc00::2
209 1.1 ozaki local ip_gw_remote=fd00:2::1
210 1.1 ozaki local ip_remote=fd00:2::2
211 1.1 ozaki local subnet_local=fd00:1::
212 1.1 ozaki local subnet_remote=fd00:2::
213 1.1 ozaki local keylen=$(get_one_valid_keylen $algo)
214 1.1 ozaki local key=$(generate_key $keylen)
215 1.1 ozaki local tmpfile=./tmp
216 1.1 ozaki local outfile=./out
217 1.1 ozaki local opt= str=
218 1.1 ozaki
219 1.1 ozaki if [ $proto = esp ]; then
220 1.1 ozaki opt=-E
221 1.1 ozaki else
222 1.1 ozaki opt=-A
223 1.1 ozaki fi
224 1.1 ozaki
225 1.1 ozaki rump_server_crypto_start $SOCK_LOCAL netinet6
226 1.1 ozaki rump_server_crypto_start $SOCK_TUN_LOCAL netipsec netinet6 gif
227 1.1 ozaki rump_server_crypto_start $SOCK_TUN_REMOTE netipsec netinet6 gif
228 1.1 ozaki rump_server_crypto_start $SOCK_REMOTE netinet6
229 1.1 ozaki rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_LOCAL
230 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif0 $BUS_LOCAL
231 1.1 ozaki rump_server_add_iface $SOCK_TUN_LOCAL shmif1 $BUS_TUNNEL
232 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif0 $BUS_REMOTE
233 1.1 ozaki rump_server_add_iface $SOCK_TUN_REMOTE shmif1 $BUS_TUNNEL
234 1.1 ozaki rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_REMOTE
235 1.1 ozaki
236 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
237 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_local/64
238 1.1 ozaki atf_check -s exit:0 -o ignore \
239 1.1 ozaki rump.route -n add -inet6 -net $subnet_remote/64 $ip_gw_local
240 1.1 ozaki
241 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
242 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_gw_local/64
243 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif1 inet6 $ip_gw_local_tun/64
244 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 create
245 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
246 1.1 ozaki tunnel $ip_gw_local_tun $ip_gw_remote_tun
247 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
248 1.1 ozaki inet6 $ip_gw_local_gif/128 $ip_gw_remote_gif
249 1.1 ozaki atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=1
250 1.1 ozaki atf_check -s exit:0 -o ignore \
251 1.1 ozaki rump.route -n add -inet6 -net $subnet_remote/64 $ip_gw_local_gif
252 1.1 ozaki
253 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
254 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_gw_remote/64
255 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif1 inet6 $ip_gw_remote_tun/64
256 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 create
257 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
258 1.1 ozaki tunnel $ip_gw_remote_tun $ip_gw_local_tun
259 1.1 ozaki atf_check -s exit:0 rump.ifconfig gif0 \
260 1.1 ozaki inet6 $ip_gw_remote_gif/128 $ip_gw_local_gif
261 1.1 ozaki atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=1
262 1.1 ozaki atf_check -s exit:0 -o ignore \
263 1.1 ozaki rump.route -n add -inet6 -net $subnet_local/64 $ip_gw_remote_gif
264 1.1 ozaki
265 1.1 ozaki export RUMP_SERVER=$SOCK_REMOTE
266 1.1 ozaki atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_remote
267 1.1 ozaki # Run ifconfig -w 10 just once for optimization
268 1.1 ozaki atf_check -s exit:0 rump.ifconfig -w 10
269 1.1 ozaki atf_check -s exit:0 -o ignore \
270 1.1 ozaki rump.route -n add -inet6 -net $subnet_local/64 $ip_gw_remote
271 1.1 ozaki
272 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
273 1.1 ozaki
274 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
275 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n -X 3 $ip_remote
276 1.1 ozaki
277 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
278 1.1 ozaki str="$ip_gw_local_tun > $ip_gw_remote_tun:"
279 1.1 ozaki str="$str $ip_local > $ip_remote: ICMP6, echo request"
280 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
281 1.1 ozaki str="$ip_gw_remote_tun > $ip_gw_local_tun:"
282 1.1 ozaki str="$str $ip_remote > $ip_local: ICMP6, echo reply,"
283 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
284 1.1 ozaki
285 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_LOCAL
286 1.1 ozaki # from https://www.netbsd.org/docs/network/ipsec/
287 1.1 ozaki cat > $tmpfile <<-EOF
288 1.1 ozaki add $ip_gw_local_tun $ip_gw_remote_tun $proto 10000 $opt $algo $key;
289 1.1 ozaki add $ip_gw_remote_tun $ip_gw_local_tun $proto 10001 $opt $algo $key;
290 1.1 ozaki spdadd $subnet_local/64 $subnet_remote/64 any -P out ipsec
291 1.1 ozaki $proto/tunnel/$ip_gw_local_tun-$ip_gw_remote_tun/require;
292 1.1 ozaki spdadd $subnet_remote/64 $subnet_local/64 any -P in ipsec
293 1.1 ozaki $proto/tunnel/$ip_gw_remote_tun-$ip_gw_local_tun/require;
294 1.1 ozaki EOF
295 1.1 ozaki $DEBUG && cat $tmpfile
296 1.1 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
297 1.1 ozaki $DEBUG && $HIJACKING setkey -D
298 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_local_tun $ip_gw_remote_tun" \
299 1.1 ozaki $HIJACKING setkey -D
300 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_remote_tun $ip_gw_local_tun" \
301 1.1 ozaki $HIJACKING setkey -D
302 1.1 ozaki # TODO: more detail checks
303 1.1 ozaki
304 1.1 ozaki export RUMP_SERVER=$SOCK_TUN_REMOTE
305 1.1 ozaki cat > $tmpfile <<-EOF
306 1.1 ozaki add $ip_gw_local_tun $ip_gw_remote_tun $proto 10000 $opt $algo $key;
307 1.1 ozaki add $ip_gw_remote_tun $ip_gw_local_tun $proto 10001 $opt $algo $key;
308 1.1 ozaki spdadd $subnet_remote/64 $subnet_local/64 any -P out ipsec
309 1.1 ozaki $proto/tunnel/$ip_gw_remote_tun-$ip_gw_local_tun/require;
310 1.1 ozaki spdadd $subnet_local/64 $subnet_remote/64 any -P in ipsec
311 1.1 ozaki $proto/tunnel/$ip_gw_local_tun-$ip_gw_remote_tun/require;
312 1.1 ozaki EOF
313 1.1 ozaki $DEBUG && cat $tmpfile
314 1.1 ozaki atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
315 1.1 ozaki $DEBUG && $HIJACKING setkey -D
316 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_local_tun $ip_gw_remote_tun" \
317 1.1 ozaki $HIJACKING setkey -D
318 1.1 ozaki atf_check -s exit:0 -o match:"$ip_gw_remote_tun $ip_gw_local_tun" \
319 1.1 ozaki $HIJACKING setkey -D
320 1.1 ozaki # TODO: more detail checks
321 1.1 ozaki
322 1.1 ozaki export RUMP_SERVER=$SOCK_LOCAL
323 1.1 ozaki atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n -X 3 $ip_remote
324 1.1 ozaki
325 1.1 ozaki extract_new_packets $BUS_TUNNEL > $outfile
326 1.1 ozaki str=$(make_gif_pktstr $ip_gw_local_tun $ip_gw_remote_tun \
327 1.1 ozaki $ip_local $ip_remote $proto ipv6)
328 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
329 1.1 ozaki str=$(make_gif_pktstr $ip_gw_remote_tun $ip_gw_local_tun \
330 1.1 ozaki $ip_remote $ip_local $proto ipv6)
331 1.1 ozaki atf_check -s exit:0 -o match:"$str" cat $outfile
332 1.1 ozaki }
333 1.1 ozaki
334 1.1 ozaki test_ipsec_gif_common()
335 1.1 ozaki {
336 1.1 ozaki local ipproto=$1
337 1.1 ozaki local proto=$2
338 1.1 ozaki local algo=$3
339 1.1 ozaki
340 1.1 ozaki if [ $ipproto = ipv4 ]; then
341 1.1 ozaki test_ipsec4_gif $proto $algo
342 1.1 ozaki else
343 1.1 ozaki test_ipsec6_gif $proto $algo
344 1.1 ozaki fi
345 1.1 ozaki }
346 1.1 ozaki
347 1.1 ozaki add_test_ipsec_gif()
348 1.1 ozaki {
349 1.1 ozaki local ipproto=$1
350 1.1 ozaki local proto=$2
351 1.1 ozaki local algo=$3
352 1.1 ozaki local _algo=$(echo $algo | sed 's/-//g')
353 1.1 ozaki local name= desc=
354 1.1 ozaki
355 1.1 ozaki name="ipsec_gif_${ipproto}_${proto}_${_algo}"
356 1.1 ozaki desc="Tests of IPsec ($ipproto) tunnel mode (gif) with $proto ($algo)"
357 1.1 ozaki
358 1.1 ozaki atf_test_case ${name} cleanup
359 1.1 ozaki eval " \
360 1.1 ozaki ${name}_head() { \
361 1.1 ozaki atf_set \"descr\" \"$desc\"; \
362 1.1 ozaki atf_set \"require.progs\" \"rump_server\" \"setkey\"; \
363 1.1 ozaki }; \
364 1.1 ozaki ${name}_body() { \
365 1.1 ozaki test_ipsec_gif_common $ipproto $proto $algo; \
366 1.1 ozaki rump_server_destroy_ifaces; \
367 1.1 ozaki }; \
368 1.1 ozaki ${name}_cleanup() { \
369 1.1 ozaki $DEBUG && dump; \
370 1.1 ozaki cleanup; \
371 1.1 ozaki } \
372 1.1 ozaki "
373 1.1 ozaki atf_add_test_case ${name}
374 1.1 ozaki }
375 1.1 ozaki
376 1.1 ozaki atf_init_test_cases()
377 1.1 ozaki {
378 1.1 ozaki local algo=
379 1.1 ozaki
380 1.1 ozaki for algo in $ESP_ENCRYPTION_ALGORITHMS_MINIMUM; do
381 1.1 ozaki add_test_ipsec_gif ipv4 esp $algo
382 1.1 ozaki add_test_ipsec_gif ipv6 esp $algo
383 1.1 ozaki done
384 1.1 ozaki
385 1.1 ozaki for algo in $AH_AUTHENTICATION_ALGORITHMS_MINIMUM; do
386 1.1 ozaki add_test_ipsec_gif ipv4 ah $algo
387 1.1 ozaki add_test_ipsec_gif ipv6 ah $algo
388 1.1 ozaki done
389 1.1 ozaki }
390