diff options
-rw-r--r-- | src/device.c | 4 | ||||
-rw-r--r-- | src/peer.h | 1 | ||||
-rw-r--r-- | src/timers.c | 57 | ||||
-rw-r--r-- | src/timers.h | 1 |
4 files changed, 25 insertions, 38 deletions
diff --git a/src/device.c b/src/device.c index c78a785..01dd99d 100644 --- a/src/device.c +++ b/src/device.c @@ -53,7 +53,7 @@ static int clear_noise_peer(struct wireguard_peer *peer, void *data) { noise_handshake_clear(&peer->handshake); noise_keypairs_clear(&peer->keypairs); - if (peer->timer_kill_ephemerals.data) + if (peer->timers_enabled) del_timer(&peer->timer_kill_ephemerals); return 0; } @@ -72,7 +72,7 @@ static int suspending_clear_noise_peers(struct notifier_block *nb, unsigned long static int stop_peer(struct wireguard_peer *peer, void *data) { - timers_uninit_peer_wait(peer); + timers_uninit_peer(peer); clear_noise_peer(peer, data); return 0; } @@ -43,6 +43,7 @@ struct wireguard_peer { struct timer_list timer_retransmit_handshake, timer_send_keepalive, timer_new_handshake, timer_kill_ephemerals, timer_persistent_keepalive; unsigned int timer_handshake_attempts; unsigned long persistent_keepalive_interval; + bool timers_enabled; bool timer_need_another_keepalive; bool need_resend_queue; bool sent_lastminute_handshake; diff --git a/src/timers.c b/src/timers.c index 3e6456c..41a9d3a 100644 --- a/src/timers.c +++ b/src/timers.c @@ -35,7 +35,7 @@ static void expired_retransmit_handshake(unsigned long ptr) skb_queue_purge(&peer->tx_packet_queue); /* We set a timer for destroying any residue that might be left * of a partial exchange. */ - if (likely(peer->timer_kill_ephemerals.data)) + if (likely(peer->timers_enabled)) mod_timer(&peer->timer_kill_ephemerals, jiffies + (REJECT_AFTER_TIME * 3)); goto out; } @@ -55,7 +55,8 @@ static void expired_send_keepalive(unsigned long ptr) packet_send_keepalive(peer); if (peer->timer_need_another_keepalive) { peer->timer_need_another_keepalive = false; - mod_timer(&peer->timer_send_keepalive, jiffies + KEEPALIVE_TIMEOUT); + if (peer->timers_enabled) + mod_timer(&peer->timer_send_keepalive, jiffies + KEEPALIVE_TIMEOUT); } peer_put(peer); } @@ -96,17 +97,17 @@ static void expired_send_persistent_keepalive(unsigned long ptr) /* Should be called after an authenticated data packet is sent. */ void timers_data_sent(struct wireguard_peer *peer) { - if (likely(peer->timer_send_keepalive.data)) + if (likely(peer->timers_enabled)) del_timer(&peer->timer_send_keepalive); - if (likely(peer->timer_new_handshake.data) && !timer_pending(&peer->timer_new_handshake)) + if (likely(peer->timers_enabled) && !timer_pending(&peer->timer_new_handshake)) mod_timer(&peer->timer_new_handshake, jiffies + KEEPALIVE_TIMEOUT + REKEY_TIMEOUT); } /* Should be called after an authenticated data packet is received. */ void timers_data_received(struct wireguard_peer *peer) { - if (likely(peer->timer_send_keepalive.data) && !timer_pending(&peer->timer_send_keepalive)) + if (likely(peer->timers_enabled) && !timer_pending(&peer->timer_send_keepalive)) mod_timer(&peer->timer_send_keepalive, jiffies + KEEPALIVE_TIMEOUT); else peer->timer_need_another_keepalive = true; @@ -115,23 +116,23 @@ void timers_data_received(struct wireguard_peer *peer) /* Should be called after any type of authenticated packet is received -- keepalive or data. */ void timers_any_authenticated_packet_received(struct wireguard_peer *peer) { - if (likely(peer->timer_new_handshake.data)) + if (likely(peer->timers_enabled)) del_timer(&peer->timer_new_handshake); } /* Should be called after a handshake initiation message is sent. */ void timers_handshake_initiated(struct wireguard_peer *peer) { - if (likely(peer->timer_send_keepalive.data)) + if (likely(peer->timers_enabled)) del_timer(&peer->timer_send_keepalive); - if (likely(peer->timer_retransmit_handshake.data)) + if (likely(peer->timers_enabled)) mod_timer(&peer->timer_retransmit_handshake, slack_time(jiffies + REKEY_TIMEOUT + prandom_u32_max(REKEY_TIMEOUT_JITTER_MAX))); } /* Should be called after a handshake response message is received and processed. */ void timers_handshake_complete(struct wireguard_peer *peer) { - if (likely(peer->timer_retransmit_handshake.data)) + if (likely(peer->timers_enabled)) del_timer(&peer->timer_retransmit_handshake); peer->timer_handshake_attempts = 0; } @@ -139,7 +140,7 @@ void timers_handshake_complete(struct wireguard_peer *peer) /* Should be called after an ephemeral key is created, which is before sending a handshake response or after receiving a handshake response. */ void timers_ephemeral_key_created(struct wireguard_peer *peer) { - if (likely(peer->timer_kill_ephemerals.data)) + if (likely(peer->timers_enabled)) mod_timer(&peer->timer_kill_ephemerals, jiffies + (REJECT_AFTER_TIME * 3)); do_gettimeofday(&peer->walltime_last_handshake); } @@ -147,12 +148,13 @@ void timers_ephemeral_key_created(struct wireguard_peer *peer) /* Should be called before an packet with authentication -- data, keepalive, either handshake -- is sent, or after one is received. */ void timers_any_authenticated_packet_traversal(struct wireguard_peer *peer) { - if (peer->persistent_keepalive_interval && likely(peer->timer_persistent_keepalive.data)) + if (peer->persistent_keepalive_interval && likely(peer->timers_enabled)) mod_timer(&peer->timer_persistent_keepalive, slack_time(jiffies + peer->persistent_keepalive_interval)); } void timers_init_peer(struct wireguard_peer *peer) { + peer->timers_enabled = true; setup_timer(&peer->timer_retransmit_handshake, expired_retransmit_handshake, (unsigned long)peer); setup_timer(&peer->timer_send_keepalive, expired_send_keepalive, (unsigned long)peer); setup_timer(&peer->timer_new_handshake, expired_new_handshake, (unsigned long)peer); @@ -163,29 +165,14 @@ void timers_init_peer(struct wireguard_peer *peer) void timers_uninit_peer(struct wireguard_peer *peer) { - if (peer->timer_retransmit_handshake.data) { - del_timer(&peer->timer_retransmit_handshake); - peer->timer_retransmit_handshake.data = 0; - } - if (peer->timer_send_keepalive.data) { - del_timer(&peer->timer_send_keepalive); - peer->timer_send_keepalive.data = 0; - } - if (peer->timer_new_handshake.data) { - del_timer(&peer->timer_new_handshake); - peer->timer_new_handshake.data = 0; - } - if (peer->timer_kill_ephemerals.data) { - del_timer(&peer->timer_kill_ephemerals); - peer->timer_kill_ephemerals.data = 0; - } - if (peer->timer_persistent_keepalive.data) { - del_timer(&peer->timer_persistent_keepalive); - peer->timer_persistent_keepalive.data = 0; - } -} -void timers_uninit_peer_wait(struct wireguard_peer *peer) -{ - timers_uninit_peer(peer); + if (!peer->timers_enabled) + return; + peer->timers_enabled = false; + wmb(); + del_timer_sync(&peer->timer_retransmit_handshake); + del_timer_sync(&peer->timer_send_keepalive); + del_timer_sync(&peer->timer_new_handshake); + del_timer_sync(&peer->timer_kill_ephemerals); + del_timer_sync(&peer->timer_persistent_keepalive); flush_work(&peer->clear_peer_work); } diff --git a/src/timers.h b/src/timers.h index 9c7af01..50f81a1 100644 --- a/src/timers.h +++ b/src/timers.h @@ -7,7 +7,6 @@ struct wireguard_peer; void timers_init_peer(struct wireguard_peer *peer); void timers_uninit_peer(struct wireguard_peer *peer); -void timers_uninit_peer_wait(struct wireguard_peer *peer); void timers_data_sent(struct wireguard_peer *peer); void timers_data_received(struct wireguard_peer *peer); |