History

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.

Eric Dumazet committed 12 years ago

Commit 63262311 parent 88050041 file · +6 −5Browse files

Unified · Split

include/net/tcp.h+6−5
@@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, · 479 unmodified lines
480#ifdef CONFIG_SYN_COOKIES480#ifdef CONFIG_SYN_COOKIES
481#include <linux/ktime.h>481#include <linux/ktime.h>
482 482
483/* Syncookies use a monotonic timer which increments every 64 seconds.483/* Syncookies use a monotonic timer which increments every 60 seconds.
484 * This counter is used both as a hash input and partially encoded into484 * This counter is used both as a hash input and partially encoded into
485 * the cookie value. A cookie is only validated further if the delta485 * the cookie value. A cookie is only validated further if the delta
486 * between the current counter value and the encoded one is less than this,486 * between the current counter value and the encoded one is less than this,
487 * i.e. a sent cookie is valid only at most for 128 seconds (or less if487 * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
488 * the counter advances immediately after a cookie is generated).488 * the counter advances immediately after a cookie is generated).
489 */489 */
490#define MAX_SYNCOOKIE_AGE 2490#define MAX_SYNCOOKIE_AGE 2
491 491
492static inline u32 tcp_cookie_time(void)492static inline u32 tcp_cookie_time(void)
493{493{
494 struct timespec now;494 u64 val = get_jiffies_64();
495 getnstimeofday(&now);495
496 return now.tv_sec >> 6; /* 64 seconds granularity */496 do_div(val, 60 * HZ);
497 return val;
497}498}
498 499
499u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,500u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t