]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Move run_up_down() to init.c
authorSteffan Karger <steffan.karger@fox-it.com>
Tue, 15 Aug 2017 15:39:46 +0000 (17:39 +0200)
committerDavid Sommerseth <davids@openvpn.net>
Wed, 16 Aug 2017 15:00:25 +0000 (17:00 +0200)
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)

src/openvpn/init.c
src/openvpn/misc.c
src/openvpn/misc.h

index cbb27cc769190c849aa3cdd2663e7737581e7c0c..133a9f508425c0ad3aad06dd07d5c846860f84c1 100644 (file)
@@ -93,6 +93,94 @@ context_clear_all_except_first_time(struct context *c)
     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.
index cd12f9186223d59c8580f2dc8f55f4611311d105..8c7f611693798ba66a979c2ec5822a129b93d7f3 100644 (file)
@@ -54,95 +54,6 @@ const char *iproute_path = IPROUTE_PATH; /* GLOBAL */
 /* 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
  */
index a7aa7622af30adc624030df57f10f1fc2c8985cd..eb39ce3f41635515edb38595f51bb913c40a6590 100644 (file)
@@ -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)