]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
client-connect: Refactor client-connect handling to calling a bunch of hooks in a...
authorFabian Knittel <fabian.knittel@lettink.de>
Sat, 11 Jul 2020 09:36:47 +0000 (11:36 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 15 Jul 2020 12:53:15 +0000 (14:53 +0200)
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>
Patch V5: Rebase on master.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <a@unstable.cc>
Message-Id: <20200711093655.23686-6-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20293.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/multi.c

index 9c3a513bd942512429b6a7a754ef4da8828514cc..14facfa3b675413208bf748bb8e75d7700fb3312 100644 (file)
@@ -2248,6 +2248,10 @@ cc_check_return(int *cc_succeeded_count,
     }
 }
 
+typedef enum client_connect_return (*multi_client_connect_handler)
+    (struct multi_context *m, struct multi_instance *mi,
+     unsigned int *option_types_found);
+
 /*
  * Called as soon as the SSL/TLS connection is authenticated.
  *
@@ -2275,7 +2279,17 @@ multi_connection_established(struct multi_context *m, struct multi_instance *mi)
     {
         return;
     }
-    unsigned int option_types_found = 0;
+
+        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 */
     int cc_succeeded_count = 0;
@@ -2283,31 +2297,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);
-    }
-
-
-    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);
     }