diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-22 22:33:53 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-23 00:58:05 +0200 |
commit | 6766d7fbba1b2276a28828a15d24c19be05c41fe (patch) | |
tree | d3c4c0f42665a83baef8f7089082e91b57449a5c | |
parent | 2d8170c259fd234c9608df2481f8f5a93f4fe387 (diff) |
timers: upstream removed the slack concept
No longer do we specify slack ourselves. Instead we need to add it
directly in the main scheduling.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/config.c | 7 | ||||
-rw-r--r-- | src/timers.c | 11 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/config.c b/src/config.c index 8750407..3ca23f3 100644 --- a/src/config.c +++ b/src/config.c @@ -107,11 +107,8 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t if (in_peer.persistent_keepalive_interval && (in_peer.persistent_keepalive_interval < 10 || in_peer.persistent_keepalive_interval > 3600)) ret = -EINVAL; else { - if (in_peer.persistent_keepalive_interval && netdev_pub(wg)->flags & IFF_UP) { - if (!peer->persistent_keepalive_interval) - packet_send_keepalive(peer); - set_timer_slack(&peer->timer_persistent_keepalive, max_t(int, HZ / 2, (unsigned long)in_peer.persistent_keepalive_interval * HZ / 256)); - } + if (!peer->persistent_keepalive_interval && in_peer.persistent_keepalive_interval && netdev_pub(wg)->flags & IFF_UP) + packet_send_keepalive(peer); peer->persistent_keepalive_interval = (unsigned long)in_peer.persistent_keepalive_interval * HZ; } } diff --git a/src/timers.c b/src/timers.c index 4f840c6..636b851 100644 --- a/src/timers.c +++ b/src/timers.c @@ -18,6 +18,12 @@ enum { * Timer for, if enabled, sending an empty authenticated packet every user-specified seconds */ +/* This rounds the time down to the closest power of two of the closest quarter second. */ +static inline unsigned long slack_time(unsigned long time) +{ + return time & ~(BIT_MASK(ilog2(HZ / 4) + 1) - 1); +} + static void expired_retransmit_handshake(unsigned long ptr) { struct wireguard_peer *peer = (struct wireguard_peer *)ptr; @@ -142,7 +148,7 @@ void timers_ephemeral_key_created(struct wireguard_peer *peer) void timers_any_authenticated_packet_traversal(struct wireguard_peer *peer) { if (peer->persistent_keepalive_interval && likely(peer->timer_persistent_keepalive.data)) - mod_timer(&peer->timer_persistent_keepalive, jiffies + peer->persistent_keepalive_interval); + mod_timer(&peer->timer_persistent_keepalive, slack_time(jiffies + peer->persistent_keepalive_interval)); } void timers_init_peer(struct wireguard_peer *peer) @@ -154,12 +160,10 @@ void timers_init_peer(struct wireguard_peer *peer) init_timer(&peer->timer_send_keepalive); peer->timer_send_keepalive.function = expired_send_keepalive; peer->timer_send_keepalive.data = (unsigned long)peer; - set_timer_slack(&peer->timer_send_keepalive, HZ / 4); init_timer(&peer->timer_new_handshake); peer->timer_new_handshake.function = expired_new_handshake; peer->timer_new_handshake.data = (unsigned long)peer; - set_timer_slack(&peer->timer_new_handshake, HZ / 4); init_timer(&peer->timer_kill_ephemerals); peer->timer_kill_ephemerals.function = expired_kill_ephemerals; @@ -168,7 +172,6 @@ void timers_init_peer(struct wireguard_peer *peer) init_timer(&peer->timer_persistent_keepalive); peer->timer_persistent_keepalive.function = expired_send_persistent_keepalive; peer->timer_persistent_keepalive.data = (unsigned long)peer; - set_timer_slack(&peer->timer_persistent_keepalive, max_t(int, HZ / 2, peer->persistent_keepalive_interval / 256)); INIT_WORK(&peer->clear_peer_work, queued_expired_kill_ephemerals); } |