From a699681bb86c6e9a2c9f205543f60400208aea4b Mon Sep 17 00:00:00 2001 From: Antonio Quartulli Date: Wed, 23 Jul 2025 15:39:11 +0200 Subject: [PATCH] dco: only pass struct context to init function 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 Acked-by: Gert Doering 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 --- src/openvpn/dco.h | 8 +++----- src/openvpn/dco_freebsd.c | 4 ++-- src/openvpn/dco_linux.c | 10 ++++++++-- src/openvpn/dco_linux.h | 2 ++ src/openvpn/dco_win.c | 8 +++++--- src/openvpn/init.c | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h index f38316d57..90784177c 100644 --- a/src/openvpn/dco.h +++ b/src/openvpn/dco.h @@ -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; } diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index b8816c63b..98d8fb54c 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -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; diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index 3652a49af..ec6efaad1 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -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; } diff --git a/src/openvpn/dco_linux.h b/src/openvpn/dco_linux.h index 676b8cd26..5e61cf1be 100644 --- a/src/openvpn/dco_linux.h +++ b/src/openvpn/dco_linux.h @@ -65,6 +65,8 @@ typedef struct struct nl_cb *nl_cb; int status; + struct context *c; + enum ovpn_mode ifmode; int ovpn_dco_id; diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 83db7399f..e5a33a0f3 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -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: diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 77747a2df..aac8a6aa7 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -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 */ -- 2.47.2