diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-09-28 20:04:17 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-10-11 12:34:54 +0200 |
commit | 6d176914a91d03589177e69d934c12dffdfe5855 (patch) | |
tree | 764c66e95aa4dddfd961c7bfaa762984ed6e0a9f /src/netlink.c | |
parent | 4c14ec2fb949f31966e61247b1c7b432857ab13d (diff) |
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>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 7 |
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; |