diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-10 02:46:37 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-07-10 03:46:56 +0200 |
commit | c4c3a558a1f476b3a49f33790c570a9a63b78d04 (patch) | |
tree | 031293468361b9520d7f54d870ec9ab0bc5f1298 | |
parent | 2e1bceea1388e2bd57b4ef17fb21190a8755d71e (diff) |
persistent keepalive: use unsigned long to avoid multiplication in hotpath
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/config.c | 4 | ||||
-rw-r--r-- | src/peer.h | 2 | ||||
-rw-r--r-- | src/timers.c | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/src/config.c b/src/config.c index 9cf75b1..3ca23f3 100644 --- a/src/config.c +++ b/src/config.c @@ -109,7 +109,7 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t else { if (!peer->persistent_keepalive_interval && in_peer.persistent_keepalive_interval && netdev_pub(wg)->flags & IFF_UP) packet_send_keepalive(peer); - peer->persistent_keepalive_interval = in_peer.persistent_keepalive_interval; + peer->persistent_keepalive_interval = (unsigned long)in_peer.persistent_keepalive_interval * HZ; } } @@ -251,7 +251,7 @@ static int populate_peer(struct wireguard_peer *peer, void *ctx) out_peer.last_handshake_time = peer->walltime_last_handshake; out_peer.tx_bytes = peer->tx_bytes; out_peer.rx_bytes = peer->rx_bytes; - out_peer.persistent_keepalive_interval = peer->persistent_keepalive_interval; + out_peer.persistent_keepalive_interval = (uint16_t)(peer->persistent_keepalive_interval / HZ); ipmasks_data.out_len = data->out_len; ipmasks_data.data = data->data; @@ -29,7 +29,7 @@ struct wireguard_peer { uint64_t rx_bytes, tx_bytes; struct timer_list timer_retransmit_handshake, timer_send_keepalive, timer_new_handshake, timer_kill_ephemerals, timer_persistent_keepalive; unsigned int timer_handshake_attempts; - uint16_t persistent_keepalive_interval; + unsigned long persistent_keepalive_interval; bool timer_need_another_keepalive; struct timeval walltime_last_handshake; struct sk_buff_head tx_packet_queue; diff --git a/src/timers.c b/src/timers.c index 8ef1469..58b6e64 100644 --- a/src/timers.c +++ b/src/timers.c @@ -82,7 +82,7 @@ static void expired_send_persistent_keepalive(unsigned long ptr) if (unlikely(!peer->persistent_keepalive_interval)) return; - pr_debug("Sending keep alive packet to peer %Lu (%pISpfsc), since we haven't sent or received authenticated data for %u seconds\n", peer->internal_id, &peer->endpoint_addr, peer->persistent_keepalive_interval); + pr_debug("Sending keep alive packet to peer %Lu (%pISpfsc), since we haven't sent or received authenticated data for %lu seconds\n", peer->internal_id, &peer->endpoint_addr, peer->persistent_keepalive_interval / HZ); packet_send_keepalive(peer); } @@ -134,7 +134,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 + HZ * peer->persistent_keepalive_interval); + mod_timer(&peer->timer_persistent_keepalive, jiffies + peer->persistent_keepalive_interval); } void timers_init_peer(struct wireguard_peer *peer) |