summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-10 18:34:23 +1000
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-11 20:59:53 +1000
commitd21313afe93d96edc06eeb4f9a03916a393b7e5f (patch)
treea2a2ed5cdc3eafa121f3c8dcd3d6e4ab46d155d9 /src
parentUse ifq for output queueing (diff)
downloadwireguard-openbsd-d21313afe93d96edc06eeb4f9a03916a393b7e5f.tar.xz
wireguard-openbsd-d21313afe93d96edc06eeb4f9a03916a393b7e5f.zip
Check handshake state before preparing initiation packet
Diffstat (limited to 'src')
-rw-r--r--src/if_wg.c2
-rw-r--r--src/wireguard.c13
-rw-r--r--src/wireguard.h1
3 files changed, 13 insertions, 3 deletions
diff --git a/src/if_wg.c b/src/if_wg.c
index 64933f0b326..f6360b15936 100644
--- a/src/if_wg.c
+++ b/src/if_wg.c
@@ -587,6 +587,8 @@ wg_transmit_initiation(struct wg_peer *p)
enum wg_error e;
struct wg_msg_initiation *init;
+ if (wg_handshake_initiation_ready(&p->p_hs) == WG_OK)
+ return;
WG_PKT(init, m, wg_msg_initiation, p);
diff --git a/src/wireguard.c b/src/wireguard.c
index d0c4947c735..9b13d61751c 100644
--- a/src/wireguard.c
+++ b/src/wireguard.c
@@ -344,6 +344,16 @@ wg_session_clean(struct wg_session *s)
}
enum wg_error
+wg_handshake_initiation_ready(struct wg_handshake *hs)
+{
+ int timo;
+ rw_enter_read(&hs->hs_lock);
+ timo = wg_timespec_timedout(&hs->hs_last_initiation, WG_REKEY_TIMEOUT);
+ rw_exit_read(&hs->hs_lock);
+ return timo ? WG_HS_RATE : WG_OK;
+}
+
+enum wg_error
wg_session_from_handshake(struct wg_session *s, struct wg_handshake *hs)
{
enum wg_error ret = WG_OK;
@@ -451,9 +461,6 @@ wg_handshake_make_initiation(struct wg_handshake *hs, uint32_t id, struct wg_msg
if (hs->hs_state != WG_STATE_CLEAN)
ret_error(WG_STATE);
- if (!wg_timespec_timedout(&hs->hs_last_initiation, WG_REKEY_TIMEOUT))
- ret_error(WG_HS_RATE);
-
if (hs->hs_attempts >= WG_REKEY_ATTEMPT_COUNT)
ret_error(WG_HS_ATTEMPTS);
diff --git a/src/wireguard.h b/src/wireguard.h
index 60c101b1d5a..0ae1186712f 100644
--- a/src/wireguard.h
+++ b/src/wireguard.h
@@ -241,6 +241,7 @@ enum wg_error wg_handshake_recv_cookie(struct wg_handshake *, struct wg_msg_cook
enum wg_error wg_handshake_initiation_valid_mac2(struct wg_cookie *, struct wg_msg_initiation *);
enum wg_error wg_handshake_response_valid_mac2(struct wg_cookie *, struct wg_msg_response *);
enum wg_error wg_handshake_merge(struct wg_handshake *, struct wg_handshake *);
+enum wg_error wg_handshake_initiation_ready(struct wg_handshake *);
void wg_handshake_reset_attempts(struct wg_handshake *);
uint32_t wg_handshake_id(struct wg_handshake *);