diff options
author | Simon Rozman <simon@rozman.si> | 2019-05-27 09:57:02 +0200 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2019-05-27 09:57:02 +0200 |
commit | b3dda6435d42d43b8fc4a643db983df9a26c27cf (patch) | |
tree | dd347f7322ec60a98668283053d49b456ec8aafe /tunnel/winipcfg | |
parent | build: set 6.1 PE flags (diff) | |
download | wireguard-windows-b3dda6435d42d43b8fc4a643db983df9a26c27cf.tar.xz wireguard-windows-b3dda6435d42d43b8fc4a643db983df9a26c27cf.zip |
winipcfg: make LUID.DeleteIPAddress accept IPNet
Thou DeleteUnicastIpAddressEntry() cares about the IP only.
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tunnel/winipcfg')
-rw-r--r-- | tunnel/winipcfg/luid.go | 10 | ||||
-rw-r--r-- | tunnel/winipcfg/winipcfg_test.go | 2 |
2 files changed, 9 insertions, 3 deletions
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) } |