[PATCH] Toggle TAP status to force Windows to re-run NLA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Windows runs Network Location Awareness detection during the
connection process and sometimes fails because the connection script
hasn't had an opportunity to set up the connection enough for
detection to work properly. Toggling the media status after script
execution forces re-detection which then occurs successfully.

Signed-off-by: Kyle Johnson <KyleJ61782 at gmail.com>
---
 tun-win32.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 mode change 100644 => 100755 tun-win32.c

diff --git a/tun-win32.c b/tun-win32.c
old mode 100644
new mode 100755
index 9bc9881..704c10a
--- a/tun-win32.c
+++ b/tun-win32.c
@@ -284,6 +284,7 @@ static intptr_t open_tun(struct openconnect_info
*vpninfo, char *guid, char *nam
  free(errstr);
  return -1;
  }
+
  if (!vpninfo->ifname)
  vpninfo->ifname = strdup(name);

@@ -390,6 +391,24 @@ void os_shutdown_tun(struct openconnect_info *vpninfo)

 int openconnect_setup_tun_fd(struct openconnect_info *vpninfo, intptr_t tun_fd)
 {
+ ULONG data;
+ DWORD len;
+
+ /* Toggle media status so that network location awareness picks up
all the configuration
+    that occurred and properly assigns the network so the user can
adjust firewall
+    settings. */
+ for (data = 0; data <= 1; data++) {
+ if (!DeviceIoControl((HANDLE)tun_fd, TAP_IOCTL_SET_MEDIA_STATUS,
+ &data, sizeof(data), &data, sizeof(data), &len, NULL)) {
+ char *errstr = openconnect__win32_strerror(GetLastError());
+
+ vpn_progress(vpninfo, PRG_ERR,
+ _("Failed to set TAP media status: %s\n"), errstr);
+ free(errstr);
+ return -1;
+ }
+ }
+
  vpninfo->tun_fh = (HANDLE)tun_fd;
  vpninfo->tun_rd_overlap.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  monitor_read_fd(vpninfo, tun);
-- 
2.18.0



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux