[Openvpn-devel,3/4] rename foreign_option() and move it up

Message ID 20220527012457.1819262-4-heiko@ist.eigentlich.net
State Accepted
Headers show
Series [Openvpn-devel,1/4] remove foreign_option() call for IPv6 DNS servers | expand

Commit Message

Heiko Hund May 26, 2022, 3:24 p.m. UTC
Add setenv_ prefix to foreign_option funtion so it is more obvious what
it does. Move it further up within options.c, so it is defined before
all future callers. Also declare all argv strings const.

Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
---
 src/openvpn/options.c | 78 +++++++++++++++++++++----------------------
 1 file changed, 39 insertions(+), 39 deletions(-)

Comments

Gert Doering May 26, 2022, 10:21 p.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

Slightly less trivial, but "git show --color-moved=zebra" helps
visualize that it's indeed moved 1:1 and just gets a new name.

Your patch has been applied to the master branch.

commit 2c2b22b370b239ae8311e8152ab0bb81cc66fe29
Author: Heiko Hund
Date:   Fri May 27 03:24:56 2022 +0200

     rename foreign_option() and move it up

     Signed-off-by: Heiko Hund <heiko@ist.eigentlich.net>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20220527012457.1819262-4-heiko@ist.eigentlich.net>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24436.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index bc3fd6a2..9a0634a5 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -1013,6 +1013,44 @@  setenv_settings(struct env_set *es, const struct options *o)
     }
 }
 
+static void
+setenv_foreign_option(struct options *o, const char *argv[], int len, struct env_set *es)
+{
+    if (len > 0)
+    {
+        struct gc_arena gc = gc_new();
+        struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
+        struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
+        int i;
+        bool first = true;
+        bool good = true;
+
+        good &= buf_printf(&name, "foreign_option_%d", o->foreign_option_index + 1);
+        ++o->foreign_option_index;
+        for (i = 0; i < len; ++i)
+        {
+            if (argv[i])
+            {
+                if (!first)
+                {
+                    good &= buf_printf(&value, " ");
+                }
+                good &= buf_printf(&value, "%s", argv[i]);
+                first = false;
+            }
+        }
+        if (good)
+        {
+            setenv_str(es, BSTR(&name), BSTR(&value));
+        }
+        else
+        {
+            msg(M_WARN, "foreign_option: name/value overflow");
+        }
+        gc_free(&gc);
+    }
+}
+
 static in_addr_t
 get_ip_addr(const char *ip_string, int msglevel, bool *error)
 {
@@ -4378,44 +4416,6 @@  options_string_extract_option(const char *options_string, const char *opt_name,
     return ret;
 }
 
-static void
-foreign_option(struct options *o, char *argv[], int len, struct env_set *es)
-{
-    if (len > 0)
-    {
-        struct gc_arena gc = gc_new();
-        struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
-        struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
-        int i;
-        bool first = true;
-        bool good = true;
-
-        good &= buf_printf(&name, "foreign_option_%d", o->foreign_option_index + 1);
-        ++o->foreign_option_index;
-        for (i = 0; i < len; ++i)
-        {
-            if (argv[i])
-            {
-                if (!first)
-                {
-                    good &= buf_printf(&value, " ");
-                }
-                good &= buf_printf(&value, "%s", argv[i]);
-                first = false;
-            }
-        }
-        if (good)
-        {
-            setenv_str(es, BSTR(&name), BSTR(&value));
-        }
-        else
-        {
-            msg(M_WARN, "foreign_option: name/value overflow");
-        }
-        gc_free(&gc);
-    }
-}
-
 #ifdef _WIN32
 /**
  * Parses --windows-driver config option
@@ -8014,7 +8014,7 @@  add_option(struct options *options,
     else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
     {
         VERIFY_PERMISSION(OPT_P_IPWIN32);
-        foreign_option(options, p, 3, es);
+        setenv_foreign_option(options, (const char **)p, 3, es);
     }
     else if (streq(p[0], "route-method") && p[1] && !p[2]) /* ignore when pushed to non-Windows OS */
     {