t_basic.sh revision 1.5 1 1.5 riastrad # $NetBSD: t_basic.sh,v 1.5 2024/10/08 02:28:43 riastradh Exp $
2 1.1 riastrad #
3 1.1 riastrad # Copyright (c) 2018 Ryota Ozaki <ozaki.ryota (at] gmail.com>
4 1.1 riastrad # All rights reserved.
5 1.1 riastrad #
6 1.1 riastrad # Redistribution and use in source and binary forms, with or without
7 1.1 riastrad # modification, are permitted provided that the following conditions
8 1.1 riastrad # are met:
9 1.1 riastrad # 1. Redistributions of source code must retain the above copyright
10 1.1 riastrad # notice, this list of conditions and the following disclaimer.
11 1.1 riastrad # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 riastrad # notice, this list of conditions and the following disclaimer in the
13 1.1 riastrad # documentation and/or other materials provided with the distribution.
14 1.1 riastrad #
15 1.1 riastrad # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 riastrad # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 riastrad # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 riastrad # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 riastrad # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 riastrad # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 riastrad # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 riastrad # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 riastrad # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 riastrad # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 riastrad # POSSIBILITY OF SUCH DAMAGE.
26 1.1 riastrad #
27 1.1 riastrad
28 1.1 riastrad BUS=bus
29 1.1 riastrad SOCK_LOCAL=unix://wg_local
30 1.1 riastrad SOCK_PEER=unix://wg_peer
31 1.1 riastrad SOCK_PEER2=unix://wg_peer2
32 1.1 riastrad
33 1.1 riastrad
34 1.1 riastrad check_ping_payload()
35 1.1 riastrad {
36 1.1 riastrad local proto=$1
37 1.1 riastrad local ip=$2
38 1.1 riastrad local ping= size=
39 1.1 riastrad
40 1.1 riastrad if [ $proto = inet ]; then
41 1.1 riastrad ping="atf_check -s exit:0 -o ignore rump.ping -n -c 1 -w 1"
42 1.1 riastrad else
43 1.1 riastrad ping="atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X 1"
44 1.1 riastrad fi
45 1.1 riastrad
46 1.1 riastrad for size in $(seq 1 100) $(seq 450 550) $(seq 1400 1500); do
47 1.1 riastrad $ping -s $size $ip
48 1.1 riastrad done
49 1.1 riastrad }
50 1.1 riastrad
51 1.5 riastrad check_badudp()
52 1.5 riastrad {
53 1.5 riastrad local proto=$1
54 1.5 riastrad local ip=$2
55 1.5 riastrad local port=51820 # XXX parametrize more clearly
56 1.5 riastrad
57 1.5 riastrad if [ $proto = inet ]; then
58 1.5 riastrad atf_check -o ignore -e ignore \
59 1.5 riastrad $HIJACKING nc -4uv -w1 $ip $port </dev/null
60 1.5 riastrad else
61 1.5 riastrad atf_check -o ignore -e ignore \
62 1.5 riastrad $HIJACKING nc -6uv -w1 $ip $port </dev/null
63 1.5 riastrad atf_expect_fail "PR kern/58688:" \
64 1.5 riastrad " userland panic of kernel via wg(4)"
65 1.5 riastrad fi
66 1.5 riastrad }
67 1.5 riastrad
68 1.1 riastrad test_common()
69 1.1 riastrad {
70 1.1 riastrad local type=$1
71 1.1 riastrad local outer_proto=$2
72 1.1 riastrad local inner_proto=$3
73 1.1 riastrad local ifconfig="atf_check -s exit:0 rump.ifconfig"
74 1.1 riastrad local port=51820
75 1.1 riastrad local ip_local= ip_peer=
76 1.1 riastrad local ip_wg_local= ip_wg_peer=
77 1.1 riastrad local outer_prefix= outer_prefixall=
78 1.1 riastrad local inner_prefix= inner_prefixall=
79 1.1 riastrad
80 1.1 riastrad if [ $outer_proto = inet ]; then
81 1.1 riastrad ip_local=192.168.1.1
82 1.1 riastrad ip_peer=192.168.1.2
83 1.1 riastrad outer_prefix=24
84 1.1 riastrad outer_prefixall=32
85 1.1 riastrad else
86 1.1 riastrad ip_local=fc00::1
87 1.1 riastrad ip_peer=fc00::2
88 1.1 riastrad outer_prefix=64
89 1.1 riastrad outer_prefixall=128
90 1.1 riastrad fi
91 1.1 riastrad
92 1.1 riastrad if [ $inner_proto = inet ]; then
93 1.1 riastrad ip_wg_local=10.0.0.1
94 1.1 riastrad ip_wg_peer=10.0.0.2
95 1.1 riastrad inner_prefix=24
96 1.1 riastrad inner_prefixall=32
97 1.1 riastrad else
98 1.1 riastrad ip_wg_local=fd00::1
99 1.1 riastrad ip_wg_peer=fd00::2
100 1.1 riastrad inner_prefix=64
101 1.1 riastrad inner_prefixall=128
102 1.1 riastrad fi
103 1.1 riastrad
104 1.1 riastrad setup_servers
105 1.1 riastrad
106 1.1 riastrad # It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
107 1.1 riastrad generate_keys
108 1.1 riastrad
109 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
110 1.1 riastrad setup_common shmif0 $outer_proto $ip_local $outer_prefix
111 1.1 riastrad setup_wg_common wg0 $inner_proto $ip_wg_local $inner_prefix $port "$key_priv_local"
112 1.2 roy add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/$inner_prefixall
113 1.4 simonb $ifconfig -w 10
114 1.1 riastrad
115 1.1 riastrad export RUMP_SERVER=$SOCK_PEER
116 1.1 riastrad setup_common shmif0 $outer_proto $ip_peer $outer_prefix
117 1.1 riastrad setup_wg_common wg0 $inner_proto $ip_wg_peer $inner_prefix $port "$key_priv_peer"
118 1.1 riastrad add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/$inner_prefixall
119 1.4 simonb $ifconfig -w 10
120 1.1 riastrad
121 1.1 riastrad if [ $type = basic ]; then
122 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
123 1.1 riastrad check_ping $inner_proto $ip_wg_peer
124 1.1 riastrad elif [ $type = payload ]; then
125 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
126 1.1 riastrad check_ping_payload $inner_proto $ip_wg_peer
127 1.5 riastrad elif [ $type = badudp ]; then
128 1.5 riastrad export RUMP_SERVER=$SOCK_LOCAL
129 1.5 riastrad check_badudp $outer_proto $ip_peer
130 1.1 riastrad fi
131 1.1 riastrad
132 1.1 riastrad destroy_wg_interfaces
133 1.1 riastrad }
134 1.1 riastrad
135 1.1 riastrad atf_test_case wg_create_destroy cleanup
136 1.1 riastrad wg_create_destroy_head()
137 1.1 riastrad {
138 1.1 riastrad
139 1.1 riastrad atf_set "descr" "tests to create/destroy wg(4) interfaces"
140 1.1 riastrad atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
141 1.1 riastrad }
142 1.1 riastrad
143 1.1 riastrad wg_create_destroy_body()
144 1.1 riastrad {
145 1.1 riastrad
146 1.1 riastrad rump_server_crypto_start $SOCK_LOCAL netinet6 wg
147 1.1 riastrad
148 1.1 riastrad test_create_destroy_common $SOCK_LOCAL wg0 true
149 1.1 riastrad }
150 1.1 riastrad
151 1.1 riastrad wg_create_destroy_cleanup()
152 1.1 riastrad {
153 1.1 riastrad
154 1.1 riastrad $DEBUG && dump
155 1.1 riastrad cleanup
156 1.1 riastrad }
157 1.1 riastrad
158 1.1 riastrad wg_create_destroy_peers_common()
159 1.1 riastrad {
160 1.1 riastrad local proto=$1
161 1.1 riastrad local ifconfig="atf_check -s exit:0 rump.ifconfig"
162 1.1 riastrad local port=51820
163 1.1 riastrad local ip_local= ip_peer=
164 1.1 riastrad local ip_wg_local= ip_wg_peer=
165 1.1 riastrad local outer_prefix= outer_prefixall=
166 1.1 riastrad local inner_prefix= inner_prefixall=
167 1.1 riastrad
168 1.1 riastrad if [ $proto = inet ]; then
169 1.1 riastrad ip_local=192.168.1.1
170 1.1 riastrad ip_peer=192.168.1.2
171 1.1 riastrad outer_prefix=24
172 1.1 riastrad outer_prefixall=32
173 1.1 riastrad ip_wg_local=10.0.0.1
174 1.1 riastrad ip_wg_peer=10.0.0.2
175 1.1 riastrad inner_prefix=24
176 1.1 riastrad inner_prefixall=32
177 1.1 riastrad else
178 1.1 riastrad ip_local=fc00::1
179 1.1 riastrad ip_peer=fc00::2
180 1.1 riastrad outer_prefix=64
181 1.1 riastrad outer_prefixall=128
182 1.1 riastrad ip_wg_local=fd00::1
183 1.1 riastrad ip_wg_peer=fd00::2
184 1.1 riastrad inner_prefix=64
185 1.1 riastrad inner_prefixall=128
186 1.1 riastrad fi
187 1.1 riastrad
188 1.1 riastrad rump_server_crypto_start $SOCK_LOCAL netinet6 wg
189 1.1 riastrad rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
190 1.1 riastrad
191 1.1 riastrad # It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
192 1.1 riastrad generate_keys
193 1.1 riastrad
194 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
195 1.1 riastrad setup_common shmif0 $proto $ip_local $outer_prefix
196 1.1 riastrad setup_wg_common wg0 $proto $ip_wg_local $inner_prefix $port "$key_priv_local"
197 1.1 riastrad
198 1.1 riastrad add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/$inner_prefixall
199 1.1 riastrad
200 1.1 riastrad delete_peer wg0 peer0
201 1.1 riastrad }
202 1.1 riastrad
203 1.1 riastrad atf_test_case wg_create_destroy_peers_ipv4 cleanup
204 1.1 riastrad wg_create_destroy_peers_ipv4_head()
205 1.1 riastrad {
206 1.1 riastrad
207 1.1 riastrad atf_set "descr" "tests to create/destroy peers (IPv4)"
208 1.1 riastrad atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
209 1.1 riastrad }
210 1.1 riastrad
211 1.1 riastrad wg_create_destroy_peers_ipv4_body()
212 1.1 riastrad {
213 1.1 riastrad
214 1.1 riastrad wg_create_destroy_peers_common inet
215 1.1 riastrad }
216 1.1 riastrad
217 1.1 riastrad wg_create_destroy_peers_ipv4_cleanup()
218 1.1 riastrad {
219 1.1 riastrad
220 1.1 riastrad $DEBUG && dump
221 1.1 riastrad cleanup
222 1.1 riastrad }
223 1.1 riastrad
224 1.1 riastrad atf_test_case wg_create_destroy_peers_ipv6 cleanup
225 1.1 riastrad wg_create_destroy_peers_ipv6_head()
226 1.1 riastrad {
227 1.1 riastrad
228 1.1 riastrad atf_set "descr" "tests to create/destroy peers (IPv6)"
229 1.1 riastrad atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
230 1.1 riastrad }
231 1.1 riastrad
232 1.1 riastrad wg_create_destroy_peers_ipv6_body()
233 1.1 riastrad {
234 1.1 riastrad
235 1.1 riastrad wg_create_destroy_peers_common inet6
236 1.1 riastrad }
237 1.1 riastrad
238 1.1 riastrad wg_create_destroy_peers_ipv6_cleanup()
239 1.1 riastrad {
240 1.1 riastrad
241 1.1 riastrad $DEBUG && dump
242 1.1 riastrad cleanup
243 1.1 riastrad }
244 1.1 riastrad
245 1.1 riastrad add_basic_test()
246 1.1 riastrad {
247 1.1 riastrad local inner=$1
248 1.1 riastrad local outer=$2
249 1.1 riastrad local ipv4=inet
250 1.1 riastrad local ipv6=inet6
251 1.1 riastrad
252 1.1 riastrad name="wg_basic_${inner}_over_${outer}"
253 1.1 riastrad fulldesc="Test wg(4) with ${inner} over ${outer}"
254 1.1 riastrad
255 1.1 riastrad eval inner=\$$inner
256 1.1 riastrad eval outer=\$$outer
257 1.1 riastrad
258 1.1 riastrad atf_test_case ${name} cleanup
259 1.1 riastrad eval "
260 1.1 riastrad ${name}_head() {
261 1.1 riastrad atf_set descr \"${fulldesc}\"
262 1.1 riastrad atf_set require.progs rump_server wgconfig wg-keygen
263 1.1 riastrad }
264 1.1 riastrad ${name}_body() {
265 1.1 riastrad test_common basic $outer $inner
266 1.1 riastrad rump_server_destroy_ifaces
267 1.1 riastrad }
268 1.1 riastrad ${name}_cleanup() {
269 1.1 riastrad \$DEBUG && dump
270 1.1 riastrad cleanup
271 1.1 riastrad }"
272 1.1 riastrad atf_add_test_case ${name}
273 1.1 riastrad }
274 1.1 riastrad
275 1.1 riastrad add_payload_sizes_test()
276 1.1 riastrad {
277 1.1 riastrad local inner=$1
278 1.1 riastrad local outer=$2
279 1.1 riastrad local ipv4=inet
280 1.1 riastrad local ipv6=inet6
281 1.1 riastrad
282 1.1 riastrad name="wg_payload_sizes_${inner}_over_${outer}"
283 1.1 riastrad fulldesc="Test wg(4) with ${inner} over ${outer} with various payload sizes"
284 1.1 riastrad
285 1.1 riastrad eval inner=\$$inner
286 1.1 riastrad eval outer=\$$outer
287 1.1 riastrad
288 1.1 riastrad atf_test_case ${name} cleanup
289 1.1 riastrad eval "
290 1.1 riastrad ${name}_head() {
291 1.1 riastrad atf_set descr \"${fulldesc}\"
292 1.1 riastrad atf_set require.progs rump_server wgconfig wg-keygen
293 1.1 riastrad }
294 1.1 riastrad ${name}_body() {
295 1.1 riastrad test_common payload $outer $inner
296 1.1 riastrad rump_server_destroy_ifaces
297 1.1 riastrad }
298 1.1 riastrad ${name}_cleanup() {
299 1.1 riastrad \$DEBUG && dump
300 1.1 riastrad cleanup
301 1.1 riastrad }"
302 1.1 riastrad atf_add_test_case ${name}
303 1.1 riastrad }
304 1.1 riastrad
305 1.5 riastrad add_badudp_test()
306 1.5 riastrad {
307 1.5 riastrad local inner=$1
308 1.5 riastrad local outer=$2
309 1.5 riastrad local ipv4=inet
310 1.5 riastrad local ipv6=inet6
311 1.5 riastrad
312 1.5 riastrad name="wg_badudp_${inner}_over_${outer}"
313 1.5 riastrad fulldesc="Test wg(4) with ${inner} over ${outer} with bad UDP packets"
314 1.5 riastrad
315 1.5 riastrad eval inner=\$$inner
316 1.5 riastrad eval outer=\$$outer
317 1.5 riastrad
318 1.5 riastrad atf_test_case ${name} cleanup
319 1.5 riastrad eval "
320 1.5 riastrad ${name}_head() {
321 1.5 riastrad atf_set descr \"${fulldesc}\"
322 1.5 riastrad atf_set require.progs rump_server wgconfig wg-keygen nc
323 1.5 riastrad }
324 1.5 riastrad ${name}_body() {
325 1.5 riastrad test_common badudp $outer $inner
326 1.5 riastrad rump_server_destroy_ifaces
327 1.5 riastrad }
328 1.5 riastrad ${name}_cleanup() {
329 1.5 riastrad \$DEBUG && dump
330 1.5 riastrad cleanup
331 1.5 riastrad }"
332 1.5 riastrad atf_add_test_case ${name}
333 1.5 riastrad }
334 1.5 riastrad
335 1.1 riastrad atf_test_case wg_multiple_interfaces cleanup
336 1.1 riastrad wg_multiple_interfaces_head()
337 1.1 riastrad {
338 1.1 riastrad
339 1.1 riastrad atf_set "descr" "tests multiple wg(4) interfaces"
340 1.1 riastrad atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
341 1.1 riastrad }
342 1.1 riastrad
343 1.1 riastrad wg_multiple_interfaces_body()
344 1.1 riastrad {
345 1.1 riastrad local ifconfig="atf_check -s exit:0 rump.ifconfig"
346 1.1 riastrad local ping="atf_check -s exit:0 -o ignore rump.ping -n -i 0.1 -c 3 -w 1"
347 1.1 riastrad local ping_fail="atf_check -s not-exit:0 -o ignore rump.ping -n -c 1 -w 1"
348 1.1 riastrad local key_priv_peer2=
349 1.1 riastrad local key_pub_peer2=
350 1.1 riastrad local ip_local=192.168.1.1
351 1.1 riastrad local ip_local2=192.168.2.1
352 1.1 riastrad local ip_peer=192.168.1.2
353 1.1 riastrad local ip_peer2=192.168.2.2
354 1.1 riastrad local ip_wg_local=10.0.0.1
355 1.1 riastrad local ip_wg_local2=10.0.1.1
356 1.1 riastrad local ip_wg_peer=10.0.0.2
357 1.1 riastrad local ip_wg_peer2=10.0.1.2
358 1.1 riastrad local port=51820
359 1.1 riastrad local port2=51821
360 1.1 riastrad local outfile=./out
361 1.1 riastrad
362 1.1 riastrad setup_servers
363 1.1 riastrad rump_server_add_iface $SOCK_LOCAL shmif1 $BUS
364 1.1 riastrad
365 1.1 riastrad rump_server_crypto_start $SOCK_PEER2 netinet6 wg
366 1.1 riastrad rump_server_add_iface $SOCK_PEER2 shmif0 $BUS
367 1.1 riastrad
368 1.1 riastrad # It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
369 1.1 riastrad generate_keys
370 1.1 riastrad key_priv_peer2=$(wg-keygen)
371 1.1 riastrad key_pub_peer2=$(echo $key_priv_peer2| wg-keygen --pub)
372 1.1 riastrad
373 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
374 1.1 riastrad setup_common shmif0 inet $ip_local 24
375 1.1 riastrad setup_common shmif1 inet $ip_local2 24
376 1.1 riastrad setup_wg_common wg0 inet $ip_wg_local 24 $port "$key_priv_local"
377 1.1 riastrad setup_wg_common wg1 inet $ip_wg_local2 24 $port2 "$key_priv_local"
378 1.2 roy add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/32
379 1.2 roy add_peer wg1 peer0 $key_pub_peer2 $ip_peer2:$port2 $ip_wg_peer2/32
380 1.4 simonb $ifconfig -w 10
381 1.1 riastrad
382 1.1 riastrad export RUMP_SERVER=$SOCK_PEER
383 1.1 riastrad setup_common shmif0 inet $ip_peer 24
384 1.1 riastrad setup_wg_common wg0 inet $ip_wg_peer 24 $port "$key_priv_peer"
385 1.2 roy add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/32
386 1.4 simonb $ifconfig -w 10
387 1.1 riastrad
388 1.1 riastrad export RUMP_SERVER=$SOCK_PEER2
389 1.1 riastrad setup_common shmif0 inet $ip_peer2 24
390 1.1 riastrad setup_wg_common wg0 inet $ip_wg_peer2 24 $port2 "$key_priv_peer2"
391 1.1 riastrad add_peer wg0 peer0 $key_pub_local $ip_local2:$port2 $ip_wg_local2/32
392 1.4 simonb $ifconfig -w 10
393 1.1 riastrad
394 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
395 1.1 riastrad
396 1.1 riastrad extract_new_packets $BUS > $outfile
397 1.1 riastrad $DEBUG && cat $outfile
398 1.1 riastrad
399 1.1 riastrad $ping $ip_wg_peer
400 1.1 riastrad
401 1.1 riastrad extract_new_packets $BUS > $outfile
402 1.1 riastrad $DEBUG && cat $outfile
403 1.1 riastrad
404 1.1 riastrad $ping $ip_wg_peer2
405 1.1 riastrad
406 1.1 riastrad extract_new_packets $BUS > $outfile
407 1.1 riastrad $DEBUG && cat $outfile
408 1.1 riastrad
409 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
410 1.1 riastrad $ifconfig wg0 destroy
411 1.1 riastrad $ifconfig wg1 destroy
412 1.1 riastrad export RUMP_SERVER=$SOCK_PEER
413 1.1 riastrad $ifconfig wg0 destroy
414 1.1 riastrad export RUMP_SERVER=$SOCK_PEER2
415 1.1 riastrad $ifconfig wg0 destroy
416 1.1 riastrad }
417 1.1 riastrad
418 1.1 riastrad wg_multiple_interfaces_cleanup()
419 1.1 riastrad {
420 1.1 riastrad
421 1.1 riastrad $DEBUG && dump
422 1.1 riastrad cleanup
423 1.1 riastrad }
424 1.1 riastrad
425 1.1 riastrad atf_test_case wg_multiple_peers cleanup
426 1.1 riastrad wg_multiple_peers_head()
427 1.1 riastrad {
428 1.1 riastrad
429 1.1 riastrad atf_set "descr" "tests multiple wg(4) peers"
430 1.1 riastrad atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
431 1.1 riastrad }
432 1.1 riastrad
433 1.1 riastrad wg_multiple_peers_body()
434 1.1 riastrad {
435 1.1 riastrad local ifconfig="atf_check -s exit:0 rump.ifconfig"
436 1.1 riastrad local ping="atf_check -s exit:0 -o ignore rump.ping -n -i 0.1 -c 3 -w 1"
437 1.1 riastrad local ping_fail="atf_check -s not-exit:0 -o ignore rump.ping -n -c 1 -w 1"
438 1.1 riastrad local key_priv_peer2=
439 1.1 riastrad local key_pub_peer2=
440 1.1 riastrad local ip_local=192.168.1.1
441 1.1 riastrad local ip_peer=192.168.1.2
442 1.1 riastrad local ip_peer2=192.168.1.3
443 1.1 riastrad local ip_wg_local=10.0.0.1
444 1.1 riastrad local ip_wg_peer=10.0.0.2
445 1.1 riastrad local ip_wg_peer2=10.0.0.3
446 1.1 riastrad local port=51820
447 1.1 riastrad local outfile=./out
448 1.1 riastrad
449 1.1 riastrad setup_servers
450 1.1 riastrad rump_server_add_iface $SOCK_LOCAL shmif1 $BUS
451 1.1 riastrad
452 1.1 riastrad rump_server_crypto_start $SOCK_PEER2 netinet6 wg
453 1.1 riastrad rump_server_add_iface $SOCK_PEER2 shmif0 $BUS
454 1.1 riastrad
455 1.1 riastrad # It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
456 1.1 riastrad generate_keys
457 1.1 riastrad key_priv_peer2=$(wg-keygen)
458 1.1 riastrad key_pub_peer2=$(echo $key_priv_peer2| wg-keygen --pub)
459 1.1 riastrad
460 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
461 1.1 riastrad setup_common shmif0 inet $ip_local 24
462 1.1 riastrad setup_wg_common wg0 inet $ip_wg_local 24 $port "$key_priv_local"
463 1.2 roy add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/32
464 1.2 roy add_peer wg0 peer1 $key_pub_peer2 $ip_peer2:$port $ip_wg_peer2/32
465 1.4 simonb $ifconfig -w 10
466 1.1 riastrad
467 1.1 riastrad export RUMP_SERVER=$SOCK_PEER
468 1.1 riastrad setup_common shmif0 inet $ip_peer 24
469 1.1 riastrad setup_wg_common wg0 inet $ip_wg_peer 24 $port "$key_priv_peer"
470 1.2 roy add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/32
471 1.4 simonb $ifconfig -w 10
472 1.1 riastrad
473 1.1 riastrad export RUMP_SERVER=$SOCK_PEER2
474 1.1 riastrad setup_common shmif0 inet $ip_peer2 24
475 1.1 riastrad setup_wg_common wg0 inet $ip_wg_peer2 24 $port "$key_priv_peer2"
476 1.1 riastrad add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/32
477 1.4 simonb $ifconfig -w 10
478 1.1 riastrad
479 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
480 1.1 riastrad
481 1.1 riastrad extract_new_packets $BUS > $outfile
482 1.1 riastrad $DEBUG && cat $outfile
483 1.1 riastrad
484 1.1 riastrad $ping $ip_wg_peer
485 1.1 riastrad
486 1.1 riastrad extract_new_packets $BUS > $outfile
487 1.1 riastrad $DEBUG && cat $outfile
488 1.1 riastrad
489 1.1 riastrad $ping $ip_wg_peer2
490 1.1 riastrad
491 1.1 riastrad extract_new_packets $BUS > $outfile
492 1.1 riastrad $DEBUG && cat $outfile
493 1.1 riastrad
494 1.1 riastrad export RUMP_SERVER=$SOCK_LOCAL
495 1.1 riastrad $ifconfig wg0 destroy
496 1.1 riastrad export RUMP_SERVER=$SOCK_PEER
497 1.1 riastrad $ifconfig wg0 destroy
498 1.1 riastrad export RUMP_SERVER=$SOCK_PEER2
499 1.1 riastrad $ifconfig wg0 destroy
500 1.1 riastrad }
501 1.1 riastrad
502 1.1 riastrad wg_multiple_peers_cleanup()
503 1.1 riastrad {
504 1.1 riastrad
505 1.1 riastrad $DEBUG && dump
506 1.1 riastrad cleanup
507 1.1 riastrad }
508 1.1 riastrad
509 1.1 riastrad atf_init_test_cases()
510 1.1 riastrad {
511 1.1 riastrad
512 1.5 riastrad add_badudp_test ipv4 ipv4
513 1.5 riastrad add_badudp_test ipv4 ipv6
514 1.5 riastrad add_badudp_test ipv6 ipv4
515 1.5 riastrad add_badudp_test ipv6 ipv6
516 1.5 riastrad
517 1.1 riastrad add_basic_test ipv4 ipv4
518 1.1 riastrad add_basic_test ipv4 ipv6
519 1.1 riastrad add_basic_test ipv6 ipv4
520 1.1 riastrad add_basic_test ipv6 ipv6
521 1.1 riastrad
522 1.1 riastrad add_payload_sizes_test ipv4 ipv4
523 1.1 riastrad add_payload_sizes_test ipv4 ipv6
524 1.1 riastrad add_payload_sizes_test ipv6 ipv4
525 1.1 riastrad add_payload_sizes_test ipv6 ipv6
526 1.1 riastrad
527 1.1 riastrad atf_add_test_case wg_create_destroy
528 1.1 riastrad atf_add_test_case wg_create_destroy_peers_ipv4
529 1.1 riastrad atf_add_test_case wg_create_destroy_peers_ipv6
530 1.1 riastrad atf_add_test_case wg_multiple_interfaces
531 1.1 riastrad atf_add_test_case wg_multiple_peers
532 1.1 riastrad }
533