Commit 63262315 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

tcp: syncookies: do not use getnstimeofday()

While it is true that getnstimeofday() uses about 40 cycles if TSC
is available, it can use 1600 cycles if hpet is the clocksource.

Switch to get_jiffies_64(), as this is more than enough, and
go back to 60 seconds periods.

Fixes: 8c27bd75 ("tcp: syncookies: reduce cookie lifetime to 128 seconds")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Cc: Florian Westphal <fw@strlen.de>
Acked-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 88050049
...@@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, ...@@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
#ifdef CONFIG_SYN_COOKIES #ifdef CONFIG_SYN_COOKIES
#include <linux/ktime.h> #include <linux/ktime.h>
/* Syncookies use a monotonic timer which increments every 64 seconds. /* Syncookies use a monotonic timer which increments every 60 seconds.
* This counter is used both as a hash input and partially encoded into * This counter is used both as a hash input and partially encoded into
* the cookie value. A cookie is only validated further if the delta * the cookie value. A cookie is only validated further if the delta
* between the current counter value and the encoded one is less than this, * between the current counter value and the encoded one is less than this,
* i.e. a sent cookie is valid only at most for 128 seconds (or less if * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
* the counter advances immediately after a cookie is generated). * the counter advances immediately after a cookie is generated).
*/ */
#define MAX_SYNCOOKIE_AGE 2 #define MAX_SYNCOOKIE_AGE 2
static inline u32 tcp_cookie_time(void) static inline u32 tcp_cookie_time(void)
{ {
struct timespec now; u64 val = get_jiffies_64();
getnstimeofday(&now);
return now.tv_sec >> 6; /* 64 seconds granularity */ do_div(val, 60 * HZ);
return val;
} }
u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th, u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment