]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: do not allow get to run while set runs
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 28 Jan 2021 14:26:22 +0000 (15:26 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 28 Jan 2021 14:26:22 +0000 (15:26 +0100)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
device/device.go
device/uapi.go

index e769a2042f2f7bd57904067f0f866b642abd2c52..c6b62ea0d675869ec3d6a022584198f9eb15b276 100644 (file)
@@ -23,7 +23,6 @@ type Device struct {
        isUp     AtomicBool // device is (going) up
        isClosed AtomicBool // device is closed? (acting as guard)
        log      *Logger
-       ipcSetMu sync.Mutex // serializes UAPI set operations
 
        // synchronized resources (locks acquired in order)
 
@@ -89,6 +88,8 @@ type Device struct {
                device tun.Device
                mtu    int32
        }
+
+       ipcMutex sync.RWMutex
 }
 
 // An encryptionQueue is a channel of QueueOutboundElements awaiting encryption.
index 6f7fb2a48d6e40bc8206d8466449ccfd5631c7e3..43bb0d677e90f03e1eba51f9b8627fae585230e0 100644 (file)
@@ -50,6 +50,9 @@ var byteBufferPool = &sync.Pool{
 // IpcGetOperation implements the WireGuard configuration protocol "get" operation.
 // See https://www.wireguard.com/xplatform/#configuration-protocol for details.
 func (device *Device) IpcGetOperation(w io.Writer) error {
+       device.ipcMutex.RLock()
+       defer device.ipcMutex.RUnlock()
+
        buf := byteBufferPool.Get().(*bytes.Buffer)
        buf.Reset()
        defer byteBufferPool.Put(buf)
@@ -137,8 +140,8 @@ func (device *Device) IpcGetOperation(w io.Writer) error {
 // IpcSetOperation implements the WireGuard configuration protocol "set" operation.
 // See https://www.wireguard.com/xplatform/#configuration-protocol for details.
 func (device *Device) IpcSetOperation(r io.Reader) (err error) {
-       device.ipcSetMu.Lock()
-       defer device.ipcSetMu.Unlock()
+       device.ipcMutex.Lock()
+       defer device.ipcMutex.Unlock()
 
        defer func() {
                if err != nil {