Skip to content

Commit

Permalink
Refactor methods to use the actual state of tun rather the options st…
Browse files Browse the repository at this point in the history
…ruct

Change-Id: Ib8ba2b63ea9fd1944ff07f69c545a880e464680c
Signed-off-by: Arne Schwabe <[email protected]>
  • Loading branch information
schwabe committed Sep 18, 2024
1 parent dc39566 commit 418ea97
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/openvpn/dco.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ dco_check_pull_options(int msglevel, const struct options *o)
int
dco_p2p_add_new_peer(struct context *c)
{
if (!dco_enabled(&c->options))
if (!tun_dco_enabled(c->c1.tuntap))
{
return 0;
}
Expand Down Expand Up @@ -511,7 +511,7 @@ dco_p2p_add_new_peer(struct context *c)
void
dco_remove_peer(struct context *c)
{
if (!dco_enabled(&c->options))
if (!tun_dco_enabled(c->c1.tuntap))
{
return;
}
Expand Down Expand Up @@ -631,7 +631,7 @@ dco_install_iroute(struct multi_context *m, struct multi_instance *mi,
struct mroute_addr *addr)
{
#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
if (!dco_enabled(&m->top.options))
if (tun_dco_enabled(m->top.c1.tuntap))
{
return;
}
Expand Down Expand Up @@ -668,7 +668,7 @@ void
dco_delete_iroutes(struct multi_context *m, struct multi_instance *mi)
{
#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
if (!dco_enabled(&m->top.options))
if (!tun_dco_enabled(m->top.c1.tuntap))
{
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/openvpn/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void
check_dco_key_status(struct context *c)
{
/* DCO context is not yet initialised or enabled */
if (!dco_enabled(&c->options))
if (!tun_dco_enabled(c->c1.tuntap))
{
return;
}
Expand Down Expand Up @@ -483,7 +483,7 @@ check_add_routes(struct context *c)
static void
check_inactivity_timeout(struct context *c)
{
if (dco_enabled(&c->options) && dco_get_peer_stats(c) == 0)
if (tun_dco_enabled(c->c1.tuntap) && dco_get_peer_stats(c) == 0)
{
int64_t tot_bytes = c->c2.tun_read_bytes + c->c2.tun_write_bytes;
int64_t new_bytes = tot_bytes - c->c2.inactivity_bytes;
Expand Down Expand Up @@ -623,7 +623,7 @@ encrypt_sign(struct context *c, bool comp_frag)
const uint8_t *orig_buf = c->c2.buf.data;
struct crypto_options *co = NULL;

if (dco_enabled(&c->options))
if (tun_dco_enabled(c->c1.tuntap))
{
msg(M_WARN, "Attempting to send data packet while data channel offload is in use. "
"Dropping packet");
Expand Down
9 changes: 0 additions & 9 deletions src/openvpn/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1872,15 +1872,6 @@ tun_name_is_fixed(const char *dev)
return has_digit(dev);
}

#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD)
static bool
tun_dco_enabled(struct tuntap *tt)
{
return tt->backend_driver == DRIVER_DCO;
}
#endif


#if !(defined(_WIN32) || defined(TARGET_LINUX) || defined(TARGET_SOLARIS))
static void
open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
Expand Down
6 changes: 6 additions & 0 deletions src/openvpn/tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ enum tun_driver_type {
DRIVER_UTUN
};

inline static bool
tun_dco_enabled(struct tuntap *tt)
{
return tt && tt->backend_driver == DRIVER_DCO;

Check failure on line 63 in src/openvpn/tun.h

View workflow job for this annotation

GitHub Actions / gcc-mingw - x86 - OSSL

invalid use of undefined type ‘struct tuntap’

Check failure on line 63 in src/openvpn/tun.h

View workflow job for this annotation

GitHub Actions / gcc-mingw - x86 - OSSL

invalid use of undefined type ‘struct tuntap’

Check failure on line 63 in src/openvpn/tun.h

View workflow job for this annotation

GitHub Actions / gcc-mingw - x64 - OSSL

invalid use of undefined type ‘struct tuntap’

Check failure on line 63 in src/openvpn/tun.h

View workflow job for this annotation

GitHub Actions / gcc-mingw - x64 - OSSL

invalid use of undefined type ‘struct tuntap’
}

#ifdef _WIN32
#define WINTUN_COMPONENT_ID "wintun"
#define DCO_WIN_REFERENCE_STRING "ovpn-dco"
Expand Down

0 comments on commit 418ea97

Please sign in to comment.