[Openvpn-devel] multi: call client-disconnect handlers when late client setup fails
| Message ID | CADJo8AbsiVxntM2bXe+RsjA756MvwiTqw9FLa7d5KT1q0YT3+g@mail.gmail.com |
|---|---|
| State | New |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id
tl9-n1csp6283824lad;
Wed, 25 Nov 2026 12:46:13 -0800 (PST)
X-Forwarded-Encrypted: i=3;
AL+hErETtbks/l/3J8o+U/q7/BQ5n3sMRo6oSjYTrQ93q00r1fBkZLiaJ5V0kVKVraXVBjDH9qhm5+EP0qw=@openvpn.net
X-Received: by 2002:a05:6820:f033:b0:71a:f0b8:5dc7 with SMTP id
006d021491bc7-71b77d9c7d4mr4051204eaf.8.1795639573447;
Wed, 25 Nov 2026 12:46:13 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1795639573; cv=fail;
d=google.com; s=arc-20260327;
b=W6Zdf6KmLVmquv6F1JpmB1rGlKF3LV1QfigK4YLqA7ednEUVSvJRrkojxZ+INtc7BX
X+ziL2WqqH1XKW/Fy3RMzAzB01Rypcfe425dVsvqGVxlgUx/Bdxwt4Wx3aZjGf9Dnxj0
DzQwOXsiTxDGz3i+zFxd+NHBUaBvGdbAlIyoJxpqSlSUJPXflyL16dl9DNeYgysBYm8r
lwTZ29xBZQGnr5Nyfe0w+zydwJwkqz+nQpHfarsqEz52TQfmwYlnibL6BN3UQoJpC6dz
NHznJgnhf9jMfV3pSLjv3FtJCcZGGtZfGU5Da2CQz2G4QNdJjpIpBZEdd9lP/tYYNMDV
i8ow==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20260327;
h=errors-to:list-subscribe:list-help:list-post:list-archive
:list-unsubscribe:list-id:precedence:subject:to:message-id:date:from
:mime-version:dkim-signature:dkim-signature:dkim-signature
:dkim-signature;
bh=YrXkkNpxoJaklGR/mZFUEmDfj7HVxWEZBVFiNCqJj+4=;
fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=;
b=Uvz1MD0Y+UUVYa6SSA/qTfKTKCqTpMcS/0lSSP/NMV1/QeEO7cfzPRf+AVKPrvP6EH
kufLNZf9Sz4NbqkyMryY6wvlxhcGciHD5PQkZP6r1jWjW/5IjaX6E7RSkZE0u2qGOJV4
gvxrphb/ex5vqrrUKI8Ad+I2dOjsncQz6H7ZpAOlODvWcVWIaGEVNMi3F/2KatzXwUNq
ceORsnmMb1p1pWAAzBCbmle00AjWgc29XUEcjlIHpgZ2NtjHNn1NVcREltLY0YfcNzeu
3ZFZiZ3aYEZuU7XB6Xz7QNrXMVM1suyHPi/I96NiGlWc2H1vBan9YajtiZyFf3dhcwyV
i1Yg==;
dara=google.com
ARC-Authentication-Results: i=2; mx.google.com;
dkim=pass header.i=@lists.sourceforge.net header.s=beta
header.b=nCuBqFe1;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=OQ3TW4dc;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=PQFgTQ4H;
dkim=neutral (body hash did not verify) header.i=@gmail.com
header.s=20260707 header.b=UChj4Kof;
arc=fail (body hash mismatch);
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=QUARANTINE dis=NONE) header.from=gmail.com;
dara=neutral header.i=@openvpn.net
Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7])
by mx.google.com with ESMTPS id
586e51a60fabf-4bc6107437asi27597746fac.154.2026.11.25.12.46.13
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Wed, 25 Nov 2026 12:46:13 -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=nCuBqFe1;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=OQ3TW4dc;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=PQFgTQ4H;
dkim=neutral (body hash did not verify) header.i=@gmail.com
header.s=20260707 header.b=UChj4Kof;
arc=fail (body hash mismatch);
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=QUARANTINE dis=NONE) header.from=gmail.com;
dara=neutral header.i=@openvpn.net
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=lists.sourceforge.net; s=beta; h=List-Subscribe:List-Help:List-Post:
List-Archive:List-Unsubscribe:List-Id:Subject:Content-Type:To:Message-ID:Date
:From:MIME-Version:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:In-Reply-To:References:List-Unsubscribe-Post:List-Owner;
bh=YrXkkNpxoJaklGR/mZFUEmDfj7HVxWEZBVFiNCqJj+4=; b=nCuBqFe1VAYmle9nOVm1PPz1xX
uHxdBkPIfo5fQM0Na+mDtYDSTqAubLUUDmKV6yykuwGrc95Vtkoloo6DHzBtpsG2G6d2CY6b1RXpv
5bq3ujpwbsqiSS+k0+nryC+JdvpnRjQ1BV7Y/+92Hywgqy2j4EK2lZelTVVERT3vk5YA=;
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 <openvpn-devel-bounces@lists.sourceforge.net>)
id 1xWJsY-0000000006k-1yUP;
Wed, 25 Nov 2026 20:46:10 +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 <farshidrezaiyan@gmail.com>)
id 1xWJsX-0000000006e-0Wp0 for openvpn-devel@lists.sourceforge.net;
Wed, 25 Nov 2026 20:46:09 +0000
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=sourceforge.net; s=x; h=Content-Type:To:Subject:Message-ID:Date:From:
MIME-Version:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:
List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive;
bh=LZDZkffs5sZyS+19q2DaWOLCHIadnub2BnMVbvV+AKA=; b=OQ3TW4dcY/XOPQxl4ut3hk83vJ
HxUx4SzrGb3tTRwYQqMOWOsWGKgjcggrwdiF2pXDpIyzocPNq2rOoWZbMy5xggk/uYeyQsmpL5axs
/uJQLpBomIFovAvW5TTBTPQvm5pcwcykZBWMnjjPIIMX+GSXzfD2ohPoCGjyPBK0AlD0=;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x
;
h=Content-Type:To:Subject:Message-ID:Date:From:MIME-Version:Sender:Reply-To
:Cc:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:
Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:
References:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post:
List-Subscribe:List-Post:List-Owner:List-Archive;
bh=LZDZkffs5sZyS+19q2DaWOLCHIadnub2BnMVbvV+AKA=; b=PQFgTQ4HGVSWvxv8Jjgvnwv6s8
mGRQl3Rg1DhClcv+oCICvED8aD3ZAQIP59sZsiUYaKbL0FioYp5MZYDUi2Uu0bH+FN0wGdarYJ6bA
okBq8QzkaWFuAvNe7qmWyDYD++iueABpKwJofi6x1qgavOrPtLkfvJyoVkhIAzaf5Y70=;
Received: from mail-qt1-f182.google.com ([209.85.160.182])
by sfi-mx-2.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.100.1)
id 1xWJsV-000000004Dh-2wbr for openvpn-devel@lists.sourceforge.net;
Wed, 25 Nov 2026 20:46:09 +0000
Received: by mail-qt1-f182.google.com with SMTP id
d75a77b69052e-5365d26ccbdso69500451cf.0
for <openvpn-devel@lists.sourceforge.net>;
Wed, 25 Nov 2026 12:46:07 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1795639562; cv=none;
d=google.com; s=arc-20260327;
b=p9rzLWhZRlLVEq/WoD89pVPyMCeXqyXsIB2cs6NjjzwA0LMSsbmqjQCCzBIdqmIT7k
MIEaQW0g2Ub2VigQUUGWTm0EioQrJiRWOwCpgUH/pStCTdUmSGUfcukzPIhjANHLy15C
m2V6KUNpo1WxIsndnGQ0pdXYTtqMACoFMg9u2smC4vxOsKMPxtMmB7ptIgh7dEm/YLeH
TEAG0IsUs2Q8+XQNLeHb1AX59XxGLbKVUbHXUsdBRCGhzB35tfquEgVFlU7BMHHPAmrj
96V3MvOaFq9OrlF240RTMtcEOQWLAR2kMaoJR3kyvj7UgS2yNwdpUUP15Eceq4W5DfEX
TTFA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20260327;
h=to:subject:message-id:date:from:mime-version:dkim-signature;
bh=LZDZkffs5sZyS+19q2DaWOLCHIadnub2BnMVbvV+AKA=;
fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=;
b=BrP3Le245LzCVSrxgmJwEbne93A8eEBxe9sOQZ1GHbZj2ft/0MiKkqFKJ+d0shT+e5
Hww6BplFhiwHXA1F+QNsli4Ees+kc69TUHRYITXDxkAbrYnZ90ur7we6AAPnmykDciuW
ju+1H+iCwAJUISJnotTlA2rKlTmOtJWkrSmKge5H3nJnNpBxX4k/3DvpLwq78auKx7Ly
t/M2mCzdRVUF7deb2AjElXY79O1tDzAhhQqrKCleYxmbOQtv8jW6nqIJ9C9sNMuYXJsS
weDxRJfor5Q6w7pT0CI8QUu9zeLfeurBZCApMJZrM+RT+ccLZkr+TkmK9hl1N0GGvgKP
+/ug==; darn=lists.sourceforge.net
ARC-Authentication-Results: i=1; mx.google.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795639562; x=1796244362;
darn=lists.sourceforge.net;
h=content-type:to:subject:message-id:date:from:mime-version:from:to
:cc:subject:date:message-id:reply-to:content-type;
bh=LZDZkffs5sZyS+19q2DaWOLCHIadnub2BnMVbvV+AKA=;
b=UChj4Kofqgghusda5LWrVk9n5f21C6TgNo5yfMTjSo5qqwpny8D+kCuY3EwLwbg8Bl
tdYyP2ZKzemma0WFEy2r0ne/1IlJ5RpX6IMPvdtdMEJNwzEufAIkxTh2GoLj+gjV8Wlc
UXY/AXG6PVU1WZ8gcsklXeQbm41YVDkBmwGnOZbo2jhzwvRGOPlXPOInijwoUUXh38sr
1kBVfVR1IFndBYPYKOjFQGnNKFBPmD3ugzbcNiV/kRC0Kq7GNsY2/KZirLM73nf+njp8
vMMznu3FY254mcux1VAr3RXQzKLPGugEgm9P+PDYlFTVfBOmaN6VUVrKgbAZcZ7+/GqF
b3rQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795639562; x=1796244362;
h=content-type:to:subject:message-id:date:from:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=LZDZkffs5sZyS+19q2DaWOLCHIadnub2BnMVbvV+AKA=;
b=mjruxr7SnKMbQEA4bQnO34NcvEX4IL61cJ6V4M61IMKGoRWAQWG2kxDwkNorgifvah
Q9jdO+mu7p0hrzv0LbK1G4i9ahPrNsYcIM3xCk/LKLU5DuRNq+87pKhsStRJONHQydU/
CC3V3ElSV4r0lXsSLnp91OZsE8JW3BingCxnNSd2gism1x+lHVTL62PoIquz+pkXS2r9
c+ZyNJte4jNNCe9K9sodzWPB0UaFOlwAORExXNRvtI/Qqa5tpVqYq8oHonOETgZ3d5H9
zVYKxGGm6iPr+xrO9yVGUdk4Nm5tOdtGiSl3Qd27NZ/bHYfHV3MVQMadAeEUd0Oy+LIf
9FnA==
X-Gm-Message-State: APuU4Z8LyQqWF9rOCurWstUdINxjAdYrYKq1DFey79SKVFRfidi/P5qM
tQyUQml+81D0crAN0VKoYthSPQaDelMBCbteDjfaRB9gCqRRth2oXyLDAlmsCqAlurDi3ZfU0UC
P3X2+L+cvb1ax50gMY4zuwbSMhhsmZKA0OxCQQFmF8Q==
X-Gm-Gg: AZFdTZcSHVNhlSC4MkXRJJIpyhWKdnjki1KvY+h02zlld8+uG1c+EHV3zUAuxGvifDH
HvbFey4Jz5CQT7KqKQv6d1TyXH390hJZZZYphCz5ICTqutZO2TDPkJBXLZhVUaWA9w51sIps5gO
g55DyaOhScfZxleIsmfbqDHKHZRUXaee7zxZfiRm0ZrOh5Sz1J+80k3nSi0rQG/Sos3qAhQMxQL
HYQfk3Xr85CugZXg/d0NtYmpZj9Jl6GAn+DYC2Kx2rjYGCEZwsXS2y0nsC7xU10gejbvStZnIA6
V+TamdtlHd2LHEM6Z9F0C7/GZualabWOyihsgXCYED6j09QX//K/DGS0NSpPW/NV8GTzl3g3ze7
TuhZfhL1A4gLrywF/qeGcDtLj6Rov1900DLATGnJiQm50l7+AmxTEuKgRbzE2uy8Z0FtVkX+pio
8Bq895Cof01LdwIFpTJdfL
X-Received: by 2002:a05:622a:a10:b0:535:84e3:b165 with SMTP id
d75a77b69052e-55d768a3030mr357162691cf.9.1795639561728; Wed, 25 Nov 2026
12:46:01 -0800 (PST)
MIME-Version: 1.0
From: Farshid Rezaiyan <farshidrezaiyan@gmail.com>
Date: Thu, 26 Nov 2026 00:15:50 +0330
X-Gm-Features: Aa3M54ro1ilJudsVCrcb20fuEfBq7tbCWxrttGZkZGeqRsmszGoUYmXa-HYriy4
Message-ID:
<CADJo8AbsiVxntM2bXe+RsjA756MvwiTqw9FLa7d5KT1q0YT3+g@mail.gmail.com>
To: openvpn-devel@lists.sourceforge.net
Content-Type: multipart/mixed; boundary="0000000000003929e906611fea17"
X-Spam-Score: -0.2 (/)
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: 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: (-0.2 points, 5.0 required)
pts rule name description
---- ----------------------
--------------------------------------------------
0.0 RCVD_IN_DNSWL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to DNSWL
was blocked. See
http://wiki.apache.org/spamassassin/DnsBlocklists#DnsBlocklists-dnsbl-block
for more information. [209.85.160.182 listed in list.dnswl.org]
-0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
0.1 DKIM_SIGNED Message has a DKIM or DK signature,
not necessarily valid
-0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's
domain
-0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from
envelope-from domain
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
[farshidrezaiyan(at)gmail.com]
0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3)
[209.85.160.182 listed in wl.mailspike.net]
0.0 RCVD_IN_MSPIKE_WL Mailspike good senders
X-Headers-End: 1xWJsV-000000004Dh-2wbr
Subject: [Openvpn-devel] [PATCH] 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: <openvpn-devel.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive:
<http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel>
List-Post: <mailto:openvpn-devel@lists.sourceforge.net>
List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe>
Errors-To: openvpn-devel-bounces@lists.sourceforge.net
X-getmail-retrieved-from-mailbox: Inbox
X-GMAIL-THRID: 1882864561225963415
X-GMAIL-MSGID: 1882864561225963415
|
| Series |
[Openvpn-devel] multi: call client-disconnect handlers when late client setup fails
|
|
Commit Message
Farshid Rezaiyan
Nov. 25, 2026, 8:45 p.m. UTC
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
Signed-off-by: Farshid Rezaiyan <farshidrezaiyan@gmail.com>
---
This is the squashed patch of GitHub PR #1156, as asked there:
https://github.com/OpenVPN/openvpn/pull/1156
The patch made with git format-patch is attached, because the Gmail
web interface wraps long lines. It applies to master (99ee0917).
Tested on Linux 6.8 with DCO (ovpn-backports), TCP and UDP, with
client-connect / client-disconnect scripts and a small test plugin.
The test cases are listed in the PR.
src/openvpn/multi.c | 14 +++++++++++++-
src/openvpn/multi.h | 3 +++
2 files changed, 16 insertions(+), 1 deletion(-)
From 34c1f0ef2bf1ad536131ddd6052ef80f616b65cd Mon Sep 17 00:00:00 2001
From: Farshid Rezaiyan <farshidrezaiyan@gmail.com>
Date: Wed, 25 Nov 2026 23:56:59 +0330
Subject: [PATCH] multi: call client-disconnect handlers when late client setup
fails
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
Signed-off-by: Farshid Rezaiyan <farshidrezaiyan@gmail.com>
---
src/openvpn/multi.c | 14 +++++++++++++-
src/openvpn/multi.h | 3 +++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 900b5a3b..706195ac 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -718,7 +718,10 @@ multi_close_instance(struct multi_context *m, struct multi_instance *mi, bool sh 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 @@ multi_client_connect_late_setup(struct multi_context *m, struct multi_instance * /* 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 3d2e9321..9cc986c9 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -145,6 +145,9 @@ struct multi_instance 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