From patchwork Sat Nov 14 22:15:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5703 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:3119:b0:11a:a05e:cb97 with SMTP id e25csp1125433laa; Sat, 14 Nov 2026 14:16:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErF2t+9ogSpEVC4bqmyPcWfdlekFkG9CFyaY4j8YNObGWMIiH8NBdHSVfeDh4FcvDi/IOJL7iav5ncE=@openvpn.net X-Received: by 2002:a05:701b:21c3:b0:1b3:a8a3:c6de with SMTP id a92af1059eb24-1b50306c4e1mr6505041c88.5.1794694564964; Sat, 14 Nov 2026 14:16:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794694564; cv=none; d=google.com; s=arc-20260327; b=jsKyB4NJaOJmVNIffR/HAtTr2Ng2sFUjN7nFYcQk+Ip2+VaTqYf+JVohg1YeaYcQTe FG1LAZ/eVs9ibei4A6wKu//BD6Wf3wyK9Xs7wFlY9wfPh11wNHqMyJXox9uy9LTuPm+N 39yISkHFRJIA7jNeH2ewbwkKEMDlBxp4KA71G6hdHeAFu6EwrOthdPvpgEnMKd7Hcl5H paVUJUIbqrTblQ+NXhr6Cv0Sh+lT4RA5hgYocTRoVwcs1NlYJsEpYWl3EkkzdNOeob6P 99rnArKjaPUowWaq1Y+PbDeMOWb6G9U1H4WQV6AEdemheMb3KX/CM4l2Q+E2zknfGtrn UaCw== 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=kLy2zTsYK3315fdzVfIte06VTKLMDuIHSabhascbsE0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=Pt+mt+0ZNiqn5O4c72OkLrpWNP72aFcAtEfwXN12DrzZfL/z53bVLv3B184z11m5yA vTaD9GDfbdm0hOqgoQrR5czu6zlS09uIVlmgYPbpH/bu7Dgk7iyL80cu/742NGs9npl8 bYWV7DeYwRdu0RoXlasXUGH3s3vFjliFAEfqA5qi6WjAookPZOtrheNex2PYjQxZAM2J oZuTeT0LFzbzI90GpG42tg+vejo5G2JYkIrdvj7y9/li/5HT/QA8vK5ecL14j1bszyeS hvjFAwijguHvHIzg4brenpQkooGTRAKkAndo1UZOBSYYpzSWzpd6xjJ3wSK27PObZIxp uByA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=W+SMSo1y; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=hSrv3kBq; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Z7SfA/f+"; 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-1b50320c05dsi17963859c88.41.2026.11.14.14.16.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Nov 2026 14:16:04 -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=W+SMSo1y; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=hSrv3kBq; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Z7SfA/f+"; 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=kLy2zTsYK3315fdzVfIte06VTKLMDuIHSabhascbsE0=; b=W+SMSo1y0YW71t hrXJRBuynzTPnlHHq9SBIzhAYesqnWLhBKnS0xRSk8gAdyk4/w2s81v7SpgsrcULmLsMd56emGjmI zLJ4RSn2qpcjK5YGt3iptAJjF7PUh0RXO5DNIkXhrleNc+bNgMvNb7AcsSwetKHGLsULpa2z7l0FW dBY=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xSM2R-000000005kh-3Tsd; Sat, 14 Nov 2026 22:15:59 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xSM2Q-000000005kZ-0yGi for openvpn-devel@lists.sourceforge.net; Sat, 14 Nov 2026 22:15:58 +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=QPrLyZrJ5YpMm0grCkxYMq6fWoT9s51XlNCX85VOe14=; b=hSrv3kBq5l24F2/QwZDno24SUk 4iZ6w/9d/xUPu9ZPuGi5vOFbi6YWKEBWbcoR+EosNtygHa1uWGuGMMkTDhr/wLGsaY1pGSVDNKd10 EpwvwAUuNRnq3bOH5ZM5FR/yQ0ZDCxd69h9fegT8LJwgiKAFoKa1/2s4wBwU4H6C+lBM=; 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=QPrLyZrJ5YpMm0grCkxYMq6fWoT9s51XlNCX85VOe14=; b=Z7SfA/f+LNC0yzbsubYqoBGgr1 dib8zjLYXLQqrsI5x9+3HeqtK+ktkDkc8jxjfRVQh4OliReZI7DTSafAtZfpNXFwjykez8Zhs/J28 MkUGj4Nlm+TbSnmx9RneAs9eF2iyil4yAyrO5gW2tBx97GCzSby+rAerPD3mhdIPVxUk=; 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 1xSM2O-000000007Rv-3Vgz for openvpn-devel@lists.sourceforge.net; Sat, 14 Nov 2026 22:15:58 +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 6AEMFnrP007036 for ; Sat, 14 Nov 2026 23:15:49 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AEMFnox007034 for openvpn-devel@lists.sourceforge.net; Sat, 14 Nov 2026 23:15:49 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sat, 14 Nov 2026 23:15:43 +0100 Message-ID: <20261114221549.7019-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-2.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: Razvan Cojocaru ifconfig_pool_acquire() duplicated the address calculation of ifconfig_pool_handle_to_ip_base() and ifconfig_pool_handle_to_ipv6_base(). Use those instead, and add in6_addr_low32() for the three open- [...] 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: 1xSM2O-000000007Rv-3Vgz Subject: [Openvpn-devel] [PATCH v1] pool: reuse handle-to-address helpers in ifconfig_pool_acquire() 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: 1881873648579570508 X-GMAIL-MSGID: 1881873648579570508 From: Razvan Cojocaru ifconfig_pool_acquire() duplicated the address calculation of ifconfig_pool_handle_to_ip_base() and ifconfig_pool_handle_to_ipv6_base(). Use those instead, and add in6_addr_low32() for the three open-coded conversions of the last 32 bits of an IPv6 address. Its uint32_t casts also avoid shifting an int into the sign bit. Change-Id: I0f8ea4fa572f84e6dcc9b0806c23977c64ea645d Signed-off-by: Razvan Cojocaru Acked-by: Antonio Quartulli Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2126 --- 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/+/2126 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Antonio Quartulli diff --git a/src/openvpn/pool.c b/src/openvpn/pool.c index fff0e3f..7978f93 100644 --- a/src/openvpn/pool.c +++ b/src/openvpn/pool.c @@ -35,6 +35,20 @@ #include "memdbg.h" +static in_addr_t ifconfig_pool_handle_to_ip_base(const struct ifconfig_pool *pool, + ifconfig_pool_handle hand); + +static struct in6_addr ifconfig_pool_handle_to_ipv6_base(const struct ifconfig_pool *pool, + ifconfig_pool_handle hand); + +/* Return the last 32 bits of an IPv6 address in host byte order */ +static inline uint32_t +in6_addr_low32(const struct in6_addr *a) +{ + return ((uint32_t)a->s6_addr[12] << 24) | ((uint32_t)a->s6_addr[13] << 16) + | ((uint32_t)a->s6_addr[14] << 8) | a->s6_addr[15]; +} + static void ifconfig_pool_entry_free(struct ifconfig_pool_entry *ipe, bool hard) { @@ -192,8 +206,7 @@ * 4 bytes, therefore we can just extract that and use it as base in * integer form */ - uint32_t base = (ipv6_base.s6_addr[12] << 24) | (ipv6_base.s6_addr[13] << 16) - | (ipv6_base.s6_addr[14] << 8) | ipv6_base.s6_addr[15]; + uint32_t base = in6_addr_low32(&ipv6_base); /* some bits of the last 4 bytes may still be part of the network * portion of the address, therefore we need to set them to 0 */ @@ -314,33 +327,22 @@ if (pool->ipv4.enabled && local && remote) { - switch (pool->ipv4.type) + const in_addr_t b = ifconfig_pool_handle_to_ip_base(pool, i); + if (pool->ipv4.type == IFCONFIG_POOL_30NET) { - case IFCONFIG_POOL_30NET: - { - in_addr_t b = pool->ipv4.base + (i << 2); - *local = b + 1; - *remote = b + 2; - break; - } - - case IFCONFIG_POOL_INDIV: - { - in_addr_t b = pool->ipv4.base + i; - *local = 0; - *remote = b; - break; - } - - default: - ASSERT(0); + *local = b + 1; + *remote = b + 2; + } + else + { + *local = 0; + *remote = b; } } - /* IPv6 pools are always INDIV (--linear) */ if (pool->ipv6.enabled && remote_ipv6) { - *remote_ipv6 = add_in6_addr(pool->ipv6.base, i); + *remote_ipv6 = ifconfig_pool_handle_to_ipv6_base(pool, i); } } return i; @@ -415,11 +417,8 @@ } } - base = (pool->ipv6.base.s6_addr[12] << 24) | (pool->ipv6.base.s6_addr[13] << 16) - | (pool->ipv6.base.s6_addr[14] << 8) | pool->ipv6.base.s6_addr[15]; - - addr = (in_addr->s6_addr[12] << 24) | (in_addr->s6_addr[13] << 16) | (in_addr->s6_addr[14] << 8) - | in_addr->s6_addr[15]; + base = in6_addr_low32(&pool->ipv6.base); + addr = in6_addr_low32(in_addr); ret = addr - base; if (ret < 0 || ret >= pool->size)