summaryrefslogtreecommitdiffhomepage
path: root/src/timers.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-10-26 02:09:02 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-27 14:20:00 +0200
commitf33fec86c011033103c0ab572ffe8e6e36d9ed24 (patch)
treea0d26cc893c94b16a82b25c24c926aa79fff035c /src/timers.c
parent4ddf81d009853bf094ef14c97939407714f587be (diff)
timers: it is always reasonable to remove a timer
If struct timer_list has not been setup, it is zeroed, in which case timer_pending is false, so calling del_timer is safe. Calling del_timer is also safe on a timer that has already been del_timer'd. And calling del_timer is safe after a peer is dead, since the whole point of it being dead is that no more timers are created and all contexts eventually stop. Finally del_timer uses a lock, which means it's safe to call it concurrently. Therefore, we do not need any guards around calls to del_timer. While we're at it, we can get rid of the old lingering timers_enabled boolean which wasn't doing anything anyway anymore. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/timers.c')
-rw-r--r--src/timers.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/timers.c b/src/timers.c
index d2697b5..a9bcd36 100644
--- a/src/timers.c
+++ b/src/timers.c
@@ -37,16 +37,6 @@ static inline void mod_peer_timer(struct wg_peer *peer,
rcu_read_unlock_bh();
}
-static inline void del_peer_timer(struct wg_peer *peer,
- struct timer_list *timer)
-{
- rcu_read_lock_bh();
- if (likely(netif_running(peer->device->dev) &&
- !READ_ONCE(peer->is_dead)))
- del_timer(timer);
- rcu_read_unlock_bh();
-}
-
static void wg_expired_retransmit_handshake(struct timer_list *timer)
{
struct wg_peer *peer = from_timer(peer, timer,
@@ -57,7 +47,7 @@ static void wg_expired_retransmit_handshake(struct timer_list *timer)
peer->device->dev->name, peer->internal_id,
&peer->endpoint.addr, MAX_TIMER_HANDSHAKES + 2);
- del_peer_timer(peer, &peer->timer_send_keepalive);
+ del_timer(&peer->timer_send_keepalive);
/* We drop all packets without a keypair and don't try again,
* if we try unsuccessfully for too long to make a handshake.
*/
@@ -175,7 +165,7 @@ void wg_timers_data_received(struct wg_peer *peer)
*/
void wg_timers_any_authenticated_packet_sent(struct wg_peer *peer)
{
- del_peer_timer(peer, &peer->timer_send_keepalive);
+ del_timer(&peer->timer_send_keepalive);
}
/* Should be called after any type of authenticated packet is received, whether
@@ -183,7 +173,7 @@ void wg_timers_any_authenticated_packet_sent(struct wg_peer *peer)
*/
void wg_timers_any_authenticated_packet_received(struct wg_peer *peer)
{
- del_peer_timer(peer, &peer->timer_new_handshake);
+ del_timer(&peer->timer_new_handshake);
}
/* Should be called after a handshake initiation message is sent. */
@@ -199,7 +189,7 @@ void wg_timers_handshake_initiated(struct wg_peer *peer)
*/
void wg_timers_handshake_complete(struct wg_peer *peer)
{
- del_peer_timer(peer, &peer->timer_retransmit_handshake);
+ del_timer(&peer->timer_retransmit_handshake);
peer->timer_handshake_attempts = 0;
peer->sent_lastminute_handshake = false;
getnstimeofday(&peer->walltime_last_handshake);