From: "plaisthos (Code Review)" Date: Mon, 16 Sep 2024 13:03:50 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <7fb4ece64e751055d163c253b0ce343043aa2215-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="LthCVAeO+XM="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Move to common backend_driver type in struct tuntap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --LthCVAeO+XM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello flichtenheld, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/738?usp=3Demail to look at the new patch set (#2). The following approvals got outdated and were removed: Code-Review-1 by flichtenheld Change subject: Move to common backend_driver type in struct tuntap ...................................................................... Move to common backend_driver type in struct tuntap 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 --- M src/openvpn/dco.c M src/openvpn/dco_win.c M src/openvpn/forward.c M src/openvpn/init.c M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/tun.c M src/openvpn/tun.h 8 files changed, 119 insertions(+), 98 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/38/738/2 diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c index 7f0d53d..0df185e 100644 --- a/src/openvpn/dco.c +++ b/src/openvpn/dco.c @@ -328,7 +328,7 @@ || (o->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6)) { msg(msglevel, "--windows-driver is set to '%s'. Disabling Data Cha= nnel Offload", - print_windows_driver(o->windows_driver)); + print_tun_backend_driver(o->windows_driver)); return false; } diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 3ec946f..892c616 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -44,7 +44,7 @@ struct tuntap create_dco_handle(const char *devname, struct gc_arena *gc) { - struct tuntap tt =3D { .windows_driver =3D WINDOWS_DRIVER_DCO }; + struct tuntap tt =3D { .backend_driver =3D DRIVER_DCO }; const char *device_guid; tun_open_device(&tt, devname, &device_guid, gc); diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 374ba47..7b23131 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1299,7 +1299,7 @@ c->c2.buf =3D c->c2.buffers->read_tun_buf; #ifdef _WIN32 - if (c->c1.tuntap->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN) + if (c->c1.tuntap->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN) { read_wintun(c->c1.tuntap, &c->c2.buf); if (c->c2.buf.len =3D=3D -1) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index dd56961..83cc670 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1126,7 +1126,7 @@ msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN = interface."); } - options->tuntap_options.disable_dco =3D true; + options->disable_dco =3D true; } #endif @@ -1759,7 +1759,16 @@ c->c1.tuntap); #ifdef _WIN32 - c->c1.tuntap->windows_driver =3D c->options.windows_driver; + c->c1.tuntap->backend_driver =3D c->options.windows_driver; +#else + if (dco_enabled(&c->options)) + { + c->c1.tuntap->backend_driver =3D DRIVER_DCO; + } + else + { + c->c1.tuntap->backend_driver =3D DRIVER_GENERIC_TUNTAP; + } #endif init_tun_post(c->c1.tuntap, diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 649f48b..61f6285 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -905,7 +905,7 @@ o->allow_recursive_routing =3D false; #ifndef ENABLE_DCO - o->tuntap_options.disable_dco =3D true; + o->disable_dco =3D true; #endif /* ENABLE_DCO */ } @@ -1829,7 +1829,7 @@ 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); @@ -2489,7 +2489,7 @@ if (options->windows_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6) { msg(M_USAGE, "%s, which is not supported by the selected %s dr= iver", - prefix, print_windows_driver(options->windows_driver)); + prefix, print_tun_backend_driver(options->windows_driver)); } else if (options->tuntap_options.ip_win32_type !=3D IPW32_SET_DHCP= _MASQ && options->tuntap_options.ip_win32_type !=3D IPW32_SET_A= DAPTIVE) @@ -3403,7 +3403,7 @@ /* when using wintun/ovpn-dco, kernel doesn't send DHCP requests, so d= on't use it */ if ((options->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN - || options->windows_driver =3D=3D WINDOWS_DRIVER_DCO) + || options->windows_driver =3D=3D DRIVER_DCO) && (options->tuntap_options.ip_win32_type =3D=3D IPW32_SET_DHCP_MA= SQ || options->tuntap_options.ip_win32_type =3D=3D IPW32_SET_ADAP= TIVE)) { @@ -3777,8 +3777,8 @@ if (dco_enabled(o)) { /* check if any option should force disabling DCO */ - o->tuntap_options.disable_dco =3D !dco_check_option(D_DCO, o) - || !dco_check_startup_option(D_DCO= , o); + o->disable_dco =3D !dco_check_option(D_DCO, o) + || !dco_check_startup_option(D_DCO, o); } #ifdef USE_COMP if (dco_enabled(o)) @@ -3790,11 +3790,11 @@ #ifdef _WIN32 if (dco_enabled(o)) { - o->windows_driver =3D WINDOWS_DRIVER_DCO; + o->windows_driver =3D DRIVER_DCO; } else { - if (o->windows_driver =3D=3D WINDOWS_DRIVER_DCO) + if (o->windows_driver =3D=3D DRIVER_DCO) { msg(M_WARN, "Option --windows-driver ovpn-dco is ignored becau= se Data Channel Offload is disabled"); o->windows_driver =3D WINDOWS_DRIVER_TAP_WINDOWS6; @@ -4699,9 +4699,9 @@ * * @param str value of --windows-driver option * @param msglevel msglevel to report parsing error - * @return enum windows_driver_type driver type, WINDOWS_DRIVER_UNSPECIFI= ED on unknown --windows-driver value + * @return enum tun_driver_type driver type, WINDOWS_DRIVER_UNSPECIFIED o= n 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")) @@ -4715,7 +4715,7 @@ else if (streq(str, "ovpn-dco")) { - return WINDOWS_DRIVER_DCO; + return DRIVER_DCO; } else { @@ -6053,7 +6053,7 @@ #endif else if (streq(p[0], "disable-dco")) { - options->tuntap_options.disable_dco =3D true; + options->disable_dco =3D true; } else if (streq(p[0], "dev-node") && p[1] && !p[2]) { diff --git a/src/openvpn/options.h b/src/openvpn/options.h index f608cb8..ee39dbb 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -354,6 +354,9 @@ 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; @@ -676,7 +679,7 @@ 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; @@ -907,7 +910,7 @@ 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 */ diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 82c5c00..1f0eadd 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -55,6 +55,36 @@ #include +const char * +print_tun_backend_driver(enum tun_driver_type driver) +{ + switch (driver) + { +#ifdef WIN32 + case WINDOWS_DRIVER_TAP_WINDOWS6: + return "tap-windows6"; + + case WINDOWS_DRIVER_WINTUN: + return "wintun"; + +#else /* ifdef WIN32 */ + case DRIVER_GENERIC_TUNTAP: + return "tun/tap"; + +#endif + case DRIVER_DCO: + return "ovpn-dco"; + +#ifdef HAVE_NET_IF_UTUN_H + case DRIVER_UTUN: + return "utun"; + +#endif + default: + return "unspecified"; + } +} + #ifdef _WIN32 const static GUID GUID_DEVCLASS_NET =3D { 0x4d36e972L, 0xe325, 0x11ce, { 0= xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } }; @@ -964,7 +994,7 @@ { tt->options =3D *options; #ifdef _WIN32 - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_DCO) + if (tt->backend_driver =3D=3D DRIVER_DCO) { dco_start_tun(tt); return; @@ -974,7 +1004,7 @@ overlapped_io_init(&tt->writes, frame, TRUE); tt->adapter_index =3D TUN_ADAPTER_INDEX_INVALID; - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN) { tt->wintun_send_ring_handle =3D CreateFileMapping(INVALID_HANDLE_V= ALUE, NULL, PAGE_READWRITE, @@ -1857,7 +1887,7 @@ static bool tun_dco_enabled(struct tuntap *tt) { - return !tt->options.disable_dco; + return tt->backend_driver =3D=3D DRIVER_DCO; } #endif @@ -3337,7 +3367,7 @@ tt->actual_name =3D string_alloc(utunname, NULL); msg(M_INFO, "Opened utun device %s", utunname); - tt->is_utun =3D true; + tt->backend_driver =3D DRIVER_UTUN; } #endif /* ifdef HAVE_NET_IF_UTUN_H */ @@ -3364,7 +3394,7 @@ * and dev_node is not specified */ open_darwin_utun(dev, dev_type, dev_node, tt); - if (!tt->is_utun) + if (tt->backend_driver !=3D DRIVER_UTUN) { if (!dev_node) { @@ -3426,7 +3456,7 @@ write_tun(struct tuntap *tt, uint8_t *buf, int len) { #ifdef HAVE_NET_IF_UTUN_H - if (tt->is_utun) + if (tt->backend_driver =3D=3D DRIVER_UTUN) { return write_tun_header(tt, buf, len); } @@ -3439,7 +3469,7 @@ read_tun(struct tuntap *tt, uint8_t *buf, int len) { #ifdef HAVE_NET_IF_UTUN_H - if (tt->is_utun) + if (tt->backend_driver =3D=3D DRIVER_UTUN) { return read_tun_header(tt, buf, len); } @@ -3970,7 +4000,7 @@ if (status =3D=3D ERROR_SUCCESS && data_type =3D=3D REG_SZ) { /* Is this adapter supported? */ - enum windows_driver_type windows_driver =3D WINDOWS_DR= IVER_UNSPECIFIED; + enum tun_driver_type windows_driver =3D WINDOWS_DRIVER= _UNSPECIFIED; if (strcasecmp(component_id, TAP_WIN_COMPONENT_ID) =3D= =3D 0 || strcasecmp(component_id, "root\\" TAP_WIN_COMPO= NENT_ID) =3D=3D 0) { @@ -3982,7 +4012,7 @@ } else if (strcasecmp(component_id, "ovpn-dco") =3D=3D 0) { - windows_driver =3D WINDOWS_DRIVER_DCO; + windows_driver =3D DRIVER_DCO; } =20 if (windows_driver !=3D WINDOWS_DRIVER_UNSPECIFIED) @@ -4004,7 +4034,7 @@ last =3D reg; msg(D_TAP_WIN_DEBUG, "NetCfgInstanceId: %s, Driver= : %s", - reg->guid, print_windows_driver(reg->windows_d= river)); + reg->guid, print_tun_backend_driver(reg->windo= ws_driver)); } } } @@ -4236,7 +4266,7 @@ { if (!strcmp(tr->guid, pr->guid)) { - msg(msglev, "'%s' %s %s", pr->name, tr->guid, print_window= s_driver(tr->windows_driver)); + msg(msglev, "'%s' %s %s", pr->name, tr->guid, print_tun_ba= ckend_driver(tr->windows_driver)); ++links; } } @@ -4357,7 +4387,7 @@ int actual_name_size, const struct tap_reg *tap_reg_src, const struct panel_reg *panel_reg_src, - enum windows_driver_type *windows_driver, + enum tun_driver_type *windows_driver, struct gc_arena *gc) { const struct tap_reg *tap_reg =3D tap_reg_src; @@ -4421,7 +4451,7 @@ get_device_guid(const char *name, uint8_t *actual_name, int actual_name_size, - enum windows_driver_type *windows_driver, + enum tun_driver_type *windows_driver, const struct tap_reg *tap_reg, const struct panel_reg *panel_reg, struct gc_arena *gc) @@ -6207,7 +6237,7 @@ const DWORD index =3D tt->adapter_index; /* flush arp cache */ - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 && index !=3D TUN_ADAPTER_INDEX_INVALID) { DWORD status =3D -1; @@ -6544,8 +6574,8 @@ const char *path =3D NULL; char tuntap_device_path[256]; - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN - || tt->windows_driver =3D=3D WINDOWS_DRIVER_DCO) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN + || tt->backend_driver =3D=3D DRIVER_DCO) { const struct device_instance_id_interface *dev_if; @@ -6556,7 +6586,7 @@ continue; } - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_DCO) + if (tt->backend_driver =3D=3D DRIVER_DCO) { char *last_sep =3D strrchr(dev_if->device_interface, '\\'); if (!last_sep @@ -6595,11 +6625,11 @@ 0); if (tt->hand =3D=3D INVALID_HANDLE_VALUE) { - msg(D_TUNTAP_INFO | M_ERRNO, "CreateFile failed on %s device: %s",= print_windows_driver(tt->windows_driver), path); + msg(D_TUNTAP_INFO | M_ERRNO, "CreateFile failed on %s device: %s",= print_tun_backend_driver(tt->backend_driver), path); return false; } - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN) { /* Wintun adapter may be considered "open" after ring buffers are = successfuly registered. */ if (!wintun_register_ring_buffer(tt, device_guid)) @@ -6629,7 +6659,7 @@ */ if (dev_node) { - enum windows_driver_type windows_driver =3D WINDOWS_DRIVER_UNSPECI= FIED; + enum tun_driver_type windows_driver =3D WINDOWS_DRIVER_UNSPECIFIED; /* Get the device GUID for the device specified with --dev-node. */ *device_guid =3D get_device_guid(dev_node, actual_buffer, sizeof(a= ctual_buffer), &windows_driver, tap_reg, panel_reg, gc); @@ -6639,15 +6669,15 @@ msg(M_FATAL, "Adapter '%s' not found", dev_node); } - if (tt->windows_driver !=3D windows_driver) + if (tt->backend_driver !=3D windows_driver) { msg(M_FATAL, "Adapter '%s' is using %s driver, %s expected. If= you want to use this device, adjust --windows-driver.", - dev_node, print_windows_driver(windows_driver), print_wind= ows_driver(tt->windows_driver)); + dev_node, print_tun_backend_driver(windows_driver), print_= tun_backend_driver(tt->backend_driver)); } if (!tun_try_open_device(tt, *device_guid, device_instance_id_inte= rface)) { - msg(M_FATAL, "Failed to open %s adapter: %s", print_windows_dr= iver(tt->windows_driver), dev_node); + msg(M_FATAL, "Failed to open %s adapter: %s", print_tun_backen= d_driver(tt->backend_driver), dev_node); } } else @@ -6657,7 +6687,7 @@ /* Try opening all TAP devices until we find one available */ while (true) { - enum windows_driver_type windows_driver =3D WINDOWS_DRIVER_UNS= PECIFIED; + enum tun_driver_type windows_driver =3D WINDOWS_DRIVER_UNSPECI= FIED; *device_guid =3D get_unspecified_device_guid(device_number, actual_buffer, sizeof(actual_buffe= r), @@ -6668,10 +6698,10 @@ if (!*device_guid) { - msg(M_FATAL, "All %s adapters on this system are currently= in use or disabled.", print_windows_driver(tt->windows_driver)); + msg(M_FATAL, "All %s adapters on this system are currently= in use or disabled.", print_tun_backend_driver(tt->backend_driver)); } - if (tt->windows_driver !=3D windows_driver) + if (tt->backend_driver !=3D windows_driver) { goto next; } @@ -6690,7 +6720,7 @@ * GUID using the registry */ tt->actual_name =3D string_alloc((const char *)actual_buffer, NULL); - msg(M_INFO, "%s device [%s] opened", print_windows_driver(tt->windows_= driver), tt->actual_name); + msg(M_INFO, "%s device [%s] opened", print_tun_backend_driver(tt->back= end_driver), tt->actual_name); tt->adapter_index =3D get_adapter_index(*device_guid); } @@ -6743,7 +6773,7 @@ bool dhcp_masq =3D false; bool dhcp_masq_post =3D false; - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6) { /* get driver version info */ tuntap_get_version_info(tt); @@ -6786,11 +6816,11 @@ openvpn_net_ctx_t *ctx) { if ((tt->options.dhcp_options & DHCP_OPTIONS_DHCP_REQUIRED) - && tt->windows_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6) + && tt->backend_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6) { msg(M_WARN, "Some --dhcp-option or --dns options require DHCP serv= er," " which is not supported by the selected %s driver. They will = be" - " ignored.", print_windows_driver(tt->windows_driver)); + " ignored.", print_tun_backend_driver(tt->backend_driver)); } /* dco-win already opened the device, which handle we treat as socket = */ @@ -6828,7 +6858,7 @@ const char * tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc) { - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6) { struct buffer out =3D alloc_buf_gc(256, gc); DWORD len; @@ -6846,7 +6876,7 @@ void tun_show_debug(struct tuntap *tt) { - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6) { struct buffer out =3D alloc_buf(1024); DWORD len; @@ -6923,7 +6953,7 @@ void close_tun_handle(struct tuntap *tt) { - const char *adaptertype =3D print_windows_driver(tt->windows_driver); + const char *adaptertype =3D print_tun_backend_driver(tt->backend_drive= r); if (tt->hand) { @@ -6950,7 +6980,7 @@ tt->hand =3D NULL; } - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN) { CloseHandle(tt->rw_handle.read); CloseHandle(tt->rw_handle.write); @@ -7111,25 +7141,6 @@ return BSTR(&out); } -const char * -print_windows_driver(enum windows_driver_type windows_driver) -{ - switch (windows_driver) - { - case WINDOWS_DRIVER_TAP_WINDOWS6: - return "tap-windows6"; - - case WINDOWS_DRIVER_WINTUN: - return "wintun"; - - case WINDOWS_DRIVER_DCO: - return "ovpn-dco"; - - default: - return "unspecified"; - } -} - #else /* generic */ void diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 33b9552..e41b616 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -42,16 +42,23 @@ #include "ring_buffer.h" #include "dco.h" -#ifdef _WIN32 -#define WINTUN_COMPONENT_ID "wintun" -#define DCO_WIN_REFERENCE_STRING "ovpn-dco" - -enum windows_driver_type { +enum tun_driver_type { +#ifdef WIN32 WINDOWS_DRIVER_UNSPECIFIED, WINDOWS_DRIVER_TAP_WINDOWS6, WINDOWS_DRIVER_WINTUN, - WINDOWS_DRIVER_DCO +#else + DRIVER_GENERIC_TUNTAP, +#endif + DRIVER_DCO, +#ifdef HAVE_NET_IF_UTUN_H + DRIVER_UTUN +#endif }; + +#ifdef _WIN32 +#define WINTUN_COMPONENT_ID "wintun" +#define DCO_WIN_REFERENCE_STRING "ovpn-dco" #endif #if defined(_WIN32) || defined(TARGET_ANDROID) @@ -70,8 +77,6 @@ /* --ip-win32 options */ bool ip_win32_defined; - bool disable_dco; - #define IPW32_SET_MANUAL 0 /* "--ip-win32 manual" */ #define IPW32_SET_NETSH 1 /* "--ip-win32 netsh" */ #define IPW32_SET_IPAPI 2 /* "--ip-win32 ipapi" */ @@ -147,20 +152,12 @@ struct tuntap_options { int txqueuelen; - bool disable_dco; -}; - -#elif defined(TARGET_FREEBSD) - -struct tuntap_options { - bool disable_dco; }; #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */ struct tuntap_options { int dummy; /* not used */ - bool disable_dco; /* not used, but removes the need in #ifdefs */ }; #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */ @@ -177,6 +174,11 @@ #define TUNNEL_TOPOLOGY(tt) ((tt) ? ((tt)->topology) : TOP_UNDEF) int topology; /* one of the TOP_x values */ =20 + /** The backend driver that used for this tun/tap device. This can be + * one of the various windows drivers, "normal" tun/tap, utun, dco, ... + */ + enum tun_driver_type backend_driver; + bool did_ifconfig_setup; bool did_ifconfig_ipv6_setup; @@ -211,7 +213,6 @@ * ~0 if undefined */ DWORD adapter_index; - enum windows_driver_type windows_driver; int standby_iter; HANDLE wintun_send_ring_handle; @@ -226,9 +227,6 @@ int ip_fd; #endif -#ifdef HAVE_NET_IF_UTUN_H - bool is_utun; -#endif /* used for printing status info only */ unsigned int rwflags_debug; @@ -249,7 +247,7 @@ static inline bool tuntap_is_wintun(struct tuntap *tt) { - return tt && tt->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN; + return tt && tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN; } static inline bool @@ -397,7 +395,7 @@ struct tap_reg { const char *guid; - enum windows_driver_type windows_driver; + enum tun_driver_type windows_driver; struct tap_reg *next; }; @@ -643,7 +641,7 @@ static inline int write_tun_buffered(struct tuntap *tt, struct buffer *buf) { - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN) { return write_wintun(tt, buf); } @@ -656,7 +654,7 @@ static inline bool tuntap_is_dco_win(struct tuntap *tt) { - return tt && tt->windows_driver =3D=3D WINDOWS_DRIVER_DCO; + return tt && tt->backend_driver =3D=3D DRIVER_DCO; } static inline bool @@ -666,7 +664,7 @@ } const char * -print_windows_driver(enum windows_driver_type windows_driver); +print_tun_backend_driver(enum tun_driver_type driver); #else /* ifdef _WIN32 */ @@ -744,7 +742,7 @@ } } #ifdef _WIN32 - if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 && (rwflags = & EVENT_READ)) + if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 && (rwflags = & EVENT_READ)) { tun_read_queue(tt, 0); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/738?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I8c0e9f32b235cb262ca2be6aac8d520e49b30d74 Gerrit-Change-Number: 738 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --LthCVAeO+XM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

plaisthos uploaded patch set #2 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/738?usp=3Demail">View Chang= e

The following approvals got outdated and were removed: Code-Review-1 by flichtenheld

Move to common backend_driver type in struct =
tuntap

With the introduction of utun on macOS and DCO on Linux, Free= BSD and
Windows, a lot of platforms have now more than one driver/backen= d for
the tun interface but each one uses a different mechanism. Unify t= hese
approach with using a common enum that defines the driver_type.
=
Change-Id: I8c0e9f32b235cb262ca2be6aac8d520e49b30d74
Signed-off-by: = Arne Schwabe <arne@...1227...>
---
M src/openvpn/dco.c
M src= /openvpn/dco_win.c
M src/openvpn/forward.c
M src/openvpn/init.c
M = src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/tun.c
= M src/openvpn/tun.h
8 files changed, 119 insertions(+), 98 deletions(-)<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/38/7=
38/2
diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c
<= span>index 7f0d53d..0df185e 100644
--- a/src/openvpn/dco.c<= /span>
+++ b/src/openvpn/dco.c
@@ -328,7 +328,7 @@=
|| (o->windows_driver =3D=3D WINDOWS_DRIVER_TA= P_WINDOWS6))
{
msg(msglevel, = "--windows-driver is set to '%s'. Disabling Data Channel Offlo= ad",
- = print_windows_driver(o->windows_driver));
+ print_tun_backend_driver(o->windows= _driver));
return false;
}

