From patchwork Tue Oct 28 18:43:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4537 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:2995:b0:72f:f16c:e055 with SMTP id f21csp2248860max; Tue, 28 Oct 2025 11:43:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXfR9gs3tvKT/qHCqbRsngMxh2QLXBEH7JUS/gxB7Ct2K4jkceG/B1t7VAsIt0FCfP6dnlXSg4qSAY=@openvpn.net X-Google-Smtp-Source: AGHT+IHkR8nYMYsxujmgDgQEEKw6q7CBi0z728Ag6V6h33V/JjSXoava0KLAwyfXxM5RXX1aYu1I X-Received: by 2002:a05:6602:60c2:b0:93e:871f:b060 with SMTP id ca18e2360f4ac-945c9836dfdmr86437239f.15.1761677036662; Tue, 28 Oct 2025 11:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1761677036; cv=none; d=google.com; s=arc-20240605; b=hk6hVJdsLviRKwII24A7IBVS21p9Q5cCdvRtIFFic75nYNRQuJX9HEz9/0yojjYRrp R8N7SSUOh2IX+UJ3zR+bCSem4Zt9b9jO1jfOYZERpbHgFG0KF5cK/qdy0e8Xcg8Tta/H /6uIIUYrnuP/ANoc+anyGsoeh4nIyDZ7tqFXoWjg5vRQQj6rpWRCSuq6rz1ShROpQjDR SMIQHiLnWDHzLAG/HVZEjIXbmLPDF9CTSgzCLpfqsxgfaq6aEN1gkUOB8/ibnfnpUwxv w4Aq2Po7K5HdLnhDACP7NPNkPS/R0UZX1mAIGaLgxXvMwIKgv3jbQKxfg408IhEul/+w Hycg== 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=KL2qQ7z9IXBl/qosIBVBbTl41E4TvvhN/ipfQ4/IKWk=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=DvHgtdc0v/SZu1854U9Igd5nndIcDgSe2abaHW4OQc9njJmyg1gTWR0Yv/RrBsuLoy a1p0T3hHAQbwid7r7p4ZbIpJq7vZRWc5Z7rnhqDLRsGnhQkQMvZfvHCyXtg/g6Yk7Nko h9k8zQTDWQuAJAT8E2ZBdL+tm1uX0snbxD4RStKyaLKw4m8WnFhBEwUJNpGQiz8t9oSm 4sCfcSMrVLmBeVgKLps+gh8AsIBSO75xAnTVVCQ8bmq50C8t4xLsQt0Pt63AXxaKlLuu mB4EP9axvzCMnU+OxR7IItuGf6pTkY2GZCEQRVDqHN6cQtytIqgSns7zrQaT4bYAJshC GjKA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=afXp+L9w; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=On3Ua4EX; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Bwl90UH/"; 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 ca18e2360f4ac-9435c7d3e90si849247339f.226.2025.10.28.11.43.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Oct 2025 11:43:56 -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=afXp+L9w; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=On3Ua4EX; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Bwl90UH/"; 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=KL2qQ7z9IXBl/qosIBVBbTl41E4TvvhN/ipfQ4/IKWk=; b=afXp+L9wJWIfqLzICa5gPPxujr KFGbUjJGm7ATh/0SnjMg4v6Uz+kH1Kousus8zgxKY1NC4lHinoiLLXz1w8jQNh9qZsVuczpIgN2ac mWIwapkerG0v9129VAOZ23o/fGb7iTOsrClhR3vJCLcWBEyHM59hq3GKUPLWcVVx1BjE=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vDoff-0004Ha-Ql; Tue, 28 Oct 2025 18:43:51 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vDofd-0004HS-RY for openvpn-devel@lists.sourceforge.net; Tue, 28 Oct 2025 18:43:49 +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=3d9tWtHjJ3b/AyfMzHvLFpHw7VI6wzXgkvctTCAuZxw=; b=On3Ua4EX7C52eI9sPSkTe4D220 vlC+3REy7nIbgdsQTgJXIYwqc0EmM25eaeSjLVuMmNJpSjcL5V3SHVypepbLcfqOl8oVpEu7iPYop WoigZOmI8sV8HzJp8tP5+prSMQbYqpLQR7vNgDdcSQFIxak7kuQ0Nfwy0hmpFVeW2XtE=; 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=3d9tWtHjJ3b/AyfMzHvLFpHw7VI6wzXgkvctTCAuZxw=; b=Bwl90UH/iTOFEuNHUSU2blKIGJ fRS1n+pgrYUJYyS0vP/IMf0ZmWO8ziZlvvWHyUFath1w0eZWuL+DjNI6TCMYM8idSS16Ox51T5LOd ggqPSX1q8+Zrp/G8kyts3lbHoU0x2QgAjiAhMtQ4H03XAlaA1Zh0Z6+n6km9HkVb5Fwc=; 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 1vDofd-0008Ph-0i for openvpn-devel@lists.sourceforge.net; Tue, 28 Oct 2025 18:43:49 +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 59SIhb0E032313 for ; Tue, 28 Oct 2025 19:43:37 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 59SIhbBX032312 for openvpn-devel@lists.sourceforge.net; Tue, 28 Oct 2025 19:43:37 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 28 Oct 2025 19:43:31 +0100 Message-ID: <20251028184337.32294-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: 1vDofd-0008Ph-0i 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?1847252260350205570?= 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 Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1285 --- 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;