[Openvpn-devel,v1] Make parameter openvpn_net_ctx_t const where possible

Message ID 20261103193058.14082-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] Make parameter openvpn_net_ctx_t const where possible |

Commit Message

Gert Doering Nov. 3, 2026, 7:30 p.m. UTC
  From: Arne Schwabe <arne@rfc2549.org>

After move the gc_arena inside the various iproute2 related
function most of the openvpn_net_ctx_t parameters can be made const.

This does not make net_ctx_free and net_ctx_reset const as those
functions are intended to modify the net ctx even though none of
them do anymore.

Change-Id: Iee3ff1f5f3ec9331f61b0a7f1f3b9ca51575533d
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2106
---

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/+/2106
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
  

Patch

diff --git a/src/openvpn/lladdr.c b/src/openvpn/lladdr.c
index 195245f..8c3be91 100644
--- a/src/openvpn/lladdr.c
+++ b/src/openvpn/lladdr.c
@@ -15,7 +15,7 @@ 
 
 #ifdef TARGET_LINUX
 static int
-set_lladdr_linux(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr)
+set_lladdr_linux(const openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr)
 {
     uint8_t addr[OPENVPN_ETH_ALEN];
 
@@ -48,7 +48,7 @@ 
 #endif /* TARGET_LINUX */
 
 int
-set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, const struct env_set *es)
+set_lladdr(const openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, const struct env_set *es)
 {
     if (!ifname || !lladdr)
     {
diff --git a/src/openvpn/lladdr.h b/src/openvpn/lladdr.h
index 0c8b416..9ab6578 100644
--- a/src/openvpn/lladdr.h
+++ b/src/openvpn/lladdr.h
@@ -5,5 +5,5 @@ 
 #include "misc.h"
 #include "networking.h"
 
-int set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr,
+int set_lladdr(const openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr,
                const struct env_set *es);
diff --git a/src/openvpn/networking.h b/src/openvpn/networking.h
index 25233c8..7ad6e2e 100644
--- a/src/openvpn/networking.h
+++ b/src/openvpn/networking.h
@@ -101,7 +101,7 @@ 
  *
  * @return          0 on success, negative error code on error
  */
-int net_iface_new(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, const char *type,
+int net_iface_new(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, const char *type,
                   const void *arg);
 
 /**
@@ -113,7 +113,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_TYPE_LEN_MAX]);
+int net_iface_type(const openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_TYPE_LEN_MAX]);
 
 /**
  * Remove an interface
@@ -122,7 +122,7 @@ 
  * @param iface     interface to delete
  * @return int 0 on success, negative error code on error
  */
-int net_iface_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface);
+int net_iface_del(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface);
 
 /**
  * Bring interface up or down.
@@ -133,7 +133,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_iface_up(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, bool up);
+int net_iface_up(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, bool up);
 
 /**
  * Set the MTU for an interface
@@ -144,7 +144,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_iface_mtu_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint32_t mtu);
+int net_iface_mtu_set(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint32_t mtu);
 
 /**
  * Set the Link Layer (Ethernet) address of the TAP interface
@@ -155,7 +155,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint8_t *addr);
+int net_addr_ll_set(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint8_t *addr);
 
 /**
  * Add an IPv4 address to an interface
@@ -167,7 +167,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_addr_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, const in_addr_t *addr,
+int net_addr_v4_add(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, const in_addr_t *addr,
                     int prefixlen);
 
 /**
@@ -181,7 +181,7 @@ 
  * @return          0 on success, a negative error code otherwise
  */
 
-int net_addr_v6_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
+int net_addr_v6_add(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
                     const struct in6_addr *addr, int prefixlen);
 
 /**
@@ -193,7 +193,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_addr_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, const in_addr_t *addr,
+int net_addr_v4_del(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, const in_addr_t *addr,
                     int prefixlen);
 
 /**
@@ -205,7 +205,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_addr_v6_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
+int net_addr_v6_del(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
                     const struct in6_addr *addr, int prefixlen);
 
 /**
@@ -218,7 +218,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
+int net_addr_ptp_v4_add(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
                         const in_addr_t *local, const in_addr_t *remote);
 
 /**
@@ -231,7 +231,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
+int net_addr_ptp_v4_del(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface,
                         const in_addr_t *local, const in_addr_t *remote);
 
 #endif /* ENABLE_SITNL || ENABLE_IPROUTE */
@@ -251,7 +251,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
+int net_route_v4_add(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
                      const in_addr_t *gw, const openvpn_net_iface_t *iface, uint32_t table,
                      int metric);
 
@@ -269,7 +269,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+int net_route_v6_add(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                      const struct in6_addr *gw, const openvpn_net_iface_t *iface, uint32_t table,
                      int metric);
 
@@ -287,7 +287,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
+int net_route_v4_del(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen,
                      const in_addr_t *gw, const openvpn_net_iface_t *iface, uint32_t table,
                      int metric);
 
@@ -305,7 +305,7 @@ 
  *
  * @return          0 on success, a negative error code otherwise
  */
-int net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+int net_route_v6_del(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                      const struct in6_addr *gw, const openvpn_net_iface_t *iface, uint32_t table,
                      int metric);
 
diff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/networking_freebsd.c
index 04051a6..88fd5c0 100644
--- a/src/openvpn/networking_freebsd.c
+++ b/src/openvpn/networking_freebsd.c
@@ -82,28 +82,28 @@ 
 }
 
 int
-net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
+net_route_v4_add(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
                  const char *iface, uint32_t table, int metric)
 {
     return net_route_v4("add", dst, prefixlen, gw, iface, table, metric);
 }
 
 int
-net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+net_route_v6_add(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     return net_route_v6("add", dst, prefixlen, gw, iface, table, metric);
 }
 
 int
-net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
+net_route_v4_del(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
                  const char *iface, uint32_t table, int metric)
 {
     return net_route_v4("del", dst, prefixlen, gw, iface, table, metric);
 }
 
 int
-net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+net_route_v6_del(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     return net_route_v6("del", dst, prefixlen, gw, iface, table, metric);
diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networking_iproute2.c
index 4685465..68e6dfe 100644
--- a/src/openvpn/networking_iproute2.c
+++ b/src/openvpn/networking_iproute2.c
@@ -59,7 +59,7 @@ 
 }
 
 int
-net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, const char *type, const void *arg)
+net_iface_new(const openvpn_net_ctx_t *ctx, const char *iface, const char *type, const void *arg)
 {
     struct argv argv = argv_new();
 
@@ -73,7 +73,7 @@ 
 }
 
 int