diff --git a/src/openvpn/dco_win.c b/src/op= envpn/dco_win.c
index 3ec946f..892c616 100644
--- a/src/openvpn/dco_win.c

+++ b/src/openvpn/dco_win.c<= /span>
@@ -44,7 +44,7 @@
struct tuntap
= create_dco_handle(const char *devname, struct gc_arena *gc) {
- struct = tuntap tt =3D { .windows_driver =3D WINDOWS_DRIVER_DCO };
+ struct tuntap tt =3D { .backend_d= river =3D DRIVER_DCO };
const char *device_guid;

tun_open_device(&tt, devname, &de= vice_guid, gc);
diff --git a/src/openvpn/forward.c b/src/op= envpn/forward.c
index 374ba47..7b23131 100644
--- a/src/openvpn/forward.c

+++ b/src/openvpn/forward.c<= /span>
@@ -1299,7 +1299,7 @@
c->c2.buf =3D= c->c2.buffers->read_tun_buf;

#ifd= ef _WIN32
- if (c-&g= t;c1.tuntap->windows_driver =3D=3D WINDOWS_DRIVER_WINTUN)
+ if (c->c1.tuntap->backen= d_driver =3D=3D WINDOWS_DRIVER_WINTUN)

{
read_wintun(c->c1.tuntap, &c->c2.buf);

if (c->c2.buf.len =3D=3D -1)

diff --git a/src= /openvpn/init.c b/src/openvpn/init.c
index dd56961..83cc670= 100644
--- a/src/openvpn/init.c
+++ b/src/= openvpn/init.c
@@ -1126,7 +1126,7 @@
= msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN i= nterface.");
}

- options->tuntap_options= .disable_dco =3D true;
- c->c1.tuntap->windows_driver =3D c->options.wind= ows_driver;
+ c-&g= t;c1.tuntap->backend_driver =3D c->options.windows_driver;
= +#else
+ if (dco_enabled(&c->options))
+ {
+ c->c1.tuntap->backend_d= river =3D DRIVER_DCO;
+ }
+ else
+ {
+ c->c1.tuntap->backend_d= river =3D DRIVER_GENERIC_TUNTAP;
+ }
#endif

init_tun_post(c->c1.tuntap,

diff --git a/src/open= vpn/options.c b/src/openvpn/options.c
index 649f48b..61f628= 5 100644
--- a/src/openvpn/options.c
+++ b/= src/openvpn/options.c
@@ -905,7 +905,7 @@
= o->allow_recursive_routing =3D false;

#ifndef ENABLE_DCO

- o->tuntap_options.disable_dco =3D true;
+ o->disable_dco =3D true;
#endif /* ENABLE_DCO */
}

<= span>@@ -1829,7 +1829,7 @@
SHOW_STR(dev_type);<= br> SHOW_STR(dev_node);
#if defined(ENABLE_DCO)<= /span>
- SHOW_BOOL(tuntap_o= ptions.disable_dco);
= + SHOW_BOOL(disable_dco);
#endif
S= HOW_STR(lladdr);
SHOW_INT(topology);
@= @ -2489,7 +2489,7 @@
if (options->windows_drive= r !=3D WINDOWS_DRIVER_TAP_WINDOWS6)
{
msg(M_USAGE, "%s, which is not supported by the selec= ted %s driver",

- = prefix, print_windows_driver(options->windows_driver));
+ prefi= x, print_tun_backend_driver(options->windows_driver));
= }
else if (options->tuntap_options.ip_w= in32_type !=3D IPW32_SET_DHCP_MASQ
&&= amp; options->tuntap_options.ip_win32_type !=3D IPW32_SET_ADAPTIVE)

@@ -3403,7 +3403,7 @@

/*= when using wintun/ovpn-dco, kernel doesn't send DHCP requests, so don&= #39;t use it */
if ((options->windows_driver =3D=3D= WINDOWS_DRIVER_WINTUN
= - || options->windows_driver =3D=3D WINDOWS_DRIVER_DCO)+ || options->wind= ows_driver =3D=3D DRIVER_DCO)
&& (options-= >tuntap_options.ip_win32_type =3D=3D IPW32_SET_DHCP_MASQ
|| options->tuntap_options.ip_win32_type =3D=3D IPW32_SET_= ADAPTIVE))
{
@@ -3777,8 +3777,8 @@
if (dco_enabled(o))
{
/* check if any option should force disabling DCO */

<= span style=3D"color: hsl(0, 100%, 40%);">- o->tuntap_options.disa= ble_dco =3D !dco_check_option(D_DCO, o)
- || !dco_check_sta= rtup_option(D_DCO, o);
+ || !dco_c= heck_startup_option(D_DCO, o);
}
#ifd= ef USE_COMP
if (dco_enabled(o))
@@ -37= 90,11 +3790,11 @@
#ifdef _WIN32
if (d= co_enabled(o))
{
- o->windows_driver =3D WINDOWS_DRIVER_DCO;=
+ o->windows_driv= er =3D DRIVER_DCO;
}
else<= br> {
- = if (o->windows_driver =3D=3D WINDOWS_DRIVER_DCO)
+ if (o->windows_driver =3D=3D D= RIVER_DCO)
{
msg(M_WA= RN, "Option --windows-driver ovpn-dco is ignored because Data Channel = Offload is disabled");
o->windows_driv= er =3D WINDOWS_DRIVER_TAP_WINDOWS6;
@@ -4699,9 +4699,9 @@
*
* @param str value of --windows-= driver option
* @param msglevel msglevel to report parsi= ng error
- * @return en= um windows_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&qu= ot;))
@@ -4715,7 +4715,7 @@

else if (streq(str, "ovpn-dco"))

{
- return WINDOWS_= DRIVER_DCO;
+ = return DRIVER_DCO;
}
else<= br> {
@@ -6053,7 +6053,7 @@
#end= if
else if (streq(p[0], "disable-dco"))
{
- = options->tuntap_options.disable_dco =3D true;
+ options->disable_dco =3D true;=
}
else if (streq(p[0], "dev= -node") && p[1] && !p[2])
{

diff --git a/src/openvpn/options.h b/src/openvpn/options.h
index f608cb8..ee39dbb 100644
--- a/src/openvpn/= options.h
+++ b/src/openvpn/options.h
@@ -3= 54,6 +354,9 @@
const char *ip_remote_hint;
<= span>

struct tuntap_options tuntap_options;+ /* DCO is disabled and sh= ould not be used as backend driver for the
+ * tun/tap device */
+ bool disable_dco;
<= br> /* Misc parms */
const char *username;
@@ -676,7 +679,7 @@
bool show_net_up;
int route_method;
bool block_outsi= de_dns;
- enum windo= ws_driver_type windows_driver;
+ enum tun_driver_type windows_driver;
#endif=

bool use_peer_id;
@= @ -907,7 +910,7 @@
dco_enabled(const struct options *o)

{
#ifdef ENABLE_DCO
- return !o->tuntap_options.disable_dc= o;
+ return !o->= ;disable_dco;
#else
return false;
#endif /* ENABLE_DCO */
diff --git a/src/open= vpn/tun.c b/src/openvpn/tun.c
index 82c5c00..1f0eadd 100644=
--- a/src/openvpn/tun.c
+++ b/src/openvpn/= tun.c
@@ -55,6 +55,36 @@

= #include <string.h>

+const char *
+print_tun_backend_driver(enum tun_driver_type driver)
+{
+ switch (driver)
+ {
+#ifdef WIN32
+ case WINDOWS_DRIVER_TAP_WINDOWS6:
+ return "tap-windows6&qu= ot;;
+
+ case WINDOWS_DRIVER_WINTUN= :

+ return= "wintun";
= +
+#else /* ifdef WI= N32 */
+ case = DRIVER_GENERIC_TUNTAP:
+
+#endif
+ c= ase DRIVER_DCO:
+ = return "ovpn-dco";
+
+#i= fdef HAVE_NET_IF_UTUN_H
+ case DRIVER_UTUN:
+ return "utun";
+
+#endif
+ = default:
+ = return "unspecified";
+ }
+}
+
#ifdef _WIN32


const static GUID GUID_D= EVCLASS_NET =3D { 0x4d36e972L, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x= 2b, 0xe1, 0x03, 0x18 } };
@@ -964,7 +994,7 @@
{
tt->options =3D *options;
#i= fdef _WIN32
- if (tt= ->windows_driver =3D=3D WINDOWS_DRIVER_DCO)
+ if (tt->backend_driver =3D=3D DRIVER_DCO)=
{
dco_start_tun(tt);<= br> return;
@@ -974,7 +1004,7 @@
overlapped_io_init(&tt->writes, frame, TRUE);
tt->adapter_index =3D TUN_ADAPTER_INDEX_INVALID;

- if (tt->wind= ows_driver =3D=3D WINDOWS_DRIVER_WINTUN)
+ if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WI= NTUN)
{
tt->wintun_send_ri= ng_handle =3D CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE,
@@ -1857,7 +1887,7 @@
static bool tun_dco_enabled(struct tuntap *tt)
{
- return !tt->options.disable_= dco;
+ return tt-&= gt;backend_driver =3D=3D DRIVER_DCO;
}
#e= ndif

@@ -3337,7 +3367,7 @@
tt->actual_name =3D string_alloc(utunname, NULL);

msg(M_INFO, "Opened utun device %s", utun= name);
- tt->is_u= tun =3D true;
+ tt= ->backend_driver =3D DRIVER_UTUN;
}

#endif /* ifdef HAVE_NET_IF_UTUN_H */
@@ -3= 364,7 +3394,7 @@
* and dev_node is not specified = */
open_darwin_utun(dev, dev_type, dev_node, tt);<= /span>

- = if (!tt->is_utun)
+ if (tt->backend_driver !=3D DRIVER_UTUN)
= {
if (!dev_node)
= {
@@ -3426,7 +3456,7 @@
write_tun(s= truct tuntap *tt, uint8_t *buf, int len)
{
#ifdef HAVE_NET_IF_UTUN_H

- if (tt->is_utun)
+ if (tt->backend_driver =3D=3D DRIVER_UTUN)
{

return write_tun_header(tt, buf, len);

}
@@ -3439,7 +3469,7 @@
= read_tun(struct tuntap *tt, uint8_t *buf, int len)
{

#ifdef HAVE_NET_IF_UTUN_H
- if (tt->is_utun)
+ if (tt->backend_driver =3D=3D DRIVER_UTUN)

{
return read_tun_header(tt, buf, = len);
}
@@ -3970,7 +4000,7 @@ if (status =3D=3D ERROR_SUCCESS && data_ty= pe =3D=3D REG_SZ)
{
= /* Is this adapter supported? */
- enum windows_driver_type wind= ows_driver =3D WINDOWS_DRIVER_UNSPECIFIED;
+ enum tun_driver_type windows_dri= ver =3D WINDOWS_DRIVER_UNSPECIFIED;
if= (strcasecmp(component_id, TAP_WIN_COMPONENT_ID) =3D=3D 0
= || strcasecmp(component_id, "root\\" TAP_= WIN_COMPONENT_ID) =3D=3D 0)
{@@ -3982,7 +4012,7 @@
}=
else if (strcasecmp(component_id, "ovpn= -dco") =3D=3D 0)
{
- windows_driv= er =3D WINDOWS_DRIVER_DCO;
+ windows_driver =3D DRIVER_DCO;
}

= if (windows_driver !=3D WINDOWS_DRIVER_UNSPECIFIED)
@= @ -4004,7 +4034,7 @@
last =3D reg;=

msg(D_TAP_WIN_D= EBUG, "NetCfgInstanceId: %s, Driver: %s",
- reg->guid, p= rint_windows_driver(reg->windows_driver));
+ reg->guid, print_t= un_backend_driver(reg->windows_driver));
= }
}
}
@@ -4236,7 +4266,7 @@
{
<= span> if (!strcmp(tr->guid, pr->guid))

= {
- = msg(msglev, "'%s' %s %s", pr->name, tr->guid= , print_windows_driver(tr->windows_driver));
+ msg(msglev, "'%s' = %s %s", pr->name, tr->guid, print_tun_backend_driver(tr->wind= ows_driver));
++links;
= }
}
@@ -4357,7 +4387,7 @= @
int actual_name_size,=
const struct tap_reg *tap_reg_src,
const struct panel_reg *panel_r= eg_src,
- = enum windows_driver_type *windows_driver,
+ enum tun_dr= iver_type *windows_driver,
str= uct gc_arena *gc)
{
const struct tap_= reg *tap_reg =3D tap_reg_src;
@@ -4421,7 +4451,7 @@<= br> get_device_guid(const char *name,
= uint8_t *actual_name,
int actual_name_si= ze,
- en= um windows_driver_type *windows_driver,
+ enum tun_driver_type *windows_driver,
const struct tap_reg *tap_reg,
const struct panel_reg *panel_reg,

= struct gc_arena *gc)
@@ -6207,7 +6237,7 @@

const DWORD index =3D tt->adapter_index;

/* flush arp cache */
- if (tt->windows_driver =3D=3D WINDOWS_DRI= VER_TAP_WINDOWS6
+ = if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6
&& index !=3D TUN_ADAPTER_INDEX_INVALID)
{
DWORD status =3D -1;
@@ -= 6544,8 +6574,8 @@
const char *path =3D NULL; char tuntap_device_path[256];

- if (tt->windows_driver =3D=3D = WINDOWS_DRIVER_WINTUN
-= || tt->windows_driver =3D=3D WINDOWS_DRIVER_DCO)
+ if (tt->backend_driver =3D= =3D WINDOWS_DRIVER_WINTUN
+ || tt->backend_driver =3D=3D DRIVER_DCO)
= {
const struct device_instance_id_interface *d= ev_if;

@@ -6556,7 +6586,7 @@
continue;
}

- if (t= t->windows_driver =3D=3D WINDOWS_DRIVER_DCO)
+ if (tt->backend_driver =3D=3D DR= IVER_DCO)
{
c= har *last_sep =3D strrchr(dev_if->device_interface, '\\');

if (!last_sep
@@ -6595,11 +6625= ,11 @@
0);
= if (tt->hand =3D=3D INVALID_HANDLE_VALUE)
{<= br>- msg(D_TUNTAP_INFO | M= _ERRNO, "CreateFile failed on %s device: %s", print_windows_drive= r(tt->windows_driver), path);
+ msg(D_TUNTAP_INFO | M_ERRNO, "CreateFile failed o= n %s device: %s", print_tun_backend_driver(tt->backend_driver), pat= h);
return false;
}
- if (tt-&g= t;windows_driver =3D=3D WINDOWS_DRIVER_WINTUN)
+ if (tt->backend_driver =3D=3D WINDOWS_DRI= VER_WINTUN)
{
/* Wintun adapt= er may be considered "open" after ring buffers are successfuly re= gistered. */
if (!wintun_register_ring_buffer(tt, = device_guid))
@@ -6629,7 +6659,7 @@
*= /
if (dev_node)
{
- enum windows_driver_type wind= ows_driver =3D WINDOWS_DRIVER_UNSPECIFIED;
+ enum tun_driver_type windows_driver =3D WIND= OWS_DRIVER_UNSPECIFIED;

/* Get t= he device GUID for the device specified with --dev-node. */
*device_guid =3D get_device_guid(dev_node, actual_buffer, sizeof(= actual_buffer), &windows_driver, tap_reg, panel_reg, gc);
@@ -6639,15 +6669,15 @@
msg(M_FATAL, "= Adapter '%s' not found", dev_node);
}=

- = if (tt->windows_driver !=3D windows_driver)
+ if (tt->backend_driver !=3D wi= ndows_driver)
{
msg(M= _FATAL, "Adapter '%s' is using %s driver, %s expected. If you = want to use this device, adjust --windows-driver.",
- dev_node, print_windows_= driver(windows_driver), print_windows_driver(tt->windows_driver));

+ dev_node,= print_tun_backend_driver(windows_driver), print_tun_backend_driver(tt->= backend_driver));
}

if (!tun_try_open_device(tt, *device_guid, device_instance_id_= interface))
{
- msg(M_FATAL, "Failed to open %s adapter: = %s", print_windows_driver(tt->windows_driver), dev_node);+ msg(M_FATAL, &quo= t;Failed to open %s adapter: %s", print_tun_backend_driver(tt->back= end_driver), dev_node);
}
}
else
@@ -6657,7 +6687,7 @@
/* Try opening all TAP devices until we find one available */<= /span>
while (true)
{
= - enum windows_driver_= type windows_driver =3D WINDOWS_DRIVER_UNSPECIFIED;
+ enum tun_driver_type windows_= driver =3D WINDOWS_DRIVER_UNSPECIFIED;
*device= _guid =3D get_unspecified_device_guid(device_number,
= actual_buffer,
= sizeof(actual= _buffer),
@@ -6668,10 +6698,10 @@
<= br> if (!*device_guid)
{

- msg(M_FAT= AL, "All %s adapters on this system are currently in use or disabled.&= quot;, print_windows_driver(tt->windows_driver));
+ msg(M_FATAL, "All %s= adapters on this system are currently in use or disabled.", print_tun= _backend_driver(tt->backend_driver));
}


- = if (tt->windows_driver !=3D windows_driver)
+ if (tt->backend_driver != =3D windows_driver)
{
= goto next;
}
@@ -6690= ,7 +6720,7 @@
* GUID using the registry */
= tt->actual_name =3D string_alloc((const char *)actual_buffer,= NULL);

- msg(M_INFO, "%s device [%s] opened", print_windows_driver= (tt->windows_driver), tt->actual_name);
+ msg(M_INFO, "%s device [%s] opened"= , print_tun_backend_driver(tt->backend_driver), tt->actual_name);
tt->adapter_index =3D get_adapter_index(*device_guid);=
}

@@ -6743,7 +6773,7 @@=
bool dhcp_masq =3D false;
bool d= hcp_masq_post =3D false;

- if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TA= P_WINDOWS6)
+ if (= tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6)
= {
/* get driver version info */
tuntap_get_version_info(tt);

@@ -6786,11 +6816,1= 1 @@
openvpn_net_ctx_t *ctx)
{
if ((tt->options.dhcp_options & DHCP_OPTIONS_DHC= P_REQUIRED)
- &a= mp;& tt->windows_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6)
= + && tt->back= end_driver !=3D WINDOWS_DRIVER_TAP_WINDOWS6)
{<= br> msg(M_WARN, "Some --dhcp-option or --dns options req= uire DHCP server,"
" which is not su= pported by the selected %s driver. They will be"
- " ignored.", print_wi= ndows_driver(tt->windows_driver));
+ " ignored.", print_tun_backend_driv= er(tt->backend_driver));
}
=
/* dco-win already opened the device, which handle we treat = as socket */
@@ -6828,7 +6858,7 @@
const c= har *
tap_win_getinfo(const struct tuntap *tt, struct gc_a= rena *gc)
{
- if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6)
+ if (tt->backend= _driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6)
{ struct buffer out =3D alloc_buf_gc(256, gc);
DWORD len;

@@ -6846,7 +6876,7 @@
void

tun_show_debug(struct tuntap *tt)
= {
- if (tt->wind= ows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6)
+ if (tt->backend_driver =3D=3D WINDOWS_DRI= VER_TAP_WINDOWS6)
{
struct bu= ffer out =3D alloc_buf(1024);
DWORD len;@@ -6923,7 +6953,7 @@
void
close_t= un_handle(struct tuntap *tt)
{
- const char *adaptertype =3D print_windows_dri= ver(tt->windows_driver);
+ const char *adaptertype =3D print_tun_backend_driver(tt->bac= kend_driver);

if (tt->hand)
{
@@ -6950,7 +6980,7 @@
= tt->hand =3D NULL;
}
=
- if (tt->windows_drive= r =3D=3D WINDOWS_DRIVER_WINTUN)
+ if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN)
{
CloseHandle(tt->rw_handle.r= ead);
CloseHandle(tt->rw_handle.write);<= br>@@ -7111,25 +7141,6 @@
return BSTR(&out);=
}

-const char *
-print_windows_driver(enum windows_driver_type windows_driver)=
-{
- switch (windows_driver)
- {
- case WINDOWS_DRIVER_TAP_WINDOWS6:
- return "tap-windows6&= quot;;
-
- case WINDOWS_DRIVER_WINTUN:<= /span>
- return &qu= ot;wintun";
-

- case WINDOWS_DRIVE= R_DCO:
- ret= urn "ovpn-dco";
-
- default:<= /span>
- return &qu= ot;unspecified";
-= }
-}
-

#else /* generic *= /

void
diff --git a/src/= openvpn/tun.h b/src/openvpn/tun.h
index 33b9552..e41b616 10= 0644
--- a/src/openvpn/tun.h
+++ b/src/open= vpn/tun.h
@@ -42,16 +42,23 @@
#include &qu= ot;ring_buffer.h"
#include "dco.h"
-#ifdef _WIN3= 2
-#define WINTUN_COMPO= NENT_ID "wintun"
-#define DCO_WIN_REFERENCE_STRING "ovpn-dco"
-
-enum windows_driver_type {
+enum tun_driver_type {
+#ifdef WIN32
WINDOWS_DRIVER_= UNSPECIFIED,
WINDOWS_DRIVER_TAP_WINDOWS6,
WINDOWS_DRIVER_WINTUN,

- WINDOWS_DRIVER_DCO
+#else
+ = DRIVER_GENERIC_TUNTAP,
+#endif
+ DRI= VER_DCO,
+#ifdef HAVE= _NET_IF_UTUN_H
+ D= RIVER_UTUN
+#endif
};
+
+#ifdef _WIN32<= br>+#define WINTUN_COMPONENT_ID= "wintun"
+= #define DCO_WIN_REFERENCE_STRING "ovpn-dco"
#end= if

#if defined(_WIN32) || defined(TARGET= _ANDROID)
@@ -70,8 +77,6 @@
/* --ip-wi= n32 options */
bool ip_win32_defined;
=
- bool disable_dco= ;
-
#d= efine IPW32_SET_MANUAL 0 /* "--ip-win32 manual" */=
#define IPW32_SET_NETSH 1 /* "--ip-win32 netsh&quo= t; */
#define IPW32_SET_IPAPI 2 /* "--ip-win= 32 ipapi" */
@@ -147,20 +152,12 @@

struct tuntap_options {
int txqueuelen= ;
- bool disable_dco= ;
-};
-
-#elif defined(TARGET_FREEBSD)
-
-struct tuntap_options {
- bool disable_dco;
};

<= span> #else /* if defined(_WIN32) || defined(TARGET_ANDROID) */

=
struct tuntap_options {
int d= ummy; /* not used */
- = bool disable_dco; /* not used, but removes the need in #ifdefs */=
};

#endif /* if defined(_WIN3= 2) || defined(TARGET_ANDROID) */
@@ -177,6 +174,11 @@
#define TUNNEL_TOPOLOGY(tt) ((tt) ? ((tt)->topology) : TOP_U= NDEF)
int topology; /* one of the TOP_x values */

+ /*= * The backend driver that used for this tun/tap device. This can be<= br>+ * one of the various w= indows drivers, "normal" tun/tap, utun, dco, ...
+ */
+ enum tun_driver_type backend_driver;<= br>+
bool = did_ifconfig_setup;
bool did_ifconfig_ipv6_setup;

@@ -211,7 +213,6 @@
* ~= 0 if undefined */
DWORD adapter_index;

- enum windows_dr= iver_type windows_driver;
int standby_iter;
=
HANDLE wintun_send_ring_handle;
@@ -226,9 +227,6 @@

int ip_fd;
#end= if

-#= ifdef HAVE_NET_IF_UTUN_H
-#= endif
/* used for printing status info only */<= br> unsigned int rwflags_debug;

@@ -249,7 +247,7 @@

static inline bool
t= untap_is_wintun(struct tuntap *tt)
{
- return tt && tt->windows_dri= ver =3D=3D WINDOWS_DRIVER_WINTUN;
+ return tt && tt->backend_driver =3D=3D WINDOWS= _DRIVER_WINTUN;
}

stati= c inline bool
@@ -397,7 +395,7 @@
struct t= ap_reg
{
const char *guid;
= - enum windows_driver_type win= dows_driver;
+ enu= m tun_driver_type windows_driver;
struct tap_reg *next= ;
};

@@ -643,7 +641,7 @@=
static inline int
write_tun_buffered(str= uct tuntap *tt, struct buffer *buf)
{
- if (tt->windows_driver =3D=3D WINDO= WS_DRIVER_WINTUN)
+ = if (tt->backend_driver =3D=3D WINDOWS_DRIVER_WINTUN)
= {
return write_wintun(tt, buf);
}

@@ -656,7 +654,7 @@
static inline= bool
tuntap_is_dco_win(struct tuntap *tt)
{

- return tt &= ;& tt->windows_driver =3D=3D WINDOWS_DRIVER_DCO;
+ return tt && tt->backend= _driver =3D=3D DRIVER_DCO;
}

<= span> static inline bool

@@ -666,7 +664,7 @@
}

const char *
-print_windows_driver(enum windows_driver_ty= pe windows_driver);
+= print_tun_backend_driver(enum tun_driver_type driver);

#else /* ifdef _WIN32 */

= @@ -744,7 +742,7 @@
}
}
#ifdef _WIN32
- if (tt->windows_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOWS6 &&= amp; (rwflags & EVENT_READ))
+ if (tt->backend_driver =3D=3D WINDOWS_DRIVER_TAP_WINDOW= S6 && (rwflags & EVENT_READ))
{
= tun_read_queue(tt, 0);
}

To view, visit change 738. To unsubscribe, or for help wri= ting mail filters, visit set= tings.

=
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8c0e9f32b235cb262ca2be6aac8= d520e49b30d74
Gerrit-Change-Number: 738
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--LthCVAeO+XM=--