From patchwork Fri Dec 27 16:17:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4027 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:998b:b0:5e7:b9eb:58e8 with SMTP id d11csp6317496mav; Fri, 27 Dec 2024 08:18:21 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVtwnGztxHlsh/Sb0/edCKdKVONauvfp4L7VNLIw1rFi8Np5vc40+R9Qs4MZ/f6SkSUcmSTSMEs0rA=@openvpn.net X-Google-Smtp-Source: AGHT+IFBTII43A5yQKEG7zw+Zs7ko3nozMkiq2ldrT7Tn2YGL8j1CePG0OfpE1imeidydB2QRtK3 X-Received: by 2002:a05:6808:444b:b0:3eb:7399:29d3 with SMTP id 5614622812f47-3ed8fdd3860mr15632883b6e.43.1735316300775; Fri, 27 Dec 2024 08:18:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735316300; cv=none; d=google.com; s=arc-20240605; b=I2zlYGJdqc36x10SKrt6tviOxzCsPOhcNH+v+ByJfUDFGDS2wpANxkODBYU9hATYKL NAmPr+nNcBXEAvLHpzkNgO2NkmHH5jYgmLUieZl28U6EoOYkTqsIX4SACWmlk1cy02M5 oX1TlcjzZRDcz1tTYUwE8Hvk9y6AzZdC7LOO4me89BsjRtgfLAmhn7y/LBn+D5XjGeDV 3sSFTCsGlqUrRC4G8iwqUY4/24yJInoYxMqpDydRmvi8apztT1NLBkx+watLVD+hczuA xzSNFLEWqR4ZlSzMHwH/IzoQ81yXnCtbgZ4ISvtoZxX2HbExYSeTCaGhhdQebJ49Fu4F nx1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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; bh=L1knj1VoUwaJZoS0sSXSt3brENeLFt7ZCiQSioOafGk=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=Tdf5n5LhFzZ7Hdodoiu8ML4V0n0oKZg9h0iQtqHmGWq/d8I5M+QyeO/wO5QLh4h6At sfKr+VtXW6bkZQwqsGCW1UsG4wlSzte/5w/RgfOfKP0qyjpe/G3O1u7CQkTowFMaqbfA U+M0l5E7hW9ZTiTXevamqNhuOl3Ux9zKBRN0iM6p3OkB6cXsFxiC/2zM9rMogBsf9TvB 6AzqdyVKX3DaT8cVhfmiq+BtJdwiuyzF0huunS+5+1eJY5jmO+Iqx8fB21zy1EaPMZWp mnBBwnp5yQu/vPjuGc3Gr1ejM+4nJWKUxevVDUvmoJWlngHEcVvlr//6whYptaBmEviQ FbBg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Boxpr3Ea; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=YjX7EQQs; 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 46e09a7af769-71fc9a1e002si12947009a34.252.2024.12.27.08.18.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Dec 2024 08:18:20 -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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Boxpr3Ea; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=YjX7EQQs; 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 [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tRD2X-00082k-DV; Fri, 27 Dec 2024 16:18:17 +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.95) (envelope-from ) id 1tRD2T-000823-4S for openvpn-devel@lists.sourceforge.net; Fri, 27 Dec 2024 16:18:13 +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-Subscribe:List-Post:List-Owner:List-Archive; bh=735Id0EvIBbkSpEKMniagPrR+OKzD4nbXODEagwsn3s=; b=Boxpr3Eaf6K53/CSVEA00YmlM0 WDcYkl3qcLjEUkNkQBubDZ298BdztoWvxCUmCEzQNNAzxwPSy2NV8GBd07PtH64PcYKmUGgDM3mSV beBWZGHoFdoHiZKcoAtsK6IoqmKn8FnhG36t14MiHSIgjNWR6fLOkjPApUH1jvjgP50o=; 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-Subscribe: List-Post:List-Owner:List-Archive; bh=735Id0EvIBbkSpEKMniagPrR+OKzD4nbXODEagwsn3s=; b=YjX7EQQsCFSzwDLvnI1ddIyeoM fu1DicZbLZFfpHuE/Mm4UYPV16QnhkzuT9lnkugu/gcVpWkGKMaBpoRANlBm6L0Cqy+RBVGAA+IBU oSdKmzV3ohNFxn+H6YxOj5K0zUqsmkJjB2m19UrUD08P2Rzoa4H9qr+4XthEnPeqq1VQ=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tRD2N-0004GV-Cu for openvpn-devel@lists.sourceforge.net; Fri, 27 Dec 2024 16:18:08 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 4BRGHthV004020 for ; Fri, 27 Dec 2024 17:17:55 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 4BRGHtMc004019 for openvpn-devel@lists.sourceforge.net; Fri, 27 Dec 2024 17:17:55 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Fri, 27 Dec 2024 17:17:55 +0100 Message-ID: <20241227161755.4010-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", 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: Antonio Quartulli This change ensures that when a numeric IP address is specified as argument to a 'local' directive, its ai_family overrides the one extracted from the 'proto' config option. Content analysis details: (0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in bl.score.senderscore.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-Headers-End: 1tRD2N-0004GV-Cu Subject: [Openvpn-devel] [PATCH v9] override ai_family if 'local' numeric address was specified 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: =?utf-8?q?1819324054327917395?= X-GMAIL-MSGID: =?utf-8?q?1819611025335370456?= From: Antonio Quartulli This change ensures that when a numeric IP address is specified as argument to a 'local' directive, its ai_family overrides the one extracted from the 'proto' config option. Change-Id: Ie2471e6b2d6974e70423b09918ad1c2136253754 Signed-off-by: Antonio Quartulli Signed-off-by: Gianmarco De Gregori Acked-by: Gert Doering --- 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/+/762 This mail reflects revision 9 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 7921433..b84521a 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -488,9 +488,8 @@ sig_info = &sigrec; } - /* try numeric ipv6 addr first */ + /* try numeric ip addr first */ CLEAR(hints); - hints.ai_family = ai_family; hints.ai_flags = AI_NUMERICHOST; if (flags & GETADDR_PASSIVE) @@ -507,6 +506,13 @@ hints.ai_socktype = SOCK_STREAM; } + /* if hostname is not set, we want to bind to 'ANY', with + * the correct address family - v4-only or v6/v6-dual-stack */ + if (!hostname) + { + hints.ai_family = ai_family; + } + status = getaddrinfo(hostname, servname, &hints, res); if (status != 0) /* parse as numeric address failed? */ @@ -518,6 +524,10 @@ const char *fmt; int level = 0; + /* this is not a numeric IP, therefore force resolution using the + * provided ai_family */ + hints.ai_family = ai_family; + if (hostname && (flags & GETADDR_RANDOMIZE)) { hostname = hostname_randomize(hostname, &gc); @@ -1716,6 +1726,10 @@ sock->local_host, sock->local_port, gai_strerror(status)); } + + /* the resolved 'local entry' might have a different family than what + * was globally configured */ + sock->info.af = sock->info.lsa->bind_local->ai_family; } gc_free(&gc);