summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josh@tailscale.com>2021-01-25 09:35:35 -0800
committerJosh Bleecher Snyder <josh@tailscale.com>2021-01-25 09:38:09 -0800
commitcecb41515d780213fd6b37bd04686f5296edf84c (patch)
treef4ac4a6f0f1566025aa9e246245ba2a16aa281d8
parenta9ce4b762cd8b9898ff69571194ad3f09ad6d7bd (diff)
device: serialize access to IpcSetOperation
Interleaves IpcSetOperations would spell trouble. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
-rw-r--r--device/device.go1
-rw-r--r--device/uapi.go3
2 files changed, 4 insertions, 0 deletions
diff --git a/device/device.go b/device/device.go
index 58e996f..5d11766 100644
--- a/device/device.go
+++ b/device/device.go
@@ -23,6 +23,7 @@ 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)
diff --git a/device/uapi.go b/device/uapi.go
index bf38459..c1ddb38 100644
--- a/device/uapi.go
+++ b/device/uapi.go
@@ -121,6 +121,9 @@ 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()
+
defer func() {
if err != nil {
device.log.Error.Println(err)