tcp: syncookies: reduce cookie lifetime to 128 seconds
[deliverable/linux.git] / net / ipv6 / syncookies.c
index bf63ac8a49b9df8601a5e0dabc4074e65007f94b..13ca0a0ea68003e1937cb45b0d6bc2c24b4773f0 100644 (file)
@@ -36,14 +36,6 @@ static __u16 const msstab[] = {
        9000 - 60,
 };
 
-/*
- * This (misnamed) value is the age of syncookie which is permitted.
- * Its ideal value should be dependent on TCP_TIMEOUT_INIT and
- * sysctl_tcp_retries1. It's a rather complicated formula (exponential
- * backoff) to compute at runtime so it's currently hardcoded here.
- */
-#define COUNTER_TRIES 4
-
 static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb,
                                           struct request_sock *req,
                                           struct dst_entry *dst)
@@ -86,8 +78,9 @@ static u32 cookie_hash(const struct in6_addr *saddr, const struct in6_addr *dadd
 static __u32 secure_tcp_syn_cookie(const struct in6_addr *saddr,
                                   const struct in6_addr *daddr,
                                   __be16 sport, __be16 dport, __u32 sseq,
-                                  __u32 count, __u32 data)
+                                  __u32 data)
 {
+       u32 count = tcp_cookie_time();
        return (cookie_hash(saddr, daddr, sport, dport, 0, 0) +
                sseq + (count << COOKIEBITS) +
                ((cookie_hash(saddr, daddr, sport, dport, count, 1) + data)
@@ -96,15 +89,14 @@ static __u32 secure_tcp_syn_cookie(const struct in6_addr *saddr,
 
 static __u32 check_tcp_syn_cookie(__u32 cookie, const struct in6_addr *saddr,
                                  const struct in6_addr *daddr, __be16 sport,
-                                 __be16 dport, __u32 sseq, __u32 count,
-                                 __u32 maxdiff)
+                                 __be16 dport, __u32 sseq)
 {
-       __u32 diff;
+       __u32 diff, count = tcp_cookie_time();
 
        cookie -= cookie_hash(saddr, daddr, sport, dport, 0, 0) + sseq;
 
        diff = (count - (cookie >> COOKIEBITS)) & ((__u32) -1 >> COOKIEBITS);
-       if (diff >= maxdiff)
+       if (diff >= MAX_SYNCOOKIE_AGE)
                return (__u32)-1;
 
        return (cookie -
@@ -125,8 +117,7 @@ u32 __cookie_v6_init_sequence(const struct ipv6hdr *iph,
        *mssp = msstab[mssind];
 
        return secure_tcp_syn_cookie(&iph->saddr, &iph->daddr, th->source,
-                                    th->dest, ntohl(th->seq),
-                                    jiffies / (HZ * 60), mssind);
+                                    th->dest, ntohl(th->seq), mssind);
 }
 EXPORT_SYMBOL_GPL(__cookie_v6_init_sequence);
 
@@ -146,8 +137,7 @@ int __cookie_v6_check(const struct ipv6hdr *iph, const struct tcphdr *th,
 {
        __u32 seq = ntohl(th->seq) - 1;
        __u32 mssind = check_tcp_syn_cookie(cookie, &iph->saddr, &iph->daddr,
-                                           th->source, th->dest, seq,
-                                           jiffies / (HZ * 60), COUNTER_TRIES);
+                                           th->source, th->dest, seq);
 
        return mssind < ARRAY_SIZE(msstab) ? msstab[mssind] : 0;
 }
This page took 0.091736 seconds and 5 git commands to generate.