aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 20:48:29 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 20:48:29 +0100
commit22bd274d1e1a9db97ea6463148c6fe2f00c95558 (patch)
tree29d1d80492d25e1dd2f90b4cd62a19bdb29c0ed1
parentMinor lock changes (diff)
downloadwireguard-openbsd-22bd274d1e1a9db97ea6463148c6fe2f00c95558.tar.xz
wireguard-openbsd-22bd274d1e1a9db97ea6463148c6fe2f00c95558.zip
Add debug messages to ref counting
-rw-r--r--src/wireguard.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/wireguard.c b/src/wireguard.c
index 32d905a..4b8005f 100644
--- a/src/wireguard.c
+++ b/src/wireguard.c
@@ -59,6 +59,9 @@ CTASSERT(WG_XNONCE_SIZE == XCHACHA20POLY1305_NONCE_SIZE);
#define ret_error(err) do { ret = err; goto leave; } while (0)
#define offsetof(type, member) ((size_t)(&((type *)0)->member))
+int wireguard_debug = 0;
+#define WGDEBUG(...) do { if (wireguard_debug) printf(__VA_ARGS__); } while (0)
+
/* wireguard.c */
void wg_kdf(uint8_t [WG_HASH_SIZE], uint8_t [WG_HASH_SIZE],
uint8_t [WG_HASH_SIZE], uint8_t [WG_KEY_SIZE], uint8_t *, size_t);
@@ -128,6 +131,8 @@ wg_device_new_session(struct wg_device *dev)
rw_exit_write(&session->s_lock);
rw_exit_write(&dev->d_lock);
+ WGDEBUG("wg_device_new_session: %x\n", session->s_local_id);
+
return session;
}
@@ -160,7 +165,7 @@ wg_device_ref_peerid(struct wg_device *dev, uint32_t id)
rw_enter_read(&dev->d_lock);
peer = fm_lookup(&dev->d_peers, id);
if (peer)
- refcnt_take(&peer->p_refcnt);
+ wg_peer_ref(peer);
rw_exit_read(&dev->d_lock);
return peer;
}
@@ -169,12 +174,14 @@ void
wg_peer_ref(struct wg_peer *peer)
{
refcnt_take(&peer->p_refcnt);
+ WGDEBUG("wg_peer_ref(%d): %x\n", peer->p_refcnt.refs, peer->p_id);
}
void
wg_peer_put(struct wg_peer *peer)
{
refcnt_rele_wake(&peer->p_refcnt);
+ WGDEBUG("wg_peer_put(%d): %x\n", peer->p_refcnt.refs, peer->p_id);
}
void
@@ -184,6 +191,7 @@ wg_peer_drop(struct wg_peer *peer)
fm_remove(&peer->p_device->d_peers, peer->p_id);
rw_exit_write(&peer->p_device->d_lock);
refcnt_finalize(&peer->p_refcnt, "wg_peer drop");
+ WGDEBUG("wg_peer_drop(%d): %x\n", peer->p_refcnt.refs, peer->p_id);
free(peer, M_DEVBUF, sizeof(*peer));
}
@@ -203,12 +211,16 @@ void
wg_session_ref(struct wg_session *session)
{
refcnt_take(&session->s_refcnt);
+ WGDEBUG("wg_session_ref(%d): %x\n", session->s_refcnt.refs,
+ session->s_local_id);
}
void
wg_session_put(struct wg_session *session)
{
refcnt_rele_wake(&session->s_refcnt);
+ WGDEBUG("wg_session_put(%d): %x\n", session->s_refcnt.refs,
+ session->s_local_id);
}
void
@@ -218,6 +230,8 @@ wg_session_drop(struct wg_session *session)
fm_remove(&session->s_peer->p_device->d_sessions, session->s_local_id);
rw_exit_write(&session->s_peer->p_device->d_lock);
refcnt_finalize(&session->s_refcnt, "wg_session drop");
+ WGDEBUG("wg_session_drop(%d): %x\n", session->s_refcnt.refs,
+ session->s_local_id);
free(session, M_DEVBUF, sizeof(*session));
}