From f2501aa6c8c0e658b0c026201de3e9fdb7697593 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 28 Sep 2019 20:12:46 +0200 Subject: [PATCH] uapi: allow preventing creation of new peers when updating This enables race-free updates for wg-dynamic and similar tools. Suggested-by: Thomas Gschwantner --- device/uapi.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/device/uapi.go b/device/uapi.go index efa757b..999eeb5 100644 --- a/device/uapi.go +++ b/device/uapi.go @@ -113,6 +113,7 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError { var peer *Peer dummy := false + createdNewPeer := false deviceConfig := true for scanner.Scan() { @@ -237,7 +238,8 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError { peer = device.LookupPeer(publicKey) } - if peer == nil { + createdNewPeer = peer == nil + if createdNewPeer { peer, err = device.NewPeer(publicKey) if err != nil { logError.Println("Failed to create new peer:", err) @@ -251,6 +253,20 @@ func (device *Device) IpcSetOperation(socket *bufio.Reader) *IPCError { } } + case "update_only": + + // allow disabling of creation + + if value != "true" { + logError.Println("Failed to set update only, invalid value:", value) + return &IPCError{ipc.IpcErrorInvalid} + } + if createdNewPeer && !dummy { + device.RemovePeer(peer.handshake.remoteStatic) + peer = &Peer{} + dummy = true + } + case "remove": // remove currently selected peer from device