aboutsummaryrefslogtreecommitdiffstats
path: root/device/send.go
diff options
context:
space:
mode:
authorHaichao Liu <liuhaichao@bytedance.com>2020-11-18 20:53:22 +0800
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-18 14:22:15 +0100
commit913f68ce3820801e045632cb05c6f11e0df50b47 (patch)
treefb7ef8b175cfd7372ff8c5736d24381b6d2d8086 /device/send.go
parentwintun: load from filesystem by default (diff)
downloadwireguard-go-913f68ce3820801e045632cb05c6f11e0df50b47.tar.xz
wireguard-go-913f68ce3820801e045632cb05c6f11e0df50b47.zip
device: add write queue mutex for peer
fix panic: send on closed channel when remove peer Signed-off-by: Haichao Liu <liuhaichao@bytedance.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device/send.go')
-rw-r--r--device/send.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/device/send.go b/device/send.go
index c0bdba3..d202b62 100644
--- a/device/send.go
+++ b/device/send.go
@@ -107,6 +107,8 @@ func addToOutboundAndEncryptionQueues(outboundQueue chan *QueueOutboundElement,
/* Queues a keepalive if no packets are queued for peer
*/
func (peer *Peer) SendKeepalive() bool {
+ peer.queue.RLock()
+ defer peer.queue.RUnlock()
if len(peer.queue.nonce) != 0 || peer.queue.packetInNonceQueueIsAwaitingKey.Get() || !peer.isRunning.Get() {
return false
}
@@ -310,6 +312,7 @@ func (device *Device) RoutineReadFromTUN() {
// insert into nonce/pre-handshake queue
+ peer.queue.RLock()
if peer.isRunning.Get() {
if peer.queue.packetInNonceQueueIsAwaitingKey.Get() {
peer.SendHandshakeInitiation(false)
@@ -317,6 +320,7 @@ func (device *Device) RoutineReadFromTUN() {
addToNonceQueue(peer.queue.nonce, elem, device)
elem = nil
}
+ peer.queue.RUnlock()
}
}