aboutsummaryrefslogtreecommitdiff
path: root/tests/sys/net
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sys/net')
-rw-r--r--tests/sys/net/Makefile1
-rwxr-xr-xtests/sys/net/if_bridge_test.sh19
-rwxr-xr-xtests/sys/net/if_tun_test.sh22
-rw-r--r--tests/sys/net/transient_tuntap.c54
4 files changed, 96 insertions, 0 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_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);
+}