diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-23 04:20:14 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-23 06:08:37 +0200 |
commit | f8b3991e881a64f47412082ae15c08285eb6880b (patch) | |
tree | c5308716de6dc4765ed466e73f5bf70829f9ecfd /src/ratelimiter.c | |
parent | 66518b5ce61f74375c120a872a168585dc392ba7 (diff) |
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.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/ratelimiter.c')
-rw-r--r-- | src/ratelimiter.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/ratelimiter.c b/src/ratelimiter.c index e1afcd6..e35bf64 100644 --- a/src/ratelimiter.c +++ b/src/ratelimiter.c @@ -57,7 +57,7 @@ static void gc_entries(struct work_struct *work) unsigned int i; struct ratelimiter_entry *entry; struct hlist_node *temp; - const u64 now = ktime_get_ns(); + const u64 now = ktime_get_boot_ns(); for (i = 0; i < table_size; ++i) { spin_lock(&table_lock); @@ -107,7 +107,7 @@ bool ratelimiter_allow(struct sk_buff *skb, struct net *net) * tokens, rather than as part of the rate. */ spin_lock(&entry->lock); - now = ktime_get_ns(); + now = ktime_get_boot_ns(); tokens = min_t(u64, TOKEN_MAX, entry->tokens + now - entry->last_time_ns); entry->last_time_ns = now; ret = tokens >= PACKET_COST; @@ -130,7 +130,7 @@ bool ratelimiter_allow(struct sk_buff *skb, struct net *net) entry->ip = data.ip; INIT_HLIST_NODE(&entry->hash); spin_lock_init(&entry->lock); - entry->last_time_ns = ktime_get_ns(); + entry->last_time_ns = ktime_get_boot_ns(); entry->tokens = TOKEN_MAX - PACKET_COST; spin_lock(&table_lock); hlist_add_head_rcu(&entry->hash, bucket); |