From 65317dcd758e916b751dcae5928e3a53f6d9f701 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 27 May 2019 09:57:02 +0200 Subject: winipcfg: make LUID.DeleteIPAddress accept IPNet Thou DeleteUnicastIpAddressEntry() cares about the IP only. Signed-off-by: Simon Rozman --- tunnel/ifaceconfig.go | 2 +- tunnel/winipcfg/luid.go | 10 ++++++++-- tunnel/winipcfg/winipcfg_test.go | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'tunnel') diff --git a/tunnel/ifaceconfig.go b/tunnel/ifaceconfig.go index fcf9dce3..1ad076fa 100644 --- a/tunnel/ifaceconfig.go +++ b/tunnel/ifaceconfig.go @@ -51,7 +51,7 @@ func cleanupAddressesOnDisconnectedInterfaces(addresses []net.IPNet) { 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'", ipnet.String(), iface.FriendlyName()) - iface.LUID.DeleteIPAddress(ipnet.IP) //TODO: BUG(rozmansi): DeleteIPAddress needs to take the full IPNet, not just the IP + iface.LUID.DeleteIPAddress(ipnet) } } } diff --git a/tunnel/winipcfg/luid.go b/tunnel/winipcfg/luid.go index b4bf5146..f3cc1f43 100644 --- a/tunnel/winipcfg/luid.go +++ b/tunnel/winipcfg/luid.go @@ -118,11 +118,17 @@ func (luid LUID) SetIPAddresses(addresses []net.IPNet) error { // DeleteIPAddress method deletes interface's unicast IP address. Corresponds to DeleteUnicastIpAddressEntry function // (https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-deleteunicastipaddressentry). -func (luid LUID) DeleteIPAddress(ip net.IP) error { - row, err := luid.IPAddress(ip) +func (luid LUID) DeleteIPAddress(address net.IPNet) error { + row := &MibUnicastIPAddressRow{} + initializeUnicastIPAddressEntry(row) + row.InterfaceLUID = luid + err := row.Address.SetIP(address.IP, 0) if err != nil { return err } + // Note: OnLinkPrefixLength member is ignored by DeleteUnicastIpAddressEntry(). + ones, _ := address.Mask.Size() + row.OnLinkPrefixLength = uint8(ones) return row.Delete() } diff --git a/tunnel/winipcfg/winipcfg_test.go b/tunnel/winipcfg/winipcfg_test.go index c69c1847..829d2675 100644 --- a/tunnel/winipcfg/winipcfg_test.go +++ b/tunnel/winipcfg/winipcfg_test.go @@ -439,7 +439,7 @@ func TestAddDeleteIPAddress(t *testing.T) { t.Errorf("Notification handler has not been called on add.") } - err = ifc.LUID.DeleteIPAddress(unexistentIPAddresToAdd.IP) + err = ifc.LUID.DeleteIPAddress(unexistentIPAddresToAdd) if err != nil { t.Errorf("LUID.DeleteIPAddress() returned an error: %v", err) } -- cgit v1.2.3-59-g8ed1b