Skip to content

Commit

Permalink
Move to common backend_driver type in struct tuntap
Browse files Browse the repository at this point in the history
With the introduction of utun on macOS and DCO on Linux, FreeBSD and
Windows, a lot of platforms have now more than one driver/backend for
the tun interface but each one uses a different mechanism. Unify these
approach with using a common enum that defines the driver_type.

Change-Id: I8c0e9f32b235cb262ca2be6aac8d520e49b30d74
Signed-off-by: Arne Schwabe <[email protected]>
Acked-by: Gert Doering <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg29352.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
schwabe authored and cron2 committed Sep 22, 2024
1 parent b322690 commit d849073
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/openvpn/dco.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ dco_check_startup_option(int msglevel, const struct options *o)
|| (o->windows_driver == WINDOWS_DRIVER_TAP_WINDOWS6))
{
msg(msglevel, "--windows-driver is set to '%s'. Disabling Data Channel Offload",
print_windows_driver(o->windows_driver));
print_tun_backend_driver(o->windows_driver));
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/openvpn/dco_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const IN_ADDR in4addr_any = { 0 };
struct tuntap
create_dco_handle(const char *devname, struct gc_arena *gc)
{
struct tuntap tt = { .windows_driver = WINDOWS_DRIVER_DCO };
struct tuntap tt = { .backend_driver = DRIVER_DCO };
const char *device_guid;

tun_open_device(&tt, devname, &device_guid, gc);
Expand Down
2 changes: 1 addition & 1 deletion src/openvpn/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ read_incoming_tun(struct context *c)
c->c2.buf = c->c2.buffers->read_tun_buf;

#ifdef _WIN32
if (c->c1.tuntap->windows_driver == WINDOWS_DRIVER_WINTUN)
if (c->c1.tuntap->backend_driver == WINDOWS_DRIVER_WINTUN)
{
read_wintun(c->c1.tuntap, &c->c2.buf);
if (c->c2.buf.len == -1)
Expand Down
13 changes: 11 additions & 2 deletions src/openvpn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ do_persist_tuntap(struct options *options, openvpn_net_ctx_t *ctx)
msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN interface.");
}

options->tuntap_options.disable_dco = true;
options->disable_dco = true;
}
#endif

Expand Down Expand Up @@ -1759,7 +1759,16 @@ do_init_tun(struct context *c)
c->c1.tuntap);

#ifdef _WIN32
c->c1.tuntap->windows_driver = c->options.windows_driver;
c->c1.tuntap->backend_driver = c->options.windows_driver;
#else
if (dco_enabled(&c->options))
{
c->c1.tuntap->backend_driver = DRIVER_DCO;
}
else
{
c->c1.tuntap->backend_driver = DRIVER_GENERIC_TUNTAP;
}
#endif

init_tun_post(c->c1.tuntap,
Expand Down
24 changes: 12 additions & 12 deletions src/openvpn/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ init_options(struct options *o, const bool init_gc)
o->allow_recursive_routing = false;

#ifndef ENABLE_DCO
o->tuntap_options.disable_dco = true;
o->disable_dco = true;
#endif /* ENABLE_DCO */
}

Expand Down Expand Up @@ -1829,7 +1829,7 @@ show_settings(const struct options *o)
SHOW_STR(dev_type);
SHOW_STR(dev_node);
#if defined(ENABLE_DCO)
SHOW_BOOL(tuntap_options.disable_dco);
SHOW_BOOL(disable_dco);
#endif
SHOW_STR(lladdr);
SHOW_INT(topology);
Expand Down Expand Up @@ -2489,7 +2489,7 @@ options_postprocess_verify_ce(const struct options *options,
if (options->windows_driver != WINDOWS_DRIVER_TAP_WINDOWS6)
{
msg(M_USAGE, "%s, which is not supported by the selected %s driver",
prefix, print_windows_driver(options->windows_driver));
prefix, print_tun_backend_driver(options->windows_driver));
}
else if (options->tuntap_options.ip_win32_type != IPW32_SET_DHCP_MASQ
&& options->tuntap_options.ip_win32_type != IPW32_SET_ADAPTIVE)
Expand Down Expand Up @@ -3403,7 +3403,7 @@ options_postprocess_mutate_invariant(struct options *options)

