t_ipsec_tunnel.sh revision 1.3.4.2 1 1.3.4.2 pgoyette # $NetBSD: t_ipsec_tunnel.sh,v 1.3.4.2 2017/04/26 02:53:34 pgoyette Exp $
2 1.3.4.2 pgoyette #
3 1.3.4.2 pgoyette # Copyright (c) 2017 Internet Initiative Japan Inc.
4 1.3.4.2 pgoyette # All rights reserved.
5 1.3.4.2 pgoyette #
6 1.3.4.2 pgoyette # Redistribution and use in source and binary forms, with or without
7 1.3.4.2 pgoyette # modification, are permitted provided that the following conditions
8 1.3.4.2 pgoyette # are met:
9 1.3.4.2 pgoyette # 1. Redistributions of source code must retain the above copyright
10 1.3.4.2 pgoyette # notice, this list of conditions and the following disclaimer.
11 1.3.4.2 pgoyette # 2. Redistributions in binary form must reproduce the above copyright
12 1.3.4.2 pgoyette # notice, this list of conditions and the following disclaimer in the
13 1.3.4.2 pgoyette # documentation and/or other materials provided with the distribution.
14 1.3.4.2 pgoyette #
15 1.3.4.2 pgoyette # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.3.4.2 pgoyette # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.3.4.2 pgoyette # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.3.4.2 pgoyette # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.3.4.2 pgoyette # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.3.4.2 pgoyette # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.3.4.2 pgoyette # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.3.4.2 pgoyette # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.3.4.2 pgoyette # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.3.4.2 pgoyette # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.3.4.2 pgoyette # POSSIBILITY OF SUCH DAMAGE.
26 1.3.4.2 pgoyette #
27 1.3.4.2 pgoyette
28 1.3.4.2 pgoyette SOCK_LOCAL=unix://ipsec_local
29 1.3.4.2 pgoyette SOCK_TUNNEL_LOCAL=unix://ipsec_tunel_local
30 1.3.4.2 pgoyette SOCK_TUNNEL_REMOTE=unix://ipsec_tunnel_remote
31 1.3.4.2 pgoyette SOCK_REMOTE=unix://ipsec_remote
32 1.3.4.2 pgoyette BUS_LOCAL=./bus_ipsec_local
33 1.3.4.2 pgoyette BUS_TUNNEL=./bus_ipsec_tunnel
34 1.3.4.2 pgoyette BUS_REMOTE=./bus_ipsec_remote
35 1.3.4.2 pgoyette
36 1.3.4.2 pgoyette DEBUG=${DEBUG:-false}
37 1.3.4.2 pgoyette
38 1.3.4.2 pgoyette test_ipsec4_tunnel()
39 1.3.4.2 pgoyette {
40 1.3.4.2 pgoyette local proto=$1
41 1.3.4.2 pgoyette local algo=$2
42 1.3.4.2 pgoyette local ip_local=10.0.1.2
43 1.3.4.2 pgoyette local ip_gw_local=10.0.1.1
44 1.3.4.2 pgoyette local ip_gw_local_tunnel=20.0.0.1
45 1.3.4.2 pgoyette local ip_gw_remote_tunnel=20.0.0.2
46 1.3.4.2 pgoyette local ip_gw_remote=10.0.2.1
47 1.3.4.2 pgoyette local ip_remote=10.0.2.2
48 1.3.4.2 pgoyette local subnet_local=10.0.1.0
49 1.3.4.2 pgoyette local subnet_remote=10.0.2.0
50 1.3.4.2 pgoyette local keylen=$(get_one_valid_keylen $algo)
51 1.3.4.2 pgoyette local key=$(generate_key $keylen)
52 1.3.4.2 pgoyette local tmpfile=./tmp
53 1.3.4.2 pgoyette local outfile=./out
54 1.3.4.2 pgoyette local opt= proto_cap=
55 1.3.4.2 pgoyette
56 1.3.4.2 pgoyette if [ $proto = esp ]; then
57 1.3.4.2 pgoyette opt=-E
58 1.3.4.2 pgoyette proto_cap=ESP
59 1.3.4.2 pgoyette else
60 1.3.4.2 pgoyette opt=-A
61 1.3.4.2 pgoyette proto_cap=AH
62 1.3.4.2 pgoyette fi
63 1.3.4.2 pgoyette
64 1.3.4.2 pgoyette # See https://www.netbsd.org/docs/network/ipsec/#sample_vpn
65 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_LOCAL
66 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_TUNNEL_LOCAL netipsec
67 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_TUNNEL_REMOTE netipsec
68 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_REMOTE
69 1.3.4.2 pgoyette rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_LOCAL
70 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_LOCAL shmif0 $BUS_LOCAL
71 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_LOCAL shmif1 $BUS_TUNNEL
72 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_REMOTE shmif0 $BUS_REMOTE
73 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_REMOTE shmif1 $BUS_TUNNEL
74 1.3.4.2 pgoyette rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_REMOTE
75 1.3.4.2 pgoyette
76 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_LOCAL
77 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 $ip_local/24
78 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
79 1.3.4.2 pgoyette rump.route -n add -net $subnet_remote $ip_gw_local
80 1.3.4.2 pgoyette
81 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_LOCAL
82 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 $ip_gw_local/24
83 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif1 $ip_gw_local_tunnel/24
84 1.3.4.2 pgoyette atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=1
85 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
86 1.3.4.2 pgoyette rump.route -n add -net $subnet_remote $ip_gw_remote_tunnel
87 1.3.4.2 pgoyette
88 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_REMOTE
89 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 $ip_gw_remote/24
90 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif1 $ip_gw_remote_tunnel/24
91 1.3.4.2 pgoyette atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=1
92 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
93 1.3.4.2 pgoyette rump.route -n add -net $subnet_local $ip_gw_local_tunnel
94 1.3.4.2 pgoyette
95 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_REMOTE
96 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 $ip_remote/24
97 1.3.4.2 pgoyette # Run ifconfig -w 10 just once for optimization
98 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig -w 10
99 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
100 1.3.4.2 pgoyette rump.route -n add -net $subnet_local $ip_gw_remote
101 1.3.4.2 pgoyette
102 1.3.4.2 pgoyette extract_new_packets $BUS_TUNNEL > $outfile
103 1.3.4.2 pgoyette
104 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_LOCAL
105 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore rump.ping -c 1 -n -w 3 $ip_remote
106 1.3.4.2 pgoyette
107 1.3.4.2 pgoyette extract_new_packets $BUS_TUNNEL > $outfile
108 1.3.4.2 pgoyette atf_check -s exit:0 \
109 1.3.4.2 pgoyette -o match:"$ip_local > $ip_remote: ICMP echo request" \
110 1.3.4.2 pgoyette cat $outfile
111 1.3.4.2 pgoyette atf_check -s exit:0 \
112 1.3.4.2 pgoyette -o match:"$ip_remote > $ip_local: ICMP echo reply" \
113 1.3.4.2 pgoyette cat $outfile
114 1.3.4.2 pgoyette
115 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_LOCAL
116 1.3.4.2 pgoyette # from https://www.netbsd.org/docs/network/ipsec/
117 1.3.4.2 pgoyette cat > $tmpfile <<-EOF
118 1.3.4.2 pgoyette add $ip_gw_local_tunnel $ip_gw_remote_tunnel $proto 10000 $opt $algo $key;
119 1.3.4.2 pgoyette add $ip_gw_remote_tunnel $ip_gw_local_tunnel $proto 10001 $opt $algo $key;
120 1.3.4.2 pgoyette spdadd $subnet_local/24 $subnet_remote/24 any -P out ipsec
121 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_local_tunnel-$ip_gw_remote_tunnel/require;
122 1.3.4.2 pgoyette spdadd $subnet_remote/24 $subnet_local/24 any -P in ipsec
123 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_remote_tunnel-$ip_gw_local_tunnel/require;
124 1.3.4.2 pgoyette EOF
125 1.3.4.2 pgoyette $DEBUG && cat $tmpfile
126 1.3.4.2 pgoyette atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
127 1.3.4.2 pgoyette $DEBUG && $HIJACKING setkey -D
128 1.3.4.2 pgoyette atf_check -s exit:0 \
129 1.3.4.2 pgoyette -o match:"$ip_gw_local_tunnel $ip_gw_remote_tunnel" \
130 1.3.4.2 pgoyette $HIJACKING setkey -D
131 1.3.4.2 pgoyette atf_check -s exit:0 \
132 1.3.4.2 pgoyette -o match:"$ip_gw_remote_tunnel $ip_gw_local_tunnel" \
133 1.3.4.2 pgoyette $HIJACKING setkey -D
134 1.3.4.2 pgoyette # TODO: more detail checks
135 1.3.4.2 pgoyette
136 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_REMOTE
137 1.3.4.2 pgoyette cat > $tmpfile <<-EOF
138 1.3.4.2 pgoyette add $ip_gw_local_tunnel $ip_gw_remote_tunnel $proto 10000 $opt $algo $key;
139 1.3.4.2 pgoyette add $ip_gw_remote_tunnel $ip_gw_local_tunnel $proto 10001 $opt $algo $key;
140 1.3.4.2 pgoyette spdadd $subnet_remote/24 $subnet_local/24 any -P out ipsec
141 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_remote_tunnel-$ip_gw_local_tunnel/require;
142 1.3.4.2 pgoyette spdadd $subnet_local/24 $subnet_remote/24 any -P in ipsec
143 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_local_tunnel-$ip_gw_remote_tunnel/require;
144 1.3.4.2 pgoyette EOF
145 1.3.4.2 pgoyette $DEBUG && cat $tmpfile
146 1.3.4.2 pgoyette atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
147 1.3.4.2 pgoyette $DEBUG && $HIJACKING setkey -D
148 1.3.4.2 pgoyette atf_check -s exit:0 \
149 1.3.4.2 pgoyette -o match:"$ip_gw_local_tunnel $ip_gw_remote_tunnel" \
150 1.3.4.2 pgoyette $HIJACKING setkey -D
151 1.3.4.2 pgoyette atf_check -s exit:0 \
152 1.3.4.2 pgoyette -o match:"$ip_gw_remote_tunnel $ip_gw_local_tunnel" \
153 1.3.4.2 pgoyette $HIJACKING setkey -D
154 1.3.4.2 pgoyette # TODO: more detail checks
155 1.3.4.2 pgoyette
156 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_LOCAL
157 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore rump.ping -c 1 -n -w 3 $ip_remote
158 1.3.4.2 pgoyette
159 1.3.4.2 pgoyette extract_new_packets $BUS_TUNNEL > $outfile
160 1.3.4.2 pgoyette atf_check -s exit:0 \
161 1.3.4.2 pgoyette -o match:"$ip_gw_local_tunnel > $ip_gw_remote_tunnel: $proto_cap" \
162 1.3.4.2 pgoyette cat $outfile
163 1.3.4.2 pgoyette atf_check -s exit:0 \
164 1.3.4.2 pgoyette -o match:"$ip_gw_remote_tunnel > $ip_gw_local_tunnel: $proto_cap" \
165 1.3.4.2 pgoyette cat $outfile
166 1.3.4.2 pgoyette }
167 1.3.4.2 pgoyette
168 1.3.4.2 pgoyette test_ipsec6_tunnel()
169 1.3.4.2 pgoyette {
170 1.3.4.2 pgoyette local proto=$1
171 1.3.4.2 pgoyette local algo=$2
172 1.3.4.2 pgoyette local ip_local=fd00:1::2
173 1.3.4.2 pgoyette local ip_gw_local=fd00:1::1
174 1.3.4.2 pgoyette local ip_gw_local_tunnel=fc00::1
175 1.3.4.2 pgoyette local ip_gw_remote_tunnel=fc00::2
176 1.3.4.2 pgoyette local ip_gw_remote=fd00:2::1
177 1.3.4.2 pgoyette local ip_remote=fd00:2::2
178 1.3.4.2 pgoyette local subnet_local=fd00:1::
179 1.3.4.2 pgoyette local subnet_remote=fd00:2::
180 1.3.4.2 pgoyette local keylen=$(get_one_valid_keylen $algo)
181 1.3.4.2 pgoyette local key=$(generate_key $keylen)
182 1.3.4.2 pgoyette local tmpfile=./tmp
183 1.3.4.2 pgoyette local outfile=./out
184 1.3.4.2 pgoyette local opt= proto_cap=
185 1.3.4.2 pgoyette
186 1.3.4.2 pgoyette if [ $proto = esp ]; then
187 1.3.4.2 pgoyette opt=-E
188 1.3.4.2 pgoyette proto_cap=ESP
189 1.3.4.2 pgoyette else
190 1.3.4.2 pgoyette opt=-A
191 1.3.4.2 pgoyette proto_cap=AH
192 1.3.4.2 pgoyette fi
193 1.3.4.2 pgoyette
194 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_LOCAL netinet6
195 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_TUNNEL_LOCAL netipsec netinet6
196 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_TUNNEL_REMOTE netipsec netinet6
197 1.3.4.2 pgoyette rump_server_crypto_start $SOCK_REMOTE netinet6
198 1.3.4.2 pgoyette rump_server_add_iface $SOCK_LOCAL shmif0 $BUS_LOCAL
199 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_LOCAL shmif0 $BUS_LOCAL
200 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_LOCAL shmif1 $BUS_TUNNEL
201 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_REMOTE shmif0 $BUS_REMOTE
202 1.3.4.2 pgoyette rump_server_add_iface $SOCK_TUNNEL_REMOTE shmif1 $BUS_TUNNEL
203 1.3.4.2 pgoyette rump_server_add_iface $SOCK_REMOTE shmif0 $BUS_REMOTE
204 1.3.4.2 pgoyette
205 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_LOCAL
206 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_local/64
207 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
208 1.3.4.2 pgoyette rump.route -n add -inet6 -net $subnet_remote/64 $ip_gw_local
209 1.3.4.2 pgoyette
210 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_LOCAL
211 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_gw_local/64
212 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif1 inet6 $ip_gw_local_tunnel/64
213 1.3.4.2 pgoyette atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=1
214 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
215 1.3.4.2 pgoyette rump.route -n add -inet6 -net $subnet_remote/64 $ip_gw_remote_tunnel
216 1.3.4.2 pgoyette
217 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_REMOTE
218 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_gw_remote/64
219 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif1 inet6 $ip_gw_remote_tunnel/64
220 1.3.4.2 pgoyette atf_check -s exit:0 rump.sysctl -q -w net.inet6.ip6.forwarding=1
221 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
222 1.3.4.2 pgoyette rump.route -n add -inet6 -net $subnet_local/64 $ip_gw_local_tunnel
223 1.3.4.2 pgoyette
224 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_REMOTE
225 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip_remote
226 1.3.4.2 pgoyette # Run ifconfig -w 10 just once for optimization
227 1.3.4.2 pgoyette atf_check -s exit:0 rump.ifconfig -w 10
228 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore \
229 1.3.4.2 pgoyette rump.route -n add -inet6 -net $subnet_local/64 $ip_gw_remote
230 1.3.4.2 pgoyette
231 1.3.4.2 pgoyette extract_new_packets $BUS_TUNNEL > $outfile
232 1.3.4.2 pgoyette
233 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_LOCAL
234 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n -X 3 $ip_remote
235 1.3.4.2 pgoyette
236 1.3.4.2 pgoyette extract_new_packets $BUS_TUNNEL > $outfile
237 1.3.4.2 pgoyette atf_check -s exit:0 \
238 1.3.4.2 pgoyette -o match:"$ip_local > $ip_remote: ICMP6, echo request" \
239 1.3.4.2 pgoyette cat $outfile
240 1.3.4.2 pgoyette atf_check -s exit:0 \
241 1.3.4.2 pgoyette -o match:"$ip_remote > $ip_local: ICMP6, echo reply" \
242 1.3.4.2 pgoyette cat $outfile
243 1.3.4.2 pgoyette
244 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_LOCAL
245 1.3.4.2 pgoyette # from https://www.netbsd.org/docs/network/ipsec/
246 1.3.4.2 pgoyette cat > $tmpfile <<-EOF
247 1.3.4.2 pgoyette add $ip_gw_local_tunnel $ip_gw_remote_tunnel $proto 10000 $opt $algo $key;
248 1.3.4.2 pgoyette add $ip_gw_remote_tunnel $ip_gw_local_tunnel $proto 10001 $opt $algo $key;
249 1.3.4.2 pgoyette spdadd $subnet_local/64 $subnet_remote/64 any -P out ipsec
250 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_local_tunnel-$ip_gw_remote_tunnel/require;
251 1.3.4.2 pgoyette spdadd $subnet_remote/64 $subnet_local/64 any -P in ipsec
252 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_remote_tunnel-$ip_gw_local_tunnel/require;
253 1.3.4.2 pgoyette EOF
254 1.3.4.2 pgoyette $DEBUG && cat $tmpfile
255 1.3.4.2 pgoyette atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
256 1.3.4.2 pgoyette $DEBUG && $HIJACKING setkey -D
257 1.3.4.2 pgoyette atf_check -s exit:0 \
258 1.3.4.2 pgoyette -o match:"$ip_gw_local_tunnel $ip_gw_remote_tunnel" \
259 1.3.4.2 pgoyette $HIJACKING setkey -D
260 1.3.4.2 pgoyette atf_check -s exit:0 \
261 1.3.4.2 pgoyette -o match:"$ip_gw_remote_tunnel $ip_gw_local_tunnel" \
262 1.3.4.2 pgoyette $HIJACKING setkey -D
263 1.3.4.2 pgoyette # TODO: more detail checks
264 1.3.4.2 pgoyette
265 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_TUNNEL_REMOTE
266 1.3.4.2 pgoyette cat > $tmpfile <<-EOF
267 1.3.4.2 pgoyette add $ip_gw_local_tunnel $ip_gw_remote_tunnel $proto 10000 $opt $algo $key;
268 1.3.4.2 pgoyette add $ip_gw_remote_tunnel $ip_gw_local_tunnel $proto 10001 $opt $algo $key;
269 1.3.4.2 pgoyette spdadd $subnet_remote/64 $subnet_local/64 any -P out ipsec
270 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_remote_tunnel-$ip_gw_local_tunnel/require;
271 1.3.4.2 pgoyette spdadd $subnet_local/64 $subnet_remote/64 any -P in ipsec
272 1.3.4.2 pgoyette $proto/tunnel/$ip_gw_local_tunnel-$ip_gw_remote_tunnel/require;
273 1.3.4.2 pgoyette EOF
274 1.3.4.2 pgoyette $DEBUG && cat $tmpfile
275 1.3.4.2 pgoyette atf_check -s exit:0 -o empty $HIJACKING setkey -c < $tmpfile
276 1.3.4.2 pgoyette $DEBUG && $HIJACKING setkey -D
277 1.3.4.2 pgoyette atf_check -s exit:0 \
278 1.3.4.2 pgoyette -o match:"$ip_gw_local_tunnel $ip_gw_remote_tunnel" \
279 1.3.4.2 pgoyette $HIJACKING setkey -D
280 1.3.4.2 pgoyette atf_check -s exit:0 \
281 1.3.4.2 pgoyette -o match:"$ip_gw_remote_tunnel $ip_gw_local_tunnel" \
282 1.3.4.2 pgoyette $HIJACKING setkey -D
283 1.3.4.2 pgoyette # TODO: more detail checks
284 1.3.4.2 pgoyette
285 1.3.4.2 pgoyette export RUMP_SERVER=$SOCK_LOCAL
286 1.3.4.2 pgoyette atf_check -s exit:0 -o ignore rump.ping6 -c 1 -n -X 3 $ip_remote
287 1.3.4.2 pgoyette
288 1.3.4.2 pgoyette extract_new_packets $BUS_TUNNEL > $outfile
289 1.3.4.2 pgoyette atf_check -s exit:0 \
290 1.3.4.2 pgoyette -o match:"$ip_gw_local_tunnel > $ip_gw_remote_tunnel: $proto_cap" \
291 1.3.4.2 pgoyette cat $outfile
292 1.3.4.2 pgoyette atf_check -s exit:0 \
293 1.3.4.2 pgoyette -o match:"$ip_gw_remote_tunnel > $ip_gw_local_tunnel: $proto_cap" \
294 1.3.4.2 pgoyette cat $outfile
295 1.3.4.2 pgoyette }
296 1.3.4.2 pgoyette
297 1.3.4.2 pgoyette test_tunnel_common()
298 1.3.4.2 pgoyette {
299 1.3.4.2 pgoyette local ipproto=$1
300 1.3.4.2 pgoyette local proto=$2
301 1.3.4.2 pgoyette local algo=$3
302 1.3.4.2 pgoyette
303 1.3.4.2 pgoyette if [ $ipproto = ipv4 ]; then
304 1.3.4.2 pgoyette test_ipsec4_tunnel $proto $algo
305 1.3.4.2 pgoyette else
306 1.3.4.2 pgoyette test_ipsec6_tunnel $proto $algo
307 1.3.4.2 pgoyette fi
308 1.3.4.2 pgoyette }
309 1.3.4.2 pgoyette
310 1.3.4.2 pgoyette add_test_tunnel_mode()
311 1.3.4.2 pgoyette {
312 1.3.4.2 pgoyette local ipproto=$1
313 1.3.4.2 pgoyette local proto=$2
314 1.3.4.2 pgoyette local algo=$3
315 1.3.4.2 pgoyette local _algo=$(echo $algo | sed 's/-//g')
316 1.3.4.2 pgoyette local name= desc=
317 1.3.4.2 pgoyette
318 1.3.4.2 pgoyette name="ipsec_tunnel_${ipproto}_${proto}_${_algo}"
319 1.3.4.2 pgoyette desc="Tests of IPsec ($ipproto) tunnel mode with $proto ($algo)"
320 1.3.4.2 pgoyette
321 1.3.4.2 pgoyette atf_test_case ${name} cleanup
322 1.3.4.2 pgoyette eval " \
323 1.3.4.2 pgoyette ${name}_head() { \
324 1.3.4.2 pgoyette atf_set \"descr\" \"$desc\"; \
325 1.3.4.2 pgoyette atf_set \"require.progs\" \"rump_server\" \"setkey\"; \
326 1.3.4.2 pgoyette }; \
327 1.3.4.2 pgoyette ${name}_body() { \
328 1.3.4.2 pgoyette test_tunnel_common $ipproto $proto $algo; \
329 1.3.4.2 pgoyette rump_server_destroy_ifaces; \
330 1.3.4.2 pgoyette }; \
331 1.3.4.2 pgoyette ${name}_cleanup() { \
332 1.3.4.2 pgoyette $DEBUG && dump; \
333 1.3.4.2 pgoyette cleanup; \
334 1.3.4.2 pgoyette } \
335 1.3.4.2 pgoyette "
336 1.3.4.2 pgoyette atf_add_test_case ${name}
337 1.3.4.2 pgoyette }
338 1.3.4.2 pgoyette
339 1.3.4.2 pgoyette atf_init_test_cases()
340 1.3.4.2 pgoyette {
341 1.3.4.2 pgoyette local algo=
342 1.3.4.2 pgoyette
343 1.3.4.2 pgoyette for algo in $ESP_ENCRYPTION_ALGORITHMS; do
344 1.3.4.2 pgoyette add_test_tunnel_mode ipv4 esp $algo
345 1.3.4.2 pgoyette add_test_tunnel_mode ipv6 esp $algo
346 1.3.4.2 pgoyette done
347 1.3.4.2 pgoyette
348 1.3.4.2 pgoyette for algo in $AH_AUTHENTICATION_ALGORITHMS; do
349 1.3.4.2 pgoyette add_test_tunnel_mode ipv4 ah $algo
350 1.3.4.2 pgoyette add_test_tunnel_mode ipv6 ah $algo
351 1.3.4.2 pgoyette done
352 1.3.4.2 pgoyette }
353