From 0f4fbc18851b4375d09b97800d8f3360702f61b8 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 25 May 2019 00:25:04 +0200 Subject: winipcfg: SocketAddressToIP was upstreamed Signed-off-by: Jason A. Donenfeld --- tunnel/ifaceconfig.go | 6 +++--- tunnel/winipcfg/luid.go | 2 +- tunnel/winipcfg/utils.go | 26 -------------------------- 3 files changed, 4 insertions(+), 30 deletions(-) delete mode 100644 tunnel/winipcfg/utils.go 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 - } -} -- cgit v1.2.3-59-g8ed1b