Home | History | Annotate | Line # | Download | only in if_wg
t_basic.sh revision 1.6
      1  1.6  riastrad #	$NetBSD: t_basic.sh,v 1.6 2024/10/08 02:29:40 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 	fi
     64  1.5  riastrad }
     65  1.5  riastrad 
     66  1.1  riastrad test_common()
     67  1.1  riastrad {
     68  1.1  riastrad 	local type=$1
     69  1.1  riastrad 	local outer_proto=$2
     70  1.1  riastrad 	local inner_proto=$3
     71  1.1  riastrad 	local ifconfig="atf_check -s exit:0 rump.ifconfig"
     72  1.1  riastrad 	local port=51820
     73  1.1  riastrad 	local ip_local= ip_peer=
     74  1.1  riastrad 	local ip_wg_local= ip_wg_peer=
     75  1.1  riastrad 	local outer_prefix= outer_prefixall=
     76  1.1  riastrad 	local inner_prefix= inner_prefixall=
     77  1.1  riastrad 
     78  1.1  riastrad 	if [ $outer_proto = inet ]; then
     79  1.1  riastrad 		ip_local=192.168.1.1
     80  1.1  riastrad 		ip_peer=192.168.1.2
     81  1.1  riastrad 		outer_prefix=24
     82  1.1  riastrad 		outer_prefixall=32
     83  1.1  riastrad 	else
     84  1.1  riastrad 		ip_local=fc00::1
     85  1.1  riastrad 		ip_peer=fc00::2
     86  1.1  riastrad 		outer_prefix=64
     87  1.1  riastrad 		outer_prefixall=128
     88  1.1  riastrad 	fi
     89  1.1  riastrad 
     90  1.1  riastrad 	if [ $inner_proto = inet ]; then
     91  1.1  riastrad 		ip_wg_local=10.0.0.1
     92  1.1  riastrad 		ip_wg_peer=10.0.0.2
     93  1.1  riastrad 		inner_prefix=24
     94  1.1  riastrad 		inner_prefixall=32
     95  1.1  riastrad 	else
     96  1.1  riastrad 		ip_wg_local=fd00::1
     97  1.1  riastrad 		ip_wg_peer=fd00::2
     98  1.1  riastrad 		inner_prefix=64
     99  1.1  riastrad 		inner_prefixall=128
    100  1.1  riastrad 	fi
    101  1.1  riastrad 
    102  1.1  riastrad 	setup_servers
    103  1.1  riastrad 
    104  1.1  riastrad 	# It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
    105  1.1  riastrad 	generate_keys
    106  1.1  riastrad 
    107  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    108  1.1  riastrad 	setup_common shmif0 $outer_proto $ip_local $outer_prefix
    109  1.1  riastrad 	setup_wg_common wg0 $inner_proto $ip_wg_local $inner_prefix $port "$key_priv_local"
    110  1.2       roy 	add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/$inner_prefixall
    111  1.4    simonb 	$ifconfig -w 10
    112  1.1  riastrad 
    113  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER
    114  1.1  riastrad 	setup_common shmif0 $outer_proto $ip_peer $outer_prefix
    115  1.1  riastrad 	setup_wg_common wg0 $inner_proto $ip_wg_peer $inner_prefix $port "$key_priv_peer"
    116  1.1  riastrad 	add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/$inner_prefixall
    117  1.4    simonb 	$ifconfig -w 10
    118  1.1  riastrad 
    119  1.1  riastrad 	if [ $type = basic ]; then
    120  1.1  riastrad 		export RUMP_SERVER=$SOCK_LOCAL
    121  1.1  riastrad 		check_ping $inner_proto $ip_wg_peer
    122  1.1  riastrad 	elif [ $type = payload ]; then
    123  1.1  riastrad 		export RUMP_SERVER=$SOCK_LOCAL
    124  1.1  riastrad 		check_ping_payload $inner_proto $ip_wg_peer
    125  1.5  riastrad 	elif [ $type = badudp ]; then
    126  1.5  riastrad 		export RUMP_SERVER=$SOCK_LOCAL
    127  1.5  riastrad 		check_badudp $outer_proto $ip_peer
    128  1.1  riastrad 	fi
    129  1.1  riastrad 
    130  1.1  riastrad 	destroy_wg_interfaces
    131  1.1  riastrad }
    132  1.1  riastrad 
    133  1.1  riastrad atf_test_case wg_create_destroy cleanup
    134  1.1  riastrad wg_create_destroy_head()
    135  1.1  riastrad {
    136  1.1  riastrad 
    137  1.1  riastrad 	atf_set "descr" "tests to create/destroy wg(4) interfaces"
    138  1.1  riastrad 	atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
    139  1.1  riastrad }
    140  1.1  riastrad 
    141  1.1  riastrad wg_create_destroy_body()
    142  1.1  riastrad {
    143  1.1  riastrad 
    144  1.1  riastrad 	rump_server_crypto_start $SOCK_LOCAL netinet6 wg
    145  1.1  riastrad 
    146  1.1  riastrad 	test_create_destroy_common $SOCK_LOCAL wg0 true
    147  1.1  riastrad }
    148  1.1  riastrad 
    149  1.1  riastrad wg_create_destroy_cleanup()
    150  1.1  riastrad {
    151  1.1  riastrad 
    152  1.1  riastrad 	$DEBUG && dump
    153  1.1  riastrad 	cleanup
    154  1.1  riastrad }
    155  1.1  riastrad 
    156  1.1  riastrad wg_create_destroy_peers_common()
    157  1.1  riastrad {
    158  1.1  riastrad 	local proto=$1
    159  1.1  riastrad 	local ifconfig="atf_check -s exit:0 rump.ifconfig"
    160  1.1  riastrad 	local port=51820
    161  1.1  riastrad 	local ip_local= ip_peer=
    162  1.1  riastrad 	local ip_wg_local= ip_wg_peer=
    163  1.1  riastrad 	local outer_prefix= outer_prefixall=
    164  1.1  riastrad 	local inner_prefix= inner_prefixall=
    165  1.1  riastrad 
    166  1.1  riastrad 	if [ $proto = inet ]; then
    167  1.1  riastrad 		ip_local=192.168.1.1
    168  1.1  riastrad 		ip_peer=192.168.1.2
    169  1.1  riastrad 		outer_prefix=24
    170  1.1  riastrad 		outer_prefixall=32
    171  1.1  riastrad 		ip_wg_local=10.0.0.1
    172  1.1  riastrad 		ip_wg_peer=10.0.0.2
    173  1.1  riastrad 		inner_prefix=24
    174  1.1  riastrad 		inner_prefixall=32
    175  1.1  riastrad 	else
    176  1.1  riastrad 		ip_local=fc00::1
    177  1.1  riastrad 		ip_peer=fc00::2
    178  1.1  riastrad 		outer_prefix=64
    179  1.1  riastrad 		outer_prefixall=128
    180  1.1  riastrad 		ip_wg_local=fd00::1
    181  1.1  riastrad 		ip_wg_peer=fd00::2
    182  1.1  riastrad 		inner_prefix=64
    183  1.1  riastrad 		inner_prefixall=128
    184  1.1  riastrad 	fi
    185  1.1  riastrad 
    186  1.1  riastrad 	rump_server_crypto_start $SOCK_LOCAL netinet6 wg
    187  1.1  riastrad 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    188  1.1  riastrad 
    189  1.1  riastrad 	# It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
    190  1.1  riastrad 	generate_keys
    191  1.1  riastrad 
    192  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    193  1.1  riastrad 	setup_common shmif0 $proto $ip_local $outer_prefix
    194  1.1  riastrad 	setup_wg_common wg0 $proto $ip_wg_local $inner_prefix $port "$key_priv_local"
    195  1.1  riastrad 
    196  1.1  riastrad 	add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/$inner_prefixall
    197  1.1  riastrad 
    198  1.1  riastrad 	delete_peer wg0 peer0
    199  1.1  riastrad }
    200  1.1  riastrad 
    201  1.1  riastrad atf_test_case wg_create_destroy_peers_ipv4 cleanup
    202  1.1  riastrad wg_create_destroy_peers_ipv4_head()
    203  1.1  riastrad {
    204  1.1  riastrad 
    205  1.1  riastrad 	atf_set "descr" "tests to create/destroy peers (IPv4)"
    206  1.1  riastrad 	atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
    207  1.1  riastrad }
    208  1.1  riastrad 
    209  1.1  riastrad wg_create_destroy_peers_ipv4_body()
    210  1.1  riastrad {
    211  1.1  riastrad 
    212  1.1  riastrad 	wg_create_destroy_peers_common inet
    213  1.1  riastrad }
    214  1.1  riastrad 
    215  1.1  riastrad wg_create_destroy_peers_ipv4_cleanup()
    216  1.1  riastrad {
    217  1.1  riastrad 
    218  1.1  riastrad 	$DEBUG && dump
    219  1.1  riastrad 	cleanup
    220  1.1  riastrad }
    221  1.1  riastrad 
    222  1.1  riastrad atf_test_case wg_create_destroy_peers_ipv6 cleanup
    223  1.1  riastrad wg_create_destroy_peers_ipv6_head()
    224  1.1  riastrad {
    225  1.1  riastrad 
    226  1.1  riastrad 	atf_set "descr" "tests to create/destroy peers (IPv6)"
    227  1.1  riastrad 	atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
    228  1.1  riastrad }
    229  1.1  riastrad 
    230  1.1  riastrad wg_create_destroy_peers_ipv6_body()
    231  1.1  riastrad {
    232  1.1  riastrad 
    233  1.1  riastrad 	wg_create_destroy_peers_common inet6
    234  1.1  riastrad }
    235  1.1  riastrad 
    236  1.1  riastrad wg_create_destroy_peers_ipv6_cleanup()
    237  1.1  riastrad {
    238  1.1  riastrad 
    239  1.1  riastrad 	$DEBUG && dump
    240  1.1  riastrad 	cleanup
    241  1.1  riastrad }
    242  1.1  riastrad 
    243  1.1  riastrad add_basic_test()
    244  1.1  riastrad {
    245  1.1  riastrad 	local inner=$1
    246  1.1  riastrad 	local outer=$2
    247  1.1  riastrad 	local ipv4=inet
    248  1.1  riastrad 	local ipv6=inet6
    249  1.1  riastrad 
    250  1.1  riastrad 	name="wg_basic_${inner}_over_${outer}"
    251  1.1  riastrad 	fulldesc="Test wg(4) with ${inner} over ${outer}"
    252  1.1  riastrad 
    253  1.1  riastrad 	eval inner=\$$inner
    254  1.1  riastrad 	eval outer=\$$outer
    255  1.1  riastrad 
    256  1.1  riastrad 	atf_test_case ${name} cleanup
    257  1.1  riastrad 	eval "
    258  1.1  riastrad 		${name}_head() {
    259  1.1  riastrad 			atf_set descr \"${fulldesc}\"
    260  1.1  riastrad 			atf_set require.progs rump_server wgconfig wg-keygen
    261  1.1  riastrad 		}
    262  1.1  riastrad 		${name}_body() {
    263  1.1  riastrad 			test_common basic $outer $inner
    264  1.1  riastrad 			rump_server_destroy_ifaces
    265  1.1  riastrad 		}
    266  1.1  riastrad 		${name}_cleanup() {
    267  1.1  riastrad 			\$DEBUG && dump
    268  1.1  riastrad 			cleanup
    269  1.1  riastrad 		}"
    270  1.1  riastrad 	atf_add_test_case ${name}
    271  1.1  riastrad }
    272  1.1  riastrad 
    273  1.1  riastrad add_payload_sizes_test()
    274  1.1  riastrad {
    275  1.1  riastrad 	local inner=$1
    276  1.1  riastrad 	local outer=$2
    277  1.1  riastrad 	local ipv4=inet
    278  1.1  riastrad 	local ipv6=inet6
    279  1.1  riastrad 
    280  1.1  riastrad 	name="wg_payload_sizes_${inner}_over_${outer}"
    281  1.1  riastrad 	fulldesc="Test wg(4) with ${inner} over ${outer} with various payload sizes"
    282  1.1  riastrad 
    283  1.1  riastrad 	eval inner=\$$inner
    284  1.1  riastrad 	eval outer=\$$outer
    285  1.1  riastrad 
    286  1.1  riastrad 	atf_test_case ${name} cleanup
    287  1.1  riastrad 	eval "
    288  1.1  riastrad 		${name}_head() {
    289  1.1  riastrad 			atf_set descr \"${fulldesc}\"
    290  1.1  riastrad 			atf_set require.progs rump_server wgconfig wg-keygen
    291  1.1  riastrad 		}
    292  1.1  riastrad 		${name}_body() {
    293  1.1  riastrad 			test_common payload $outer $inner
    294  1.1  riastrad 			rump_server_destroy_ifaces
    295  1.1  riastrad 		}
    296  1.1  riastrad 		${name}_cleanup() {
    297  1.1  riastrad 			\$DEBUG && dump
    298  1.1  riastrad 			cleanup
    299  1.1  riastrad 		}"
    300  1.1  riastrad 	atf_add_test_case ${name}
    301  1.1  riastrad }
    302  1.1  riastrad 
    303  1.5  riastrad add_badudp_test()
    304  1.5  riastrad {
    305  1.5  riastrad 	local inner=$1
    306  1.5  riastrad 	local outer=$2
    307  1.5  riastrad 	local ipv4=inet
    308  1.5  riastrad 	local ipv6=inet6
    309  1.5  riastrad 
    310  1.5  riastrad 	name="wg_badudp_${inner}_over_${outer}"
    311  1.5  riastrad 	fulldesc="Test wg(4) with ${inner} over ${outer} with bad UDP packets"
    312  1.5  riastrad 
    313  1.5  riastrad 	eval inner=\$$inner
    314  1.5  riastrad 	eval outer=\$$outer
    315  1.5  riastrad 
    316  1.5  riastrad 	atf_test_case ${name} cleanup
    317  1.5  riastrad 	eval "
    318  1.5  riastrad 		${name}_head() {
    319  1.5  riastrad 			atf_set descr \"${fulldesc}\"
    320  1.5  riastrad 			atf_set require.progs rump_server wgconfig wg-keygen nc
    321  1.5  riastrad 		}
    322  1.5  riastrad 		${name}_body() {
    323  1.5  riastrad 			test_common badudp $outer $inner
    324  1.5  riastrad 			rump_server_destroy_ifaces
    325  1.5  riastrad 		}
    326  1.5  riastrad 		${name}_cleanup() {
    327  1.5  riastrad 			\$DEBUG && dump
    328  1.5  riastrad 			cleanup
    329  1.5  riastrad 		}"
    330  1.5  riastrad 	atf_add_test_case ${name}
    331  1.5  riastrad }
    332  1.5  riastrad 
    333  1.1  riastrad atf_test_case wg_multiple_interfaces cleanup
    334  1.1  riastrad wg_multiple_interfaces_head()
    335  1.1  riastrad {
    336  1.1  riastrad 
    337  1.1  riastrad 	atf_set "descr" "tests multiple wg(4) interfaces"
    338  1.1  riastrad 	atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
    339  1.1  riastrad }
    340  1.1  riastrad 
    341  1.1  riastrad wg_multiple_interfaces_body()
    342  1.1  riastrad {
    343  1.1  riastrad 	local ifconfig="atf_check -s exit:0 rump.ifconfig"
    344  1.1  riastrad 	local ping="atf_check -s exit:0 -o ignore rump.ping -n -i 0.1 -c 3 -w 1"
    345  1.1  riastrad 	local ping_fail="atf_check -s not-exit:0 -o ignore rump.ping -n -c 1 -w 1"
    346  1.1  riastrad 	local key_priv_peer2=
    347  1.1  riastrad 	local key_pub_peer2=
    348  1.1  riastrad 	local ip_local=192.168.1.1
    349  1.1  riastrad 	local ip_local2=192.168.2.1
    350  1.1  riastrad 	local ip_peer=192.168.1.2
    351  1.1  riastrad 	local ip_peer2=192.168.2.2
    352  1.1  riastrad 	local ip_wg_local=10.0.0.1
    353  1.1  riastrad 	local ip_wg_local2=10.0.1.1
    354  1.1  riastrad 	local ip_wg_peer=10.0.0.2
    355  1.1  riastrad 	local ip_wg_peer2=10.0.1.2
    356  1.1  riastrad 	local port=51820
    357  1.1  riastrad 	local port2=51821
    358  1.1  riastrad 	local outfile=./out
    359  1.1  riastrad 
    360  1.1  riastrad 	setup_servers
    361  1.1  riastrad 	rump_server_add_iface $SOCK_LOCAL shmif1 $BUS
    362  1.1  riastrad 
    363  1.1  riastrad 	rump_server_crypto_start $SOCK_PEER2 netinet6 wg
    364  1.1  riastrad 	rump_server_add_iface $SOCK_PEER2 shmif0 $BUS
    365  1.1  riastrad 
    366  1.1  riastrad 	# It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
    367  1.1  riastrad 	generate_keys
    368  1.1  riastrad 	key_priv_peer2=$(wg-keygen)
    369  1.1  riastrad 	key_pub_peer2=$(echo $key_priv_peer2| wg-keygen --pub)
    370  1.1  riastrad 
    371  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    372  1.1  riastrad 	setup_common shmif0 inet $ip_local 24
    373  1.1  riastrad 	setup_common shmif1 inet $ip_local2 24
    374  1.1  riastrad 	setup_wg_common wg0 inet $ip_wg_local 24 $port "$key_priv_local"
    375  1.1  riastrad 	setup_wg_common wg1 inet $ip_wg_local2 24 $port2 "$key_priv_local"
    376  1.2       roy 	add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/32
    377  1.2       roy 	add_peer wg1 peer0 $key_pub_peer2 $ip_peer2:$port2 $ip_wg_peer2/32
    378  1.4    simonb 	$ifconfig -w 10
    379  1.1  riastrad 
    380  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER
    381  1.1  riastrad 	setup_common shmif0 inet $ip_peer 24
    382  1.1  riastrad 	setup_wg_common wg0 inet $ip_wg_peer 24 $port "$key_priv_peer"
    383  1.2       roy 	add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/32
    384  1.4    simonb 	$ifconfig -w 10
    385  1.1  riastrad 
    386  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER2
    387  1.1  riastrad 	setup_common shmif0 inet $ip_peer2 24
    388  1.1  riastrad 	setup_wg_common wg0 inet $ip_wg_peer2 24 $port2 "$key_priv_peer2"
    389  1.1  riastrad 	add_peer wg0 peer0 $key_pub_local $ip_local2:$port2 $ip_wg_local2/32
    390  1.4    simonb 	$ifconfig -w 10
    391  1.1  riastrad 
    392  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    393  1.1  riastrad 
    394  1.1  riastrad 	extract_new_packets $BUS > $outfile
    395  1.1  riastrad 	$DEBUG && cat $outfile
    396  1.1  riastrad 
    397  1.1  riastrad 	$ping $ip_wg_peer
    398  1.1  riastrad 
    399  1.1  riastrad 	extract_new_packets $BUS > $outfile
    400  1.1  riastrad 	$DEBUG && cat $outfile
    401  1.1  riastrad 
    402  1.1  riastrad 	$ping $ip_wg_peer2
    403  1.1  riastrad 
    404  1.1  riastrad 	extract_new_packets $BUS > $outfile
    405  1.1  riastrad 	$DEBUG && cat $outfile
    406  1.1  riastrad 
    407  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    408  1.1  riastrad 	$ifconfig wg0 destroy
    409  1.1  riastrad 	$ifconfig wg1 destroy
    410  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER
    411  1.1  riastrad 	$ifconfig wg0 destroy
    412  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER2
    413  1.1  riastrad 	$ifconfig wg0 destroy
    414  1.1  riastrad }
    415  1.1  riastrad 
    416  1.1  riastrad wg_multiple_interfaces_cleanup()
    417  1.1  riastrad {
    418  1.1  riastrad 
    419  1.1  riastrad 	$DEBUG && dump
    420  1.1  riastrad 	cleanup
    421  1.1  riastrad }
    422  1.1  riastrad 
    423  1.1  riastrad atf_test_case wg_multiple_peers cleanup
    424  1.1  riastrad wg_multiple_peers_head()
    425  1.1  riastrad {
    426  1.1  riastrad 
    427  1.1  riastrad 	atf_set "descr" "tests multiple wg(4) peers"
    428  1.1  riastrad 	atf_set "require.progs" "rump_server" "wgconfig" "wg-keygen"
    429  1.1  riastrad }
    430  1.1  riastrad 
    431  1.1  riastrad wg_multiple_peers_body()
    432  1.1  riastrad {
    433  1.1  riastrad 	local ifconfig="atf_check -s exit:0 rump.ifconfig"
    434  1.1  riastrad 	local ping="atf_check -s exit:0 -o ignore rump.ping -n -i 0.1 -c 3 -w 1"
    435  1.1  riastrad 	local ping_fail="atf_check -s not-exit:0 -o ignore rump.ping -n -c 1 -w 1"
    436  1.1  riastrad 	local key_priv_peer2=
    437  1.1  riastrad 	local key_pub_peer2=
    438  1.1  riastrad 	local ip_local=192.168.1.1
    439  1.1  riastrad 	local ip_peer=192.168.1.2
    440  1.1  riastrad 	local ip_peer2=192.168.1.3
    441  1.1  riastrad 	local ip_wg_local=10.0.0.1
    442  1.1  riastrad 	local ip_wg_peer=10.0.0.2
    443  1.1  riastrad 	local ip_wg_peer2=10.0.0.3
    444  1.1  riastrad 	local port=51820
    445  1.1  riastrad 	local outfile=./out
    446  1.1  riastrad 
    447  1.1  riastrad 	setup_servers
    448  1.1  riastrad 	rump_server_add_iface $SOCK_LOCAL shmif1 $BUS
    449  1.1  riastrad 
    450  1.1  riastrad 	rump_server_crypto_start $SOCK_PEER2 netinet6 wg
    451  1.1  riastrad 	rump_server_add_iface $SOCK_PEER2 shmif0 $BUS
    452  1.1  riastrad 
    453  1.1  riastrad 	# It sets key_priv_local key_pub_local key_priv_peer key_pub_peer
    454  1.1  riastrad 	generate_keys
    455  1.1  riastrad 	key_priv_peer2=$(wg-keygen)
    456  1.1  riastrad 	key_pub_peer2=$(echo $key_priv_peer2| wg-keygen --pub)
    457  1.1  riastrad 
    458  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    459  1.1  riastrad 	setup_common shmif0 inet $ip_local 24
    460  1.1  riastrad 	setup_wg_common wg0 inet $ip_wg_local 24 $port "$key_priv_local"
    461  1.2       roy 	add_peer wg0 peer0 $key_pub_peer $ip_peer:$port $ip_wg_peer/32
    462  1.2       roy 	add_peer wg0 peer1 $key_pub_peer2 $ip_peer2:$port $ip_wg_peer2/32
    463  1.4    simonb 	$ifconfig -w 10
    464  1.1  riastrad 
    465  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER
    466  1.1  riastrad 	setup_common shmif0 inet $ip_peer 24
    467  1.1  riastrad 	setup_wg_common wg0 inet $ip_wg_peer 24 $port "$key_priv_peer"
    468  1.2       roy 	add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/32
    469  1.4    simonb 	$ifconfig -w 10
    470  1.1  riastrad 
    471  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER2
    472  1.1  riastrad 	setup_common shmif0 inet $ip_peer2 24
    473  1.1  riastrad 	setup_wg_common wg0 inet $ip_wg_peer2 24 $port "$key_priv_peer2"
    474  1.1  riastrad 	add_peer wg0 peer0 $key_pub_local $ip_local:$port $ip_wg_local/32
    475  1.4    simonb 	$ifconfig -w 10
    476  1.1  riastrad 
    477  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    478  1.1  riastrad 
    479  1.1  riastrad 	extract_new_packets $BUS > $outfile
    480  1.1  riastrad 	$DEBUG && cat $outfile
    481  1.1  riastrad 
    482  1.1  riastrad 	$ping $ip_wg_peer
    483  1.1  riastrad 
    484  1.1  riastrad 	extract_new_packets $BUS > $outfile
    485  1.1  riastrad 	$DEBUG && cat $outfile
    486  1.1  riastrad 
    487  1.1  riastrad 	$ping $ip_wg_peer2
    488  1.1  riastrad 
    489  1.1  riastrad 	extract_new_packets $BUS > $outfile
    490  1.1  riastrad 	$DEBUG && cat $outfile
    491  1.1  riastrad 
    492  1.1  riastrad 	export RUMP_SERVER=$SOCK_LOCAL
    493  1.1  riastrad 	$ifconfig wg0 destroy
    494  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER
    495  1.1  riastrad 	$ifconfig wg0 destroy
    496  1.1  riastrad 	export RUMP_SERVER=$SOCK_PEER2
    497  1.1  riastrad 	$ifconfig wg0 destroy
    498  1.1  riastrad }
    499  1.1  riastrad 
    500  1.1  riastrad wg_multiple_peers_cleanup()
    501  1.1  riastrad {
    502  1.1  riastrad 
    503  1.1  riastrad 	$DEBUG && dump
    504  1.1  riastrad 	cleanup
    505  1.1  riastrad }
    506  1.1  riastrad 
    507  1.1  riastrad atf_init_test_cases()
    508  1.1  riastrad {
    509  1.1  riastrad 
    510  1.5  riastrad 	add_badudp_test ipv4 ipv4
    511  1.5  riastrad 	add_badudp_test ipv4 ipv6
    512  1.5  riastrad 	add_badudp_test ipv6 ipv4
    513  1.5  riastrad 	add_badudp_test ipv6 ipv6
    514  1.5  riastrad 
    515  1.1  riastrad 	add_basic_test ipv4 ipv4
    516  1.1  riastrad 	add_basic_test ipv4 ipv6
    517  1.1  riastrad 	add_basic_test ipv6 ipv4
    518  1.1  riastrad 	add_basic_test ipv6 ipv6
    519  1.1  riastrad 
    520  1.1  riastrad 	add_payload_sizes_test ipv4 ipv4
    521  1.1  riastrad 	add_payload_sizes_test ipv4 ipv6
    522  1.1  riastrad 	add_payload_sizes_test ipv6 ipv4
    523  1.1  riastrad 	add_payload_sizes_test ipv6 ipv6
    524  1.1  riastrad 
    525  1.1  riastrad 	atf_add_test_case wg_create_destroy
    526  1.1  riastrad 	atf_add_test_case wg_create_destroy_peers_ipv4
    527  1.1  riastrad 	atf_add_test_case wg_create_destroy_peers_ipv6
    528  1.1  riastrad 	atf_add_test_case wg_multiple_interfaces
    529  1.1  riastrad 	atf_add_test_case wg_multiple_peers
    530  1.1  riastrad }
    531