|
@@ -89,8 +89,7 @@ __u32 cookie_init_timestamp(struct request_sock *req)
|
|
|
|
|
|
|
|
|
static __u32 secure_tcp_syn_cookie(__be32 saddr, __be32 daddr, __be16 sport,
|
|
|
- __be16 dport, __u32 sseq, __u32 count,
|
|
|
- __u32 data)
|
|
|
+ __be16 dport, __u32 sseq, __u32 data)
|
|
|
{
|
|
|
/*
|
|
|
* Compute the secure sequence number.
|
|
@@ -102,7 +101,7 @@ static __u32 secure_tcp_syn_cookie(__be32 saddr, __be32 daddr, __be16 sport,
|
|
|
* As an extra hack, we add a small "data" value that encodes the
|
|
|
* MSS into the second hash value.
|
|
|
*/
|
|
|
-
|
|
|
+ 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)
|
|
@@ -114,22 +113,21 @@ static __u32 secure_tcp_syn_cookie(__be32 saddr, __be32 daddr, __be16 sport,
|
|
|
* If the syncookie is bad, the data returned will be out of
|
|
|
* range. This must be checked by the caller.
|
|
|
*
|
|
|
- * The count value used to generate the cookie must be within
|
|
|
- * "maxdiff" if the current (passed-in) "count". The return value
|
|
|
- * is (__u32)-1 if this test fails.
|
|
|
+ * The count value used to generate the cookie must be less than
|
|
|
+ * MAX_SYNCOOKIE_AGE minutes in the past.
|
|
|
+ * The return value (__u32)-1 if this test fails.
|
|
|
*/
|
|
|
static __u32 check_tcp_syn_cookie(__u32 cookie, __be32 saddr, __be32 daddr,
|
|
|
- __be16 sport, __be16 dport, __u32 sseq,
|
|
|
- __u32 count, __u32 maxdiff)
|
|
|
+ __be16 sport, __be16 dport, __u32 sseq)
|
|
|
{
|
|
|
- __u32 diff;
|
|
|
+ u32 diff, count = tcp_cookie_time();
|
|
|
|
|
|
/* Strip away the layers from the cookie */
|
|
|
cookie -= cookie_hash(saddr, daddr, sport, dport, 0, 0) + sseq;
|
|
|
|
|
|
/* Cookie is now reduced to (count * 2^24) ^ (hash % 2^24) */
|
|
|
diff = (count - (cookie >> COOKIEBITS)) & ((__u32) - 1 >> COOKIEBITS);
|
|
|
- if (diff >= maxdiff)
|
|
|
+ if (diff >= MAX_SYNCOOKIE_AGE)
|
|
|
return (__u32)-1;
|
|
|
|
|
|
return (cookie -
|
|
@@ -173,7 +171,7 @@ u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
|
|
|
|
|
|
return secure_tcp_syn_cookie(iph->saddr, iph->daddr,
|
|
|
th->source, th->dest, ntohl(th->seq),
|
|
|
- jiffies / (HZ * 60), mssind);
|
|
|
+ mssind);
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(__cookie_v4_init_sequence);
|
|
|
|
|
@@ -188,13 +186,6 @@ __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
|
|
|
return __cookie_v4_init_sequence(iph, th, mssp);
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
- * 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
|
|
|
/*
|
|
|
* Check if a ack sequence number is a valid syncookie.
|
|
|
* Return the decoded mss if it is, or 0 if not.
|
|
@@ -204,9 +195,7 @@ int __cookie_v4_check(const struct iphdr *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;
|
|
|
}
|