From 64669564122e5112a01536cbe28e8c2159eb056b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 6 Oct 2017 15:55:47 +0200 Subject: receive: do not consider 0 jiffies as being set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This causes tests to fail if run within the first 5 minutes. We also move to jiffies 64, so that there's low chance of wrapping in case handshakes are spread far apart. Reported-by: René van Dorst --- src/receive.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/receive.c b/src/receive.c index b3ad9c3..ca87476 100644 --- a/src/receive.c +++ b/src/receive.c @@ -83,7 +83,7 @@ static inline int skb_prepare_header(struct sk_buff *skb, struct wireguard_devic static void receive_handshake_packet(struct wireguard_device *wg, struct sk_buff *skb) { - static unsigned long last_under_load = 0; /* Yes this is global, so that our load calculation applies to the whole system. */ + static u64 last_under_load = 0; /* Yes this is global, so that our load calculation applies to the whole system. */ struct wireguard_peer *peer = NULL; bool under_load; enum cookie_mac_state mac_state; @@ -97,9 +97,9 @@ static void receive_handshake_packet(struct wireguard_device *wg, struct sk_buff under_load = skb_queue_len(&wg->incoming_handshakes) >= MAX_QUEUED_INCOMING_HANDSHAKES / 8; if (under_load) - last_under_load = jiffies; - else - under_load = time_is_after_jiffies(last_under_load + HZ); + last_under_load = get_jiffies_64(); + else if (last_under_load) + under_load = time_is_after_jiffies64(last_under_load + HZ); mac_state = cookie_validate_packet(&wg->cookie_checker, skb, under_load); if ((under_load && mac_state == VALID_MAC_WITH_COOKIE) || (!under_load && mac_state == VALID_MAC_BUT_NO_COOKIE)) packet_needs_cookie = false; -- cgit v1.2.3-59-g8ed1b