aboutsummaryrefslogtreecommitdiff
path: root/device.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-01 16:59:13 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-01 17:46:28 +0200
commit168ef61a638e4875b260edbc51551bae0dc34ac3 (patch)
tree579a18ee07b9cf5427c9bab187707917215b7e5f /device.go
parentb34604245ec4dfb50846d0ba28d022be5b756c25 (diff)
downloadwireguard-go-168ef61a638e4875b260edbc51551bae0dc34ac3.tar.gz
wireguard-go-168ef61a638e4875b260edbc51551bae0dc34ac3.zip
Add missing locks and fix debug output, and try to flush queues
Flushing queues on exit is sort of a partial solution, but this could be better. Really what we want is for no more packets to be enqueued after isUp is set to false.
Diffstat (limited to 'device.go')
-rw-r--r--device.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/device.go b/device.go
index 3ad53c9..dddb547 100644
--- a/device.go
+++ b/device.go
@@ -339,6 +339,8 @@ func (device *Device) RemovePeer(key NoisePublicKey) {
}
func (device *Device) RemoveAllPeers() {
+ device.noise.mutex.Lock()
+ defer device.noise.mutex.Unlock()
device.routing.mutex.Lock()
defer device.routing.mutex.Unlock()
@@ -354,16 +356,25 @@ func (device *Device) RemoveAllPeers() {
}
func (device *Device) Close() {
- device.log.Info.Println("Device closing")
if device.isClosed.Swap(true) {
return
}
- device.signal.stop.Broadcast()
+ device.log.Info.Println("Device closing")
+ device.state.changing.Set(true)
+ device.state.mutex.Lock()
+ defer device.state.mutex.Unlock()
+
device.tun.device.Close()
device.BindClose()
+
device.isUp.Set(false)
+
+ device.signal.stop.Broadcast()
+
device.RemoveAllPeers()
device.rate.limiter.Close()
+
+ device.state.changing.Set(false)
device.log.Info.Println("Interface closed")
}