[Openvpn-devel] options: don't export local function pre_connect_save()

Message ID 20220711122348.8756-1-a@unstable.cc
State Accepted
Headers show
Series [Openvpn-devel] options: don't export local function pre_connect_save() | expand

Commit Message

Antonio Quartulli July 11, 2022, 2:23 a.m. UTC
The pre_connect_save() function is not used outside of options.c,
therefore it should not be exported.

Make it static and move definition before its invocation.
Move also pre_connect_restore() along with it in order to keep the two
close to each other.

Cc: Arne Schwabe <arne@rfc2549.org>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
 src/openvpn/options.c | 238 +++++++++++++++++++++---------------------
 src/openvpn/options.h |   2 -
 2 files changed, 119 insertions(+), 121 deletions(-)

Comments

Heiko Hund July 11, 2022, 5:12 a.m. UTC | #1
On Montag, 11. Juli 2022 14:23:48 CEST Antonio Quartulli wrote:
> The pre_connect_save() function is not used outside of options.c,
> therefore it should not be exported.
> 
> Make it static and move definition before its invocation.
> Move also pre_connect_restore() along with it in order to keep the two
> close to each other.
> 
> Cc: Arne Schwabe <arne@rfc2549.org>
> Signed-off-by: Antonio Quartulli <a@unstable.cc>

Noticed this as well before, but was too lazy to patch ;-)

Acked-by: Heiko Hund <heiko@ist.eigentlich.net>
Gert Doering July 13, 2022, 12:27 a.m. UTC | #2
"git show --color-moved=zebra" is very clear on this :-) - so I did not
bother to do more testing than "does it really still compile?"

Your patch has been applied to the master branch.

commit ad085464b15d63324846d0a5151141f58ccb5a34
Author: Antonio Quartulli
Date:   Mon Jul 11 14:23:48 2022 +0200

     options: don't export local function pre_connect_save()

     Signed-off-by: Antonio Quartulli <a@unstable.cc>
     Acked-by: Heiko Hund <heiko@ist.eigentlich.net>
     Message-Id: <20220711122348.8756-1-a@unstable.cc>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24666.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 fa66b513..6f83406b 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -3219,6 +3219,125 @@  remap_redirect_gateway_flags(struct options *opt)
 }
 #endif
 
+/*
+ * Save/Restore certain option defaults before --pull is applied.
+ */
+
+static void
+pre_connect_save(struct options *o)
+{
+    ALLOC_OBJ_CLEAR_GC(o->pre_connect, struct options_pre_connect, &o->gc);
+    o->pre_connect->tuntap_options = o->tuntap_options;
+    o->pre_connect->tuntap_options_defined = true;
+    o->pre_connect->foreign_option_index = o->foreign_option_index;
+
+    if (o->routes)
+    {
+        o->pre_connect->routes = clone_route_option_list(o->routes, &o->gc);
+        o->pre_connect->routes_defined = true;
+    }
+    if (o->routes_ipv6)
+    {
+        o->pre_connect->routes_ipv6 = clone_route_ipv6_option_list(o->routes_ipv6, &o->gc);
+        o->pre_connect->routes_ipv6_defined = true;
+    }
+    if (o->client_nat)
+    {
+        o->pre_connect->client_nat = clone_client_nat_option_list(o->client_nat, &o->gc);
+        o->pre_connect->client_nat_defined = true;
+    }
+
+    o->pre_connect->route_default_gateway = o->route_default_gateway;
+    o->pre_connect->route_ipv6_default_gateway = o->route_ipv6_default_gateway;
+
+    o->pre_connect->dns_options = clone_dns_options(o->dns_options, &o->gc);
+
+    /* NCP related options that can be overwritten by a push */
+    o->pre_connect->ciphername = o->ciphername;
+    o->pre_connect->authname = o->authname;
+
+    /* Ping related options should be reset to the config values on reconnect */
+    o->pre_connect->ping_rec_timeout = o->ping_rec_timeout;
+    o->pre_connect->ping_rec_timeout_action = o->ping_rec_timeout_action;
+    o->pre_connect->ping_send_timeout = o->ping_send_timeout;
+
+    /* Miscellaneous Options */
+#ifdef USE_COMP
+    o->pre_connect->comp = o->comp;
+#endif
+}
+
+void
+pre_connect_restore(struct options *o, struct gc_arena *gc)
+{
+    const struct options_pre_connect *pp = o->pre_connect;
+    if (pp)
+    {
+        CLEAR(o->tuntap_options);
+        if (pp->tuntap_options_defined)
+        {
+            o->tuntap_options = pp->tuntap_options;
+        }
+
+        if (pp->routes_defined)
+        {
+            rol_check_alloc(o);
+            copy_route_option_list(o->routes, pp->routes, gc);
+        }
+        else
+        {
+            o->routes = NULL;
+        }
+
+        if (pp->routes_ipv6_defined)
+        {
+            rol6_check_alloc(o);
+            copy_route_ipv6_option_list(o->routes_ipv6, pp->routes_ipv6, gc);
+        }
+        else
+        {
+            o->routes_ipv6 = NULL;
+        }
+
+        o->route_default_gateway = pp->route_default_gateway;
+        o->route_ipv6_default_gateway = pp->route_ipv6_default_gateway;
+
+        /* Free DNS options and reset them to pre-pull state */
+        gc_free(&o->dns_options.gc);
+        struct gc_arena dns_gc = gc_new();
+        o->dns_options = clone_dns_options(pp->dns_options, &dns_gc);
+        o->dns_options.gc = dns_gc;
+
+        if (pp->client_nat_defined)
+        {
+            cnol_check_alloc(o);
+            copy_client_nat_option_list(o->client_nat, pp->client_nat);
+        }
+        else
+        {
+            o->client_nat = NULL;
+        }
+
+        o->foreign_option_index = pp->foreign_option_index;
+
+        o->ciphername = pp->ciphername;
+        o->authname = pp->authname;
+
+        o->ping_rec_timeout = pp->ping_rec_timeout;
+        o->ping_rec_timeout_action = pp->ping_rec_timeout_action;
+        o->ping_send_timeout = pp->ping_send_timeout;
+
+        /* Miscellaneous Options */
+#ifdef USE_COMP
+        o->comp = pp->comp;
+#endif
+    }
+
+    o->push_continuation = 0;
+    o->push_option_types_found = 0;
+    o->data_channel_crypto_flags = 0;
+}
+
 static void
 options_postprocess_mutate_invariant(struct options *options)
 {
@@ -3946,125 +4065,6 @@  options_postprocess_pull(struct options *o, struct env_set *es)
     return success;
 }
 
