Skip to content

Commit 482409c

Browse files
committed
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 <antonio@mandelbit.com>
1 parent 7f5a6de commit 482409c

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

src/openvpn/dco.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ bool dco_check_pull_options(int msglevel, const struct options *o);
104104
/**
105105
* Initialize the DCO context
106106
*
107-
* @param mode the instance operating mode (P2P or multi-peer)
108-
* @param dco the context to initialize
109-
* @param dev_node device node, used on Windows to specify certain DCO adapter
107+
* @param c the main instance context
110108
* @return true on success, false otherwise
111109
*/
112-
bool ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node);
110+
bool ovpn_dco_init(struct context *c);
113111

114112
/**
115113
* Open/create a DCO interface
@@ -297,7 +295,7 @@ dco_check_pull_options(int msglevel, const struct options *o)
297295
}
298296

299297
static inline bool
300-
ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
298+
ovpn_dco_init(struct context *c)
301299
{
302300
return true;
303301
}

src/openvpn/dco_freebsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ close_fd(dco_context_t *dco)
165165
}
166166

167167
bool
168-
ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
168+
ovpn_dco_init(struct context *c)
169169
{
170-
if (open_fd(dco) < 0)
170+
if (open_fd(&c->c1.tuntap->dco) < 0)
171171
{
172172
msg(M_ERR, "Failed to open socket");
173173
return false;

src/openvpn/dco_linux.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,11 @@ ovpn_dco_init_netlink(dco_context_t *dco)
438438
}
439439

440440
bool
441-
ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
441+
ovpn_dco_init(struct context *c)
442442
{
443-
switch (mode)
443+
dco_context_t *dco = &c->c1.tuntap->dco;
444+
445+
switch (c->mode)
444446
{
445447
case CM_TOP:
446448
dco->ifmode = OVPN_MODE_MP;
@@ -454,6 +456,10 @@ ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
454456
ASSERT(false);
455457
}
456458

459+
/* store pointer to context as it may be required by message
460+
* parsing routines
461+
*/
462+
dco->c = c;
457463
ovpn_dco_init_netlink(dco);
458464
return true;
459465
}

src/openvpn/dco_linux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typedef struct
6565
struct nl_cb *nl_cb;
6666
int status;
6767

68+
struct context *c;
69+
6870
enum ovpn_mode ifmode;
6971

7072
int ovpn_dco_id;

src/openvpn/dco_win.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,19 @@ dco_p2p_start_vpn(struct tuntap *tt)
188188
* state. The server socket should be initialized later by dco_mp_start_vpn().
189189
*/
190190
bool
191-
ovpn_dco_init(int mode, dco_context_t *dco, const char *dev_node)
191+
ovpn_dco_init(struct context *c)
192192
{
193-
switch (mode)
193+
dco_context_t *dco = &c->c1.tuntap->dco;
194+
195+
switch (c->mode)
194196
{
195197
case MODE_POINT_TO_POINT:
196198
dco->ifmode = DCO_MODE_P2P;
197199
dco_p2p_start_vpn(dco->tt);
198200
break;
199201

200202
case MODE_SERVER:
201-
ovpn_dco_init_mp(dco, dev_node);
203+
ovpn_dco_init_mp(dco, c->options.dev_node);
202204
break;
203205

204206
default:

src/openvpn/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ do_open_tun(struct context *c, int *error_flags)
20072007

20082008
if (dco_enabled(&c->options))
20092009
{
2010-
ovpn_dco_init(c->mode, &c->c1.tuntap->dco, c->options.dev_node);
2010+
ovpn_dco_init(c);
20112011
}
20122012

20132013
/* open the tun device */

0 commit comments

Comments
 (0)