diff options
Diffstat (limited to 'src/openvpn/dco_win.c')
-rw-r--r-- | src/openvpn/dco_win.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index d0fe206..48a1755 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -42,7 +42,7 @@ const IN_ADDR in4addr_any = { 0 }; #endif -static struct tuntap +struct tuntap create_dco_handle(const char *devname, struct gc_arena *gc) { struct tuntap tt = { .windows_driver = WINDOWS_DRIVER_DCO }; @@ -104,7 +104,7 @@ dco_start_tun(struct tuntap *tt) dco_wait_ready(tt->adapter_index); } -static int +static void dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, volatile int *signal_received) { /* GetOverlappedResultEx is available starting from Windows 8 */ @@ -129,7 +129,7 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, volatile int *signa if (get_overlapped_result_ex(handle, ov, &transferred, poll_interval_ms, FALSE) != 0) { /* TCP connection established by dco */ - return 0; + return; } DWORD err = GetLastError(); @@ -138,13 +138,13 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, volatile int *signa /* dco reported connection error */ msg(M_NONFATAL | M_ERRNO, "dco connect error"); *signal_received = SIGUSR1; - return -1; + return; } get_signal(signal_received); if (*signal_received) { - return -1; + return; } management_sleep(0); @@ -153,14 +153,11 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, volatile int *signa /* we end up here when timeout occurs in userspace */ msg(M_NONFATAL, "dco connect timeout"); *signal_received = SIGUSR1; - - return -1; } -struct tuntap -dco_create_socket(struct addrinfo *remoteaddr, bool bind_local, - struct addrinfo *bind, const char *devname, - struct gc_arena *gc, int timeout, +void +dco_create_socket(HANDLE handle, struct addrinfo *remoteaddr, bool bind_local, + struct addrinfo *bind, int timeout, volatile int *signal_received) { msg(D_DCO_DEBUG, "%s", __func__); @@ -232,10 +229,8 @@ dco_create_socket(struct addrinfo *remoteaddr, bool bind_local, ASSERT(0); } - struct tuntap tt = create_dco_handle(devname, gc); - OVERLAPPED ov = { 0 }; - if (!DeviceIoControl(tt.hand, OVPN_IOCTL_NEW_PEER, &peer, sizeof(peer), NULL, 0, NULL, &ov)) + if (!DeviceIoControl(handle, OVPN_IOCTL_NEW_PEER, &peer, sizeof(peer), NULL, 0, NULL, &ov)) { DWORD err = GetLastError(); if (err != ERROR_IO_PENDING) @@ -244,13 +239,9 @@ dco_create_socket(struct addrinfo *remoteaddr, bool bind_local, } else { - if (dco_connect_wait(tt.hand, &ov, timeout, signal_received) < 0) - { - close_tun_handle(&tt); - } + dco_connect_wait(handle, &ov, timeout, signal_received); } } - return tt; } int @@ -265,7 +256,15 @@ dco_new_peer(dco_context_t *dco, unsigned int peerid, int sd, int dco_del_peer(dco_context_t *dco, unsigned int peerid) { - msg(D_DCO_DEBUG, "%s: peer-id %d - not implemented", __func__, peerid); + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peerid); + + DWORD bytes_returned = 0; + if (!DeviceIoControl(dco->tt->hand, OVPN_IOCTL_DEL_PEER, NULL, + 0, NULL, 0, &bytes_returned, NULL)) + { + msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_DEL_PEER) failed"); + return -1; + } return 0; } |