[Openvpn-devel,v4,06/13] client-connect: Change connection_established_flag from bool to enum

Message ID 20181121101019.1801-7-arne@rfc2549.org
State New
Delegated to: Antonio Quartulli
Headers show
Series
  • Deferred client-connect patch set
Related show

Commit Message

Arne Schwabe Nov. 21, 2018, 10:10 a.m.
This prepares from the yes/no logic to a tristate logic with defered being
the third state. This deviates from Fabian's original patch that
that used a pointer being NULL or non NULL as implicit third state.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/multi.c | 14 ++++++++------
 src/openvpn/multi.h | 14 ++++++++++----
 2 files changed, 18 insertions(+), 10 deletions(-)

Patch

diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 18a1313e..1093d8aa 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -574,7 +574,8 @@  static void
 multi_client_disconnect_script(struct multi_context *m,
                                struct multi_instance *mi)
 {
-    if ((mi->context.c2.context_auth == CAS_SUCCEEDED && mi->connection_established_flag)
+    if ((mi->context.c2.context_auth == CAS_SUCCEEDED
+         && mi->client_connect_status == CC_STATUS_ESTABLISHED)
         || mi->context.c2.context_auth == CAS_PARTIAL)
     {
         multi_client_disconnect_setenv(m, mi);
@@ -2051,7 +2052,7 @@  multi_client_connect_early_setup(struct multi_context *m,
  * Try to source a dynamic config file from the
  * --client-config-dir directory.
  */
-enum client_connect_return
+static enum client_connect_return
 multi_client_connect_source_ccd(struct multi_context *m,
                                 struct multi_instance *mi,
                                 unsigned int *option_types_found)
@@ -2196,7 +2197,7 @@  multi_connection_established(struct multi_context *m, struct multi_instance *mi)
         }
 
         /* set flag so we don't get called again */
-        mi->connection_established_flag = true;
+        mi->client_connect_status = CC_STATUS_ESTABLISHED;
 
         /* increment number of current authenticated clients */
         ++m->n_clients;
@@ -2479,7 +2480,8 @@  multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns
         {
             /* connection is "established" when SSL/TLS key negotiation succeeds
              * and (if specified) auth user/pass succeeds */
-            if (!mi->connection_established_flag && CONNECTION_ESTABLISHED(&mi->context))
+            if (mi->client_connect_status != CC_STATUS_ESTABLISHED
+                && CONNECTION_ESTABLISHED(&mi->context))
             {
                 multi_connection_established(m, mi);
             }
@@ -3385,7 +3387,7 @@  management_client_auth(void *arg,
         {
             if (auth)
             {
-                if (!mi->connection_established_flag)
+                if (mi->client_connect_status == CC_STATUS_NOT_ESTABLISHED)
                 {
                     set_cc_config(mi, cc_config);
                     cc_config_owned = false;
@@ -3397,7 +3399,7 @@  management_client_auth(void *arg,
                 {
                     msg(D_MULTI_LOW, "MULTI: connection rejected: %s, CLI:%s", reason, np(client_reason));
                 }
-                if (mi->connection_established_flag)
+                if (mi->client_connect_status == CC_STATUS_ESTABLISHED)
                 {
                     send_auth_failed(&mi->context, client_reason); /* mid-session reauth failed */
                     multi_schedule_context_wakeup(m, mi);
diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h
index 0a1ab2c3..bd4882ea 100644
--- a/src/openvpn/multi.h
+++ b/src/openvpn/multi.h
@@ -63,6 +63,12 @@  struct deferred_signal_schedule_entry
     struct timeval wakeup;
 };
 
+enum client_connect_status
+{
+    CC_STATUS_NOT_ESTABLISHED,
+    CC_STATUS_ESTABLISHED
+};
+
 /**
  * Server-mode state structure for one single VPN tunnel.
  *
@@ -105,7 +111,7 @@  struct multi_instance {
     bool did_cid_hash;
     struct buffer_list *cc_config;
 #endif
-    bool connection_established_flag;
+    enum client_connect_status client_connect_status;
     bool did_iroutes;
     int n_clients_delta; /* added to multi_context.n_clients when instance is closed */
 
@@ -196,9 +202,9 @@  struct multi_context {
  */
 enum client_connect_return
 {
-  CC_RET_FAILED,
-  CC_RET_SUCCEEDED,
-  CC_RET_SKIPPED
+    CC_RET_FAILED,
+    CC_RET_SUCCEEDED,
+    CC_RET_SKIPPED
 };
 
 /*