aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/netlink.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-09-28 20:04:17 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-11 12:34:54 +0200
commit54db1977b2501680eb0e407efbf0350c103ca7a0 (patch)
tree0c094a992e9e6d7c22341242cf23d0e7b0eb3c95 /src/netlink.c
parentnetns: add test for failing 5.3 FIB changes (diff)
downloadwireguard-monolithic-historical-54db1977b2501680eb0e407efbf0350c103ca7a0.tar.xz
wireguard-monolithic-historical-54db1977b2501680eb0e407efbf0350c103ca7a0.zip
netlink: 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 'src/netlink.c')
-rw-r--r--src/netlink.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/netlink.c b/src/netlink.c
index 0805a26..190e405 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -389,10 +389,10 @@ static int set_peer(struct wg_device *wg, struct nlattr **attrs)
peer = wg_pubkey_hashtable_lookup(wg->peer_hashtable,
nla_data(attrs[WGPEER_A_PUBLIC_KEY]));
+ ret = 0;
if (!peer) { /* Peer doesn't exist yet. Add a new one. */
- ret = -ENODEV;
- if (flags & WGPEER_F_REMOVE_ME)
- goto out; /* Tried to remove a non-existing peer. */
+ if (flags & (WGPEER_F_REMOVE_ME | WGPEER_F_UPDATE_ONLY))
+ goto out;
/* The peer is new, so there aren't allowed IPs to remove. */
flags &= ~WGPEER_F_REPLACE_ALLOWEDIPS;
@@ -429,7 +429,6 @@ static int set_peer(struct wg_device *wg, struct nlattr **attrs)
wg_peer_get(peer);
}
- ret = 0;
if (flags & WGPEER_F_REMOVE_ME) {
wg_peer_remove(peer);
goto out;