From patchwork Sun Nov 15 16:43:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5705 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:9292:b0:11a:f58a:e788 with SMTP id dc18csp273813lab; Sun, 15 Nov 2026 08:43:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHmfAx7s+TTd3UlzIlTsN+8+/j43/LMNRDbFao8LA2Ytodtl5+RGHTtcDbi5y9Q0lRc8ASvB3NXCsc=@openvpn.net X-Received: by 2002:a05:7022:1701:b0:1b4:f5cb:ebe3 with SMTP id a92af1059eb24-1b50311597dmr8139665c88.16.1794761023481; Sun, 15 Nov 2026 08:43:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794761023; cv=none; d=google.com; s=arc-20260327; b=aV62YOOKWZVUiNXYBuHf/shFihtpNijh6T21PAhDcv0TNct+qaeXVI7+ULBTpYNOnu vzDRz+Kkmq6YIHD2qLI77ssomus5ZlCdJkrgxYWMTFwsIqfkfxAmqUsp0yT2Af1K/DHb zIPyB8UPaXGCcqp/grkanjD3bVDdlaqjI2/0zODb/YeBoUBXMcU7H1FOlTfwl9Ie0b4W KerZgT3ows4NDCcgXQ/k9Rx8Eo91Wpt2QJKtiivufvAGQsKKX212MlXd6yXzadyKG4SF 23BpnErrHtl44geEkI2kyJRJ49h3N2YKIyshFZxH7Z3vBlflT+fpgnvJWXy9IluHn5BG G4Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=J878fV2KvdAW5xSMHAGKOuBsgrqKf7q6QYd7md0EMwU=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=QEkrk30/WVkB1tNOXk9B7B4QXUqXVwhSr1JGAI06GSEZ7WOY5Z4pbBOIjwj+1STGTz Y94CP7BidMG9uPnFSTS8sqxyg1mqLRYv2SLuAXAcrCQedtxfbzgvmrglyABz7tTkthWG 4tHMoZFXz3vVYQtdho2epeZtsnx6Q4xQf9PiwCs5UuvG/uRssAnijxGDHDzURChrqlVt jD36dIOUXowD52cvINEf7UxDNI6fLeZq+ckvI/SWobS+m0drfbYLn/PP4XVUZ1YpodzE hmBbXkut2pmvUkzE+oO5DL80t+0vmpmf8XRSwqaWMMochhbFIIBtRDFqcI+3aU6+BvYB 4i3Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=iPVDPspy; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Fun0G04+; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=OWYD69H1; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id a92af1059eb24-1b503202c0asi24255963c88.32.2026.11.15.08.43.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Nov 2026 08:43:43 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=iPVDPspy; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Fun0G04+; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=OWYD69H1; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=J878fV2KvdAW5xSMHAGKOuBsgrqKf7q6QYd7md0EMwU=; b=iPVDPspytRTMDi P/DJlMHOsKgqFNjEmfSnGnPOug/hsm+Gy9PMtFFiXcYG2XdRjU65EYwHVgW43VesccxJi4HryvbqY 9yrqf49y7Jzv/X6T6nqcTu59eMRK3gZNigId7imX97a8yR1bl/HpyA061P+qathpoufsZp4I04gya Rxs=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xSdKP-000000002mX-3vrO; Sun, 15 Nov 2026 16:43:41 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xSdKO-000000002mI-0ryg for openvpn-devel@lists.sourceforge.net; Sun, 15 Nov 2026 16:43:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=tQ87OEVZb07QuFnxcQOtNxRLfEMrSY1jSqe67dp3bxY=; b=Fun0G04+hSLaonL7ZC50zDRQsG IAGzTXg1gQw6Vo+cJQ319Mwyc8w8bmxYfQ+uuXzPC2rqJSRsc2uJNWcFzulsFHZd2kJ9LgyqKiK3p kKtXf0JjVA8BhwdZcuMGTOU0vhVy/LTf2UOlk5nLPpMxCzQ2s6Sw8XpnBFw4uf+MFu2g=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=tQ87OEVZb07QuFnxcQOtNxRLfEMrSY1jSqe67dp3bxY=; b=OWYD69H1iYxBER/6Z6K7Otl2zi jafgcl93nzOatni8f2LQqTtcuOea9/bQ3ykASQ5gu7yYjWM+K+1FdmJSKUYR6Jm9lGji+w7jcj+yn u4wJHlveqNg4Ivx/YJkrtncLnGIDyhcwcLX4PHuzFRnUsZlOJ+tqsqOe9C96h9lx0kOI=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xSdKM-000000003X8-2e7V for openvpn-devel@lists.sourceforge.net; Sun, 15 Nov 2026 16:43:40 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6AFGhVJF008525 for ; Sun, 15 Nov 2026 17:43:31 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AFGhVC7008524 for openvpn-devel@lists.sourceforge.net; Sun, 15 Nov 2026 17:43:31 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sun, 15 Nov 2026 17:43:24 +0100 Message-ID: <20261115164331.8511-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: - t_client.sh(.in): add "DragonFly" to the OS versions "like FreeBSD" - tun.c open_tun() - add DragonFly specific handling of dynamic tun/tap devices (open /dev/{tun,tap}, assigns first-free node, fdevname(fd) returns true device name) --dev tunN (and tapN) works "the o [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xSdKM-000000003X8-2e7V Subject: [Openvpn-devel] [PATCH v3] DragonFly: bring things back into a working state X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1881943334634774222 X-GMAIL-MSGID: 1881943334634774222 - t_client.sh(.in): add "DragonFly" to the OS versions "like FreeBSD" - tun.c open_tun() - add DragonFly specific handling of dynamic tun/tap devices (open /dev/{tun,tap}, assigns first-free node, fdevname(fd) returns true device name) --dev tunN (and tapN) works "the old way", by opening /dev/tunN - but only for devices pre-created with "ifconfig tun3 create" - set ioctl(TUNSIFMODE, IFF_BROADCAST=1) for "topology subnet" tun ifs -> this is sufficient to make FreeBSD "ifconfig ipv4" code work (DragonFly was broken by FreeBSD commit 94db3261659) - tun.c do_ifconfig_ipv4() - use TARGET_FREEBSD code path for DragonFly too, just amend the error message ("FreeBSD/DragonFly ifconfig failed") - tun.c do_ifconfig_ipv6() - needs "add_route_connected_v6_net()" for tun and tap(!) devices, otherwise the on-link /64 is not routed to the tun device - tun.c undo_ifconfig_ipv4(), undo_ifconfig_ipv6() - share FreeBSD code to undo IPv4/IPv6 ifconfig on precreated interfaces - add delete_route_connected_v6_net() call for DragonFly only (this is not removing fe80:: addresses from the tun if, which upsets t_client test, but for normal usage is considered "reasonably fine") - lladdr.c: add TARGET_DRAGONFLY to TARGET_FREEBSD format v1 -> v2: - fix clang-format issues - introduce TUNSIFMODE setting - revert do_ifconfig_ipv4 change from v1 (use FREEBSD code path) - use M_ERR instead of M_FATAL - gate --dev tun/tap check on --dev-node being unset v2 -> v3: - clang-format in lladdr.c and t_client.sh.in Change-Id: I5ab959e7101cf801ac93e5185855e75db0fb6225 Signed-off-by: Gert Doering Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2170 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2170 This mail reflects revision 3 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c index 8bd572a..43480f1 100644 --- a/src/openvpn/lladdr.c +++ b/src/openvpn/lladdr.c @@ -24,7 +24,7 @@ } #else /* TARGET_LINUX */ -#if defined(TARGET_OPENBSD) || defined(TARGET_FREEBSD) || defined(TARGET_DARWIN) +#if defined(TARGET_OPENBSD) || defined(TARGET_FREEBSD) || defined(TARGET_DARWIN) || defined(TARGET_DRAGONFLY) #define IFCONFIG_LLADDR_FMT "%s %s lladdr %s" #elif defined(TARGET_NETBSD) #define IFCONFIG_LLADDR_FMT "%s %s link %s active" diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 70fdd7e..c1c5548 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -979,7 +979,7 @@ #endif /* ifdef _WIN32 */ } -#if defined(_WIN32) +#if defined(_WIN32) || defined(TARGET_DRAGONFLY) /* some of the platforms will auto-add a "network route" pointing * to the interface on "ifconfig tunX 2001:db8::1/64", others need @@ -1160,6 +1160,10 @@ openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD BSD 'ifconfig inet6 -ifdisabled' failed"); #endif +#ifdef TARGET_DRAGONFLY + add_route_connected_v6_net(tt, es); +#endif + #elif defined(TARGET_AIX) argv_printf(&argv, "%s %s inet6 %s/%d mtu %d up", IFCONFIG_PATH, ifname, ifconfig_ipv6_local, tt->netbits_ipv6, tun_mtu); @@ -1490,7 +1494,7 @@ } argv_msg(M_INFO, &argv); - openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD ifconfig failed"); + openvpn_execve_check(&argv, es, S_FATAL, "FreeBSD/DragonFly ifconfig failed"); #elif defined(TARGET_AIX) { @@ -1623,14 +1627,14 @@ msg(M_WARN, "Linux can't del IP from iface %s", tt->actual_name); } } -#elif defined(TARGET_FREEBSD) +#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) struct gc_arena gc = gc_new(); const char *ifconfig_local = print_in_addr_t(tt->local, 0, &gc); struct argv argv = argv_new(); argv_printf(&argv, "%s %s %s -alias", IFCONFIG_PATH, tt->actual_name, ifconfig_local); argv_msg(M_INFO, &argv); - openvpn_execve_check(&argv, NULL, 0, "FreeBSD ip addr del failed"); + openvpn_execve_check(&argv, NULL, 0, "FreeBSD/DragonFly ip addr del failed"); argv_free(&argv); gc_free(&gc); @@ -1646,7 +1650,12 @@ { msg(M_WARN, "Linux can't del IPv6 from iface %s", tt->actual_name); } -#elif defined(TARGET_FREEBSD) +#elif defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) + +#ifdef TARGET_DRAGONFLY + delete_route_connected_v6_net(tt); +#endif + struct gc_arena gc = gc_new(); const char *ifconfig_ipv6_local = print_in6_addr(tt->local_ipv6, 0, &gc); struct argv argv = argv_new(); @@ -1655,7 +1664,7 @@ ifconfig_ipv6_local, tt->netbits_ipv6); argv_msg(M_INFO, &argv); - openvpn_execve_check(&argv, NULL, 0, "FreeBSD ip -6 addr del failed"); + openvpn_execve_check(&argv, NULL, 0, "FreeBSD/DragonFly ip -6 addr del failed"); argv_free(&argv); gc_free(&gc); @@ -2897,20 +2906,70 @@ #elif defined(TARGET_DRAGONFLY) +/* DragonFly tun/tap devices are similar to NetBSD + * - for a dynamic tun/tap, open /dev/tun or /dev/tap, get assigned + * the first free device, ask with (f)devname(3) what you got, and + * the interface will auto-destruct on close + * - for a pre-created tun/tap, open "/dev/tun3" + * - using "--dev tun3" and have it dynamically created needs a call + * to "ifconfig tun3 create" which we don't currently do + */ + void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt, openvpn_net_ctx_t *ctx) { - open_tun_generic(dev, dev_type, dev_node, tt); - - if (tt->fd >= 0) + if (!dev_node && (strcmp(dev, "tap") == 0 || strcmp(dev, "tun") == 0)) { - int i = 0; + char tunname[256]; + snprintf(tunname, sizeof(tunname), "/dev/%s", dev); - /* Disable extended modes */ + if ((tt->fd = open(tunname, O_RDWR)) < 0) + { + msg(M_ERR, "Cannot allocate DragonFly TUN/TAP %s dynamically", tunname); + } + + char *devname = fdevname(tt->fd); + if (devname == NULL) + { + msg(M_ERR, "Cannot query DragonFly TUN/TAP device name"); + } + set_nonblock(tt->fd); + set_cloexec(tt->fd); /* don't pass fd to scripts */ + msg(M_INFO, "TUN/TAP device %s opened", devname); + + tt->actual_name = string_alloc(devname, NULL); + } + else + { + open_tun_generic(dev, dev_type, dev_node, tt); + } + + if (tt->fd >= 0 && tt->type == DEV_TYPE_TUN) + { + /* see "Interface Flags" in ifnet(9) */ + int i = IFF_POINTOPOINT | IFF_MULTICAST; + if (tt->topology == TOP_SUBNET) + { + i = IFF_BROADCAST | IFF_MULTICAST; + } + + if (ioctl(tt->fd, TUNSIFMODE, &i) < 0) + { + msg(M_WARN | M_ERRNO, "ioctl(TUNSIFMODE)"); + } + + /* Disable "link layer" mode (would prepend route-nexthop address + * on read, but is incompatible with TUNSIFHEAD multi-af mode) */ + i = 0; ioctl(tt->fd, TUNSLMODE, &i); + + /* multi_af mode for v4+v6, see "tun(4)" */ i = 1; - ioctl(tt->fd, TUNSIFHEAD, &i); + if (ioctl(tt->fd, TUNSIFHEAD, &i) < 0) + { + msg(M_WARN | M_ERRNO, "ioctl(TUNSIFHEAD)"); + } } } diff --git a/tests/t_client.sh.in b/tests/t_client.sh.in index 5e924bb..d81cef0 100755 --- a/tests/t_client.sh.in +++ b/tests/t_client.sh.in @@ -212,8 +212,8 @@ LANG=C @NETSTAT@ -rn -4 -6 fi ;; - FreeBSD | NetBSD | Darwin) - echo "-- FreeBSD/NetBSD/Darwin [MacOS X] --" + FreeBSD | DragonFly | NetBSD | Darwin) + echo "-- FreeBSD/DragonFly/NetBSD/Darwin [MacOS X] --" @IFCONFIG@ -a | egrep "(flags=|inet)" @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }' ;;