/* when using wintun/ovpn-dco, kernel doesn't send DHCP requests, so don't use it */
if ((options->windows_driver == WINDOWS_DRIVER_WINTUN
|| options->windows_driver == WINDOWS_DRIVER_DCO)
|| options->windows_driver == DRIVER_DCO)
&& (options->tuntap_options.ip_win32_type == IPW32_SET_DHCP_MASQ
|| options->tuntap_options.ip_win32_type == IPW32_SET_ADAPTIVE))
{
Expand Down Expand Up @@ -3777,8 +3777,8 @@ options_postprocess_mutate(struct options *o, struct env_set *es)
if (dco_enabled(o))
{
/* check if any option should force disabling DCO */
o->tuntap_options.disable_dco = !dco_check_option(D_DCO, o)
|| !dco_check_startup_option(D_DCO, o);
o->disable_dco = !dco_check_option(D_DCO, o)
|| !dco_check_startup_option(D_DCO, o);
}
#ifdef USE_COMP
if (dco_enabled(o))
Expand All @@ -3790,11 +3790,11 @@ options_postprocess_mutate(struct options *o, struct env_set *es)
#ifdef _WIN32
if (dco_enabled(o))
{
o->windows_driver = WINDOWS_DRIVER_DCO;
o->windows_driver = DRIVER_DCO;
}
else
{
if (o->windows_driver == WINDOWS_DRIVER_DCO)
if (o->windows_driver == DRIVER_DCO)
{
msg(M_WARN, "Option --windows-driver ovpn-dco is ignored because Data Channel Offload is disabled");
o->windows_driver = WINDOWS_DRIVER_TAP_WINDOWS6;
Expand Down Expand Up @@ -4699,9 +4699,9 @@ options_string_extract_option(const char *options_string, const char *opt_name,
*
* @param str value of --windows-driver option
* @param msglevel msglevel to report parsing error
* @return enum windows_driver_type driver type, WINDOWS_DRIVER_UNSPECIFIED on unknown --windows-driver value
* @return enum tun_driver_type driver type, WINDOWS_DRIVER_UNSPECIFIED on unknown --windows-driver value
*/
static enum windows_driver_type
static enum tun_driver_type
parse_windows_driver(const char *str, const int msglevel)
{
if (streq(str, "tap-windows6"))
Expand All @@ -4715,7 +4715,7 @@ parse_windows_driver(const char *str, const int msglevel)

else if (streq(str, "ovpn-dco"))
{
return WINDOWS_DRIVER_DCO;
return DRIVER_DCO;
}
else
{
Expand Down Expand Up @@ -6053,7 +6053,7 @@ add_option(struct options *options,
#endif
else if (streq(p[0], "disable-dco"))
{
options->tuntap_options.disable_dco = true;
options->disable_dco = true;
}
else if (streq(p[0], "dev-node") && p[1] && !p[2])
{
Expand Down
7 changes: 5 additions & 2 deletions src/openvpn/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ struct options
const char *ip_remote_hint;

struct tuntap_options tuntap_options;
/* DCO is disabled and should not be used as backend driver for the
* tun/tap device */
bool disable_dco;

/* Misc parms */
const char *username;
Expand Down Expand Up @@ -676,7 +679,7 @@ struct options
bool show_net_up;
int route_method;
bool block_outside_dns;
enum windows_driver_type windows_driver;
enum tun_driver_type windows_driver;
#endif

bool use_peer_id;
Expand Down Expand Up @@ -907,7 +910,7 @@ static inline bool
dco_enabled(const struct options *o)
{
#ifdef ENABLE_DCO
return !o->tuntap_options.disable_dco;
return !o->disable_dco;
#else
return false;
#endif /* ENABLE_DCO */
Expand Down
Loading

0 comments on commit d849073

Please sign in to comment.