Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/2350?usp=email
to review the following change.
Change subject: multi: call client-disconnect handlers when late client setup
fails
......................................................................
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
Change-Id: Ic667de6f830fa86e2842f1da2820e1250b9d6054
Signed-off-by: Farshid Rezaiyan <[email protected]>
---
M src/openvpn/multi.c
M src/openvpn/multi.h
2 files changed, 16 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/2350/1
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
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2350?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic667de6f830fa86e2842f1da2820e1250b9d6054
Gerrit-Change-Number: 2350
Gerrit-PatchSet: 1
Gerrit-Owner: Farshid Rezaiyan <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel