From patchwork Thu Nov 26 10:15:45 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5791 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp6962401lad; Thu, 26 Nov 2026 02:16:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFpT1jsc9e6DR++Dhhf+PZcK3YYuB289u8L6oWhGiO9Ti/AnAHNbMszkuMUuKFPGJe+WQgeETKghKU=@openvpn.net X-Received: by 2002:a05:7022:7f12:b0:1b2:4f97:27d7 with SMTP id a92af1059eb24-1b55692891bmr18919963c88.36.1795688163346; Thu, 26 Nov 2026 02:16:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795688163; cv=none; d=google.com; s=arc-20260327; b=G4VTKK+WOnDYSuGSNYz08K59fbm0VKUwPEiNDn81fJdekRLx7FV0ULwtsnNk33T4Oe EuZ+beCiI7AX0Cpbx/5+B14gi8/YX2+BSS+Oi/VfPLCCBCCWM6R9fxn5aQhLxyevG0tK rYbudogOJkxOs0COOMz1HjekJK86J/zgE46XbiEPzZfUyT7fHKyPNHc+x3YSDVPVF2fk 46OjZ/dSNzPehB+h7cpOQkfSYH+6ryd7W31g1lShH1sgKhPslLOKjTeJZale4WCVCYHi BU/m9Y/jLpAUmjFPM1l30BsH3ac4AtJnYbhngvnMh/YkG2WAoaO+HdPrd/hW6UD31bN0 v+qg== 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=KzTa4FLeM/ed0nJr1SkpSVSdORJnX+2ZIByg0bDlGww=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=WNGQ14UHcmUrIS+QzOWKI5Xa/jXlTaqw7hUoXqS99lL+8EXVDKGazisRpPbfYu7EWO fXvgUYRsDyxY1gnCdWleaur4HxCZOBtj7MSr53VVnU5/EmcBKjuA8NSSpyrIxX3tPLEz q/6HsXWo0CkG+EfnEWWou98o6xY9o9qFhoE3RPQ/jq/0DPoLvtt0lhKYf5M7rDQGxpnc 8wnvCC3dInk9H3/fGl+7mbohQqNxi9BvpYxEW1qBntXO+TSsUPOEEAV4wRWI1VTxmfm3 5SrJUYXmvl/8ribkkjKKn/QeelOu4JXlZFJrbbh5N2/9bH1/0nNht0nQuVbcuGKbpcn2 xfHw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=SvnA76jc; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="Ibo/zsIg"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="AT0+o/i+"; 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-1b5567e7eedsi62938485c88.32.2026.11.26.02.16.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2026 02:16:03 -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=SvnA76jc; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="Ibo/zsIg"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="AT0+o/i+"; 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=KzTa4FLeM/ed0nJr1SkpSVSdORJnX+2ZIByg0bDlGww=; b=SvnA76jcAVTEYP 72ezPeSBM4CphIxkq6sLymqR1KTyaKg5pEsJ7wv7kuASNzbtaATATkVRPXE2s3TFRLKq4+gjQkUEU fruJ3Rm2KZWx/D1Jqs84ACNM1xm8Gnr861UscML3sxsmxfV/nGlz4EFED6p7iQI11wyfW6j7lr+7Z cb4=; 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.100.1) (envelope-from ) id 1xWWWI-000000005Uo-0J6c; Thu, 26 Nov 2026 10:16:02 +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.100.1) (envelope-from ) id 1xWWWG-000000005Ua-3FN8 for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 10:16:00 +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=XW+J81OShVrSdj5zSvb8x+l5t+RBTwHQmhU4pjWcTOM=; b=Ibo/zsIg2hQlcLRNhwrdap2TL3 243/85ZCw5O2o4nsPJr2oVsbozzZnOB2N6PaCgUJb9PUFyhzecRpDZ93kXh0teZtxWoCGKotdNK6J EUEeRRC/rHzdao4hu4YYz+/tz/5QQAkXdxDqUVip7t6EDu3JDjUU4yRicIGjJYnyt2Ec=; 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=XW+J81OShVrSdj5zSvb8x+l5t+RBTwHQmhU4pjWcTOM=; b=AT0+o/i+gybX+87qFga5uTzYhA itHvmvGAaHsHKvXYR+VK+h/cvxhd8lOeFW9IA+E3c8MWQZk9FFgpX4qC08iMgnGm8Tlb6vowWyZXh cC8u35f1u9cIhkxPwkONLwTqQdGWE27hc8zXnUCFw+OKpoIBD6YFQnYfrdj4tPMM18Qs=; Received: from [193.149.48.129] (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.100.1) id 1xWWWD-000000006j9-2vb0 for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 10:16:00 +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 6AQAFomq028795 for ; Thu, 26 Nov 2026 11:15:50 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AQAFo3r028794 for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 11:15:50 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 26 Nov 2026 11:15:45 +0100 Message-ID: <20261126101550.28784-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-1.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: Farshid Rezaiyan multi_client_connect_late_setup() is only reached after all client-connect handlers (scripts and plugins) have succeeded. It sets the state to CAS_CONNECT_DONE and then downgrades it to CAS_FAILED if [...] 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: 1xWWWD-000000006j9-2vb0 Subject: [Openvpn-devel] [PATCH v1] multi: call client-disconnect handlers when late client setup fails 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: 1882915512028832227 X-GMAIL-MSGID: 1882915512028832227 From: Farshid Rezaiyan multi_client_connect_late_setup() is only reached after all client-connect handlers (scripts and plugins) have succeeded. It sets the state to CAS_CONNECT_DONE and then downgrades it to CAS_FAILED if setting the protocol options, adding the DCO peer or generating the data channel keys fails. multi_close_instance() only calls the client-disconnect handlers for instances in state CAS_CONNECT_DONE, so for such a client the client-connect handlers have run but client-disconnect never does. Anything that pairs the two calls gets out of sync. For example, a RADIUS accounting plugin that sends Accounting-Start on connect and Accounting-Stop on disconnect keeps the session open forever. This is easy to hit with DCO on Linux and TCP: if the client closes the TCP connection while a client-connect handler is running, the kernel refuses to attach the socket ("provided TCP socket is not in ESTABLISHED state") and dco_multi_add_new_peer() fails. Remember in the new did_client_connect flag that a client-connect plugin or script was called with success. This is the case if one is defined, because multi_client_connect_late_setup() is only reached when all client-connect handlers have succeeded. multi_close_instance() then also calls the disconnect handlers for an instance in CAS_FAILED that has this flag set. So they run on instance shutdown and exactly once, as for any other client, and only after a successful client-connect. GitHub: closes OpenVPN/openvpn#1155 Change-Id: Ic667de6f830fa86e2842f1da2820e1250b9d6054 Signed-off-by: Farshid Rezaiyan Acked-by: Ralf Lici Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2350 --- 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/+/2350 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Ralf Lici diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 900b5a3..706195a 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -718,7 +718,10 @@ set_cc_config(mi, NULL); #endif - if (mi->context.c2.tls_multi->multi_state >= CAS_CONNECT_DONE) + /* A client that failed in multi_client_connect_late_setup() is in + * CAS_FAILED, but its client-connect handlers did succeed */ + if (mi->context.c2.tls_multi->multi_state >= CAS_CONNECT_DONE + || (mi->did_client_connect && mi->context.c2.tls_multi->multi_state == CAS_FAILED)) { multi_client_disconnect_script(mi); } @@ -2414,6 +2417,15 @@ /* set context-level authentication flag */ mi->context.c2.tls_multi->multi_state = CAS_CONNECT_DONE; + /* We only get here if all client-connect handlers succeeded, so a + * defined client-connect plugin or script has been called with + * success. Remember this, as the steps below may still set + * CAS_FAILED, and the client-disconnect handlers must then be called + * when the instance is closed. */ + mi->did_client_connect = plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT) + || plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT_V2) + || mi->context.options.client_connect_script != NULL; + /* Since dco-win maintains iroute routing table (subnet -> peer), * peer must be added before iroutes. For other platforms it doesn't matter. */ diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 3d2e932..9cc986c 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -145,6 +145,9 @@ struct buffer_list *cc_config; #endif bool did_iroutes; + /** a client-connect plugin or script was called and succeeded, so + * client-disconnect must be called when the instance is closed */ + bool did_client_connect; int n_clients_delta; /* added to multi_context.n_clients when instance is closed */ struct context context; /**< The context structure storing state