diff options
author | Patrick McHardy <kaber@trash.net> | 2008-03-20 16:11:27 -0700 |
---|---|---|
committer | Willy Tarreau <w@1wt.eu> | 2008-07-20 18:25:42 +0200 |
commit | a2a0bc826ea1cd30de2aec1130ed5c004bd0ef4f (patch) | |
tree | 6a46e213b4d68e6cae33af487b32b8b5d5a7bb11 | |
parent | fdbe5316972c6a8fd9993e38d80b74f5bd4c0894 (diff) | |
download | linux-2.4-a2a0bc826ea1cd30de2aec1130ed5c004bd0ef4f.tar.gz |
[TCP]: Fix shrinking windows with window scaling
[backported from 2.6 commit 607bfbf2d55dd1cfe5368b41c2a81a8c9ccf4723]
When selecting a new window, tcp_select_window() tries not to shrink
the offered window by using the maximum of the remaining offered window
size and the newly calculated window size. The newly calculated window
size is always a multiple of the window scaling factor, the remaining
window size however might not be since it depends on rcv_wup/rcv_nxt.
This means we're effectively shrinking the window when scaling it down.
The dump below shows the problem (scaling factor 2^7):
- Window size of 557 (71296) is advertised, up to 3111907257:
IP 172.2.2.3.33000 > 172.2.2.2.33000: . ack 3111835961 win 557 <...>
- New window size of 514 (65792) is advertised, up to 3111907217, 40 bytes
below the last end:
IP 172.2.2.3.33000 > 172.2.2.2.33000: . 3113575668:3113577116(1448) ack 3111841425 win 514 <...>
The number 40 results from downscaling the remaining window:
3111907257 - 3111841425 = 65832
65832 / 2^7 = 514
65832 % 2^7 = 40
If the sender uses up the entire window before it is shrunk, this can have
chaotic effects on the connection. When sending ACKs, tcp_acceptable_seq()
will notice that the window has been shrunk since tcp_wnd_end() is before
tp->snd_nxt, which makes it choose tcp_wnd_end() as sequence number.
This will fail the receivers checks in tcp_sequence() however since it
is before it's tp->rcv_wup, making it respond with a dupack.
If both sides are in this condition, this leads to a constant flood of
ACKs until the connection times out.
Make sure the window is never shrunk by aligning the remaining window to
the window scaling factor.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/ipv4/tcp_output.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 142eacceaeee2f..daa40d51b4b467 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -142,6 +142,10 @@ static __inline__ void tcp_event_ack_sent(struct sock *sk) tcp_clear_xmit_timer(sk, TCP_TIME_DACK); } +/* from 2.6's ALIGN, used in tcp_select_window() */ +#define ALIGN_WIN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) + /* Chose a new window to advertise, update state in tcp_opt for the * socket, and return result with RFC1323 scaling applied. The return * value can be stuffed directly into th->window for an outgoing @@ -162,7 +166,7 @@ static __inline__ u16 tcp_select_window(struct sock *sk) * * Relax Will Robinson. */ - new_win = cur_win; + new_win = ALIGN_WIN(cur_win, 1 << tp->rcv_wscale); } tp->rcv_wnd = new_win; tp->rcv_wup = tp->rcv_nxt; |