]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Attempt to configure interface wintun
authorDavid Woodhouse <dwmw2@infradead.org>
Tue, 30 Mar 2021 22:23:29 +0000 (23:23 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Tue, 30 Mar 2021 22:23:29 +0000 (23:23 +0100)
vpnc-script-win.js seems to wait until the Legacy IP address of the
interface appears in 'route print' output. How that'll work in the
21st century when there's only IPv6 and no Legacy IP, I have no
idea. But set it for now like the old TAP driver did, and see if
we can make it work...

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
wintun.c

index 54d01f314aa57e6c7ee1a9ddcf7eca00717664e9..4fee4bc34e1394c37666e2d3504a368261bd27e4 100644 (file)
--- a/wintun.c
+++ b/wintun.c
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <winioctl.h>
+#include <winsock2.h>
+#include <ws2ipdef.h>
 #include <iphlpapi.h>
+#include <netioapi.h>
 
 #include <errno.h>
 #include <stdio.h>
@@ -135,6 +138,18 @@ intptr_t open_wintun(struct openconnect_info *vpninfo, char *guid, wchar_t *wnam
                }
        }
 
+       MIB_UNICASTIPADDRESS_ROW AddressRow;
+       InitializeUnicastIpAddressEntry(&AddressRow);
+       WintunGetAdapterLUID(vpninfo->wintun_adapter, &AddressRow.InterfaceLuid);
+       AddressRow.Address.Ipv4.sin_family = AF_INET;
+       AddressRow.Address.Ipv4.sin_addr.S_un.S_addr = htonl(inet_addr(vpninfo->ip_info.addr));
+       AddressRow.OnLinkPrefixLength = 32; /* This is a /24 network */
+       DWORD LastError = CreateUnicastIpAddressEntry(&AddressRow);
+       if (LastError != ERROR_SUCCESS && LastError != ERROR_OBJECT_ALREADY_EXISTS) {
+               vpn_progress(vpninfo, PRG_ERR, _("Failed to set Legacy IP address on Wintun\n"));
+       }
+       vpn_progress(vpninfo, PRG_INFO, "Set Legacy IP address %s (%x)\n", vpninfo->ip_info.addr, AddressRow.Address.Ipv4.sin_addr.S_un.S_addr);
+
        vpninfo->wintun_session = WintunStartSession(vpninfo->wintun_adapter, 0x400000);
        if (!vpninfo->wintun_session) {
                char *errstr = openconnect__win32_strerror(GetLastError());
@@ -193,7 +208,8 @@ void os_shutdown_wintun(struct openconnect_info *vpninfo)
                vpninfo->wintun_session = NULL;
        }
        if (vpninfo->wintun_adapter) {
-               WintunFreeAdapter(vpninfo->wintun_adapter);
+               BOOL rr;
+               WintunDeleteAdapter(vpninfo->wintun_adapter, FALSE, &rr);
                vpninfo->wintun_adapter = NULL;
        }
        logger_vpninfo = NULL;
@@ -205,6 +221,6 @@ int setup_wintun_fd(struct openconnect_info *vpninfo, intptr_t tun_fd)
 {
        vpninfo->tun_rd_overlap.hEvent = WintunGetReadWaitEvent(vpninfo->wintun_session);
        monitor_read_fd(vpninfo, tun);
-       vpninfo->tun_fh = 1;
+       vpninfo->tun_fh = (HANDLE)tun_fd;
        return 0;
 }