[Openvpn-devel,v2] Move gc from openvpn_net_ctx_t to local variables

Message ID 20261106131044.16659-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] Move gc from openvpn_net_ctx_t to local variables |

Commit Message

Gert Doering Nov. 6, 2026, 1:10 p.m. UTC
  From: Arne Schwabe <arne@rfc2549.org>

All the iproute2 functions use the gc only to create local variables
and strings to ultimately pass to openvpn_execve_check. These do not
need to live longer than the function that calls openvpn_execve_check.

Since argv already has a gc and the variables are used for the
command construction with that argv, just use the gc of that local
argv.

Change-Id: I494a427924ea501382275ea96ef85a6abcd780e5
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2105
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2105
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <gert@greenie.muc.de>
  

Patch

diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networking_iproute2.c
index f091fb3..7a0f4f7 100644
--- a/src/openvpn/networking_iproute2.c
+++ b/src/openvpn/networking_iproute2.c
@@ -43,21 +43,19 @@ 
     {
         ctx->es = c->es;
     }
-    ctx->gc = gc_new();
-
     return 0;
 }
 
 void
 net_ctx_reset(openvpn_net_ctx_t *ctx)
 {
-    gc_reset(&ctx->gc);
+    (void)ctx;
 }
 
 void
 net_ctx_free(openvpn_net_ctx_t *ctx)
 {
-    gc_free(&ctx->gc);
+    (void)ctx;
 }
 
 int
@@ -148,7 +146,7 @@ 
 {
     struct argv argv = argv_new();
 
-    const char *addr_str = print_in_addr_t(*addr, 0, &ctx->gc);
+    const char *addr_str = print_in_addr_t(*addr, 0, &argv.gc);
 
     argv_printf(&argv, "%s addr add dev %s %s/%d broadcast +", iproute_path, iface, addr_str, prefixlen);
     argv_msg(M_INFO, &argv);
@@ -164,7 +162,7 @@ 
                 int prefixlen)
 {
     struct argv argv = argv_new();
-    char *addr_str = (char *)print_in6_addr(*addr, 0, &ctx->gc);
+    char *addr_str = (char *)print_in6_addr(*addr, 0, &argv.gc);
 
     argv_printf(&argv, "%s -6 addr add %s/%d dev %s", iproute_path, addr_str, prefixlen, iface);
     argv_msg(M_INFO, &argv);
@@ -179,7 +177,7 @@ 
 net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
 {
     struct argv argv = argv_new();
-    const char *addr_str = print_in_addr_t(*addr, 0, &ctx->gc);
+    const char *addr_str = print_in_addr_t(*addr, 0, &argv.gc);
 
     argv_printf(&argv, "%s addr del dev %s %s/%d", iproute_path, iface, addr_str, prefixlen);
 
@@ -196,7 +194,7 @@ 
                 int prefixlen)
 {
     struct argv argv = argv_new();
-    char *addr_str = (char *)print_in6_addr(*addr, 0, &ctx->gc);
+    char *addr_str = (char *)print_in6_addr(*addr, 0, &argv.gc);
 
     argv_printf(&argv, "%s -6 addr del %s/%d dev %s", iproute_path, addr_str, prefixlen, iface);
     argv_msg(M_INFO, &argv);
@@ -212,8 +210,8 @@ 
                     const in_addr_t *remote)
 {
     struct argv argv = argv_new();
-    const char *local_str = print_in_addr_t(*local, 0, &ctx->gc);
-    const char *remote_str = print_in_addr_t(*remote, 0, &ctx->gc);
+    const char *local_str = print_in_addr_t(*local, 0, &argv.gc);
+    const char *remote_str = print_in_addr_t(*remote, 0, &argv.gc);
 
     argv_printf(&argv, "%s addr add dev %s local %s peer %s", iproute_path, iface, local_str,
                 remote_str);
@@ -230,8 +228,8 @@ 
                     const in_addr_t *remote)
 {
     struct argv argv = argv_new();
-    const char *local_str = print_in_addr_t(*local, 0, &ctx->gc);
-    const char *remote_str = print_in_addr_t(*remote, 0, &ctx->gc);
+    const char *local_str = print_in_addr_t(*local, 0, &argv.gc);
+    const char *remote_str = print_in_addr_t(*remote, 0, &argv.gc);
 
     argv_printf(&argv, "%s addr del dev %s local %s peer %s", iproute_path, iface, local_str,
                 remote_str);
@@ -248,7 +246,7 @@ 
                  const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
-    const char *dst_str = print_in_addr_t(*dst, 0, &ctx->gc);
+    const char *dst_str = print_in_addr_t(*dst, 0, &argv.gc);
     int ret = 0;
 
     argv_printf(&argv, "%s route add %s/%d", iproute_path, dst_str, prefixlen);
@@ -265,7 +263,7 @@ 
 
     if (gw)
     {
-        const char *gw_str = print_in_addr_t(*gw, 0, &ctx->gc);
+        const char *gw_str = print_in_addr_t(*gw, 0, &argv.gc);
 
         argv_printf_cat(&argv, "via %s", gw_str);
     }
@@ -286,14 +284,14 @@ 
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
-    char *dst_str = (char *)print_in6_addr(*dst, 0, &ctx->gc);
+    char *dst_str = (char *)print_in6_addr(*dst, 0, &argv.gc);
     int ret = 0;
 
     argv_printf(&argv, "%s -6 route add %s/%d dev %s", iproute_path, dst_str, prefixlen, iface);
 
     if (gw)
     {
-        char *gw_str = (char *)print_in6_addr(*gw, 0, &ctx->gc);
+        char *gw_str = (char *)print_in6_addr(*gw, 0, &argv.gc);
 
         argv_printf_cat(&argv, "via %s", gw_str);
     }
@@ -319,7 +317,7 @@ 
                  const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
-    const char *dst_str = print_in_addr_t(*dst, 0, &ctx->gc);
+    const char *dst_str = print_in_addr_t(*dst, 0, &argv.gc);
     int ret = 0;
 
     argv_printf(&argv, "%s route del %s/%d", iproute_path, dst_str, prefixlen);
@@ -345,14 +343,14 @@ 
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
-    char *dst_str = (char *)print_in6_addr(*dst, 0, &ctx->gc);
+    char *dst_str = (char *)print_in6_addr(*dst, 0, &argv.gc);
     int ret = 0;
 
     argv_printf(&argv, "%s -6 route del %s/%d dev %s", iproute_path, dst_str, prefixlen, iface);
 
     if (gw)
     {
-        char *gw_str = (char *)print_in6_addr(*gw, 0, &ctx->gc);
+        char *gw_str = (char *)print_in6_addr(*gw, 0, &argv.gc);
 
         argv_printf_cat(&argv, "via %s", gw_str);
     }
diff --git a/src/openvpn/networking_iproute2.h b/src/openvpn/networking_iproute2.h
index dd7d8b3..dac5f0d 100644
--- a/src/openvpn/networking_iproute2.h
+++ b/src/openvpn/networking_iproute2.h
@@ -28,7 +28,6 @@ 
 struct openvpn_net_ctx
 {
     struct env_set *es;
-    struct gc_arena gc;
 };
 
 typedef struct openvpn_net_ctx openvpn_net_ctx_t;