Move run_up_down() to init.c
PATCH 1/1 Move run_up_down() to init.c
This function is only used in init.c, and is not easy to fit into a specific category because it both runs scripts and plugin hooks. Making it static in init.c is probably the best place for this function.
(I think we should find a better place for everything currently in misc.c, and get rid of it all together. This patch is part of that effort.)
--- src/openvpn/init.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/openvpn/misc.c | 89 ------------------------------------------------------ src/openvpn/misc.h | 17 ----------- 3 files changed, 88 insertions(+), 106 deletions(-)
src/openvpn/init.c +88 -0
@@ -94,6 +94,94 @@ context_clear_all_except_first_time(struct context *c) }/* +* Pass tunnel endpoint and MTU parms to a user-supplied script. +* Used to execute the up/down script/plugins. +*/ +static void +run_up_down (const char *command, +const struct plugin_list *plugins, +int plugin_type, +const char *arg, +#ifdef _WIN32 + DWORD adapter_index, +#endif +const char *dev_type, +int tun_mtu, +int link_mtu, +const char *ifconfig_local, +const char *ifconfig_remote, +const char *context, +const char *signal_text, +const char *script_type, +struct env_set *es) +{ +struct gc_arena gc =gc_new (); + +if (signal_text) + { +setenv_str (es,"signal" , signal_text); + } +setenv_str (es,"script_context" , context); +setenv_int (es,"tun_mtu" , tun_mtu); +setenv_int (es,"link_mtu" , link_mtu); +setenv_str (es,"dev" , arg); +if (dev_type) + { +setenv_str (es,"dev_type" , dev_type); + } +#ifdef _WIN32 +setenv_int (es,"dev_idx" , adapter_index); +#endif + +if (!ifconfig_local) + { + ifconfig_local ="" ; + } +if (!ifconfig_remote) + { + ifconfig_remote ="" ; + } +if (!context) + { + context ="" ; + } + +if (plugin_defined (plugins, plugin_type)) + { +struct argv argv =argv_new (); +ASSERT (arg); +argv_printf (&argv, +"%s %d %d %s %s %s" , + arg, + tun_mtu, link_mtu, + ifconfig_local, ifconfig_remote, + context); + +if (plugin_call (plugins, plugin_type, &argv,NULL , es) !=OPENVPN_PLUGIN_FUNC_SUCCESS ) + { +msg (M_FATAL ,"ERROR: up/down plugin call failed" ); + } + +argv_reset (&argv); + } + +if (command) + { +struct argv argv =argv_new (); +ASSERT (arg); +setenv_str (es,"script_type" , script_type); +argv_parse_cmd (&argv, command); +argv_printf_cat (&argv,"%s %d %d %s %s %s" , arg, tun_mtu, link_mtu, + ifconfig_local, ifconfig_remote, context); +argv_msg (M_INFO , &argv); +openvpn_run_script (&argv, es,S_FATAL ,"--up/--down" ); +argv_reset (&argv); + } + +gc_free (&gc); +} + +/* * Should be called after options->ce is modified at the top * of a SIGUSR1 restart. */
src/openvpn/misc.c +0 -89
95 lines not on this page · raw message
src/openvpn/misc.h +0 -17
@@ -51,23 +51,6 @@ struct env_set {struct env_item *list; }; -void run_up_down (const char *command, -const struct plugin_list *plugins, -int plugin_type, -const char *arg, -#ifdef _WIN32 - DWORD adapter_index, -#endif -const char *dev_type, -int tun_mtu, -int link_mtu, -const char *ifconfig_local, -const char *ifconfig_remote, -const char *context, -const char *signal_text, -const char *script_type, -struct env_set *es); -/* system flags */ #define S_SCRIPT (1<<0)#define S_FATAL (1<<1)
Signature · 1 line
2.7.4
Aloha,
Quoted 8 lines · Steffan Karger
This function is only used in
init.c, and is not easy to fit into a specific category because it both runs scripts and plugin hooks. Making it static ininit.cis probably the best place for this function.(I think we should find a better place for everything currently in
misc.c, and get rid of it all together. This patch is part of that effort.)Signed-off-by Steffan Karger <[email protected]...>
This patch just does what it says without introducing any functional change. I also agree that we should try to shrink misc.c as much as possible..therefore any cleanup going towards that direction is welcome.
ACK
Cheers,
Signature · 1 line
Antonio Quartulli
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Your patch has been applied to the following branches
commit 4a9d1d70d5b0ff04dbf26ba7e679733a54c694b6 (master) commit 81b78cf5de03f843cdf917bb2ee350ba85f49cbd (release/2.4)
Author: Steffan Karger Date: Tue Aug 15 17:39:46 2017 +0200
Move run_up_down() to init.c
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg15256.html
Signed-off-by: David Sommerseth <[email protected]...>- --
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
iQIcBAEBCgAGBQJZlGAuAAoJEIbPlEyWcf3ylAQP/3mQukJluWtKhHBsbwNvC6RV pm0kQ6BXwhIpQoR0FrUo8uCWsH+Orlo/OfdwiImY7Kit+hCyUuCb4Bg7AlVj3MEE YQefMXJdu0SWyhUPITlDykW3RbtR6ATcoEsigi+BVmUbjZ3+nKtW5feN/OtHcsuk AMp1+NPIg5tM0cQPUxCZUFx2kObkNYDgk4IsgApMNeNgZmpVfAIv3yajOUyy347U XoAZUF2igUP3xjjGvXdNa9v/bZvQAX05xfs4avcOjVHS8445CCl9kROQ1fcF1iAf 8c6zlq/GfS7xT4XJ377dkpbiquPMSc8qJnI11c0t7Dxp29+shKaWY28dUuJ8SS7s dUQPd7tvWt3hV2fMHQ/NKROZDILwjTsU5BCZQBkvijJdjeCYxs+lpA+Qolab9e0h ekyZsiuHMBUsEH33F5V8noGooZMvx9+XmQVN4M0rMaMTwSUC/7xhrNkg0SoZPZve 8PxxQmeF9XXY6PfcBc90SSwP6cjqUCiQCVsJm9RWUaHC+6fF0ec6Lzg4NRf77DEn mxHCmCGikP0zcQB6/7lPaGS/iERFfrn3Y2i4u/so0ci1C/7WMOk0rnImoDAXiW40 AyCwbB0Efrt7Y2/W1RDwfK7B/Z4U8Ow747P6adaW0SiYkQSe/EmRsGE8S8lvdNcU qMYAqEXEk3khDZEvDX/p
=qS4+
-----END PGP SIGNATURE-----