aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tunnel/interfacewatcher.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-09-27 10:40:59 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-09-27 10:53:37 +0200
commit21aa23c7430ce9949d52a98c3f81b829bb5fdf2f (patch)
tree68853e8b657762ebb09452b6e5ec514baf34ad67 /tunnel/interfacewatcher.go
parentwinipcfg: port more granular locking from route change to others (diff)
downloadwireguard-windows-21aa23c7430ce9949d52a98c3f81b829bb5fdf2f.tar.xz
wireguard-windows-21aa23c7430ce9949d52a98c3f81b829bb5fdf2f.zip
winipcfg: make Unregister wait for callbacks to complete
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tunnel/interfacewatcher.go')
-rw-r--r--tunnel/interfacewatcher.go53
1 files changed, 31 insertions, 22 deletions
diff --git a/tunnel/interfacewatcher.go b/tunnel/interfacewatcher.go
index b7a07f77..d74db0e9 100644
--- a/tunnel/interfacewatcher.go
+++ b/tunnel/interfacewatcher.go
@@ -116,33 +116,42 @@ func (iw *interfaceWatcher) Configure(device *device.Device, conf *conf.Config,
func (iw *interfaceWatcher) Destroy() {
iw.setupMutex.Lock()
- defer iw.setupMutex.Unlock()
-
- if iw.tun == nil {
- return
+ routeChangeCallback4 := iw.routeChangeCallback4
+ routeChangeCallback6 := iw.routeChangeCallback6
+ interfaceChangeCallback := iw.interfaceChangeCallback
+ tun := iw.tun
+ iw.setupMutex.Unlock()
+
+ if interfaceChangeCallback != nil {
+ interfaceChangeCallback.Unregister()
+ }
+ if routeChangeCallback4 != nil {
+ routeChangeCallback4.Unregister()
+ }
+ if routeChangeCallback6 != nil {
+ routeChangeCallback6.Unregister()
}
- if iw.routeChangeCallback4 != nil {
- iw.routeChangeCallback4.Unregister()
+ iw.setupMutex.Lock()
+ if interfaceChangeCallback == iw.interfaceChangeCallback {
+ iw.interfaceChangeCallback = nil
+ }
+ if routeChangeCallback4 == iw.routeChangeCallback4 {
iw.routeChangeCallback4 = nil
}
- if iw.routeChangeCallback6 != nil {
- iw.routeChangeCallback6.Unregister()
+ if routeChangeCallback6 == iw.routeChangeCallback6 {
iw.routeChangeCallback6 = nil
}
- if iw.interfaceChangeCallback != nil {
- iw.interfaceChangeCallback.Unregister()
- iw.interfaceChangeCallback = nil
- }
-
firewall.DisableFirewall()
-
- // It seems that the Windows networking stack doesn't like it when we destroy interfaces that have active
- // routes, so to be certain, just remove everything before destroying.
- luid := winipcfg.LUID(iw.tun.LUID())
- luid.FlushRoutes(windows.AF_INET)
- luid.FlushIPAddresses(windows.AF_INET)
- luid.FlushRoutes(windows.AF_INET6)
- luid.FlushIPAddresses(windows.AF_INET6)
- luid.FlushDNS()
+ if tun != nil && iw.tun == tun {
+ // It seems that the Windows networking stack doesn't like it when we destroy interfaces that have active
+ // routes, so to be certain, just remove everything before destroying.
+ luid := winipcfg.LUID(tun.LUID())
+ luid.FlushRoutes(windows.AF_INET)
+ luid.FlushIPAddresses(windows.AF_INET)
+ luid.FlushRoutes(windows.AF_INET6)
+ luid.FlushIPAddresses(windows.AF_INET6)
+ luid.FlushDNS()
+ }
+ iw.setupMutex.Unlock()
}