[Openvpn-devel,v4,05/13] client-connect: Refactor client-connect handling to calling a bunch of hooks in a loop

Message ID 20181121101019.1801-6-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.
From: Fabian Knittel <fabian.knittel@lettink.de>

This patch changes the calling of the client-connect functions into an array
of hooks and a block of code that calls them in a loop.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/multi.c | 44 ++++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

Patch

diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 4182b553..18a1313e 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -2144,6 +2144,20 @@  multi_connection_established(struct multi_context *m, struct multi_instance *mi)
     if (tls_authentication_status(mi->context.c2.tls_multi, 0)
         == TLS_AUTHENTICATION_SUCCEEDED)
     {
+        typedef enum client_connect_return
+        (*multi_client_connect_handler)
+            (struct multi_context *m, struct multi_instance *mi,
+            unsigned int *option_types_found);
+
+        multi_client_connect_handler handlers[] = {
+            multi_client_connect_source_ccd,
+            multi_client_connect_call_plugin_v1,
+            multi_client_connect_call_plugin_v2,
+            multi_client_connect_call_script,
+            multi_client_connect_mda,
+            NULL
+        };
+
         unsigned int option_types_found = 0;
 
         int cc_succeeded = true; /* client connect script status */
@@ -2152,35 +2166,9 @@  multi_connection_established(struct multi_context *m, struct multi_instance *mi)
 
         multi_client_connect_early_setup(m, mi);
 
-        ret = multi_client_connect_source_ccd(m, mi, &option_types_found);
-        cc_succeeded = cc_check_return(&cc_succeeded_count, ret);
-
-        if (cc_succeeded)
-        {
-            ret = multi_client_connect_call_plugin_v1(m, mi,
-                                                      &option_types_found);
-            cc_succeeded = cc_check_return(&cc_succeeded_count, ret);
-        }
-
-        if (cc_succeeded)
-        {
-            ret = multi_client_connect_call_plugin_v2(m, mi,
-                                                      &option_types_found);
-            cc_succeeded = cc_check_return(&cc_succeeded_count, ret);
-        }
-
-        /*
-         * Check for client-connect script left by management interface client
-         */
-        if (cc_succeeded)
-        {
-            ret = multi_client_connect_call_script(m, mi, &option_types_found);
-            cc_succeeded = cc_check_return(&cc_succeeded_count, ret);
-        }
-
-        if (cc_succeeded)
+        for (int i = 0; cc_succeeded && handlers[i]; i++)
         {
-            ret = multi_client_connect_mda(m, mi, &option_types_found);
+            ret = handlers[i](m, mi, &option_types_found);
             cc_succeeded = cc_check_return(&cc_succeeded_count, ret);
         }