Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 203187
b: refs/heads/master
c: 734f614
h: refs/heads/master
i:
  203185: 9c0b589
  203183: a001139
v: v3
  • Loading branch information
Florian Westphal authored and David S. Miller committed Jun 27, 2010
1 parent 55f97eb commit 2d1428d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9587c6ddd452314e8ed5707ad832a507a030ef57
refs/heads/master: 734f614bc1e7c6bf075d201f6bd9a555b8b4a984
35 changes: 14 additions & 21 deletions trunk/net/ipv4/syncookies.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <net/tcp.h>
#include <net/route.h>

/* Timestamps: lowest 9 bits store TCP options */
#define TSBITS 9
/* Timestamps: lowest bits store TCP options */
#define TSBITS 5
#define TSMASK (((__u32)1 << TSBITS) - 1)

extern int sysctl_tcp_syncookies;
Expand Down Expand Up @@ -58,7 +58,7 @@ static u32 cookie_hash(__be32 saddr, __be32 daddr, __be16 sport, __be16 dport,

/*
* when syncookies are in effect and tcp timestamps are enabled we encode
* tcp options in the lowest 9 bits of the timestamp value that will be
* tcp options in the lower bits of the timestamp value that will be
* sent in the syn-ack.
* Since subsequent timestamps use the normal tcp_time_stamp value, we
* must make sure that the resulting initial timestamp is <= tcp_time_stamp.
Expand All @@ -70,11 +70,9 @@ __u32 cookie_init_timestamp(struct request_sock *req)
u32 options = 0;

ireq = inet_rsk(req);
if (ireq->wscale_ok) {
options = ireq->snd_wscale;
options |= ireq->rcv_wscale << 4;
}
options |= ireq->sack_ok << 8;

options = ireq->wscale_ok ? ireq->snd_wscale : 0xf;
options |= ireq->sack_ok << 4;

ts = ts_now & ~TSMASK;
ts |= options;
Expand Down Expand Up @@ -227,15 +225,14 @@ static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb,
* additional tcp options in the timestamp.
* This extracts these options from the timestamp echo.
*
* The lowest 4 bits are for snd_wscale
* The next 4 lsb are for rcv_wscale
* The lowest 4 bits store snd_wscale.
* The next lsb is for sack_ok
*
* return false if we decode an option that should not be.
*/
bool cookie_check_timestamp(struct tcp_options_received *tcp_opt)
{
/* echoed timestamp, 9 lowest bits contain options */
/* echoed timestamp, lowest bits contain options */
u32 options = tcp_opt->rcv_tsecr & TSMASK;

if (!tcp_opt->saw_tstamp) {
Expand All @@ -246,20 +243,17 @@ bool cookie_check_timestamp(struct tcp_options_received *tcp_opt)
if (!sysctl_tcp_timestamps)
return false;

tcp_opt->snd_wscale = options & 0xf;
options >>= 4;
tcp_opt->rcv_wscale = options & 0xf;

tcp_opt->sack_ok = (options >> 4) & 0x1;

if (tcp_opt->sack_ok && !sysctl_tcp_sack)
return false;

if (tcp_opt->snd_wscale || tcp_opt->rcv_wscale) {
tcp_opt->wscale_ok = 1;
return sysctl_tcp_window_scaling != 0;
}
return true;
if ((options & 0xf) == 0xf)
return true; /* no window scaling */

tcp_opt->wscale_ok = 1;
tcp_opt->snd_wscale = options & 0xf;
return sysctl_tcp_window_scaling != 0;
}
EXPORT_SYMBOL(cookie_check_timestamp);

Expand Down Expand Up @@ -313,7 +307,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
ireq->rmt_addr = ip_hdr(skb)->saddr;
ireq->ecn_ok = 0;
ireq->snd_wscale = tcp_opt.snd_wscale;
ireq->rcv_wscale = tcp_opt.rcv_wscale;
ireq->sack_ok = tcp_opt.sack_ok;
ireq->wscale_ok = tcp_opt.wscale_ok;
ireq->tstamp_ok = tcp_opt.saw_tstamp;
Expand Down
1 change: 0 additions & 1 deletion trunk/net/ipv6/syncookies.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
req->retrans = 0;
ireq->ecn_ok = 0;
ireq->snd_wscale = tcp_opt.snd_wscale;
ireq->rcv_wscale = tcp_opt.rcv_wscale;
ireq->sack_ok = tcp_opt.sack_ok;
ireq->wscale_ok = tcp_opt.wscale_ok;
ireq->tstamp_ok = tcp_opt.saw_tstamp;
Expand Down

0 comments on commit 2d1428d

Please sign in to comment.