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

2019-12-20 Thread Lev Stipakov
Compiled, tested.

Acked-by: Lev Stipakov 

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:

Signed-off-by: Antonio Quartulli 
---

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 (si...@rozman.si) kirjoitti:

> 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.
>
> Signed-off-by: Simon Rozman 
> ---
>  src/openvpn/tun.c | 111 +++---
>  1 file changed, 65 insertions(+), 46 deletions(-)
>
> diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
> index c6bbbd41..aef2c7f8 100644
> --- a/src/openvpn/tun.c
> +++ b/src/openvpn/tun.c
> @@ -6129,11 +6129,72 @@ tuntap_dhcp_mask(const struct tuntap *tt, const
> char *device_guid)
>  gc_free();
>  }
>
> +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();
>  const struct panel_reg* panel_reg = get_panel_reg();
> @@ -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;
>  }
> -
> -   

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

2019-12-20 Thread 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.

Signed-off-by: Simon Rozman 
---
 src/openvpn/tun.c | 111 +++---
 1 file changed, 65 insertions(+), 46 deletions(-)

diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index c6bbbd41..aef2c7f8 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -6129,11 +6129,72 @@ tuntap_dhcp_mask(const struct tuntap *tt, const char 
*device_guid)
 gc_free();
 }
 
+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();
 const struct panel_reg* panel_reg = get_panel_reg();
@@ -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