]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
dco: only pass struct context to init function
authorAntonio Quartulli <antonio@mandelbit.com>
Wed, 23 Jul 2025 13:39:11 +0000 (15:39 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 23 Jul 2025 14:58:09 +0000 (16:58 +0200)
Future DCO code will require accessing the `multi` member of the
context object.

For this reason a pointer to the context has to be stored in the
DCO context along with the rest.

At this point, rather than making the call to ovpn_dco_init()
longer with more and more parameters, pass the struct context
only and let the implementation extract the needed fields.

Change-Id: I673a17f8c5dec66cc6c28c1ed44780a7a63927d7
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250723133918.19431-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32293.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/dco.h
src/openvpn/dco_freebsd.c
src/openvpn/dco_linux.c
src/openvpn/dco_linux.h
src/openvpn/dco_win.c
src/openvpn/init.c

index f38316d5714839150658f476a059f7cdbaed0739..90784177c8c2d49bfc5002695a3dfdf8409cd9a1 100644 (file)
@@ -104,12 +104,10 @@ bool dco_check_pull_options(int msglevel, const struct options *o);
 /**
  * Initialize the DCO context
  *
- * @param mode      the instance operating mode (P2P or multi-peer)
- * @param dco       the context to initialize
- * @param dev_node  device node, used on Windows to specify certain DCO adapter
+ * @param c         the main instance context
  * @return          true on success, false otherwise
  */
-bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
+bool ovpn_dco_init(struct context *c);
 
 /**
  * Open/create a DCO interface
@@ -297,7 +295,7 @@ dco_check_pull_options(int msglevel, const struct options *o)
 }
 
 static inline bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
     return true;
 }
index b8816c63bd4362910b6802f15168ee4443bbd1d1..98d8fb54cbb6775774af51b1c25390a5cdca8833 100644 (file)
@@ -165,9 +165,9 @@ close_fd(dco_context_t *dco)
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    if (open_fd(dco) < 0)
+    if (open_fd(&c->c1.tuntap->dco) < 0)
     {
         msg(M_ERR, "Failed to open socket");
         return false;
index 3652a49af64ae9c4f3e321245db2f93b5e2cc3c7..ec6efaad12e6dfe2d6904351c69e83c7c8111806 100644 (file)
@@ -438,9 +438,11 @@ ovpn_dco_init_netlink(dco_context_t *dco)
 }
 
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case CM_TOP:
             dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@ ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
             ASSERT(false);
     }
 
+    /* store pointer to context as it may be required by message
+     * parsing routines
+     */
+    dco->c = c;
     ovpn_dco_init_netlink(dco);
     return true;
 }
index 676b8cd2656f74296d6189e5d2e4545da3cc890e..5e61cf1be369ea5d0fa24bb7cbb73cd34d970b53 100644 (file)
@@ -65,6 +65,8 @@ typedef struct
     struct nl_cb *nl_cb;
     int status;
 
+    struct context *c;
+
     enum ovpn_mode ifmode;
 
     int ovpn_dco_id;
index 83db7399f9c833e80603fe64e5ccde131e11a22b..e5a33a0f3f8232fd5afc9c53c18a3cf767cc520d 100644 (file)
@@ -188,9 +188,11 @@ dco_p2p_start_vpn(struct tuntap *tt)
  * state. The server socket should be initialized later by dco_mp_start_vpn().
  */
 bool
-ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
+ovpn_dco_init(struct context *c)
 {
-    switch (mode)
+    dco_context_t *dco = &c->c1.tuntap->dco;
+
+    switch (c->mode)
     {
         case MODE_POINT_TO_POINT:
             dco->ifmode = DCO_MODE_P2P;
@@ -198,7 +200,7 @@ ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
             break;
 
         case MODE_SERVER:
-            ovpn_dco_init_mp(dco, dev_node);
+            ovpn_dco_init_mp(dco, c->options.dev_node);
             break;
 
         default:
index 77747a2dfb61b9b1a5a20faf2bee236eef431127..aac8a6aa7a81f3ff102f4f7be636bde4e50aa729 100644 (file)
@@ -2007,7 +2007,7 @@ do_open_tun(struct context *c, int *error_flags)
 
         if (dco_enabled(&c->options))
         {
-            ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
+            ovpn_dco_init(c);
         }
 
         /* open the tun device */