]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: handshake routine writes into encryption queue
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 18:26:45 +0000 (19:26 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 9 Feb 2021 18:26:45 +0000 (19:26 +0100)
Since RoutineHandshake calls peer.SendKeepalive(), it potentially is a
writer into the encryption queue, so we need to bump the wg count.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
device/device.go
device/receive.go

index 9375448d6c1474c6d747065f29363f88457a117c..7f96a1e9edd9279b87aab4ec4a100bcaba56ff97 100644 (file)
@@ -305,6 +305,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger) *Device {
 
        cpus := runtime.NumCPU()
        device.state.stopping.Wait()
+       device.queue.encryption.wg.Add(cpus) // One for each RoutineHandshake
        for i := 0; i < cpus; i++ {
                go device.RoutineEncryption()
                go device.RoutineDecryption()
index 3fc6831e8a7ae16c6ef5ad1fcef388307f5d4d43..6b9cccd3f9d067aef8e49fe3ecc06db7330131cf 100644 (file)
@@ -237,7 +237,10 @@ func (device *Device) RoutineDecryption() {
 /* Handles incoming packets related to handshake
  */
 func (device *Device) RoutineHandshake() {
-       defer device.log.Verbosef("Routine: handshake worker - stopped")
+       defer func() {
+               device.log.Verbosef("Routine: handshake worker - stopped")
+               device.queue.encryption.wg.Done()
+       }()
        device.log.Verbosef("Routine: handshake worker - started")
 
        for elem := range device.queue.handshake.c {