do_persist_tuntap: remove indentation level
PATCH 1/1 do_persist_tuntap: remove indentation level
From: Lev Stipakov <[email protected]...>
Reverse if condition - this allows us to get rid of indentation level, which makes code easier to read.
Signed-off-by Lev Stipakov <[email protected]...>
--- src/openvpn/init.c | 88 ++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 43 deletions(-)
src/openvpn/init.c +45 -43
@@ -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; }
Signature · 1 line
2.23.0.windows.1
Hi,
Quoted 6 lines · Lev Stipakov
From: Lev Stipakov <[email protected]...>
Reverse if condition - this allows us to get rid of indentation level, which makes code easier to read.
Signed-off-by Lev Stipakov <[email protected]...>
Thanks for this change. I also firmly believe this style makes the code easier to read (and to brain process, imho).
Signature · 1 line
Antonio Quartulli
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 <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25153.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering