Skip to contentSkip to conversation

tun.c: make Windows device lookup functions more general

PATCH Superseded Simon Rozman 3 participants 40 messages Dec 19, 2019 – Jan 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 tun.c: make Windows device lookup functions more general

Since the introduction of Wintun, not all network devices in Windows are TAP-Windows6. Rather than returning a simple true/false answer, a couple of functions were reworked to return a corresponding struct tap_reg * or NULL instead.

As it would make the code tr = is_tap_win(...) a bit awkward those functions (both static) were renamed to better reflect their nature.

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
src/openvpn/tun.c +22 -17
index ad497a71..053a8232 100644
@@ -3976,10 +3976,10 @@ show_tap_win_adapters(int msglev, int warnlev)
 }
 
 /*
- * Confirm that GUID is a TAP-Windows adapter.
+ * Lookup a TAP-Windows or Wintun adapter by GUID.
  */
-static bool
-is_tap_win(const char *guid, const struct tap_reg *tap_reg)
+static const struct tap_reg *
+get_tap_by_guid(const char *guid, const struct tap_reg *tap_reg)
 {
     const struct tap_reg *tr;
 
@@ -3987,11 +3987,11 @@ is_tap_win(const char *guid, const struct tap_reg *tap_reg)
     {
         if (guid && !strcmp(tr->guid, guid))
         {
-            return true;
+            return tr;
         }
     }
 
-    return false;
+    return NULL;
 }
 
 static const char *
@@ -4010,16 +4010,16 @@ guid_to_name(const char *guid, const struct panel_reg *panel_reg)
     return NULL;
 }
 
-static const char *
-name_to_guid(const char *name, const struct tap_reg *tap_reg, const struct panel_reg *panel_reg)
+static const struct tap_reg *
+get_tap_by_name(const char *name, const struct tap_reg *tap_reg, const struct panel_reg *panel_reg)
 {
     const struct panel_reg *pr;
 
     for (pr = panel_reg; pr != NULL; pr = pr->next)
     {
-        if (name && !strcmp(pr->name, name) && is_tap_win(pr->guid, tap_reg))
+        if (name && !strcmp(pr->name, name))
         {
-            return pr->guid;
+            return get_tap_by_guid(pr->guid, tap_reg);
         }
     }
 
@@ -4116,6 +4116,7 @@ get_device_guid(const char *name,
 {
     struct buffer ret = alloc_buf_gc(256, gc);
     struct buffer actual = clear_buf();
+    const struct tap_reg *tr;
 
     /* Make sure we have at least one TAP adapter */
     if (!tap_reg)
@@ -4131,7 +4132,8 @@ get_device_guid(const char *name,
     }
 
     /* Check if GUID was explicitly specified as --dev-node parameter */
-    if (is_tap_win(name, tap_reg))
+    tr = get_tap_by_guid(name, tap_reg);
+    if (tr)
     {
         const char *act = guid_to_name(name, panel_reg);
         buf_printf(&ret, "%s", name);
@@ -4148,11 +4150,11 @@ get_device_guid(const char *name,
 
     /* Lookup TAP adapter in network connections list */
     {
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        if (guid)
+        tr = get_tap_by_name(name, tap_reg, panel_reg);
+        if (tr)
         {
             buf_printf(&actual, "%s", name);
-            buf_printf(&ret, "%s", guid);
+            buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
     }
@@ -4696,11 +4698,14 @@ get_adapter_index_flexible(const char *name)  /* actual name or GUID */
     {
         const struct tap_reg *tap_reg = get_tap_reg(&gc);
         const struct panel_reg *panel_reg = get_panel_reg(&gc);
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        index = get_adapter_index_method_1(guid);
-        if (index == TUN_ADAPTER_INDEX_INVALID)
+        const struct tap_reg *tr = get_tap_by_name(name, tap_reg, panel_reg);
+        if (tr)
         {
-            index = get_adapter_index_method_2(guid);
+            index = get_adapter_index_method_1(tr->guid);
+            if (index == TUN_ADAPTER_INDEX_INVALID)
+            {
+                index = get_adapter_index_method_2(tr->guid);
+            }
         }
     }
     if (index == TUN_ADAPTER_INDEX_INVALID)
Signature · 1 line
2.24.1.windows.2
#1 lore raw

PATCH 2/7 tun.c: upgrade get_device_guid() to return the Windows driver type

---
 src/openvpn/tun.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
src/openvpn/tun.c +12 -3
index 053a8232..623ed37b 100644
@@ -4110,6 +4110,7 @@ static const char *
 get_device_guid(const char *name,
                 char *actual_name,
                 int actual_name_size,
+                bool *wintun,
                 const struct tap_reg *tap_reg,
                 const struct panel_reg *panel_reg,
                 struct gc_arena *gc)
@@ -4145,6 +4146,10 @@ get_device_guid(const char *name,
         {
             buf_printf(&actual, "%s", name);
         }
+        if (wintun)
+        {
+            *wintun = tr->wintun;
+        }
         return BSTR(&ret);
     }
 
@@ -4154,6 +4159,10 @@ get_device_guid(const char *name,
         if (tr)
         {
             buf_printf(&actual, "%s", name);
+            if (wintun)
+            {
+                *wintun = tr->wintun;
+            }
             buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
@@ -4838,7 +4847,7 @@ tap_allow_nonadmin_access(const char *dev_node)
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node. */
-        device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
 
         if (!device_guid)
         {
@@ -5412,7 +5421,7 @@ netsh_get_id(const char *dev_node, struct gc_arena *gc)
 
     if (dev_node)
     {
-        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), tap_reg, panel_reg, gc);
+        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), NULL, tap_reg, panel_reg, gc);
     }
     else
     {
@@ -6132,7 +6141,7 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node. */
-        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
 
         if (!*device_guid)
         {
Signature · 1 line
2.24.1.windows.2
#6 lore raw

PATCH 3/7 tun.c: make wintun_register_ring_buffer() non-fatal on failures

In reply to Simon Rozman

Wintun allows multiple handles to be opened on it's NDIS device pipe. Just by succeeding to open the pipe does not warrant the adapter is unused.

When iterating for available Wintun adapter, we will need to try registering ring buffers with each one to actually determine which one is used and which one is not.

Therefore, a failure to register ring buffers should be detectable, but not M_FATAL.

---
 src/openvpn/tun.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
src/openvpn/tun.c +18 -8
index 623ed37b..220dee87 100644
@@ -5647,11 +5647,12 @@ register_dns_service(const struct tuntap *tt)
     gc_free(&gc);
 }
 
-static void
+static bool
 service_register_ring_buffers(const struct tuntap *tt)
 {
     HANDLE msg_channel = tt->options.msg_channel;
     ack_message_t ack;
+    bool ret = true;
     struct gc_arena gc = gc_new();
 
     register_ring_buffers_message_t msg = {
@@ -5669,13 +5670,13 @@ service_register_ring_buffers(const struct tuntap *tt)
 
     if (!send_msg_iservice(msg_channel, &msg, sizeof(msg), &ack, "Register ring buffers"))
     {
-        gc_free(&gc);
-        return;
+        ret = false;
     }
     else if (ack.error_number != NO_ERROR)
     {
-        msg(M_FATAL, "Register ring buffers failed using service: %s [status=0x%x]",
+        msg(M_NONFATAL, "Register ring buffers failed using service: %s [status=0x%x]",
             strerror_win32(ack.error_number, &gc), ack.error_number);
+        ret = false;
     }
     else
     {
@@ -5683,6 +5684,7 @@ service_register_ring_buffers(const struct tuntap *tt)
     }
 
     gc_free(&gc);
+    return ret;
 }
 
 void
@@ -5922,9 +5924,11 @@ tuntap_set_ip_addr(struct tuntap *tt,
     gc_free(&gc);
 }
 
-static void
+static bool
 wintun_register_ring_buffer(struct tuntap *tt)
 {
+    bool ret = true;
+
     tt->wintun_send_ring = (struct tun_ring *)MapViewOfFile(tt->wintun_send_ring_handle,
                                                             FILE_MAP_ALL_ACCESS,
                                                             0,
@@ -5939,7 +5943,7 @@ wintun_register_ring_buffer(struct tuntap *tt)
 
     if (tt->options.msg_channel)
     {
-        service_register_ring_buffers(tt);
+        ret = service_register_ring_buffers(tt);
     }
     else
     {
@@ -5953,13 +5957,16 @@ wintun_register_ring_buffer(struct tuntap *tt)
             tt->rw_handle.read,
             tt->rw_handle.write))
         {
-            msg(M_FATAL, "ERROR:  Failed to register ring buffers: %lu", GetLastError());
+            msg(M_NONFATAL, "Failed to register ring buffers: %lu", GetLastError());
+            ret = false;
         }
         if (!RevertToSelf())
         {
             msg(M_FATAL, "ERROR:  RevertToSelf error: %lu", GetLastError());
         }
     }
+
+    return ret;
 }
 
 static void
@@ -6367,7 +6374,10 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 
     if (tt->wintun)
     {
-        wintun_register_ring_buffer(tt);
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(M_FATAL, "Failed to register ring buffers");
+        }
     }
     else
     {
Signature · 1 line
2.24.1.windows.2
#11 lore raw

PATCH 4/7 wintun: register ring buffers when iterating adapters

In reply to Simon Rozman

Wintun adapters may be considered available if ring buffer registration succeeded. Therefore, we must attempt to register ring buffers when iterating adapters and continue on failure.

---
 src/openvpn/tun.c | 110 +++++++++++++++++++++++++++-------------------
 1 file changed, 64 insertions(+), 46 deletions(-)
src/openvpn/tun.c +64 -46
index 220dee87..9dc9b3a2 100644
@@ -6129,11 +6129,71 @@ tuntap_dhcp_mask(const struct tuntap *tt, const char *device_guid)
     gc_free(&gc);
 }
 
+static bool
+tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct device_instance_id_interface *device_instance_id_interface)
+{
+    const char *path = NULL;
+    char tuntap_device_path[256];
+
+    if (tt->wintun)
+    {
+        const struct device_instance_id_interface *dev_if;
+
+        /* Open Wintun adapter */
+        for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next)
+        {
+            if (strcmp(dev_if->net_cfg_instance_id, device_guid) == 0)
+            {
+                path = dev_if->device_interface_list;
+                break;
+            }
+        }
+        if (path == NULL)
+        {
+            return false;
+        }
+    }
+    else
+    {
+        /* Open TAP-Windows adapter */
+        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
+                            USERMODEDEVICEDIR,
+                            device_guid,
+                            TAP_WIN_SUFFIX);
+        path = tuntap_device_path;
+    }
+
+    tt->hand = CreateFile(path,
+                          GENERIC_READ | GENERIC_WRITE,
+                          0,                /* was: FILE_SHARE_READ */
+                          0,
+                          OPEN_EXISTING,
+                          FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
+                          0);
+
+    if (tt->hand == INVALID_HANDLE_VALUE)
+    {
+        msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "Wintun" : "TAP-Windows", path);
+        return false;
+    }
+
+    if (tt->wintun)
+    {
+        /* Wintun adapter may be considered "open" after ring buffers are successfuly registered. */
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(D_TUNTAP_INFO, "Failed to register %s adapter ring buffers", device_guid);
+            return false;
+        }
+    }
+
+    return true;
+}
+
 static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid)
 {
     struct gc_arena gc = gc_new();
-    char *path = NULL;
     char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);
@@ -6197,27 +6257,11 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
 
             if (tt->wintun)
             {
-                const struct device_instance_id_interface* dev_if;
-
                 if (!is_picked_device_wintun)
                 {
                     /* wintun driver specified but picked adapter is not wintun, proceed to next one */
                     goto next;
                 }
-
-                path = NULL;
-                for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next)
-                {
-                    if (strcmp(dev_if->net_cfg_instance_id, *device_guid) == 0)
-                    {
-                        path = (char*)dev_if->device_interface_list;
-                        break;
-                    }
-                }
-                if (path == NULL)
-                {
-                    goto next;
-                }
             }
             else
             {
@@ -6226,28 +6270,9 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
                     /* tap-windows6 driver specified but picked adapter is wintun, proceed to next one */
                     goto next;
                 }
-
-                /* Open Windows TAP-Windows adapter */
-                openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
-                                 USERMODEDEVICEDIR,
-                                 *device_guid,
-                                 TAP_WIN_SUFFIX);
-                path = tuntap_device_path;
             }
 
-            tt->hand = CreateFile(path,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  0,                /* was: FILE_SHARE_READ */
-                                  0,
-                                  OPEN_EXISTING,
-                                  FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
-                                  0);
-
-            if (tt->hand == INVALID_HANDLE_VALUE)
-            {
-                msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "wintun" : "TAP", tuntap_device_path);
-            }
-            else
+            if (tun_try_open_device(tt, *device_guid, device_instance_id_interface))
             {
                 break;
             }
@@ -6261,7 +6286,7 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
      * GUID using the registry */
     tt->actual_name = string_alloc(actual_buffer, NULL);
 
-    msg(M_INFO, "%s device [%s] opened: %s", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name, path);
+    msg(M_INFO, "%s device [%s] opened", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name);
     tt->adapter_index = get_adapter_index(*device_guid);
 
     gc_free(&gc);
@@ -6372,14 +6397,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 
     tun_open_device(tt, dev_node, &device_guid);
 
-    if (tt->wintun)
-    {
-        if (!wintun_register_ring_buffer(tt))
-        {
-            msg(M_FATAL, "Failed to register ring buffers");
-        }
-    }
-    else
+    if (!tt->wintun)
     {
         tuntap_post_open(tt, device_guid);
     }
Signature · 1 line
2.24.1.windows.2
#18 lore raw

PATCH 5/7 wintun: add support for --dev-node

In reply to Simon Rozman
---
 src/openvpn/tun.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
src/openvpn/tun.c +20 -18
index 9dc9b3a2..8508b9c0 100644
@@ -6194,7 +6194,6 @@ static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid)
 {
     struct gc_arena gc = gc_new();
-    char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);
     const struct device_instance_id_interface* device_instance_id_interface = get_device_instance_id_interface(&gc);
@@ -6207,31 +6206,34 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
      */
     if (dev_node)
     {
+        bool is_picked_device_wintun = false;
+
         /* Get the device GUID for the device specified with --dev-node. */
-        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), &is_picked_device_wintun, tap_reg, panel_reg, &gc);
 
         if (!*device_guid)
         {
-            msg(M_FATAL, "TAP-Windows adapter '%s' not found", dev_node);
+            msg(M_FATAL, "Adapter '%s' not found", dev_node);
         }
 
-        /* Open Windows TAP-Windows adapter */
-        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
-                         USERMODEDEVICEDIR,
-                         *device_guid,
-                         TAP_WIN_SUFFIX);
-
-        tt->hand = CreateFile(tuntap_device_path,
-                              GENERIC_READ | GENERIC_WRITE,
-                              0,                /* was: FILE_SHARE_READ */
-                              0,
-                              OPEN_EXISTING,
-                              FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
-                              0);
+        if (tt->wintun)
+        {
+            if (!is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is TAP-Windows, Wintun expected", dev_node);
+            }
+        }
+        else
+        {
+            if (is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is Wintun, TAP-Windows expected", dev_node);
+            }
+        }
 
-        if (tt->hand == INVALID_HANDLE_VALUE)
+        if (!tun_try_open_device(tt, *device_guid, device_instance_id_interface))
         {
-            msg(M_ERR, "CreateFile failed on TAP device: %s", tuntap_device_path);
+            msg(M_FATAL, "Failed to open %s adapter: %s", tt->wintun ? "Wintun" : "TAP-Windows", dev_node);
         }
     }
     else
Signature · 1 line
2.24.1.windows.2
#23 lore raw

PATCH 6/7 wintun: stop sending TAP-Windows6 ioctls to NDIS device

In reply to Simon Rozman

Wintun doesn't have its own I/O device. Rather, it taps on existing Windows-provided NDIS device. Sending TAP-Windows6 IOCTL requests to it is risky, as TAP-Windows6 is using one of the well-known device types (FILE_DEVICE_UNKNOWN) with function IDs as 1, 2, 3 etc. raising a chance of collision as NDIS might react to one of these IOCTLs.

---
 src/openvpn/error.c   | 5 ++++-
 src/openvpn/forward.c | 2 +-
 src/openvpn/sig.c     | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)
src/openvpn/error.c +4 -1
index b2492f2b..8d91a131 100644
@@ -688,7 +688,10 @@ x_check_status(int status,
         }
 #elif defined(_WIN32)
         /* get possible driver error from TAP-Windows driver */
