aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 23:34:35 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 23:34:35 +0100
commit7911243d337e762bf1f82a68cac51ef4da2ec5a1 (patch)
tree8caf5055feb65331e1dcdd0f705507763e10710a
parentAdd initiation attempt reset (diff)
downloadwireguard-openbsd-7911243d337e762bf1f82a68cac51ef4da2ec5a1.tar.xz
wireguard-openbsd-7911243d337e762bf1f82a68cac51ef4da2ec5a1.zip
Move wg_peer_ref to wg_device_new_peer
-rw-r--r--src/if_wg.c1
-rw-r--r--src/wireguard.c4
-rw-r--r--src/wireguard.h1
3 files changed, 4 insertions, 2 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index 2b9dd5b..51d7b32 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -1059,7 +1059,6 @@ wg_ioctl_set_peer(struct wg_softc *sc, u_long cmd, struct wg_set_peer *wsp)
if ((peer = wg_device_ref_peerkey(&sc->sc_dev, &pub)) == NULL) {
route = malloc(sizeof(*route), M_DEVBUF, M_WAITOK | M_ZERO);
peer = wg_device_new_peer(&sc->sc_dev, &pub, route);
- wg_peer_ref(peer);
route->r_sc = sc;
route->r_peer = peer;
diff --git a/src/wireguard.c b/src/wireguard.c
index eeb7d40..5e06dcf 100644
--- a/src/wireguard.c
+++ b/src/wireguard.c
@@ -80,6 +80,7 @@ enum wg_error wg_msg_response_valid_mac2(struct wg_msg_response *, struct wg_coo
void wg_session_drop(struct wg_session *);
void wg_session_ref(struct wg_session *);
+void wg_peer_ref(struct wg_peer *);
/* Some crappy API */
void
@@ -112,6 +113,9 @@ wg_device_new_peer(struct wg_device *dev, struct wg_pubkey *key, void *arg)
rw_exit_write(&peer->p_lock);
rw_exit_write(&dev->d_lock);
+ /* Take reference to return */
+ wg_peer_ref(peer);
+
/* All other elements of wg_peer are nulled by M_ZERO */
return peer;
}
diff --git a/src/wireguard.h b/src/wireguard.h
index 7ddf5e2..401a7f7 100644
--- a/src/wireguard.h
+++ b/src/wireguard.h
@@ -249,7 +249,6 @@ struct wg_peer *wg_device_new_peer(struct wg_device *, struct wg_pubkey *, void
struct wg_peer *wg_device_ref_peerkey(struct wg_device *, struct wg_pubkey *);
struct wg_peer *wg_device_ref_peerid(struct wg_device *, uint32_t);
-void wg_peer_ref(struct wg_peer *);
void wg_peer_put(struct wg_peer *);
void wg_peer_drop(struct wg_peer *);
void wg_peer_attach_session(struct wg_peer *, struct wg_session *);