From patchwork Sun Nov 22 13:53:56 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5765 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp1615387lad; Sun, 22 Nov 2026 05:54:15 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFwYb30CLg0mbrGguaLUyKHrXcPHVKDXPzQC4mmopvICpJPmTyrr3p05/kE41KoprKaFBYwhujhFVQ=@openvpn.net X-Received: by 2002:a05:7301:2222:b0:384:2662:a7fe with SMTP id 5a478bee46e88-3856c9a1180mr8098120eec.1.1795355655490; Sun, 22 Nov 2026 05:54:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795355655; cv=none; d=google.com; s=arc-20260327; b=tBvlyZpI1eBT/EA92F0zQgH0W2ZmcOGIEYyl75bs7vIKrrLmqoJDzxzlGTYClyyytL LTTIcFAOSCIwoU/KpJt7ngz3OQLo64aIAPC6r9sO48c31nCWgqBLxmaGt1TleeC1YzXV XwMB8kyYe3E1I6WW/k2Dc63Fyf+tjLUCTkKrZCDUsKYIsR5LA79FG1AJUYKr15hJ4vLl Lwi3db/cCp20ALHYG3updvaQE2ZSDJgjIZnAY4gRPfJPyQ93fGF5jjCY4eULuigMJcf4 eyJ72UIgNogvl/5M7501b3LlnprdjNjZ162Frh8w7EaBvupQMplqHktr6RGsveMdk2Cj k14g== 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=P2Jyd1HKrhcOb0RfzrEBrHNQ85q/wUo7zR+FZERq4TM=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=ARhSf4Z7HSJmBOmZy2T8LkrkUu9WC1yTzVF824qpRVddXtAL8ZGd4KafzW34UetBYK OSbp1QE/MMXmEIij0NVRoM+o3ruWeMBJ7VXp1qD+J2NG3BqPey10GLGNaze3Bc/XWske B3dy/+2jXZaKr5rqiKzEUdH/CZ11Hnw15yz8BpYK22y8e0Gbgt3GNvZ6E33J4mWGUdti ZR+U2eoE0gMWDmMv/+YiLStGdqaEtQgl6vX9HZsiTR9rY8XDAJkTv8hfuZbg07P5cT8y Z3fGG3ANfpGhpvmSOhC3EWWhl3HiHQffoKMKmSbFm18Zss4nxd8JTtGu7pPDAAKNKyOz LohA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=BcDC4NDD; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=iVChCxc6; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=HCHXeGTT; 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 5a478bee46e88-38564768160si33885163eec.3.2026.11.22.05.54.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Nov 2026 05:54:15 -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=BcDC4NDD; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=iVChCxc6; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=HCHXeGTT; 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=P2Jyd1HKrhcOb0RfzrEBrHNQ85q/wUo7zR+FZERq4TM=; b=BcDC4NDDWaZNmj XUSBgG+GzcYsJFR/NjT+tlya1LaTwYCa658NFuGDpyde9d6npGoBtGexiq7d9vpaRvCBlAXTeXZoU WDeUeRtaUMKHnU9BRJCNqky3+EGFrDS8mF3TxlFP1OF/XoRuSZq7xJxfmC1VHNuxdHYxIkfsWK/g3 i+k=; 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 1xV81D-000000008S1-36ME; Sun, 22 Nov 2026 13:54:11 +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 1xV81D-000000008Rs-0dYO for openvpn-devel@lists.sourceforge.net; Sun, 22 Nov 2026 13:54:11 +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=uvVspdnWVqOwvrEx2vrDaCMp/2kZT6IFFU69EV78Xzw=; b=iVChCxc6KDbPUTHHyzTxipPlDM UEZWmwnRcNnxc/5+zjznDPK3i93tWQh+aPtsHK1QoUSWwS6AWBI7Nnx7JLKBuAqliYn1yHQmR9wzJ YXgR4Wpouyo00mJYPcY+EQazXtUG1RSQft1uPI5j2lU3h+CLqBYCWsyZRxLStFHXna3A=; 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=uvVspdnWVqOwvrEx2vrDaCMp/2kZT6IFFU69EV78Xzw=; b=HCHXeGTTK3Zporxe4VUYZXcZif olrnlf70HDzioM70hqvgcaMtl/vz/EnJQhtFJHfLSxbWFZeIpEVjfrHOIvU+WRonppqcD56V76CDi FO2Ikmn0rys9EVi4fLpk+FwgjtNXAxaqfwjBlvLRW6q2YA6gXxkJ6ssjG7BXga/th6OM=; 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 1xV81B-000000001gM-3QHJ for openvpn-devel@lists.sourceforge.net; Sun, 22 Nov 2026 13:54:11 +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 6AMDs2Lc012183 for ; Sun, 22 Nov 2026 14:54:02 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AMDs2CP012182 for openvpn-devel@lists.sourceforge.net; Sun, 22 Nov 2026 14:54:02 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sun, 22 Nov 2026 14:53:56 +0100 Message-ID: <20261122135402.12147-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: From: Lev Stipakov create_socket_udp_configured()'s "optional" argument covers only the socket() call: socket_bind() is fatal, so a caller that can do without the socket still dies if the address is unavailable. Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URI: openvpn.net] 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xV81B-000000001gM-3QHJ Subject: [Openvpn-devel] [PATCH v12] socket: Let an optional UDP socket give up on a failed bind 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: 1882566851941208398 X-GMAIL-MSGID: 1882566851941208398 From: Lev Stipakov create_socket_udp_configured()'s "optional" argument covers only the socket() call: socket_bind() is fatal, so a caller that can do without the socket still dies if the address is unavailable. That is a problem for the upcoming --server-probe, which binds a probe socket for every address family in use, while a connection binds only the family of the remote it is about to try. A --lport whose IPv6 port happens to be taken by another process would therefore kill a client that could have connected over IPv4. Give socket_bind() a msglevel and a return value, and let "optional" apply to the bind as well: the socket is closed and SOCKET_UNDEFINED is returned, so the caller can skip that address family. Every existing caller passes M_FATAL and keeps its behaviour. The failure message now reports the address that was actually bound, cur, rather than the head of the list, local, which may belong to a different address family. Until now that message was always followed by a fatal exit; with an optional bind it is printed while the client carries on, so it needs to name the right address. Change-Id: I24e5925a72aaede53ef9e863fe96fcd7363df402 Signed-off-by: Lev Stipakov Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1915 --- 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/+/1915 This mail reflects revision 12 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 58f63e6..013d516 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -2105,7 +2105,7 @@ { man->connection.sd_top = create_socket_tcp(man->settings.local); socket_bind(man->connection.sd_top, man->settings.local, man->settings.local->ai_family, - "MANAGEMENT", false); + "MANAGEMENT", false, M_FATAL); } /* diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 307b5c6..c7de904 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -268,12 +268,13 @@ { if (sock->socks_proxy && sock->info.proto == PROTO_UDP) { - socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, sock->info.af, "SOCKS", false); + socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, sock->info.af, "SOCKS", false, + M_FATAL); } else { socket_bind(sock->sd, sock->info.lsa->bind_local, sock->info.af, "TCP/UDP", - sock->info.bind_ipv6_only); + sock->info.bind_ipv6_only, M_FATAL); } } } @@ -319,9 +320,11 @@ } socket_apply_options(sd, sbs, mark, bind_dev); - if (bind_addr) + if (bind_addr + && !socket_bind(sd, bind_addr, af, "TCP/UDP", bind_ipv6_only, optional ? D_LOW : M_FATAL)) { - socket_bind(sd, bind_addr, af, "TCP/UDP", bind_ipv6_only); + openvpn_close_socket(sd); + return SOCKET_UNDEFINED; } return sd; } @@ -556,9 +559,9 @@ return new_sd; } -void +bool socket_bind(socket_descriptor_t sd, const struct addrinfo *local, int ai_family, - const char *prefix, bool ipv6only) + const char *prefix, bool ipv6only, msglvl_t msglevel) { struct gc_arena gc = gc_new(); @@ -582,8 +585,10 @@ } if (!cur) { - msg(M_FATAL, "%s: Socket bind failed: Addr to bind has no %s record", prefix, + msg(msglevel, "%s: Socket bind failed: Addr to bind has no %s record", prefix, addr_family_name(ai_family)); + gc_free(&gc); + return false; } if (ai_family == AF_INET6) @@ -598,10 +603,13 @@ } if (openvpn_bind(sd, cur->ai_addr, cur->ai_addrlen)) { - msg(M_FATAL | M_ERRNO, "%s: Socket bind failed on local address %s", prefix, - print_sockaddr_ex(local->ai_addr, ":", PS_SHOW_PORT, &gc)); + msg(msglevel | M_ERRNO, "%s: Socket bind failed on local address %s", prefix, + print_sockaddr_ex(cur->ai_addr, ":", PS_SHOW_PORT, &gc)); + gc_free(&gc); + return false; } gc_free(&gc); + return true; } int diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index 52e09c9..88c51fa 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -337,8 +337,15 @@ struct link_socket *link_socket_new(void); -void socket_bind(socket_descriptor_t sd, const struct addrinfo *local, int af_family, - const char *prefix, bool ipv6only); +/** + * Bind @p sd to the first @p af_family address of @p local. A failure is + * reported at @p msglevel, so a caller that can do without the bind passes a + * non-fatal level and checks the result. + * + * @return whether the socket was bound + */ +bool socket_bind(socket_descriptor_t sd, const struct addrinfo *local, int af_family, + const char *prefix, bool ipv6only, msglvl_t msglevel); int openvpn_connect(socket_descriptor_t sd, const struct sockaddr *remote, int connect_timeout, volatile int *signal_received); @@ -392,9 +399,9 @@ * Create a UDP socket for @p af set up the way a link socket is: --sndbuf/--rcvbuf, * --mark, --bind-dev and, when @p bind_addr is given, the local bind (IPV6_V6ONLY * per @p bind_ipv6_only). Shared by create_socket() and the --server-probe sockets, - * so a probe socket is the connection socket it may become. A failed bind is - * fatal; with @p optional a socket the host cannot create is not, so - * --server-probe can skip that address family (SOCKET_UNDEFINED is returned). + * so a probe socket is the connection socket it may become. With @p optional a + * socket the host cannot create or bind is not fatal, so --server-probe can skip + * that address family (SOCKET_UNDEFINED is returned). */ socket_descriptor_t create_socket_udp_configured(sa_family_t af, unsigned int sockflags, const struct socket_buffer_size *sbs, int mark,