summaryrefslogtreecommitdiffstatshomepage
path: root/src/netlink.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-07-31 07:03:07 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-07-31 07:19:52 +0200
commitb713ab0e605b4f9291f4fde38103bf689c2cdb76 (patch)
treee18f74fc2795b8c8b80141e8bf411a8a22959dc2 /src/netlink.c
parentratelimiter: prevent init/uninit race (diff)
downloadwireguard-monolithic-historical-b713ab0e605b4f9291f4fde38103bf689c2cdb76.tar.xz
wireguard-monolithic-historical-b713ab0e605b4f9291f4fde38103bf689c2cdb76.zip
peer: simplify rcu reference counts
Use RCU reference counts only when we must, and otherwise use a more reasonably named function. Reported-by: Jann Horn <jann@thejh.net>
Diffstat (limited to 'src/netlink.c')
-rw-r--r--src/netlink.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/netlink.c b/src/netlink.c
index aef743f..90c7aa2 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -221,8 +221,8 @@ static int get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
out:
peer_put(last_peer_cursor);
- if (!ret && !done)
- next_peer_cursor = peer_rcu_get(next_peer_cursor);
+ if (!ret && !done && next_peer_cursor)
+ peer_get(next_peer_cursor);
mutex_unlock(&wg->device_update_lock);
rtnl_unlock();
@@ -326,9 +326,11 @@ static int set_peer(struct wireguard_device *wg, struct nlattr **attrs)
up_read(&wg->static_identity.lock);
ret = -ENOMEM;
- peer = peer_rcu_get(peer_create(wg, public_key, preshared_key));
+ peer = peer_create(wg, public_key, preshared_key);
if (!peer)
goto out;
+ /* Take additional reference, as though we've just been looked up. */
+ peer_get(peer);
}
ret = 0;