-/*
- * Save/Restore certain option defaults before --pull is applied.
- */
-
-void
-pre_connect_save(struct options *o)
-{
-    ALLOC_OBJ_CLEAR_GC(o->pre_connect, struct options_pre_connect, &o->gc);
-    o->pre_connect->tuntap_options = o->tuntap_options;
-    o->pre_connect->tuntap_options_defined = true;
-    o->pre_connect->foreign_option_index = o->foreign_option_index;
-
-    if (o->routes)
-    {
-        o->pre_connect->routes = clone_route_option_list(o->routes, &o->gc);
-        o->pre_connect->routes_defined = true;
-    }
-    if (o->routes_ipv6)
-    {
-        o->pre_connect->routes_ipv6 = clone_route_ipv6_option_list(o->routes_ipv6, &o->gc);
-        o->pre_connect->routes_ipv6_defined = true;
-    }
-    if (o->client_nat)
-    {
-        o->pre_connect->client_nat = clone_client_nat_option_list(o->client_nat, &o->gc);
-        o->pre_connect->client_nat_defined = true;
-    }
-
-    o->pre_connect->route_default_gateway = o->route_default_gateway;
-    o->pre_connect->route_ipv6_default_gateway = o->route_ipv6_default_gateway;
-
-    o->pre_connect->dns_options = clone_dns_options(o->dns_options, &o->gc);
-
-    /* NCP related options that can be overwritten by a push */
-    o->pre_connect->ciphername = o->ciphername;
-    o->pre_connect->authname = o->authname;
-
-    /* Ping related options should be reset to the config values on reconnect */
-    o->pre_connect->ping_rec_timeout = o->ping_rec_timeout;
-    o->pre_connect->ping_rec_timeout_action = o->ping_rec_timeout_action;
-    o->pre_connect->ping_send_timeout = o->ping_send_timeout;
-
-    /* Miscellaneous Options */
-#ifdef USE_COMP
-    o->pre_connect->comp = o->comp;
-#endif
-}
-
-void
-pre_connect_restore(struct options *o, struct gc_arena *gc)
-{
-    const struct options_pre_connect *pp = o->pre_connect;
-    if (pp)
-    {
-        CLEAR(o->tuntap_options);
-        if (pp->tuntap_options_defined)
-        {
-            o->tuntap_options = pp->tuntap_options;
-        }
-
-        if (pp->routes_defined)
-        {
-            rol_check_alloc(o);
-            copy_route_option_list(o->routes, pp->routes, gc);
-        }
-        else
-        {
-            o->routes = NULL;
-        }
-
-        if (pp->routes_ipv6_defined)
-        {
-            rol6_check_alloc(o);
-            copy_route_ipv6_option_list(o->routes_ipv6, pp->routes_ipv6, gc);
-        }
-        else
-        {
-            o->routes_ipv6 = NULL;
-        }
-
-        o->route_default_gateway = pp->route_default_gateway;
-        o->route_ipv6_default_gateway = pp->route_ipv6_default_gateway;
-
-        /* Free DNS options and reset them to pre-pull state */
-        gc_free(&o->dns_options.gc);
-        struct gc_arena dns_gc = gc_new();
-        o->dns_options = clone_dns_options(pp->dns_options, &dns_gc);
-        o->dns_options.gc = dns_gc;
-
-        if (pp->client_nat_defined)
-        {
-            cnol_check_alloc(o);
-            copy_client_nat_option_list(o->client_nat, pp->client_nat);
-        }
-        else
-        {
-            o->client_nat = NULL;
-        }
-
-        o->foreign_option_index = pp->foreign_option_index;
-
-        o->ciphername = pp->ciphername;
-        o->authname = pp->authname;
-
-        o->ping_rec_timeout = pp->ping_rec_timeout;
-        o->ping_rec_timeout_action = pp->ping_rec_timeout_action;
-        o->ping_send_timeout = pp->ping_send_timeout;
-
-        /* Miscellaneous Options */
-#ifdef USE_COMP
-        o->comp = pp->comp;
-#endif
-    }
-
-    o->push_continuation = 0;
-    o->push_option_types_found = 0;
-    o->data_channel_crypto_flags = 0;
-}
-
 /*
  * Build an options string to represent data channel encryption options.
  * This string must match exactly between peers.  The keysize is checked
diff --git a/src/openvpn/options.h b/src/openvpn/options.h
index 1b30cedd..7acffc3d 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/options.h
@@ -817,8 +817,6 @@  void options_postprocess(struct options *options, struct env_set *es);
 
 bool options_postprocess_pull(struct options *o, struct env_set *es);
 
-void pre_connect_save(struct options *o);
-
 void pre_connect_restore(struct options *o, struct gc_arena *gc);
 
 bool apply_push_options(struct options *options,