[Openvpn-devel,v5] Refactor early initialisation and uninitialisation into methods

Message ID 20211106180055.3073072-1-arne@rfc2549.org
State Accepted
Headers show
Series [Openvpn-devel,v5] Refactor early initialisation and uninitialisation into methods | expand

Commit Message

Arne Schwabe Nov. 6, 2021, 7 a.m. UTC
This put the early initialisation and uninitialisation that needs to
happen between option parsing and post processing into small methods.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/openvpn.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

Comments

Antonio Quartulli Nov. 7, 2021, 5:35 a.m. UTC | #1
Hi,

On 06/11/2021 19:00, Arne Schwabe wrote:
> This put the early initialisation and uninitialisation that needs to
> happen between option parsing and post processing into small methods.
> 
> Signed-off-by: Arne Schwabe <arne@rfc2549.org>

Change looks good, no error/warning upon compilation and a basic 
connectivity test just worked with both sitnl and iproute2.

Acked-by: Antonio Quartulli <a@unbstable.cc>
Gert Doering Nov. 7, 2021, 8:36 a.m. UTC | #2
Took us long enough for such a "simple" refactoring task... pesky 
language, this "C" stuff :-)

Thanks, Antonio, for verifying the sitnl stuff.

(GCC on Linux actually found and errored on the v4 bit with the missing
"&", I just did not look at the compile result because I saw the mismatch
in the diff earlier... now, no more warnings, and success on Linux/sitnl
with the v5 patch)

Your patch has been applied to the master branch.

commit 97056dbf936b01b367a66ea78cca3dadc41bdf64
Author: Arne Schwabe
Date:   Sat Nov 6 19:00:55 2021 +0100

     Refactor early initialisation and uninitialisation into methods

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Antonio Quartulli <antonio@openvpn.net>
     Message-Id: <20211106180055.3073072-1-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg23110.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c
index 0ac961429..da06f59c2 100644
--- a/src/openvpn/openvpn.c
+++ b/src/openvpn/openvpn.c
@@ -105,6 +105,20 @@  tunnel_point_to_point(struct context *c)
 
 #undef PROCESS_SIGNAL_P2P
 
+void init_early(struct context *c)
+{
+    net_ctx_init(c, &c->net_ctx);
+
+    /* init verbosity and mute levels */
+    init_verb_mute(c, IVM_LEVEL_1);
+
+}
+
+static void uninit_early(struct context *c)
+{
+    net_ctx_free(&c->net_ctx);
+}
+
 
 /**************************************************************************/
 /**
@@ -193,10 +207,9 @@  openvpn_main(int argc, char *argv[])
             open_plugins(&c, true, OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE);
 #endif
 
-            net_ctx_init(&c, &c.net_ctx);
-
-            /* init verbosity and mute levels */
-            init_verb_mute(&c, IVM_LEVEL_1);
+            /* Early initialisation that need to happen before option
+             * post processing and other early startup but after parsing */
+            init_early(&c);
 
             /* set dev options */
             init_options_dev(&c.options);
@@ -308,7 +321,7 @@  openvpn_main(int argc, char *argv[])
             env_set_destroy(c.es);
             uninit_options(&c.options);
             gc_reset(&c.gc);
-            net_ctx_free(&c.net_ctx);
+            uninit_early(&c);
         }
         while (c.sig->signal_received == SIGHUP);
     }