[Openvpn-devel] do_persist_tuntap: remove indentation level

Message ID 20220909064126.482-1-lstipakov@gmail.com
State Accepted
Headers show
Series [Openvpn-devel] do_persist_tuntap: remove indentation level | expand

Commit Message

Lev Stipakov Sept. 8, 2022, 8:41 p.m. UTC
From: Lev Stipakov <lev@openvpn.net>

Reverse if condition - this allows us to get rid of
indentation level, which makes code easier to read.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
---
 src/openvpn/init.c | 88 ++++++++++++++++++++++++----------------------
 1 file changed, 45 insertions(+), 43 deletions(-)

Comments

Antonio Quartulli Sept. 8, 2022, 8:58 p.m. UTC | #1
Hi,

On 09/09/2022 08:41, Lev Stipakov wrote:
> From: Lev Stipakov <lev@openvpn.net>
> 
> Reverse if condition - this allows us to get rid of
> indentation level, which makes code easier to read.
> 
> Signed-off-by: Lev Stipakov <lev@openvpn.net>

Thanks for this change. I also firmly believe this style makes the code 
easier to read (and to brain process, imho).

Acked-by: Antonio Quartulli <a@unstable.cc>
Gert Doering Sept. 8, 2022, 10:17 p.m. UTC | #2
Best viewed with "-w" :-) - mildly client-side tested.

Your patch has been applied to the master branch.

commit 84099782cfa61c9e06781ff31c4a57d65b8594d3
Author: Lev Stipakov
Date:   Fri Sep 9 09:41:26 2022 +0300

     do_persist_tuntap: remove indentation level

     Signed-off-by: Lev Stipakov <lev@openvpn.net>
     Acked-by: Antonio Quartulli <antonio@openvpn.net>
     Message-Id: <20220909064126.482-1-lstipakov@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25153.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 84d95c21..d94b781e 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -1057,57 +1057,59 @@  do_genkey(const struct options *options)
 bool
 do_persist_tuntap(struct options *options, openvpn_net_ctx_t *ctx)
 {
-    if (options->persist_config)
-    {
-        /* sanity check on options for --mktun or --rmtun */
-        notnull(options->dev, "TUN/TAP device (--dev)");
-        if (options->ce.remote || options->ifconfig_local
-            || options->ifconfig_remote_netmask
-            || options->shared_secret_file
-            || options->tls_server || options->tls_client
-            )
-        {
-            msg(M_FATAL|M_OPTERR,
-                "options --mktun or --rmtun should only be used together with --dev");
-        }
+    if (!options->persist_config)
+    {
+        return false;
+    }
 
-#if defined(ENABLE_DCO)
-        if (dco_enabled(options))
-        {
-            /* creating a DCO interface via --mktun is not supported as it does not
-             * make much sense. Since DCO is enabled by default, people may run into
-             * this without knowing, therefore this case should be properly handled.
-             *
-             * Disable DCO if --mktun was provided and print a message to let
-             * user know.
-             */
-            if (dev_type_enum(options->dev, options->dev_type) == DEV_TYPE_TUN)
-            {
-                msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN interface.");
-            }
+    /* sanity check on options for --mktun or --rmtun */
+    notnull(options->dev, "TUN/TAP device (--dev)");
+    if (options->ce.remote || options->ifconfig_local
+        || options->ifconfig_remote_netmask
+        || options->shared_secret_file
+        || options->tls_server || options->tls_client
+        )
+    {
+        msg(M_FATAL|M_OPTERR,
+            "options --mktun or --rmtun should only be used together with --dev");
+    }
 
-            options->tuntap_options.disable_dco = true;
+#if defined(ENABLE_DCO)
+    if (dco_enabled(options))
+    {
+        /* creating a DCO interface via --mktun is not supported as it does not
+         * make much sense. Since DCO is enabled by default, people may run into
+         * this without knowing, therefore this case should be properly handled.
+         *
+         * Disable DCO if --mktun was provided and print a message to let
+         * user know.
+         */
+        if (dev_type_enum(options->dev, options->dev_type) == DEV_TYPE_TUN)
+        {
+            msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN interface.");
         }
+
+        options->tuntap_options.disable_dco = true;
+    }
 #endif
 
 #ifdef ENABLE_FEATURE_TUN_PERSIST
-        tuncfg(options->dev, options->dev_type, options->dev_node,
-               options->persist_mode,
-               options->username, options->groupname, &options->tuntap_options,
-               ctx);
-        if (options->persist_mode && options->lladdr)
-        {
-            set_lladdr(ctx, options->dev, options->lladdr, NULL);
-        }
-        return true;
+    tuncfg(options->dev, options->dev_type, options->dev_node,
+           options->persist_mode,
+           options->username, options->groupname, &options->tuntap_options,
+           ctx);
+    if (options->persist_mode && options->lladdr)
+    {
+        set_lladdr(ctx, options->dev, options->lladdr, NULL);
+    }
+    return true;
 #else  /* ifdef ENABLE_FEATURE_TUN_PERSIST */
-        msg( M_FATAL|M_OPTERR,
-             "options --mktun and --rmtun are not available on your operating "
-             "system.  Please check 'man tun' (or 'tap'), whether your system "
-             "supports using 'ifconfig %s create' / 'destroy' to create/remove "
-             "persistent tunnel interfaces.", options->dev );
+    msg(M_FATAL|M_OPTERR,
+        "options --mktun and --rmtun are not available on your operating "
+        "system.  Please check 'man tun' (or 'tap'), whether your system "
+        "supports using 'ifconfig %s create' / 'destroy' to create/remove "
+        "persistent tunnel interfaces.", options->dev );
 #endif
-    }
     return false;
 }