aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tunnel
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-25 00:25:04 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-25 00:25:04 +0200
commit0f4fbc18851b4375d09b97800d8f3360702f61b8 (patch)
tree7755004b762e05c7b58a9b20890c254f5544ab5d /tunnel
parentwinipcfg: switch to windows.GetAdaptersAddresses (diff)
downloadwireguard-windows-0f4fbc18851b4375d09b97800d8f3360702f61b8.tar.xz
wireguard-windows-0f4fbc18851b4375d09b97800d8f3360702f61b8.zip
winipcfg: SocketAddressToIP was upstreamed
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tunnel')
-rw-r--r--tunnel/ifaceconfig.go6
-rw-r--r--tunnel/winipcfg/luid.go2
-rw-r--r--tunnel/winipcfg/utils.go26
3 files changed, 4 insertions, 30 deletions
diff --git a/tunnel/ifaceconfig.go b/tunnel/ifaceconfig.go
index 917d0aab..fcf9dce3 100644
--- a/tunnel/ifaceconfig.go
+++ b/tunnel/ifaceconfig.go
@@ -47,11 +47,11 @@ func cleanupAddressesOnDisconnectedInterfaces(addresses []net.IPNet) {
continue
}
for address := iface.FirstUnicastAddress; address != nil; address = address.Next {
- ip := winipcfg.SocketAddressToIP(&address.Address)
+ ip := address.Address.IP()
ipnet := net.IPNet{IP: ip, Mask: net.CIDRMask(int(address.OnLinkPrefixLength), 8*len(ip))}
if includedInAddresses(ipnet) {
- log.Printf("Cleaning up stale address %s from interface '%s'", ip.String(), iface.FriendlyName())
- iface.LUID.DeleteIPAddress(ip)
+ log.Printf("Cleaning up stale address %s from interface '%s'", ipnet.String(), iface.FriendlyName())
+ iface.LUID.DeleteIPAddress(ipnet.IP) //TODO: BUG(rozmansi): DeleteIPAddress needs to take the full IPNet, not just the IP
}
}
}
diff --git a/tunnel/winipcfg/luid.go b/tunnel/winipcfg/luid.go
index 246c7585..b4bf5146 100644
--- a/tunnel/winipcfg/luid.go
+++ b/tunnel/winipcfg/luid.go
@@ -256,7 +256,7 @@ func (luid LUID) DNS() ([]net.IP, error) {
for _, addr := range addresses {
if addr.LUID == luid {
for dns := addr.FirstDNSServerAddress; dns != nil; dns = dns.Next {
- if ip := SocketAddressToIP(&dns.Address); len(ip) != 0 {
+ if ip := dns.Address.IP(); ip != nil {
r = append(r, ip)
} else {
return nil, windows.ERROR_INVALID_PARAMETER
diff --git a/tunnel/winipcfg/utils.go b/tunnel/winipcfg/utils.go
deleted file mode 100644
index c841c40c..00000000
--- a/tunnel/winipcfg/utils.go
+++ /dev/null
@@ -1,26 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
- */
-
-package winipcfg
-
-import (
- "net"
- "unsafe"
-
- "golang.org/x/sys/windows"
-)
-
-// SocketAddressToIP function returns IPv4 or IPv6 address from windows.SocketAddress.
-// If the address is neither IPv4 not IPv6 nil is returned.
-//TODO: Remove once https://go-review.googlesource.com/c/sys/+/178577 is merged.
-func SocketAddressToIP(addr *windows.SocketAddress) net.IP {
- if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(windows.RawSockaddrInet4{}) && addr.Sockaddr.Addr.Family == windows.AF_INET {
- return (*windows.RawSockaddrInet4)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
- } else if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(windows.RawSockaddrInet6{}) && addr.Sockaddr.Addr.Family == windows.AF_INET6 {
- return (*windows.RawSockaddrInet6)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
- } else {
- return nil
- }
-}