summaryrefslogtreecommitdiffhomepage
path: root/device/uapi.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-09-28 20:12:46 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-04 11:41:02 +0200
commitf2501aa6c8c0e658b0c026201de3e9fdb7697593 (patch)
tree6e190e1af5582e2943d2ab2ef165239234f2ef08 /device/uapi.go
parentcb8d01f58a0057b437b1a448f9d8ba25bcc6d8da (diff)
uapi: allow preventing creation of new peers when updating
This enables race-free updates for wg-dynamic and similar tools. Suggested-by: Thomas Gschwantner <tharre3@gmail.com>
Diffstat (limited to 'device/uapi.go')
-rw-r--r--device/uapi.go18
1 files changed, 17 insertions, 1 deletions
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