summaryrefslogtreecommitdiffhomepage
path: root/src/netlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/netlink.c')
-rw-r--r--src/netlink.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/netlink.c b/src/netlink.c
index 90c7aa2..3147587 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -165,7 +165,7 @@ static int get_device_start(struct netlink_callback *cb)
static int get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
{
struct wireguard_device *wg = (struct wireguard_device *)cb->args[0];
- struct wireguard_peer *peer, *next_peer_cursor = NULL, *last_peer_cursor = (struct wireguard_peer *)cb->args[1];
+ struct wireguard_peer *peer, *next_peer_cursor, *last_peer_cursor;
struct allowedips_cursor *rt_cursor = (struct allowedips_cursor *)cb->args[2];
unsigned int peer_idx = 0;
struct nlattr *peers_nest;
@@ -173,6 +173,8 @@ static int get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
void *hdr;
int ret = -EMSGSIZE;
+ next_peer_cursor = last_peer_cursor = (struct wireguard_peer *)cb->args[1];
+
rtnl_lock();
mutex_lock(&wg->device_update_lock);
cb->seq = wg->device_update_gen;
@@ -220,9 +222,9 @@ static int get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
nla_nest_end(skb, peers_nest);
out:
- peer_put(last_peer_cursor);
if (!ret && !done && next_peer_cursor)
peer_get(next_peer_cursor);
+ peer_put(last_peer_cursor);
mutex_unlock(&wg->device_update_lock);
rtnl_unlock();