-        extended_msg = tap_win_getinfo(tt, &gc);
+        if (!tt->wintun)
+        {
+            extended_msg = tap_win_getinfo(tt, &gc);
+        }
 #endif
         if (!ignore_sys_error(my_errno))
         {
src/openvpn/forward.c +1 -1
index 6b823613..2bc9d871 100644
@@ -1956,7 +1956,7 @@ pre_select(struct context *c)
     if (check_debug_level(D_TAP_WIN_DEBUG))
     {
         c->c2.timeval.tv_sec = 1;
-        if (tuntap_defined(c->c1.tuntap))
+        if (tuntap_defined(c->c1.tuntap) && !c->c1.tuntap->wintun)
         {
             tun_show_debug(c->c1.tuntap);
         }
src/openvpn/sig.c +1 -1
index d7f2abb8..f02aa57c 100644
@@ -315,7 +315,7 @@ print_status(const struct context *c, struct status_output *so)
     status_printf(so, "Post-decrypt truncations," counter_format, c->c2.n_trunc_post_decrypt);
 #endif
 #ifdef _WIN32
-    if (tuntap_defined(c->c1.tuntap))
+    if (tuntap_defined(c->c1.tuntap) && !c->c1.tuntap->wintun)
     {
         status_printf(so, "TAP-WIN32 driver status,\"%s\"",
                       tap_win_getinfo(c->c1.tuntap, &gc));
Signature · 1 line
2.24.1.windows.2
#30 lore raw

PATCH 7/7 tun.c: reword the at_least_one_tap_win() error

In reply to Simon Rozman
---
 src/openvpn/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/tun.c +1 -1
index 8508b9c0..14ff0259 100644
@@ -4031,7 +4031,7 @@ at_least_one_tap_win(const struct tap_reg *tap_reg)
 {
     if (!tap_reg)
     {
-        msg(M_FATAL, "There are no TAP-Windows adapters on this system.  You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter.");
+        msg(M_FATAL, "There are no TAP-Windows nor Wintun adapters on this system.  You should be able to create an adapter by using tapctl.exe utility.");
     }
 }
 
Signature · 1 line
2.24.1.windows.2
Acked-by on v1 1/7
#35 lore raw
In reply to Simon Rozman

Hi,

Build in MSVC, tested and ran in debugger.

The only nitpick is those methods (since you have touched them)

+get_tap_by_guid(const char *guid, const struct tap_reg *tap_reg) +get_tap_by_name(const char *name, const struct tap_reg *tap_reg, const
struct panel_reg *panel_reg)

could be renamed to "get_tuntap_by_*" or even better, "get_adapter_by_*" since they're
adapter-type agnostic and deal with both tap and wintun.

pe 20. jouluk. 2019 klo 0.40 Simon Rozman ([email protected]...) kirjoitti:

Quoted 135 lines

Since the introduction of Wintun, not all network devices in Windows are TAP-Windows6. Rather than returning a simple true/false answer, a couple of functions were reworked to return a corresponding struct tap_reg * or NULL instead.

As it would make the code tr = is_tap_win(...) a bit awkward those functions (both static) were renamed to better reflect their nature.

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
src/openvpn/tun.c +5 -5
index ad497a71..053a8232 100644
@@ -3976,10 +3976,10 @@ show_tap_win_adapters(int msglev, int warnlev)
 }
 
 /*
- * Confirm that GUID is a TAP-Windows adapter.
+ * Lookup a TAP-Windows or Wintun adapter by GUID.
  */
-static bool
-is_tap_win(const char *guid, const struct tap_reg *tap_reg)
+static const struct tap_reg *
+get_tap_by_guid(const char *guid, const struct tap_reg *tap_reg)
 {
     const struct tap_reg *tr;
 
@@ -3987,11 +3987,11 @@ is_tap_win(const char *guid, const struct tap_reg
 *tap_reg)
     {
         if (guid && !strcmp(tr->guid, guid))
         {
-            return true;
+            return tr;
         }
     }
 
-    return false;
+    return NULL;
 }
 

static const char *

src/openvpn/tun.c +10 -8
@@ -4010,16 +4010,16 @@ guid_to_name(const char *guid, const struct
 panel_reg *panel_reg)
     return NULL;
 }
 
-static const char *
-name_to_guid(const char *name, const struct tap_reg *tap_reg, const
 struct panel_reg *panel_reg)
+static const struct tap_reg *
+get_tap_by_name(const char *name, const struct tap_reg *tap_reg, const
 struct panel_reg *panel_reg)
 {
     const struct panel_reg *pr;
 
     for (pr = panel_reg; pr != NULL; pr = pr->next)
     {
-        if (name && !strcmp(pr->name, name) && is_tap_win(pr->guid,
 tap_reg))
+        if (name && !strcmp(pr->name, name))
         {
-            return pr->guid;
+            return get_tap_by_guid(pr->guid, tap_reg);
         }
     }
@@ -4116,6 +4116,7 @@ get_device_guid(const char *name,
 {
     struct buffer ret = alloc_buf_gc(256, gc);
     struct buffer actual = clear_buf();
+    const struct tap_reg *tr;
 
     /* Make sure we have at least one TAP adapter */
     if (!tap_reg)
@@ -4131,7 +4132,8 @@ get_device_guid(const char *name,
     }
 
     /* Check if GUID was explicitly specified as --dev-node parameter */
-    if (is_tap_win(name, tap_reg))
+    tr = get_tap_by_guid(name, tap_reg);
+    if (tr)
     {
         const char *act = guid_to_name(name, panel_reg);
         buf_printf(&ret, "%s", name);
@@ -4148,11 +4150,11 @@ get_device_guid(const char *name,
 
     /* Lookup TAP adapter in network connections list */
     {
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        if (guid)
+        tr = get_tap_by_name(name, tap_reg, panel_reg);
+        if (tr)
         {
             buf_printf(&actual, "%s", name);
-            buf_printf(&ret, "%s", guid);
+            buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
     }
@@ -4696,11 +4698,14 @@ get_adapter_index_flexible(const char *name)  /*

actual name or GUID */

     {
         const struct tap_reg *tap_reg = get_tap_reg(&gc);
         const struct panel_reg *panel_reg = get_panel_reg(&gc);
src/openvpn/tun.c +1 -3
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        index = get_adapter_index_method_1(guid);
-        if (index == TUN_ADAPTER_INDEX_INVALID)
+        const struct tap_reg *tr = get_tap_by_name(name, tap_reg,

panel_reg);

src/openvpn/tun.c +6 -2
+        if (tr)
         {
-            index = get_adapter_index_method_2(guid);
+            index = get_adapter_index_method_1(tr->guid);
+            if (index == TUN_ADAPTER_INDEX_INVALID)
+            {
+                index = get_adapter_index_method_2(tr->guid);
+            }
         }
     }
     if (index == TUN_ADAPTER_INDEX_INVALID)
--

2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
Acked-by on v1 2/7
#2 lore raw

Re: [Openvpn-devel] [PATCH 2/7] tun.c: upgrade get_device_guid() to return the Windows driver type

In reply to Simon Rozman

Hi,

While at the moment NULL is always passed when calling get_device_guid(), this change will be needed in 5/7 "intun: add support for --dev-node".

You (or committer :) may want to update comment, since it also returns optional device type:

/*
* Lookup a --dev-node adapter name in the registry
* returning the GUID, optional actual_name and device type */

Other than that, looks good.

get_device_guid(const char *name,

Quoted 75 lines

char *actual_name,
int actual_name_size,

src/openvpn/tun.c +10 -1
+                bool *wintun,
                 const struct tap_reg *tap_reg,
                 const struct panel_reg *panel_reg,
                 struct gc_arena *gc)
@@ -4145,6 +4146,10 @@ get_device_guid(const char *name,
         {
             buf_printf(&actual, "%s", name);
         }
+        if (wintun)
+        {
+            *wintun = tr->wintun;
+        }
         return BSTR(&ret);
     }
 
@@ -4154,6 +4159,10 @@ get_device_guid(const char *name,
         if (tr)
         {
             buf_printf(&actual, "%s", name);
+            if (wintun)
+            {
+                *wintun = tr->wintun;
+            }
             buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
@@ -4838,7 +4847,7 @@ tap_allow_nonadmin_access(const char *dev_node)
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node.
 */
-        device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
         if (!device_guid)
         {
(quoted diff) +1 -1
@@ -5412,7 +5421,7 @@ netsh_get_id(const char *dev_node, struct gc_arena
 *gc)
 
     if (dev_node)
     {
-        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual),
 tap_reg, panel_reg, gc);
+        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual),
 NULL, tap_reg, panel_reg, gc);
     }
     else
     {
(quoted diff) +1 -1
@@ -6132,7 +6141,7 @@ tun_open_device(struct tuntap *tt, const char
 *dev_node, const char **device_gui
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node.
 */
-        *device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer,

sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);

         if (!*device_guid)
         {

--
2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
Acked-by on v1 3/7
#7 lore raw

Re: [Openvpn-devel] [PATCH 3/7] tun.c: make wintun_register_ring_buffer() non-fatal on failures

In reply to Simon Rozman

Compiled with MSVC, ran under debugger - works as expected.

pe 20. jouluk. 2019 klo 0.40 Simon Rozman ([email protected]...) kirjoitti:

Quoted 132 lines

Wintun allows multiple handles to be opened on it's NDIS device pipe. Just by succeeding to open the pipe does not warrant the adapter is unused.

When iterating for available Wintun adapter, we will need to try registering ring buffers with each one to actually determine which one is used and which one is not.

Therefore, a failure to register ring buffers should be detectable, but not M_FATAL.

---
 src/openvpn/tun.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
src/openvpn/tun.c +6 -4
index 623ed37b..220dee87 100644
@@ -5647,11 +5647,12 @@ register_dns_service(const struct tuntap *tt)
     gc_free(&gc);
 }
 
-static void
+static bool
 service_register_ring_buffers(const struct tuntap *tt)
 {
     HANDLE msg_channel = tt->options.msg_channel;
     ack_message_t ack;
+    bool ret = true;
     struct gc_arena gc = gc_new();
 
     register_ring_buffers_message_t msg = {
@@ -5669,13 +5670,13 @@ service_register_ring_buffers(const struct tuntap
 *tt)
 
     if (!send_msg_iservice(msg_channel, &msg, sizeof(msg), &ack,
 "Register ring buffers"))
     {
-        gc_free(&gc);
-        return;
+        ret = false;
     }
     else if (ack.error_number != NO_ERROR)
     {
-        msg(M_FATAL, "Register ring buffers failed using service: %s
 [status=0x%x]",
+        msg(M_NONFATAL, "Register ring buffers failed using service: %s
 [status=0x%x]",
             strerror_win32(ack.error_number, &gc), ack.error_number);
+        ret = false;
     }
     else
     {
@@ -5683,6 +5684,7 @@ service_register_ring_buffers(const struct tuntap
 *tt)
     }
 
     gc_free(&gc);
+    return ret;
 }
 

void

src/openvpn/tun.c +3 -1
@@ -5922,9 +5924,11 @@ tuntap_set_ip_addr(struct tuntap *tt,
     gc_free(&gc);
 }
 
-static void
+static bool
 wintun_register_ring_buffer(struct tuntap *tt)
 {
+    bool ret = true;
+
     tt->wintun_send_ring = (struct tun_ring
 *)MapViewOfFile(tt->wintun_send_ring_handle,
 

FILE_MAP_ALL_ACCESS,

                                                             0,
src/openvpn/tun.c +5 -2
@@ -5939,7 +5943,7 @@ wintun_register_ring_buffer(struct tuntap *tt)
 
     if (tt->options.msg_channel)
     {
-        service_register_ring_buffers(tt);
+        ret = service_register_ring_buffers(tt);
     }
     else
     {
@@ -5953,13 +5957,16 @@ wintun_register_ring_buffer(struct tuntap *tt)
             tt->rw_handle.read,
             tt->rw_handle.write))
         {
-            msg(M_FATAL, "ERROR:  Failed to register ring buffers: %lu",
 GetLastError());
+            msg(M_NONFATAL, "Failed to register ring buffers: %lu",
 GetLastError());
+            ret = false;
         }
         if (!RevertToSelf())
         {
             msg(M_FATAL, "ERROR:  RevertToSelf error: %lu",
 GetLastError());
         }
     }
+
+    return ret;

}

static void

src/openvpn/tun.c +0 -0
@@ -6367,7 +6374,10 @@ open_tun(const char *dev, const char *dev_type,

const char *dev_node, struct tun

     if (tt->wintun)
     {
src/openvpn/tun.c +4 -2
-        wintun_register_ring_buffer(tt);
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(M_FATAL, "Failed to register ring buffers");
+        }
     }
     else
     {
--

2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
Acked-by on v1 5/7
#19 lore raw

Re: [Openvpn-devel] [PATCH 5/7] wintun: add support for --dev-node

In reply to Simon Rozman

Built, tested - works as expected. Probably the first time I ran two VPN tunnels with OpenVPN-GUI.

The code has an assumption, however, that "windows-driver" power over "dev-node" -
if --dev-node is "OpenVPNWinTun" (for example) and "windows-driver" is not specified, we bail out.

I would add something like "if you want to use this device, add --windows-driver wintun" (and similar for tap)
to the error message - I think it is good to tell user how to proceed in case of error(s).

pe 20. jouluk. 2019 klo 0.40 Simon Rozman ([email protected]...) kirjoitti:

Quoted 92 lines
---
 src/openvpn/tun.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
src/openvpn/tun.c +0 -1
index 9dc9b3a2..8508b9c0 100644
@@ -6194,7 +6194,6 @@ static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char
 **device_guid)
 {
     struct gc_arena gc = gc_new();
-    char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);

const struct device_instance_id_interface*
device_instance_id_interface = get_device_instance_id_interface(&gc);

src/openvpn/tun.c +16 -15
@@ -6207,31 +6206,34 @@ tun_open_device(struct tuntap *tt, const char
 *dev_node, const char **device_gui
      */
     if (dev_node)
     {
+        bool is_picked_device_wintun = false;
+
         /* Get the device GUID for the device specified with --dev-node.
 */
-        *device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), &is_picked_device_wintun, tap_reg, panel_reg, &gc);
 
         if (!*device_guid)
         {
-            msg(M_FATAL, "TAP-Windows adapter '%s' not found", dev_node);
+            msg(M_FATAL, "Adapter '%s' not found", dev_node);
         }
 
-        /* Open Windows TAP-Windows adapter */
-        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path),
 "%s%s%s",
-                         USERMODEDEVICEDIR,
-                         *device_guid,
-                         TAP_WIN_SUFFIX);
-
-        tt->hand = CreateFile(tuntap_device_path,
-                              GENERIC_READ | GENERIC_WRITE,
-                              0,                /* was: FILE_SHARE_READ */
-                              0,
-                              OPEN_EXISTING,
-                              FILE_ATTRIBUTE_SYSTEM |
 FILE_FLAG_OVERLAPPED,
-                              0);
+        if (tt->wintun)
+        {
+            if (!is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is TAP-Windows, Wintun
 expected", dev_node);
+            }
+        }
+        else
+        {
+            if (is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is Wintun, TAP-Windows

expected", dev_node);

src/openvpn/tun.c +3 -1
+            }
+        }
 
-        if (tt->hand == INVALID_HANDLE_VALUE)
+        if (!tun_try_open_device(tt, *device_guid,

device_instance_id_interface))

         {
-            msg(M_ERR, "CreateFile failed on TAP device: %s",
tuntap_device_path);
+            msg(M_FATAL, "Failed to open %s adapter: %s", tt->wintun ?
"Wintun" : "TAP-Windows", dev_node);
         }
     }
     else

--
2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
#12 lore raw

Re: [Openvpn-devel] [PATCH 4/7] wintun: register ring buffers when iterating adapters

In reply to Simon Rozman

Hi,

Compiled and tested, works as expected. One thing:

Quoted 6 lines

+ if (tun_try_open_device(tt, *device_guid,
device_instance_id_interface))

             {
                 break;
             }

We leak tt->hand here if we don't break - in the next loop iteration we overwrite tt->hand
and previous value left unclosed.

Maybe add

    CloseHandle(tt->hand)
    tt->hand = NULL;

after "if" statement and before "next" label ?

Signature · 1 line
-Lev
#24 lore raw

Re: [Openvpn-devel] [PATCH 6/7] wintun: stop sending TAP-Windows6 ioctls to NDIS device

In reply to Simon Rozman

Hi,

@@ -688,7 +688,10 @@ x_check_status(int status,

src/openvpn/error.c x_check_status(int status, · line 694

Quoted 9 lines
         }
 #elif defined(_WIN32)
         /* get possible driver error from TAP-Windows driver */
src/openvpn/error.c +4 -1
-        extended_msg = tap_win_getinfo(tt, &gc);
+        if (!tt->wintun)
+        {
+            extended_msg = tap_win_getinfo(tt, &gc);
+        }

What if we make error.c device type agnostic and move that check into tun.c, tap_win_getinfo():

    const char *
    tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
    {
        if (tuntap_defined(tt) && !tuntap_is_wintun(tt))
            {
                /* get debug log from tap-windows6 */

-Lev

Acked-by on v1 7/7
#31 lore raw

Re: [Openvpn-devel] [PATCH 7/7] tun.c: reword the at_least_one_tap_win() error

In reply to Simon Rozman

Makes sense, since we now support both tap-windows and wintun.

pe 20. jouluk. 2019 klo 0.40 Simon Rozman ([email protected]...) kirjoitti:

Quoted 33 lines
---
 src/openvpn/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/tun.c +0 -1
index 8508b9c0..14ff0259 100644
@@ -4031,7 +4031,7 @@ at_least_one_tap_win(const struct tap_reg *tap_reg)
 {
     if (!tap_reg)
     {
-        msg(M_FATAL, "There are no TAP-Windows adapters on this system.

You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter.");
+ msg(M_FATAL, "There are no TAP-Windows nor Wintun adapters on
this system. You should be able to create an adapter by using tapctl.exe

utility.");
     }

}

--
2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
#39 lore raw
In reply to Simon Rozman

Hi,

Quoted 7 lines · Simon Rozman

Since the introduction of Wintun, not all network devices in Windows are TAP-Windows6. Rather than returning a simple true/false answer, a couple of functions were reworked to return a corresponding struct tap_reg * or NULL instead.

As it would make the code tr = is_tap_win(...) a bit awkward those functions (both static) were renamed to better reflect their nature.

For the sake of the archives: Simon and Lev discussed these patches on IRC today, came up with proposed changes, and Simon will send a new "v2" series of all of them - so even if they have an ACK, I won't apply them just yet.

Just to avoid confusion.

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#36 lore raw

PATCH v2 1/7 tun.c: make Windows device lookup functions more general

In reply to Lev Stipakov

Since the introduction of Wintun, not all network devices in Windows are TAP-Windows6. Rather than returning a simple true/false answer, a couple of functions were reworked to return a corresponding struct tap_reg * or NULL instead.

As it would make the code tr = is_tap_win(...) a bit awkward those functions (both static) were renamed to better reflect their nature.

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
src/openvpn/tun.c +22 -17
index ad497a71..0d6f40fe 100644
@@ -3976,10 +3976,10 @@ show_tap_win_adapters(int msglev, int warnlev)
 }
 
 /*
- * Confirm that GUID is a TAP-Windows adapter.
+ * Lookup a TAP-Windows or Wintun adapter by GUID.
  */
-static bool
-is_tap_win(const char *guid, const struct tap_reg *tap_reg)
+static const struct tap_reg *
+get_adapter_by_guid(const char *guid, const struct tap_reg *tap_reg)
 {
     const struct tap_reg *tr;
 
@@ -3987,11 +3987,11 @@ is_tap_win(const char *guid, const struct tap_reg *tap_reg)
     {
         if (guid && !strcmp(tr->guid, guid))
         {
-            return true;
+            return tr;
         }
     }
 
-    return false;
+    return NULL;
 }
 
 static const char *
@@ -4010,16 +4010,16 @@ guid_to_name(const char *guid, const struct panel_reg *panel_reg)
     return NULL;
 }
 
-static const char *
-name_to_guid(const char *name, const struct tap_reg *tap_reg, const struct panel_reg *panel_reg)
+static const struct tap_reg *
+get_adapter_by_name(const char *name, const struct tap_reg *tap_reg, const struct panel_reg *panel_reg)
 {
     const struct panel_reg *pr;
 
     for (pr = panel_reg; pr != NULL; pr = pr->next)
     {
-        if (name && !strcmp(pr->name, name) && is_tap_win(pr->guid, tap_reg))
+        if (name && !strcmp(pr->name, name))
         {
-            return pr->guid;
+            return get_adapter_by_guid(pr->guid, tap_reg);
         }
     }
 
@@ -4116,6 +4116,7 @@ get_device_guid(const char *name,
 {
     struct buffer ret = alloc_buf_gc(256, gc);
     struct buffer actual = clear_buf();
+    const struct tap_reg *tr;
 
     /* Make sure we have at least one TAP adapter */
     if (!tap_reg)
@@ -4131,7 +4132,8 @@ get_device_guid(const char *name,
     }
 
     /* Check if GUID was explicitly specified as --dev-node parameter */
-    if (is_tap_win(name, tap_reg))
+    tr = get_adapter_by_guid(name, tap_reg);
+    if (tr)
     {
         const char *act = guid_to_name(name, panel_reg);
         buf_printf(&ret, "%s", name);
@@ -4148,11 +4150,11 @@ get_device_guid(const char *name,
 
     /* Lookup TAP adapter in network connections list */
     {
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        if (guid)
+        tr = get_adapter_by_name(name, tap_reg, panel_reg);
+        if (tr)
         {
             buf_printf(&actual, "%s", name);
-            buf_printf(&ret, "%s", guid);
+            buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
     }
@@ -4696,11 +4698,14 @@ get_adapter_index_flexible(const char *name)  /* actual name or GUID */
     {
         const struct tap_reg *tap_reg = get_tap_reg(&gc);
         const struct panel_reg *panel_reg = get_panel_reg(&gc);
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        index = get_adapter_index_method_1(guid);
-        if (index == TUN_ADAPTER_INDEX_INVALID)
+        const struct tap_reg *tr = get_adapter_by_name(name, tap_reg, panel_reg);
+        if (tr)
         {
-            index = get_adapter_index_method_2(guid);
+            index = get_adapter_index_method_1(tr->guid);
+            if (index == TUN_ADAPTER_INDEX_INVALID)
+            {
+                index = get_adapter_index_method_2(tr->guid);
+            }
         }
     }
     if (index == TUN_ADAPTER_INDEX_INVALID)
Signature · 1 line
2.24.1.windows.2
#3 lore raw

PATCH v2 2/7 tun.c: upgrade get_device_guid() to return the Windows driver type

In reply to Lev Stipakov
---
 src/openvpn/tun.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
src/openvpn/tun.c +13 -4
index 0d6f40fe..f90f201d 100644
@@ -4104,12 +4104,13 @@ get_unspecified_device_guid(const int device_number,
 
 /*
  * Lookup a --dev-node adapter name in the registry
- * returning the GUID and optional actual_name.
+ * returning the GUID and optional actual_name and device type
  */
 static const char *
 get_device_guid(const char *name,
                 char *actual_name,
                 int actual_name_size,
+                bool *wintun,
                 const struct tap_reg *tap_reg,
                 const struct panel_reg *panel_reg,
                 struct gc_arena *gc)
@@ -4145,6 +4146,10 @@ get_device_guid(const char *name,
         {
             buf_printf(&actual, "%s", name);
         }
+        if (wintun)
+        {
+            *wintun = tr->wintun;
+        }
         return BSTR(&ret);
     }
 
@@ -4154,6 +4159,10 @@ get_device_guid(const char *name,
         if (tr)
         {
             buf_printf(&actual, "%s", name);
+            if (wintun)
+            {
+                *wintun = tr->wintun;
+            }
             buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
@@ -4838,7 +4847,7 @@ tap_allow_nonadmin_access(const char *dev_node)
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node. */
-        device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
 
         if (!device_guid)
         {
@@ -5412,7 +5421,7 @@ netsh_get_id(const char *dev_node, struct gc_arena *gc)
 
     if (dev_node)
     {
-        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), tap_reg, panel_reg, gc);
+        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual), NULL, tap_reg, panel_reg, gc);
     }
     else
     {
@@ -6132,7 +6141,7 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node. */
-        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
 
         if (!*device_guid)
         {
Signature · 1 line
2.24.1.windows.2
#8 lore raw

PATCH v2 3/7 tun.c: make wintun_register_ring_buffer() non-fatal on failures

In reply to Lev Stipakov

Wintun allows multiple handles to be opened on it's NDIS device pipe. Just by succeeding to open the pipe does not warrant the adapter is unused.

When iterating for available Wintun adapter, we will need to try registering ring buffers with each one to actually determine which one is used and which one is not.

Therefore, a failure to register ring buffers should be detectable, but not M_FATAL.

---
 src/openvpn/tun.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
src/openvpn/tun.c +18 -8
index f90f201d..c6bbbd41 100644
@@ -5647,11 +5647,12 @@ register_dns_service(const struct tuntap *tt)
     gc_free(&gc);
 }
 
-static void
+static bool
 service_register_ring_buffers(const struct tuntap *tt)
 {
     HANDLE msg_channel = tt->options.msg_channel;
     ack_message_t ack;
+    bool ret = true;
     struct gc_arena gc = gc_new();
 
     register_ring_buffers_message_t msg = {
@@ -5669,13 +5670,13 @@ service_register_ring_buffers(const struct tuntap *tt)
 
     if (!send_msg_iservice(msg_channel, &msg, sizeof(msg), &ack, "Register ring buffers"))
     {
-        gc_free(&gc);
-        return;
+        ret = false;
     }
     else if (ack.error_number != NO_ERROR)
     {
-        msg(M_FATAL, "Register ring buffers failed using service: %s [status=0x%x]",
+        msg(M_NONFATAL, "Register ring buffers failed using service: %s [status=0x%x]",
             strerror_win32(ack.error_number, &gc), ack.error_number);
+        ret = false;
     }
     else
     {
@@ -5683,6 +5684,7 @@ service_register_ring_buffers(const struct tuntap *tt)
     }
 
     gc_free(&gc);
+    return ret;
 }
 
 void
@@ -5922,9 +5924,11 @@ tuntap_set_ip_addr(struct tuntap *tt,
     gc_free(&gc);
 }
 
-static void
+static bool
 wintun_register_ring_buffer(struct tuntap *tt)
 {
+    bool ret = true;
+
     tt->wintun_send_ring = (struct tun_ring *)MapViewOfFile(tt->wintun_send_ring_handle,
                                                             FILE_MAP_ALL_ACCESS,
                                                             0,
@@ -5939,7 +5943,7 @@ wintun_register_ring_buffer(struct tuntap *tt)
 
     if (tt->options.msg_channel)
     {
-        service_register_ring_buffers(tt);
+        ret = service_register_ring_buffers(tt);
     }
     else
     {
@@ -5953,13 +5957,16 @@ wintun_register_ring_buffer(struct tuntap *tt)
             tt->rw_handle.read,
             tt->rw_handle.write))
         {
-            msg(M_FATAL, "ERROR:  Failed to register ring buffers: %lu", GetLastError());
+            msg(M_NONFATAL, "Failed to register ring buffers: %lu", GetLastError());
+            ret = false;
         }
         if (!RevertToSelf())
         {
             msg(M_FATAL, "ERROR:  RevertToSelf error: %lu", GetLastError());
         }
     }
+
+    return ret;
 }
 
 static void
@@ -6367,7 +6374,10 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 
     if (tt->wintun)
     {
-        wintun_register_ring_buffer(tt);
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(M_FATAL, "Failed to register ring buffers");
+        }
     }
     else
     {
Signature · 1 line
2.24.1.windows.2
#13 lore raw

PATCH v2 4/7 wintun: register ring buffers when iterating adapters

In reply to Lev Stipakov

Wintun adapters may be considered available if ring buffer registration succeeded. Therefore, we must attempt to register ring buffers when iterating adapters and continue on failure.

---
 src/openvpn/tun.c | 112 +++++++++++++++++++++++++++-------------------
 1 file changed, 66 insertions(+), 46 deletions(-)
src/openvpn/tun.c +66 -46
index c6bbbd41..f56682ef 100644
@@ -6129,11 +6129,73 @@ tuntap_dhcp_mask(const struct tuntap *tt, const char *device_guid)
     gc_free(&gc);
 }
 
+static bool
+tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct device_instance_id_interface *device_instance_id_interface)
+{
+    const char *path = NULL;
+    char tuntap_device_path[256];
+    HANDLE h;
+
+    if (tt->wintun)
+    {
+        const struct device_instance_id_interface *dev_if;
+
+        /* Open Wintun adapter */
+        for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next)
+        {
+            if (strcmp(dev_if->net_cfg_instance_id, device_guid) == 0)
+            {
+                path = dev_if->device_interface_list;
+                break;
+            }
+        }
+        if (path == NULL)
+        {
+            return false;
+        }
+    }
+    else
+    {
+        /* Open TAP-Windows adapter */
+        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
+                            USERMODEDEVICEDIR,
+                            device_guid,
+                            TAP_WIN_SUFFIX);
+        path = tuntap_device_path;
+    }
+
+    h = CreateFile(path,
+                   GENERIC_READ | GENERIC_WRITE,
+                   0,                /* was: FILE_SHARE_READ */
+                   0,
+                   OPEN_EXISTING,
+                   FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
+                   0);
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "Wintun" : "TAP-Windows", path);
+        return false;
+    }
+
+    if (tt->wintun)
+    {
+        /* Wintun adapter may be considered "open" after ring buffers are successfuly registered. */
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(D_TUNTAP_INFO, "Failed to register %s adapter ring buffers", device_guid);
+            CloseHandle(h);
+            return false;
+        }
+    }
+
+    tt->hand = h;
+    return true;
+}
+
 static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid)
 {
     struct gc_arena gc = gc_new();
-    char *path = NULL;
     char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);
@@ -6197,27 +6259,11 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
 
             if (tt->wintun)
             {
-                const struct device_instance_id_interface* dev_if;
-
                 if (!is_picked_device_wintun)
                 {
                     /* wintun driver specified but picked adapter is not wintun, proceed to next one */
                     goto next;
                 }
-
-                path = NULL;
-                for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next)
-                {
-                    if (strcmp(dev_if->net_cfg_instance_id, *device_guid) == 0)
-                    {
-                        path = (char*)dev_if->device_interface_list;
-                        break;
-                    }
-                }
-                if (path == NULL)
-                {
-                    goto next;
-                }
             }
             else
             {
@@ -6226,28 +6272,9 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
                     /* tap-windows6 driver specified but picked adapter is wintun, proceed to next one */
                     goto next;
                 }
-
-                /* Open Windows TAP-Windows adapter */
-                openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
-                                 USERMODEDEVICEDIR,
-                                 *device_guid,
-                                 TAP_WIN_SUFFIX);
-                path = tuntap_device_path;
             }
 
-            tt->hand = CreateFile(path,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  0,                /* was: FILE_SHARE_READ */
-                                  0,
-                                  OPEN_EXISTING,
-                                  FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
-                                  0);
-
-            if (tt->hand == INVALID_HANDLE_VALUE)
-            {
-                msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "wintun" : "TAP", tuntap_device_path);
-            }
-            else
+            if (tun_try_open_device(tt, *device_guid, device_instance_id_interface))
             {
                 break;
             }
@@ -6261,7 +6288,7 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
      * GUID using the registry */
     tt->actual_name = string_alloc(actual_buffer, NULL);
 
-    msg(M_INFO, "%s device [%s] opened: %s", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name, path);
+    msg(M_INFO, "%s device [%s] opened", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name);
     tt->adapter_index = get_adapter_index(*device_guid);
 
     gc_free(&gc);
@@ -6372,14 +6399,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 
     tun_open_device(tt, dev_node, &device_guid);
 
-    if (tt->wintun)
-    {
-        if (!wintun_register_ring_buffer(tt))
-        {
-            msg(M_FATAL, "Failed to register ring buffers");
-        }
-    }
-    else
+    if (!tt->wintun)
     {
         tuntap_post_open(tt, device_guid);
     }
Signature · 1 line
2.24.1.windows.2
#20 lore raw

PATCH v2 5/7 wintun: add support for --dev-node

In reply to Lev Stipakov
---
 src/openvpn/tun.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
src/openvpn/tun.c +20 -18
index f56682ef..18f06bb6 100644
@@ -6196,7 +6196,6 @@ static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid)
 {
     struct gc_arena gc = gc_new();
-    char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);
     const struct device_instance_id_interface* device_instance_id_interface = get_device_instance_id_interface(&gc);
@@ -6209,31 +6208,34 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
      */
     if (dev_node)
     {
+        bool is_picked_device_wintun = false;
+
         /* Get the device GUID for the device specified with --dev-node. */
-        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer, sizeof(actual_buffer), &is_picked_device_wintun, tap_reg, panel_reg, &gc);
 
         if (!*device_guid)
         {
-            msg(M_FATAL, "TAP-Windows adapter '%s' not found", dev_node);
+            msg(M_FATAL, "Adapter '%s' not found", dev_node);
         }
 
-        /* Open Windows TAP-Windows adapter */
-        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
-                         USERMODEDEVICEDIR,
-                         *device_guid,
-                         TAP_WIN_SUFFIX);
-
-        tt->hand = CreateFile(tuntap_device_path,
-                              GENERIC_READ | GENERIC_WRITE,
-                              0,                /* was: FILE_SHARE_READ */
-                              0,
-                              OPEN_EXISTING,
-                              FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
-                              0);
+        if (tt->wintun)
+        {
+            if (!is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is TAP-Windows, Wintun expected. If you want to use this device, remove --windows-driver wintun.", dev_node);
+            }
+        }
+        else
+        {
+            if (is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is Wintun, TAP-Windows expected. If you want to use this device, add --windows-driver wintun.", dev_node);
+            }
+        }
 
-        if (tt->hand == INVALID_HANDLE_VALUE)
+        if (!tun_try_open_device(tt, *device_guid, device_instance_id_interface))
         {
-            msg(M_ERR, "CreateFile failed on TAP device: %s", tuntap_device_path);
+            msg(M_FATAL, "Failed to open %s adapter: %s", tt->wintun ? "Wintun" : "TAP-Windows", dev_node);
         }
     }
     else
Signature · 1 line
2.24.1.windows.2
#25 lore raw

PATCH v2 6/7 wintun: stop sending TAP-Windows6 ioctls to NDIS device

In reply to Lev Stipakov

Wintun doesn't have its own I/O device. Rather, it taps on existing Windows-provided NDIS device. Sending TAP-Windows6 IOCTL requests to it is risky, as TAP-Windows6 is using one of the well-known device types (FILE_DEVICE_UNKNOWN) with function IDs as 1, 2, 3 etc. raising a chance of collision as NDIS might react to one of these IOCTLs.

---
 src/openvpn/tun.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/tun.c +2 -2
index 18f06bb6..6762402c 100644
@@ -6412,7 +6412,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 const char *
 tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
 {
-    if (tt && tt->hand != NULL)
+    if (tuntap_defined(tt) && !tt->wintun)
     {
         struct buffer out = alloc_buf_gc(256, gc);
         DWORD len;
@@ -6430,7 +6430,7 @@ tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
 void
 tun_show_debug(struct tuntap *tt)
 {
-    if (tt && tt->hand != NULL)
+    if (tuntap_defined(tt) && !tt->wintun)
     {
         struct buffer out = alloc_buf(1024);
         DWORD len;
Signature · 1 line
2.24.1.windows.2
#32 lore raw

PATCH v2 7/7 tun.c: reword the at_least_one_tap_win() error

In reply to Lev Stipakov
---
 src/openvpn/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/tun.c +1 -1
index 6762402c..4e16f989 100644
@@ -4031,7 +4031,7 @@ at_least_one_tap_win(const struct tap_reg *tap_reg)
 {
     if (!tap_reg)
     {
-        msg(M_FATAL, "There are no TAP-Windows adapters on this system.  You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter.");
+        msg(M_FATAL, "There are no TAP-Windows nor Wintun adapters on this system.  You should be able to create an adapter by using tapctl.exe utility.");
     }
 }
 
Signature · 1 line
2.24.1.windows.2
Acked-by on v2 1/7
#37 lore raw
In reply to Simon Rozman

Compared with v1, only changes are (suggested) function names.

Compiled with MSVC.

pe 20. jouluk. 2019 klo 18.14 Simon Rozman ([email protected]...) kirjoitti:

Quoted 135 lines

Since the introduction of Wintun, not all network devices in Windows are TAP-Windows6. Rather than returning a simple true/false answer, a couple of functions were reworked to return a corresponding struct tap_reg * or NULL instead.

As it would make the code tr = is_tap_win(...) a bit awkward those functions (both static) were renamed to better reflect their nature.

---
 src/openvpn/tun.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
src/openvpn/tun.c +5 -5
index ad497a71..0d6f40fe 100644
@@ -3976,10 +3976,10 @@ show_tap_win_adapters(int msglev, int warnlev)
 }
 
 /*
- * Confirm that GUID is a TAP-Windows adapter.
+ * Lookup a TAP-Windows or Wintun adapter by GUID.
  */
-static bool
-is_tap_win(const char *guid, const struct tap_reg *tap_reg)
+static const struct tap_reg *
+get_adapter_by_guid(const char *guid, const struct tap_reg *tap_reg)
 {
     const struct tap_reg *tr;
 
@@ -3987,11 +3987,11 @@ is_tap_win(const char *guid, const struct tap_reg
 *tap_reg)
     {
         if (guid && !strcmp(tr->guid, guid))
         {
-            return true;
+            return tr;
         }
     }
 
-    return false;
+    return NULL;
 }
 

static const char *

src/openvpn/tun.c +10 -8
@@ -4010,16 +4010,16 @@ guid_to_name(const char *guid, const struct
 panel_reg *panel_reg)
     return NULL;
 }
 
-static const char *
-name_to_guid(const char *name, const struct tap_reg *tap_reg, const
 struct panel_reg *panel_reg)
+static const struct tap_reg *
+get_adapter_by_name(const char *name, const struct tap_reg *tap_reg,
 const struct panel_reg *panel_reg)
 {
     const struct panel_reg *pr;
 
     for (pr = panel_reg; pr != NULL; pr = pr->next)
     {
-        if (name && !strcmp(pr->name, name) && is_tap_win(pr->guid,
 tap_reg))
+        if (name && !strcmp(pr->name, name))
         {
-            return pr->guid;
+            return get_adapter_by_guid(pr->guid, tap_reg);
         }
     }
@@ -4116,6 +4116,7 @@ get_device_guid(const char *name,
 {
     struct buffer ret = alloc_buf_gc(256, gc);
     struct buffer actual = clear_buf();
+    const struct tap_reg *tr;
 
     /* Make sure we have at least one TAP adapter */
     if (!tap_reg)
@@ -4131,7 +4132,8 @@ get_device_guid(const char *name,
     }
 
     /* Check if GUID was explicitly specified as --dev-node parameter */
-    if (is_tap_win(name, tap_reg))
+    tr = get_adapter_by_guid(name, tap_reg);
+    if (tr)
     {
         const char *act = guid_to_name(name, panel_reg);
         buf_printf(&ret, "%s", name);
@@ -4148,11 +4150,11 @@ get_device_guid(const char *name,
 
     /* Lookup TAP adapter in network connections list */
     {
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        if (guid)
+        tr = get_adapter_by_name(name, tap_reg, panel_reg);
+        if (tr)
         {
             buf_printf(&actual, "%s", name);
-            buf_printf(&ret, "%s", guid);
+            buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
     }
@@ -4696,11 +4698,14 @@ get_adapter_index_flexible(const char *name)  /*

actual name or GUID */

     {
         const struct tap_reg *tap_reg = get_tap_reg(&gc);
         const struct panel_reg *panel_reg = get_panel_reg(&gc);
src/openvpn/tun.c +1 -3
-        const char *guid = name_to_guid(name, tap_reg, panel_reg);
-        index = get_adapter_index_method_1(guid);
-        if (index == TUN_ADAPTER_INDEX_INVALID)
+        const struct tap_reg *tr = get_adapter_by_name(name, tap_reg,

panel_reg);

src/openvpn/tun.c +6 -2
+        if (tr)
         {
-            index = get_adapter_index_method_2(guid);
+            index = get_adapter_index_method_1(tr->guid);
+            if (index == TUN_ADAPTER_INDEX_INVALID)
+            {
+                index = get_adapter_index_method_2(tr->guid);
+            }
         }
     }
     if (index == TUN_ADAPTER_INDEX_INVALID)
--

2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
Acked-by on v2 2/7
#4 lore raw

Re: [Openvpn-devel] [PATCH v2 2/7] tun.c: upgrade get_device_guid() to return the Windows driver type

In reply to Simon Rozman

Compared with v1, difference is updated function comment.

Compiled with MSVC.

pe 20. jouluk. 2019 klo 18.14 Simon Rozman ([email protected]...) kirjoitti:

Quoted 94 lines
---
 src/openvpn/tun.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
src/openvpn/tun.c +2 -1
index 0d6f40fe..f90f201d 100644
@@ -4104,12 +4104,13 @@ get_unspecified_device_guid(const int
 device_number,
 
 /*
  * Lookup a --dev-node adapter name in the registry
- * returning the GUID and optional actual_name.
+ * returning the GUID and optional actual_name and device type
  */
 static const char *
 get_device_guid(const char *name,
                 char *actual_name,
                 int actual_name_size,
+                bool *wintun,
                 const struct tap_reg *tap_reg,
                 const struct panel_reg *panel_reg,

struct gc_arena *gc)

src/openvpn/tun.c +9 -1
@@ -4145,6 +4146,10 @@ get_device_guid(const char *name,
         {
             buf_printf(&actual, "%s", name);
         }
+        if (wintun)
+        {
+            *wintun = tr->wintun;
+        }
         return BSTR(&ret);
     }
 
@@ -4154,6 +4159,10 @@ get_device_guid(const char *name,
         if (tr)
         {
             buf_printf(&actual, "%s", name);
+            if (wintun)
+            {
+                *wintun = tr->wintun;
+            }
             buf_printf(&ret, "%s", tr->guid);
             return BSTR(&ret);
         }
@@ -4838,7 +4847,7 @@ tap_allow_nonadmin_access(const char *dev_node)
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node.
 */
-        device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
         if (!device_guid)
         {
src/openvpn/tun.c +1 -1
@@ -5412,7 +5421,7 @@ netsh_get_id(const char *dev_node, struct gc_arena
 *gc)
 
     if (dev_node)
     {
-        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual),
 tap_reg, panel_reg, gc);
+        guid = get_device_guid(dev_node, BPTR(&actual), BCAP(&actual),
 NULL, tap_reg, panel_reg, gc);
     }
     else
     {
src/openvpn/tun.c +1 -1
@@ -6132,7 +6141,7 @@ tun_open_device(struct tuntap *tt, const char
 *dev_node, const char **device_gui
     if (dev_node)
     {
         /* Get the device GUID for the device specified with --dev-node.
 */
-        *device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer,

sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);

         if (!*device_guid)
         {

--
2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
Acked-by on v2 3/7
#9 lore raw

Re: [Openvpn-devel] [PATCH v2 3/7] tun.c: make wintun_register_ring_buffer() non-fatal on failures

In reply to Simon Rozman

No changes since v1.

pe 20. jouluk. 2019 klo 18.14 Simon Rozman ([email protected]...) kirjoitti:

Quoted 132 lines

Wintun allows multiple handles to be opened on it's NDIS device pipe. Just by succeeding to open the pipe does not warrant the adapter is unused.

When iterating for available Wintun adapter, we will need to try registering ring buffers with each one to actually determine which one is used and which one is not.

Therefore, a failure to register ring buffers should be detectable, but not M_FATAL.

---
 src/openvpn/tun.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
src/openvpn/tun.c +6 -4
index f90f201d..c6bbbd41 100644
@@ -5647,11 +5647,12 @@ register_dns_service(const struct tuntap *tt)
     gc_free(&gc);
 }
 
-static void
+static bool
 service_register_ring_buffers(const struct tuntap *tt)
 {
     HANDLE msg_channel = tt->options.msg_channel;
     ack_message_t ack;
+    bool ret = true;
     struct gc_arena gc = gc_new();
 
     register_ring_buffers_message_t msg = {
@@ -5669,13 +5670,13 @@ service_register_ring_buffers(const struct tuntap
 *tt)
 
     if (!send_msg_iservice(msg_channel, &msg, sizeof(msg), &ack,
 "Register ring buffers"))
     {
-        gc_free(&gc);
-        return;
+        ret = false;
     }
     else if (ack.error_number != NO_ERROR)
     {
-        msg(M_FATAL, "Register ring buffers failed using service: %s
 [status=0x%x]",
+        msg(M_NONFATAL, "Register ring buffers failed using service: %s
 [status=0x%x]",
             strerror_win32(ack.error_number, &gc), ack.error_number);
+        ret = false;
     }
     else
     {
@@ -5683,6 +5684,7 @@ service_register_ring_buffers(const struct tuntap
 *tt)
     }
 
     gc_free(&gc);
+    return ret;
 }
 

void

src/openvpn/tun.c +3 -1
@@ -5922,9 +5924,11 @@ tuntap_set_ip_addr(struct tuntap *tt,
     gc_free(&gc);
 }
 
-static void
+static bool
 wintun_register_ring_buffer(struct tuntap *tt)
 {
+    bool ret = true;
+
     tt->wintun_send_ring = (struct tun_ring
 *)MapViewOfFile(tt->wintun_send_ring_handle,
 

FILE_MAP_ALL_ACCESS,

                                                             0,
src/openvpn/tun.c +5 -2
@@ -5939,7 +5943,7 @@ wintun_register_ring_buffer(struct tuntap *tt)
 
     if (tt->options.msg_channel)
     {
-        service_register_ring_buffers(tt);
+        ret = service_register_ring_buffers(tt);
     }
     else
     {
@@ -5953,13 +5957,16 @@ wintun_register_ring_buffer(struct tuntap *tt)
             tt->rw_handle.read,
             tt->rw_handle.write))
         {
-            msg(M_FATAL, "ERROR:  Failed to register ring buffers: %lu",
 GetLastError());
+            msg(M_NONFATAL, "Failed to register ring buffers: %lu",
 GetLastError());
+            ret = false;
         }
         if (!RevertToSelf())
         {
             msg(M_FATAL, "ERROR:  RevertToSelf error: %lu",
 GetLastError());
         }
     }
+
+    return ret;

}

static void

src/openvpn/tun.c +0 -0
@@ -6367,7 +6374,10 @@ open_tun(const char *dev, const char *dev_type,

const char *dev_node, struct tun

     if (tt->wintun)
     {
src/openvpn/tun.c +4 -2
-        wintun_register_ring_buffer(tt);
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(M_FATAL, "Failed to register ring buffers");
+        }
     }
     else
     {
--

2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
#14 lore raw

Re: [Openvpn-devel] [PATCH v2 4/7] wintun: register ring buffers when iterating adapters

In reply to Simon Rozman

Hi,

+ /* Wintun adapter may be considered "open" after ring buffers are

src/openvpn/tun.c tuntap_dhcp_mask(const struct tuntap *tt, const char *device_guid) · line 6184

Quoted 4 lines

successfuly registered. */

src/openvpn/tun.c +2 -0
+        if (!wintun_register_ring_buffer(tt))
+        {

Here we pass incorrect handle to wintun_register_ring_buffer - tt->hand is 0 at that point,
since CreateFile value was assigned to h.

Signature · 1 line
-Lev
#15 lore raw

PATCH v3 4/7 wintun: register ring buffers when iterating adapters

Wintun adapters may be considered available if ring buffer registration succeeded. Therefore, we must attempt to register ring buffers when iterating adapters and continue on failure.

---
 src/openvpn/tun.c | 111 +++++++++++++++++++++++++++-------------------
 1 file changed, 65 insertions(+), 46 deletions(-)
src/openvpn/tun.c +65 -46
index c6bbbd41..aef2c7f8 100644
@@ -6129,11 +6129,72 @@ tuntap_dhcp_mask(const struct tuntap *tt, const char *device_guid)
     gc_free(&gc);
 }
 
+static bool
+tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct device_instance_id_interface *device_instance_id_interface)
+{
+    const char *path = NULL;
+    char tuntap_device_path[256];
+
+    if (tt->wintun)
+    {
+        const struct device_instance_id_interface *dev_if;
+
+        /* Open Wintun adapter */
+        for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next)
+        {
+            if (strcmp(dev_if->net_cfg_instance_id, device_guid) == 0)
+            {
+                path = dev_if->device_interface_list;
+                break;
+            }
+        }
+        if (path == NULL)
+        {
+            return false;
+        }
+    }
+    else
+    {
+        /* Open TAP-Windows adapter */
+        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
+                            USERMODEDEVICEDIR,
+                            device_guid,
+                            TAP_WIN_SUFFIX);
+        path = tuntap_device_path;
+    }
+
+    tt->hand = CreateFile(path,
+                   GENERIC_READ | GENERIC_WRITE,
+                   0,                /* was: FILE_SHARE_READ */
+                   0,
+                   OPEN_EXISTING,
+                   FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
+                   0);
+    if (tt->hand == INVALID_HANDLE_VALUE)
+    {
+        msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "Wintun" : "TAP-Windows", path);
+        return false;
+    }
+
+    if (tt->wintun)
+    {
+        /* Wintun adapter may be considered "open" after ring buffers are successfuly registered. */
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(D_TUNTAP_INFO, "Failed to register %s adapter ring buffers", device_guid);
+            CloseHandle(tt->hand);
+            tt->hand = NULL;
+            return false;
+        }
+    }
+
+    return true;
+}
+
 static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid)
 {
     struct gc_arena gc = gc_new();
-    char *path = NULL;
     char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);
@@ -6197,27 +6258,11 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
 
             if (tt->wintun)
             {
-                const struct device_instance_id_interface* dev_if;
-
                 if (!is_picked_device_wintun)
                 {
                     /* wintun driver specified but picked adapter is not wintun, proceed to next one */
                     goto next;
                 }
-
-                path = NULL;
-                for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next)
-                {
-                    if (strcmp(dev_if->net_cfg_instance_id, *device_guid) == 0)
-                    {
-                        path = (char*)dev_if->device_interface_list;
-                        break;
-                    }
-                }
-                if (path == NULL)
-                {
-                    goto next;
-                }
             }
             else
             {
@@ -6226,28 +6271,9 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
                     /* tap-windows6 driver specified but picked adapter is wintun, proceed to next one */
                     goto next;
                 }
-
-                /* Open Windows TAP-Windows adapter */
-                openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s",
-                                 USERMODEDEVICEDIR,
-                                 *device_guid,
-                                 TAP_WIN_SUFFIX);
-                path = tuntap_device_path;
             }
 
-            tt->hand = CreateFile(path,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  0,                /* was: FILE_SHARE_READ */
-                                  0,
-                                  OPEN_EXISTING,
-                                  FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
-                                  0);
-
-            if (tt->hand == INVALID_HANDLE_VALUE)
-            {
-                msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "wintun" : "TAP", tuntap_device_path);
-            }
-            else
+            if (tun_try_open_device(tt, *device_guid, device_instance_id_interface))
             {
                 break;
             }
@@ -6261,7 +6287,7 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui
      * GUID using the registry */
     tt->actual_name = string_alloc(actual_buffer, NULL);
 
-    msg(M_INFO, "%s device [%s] opened: %s", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name, path);
+    msg(M_INFO, "%s device [%s] opened", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name);
     tt->adapter_index = get_adapter_index(*device_guid);
 
     gc_free(&gc);
@@ -6372,14 +6398,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 
     tun_open_device(tt, dev_node, &device_guid);
 
-    if (tt->wintun)
-    {
-        if (!wintun_register_ring_buffer(tt))
-        {
-            msg(M_FATAL, "Failed to register ring buffers");
-        }
-    }
-    else
+    if (!tt->wintun)
     {
         tuntap_post_open(tt, device_guid);
     }
Signature · 3 lines
2.24.1.windows.2

Argh, I had --windows-driver accidentially left on TAP-Windows6 when testing v2 patchset. :(
Acked-by on v3 4/7
#16 lore raw

Re: [Openvpn-devel] [PATCH v3 4/7] wintun: register ring buffers when iterating adapters

Compiled, tested.

PS

When you send v2 etc, could you add changelog to git mail after "---" line.

See https://patchwork.openvpn.net/patch/388/ as an example:

---

Changes from v2:
- patchset rebased on top of pre-ipv6-only patchset
- change commit subject/message
- move ifconfig-ipv6-pool check change into 4/8

src/openvpn/helper.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/openvpn/helper.c b/src/openvpn/helper.c

pe 20. jouluk. 2019 klo 21.39 Simon Rozman ([email protected]...) kirjoitti:

Quoted 205 lines

Wintun adapters may be considered available if ring buffer registration succeeded. Therefore, we must attempt to register ring buffers when iterating adapters and continue on failure.

---
 src/openvpn/tun.c | 111 +++++++++++++++++++++++++++-------------------
 1 file changed, 65 insertions(+), 46 deletions(-)
src/openvpn/tun.c +50 -0
index c6bbbd41..aef2c7f8 100644
@@ -6129,11 +6129,72 @@ tuntap_dhcp_mask(const struct tuntap *tt, const
 char *device_guid)
     gc_free(&gc);
 }
 
+static bool
+tun_try_open_device(struct tuntap *tt, const char *device_guid, const
 struct device_instance_id_interface *device_instance_id_interface)
+{
+    const char *path = NULL;
+    char tuntap_device_path[256];
+
+    if (tt->wintun)
+    {
+        const struct device_instance_id_interface *dev_if;
+
+        /* Open Wintun adapter */
+        for (dev_if = device_instance_id_interface; dev_if != NULL;
 dev_if = dev_if->next)
+        {
+            if (strcmp(dev_if->net_cfg_instance_id, device_guid) == 0)
+            {
+                path = dev_if->device_interface_list;
+                break;
+            }
+        }
+        if (path == NULL)
+        {
+            return false;
+        }
+    }
+    else
+    {
+        /* Open TAP-Windows adapter */
+        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path),
 "%s%s%s",
+                            USERMODEDEVICEDIR,
+                            device_guid,
+                            TAP_WIN_SUFFIX);
+        path = tuntap_device_path;
+    }
+
+    tt->hand = CreateFile(path,
+                   GENERIC_READ | GENERIC_WRITE,
+                   0,                /* was: FILE_SHARE_READ */
+                   0,
+                   OPEN_EXISTING,
+                   FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
+                   0);
+    if (tt->hand == INVALID_HANDLE_VALUE)
+    {
+        msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s",
 tt->wintun ? "Wintun" : "TAP-Windows", path);
+        return false;
+    }
+
+    if (tt->wintun)
+    {
+        /* Wintun adapter may be considered "open" after ring buffers are

successfuly registered. */

src/openvpn/tun.c +3 -0
+        if (!wintun_register_ring_buffer(tt))
+        {
+            msg(D_TUNTAP_INFO, "Failed to register %s adapter ring

buffers", device_guid);

src/openvpn/tun.c +9 -0
+            CloseHandle(tt->hand);
+            tt->hand = NULL;
+            return false;
+        }
+    }
+
+    return true;
+}
+
 static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char

**device_guid)

 {
     struct gc_arena gc = gc_new();
src/openvpn/tun.c +0 -3
-    char *path = NULL;
     char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);
@@ -6197,27 +6258,11 @@ tun_open_device(struct tuntap *tt, const char
 *dev_node, const char **device_gui
 
             if (tt->wintun)
             {
-                const struct device_instance_id_interface* dev_if;
-
                 if (!is_picked_device_wintun)
                 {
                     /* wintun driver specified but picked adapter is not

wintun, proceed to next one */

                     goto next;
                 }
src/openvpn/tun.c +0 -3
-
-                path = NULL;
-                for (dev_if = device_instance_id_interface; dev_if !=

NULL; dev_if = dev_if->next)

src/openvpn/tun.c +0 -2
-                {
-                    if (strcmp(dev_if->net_cfg_instance_id, *device_guid)

== 0)

src/openvpn/tun.c +0 -9
-                    {
-                        path = (char*)dev_if->device_interface_list;
-                        break;
-                    }
-                }
-                if (path == NULL)
-                {
-                    goto next;
-                }
             }
             else
             {
@@ -6226,28 +6271,9 @@ tun_open_device(struct tuntap *tt, const char
 *dev_node, const char **device_gui
                     /* tap-windows6 driver specified but picked adapter

is wintun, proceed to next one */

                     goto next;
                 }
src/openvpn/tun.c +0 -3
-
-                /* Open Windows TAP-Windows adapter */
-                openvpn_snprintf(tuntap_device_path,

sizeof(tuntap_device_path), "%s%s%s",

src/openvpn/tun.c +0 -7
-                                 USERMODEDEVICEDIR,
-                                 *device_guid,
-                                 TAP_WIN_SUFFIX);
-                path = tuntap_device_path;
             }
 
-            tt->hand = CreateFile(path,
-                                  GENERIC_READ | GENERIC_WRITE,
-                                  0,                /* was:

FILE_SHARE_READ */

src/openvpn/tun.c +0 -3
-                                  0,
-                                  OPEN_EXISTING,
-                                  FILE_ATTRIBUTE_SYSTEM |

FILE_FLAG_OVERLAPPED,

src/openvpn/tun.c +0 -5
-                                  0);
-
-            if (tt->hand == INVALID_HANDLE_VALUE)
-            {
-                msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s",

tt->wintun ? "wintun" : "TAP", tuntap_device_path);

src/openvpn/tun.c +1 -2
-            }
-            else
+            if (tun_try_open_device(tt, *device_guid,

device_instance_id_interface))

             {
                 break;
             }
src/openvpn/tun.c +1 -1
@@ -6261,7 +6287,7 @@ tun_open_device(struct tuntap *tt, const char
 *dev_node, const char **device_gui
      * GUID using the registry */
     tt->actual_name = string_alloc(actual_buffer, NULL);
 
-    msg(M_INFO, "%s device [%s] opened: %s", tt->wintun ? "Wintun" :
 "TAP-WIN32", tt->actual_name, path);
+    msg(M_INFO, "%s device [%s] opened", tt->wintun ? "Wintun" :
 "TAP-WIN32", tt->actual_name);
     tt->adapter_index = get_adapter_index(*device_guid);

     gc_free(&gc);
src/openvpn/tun.c +0 -0
@@ -6372,14 +6398,7 @@ open_tun(const char *dev, const char *dev_type,

const char *dev_node, struct tun

     tun_open_device(tt, dev_node, &device_guid);
src/openvpn/tun.c +1 -9
-    if (tt->wintun)
-    {
-        if (!wintun_register_ring_buffer(tt))
-        {
-            msg(M_FATAL, "Failed to register ring buffers");
-        }
-    }
-    else
+    if (!tt->wintun)
     {
         tuntap_post_open(tt, device_guid);
     }
--

2.24.1.windows.2

Argh, I had --windows-driver accidentially left on TAP-Windows6 when testing v2 patchset. :(

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
Acked-by on v2 5/7
#21 lore raw

Re: [Openvpn-devel] [PATCH v2 5/7] wintun: add support for --dev-node

In reply to Simon Rozman

Compared with v1 - the difference is more helpful error message.

Compiled, tested.

pe 20. jouluk. 2019 klo 18.14 Simon Rozman ([email protected]...) kirjoitti:

Quoted 94 lines
---
 src/openvpn/tun.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
src/openvpn/tun.c +0 -1
index f56682ef..18f06bb6 100644
@@ -6196,7 +6196,6 @@ static void
 tun_open_device(struct tuntap *tt, const char *dev_node, const char
 **device_guid)
 {
     struct gc_arena gc = gc_new();
-    char tuntap_device_path[256];
     const struct tap_reg* tap_reg = get_tap_reg(&gc);
     const struct panel_reg* panel_reg = get_panel_reg(&gc);

const struct device_instance_id_interface*
device_instance_id_interface = get_device_instance_id_interface(&gc);

src/openvpn/tun.c +9 -15
@@ -6209,31 +6208,34 @@ tun_open_device(struct tuntap *tt, const char
 *dev_node, const char **device_gui
      */
     if (dev_node)
     {
+        bool is_picked_device_wintun = false;
+
         /* Get the device GUID for the device specified with --dev-node.
 */
-        *device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), NULL, tap_reg, panel_reg, &gc);
+        *device_guid = get_device_guid(dev_node, actual_buffer,
 sizeof(actual_buffer), &is_picked_device_wintun, tap_reg, panel_reg, &gc);
 
         if (!*device_guid)
         {
-            msg(M_FATAL, "TAP-Windows adapter '%s' not found", dev_node);
+            msg(M_FATAL, "Adapter '%s' not found", dev_node);
         }
 
-        /* Open Windows TAP-Windows adapter */
-        openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path),
 "%s%s%s",
-                         USERMODEDEVICEDIR,
-                         *device_guid,
-                         TAP_WIN_SUFFIX);
-
-        tt->hand = CreateFile(tuntap_device_path,
-                              GENERIC_READ | GENERIC_WRITE,
-                              0,                /* was: FILE_SHARE_READ */
-                              0,
-                              OPEN_EXISTING,
-                              FILE_ATTRIBUTE_SYSTEM |
 FILE_FLAG_OVERLAPPED,
-                              0);
+        if (tt->wintun)
+        {
+            if (!is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is TAP-Windows, Wintun
 expected. If you want to use this device, remove --windows-driver wintun.",

dev_node);

src/openvpn/tun.c +7 -0
+            }
+        }
+        else
+        {
+            if (is_picked_device_wintun)
+            {
+                msg(M_FATAL, "Adapter '%s' is Wintun, TAP-Windows

expected. If you want to use this device, add --windows-driver wintun.", dev_node);

src/openvpn/tun.c +3 -1
+            }
+        }
 
-        if (tt->hand == INVALID_HANDLE_VALUE)
+        if (!tun_try_open_device(tt, *device_guid,

device_instance_id_interface))

         {
-            msg(M_ERR, "CreateFile failed on TAP device: %s",
tuntap_device_path);
+            msg(M_FATAL, "Failed to open %s adapter: %s", tt->wintun ?
"Wintun" : "TAP-Windows", dev_node);
         }
     }
     else

--
2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
#26 lore raw

Re: [Openvpn-devel] [PATCH v2 6/7] wintun: stop sending TAP-Windows6 ioctls to NDIS device

In reply to Simon Rozman

Hi,

Sorry for not mentioning it earlier.

There is already check in forward.c:

    if (tuntap_defined(c->c1.tuntap))
    {
        tun_show_debug(c->c1.tuntap);
    }

Same goes for tap_win_getinfo in sig.c:

    if (tuntap_defined(c->c1.tuntap))
    {
        status_printf(so, "TAP-WIN32 driver status,\"%s\"",
                      tap_win_getinfo(c->c1.tuntap, &gc));
    }

There is one place where that check is missing, error.c:

    #elif defined(_WIN32)
        /* get possible driver error from TAP-Windows driver */
        extended_msg = tap_win_getinfo(tt, &gc);
    #endif

There is no need to call tuntap_defined() twice, so either we remove it from calling code or from tun_* methods.
For the sake of consistency I propose to add it to error.c and remove from tun_* methods, which would just check for !tt->wintun.

Signature · 1 line
-Lev
Acked-by on v2 7/7
#33 lore raw

Re: [Openvpn-devel] [PATCH v2 7/7] tun.c: reword the at_least_one_tap_win() error

In reply to Simon Rozman

No changed from v1.

Compiled on MSVC.

pe 20. jouluk. 2019 klo 18.15 Simon Rozman ([email protected]...) kirjoitti:

Quoted 33 lines
---
 src/openvpn/tun.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/tun.c +0 -1
index 6762402c..4e16f989 100644
@@ -4031,7 +4031,7 @@ at_least_one_tap_win(const struct tap_reg *tap_reg)
 {
     if (!tap_reg)
     {
-        msg(M_FATAL, "There are no TAP-Windows adapters on this system.

You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter.");
+ msg(M_FATAL, "There are no TAP-Windows nor Wintun adapters on
this system. You should be able to create an adapter by using tapctl.exe

utility.");
     }

}

--
2.24.1.windows.2

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
-Lev
#38 lore raw
In reply to Simon Rozman

Your patch has been applied to the master branch.

Lev: if there is a whole new v2 series, it would be good to have a bit more verbose ACKs on the v2 patches than just "it's nearly the same as v1, so ACK" - if you haven't read the v1 thread (because "oh, a v2 is coming, so I can wait") this means you actually have to go back if you're interested...

Compile tested on Ubuntu 1604 and lightly stared at code.

commit be78706830f02b095392ff063c9490da27b6faa1

Author: Simon Rozman
Date:   Fri Dec 20 17:11:11 2019 +0100
     tun.c: make Windows device lookup functions more general

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19280.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw

[Openvpn-devel] [PATCH applied] Re: tun.c: upgrade get_device_guid() to return the Windows driver type

In reply to Simon Rozman

Your patch has been applied to the master branch.

Compile tested on Ubuntu 1604 and stared at code.

As a side note: the granularity of this one is a bit too fine-grained for my taste - it changes the function, but none of the callers make use of it, so it's somewhat of a no-op and hard to test.

commit 9db385f2d179bbc578112e7526b51d424a62aac5

Author: Simon Rozman
Date:   Fri Dec 20 17:11:12 2019 +0100
     tun.c: upgrade get_device_guid() to return the Windows driver type

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19277.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#10 lore raw

[Openvpn-devel] [PATCH applied] Re: tun.c: make wintun_register_ring_buffer() non-fatal on failures

In reply to Simon Rozman

Your patch has been applied to the master branch.

Compile-tested on Ubuntu1604, stared a bit at the code.

commit 9a8966c2cbe796a51aa971e83850a2de8f4531ec

Author: Simon Rozman
Date:   Fri Dec 20 17:11:13 2019 +0100
     tun.c: make wintun_register_ring_buffer() non-fatal on failures

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19283.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#17 lore raw

[Openvpn-devel] [PATCH applied] Re: wintun: register ring buffers when iterating adapters

In reply to Simon Rozman

Your patch has been applied to the master branch.

Compile tested on Ubuntu 1604/mingw. Lightly stared at the code.

Explanation makes sense (but I have not looked hard enough to see if it actually does what it says :) ).

commit c1a555585c90aa26390ef2f50cadd479b47541f2

Author: Simon Rozman
Date:   Fri Dec 20 20:38:05 2019 +0100
     wintun: register ring buffers when iterating adapters

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19288.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#22 lore raw

[Openvpn-devel] [PATCH applied] Re: wintun: add support for --dev-node

In reply to Simon Rozman

Your patch has been applied to the master branch.

Compile-tested on Ubuntu 1604/mingw, stared a bit at the code, seems to make sense :-)

(I do wonder if it makes sense to just use the driver we found if --dev-mode was specified, and auto-sense whether this should be handled as tap6 or wintun - after all, if one option is specifying exactly what the user wants, why require a second option to be set to something we can infer? But that's fine tuning for special cases)

commit d7142c7d883602c6083f65037a52fa1a9df10861

Author: Simon Rozman
Date:   Fri Dec 20 17:11:15 2019 +0100
     wintun: add support for --dev-node

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19282.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#34 lore raw

[Openvpn-devel] [PATCH applied] Re: tun.c: reword the at_least_one_tap_win() error

In reply to Simon Rozman

Your patch has been applied to the master branch.

"Not even compile tested" :-) - but it has enough quotes and the new msg() obviously makes sense.

commit eebce22bd18254fd14a1e6dc048b8bac26bef0e2

Author: Simon Rozman
Date:   Fri Dec 20 17:11:17 2019 +0100
     tun.c: reword the at_least_one_tap_win() error

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19278.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#27 lore raw

PATCH v3 6/7 wintun: stop sending TAP-Windows6 ioctls to NDIS device

In reply to Lev Stipakov

Wintun doesn't have its own I/O device. Rather, it taps on existing Windows-provided NDIS device. Sending TAP-Windows6 IOCTL requests to it is risky, as TAP-Windows6 is using one of the well-known device types (FILE_DEVICE_UNKNOWN) with function IDs as 1, 2, 3 etc. raising a chance of collision as NDIS might react to one of these IOCTLs.

---
 src/openvpn/error.c | 5 ++++-
 src/openvpn/sig.c   | 7 +++++--
 src/openvpn/tun.c   | 4 ++--
 3 files changed, 11 insertions(+), 5 deletions(-)
src/openvpn/error.c +4 -1
index b2492f2b..ad4f0ef4 100644
@@ -688,7 +688,10 @@ x_check_status(int status,
         }
 #elif defined(_WIN32)
         /* get possible driver error from TAP-Windows driver */
-        extended_msg = tap_win_getinfo(tt, &gc);
+        if (tuntap_defined(tt))
+        {
+            extended_msg = tap_win_getinfo(tt, &gc);
+        }
 #endif
         if (!ignore_sys_error(my_errno))
         {
src/openvpn/sig.c +5 -2
index d7f2abb8..6e3379fe 100644
@@ -317,8 +317,11 @@ print_status(const struct context *c, struct status_output *so)
 #ifdef _WIN32
     if (tuntap_defined(c->c1.tuntap))
     {
-        status_printf(so, "TAP-WIN32 driver status,\"%s\"",
-                      tap_win_getinfo(c->c1.tuntap, &gc));
+        const char *extended_msg = tap_win_getinfo(c->c1.tuntap, &gc);
+        if (extended_msg)
+        {
+            status_printf(so, "TAP-WIN32 driver status,\"%s\"", extended_msg);
+        }
     }
 #endif
 
src/openvpn/tun.c +2 -2
index 30fb78b2..e36c49b1 100644
@@ -6411,7 +6411,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
 const char *
 tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
 {
-    if (tt && tt->hand != NULL)
+    if (!tt->wintun)
     {
         struct buffer out = alloc_buf_gc(256, gc);
         DWORD len;
@@ -6429,7 +6429,7 @@ tap_win_getinfo(const struct tuntap *tt, struct gc_arena *gc)
 void
 tun_show_debug(struct tuntap *tt)
 {
-    if (tt && tt->hand != NULL)
+    if (!tt->wintun)
     {
         struct buffer out = alloc_buf(1024);
         DWORD len;
Signature · 4 lines
2.24.1.windows.2

v3 changes:
* tuntap_defined() checks revised according to Lev's recommendations
#29 lore raw

[Openvpn-devel] [PATCH applied] Re: wintun: stop sending TAP-Windows6 ioctls to NDIS device

In reply to Simon Rozman

Your patch has been applied to the master branch.

Test compiled, and stared at the code a bit, seems to make sense :)

commit 948b4f938a02dee78fb5246bcd44bc0162619b2d

Author: Simon Rozman
Date:   Wed Jan 8 12:52:24 2020 +0100
     wintun: stop sending TAP-Windows6 ioctls to NDIS device

     Signed-off-by: Simon Rozman <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg19309.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering