From d0bd6dc67d81236f66cb763c3d47dd6b5d7581a6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 23 Jun 2018 04:20:14 +0200 Subject: global: use ktime boottime instead of jiffies Since this is a network protocol, expirations need to be accounted for, even across system suspend. On real systems, this isn't a problem, since we're clearing all keys before suspend. But on Android, where we don't do that, this is something of a problem. So, we switch to using boottime instead of jiffies. --- src/send.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/send.c') diff --git a/src/send.c b/src/send.c index f0f53d4..f5ee629 100644 --- a/src/send.c +++ b/src/send.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -25,11 +24,11 @@ static void packet_send_handshake_initiation(struct wireguard_peer *peer) struct message_handshake_initiation packet; down_write(&peer->handshake.lock); - if (!time_is_before_jiffies64(peer->last_sent_handshake + REKEY_TIMEOUT)) { + if (!has_expired(peer->last_sent_handshake, REKEY_TIMEOUT)) { up_write(&peer->handshake.lock); return; /* This function is rate limited. */ } - peer->last_sent_handshake = get_jiffies_64(); + peer->last_sent_handshake = ktime_get_boottime(); up_write(&peer->handshake.lock); net_dbg_ratelimited("%s: Sending handshake initiation to peer %llu (%pISpfsc)\n", peer->device->dev->name, peer->internal_id, &peer->endpoint.addr); @@ -59,7 +58,7 @@ void packet_send_queued_handshake_initiation(struct wireguard_peer *peer, bool i /* First checking the timestamp here is just an optimization; it will * be caught while properly locked inside the actual work queue. */ - if (!time_is_before_jiffies64(peer->last_sent_handshake + REKEY_TIMEOUT)) + if (!has_expired(peer->last_sent_handshake, REKEY_TIMEOUT)) return; peer = peer_rcu_get(peer); @@ -73,7 +72,7 @@ void packet_send_handshake_response(struct wireguard_peer *peer) struct message_handshake_response packet; net_dbg_ratelimited("%s: Sending handshake response to peer %llu (%pISpfsc)\n", peer->device->dev->name, peer->internal_id, &peer->endpoint.addr); - peer->last_sent_handshake = get_jiffies_64(); + peer->last_sent_handshake = ktime_get_boottime(); if (noise_handshake_create_response(&packet, &peer->handshake)) { cookie_add_mac_to_packet(&packet, sizeof(packet), peer); @@ -104,7 +103,7 @@ static inline void keep_key_fresh(struct wireguard_peer *peer) keypair = rcu_dereference_bh(peer->keypairs.current_keypair); if (likely(keypair && keypair->sending.is_valid) && (unlikely(atomic64_read(&keypair->sending.counter.counter) > REKEY_AFTER_MESSAGES) || - (keypair->i_am_the_initiator && unlikely(time_is_before_eq_jiffies64(keypair->sending.birthdate + REKEY_AFTER_TIME))))) + (keypair->i_am_the_initiator && unlikely(has_expired(keypair->sending.birthdate, REKEY_AFTER_TIME))))) send = true; rcu_read_unlock_bh(); @@ -306,7 +305,7 @@ void packet_send_staged_packets(struct wireguard_peer *peer) key = &keypair->sending; if (unlikely(!key || !key->is_valid)) goto out_nokey; - if (unlikely(time_is_before_eq_jiffies64(key->birthdate + REJECT_AFTER_TIME))) + if (unlikely(has_expired(key->birthdate, REJECT_AFTER_TIME))) goto out_invalid; /* After we know we have a somewhat valid key, we now try to assign nonces to -- cgit v1.2.3-59-g8ed1b