-net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_TYPE_LEN_MAX])
+net_iface_type(const openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_TYPE_LEN_MAX])
 {
     /* not supported by iproute2 */
     msg(M_WARN, "%s: operation not supported by iproute2 backend", __func__);
@@ -81,7 +81,7 @@ 
 }
 
 int
-net_iface_del(openvpn_net_ctx_t *ctx, const char *iface)
+net_iface_del(const openvpn_net_ctx_t *ctx, const char *iface)
 {
     struct argv argv = argv_new();
 
@@ -94,7 +94,7 @@ 
 }
 
 int
-net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up)
+net_iface_up(const openvpn_net_ctx_t *ctx, const char *iface, bool up)
 {
     struct argv argv = argv_new();
 
@@ -108,7 +108,7 @@ 
 }
 
 int
-net_iface_mtu_set(openvpn_net_ctx_t *ctx, const char *iface, uint32_t mtu)
+net_iface_mtu_set(const openvpn_net_ctx_t *ctx, const char *iface, uint32_t mtu)
 {
     struct argv argv = argv_new();
 
@@ -122,7 +122,7 @@ 
 }
 
 int
-net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint8_t *addr)
+net_addr_ll_set(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint8_t *addr)
 {
     struct argv argv = argv_new();
     int ret = 0;
@@ -142,7 +142,7 @@ 
 }
 
 int
