aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 04:18:48 +0100
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-10-02 04:18:48 +0100
commite8e15b579866152f04cd4ffe818788e3da1b7a16 (patch)
treee98a3eb0882b4f99b1f608d69eeddaf4fcbf5251
parentFix lock ordering in tx_initiation, not perfect though. (diff)
downloadwireguard-openbsd-e8e15b579866152f04cd4ffe818788e3da1b7a16.tar.xz
wireguard-openbsd-e8e15b579866152f04cd4ffe818788e3da1b7a16.zip
Minor lock changes
-rw-r--r--src/if_wg.c6
-rw-r--r--src/wireguard.c8
2 files changed, 6 insertions, 8 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index fe2eb0d..4970c07 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -396,11 +396,11 @@ void
wg_route_send_keepalive(struct wg_route *r)
{
struct wg_session *session;
- if ((session = wg_peer_ks_session(r->r_peer)) == NULL) {
- wg_route_send_initiation(r);
- } else {
+ if ((session = wg_peer_ks_session(r->r_peer)) != NULL) {
wg_route_queue(r, WG_PKT_TRANSPORT, session->s_local_id);
wg_session_put(session);
+ } else {
+ wg_route_send_initiation(r);
}
}
diff --git a/src/wireguard.c b/src/wireguard.c
index 502bbde..32d905a 100644
--- a/src/wireguard.c
+++ b/src/wireguard.c
@@ -146,10 +146,9 @@ wg_device_ref_peerkey(struct wg_device *dev, struct wg_pubkey *key)
else
peer = NULL;
}
- rw_exit_read(&dev->d_lock);
-
if (peer)
wg_peer_ref(peer);
+ rw_exit_read(&dev->d_lock);
return peer;
}
@@ -287,10 +286,9 @@ wg_peer_hs_session(struct wg_peer *peer)
rw_enter_read(&peer->p_lock);
session = peer->p_hs_session;
- rw_exit_read(&peer->p_lock);
-
if (session)
wg_session_ref(session);
+ rw_exit_read(&peer->p_lock);
return session;
}
@@ -304,9 +302,9 @@ wg_peer_ks_session(struct wg_peer *peer)
(wg_timespec_timedout(&session->s_created, WG_REJECT_AFTER_TIME) ||
session->s_keyset.k_txcounter > WG_REJECT_AFTER_MESSAGES))
session = NULL;
- rw_exit_read(&peer->p_lock);
if (session != NULL)
wg_session_ref(session);
+ rw_exit_read(&peer->p_lock);
return session;
}