diff options
Diffstat (limited to 'tests/sys/net')
-rw-r--r-- | tests/sys/net/Makefile | 1 | ||||
-rwxr-xr-x | tests/sys/net/if_bridge_test.sh | 19 | ||||
-rw-r--r-- | tests/sys/net/if_epair.c | 4 | ||||
-rw-r--r-- | tests/sys/net/if_ovpn/if_ovpn.sh | 2 | ||||
-rw-r--r-- | tests/sys/net/if_ovpn/if_ovpn_c.c | 5 | ||||
-rw-r--r-- | tests/sys/net/if_ovpn/utils.subr | 19 | ||||
-rwxr-xr-x | tests/sys/net/if_tun_test.sh | 22 | ||||
-rw-r--r-- | tests/sys/net/transient_tuntap.c | 54 |
8 files changed, 119 insertions, 7 deletions
diff --git a/tests/sys/net/Makefile b/tests/sys/net/Makefile index 65cc99a3e932..e390c6e8059d 100644 --- a/tests/sys/net/Makefile +++ b/tests/sys/net/Makefile @@ -40,6 +40,7 @@ ${PACKAGE}FILESMODE_stp.py= 0555 MAN= PROGS+= randsleep +PROGS+= transient_tuntap CFLAGS+= -I${.CURDIR:H:H} diff --git a/tests/sys/net/if_bridge_test.sh b/tests/sys/net/if_bridge_test.sh index 0c19903714b1..b3405fd978c8 100755 --- a/tests/sys/net/if_bridge_test.sh +++ b/tests/sys/net/if_bridge_test.sh @@ -586,6 +586,25 @@ gif_body() jexec one ping -c 1 -s 1200 198.51.100.2 atf_check -s exit:0 -o ignore \ jexec one ping -c 1 -s 2000 198.51.100.2 + + # Assigning IP addresses on the gif tunneling interfaces + jexec one sysctl net.link.bridge.member_ifaddrs=1 + atf_check -s exit:0 -o ignore \ + jexec one ifconfig ${gif_one} 192.168.0.224/24 192.168.169.254 + atf_check -s exit:0 -o ignore \ + jexec one ifconfig ${gif_one} inet6 no_dad 2001:db8::1/64 + jexec one ifconfig ${bridge_one} deletem ${gif_one} + atf_check -s exit:0 -o ignore \ + jexec one ifconfig ${bridge_one} addm ${gif_one} + + jexec two sysctl net.link.bridge.member_ifaddrs=0 + atf_check -s exit:0 -o ignore \ + jexec two ifconfig ${gif_two} 192.168.169.254/24 192.168.0.224 + atf_check -s exit:0 -o ignore \ + jexec two ifconfig ${gif_two} inet6 no_dad 2001:db8::2/64 + jexec two ifconfig ${bridge_two} deletem ${gif_two} + atf_check -s exit:0 -o ignore \ + jexec two ifconfig ${bridge_two} addm ${gif_two} } gif_cleanup() diff --git a/tests/sys/net/if_epair.c b/tests/sys/net/if_epair.c index 0817b298d427..5ee4a48aea86 100644 --- a/tests/sys/net/if_epair.c +++ b/tests/sys/net/if_epair.c @@ -44,6 +44,7 @@ ATF_TC(params); ATF_TC_HEAD(params, tc) { atf_tc_set_md_var(tc, "require.user", "root"); + atf_tc_set_md_var(tc, "require.kmods", "if_epair"); } ATF_TC_BODY(params, tc) @@ -51,9 +52,6 @@ ATF_TC_BODY(params, tc) struct ifreq ifr; int s; - kldload("if_epair"); - ATF_REQUIRE_KERNEL_MODULE("if_epair"); - s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) atf_tc_fail("Failed to create socket"); diff --git a/tests/sys/net/if_ovpn/if_ovpn.sh b/tests/sys/net/if_ovpn/if_ovpn.sh index 0281e7fc273d..9dafce2242d8 100644 --- a/tests/sys/net/if_ovpn/if_ovpn.sh +++ b/tests/sys/net/if_ovpn/if_ovpn.sh @@ -510,6 +510,7 @@ linklocal_head() linklocal_body() { ovpn_init + ovpn_check_version 2.7.0 l=$(vnet_mkepair) @@ -1399,6 +1400,7 @@ float_head() float_body() { ovpn_init + ovpn_check_version 2.7.0 l=$(vnet_mkepair) diff --git a/tests/sys/net/if_ovpn/if_ovpn_c.c b/tests/sys/net/if_ovpn/if_ovpn_c.c index fa8a9a07fa35..7b558f1975dd 100644 --- a/tests/sys/net/if_ovpn/if_ovpn_c.c +++ b/tests/sys/net/if_ovpn/if_ovpn_c.c @@ -78,6 +78,7 @@ ATF_TC_WITH_CLEANUP(tcp); ATF_TC_HEAD(tcp, tc) { atf_tc_set_md_var(tc, "require.user", "root"); + atf_tc_set_md_var(tc, "require.kmods", "if_ovpn"); } ATF_TC_BODY(tcp, tc) @@ -87,10 +88,6 @@ ATF_TC_BODY(tcp, tc) int ret; nvlist_t *nvl; - /* Ensure the module is loaded. */ - if (kldfind("if_ovpn") == -1 && errno == ENOENT) - atf_tc_skip("if_ovpn not loaded"); - ovpn_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); /* Kick off a connect so there's a local address set, which we need for diff --git a/tests/sys/net/if_ovpn/utils.subr b/tests/sys/net/if_ovpn/utils.subr index 0da35119b2bf..fbe7dc98630a 100644 --- a/tests/sys/net/if_ovpn/utils.subr +++ b/tests/sys/net/if_ovpn/utils.subr @@ -40,6 +40,25 @@ ovpn_init() fi } +ovpn_check_version() +{ + expected=$1 + + expected_minor=$(echo $expected | + awk '{ split($1, ver, "\."); print(ver[2]); }') + actual_minor=$(openvpn --version 2>&1 | + awk 'NR == 1 \ + { \ + split($2, ver, "\."); \ + split(ver[2], minor, "_"); \ + print(minor[1]); \ + }') + + if [ ${actual_minor} -lt ${expected_minor} ]; then + atf_skip "OpenVPN version < ${expected}" + fi +} + ovpn_cleanup() { for jail in `cat ovpn_jails.lst | sort -u` diff --git a/tests/sys/net/if_tun_test.sh b/tests/sys/net/if_tun_test.sh index a4ffe66e04ce..f4ce7800272e 100755 --- a/tests/sys/net/if_tun_test.sh +++ b/tests/sys/net/if_tun_test.sh @@ -56,8 +56,30 @@ basic_cleanup() vnet_cleanup } +atf_test_case "transient" "cleanup" +transient_head() +{ + atf_set descr "Test transient tunnel support" + atf_set require.user root +} +transient_body() +{ + vnet_init + vnet_mkjail one + + tun=$(jexec one ifconfig tun create) + atf_check -s exit:0 -o not-empty jexec one ifconfig ${tun} + jexec one $(atf_get_srcdir)/transient_tuntap /dev/${tun} + atf_check -s not-exit:0 -e not-empty jexec one ifconfig ${tun} +} +transient_cleanup() +{ + vnet_cleanup +} + atf_init_test_cases() { atf_add_test_case "235704" atf_add_test_case "basic" + atf_add_test_case "transient" } diff --git a/tests/sys/net/transient_tuntap.c b/tests/sys/net/transient_tuntap.c new file mode 100644 index 000000000000..b0cf43064317 --- /dev/null +++ b/tests/sys/net/transient_tuntap.c @@ -0,0 +1,54 @@ +/*- + * Copyright (c) 2024 Kyle Evans <kevans@FreeBSD.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +/* + * This test simply configures the tunnel as transient and exits. By the time + * we return, the tunnel should be gone because the last reference disappears. + */ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <net/if_tun.h> +#include <net/if_tap.h> + +#include <assert.h> +#include <err.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> + +int +main(int argc, char *argv[]) +{ + unsigned long tunreq; + const char *tundev; + int one = 1, tunfd; + + assert(argc > 1); + tundev = argv[1]; + + tunfd = open(tundev, O_RDWR); + assert(tunfd >= 0); + + /* + * These are technically the same request, but we'll use the technically + * correct one just in case. + */ + if (strstr(tundev, "tun") != NULL) { + tunreq = TUNSTRANSIENT; + } else { + assert(strstr(tundev, "tap") != NULL); + tunreq = TAPSTRANSIENT; + } + + if (ioctl(tunfd, tunreq, &one) == -1) + err(1, "ioctl"); + + /* Final close should destroy the tunnel automagically. */ + close(tunfd); + + return (0); +} |