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.)
Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Antonio Quartulli <a@unstable.cc>
Message-Id: <
1502811586-19578-1-git-send-email-steffan.karger@fox-it.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15256.html
Signed-off-by: David Sommerseth <davids@openvpn.net>
(cherry picked from commit
4a9d1d70d5b0ff04dbf26ba7e679733a54c694b6)
c->persist = cpsave;
}
+/*
+ * 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.
/* contains an SSEC_x value defined in misc.h */
int script_security = SSEC_BUILT_IN; /* GLOBAL */
-/*
- * Pass tunnel endpoint and MTU parms to a user-supplied script.
- * Used to execute the up/down script/plugins.
- */
-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);
-}
-
-
/*
* Set standard file descriptors to /dev/null
*/
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)