From patchwork Tue Oct 21 07:08:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4522 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:7d42:b0:72f:f16c:e055 with SMTP id fr2csp6480328mab; Tue, 21 Oct 2025 00:08:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVtTaG+U8t114gKAfAV1saX1argULeLxVYAqJDIrHgD4lvVAHTQnq3AJd2Tb+KeDKYFnoJtBBSZjzI=@openvpn.net X-Google-Smtp-Source: AGHT+IGY1Gw6sXOl3YPsVaXia/++dntDA5jfFZ/rWZD2sL47kXikiRxAq5FnuiSBwHDfun7phCMz X-Received: by 2002:a05:6808:320a:b0:443:4144:ca09 with SMTP id 5614622812f47-443a2e15e1amr7084807b6e.16.1761030523746; Tue, 21 Oct 2025 00:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1761030523; cv=none; d=google.com; s=arc-20240605; b=LuSqjJf33IM5TkwCt5NKGciwbqigBs/GnuNr8zU4Rxyzb3xzw6CJhHQug6S8TDjo2D iXkg2FgPiaSMEHSmyKG7HQ3OUaAnTJV76ri4/3rpdEgbmPZY/yh8+BgvIjUwgsWdaUbu Yp9HpVX+H+CV7+QyH0KTmR/bdY4Um0qxbWNvy/3Y+KRO1MkkOkzSaE9TBHKfpGnQtks9 1dgqzG1XhVBlY+MvaiKhZhiL9E6BqXC73JCwkRYMZ1MI1Q2DVe9U19T9I/TAhwbPLdVI k7KpjLKJaqSFpi4VSfL00oCcXEHeq/Ohtg7D4bURRSe84F3ISUQt+PMRvdkdhqzg11oG 7wnQ== 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:dkim-signature; bh=kKhnwucbxOnAzokM37bxsrNWe/yfH0RpYQwSNYwUJQ4=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=U5oi/C9OKPaxaWGTQKTdMdCnQjZf9Zfo+i6WSFmiJItL8wKoPXysdRnWQKhAWOicX0 ntZ3ITeUCI2omk0sKpzQ1bdgYaJM68l13QlmjiUM++HGIym+XMlomq3KWlcDxySXmanN /ulwblNILOLUmTDyctdmEusvy0iGxbXkJHGKRi9ZKyQOKfu0wwqgnwe+ZD2fP+9Ygl7n hXizkOutloL4Q6nz3enJEn57b4Xbg4RHLgc2WUKES193miuzaNXy/mDi0wXnOOv65mEn XQ2oDu0R6EAXp09qt3hVitQw/0CjRwYKVxnF+Wpsv8BY1zo7RtXdyxCPoJT8b8rLQCQg L9nw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=hsM0nKuR; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=jOXYNw0M; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=W9dq0d7t; 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 5614622812f47-443dc4ced5fsi2102142b6e.34.2025.10.21.00.08.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Oct 2025 00:08:43 -0700 (PDT) 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=hsM0nKuR; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=jOXYNw0M; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=W9dq0d7t; 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-Owner; bh=kKhnwucbxOnAzokM37bxsrNWe/yfH0RpYQwSNYwUJQ4=; b=hsM0nKuR7yRpaSYzdFjqf1ESWT hthXXtqo7KlwnWKUub+Ga1d0JaWUdL68FxHN49fyPC7dM6szstZfCKurCZUYKYPVGOmhJw6yiiugu Cg4a2BhPAP4jBaPum7GRk1J/OtF7tcvlQNElnPSsFudwyRY/Z1eY3cGr5i70aoKPTiRE=; 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 1vB6U3-0001Yq-9b; Tue, 21 Oct 2025 07:08:40 +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 1vB6U2-0001Yg-IP for openvpn-devel@lists.sourceforge.net; Tue, 21 Oct 2025 07:08:39 +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=tgyBHSBgnuQyb3zvI95r7QooORDwH9xHZT8PUszsOvU=; b=jOXYNw0MPu3CuL/yiOfh22FQCP wLcI08jEP1Jf3ukQtS9mK951TbFCFlAU/J7CWrcXjDky2cPgk9JFNFM2d0TkZH0xZne9eMGdece8C dr5O2pCDh27EEqxbvcDb+dKhahTMQx9PMLwPC+82yybLK3DRvG2/H0wJppohPREWA7gg=; 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=tgyBHSBgnuQyb3zvI95r7QooORDwH9xHZT8PUszsOvU=; b=W9dq0d7tBJkhvMVE0py5BzUphH uq/+3sc5Y/D9ee5zvsawUgRAm9KFoZg4nCMLuatnElmEmjV34UmWFzoJazulk2DsVO0QcKUdPE974 xhf4j+o3mJImLApgDn7OrHtziTzcP8zwD77XVRZd3Kfrm3tyK0aQ0kRgPZxeiZSfwypk=; Received: from [193.149.48.134] (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 1vB6U2-0006ef-AX for openvpn-devel@lists.sourceforge.net; Tue, 21 Oct 2025 07:08:39 +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 59L78Qcm020797 for ; Tue, 21 Oct 2025 09:08:26 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 59L78QAr020796 for openvpn-devel@lists.sourceforge.net; Tue, 21 Oct 2025 09:08:26 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 21 Oct 2025 09:08:20 +0200 Message-ID: <20251021070825.20773-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 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: Ralf Lici The BYTECOUNT notification is expected to be emitted every N seconds when a management client issues the 'bytecount N' command. However, the server currently relies on timeouts from unrelated periodic [...] 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: 1vB6U2-0006ef-AX Subject: [Openvpn-devel] [PATCH v2] management: ensure consistent BYTECOUNT timing on server 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?1846574342168551149?= X-GMAIL-MSGID: =?utf-8?q?1846574342168551149?= From: Ralf Lici The BYTECOUNT notification is expected to be emitted every N seconds when a management client issues the 'bytecount N' command. However, the server currently relies on timeouts from unrelated periodic operations, resulting in irregular notification timing. This issue is especially noticeable with low bytecount intervals and DCO enabled, as openvpn handles less traffic in userspace, causing the main loop to run less frequently. To address this, refactor the timeout logic and pass the timeval reference to management_check_bytecount_server so that the timeout is correctly set and notifications adhere to the specified interval. Change-Id: Ifb1c49fce75e671f699f5db5f6da7246f6e0b519 Signed-off-by: Ralf Lici Acked-by: Lev Stipakov --- 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/+/1285 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Lev Stipakov diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 1cb5c63..685b137 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -4184,16 +4184,14 @@ } void -management_check_bytecount_server(struct multi_context *multi) +management_check_bytecount_server(struct multi_context *multi, struct timeval *timeval) { if (!(management->persist.callback.flags & MCF_SERVER)) { return; } - struct timeval null; - CLEAR(null); - if (event_timeout_trigger(&management->connection.bytecount_update_interval, &null, ETT_DEFAULT)) + if (event_timeout_trigger(&management->connection.bytecount_update_interval, timeval, ETT_DEFAULT)) { /* fetch counters from dco */ if (dco_enabled(&multi->top.options)) diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index a31eb06..fe460bf 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -493,7 +493,7 @@ void management_check_bytecount_client(struct context *c, struct management *man, struct timeval *timeval); -void management_check_bytecount_server(struct multi_context *multi); +void management_check_bytecount_server(struct multi_context *multi, struct timeval *timeval); void man_persist_client_stats(struct management *man, struct context *c); diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index e907524..d512c98 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -3809,13 +3809,6 @@ { check_stale_routes(m); } - -#ifdef ENABLE_MANAGEMENT - if (management) - { - management_check_bytecount_server(m); - } -#endif /* ENABLE_MANAGEMENT */ } static void @@ -4166,6 +4159,29 @@ ASSERT(mi->context.c2.tls_multi->peer_id < m->max_clients); } +/** + * @brief Determines the earliest wakeup interval based on periodic operations. + * + * Updates the \c timeval to reflect the next scheduled wakeup time. + * Also sets \c multi->earliest_wakeup to the instance with the earliest wakeup. + * + * @param multi Pointer to the multi context + * @param timeval Pointer to the timeval structure to be updated with the + * next wakeup time + */ +static void +multi_get_timeout(struct multi_context *multi, struct timeval *timeval) +{ + multi_get_timeout_instance(multi, timeval); + +#ifdef ENABLE_MANAGEMENT + if (management) + { + management_check_bytecount_server(multi, timeval); + } +#endif /* ENABLE_MANAGEMENT */ +} + /**************************************************************************/ /** * Main event loop for OpenVPN in point-to-multipoint server mode. diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 97bbc4a..960e0be 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -582,15 +582,16 @@ } /* - * Compute earliest timeout expiry from the set of - * all instances. Output: + * Updates \c dest with the earliest timeout as a delta relative to the current + * time and sets \c m->earliest_wakeup to the \c multi_instance with the + * soonest scheduled wakeup. * - * m->earliest_wakeup : instance needing the earliest service. - * dest : earliest timeout as a delta in relation - * to current time. + * @param m Pointer to the multi context + * @param dest Pointer to a timeval struct that will hold the earliest timeout + * delta. */ static inline void -multi_get_timeout(struct multi_context *m, struct timeval *dest) +multi_get_timeout_instance(struct multi_context *m, struct timeval *dest) { struct timeval tv, current;