From patchwork Wed Mar 5 17:17:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 4164 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:b342:b0:5e7:b9eb:58e8 with SMTP id w2csp901668maz; Wed, 5 Mar 2025 09:17:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWaXwqI39h8vhDRqU9K7jUp/IVJYoiqtSgb2m1+/WtAuvaeScIu/X+JMVzYu0EGbQcvFIOdo0H4Pa4=@openvpn.net X-Google-Smtp-Source: AGHT+IGXeDZz6AhlUfIiwDBQiSBrkl5fn2RepYEx3llQ2Msb5UUQzFzX2kck2vQDE9IEH/dKA/ow X-Received: by 2002:a05:6830:6587:b0:72a:1a2d:c06b with SMTP id 46e09a7af769-72a1fcb4bc9mr2232523a34.25.1741195069568; Wed, 05 Mar 2025 09:17:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741195069; cv=none; d=google.com; s=arc-20240605; b=MN49tMpane/cDGpkr/hshnpi3mPHyAofFVn07nMEwZhS98+FR7Olym0ZhlaaD1roqe 20lEz2PyMixwy4RWDMROy9QQ/WOaNWHzv049O+bNGeRW/XB0xpWu6drevLhlGX5C+rsi +SrbKX9OOYk3w5KRkLlyBbBjq5475rThdZp9AKo4PETidkbQN73H2z1iHEkcC+krgJXQ 1QvNWJfIQn/6X+yvTQ8UDvpdXomiy2A7TMAplDZ9jaJ4sFK2KPNlnLz0212jSKD46f35 WQUUS0NMiNWgG6jugNAfswwDY5nJqGWPI5MzMAUn7wDf7bBMya7c23iHtWriQgVK198S hGLQ== 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=2onguI3JSNfkFRnm9giIF2SkkrYwJAEpyiHqumlXWU4=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=WQlAuZsuhYAfNidb2qOtk/JvfoVvwbYBUGTHZrykOnHiCvWLqfAmZY0oXCTkNiegrs gjEvzqx+hmtIm3fOUGPWkPav6aVk/RUhsel8uBpmcy64G+9/ZAjp4Hqa343xIfgJW4XJ HxprDcBeZ/vsV+4s822oHAdtwg47z4xCAyyMCwjPsFhu2Zo6KCieoMIeBbL31n4dL2gw f0cGA7nW3pRVTHm77OkJevmjvH1Zt+K2h94rIzNNaVFMkPsoZNybbfnehrX3dAtfbcCt 4Z8CQY7BABB09Bh1aY/LvxYuuIS8dldHho+YFWpmzrJamiZLmODCQACmxt7WLoqOdF0O 78Hw==; 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=HFcxv7TV; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RLqDxo2D; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=RVh3eAGj; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-72a15002f45si3324798a34.265.2025.03.05.09.17.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Mar 2025 09:17:49 -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=HFcxv7TV; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RLqDxo2D; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=RVh3eAGj; 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 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 1tpsNL-0004pL-Ua; Wed, 05 Mar 2025 17:17:44 +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 1tpsNK-0004p6-Os for openvpn-devel@lists.sourceforge.net; Wed, 05 Mar 2025 17:17:43 +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:Cc:To:From:Sender:Reply-To: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=z2DdXmJe3VFjvV1jNr+aPCbBJ2+euykKLAERPBtfZCA=; b=HFcxv7TVbqEwQKUuUAvdE0CSZm kbeUQF6zFfZj4eDEDeoFLdJUgXp90NSzKws6zono7zQdmoNMgNg4Zlh5hiFM82XMM3ipdFbrmzQGW gAZi1ewLE7XsMyfFDM9lPDfsucuHwoY7riGfX4GpCzz21Bi7LT4FEMuO2g4umbs1ou6o=; 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:Cc:To:From:Sender:Reply-To: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=z2DdXmJe3VFjvV1jNr+aPCbBJ2+euykKLAERPBtfZCA=; b=RLqDxo2DWw8yKOpm5sBVgtIQHn XNEn6yugH4VUxYiu49o5sjOuAul7zDy7fmGeUnCCWKMCv48BrOGwj2ga8vRlFeQxwPtshvLn4HXGe /wwPaSk0JqBOTKoIOLsYrffueMV4L1gcZZ0XnPP1evf4NMAD+G2oZIJfidymfLCoqYPs=; Received: from mout-p-201.mailbox.org ([80.241.56.171]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tpsNJ-0002Cl-1c for openvpn-devel@lists.sourceforge.net; Wed, 05 Mar 2025 17:17:42 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Z7K4D2bhHz9sZg; Wed, 5 Mar 2025 18:17:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1741195052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z2DdXmJe3VFjvV1jNr+aPCbBJ2+euykKLAERPBtfZCA=; b=RVh3eAGjmwEwLWRoAiKuxDBOzF+5qTZD/ou3OxbCZN+ReuFMebY6bN5aAtzaShkvTeh24H He2PhuwSfQj8MF2iE5TLvWycMUXBGK9X+p7alXMZ/rjf35jYjr8iX9cJd23AiM9FVgvOss 88yLlj+1fJCR8oDQ8X5u10KnPYmuJ3whrho3B2FcjuQxmQxpPtM2dDGFxcX1a9kS0dsE2k PhhwDcTmy/LTxMIRAmiQjUviswTdipU+pMMMbaPpVo+SS0YbV0To6l95XU6Xpa2Bz+cT4j rMp2nEwZO740R1D5Rme5ZrFf8pqPk6JQ1aIqEWX4RhBR4jxKv2UdDqw/+6zHJg== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Wed, 5 Mar 2025 18:17:30 +0100 Message-Id: <20250305171730.250444-1-frank@lichtenheld.com> In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.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: Ralf Lici Occasionally, CMD_DEL_PEER is not delivered to userspace, preventing the openvpn process from registering the event. To handle this case, we check if calls to the Linux DCO module return an error, and [...] Content analysis details: (-0.9 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. [80.241.56.171 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. [80.241.56.171 listed in bl.score.senderscore.com] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.171 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1tpsNJ-0002Cl-1c Subject: [Openvpn-devel] [PATCH v3] Handle missing DCO peer by restarting the session 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?1825775361265038079?= X-GMAIL-MSGID: =?utf-8?q?1825775361265038079?= From: Ralf Lici Occasionally, CMD_DEL_PEER is not delivered to userspace, preventing the openvpn process from registering the event. To handle this case, we check if calls to the Linux DCO module return an error, and, if so, send a SIGUSR1 signal to reset the session. Most DCO commands that return an error already trigger a SIGUSR1 signal or even call _exit(1). This commit extends that behavior to include dco_get_peer_stats_multi() and dco_get_peer_stats(). Change-Id: Ib118426c5a69256894040c69856a4003d9f4637c Signed-off-by: Ralf Lici Acked-by: Frank Lichtenheld --- 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/+/831 This mail reflects revision 3 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h index 35ceace..ed194cc 100644 --- a/src/openvpn/dco.h +++ b/src/openvpn/dco.h @@ -231,17 +231,20 @@ /** * Update traffic statistics for all peers * - * @param dco DCO device context - * @param m the server context + * @param dco DCO device context + * @param m the server context + * @param raise_sigusr1_on_err whether to raise SIGUSR1 on error **/ -int dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m); +int dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m, + const bool raise_sigusr1_on_err); /** * Update traffic statistics for single peer * - * @param c instance context of the peer + * @param c instance context of the peer + * @param raise_sigusr1_on_err whether to raise SIGUSR1 on error **/ -int dco_get_peer_stats(struct context *c); +int dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err); /** * Retrieve the list of ciphers supported by the current platform @@ -373,13 +376,14 @@ } static inline int -dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) +dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m, + const bool raise_sigusr1_on_err) { return 0; } static inline int -dco_get_peer_stats(struct context *c) +dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err) { return 0; } diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 0e536de..b8816c6 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -713,7 +713,8 @@ } int -dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) +dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m, + const bool raise_sigusr1_on_err) { struct ifdrv drv; @@ -781,7 +782,7 @@ } int -dco_get_peer_stats(struct context *c) +dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err) { /* Not implemented. */ return 0; diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index 68c1a8d..b0a85fd 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -952,7 +952,8 @@ } int -dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) +dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m, + const bool raise_sigusr1_on_err) { msg(D_DCO_DEBUG, "%s", __func__); @@ -963,6 +964,14 @@ int ret = ovpn_nl_msg_send(dco, nl_msg, dco_parse_peer_multi, m, __func__); nlmsg_free(nl_msg); + + if (raise_sigusr1_on_err && ret < 0) + { + msg(M_WARN, "Error retrieving DCO peer stats: the underlying DCO peer" + "may have been deleted from the kernel without notifying " + "userspace. Restarting the session"); + register_signal(m->top.sig, SIGUSR1, "dco peer stats error"); + } return ret; } @@ -1008,9 +1017,14 @@ } int -dco_get_peer_stats(struct context *c) +dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err) { - uint32_t peer_id = c->c2.tls_multi->dco_peer_id; + int peer_id = c->c2.tls_multi->dco_peer_id; + if (peer_id == -1) + { + return 0; + } + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peer_id); if (!c->c1.tuntap) @@ -1030,6 +1044,14 @@ nla_put_failure: nlmsg_free(nl_msg); + + if (raise_sigusr1_on_err && ret < 0) + { + msg(M_WARN, "Error retrieving DCO peer stats: the underlying DCO peer" + "may have been deleted from the kernel without notifying " + "userspace. Restarting the session"); + register_signal(c->sig, SIGUSR1, "dco peer stats error"); + } return ret; } diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 45cb919..8b47124 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -712,14 +712,15 @@ } int -dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) +dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m, + const bool raise_sigusr1_on_err) { /* Not implemented. */ return 0; } int -dco_get_peer_stats(struct context *c) +dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err) { struct tuntap *tt = c->c1.tuntap; diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 8b94469..d5c5f87 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -488,16 +488,14 @@ static void check_inactivity_timeout(struct context *c) { - if (dco_enabled(&c->options) && dco_get_peer_stats(c) == 0) + if (dco_enabled(&c->options) && dco_get_peer_stats(c, true) == 0) { int64_t tot_bytes = c->c2.tun_read_bytes + c->c2.tun_write_bytes; int64_t new_bytes = tot_bytes - c->c2.inactivity_bytes; - if (new_bytes > c->options.inactivity_minimum_bytes) { c->c2.inactivity_bytes = tot_bytes; event_timeout_reset(&c->c2.inactivity_interval); - return; } } diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 484042a..0e73942 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -4146,8 +4146,13 @@ counter_type dco_read_bytes = 0; counter_type dco_write_bytes = 0; - if (dco_enabled(&c->options) && (dco_get_peer_stats(c) == 0)) + if (dco_enabled(&c->options)) { + if (dco_get_peer_stats(c, true) < 0) + { + return; + } + dco_read_bytes = c->c2.dco_read_bytes; dco_write_bytes = c->c2.dco_write_bytes; } @@ -4166,7 +4171,8 @@ void man_persist_client_stats(struct management *man, struct context *c) { - if (dco_enabled(&c->options) && (dco_get_peer_stats(c) == 0)) + /* no need to raise SIGUSR1 since we are already closing the instance */ + if (dco_enabled(&c->options) && (dco_get_peer_stats(c, false) == 0)) { management_bytes_client(man, c->c2.dco_read_bytes, c->c2.dco_write_bytes); } diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 7ab9289..65d7ce9 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -549,7 +549,10 @@ { if (dco_enabled(&m->top.options)) { - dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m); + if (dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m, false) < 0) + { + return; + } } setenv_counter(c->c2.es, "bytes_received", c->c2.link_read_bytes + c->c2.dco_read_bytes); @@ -856,7 +859,10 @@ if (dco_enabled(&m->top.options)) { - dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m); + if (dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m, true) < 0) + { + return; + } } if (version == 1) diff --git a/src/openvpn/sig.c b/src/openvpn/sig.c index 8323f0d..b0f8935 100644 --- a/src/openvpn/sig.c +++ b/src/openvpn/sig.c @@ -489,7 +489,10 @@ if (dco_enabled(&c->options)) { - dco_get_peer_stats(c); + if (dco_get_peer_stats(c, true) < 0) + { + return; + } } status_printf(so, "OpenVPN STATISTICS");