diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-10 20:41:00 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-10 21:44:38 +0200 |
commit | e9ccb85445153e5fa09d607f9afbd5a78b534844 (patch) | |
tree | 0e0f17882479a532ee5ef2a8788b8ca8ae3c7ebb /src/config.c | |
parent | 45092f8fb277fc45d7dcfa49bd549fbed10d44e7 (diff) |
timers: apply slack to hotpath timers
For timers in the hotpath, we don't want them to be rescheduled so
aggressively, and since they don't need to be that precise, we can set a
decent amount of slack.
With the persistent keepalive timer, we have something of a special
case. Since the timeout isn't fixed like the others, we don't want to
make it more often than the kernel ordinarily would. So, instead, we
make it a minimum.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/config.c b/src/config.c index 3ca23f3..8750407 100644 --- a/src/config.c +++ b/src/config.c @@ -107,8 +107,11 @@ 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 (!peer->persistent_keepalive_interval && in_peer.persistent_keepalive_interval && netdev_pub(wg)->flags & IFF_UP) - packet_send_keepalive(peer); + 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)); + } peer->persistent_keepalive_interval = (unsigned long)in_peer.persistent_keepalive_interval * HZ; } } |