193d28a83f48a9a578e14772190c8066a843566d
[openwrt/staging/pepe2k.git] /
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Fri, 14 Feb 2020 23:57:21 +0100
4 Subject: [PATCH] wireguard: receive: reset last_under_load to zero
5
6 commit 2a8a4df36462aa85b0db87b7c5ea145ba67e34a8 upstream.
7
8 This is a small optimization that prevents more expensive comparisons
9 from happening when they are no longer necessary, by clearing the
10 last_under_load variable whenever we wind up in a state where we were
11 under load but we no longer are.
12
13 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
14 Suggested-by: Matt Dunwoodie <ncon@noconroy.net>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
17 ---
18 drivers/net/wireguard/receive.c | 7 +++++--
19 1 file changed, 5 insertions(+), 2 deletions(-)
20
21 --- a/drivers/net/wireguard/receive.c
22 +++ b/drivers/net/wireguard/receive.c
23 @@ -118,10 +118,13 @@ static void wg_receive_handshake_packet(
24
25 under_load = skb_queue_len(&wg->incoming_handshakes) >=
26 MAX_QUEUED_INCOMING_HANDSHAKES / 8;
27 - if (under_load)
28 + if (under_load) {
29 last_under_load = ktime_get_coarse_boottime_ns();
30 - else if (last_under_load)
31 + } else if (last_under_load) {
32 under_load = !wg_birthdate_has_expired(last_under_load, 1);
33 + if (!under_load)
34 + last_under_load = 0;
35 + }
36 mac_state = wg_cookie_validate_packet(&wg->cookie_checker, skb,
37 under_load);
38 if ((under_load && mac_state == VALID_MAC_WITH_COOKIE) ||