-net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
+net_addr_v4_add(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
 {
     struct argv argv = argv_new();
     struct gc_arena gc = gc_new();
@@ -160,7 +160,7 @@ 
 }
 
 int
-net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
+net_addr_v6_add(const openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
                 int prefixlen)
 {
     struct argv argv = argv_new();
@@ -179,7 +179,7 @@ 
 }
 
 int
-net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
+net_addr_v4_del(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
 {
     struct argv argv = argv_new();
     struct gc_arena gc = gc_new();
@@ -198,7 +198,7 @@ 
 }
 
 int
-net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
+net_addr_v6_del(const openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
                 int prefixlen)
 {
     struct argv argv = argv_new();
@@ -217,7 +217,7 @@ 
 }
 
 int
-net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
+net_addr_ptp_v4_add(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
                     const in_addr_t *remote)
 {
     struct argv argv = argv_new();
@@ -237,7 +237,7 @@ 
 }
 
 int
-net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
+net_addr_ptp_v4_del(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
                     const in_addr_t *remote)
 {
     struct argv argv = argv_new();
@@ -257,7 +257,7 @@ 
 }
 
 int
-net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
+net_route_v4_add(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
                  const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
@@ -297,7 +297,7 @@ 
 }
 
 int
-net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+net_route_v6_add(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
@@ -332,7 +332,7 @@ 
 }
 
 int
-net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
+net_route_v4_del(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
                  const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
@@ -360,7 +360,7 @@ 
 }
 
 int
-net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+net_route_v6_del(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     struct argv argv = argv_new();
diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c
index 0c99d38..97ff7bd 100644
--- a/src/openvpn/networking_sitnl.c
+++ b/src/openvpn/networking_sitnl.c
@@ -669,7 +669,7 @@ 
 #ifdef ENABLE_SITNL
 
 int
-net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up)
+net_iface_up(const openvpn_net_ctx_t *ctx, const char *iface, bool up)
 {
     struct sitnl_link_req req;
     int ifindex;
@@ -711,7 +711,7 @@ 
 }
 
 int
-net_iface_mtu_set(openvpn_net_ctx_t *ctx, const char *iface, uint32_t mtu)
+net_iface_mtu_set(const openvpn_net_ctx_t *ctx, const char *iface, uint32_t mtu)
 {
     struct sitnl_link_req req;
     int ifindex, ret = -1;
@@ -742,7 +742,7 @@ 
 }
 
 int
-net_addr_ll_set(openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint8_t *addr)
+net_addr_ll_set(const openvpn_net_ctx_t *ctx, const openvpn_net_iface_t *iface, uint8_t *addr)
 {
     struct sitnl_link_req req;
     int ifindex, ret = -1;
@@ -1038,7 +1038,7 @@ 
 }
 
 int
-net_addr_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
+net_addr_v4_add(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
 {
     inet_address_t addr_v4 = { 0 };
     char buf[INET_ADDRSTRLEN];
@@ -1057,7 +1057,7 @@ 
 }
 
 int
-net_addr_v6_add(openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
+net_addr_v6_add(const openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
                 int prefixlen)
 {
     inet_address_t addr_v6 = { 0 };
@@ -1077,7 +1077,7 @@ 
 }
 
 int
-net_addr_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
+net_addr_v4_del(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *addr, int prefixlen)
 {
     inet_address_t addr_v4 = { 0 };
     char buf[INET_ADDRSTRLEN];
@@ -1096,7 +1096,7 @@ 
 }
 
 int
-net_addr_v6_del(openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
+net_addr_v6_del(const openvpn_net_ctx_t *ctx, const char *iface, const struct in6_addr *addr,
                 int prefixlen)
 {
     inet_address_t addr_v6 = { 0 };
@@ -1116,7 +1116,7 @@ 
 }
 
 int
-net_addr_ptp_v4_add(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
+net_addr_ptp_v4_add(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
                     const in_addr_t *remote)
 {
     inet_address_t local_v4 = { 0 };
@@ -1144,7 +1144,7 @@ 
 }
 
 int
-net_addr_ptp_v4_del(openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
+net_addr_ptp_v4_del(const openvpn_net_ctx_t *ctx, const char *iface, const in_addr_t *local,
                     const in_addr_t *remote)
 {
     inet_address_t local_v4 = { 0 };
@@ -1196,7 +1196,7 @@ 
 }
 
 int
-net_route_v4_add(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
+net_route_v4_add(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
                  const char *iface, uint32_t table, int metric)
 {
     const in_addr_t *dst_ptr = NULL, *gw_ptr = NULL;
@@ -1224,7 +1224,7 @@ 
 }
 
 int
-net_route_v6_add(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+net_route_v6_add(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     inet_address_t dst_v6 = { 0 };
@@ -1275,7 +1275,7 @@ 
 }
 
 int
-net_route_v4_del(openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
+net_route_v4_del(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int prefixlen, const in_addr_t *gw,
                  const char *iface, uint32_t table, int metric)
 {
     inet_address_t dst_v4 = { 0 };
@@ -1301,7 +1301,7 @@ 
 }
 
 int
-net_route_v6_del(openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
+net_route_v6_del(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int prefixlen,
                  const struct in6_addr *gw, const char *iface, uint32_t table, int metric)
 {
     inet_address_t dst_v6 = { 0 };
@@ -1328,7 +1328,7 @@ 
 
 
 int
-net_iface_new(openvpn_net_ctx_t *ctx, const char *iface, const char *type, const void *arg)
+net_iface_new(const openvpn_net_ctx_t *ctx, const char *iface, const char *type, const void *arg)
 {
     struct sitnl_link_req req = {};
     int ret = -1;
@@ -1431,7 +1431,7 @@ 
 }
 
 int
-net_iface_type(openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_TYPE_LEN_MAX])
+net_iface_type(const openvpn_net_ctx_t *ctx, const char *iface, char type[IFACE_TYPE_LEN_MAX])
 {
     struct sitnl_link_req req = {};
     int ifindex = if_nametoindex(iface);
@@ -1463,7 +1463,7 @@ 
 }
 
 int
-net_iface_del(openvpn_net_ctx_t *ctx, const char *iface)
+net_iface_del(const openvpn_net_ctx_t *ctx, const char *iface)
 {
     struct sitnl_link_req req = {};
     int ifindex = if_nametoindex(iface);