aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/ratelimiter.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-06-12 15:05:50 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-06-25 16:42:42 +0200
commit21c6bb547d0d46a6ce36b7e1026b62548c6acfc1 (patch)
treebce4d65b9f48ec337f92172572767c25f43a3416 /src/ratelimiter.c
parentcompat: unify custom function prefix/suffix (diff)
downloadwireguard-monolithic-historical-21c6bb547d0d46a6ce36b7e1026b62548c6acfc1.tar.xz
wireguard-monolithic-historical-21c6bb547d0d46a6ce36b7e1026b62548c6acfc1.zip
global: switch to coarse ktime
Coarse ktime is broken until [1] in 5.2 and kernels without the backport, so we use fallback code there. The fallback code has also been improved significantly. It now only uses slower clocks on kernels < 3.17, at the expense of some accuracy we're not overly concerned about. [1] https://lore.kernel.org/lkml/tip-e3ff9c3678b4d80e22d2557b68726174578eaf52@git.kernel.org/ Suggested-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'src/ratelimiter.c')
-rw-r--r--src/ratelimiter.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/ratelimiter.c b/src/ratelimiter.c
index fd09190..e33ec72 100644
--- a/src/ratelimiter.c
+++ b/src/ratelimiter.c
@@ -66,7 +66,7 @@ static void entry_uninit(struct ratelimiter_entry *entry)
/* Calling this function with a NULL work uninits all entries. */
static void wg_ratelimiter_gc_entries(struct work_struct *work)
{
- const u64 now = ktime_get_boot_fast_ns();
+ const u64 now = ktime_get_coarse_boottime_ns();
struct ratelimiter_entry *entry;
struct hlist_node *temp;
unsigned int i;
@@ -130,7 +130,7 @@ bool wg_ratelimiter_allow(struct sk_buff *skb, struct net *net)
* as part of the rate.
*/
spin_lock(&entry->lock);
- now = ktime_get_boot_fast_ns();
+ now = ktime_get_coarse_boottime_ns();
tokens = min_t(u64, TOKEN_MAX,
entry->tokens + now -
entry->last_time_ns);
@@ -155,7 +155,7 @@ bool wg_ratelimiter_allow(struct sk_buff *skb, struct net *net)
entry->ip = ip;
INIT_HLIST_NODE(&entry->hash);
spin_lock_init(&entry->lock);
- entry->last_time_ns = ktime_get_boot_fast_ns();
+ entry->last_time_ns = ktime_get_coarse_boottime_ns();
entry->tokens = TOKEN_MAX - PACKET_COST;
spin_lock(&table_lock);
hlist_add_head_rcu(&entry->hash, bucket);