* [PATCH v3] tcp: make retransmitted SKB fit into the send window
@ 2022-07-11 7:49 Yonglong Li
2022-07-11 9:06 ` Eric Dumazet
0 siblings, 1 reply; 3+ messages in thread
From: Yonglong Li @ 2022-07-11 7:49 UTC (permalink / raw)
To: netdev; +Cc: davem, dsahern, edumazet, kuba, pabeni, liyonglong
current code of __tcp_retransmit_skb only check TCP_SKB_CB(skb)->seq
in send window, and TCP_SKB_CB(skb)->seq_end maybe out of send window.
If receiver has shrunk his window, and skb is out of new window, it
should retransmit a smaller portion of the payload.
test packetdrill script:
0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+0 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR)
+0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
+0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
+0 > S 0:0(0) win 65535 <mss 1460,sackOK,TS val 100 ecr 0,nop,wscale 8>
+.05 < S. 0:0(0) ack 1 win 6000 <mss 1000,nop,nop,sackOK>
+0 > . 1:1(0) ack 1
+0 write(3, ..., 10000) = 10000
+0 > . 1:2001(2000) ack 1 win 65535
+0 > . 2001:4001(2000) ack 1 win 65535
+0 > . 4001:6001(2000) ack 1 win 65535
+.05 < . 1:1(0) ack 4001 win 1001
and tcpdump show:
192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 1:2001, ack 1, win 65535, length 2000
192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 2001:4001, ack 1, win 65535, length 2000
192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000
192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000
192.0.2.1.8080 > 192.168.226.67.55: Flags [.], ack 4001, win 1001, length 0
192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000
192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000
when cient retract window to 1001, send window is [4001,5002],
but TLP send 5001-6001 packet which is out of send window.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
---
net/ipv4/tcp_output.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 18c913a..efd0f05 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -3100,7 +3100,6 @@ static bool tcp_can_collapse(const struct sock *sk, const struct sk_buff *skb)
static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
int space)
{
- struct tcp_sock *tp = tcp_sk(sk);
struct sk_buff *skb = to, *tmp;
bool first = true;
@@ -3123,14 +3122,18 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
continue;
}
- if (space < 0)
- break;
-
- if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp)))
+ if (space < 0) {
+ if (unlikely(tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE,
+ skb, space + skb->len,
+ tcp_current_mss(sk), GFP_ATOMIC)))
+ break;
+ tcp_collapse_retrans(sk, to);
break;
+ }
if (!tcp_collapse_retrans(sk, to))
break;
+
}
}
@@ -3144,7 +3147,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
struct tcp_sock *tp = tcp_sk(sk);
unsigned int cur_mss;
int diff, len, err;
-
+ int avail_wnd;
/* Inconclusive MTU probe */
if (icsk->icsk_mtup.probe_size)
@@ -3166,17 +3169,25 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
return -EHOSTUNREACH; /* Routing failure or similar. */
cur_mss = tcp_current_mss(sk);
+ avail_wnd = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq;
/* If receiver has shrunk his window, and skb is out of
* new window, do not retransmit it. The exception is the
* case, when window is shrunk to zero. In this case
- * our retransmit serves as a zero window probe.
+ * our retransmit of one segment serves as a zero window probe.
*/
- if (!before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp)) &&
- TCP_SKB_CB(skb)->seq != tp->snd_una)
- return -EAGAIN;
+ if (avail_wnd <= 0) {
+ if (TCP_SKB_CB(skb)->seq != tp->snd_una)
+ return -EAGAIN;
+ avail_wnd = cur_mss;
+ }
len = cur_mss * segs;
+ if (len > avail_wnd) {
+ len = rounddown(avail_wnd, cur_mss);
+ if (!len)
+ len = avail_wnd;
+ }
if (skb->len > len) {
if (tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE, skb, len,
cur_mss, GFP_ATOMIC))
@@ -3190,8 +3201,9 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
diff -= tcp_skb_pcount(skb);
if (diff)
tcp_adjust_pcount(sk, skb, diff);
- if (skb->len < cur_mss)
- tcp_retrans_try_collapse(sk, skb, cur_mss);
+ avail_wnd = min_t(int, avail_wnd, cur_mss);
+ if (skb->len < avail_wnd)
+ tcp_retrans_try_collapse(sk, skb, avail_wnd);
}
/* RFC3168, section 6.1.1.1. ECN fallback */
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] tcp: make retransmitted SKB fit into the send window
2022-07-11 7:49 [PATCH v3] tcp: make retransmitted SKB fit into the send window Yonglong Li
@ 2022-07-11 9:06 ` Eric Dumazet
2022-07-11 9:34 ` Yonglong Li
0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2022-07-11 9:06 UTC (permalink / raw)
To: Yonglong Li
Cc: netdev, David Miller, David Ahern, Jakub Kicinski, Paolo Abeni
On Mon, Jul 11, 2022 at 9:56 AM Yonglong Li <liyonglong@chinatelecom.cn> wrote:
>
> current code of __tcp_retransmit_skb only check TCP_SKB_CB(skb)->seq
> in send window, and TCP_SKB_CB(skb)->seq_end maybe out of send window.
> If receiver has shrunk his window, and skb is out of new window, it
> should retransmit a smaller portion of the payload.
>
> test packetdrill script:
> 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
> +0 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR)
> +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
>
> +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
> +0 > S 0:0(0) win 65535 <mss 1460,sackOK,TS val 100 ecr 0,nop,wscale 8>
> +.05 < S. 0:0(0) ack 1 win 6000 <mss 1000,nop,nop,sackOK>
> +0 > . 1:1(0) ack 1
>
> +0 write(3, ..., 10000) = 10000
>
> +0 > . 1:2001(2000) ack 1 win 65535
> +0 > . 2001:4001(2000) ack 1 win 65535
> +0 > . 4001:6001(2000) ack 1 win 65535
>
> +.05 < . 1:1(0) ack 4001 win 1001
>
> and tcpdump show:
> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 1:2001, ack 1, win 65535, length 2000
> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 2001:4001, ack 1, win 65535, length 2000
> 192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000
> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000
> 192.0.2.1.8080 > 192.168.226.67.55: Flags [.], ack 4001, win 1001, length 0
> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000
> 192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000
>
> when cient retract window to 1001, send window is [4001,5002],
> but TLP send 5001-6001 packet which is out of send window.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
> ---
> net/ipv4/tcp_output.c | 36 ++++++++++++++++++++++++------------
> 1 file changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 18c913a..efd0f05 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -3100,7 +3100,6 @@ static bool tcp_can_collapse(const struct sock *sk, const struct sk_buff *skb)
> static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
> int space)
> {
> - struct tcp_sock *tp = tcp_sk(sk);
> struct sk_buff *skb = to, *tmp;
> bool first = true;
>
> @@ -3123,14 +3122,18 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
> continue;
> }
>
> - if (space < 0)
> - break;
> -
> - if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp)))
> + if (space < 0) {
> + if (unlikely(tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE,
> + skb, space + skb->len,
> + tcp_current_mss(sk), GFP_ATOMIC)))
What are you doing here ?
This seems wrong.
Can we please stick to the patch I sent earlier.
If you want to amend it later, you can do this in a separate patch,
with a clear explanation.
> + break;
> + tcp_collapse_retrans(sk, to);
> break;
> + }
>
> if (!tcp_collapse_retrans(sk, to))
> break;
> +
> }
> }
>
> @@ -3144,7 +3147,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
> struct tcp_sock *tp = tcp_sk(sk);
> unsigned int cur_mss;
> int diff, len, err;
> -
> + int avail_wnd;
>
> /* Inconclusive MTU probe */
> if (icsk->icsk_mtup.probe_size)
> @@ -3166,17 +3169,25 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
> return -EHOSTUNREACH; /* Routing failure or similar. */
>
> cur_mss = tcp_current_mss(sk);
> + avail_wnd = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq;
>
> /* If receiver has shrunk his window, and skb is out of
> * new window, do not retransmit it. The exception is the
> * case, when window is shrunk to zero. In this case
> - * our retransmit serves as a zero window probe.
> + * our retransmit of one segment serves as a zero window probe.
> */
> - if (!before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp)) &&
> - TCP_SKB_CB(skb)->seq != tp->snd_una)
> - return -EAGAIN;
> + if (avail_wnd <= 0) {
> + if (TCP_SKB_CB(skb)->seq != tp->snd_una)
> + return -EAGAIN;
> + avail_wnd = cur_mss;
> + }
>
> len = cur_mss * segs;
> + if (len > avail_wnd) {
> + len = rounddown(avail_wnd, cur_mss);
> + if (!len)
> + len = avail_wnd;
> + }
> if (skb->len > len) {
> if (tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE, skb, len,
> cur_mss, GFP_ATOMIC))
> @@ -3190,8 +3201,9 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
> diff -= tcp_skb_pcount(skb);
> if (diff)
> tcp_adjust_pcount(sk, skb, diff);
> - if (skb->len < cur_mss)
> - tcp_retrans_try_collapse(sk, skb, cur_mss);
> + avail_wnd = min_t(int, avail_wnd, cur_mss);
> + if (skb->len < avail_wnd)
> + tcp_retrans_try_collapse(sk, skb, avail_wnd);
> }
>
> /* RFC3168, section 6.1.1.1. ECN fallback */
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] tcp: make retransmitted SKB fit into the send window
2022-07-11 9:06 ` Eric Dumazet
@ 2022-07-11 9:34 ` Yonglong Li
0 siblings, 0 replies; 3+ messages in thread
From: Yonglong Li @ 2022-07-11 9:34 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev, David Miller, David Ahern, Jakub Kicinski, Paolo Abeni
On 7/11/2022 5:06 PM, Eric Dumazet wrote:
> On Mon, Jul 11, 2022 at 9:56 AM Yonglong Li <liyonglong@chinatelecom.cn> wrote:
>>
>> current code of __tcp_retransmit_skb only check TCP_SKB_CB(skb)->seq
>> in send window, and TCP_SKB_CB(skb)->seq_end maybe out of send window.
>> If receiver has shrunk his window, and skb is out of new window, it
>> should retransmit a smaller portion of the payload.
>>
>> test packetdrill script:
>> 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
>> +0 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR)
>> +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
>>
>> +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
>> +0 > S 0:0(0) win 65535 <mss 1460,sackOK,TS val 100 ecr 0,nop,wscale 8>
>> +.05 < S. 0:0(0) ack 1 win 6000 <mss 1000,nop,nop,sackOK>
>> +0 > . 1:1(0) ack 1
>>
>> +0 write(3, ..., 10000) = 10000
>>
>> +0 > . 1:2001(2000) ack 1 win 65535
>> +0 > . 2001:4001(2000) ack 1 win 65535
>> +0 > . 4001:6001(2000) ack 1 win 65535
>>
>> +.05 < . 1:1(0) ack 4001 win 1001
>>
>> and tcpdump show:
>> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 1:2001, ack 1, win 65535, length 2000
>> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 2001:4001, ack 1, win 65535, length 2000
>> 192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000
>> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000
>> 192.0.2.1.8080 > 192.168.226.67.55: Flags [.], ack 4001, win 1001, length 0
>> 192.168.226.67.55 > 192.0.2.1.8080: Flags [.], seq 5001:6001, ack 1, win 65535, length 1000
>> 192.168.226.67.55 > 192.0.2.1.8080: Flags [P.], seq 4001:5001, ack 1, win 65535, length 1000
>>
>> when cient retract window to 1001, send window is [4001,5002],
>> but TLP send 5001-6001 packet which is out of send window.
>>
>> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>> Signed-off-by: Yonglong Li <liyonglong@chinatelecom.cn>
>> ---
>> net/ipv4/tcp_output.c | 36 ++++++++++++++++++++++++------------
>> 1 file changed, 24 insertions(+), 12 deletions(-)
>>
>> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
>> index 18c913a..efd0f05 100644
>> --- a/net/ipv4/tcp_output.c
>> +++ b/net/ipv4/tcp_output.c
>> @@ -3100,7 +3100,6 @@ static bool tcp_can_collapse(const struct sock *sk, const struct sk_buff *skb)
>> static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
>> int space)
>> {
>> - struct tcp_sock *tp = tcp_sk(sk);
>> struct sk_buff *skb = to, *tmp;
>> bool first = true;
>>
>> @@ -3123,14 +3122,18 @@ static void tcp_retrans_try_collapse(struct sock *sk, struct sk_buff *to,
>> continue;
>> }
>>
>> - if (space < 0)
>> - break;
>> -
>> - if (after(TCP_SKB_CB(skb)->end_seq, tcp_wnd_end(tp)))
>> + if (space < 0) {
>> + if (unlikely(tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE,
>> + skb, space + skb->len,
>> + tcp_current_mss(sk), GFP_ATOMIC)))
>
> What are you doing here ?
>
> This seems wrong.
I think we can collapse more data if skb->len < avail_wnd. If you think doing this is wrong
I will remove it.
>
> Can we please stick to the patch I sent earlier.
>
> If you want to amend it later, you can do this in a separate patch,
> with a clear explanation.
>
>> + break;
>> + tcp_collapse_retrans(sk, to);
>> break;
>> + }
>>
>> if (!tcp_collapse_retrans(sk, to))
>> break;
>> +
>> }
>> }
>>
>> @@ -3144,7 +3147,7 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
>> struct tcp_sock *tp = tcp_sk(sk);
>> unsigned int cur_mss;
>> int diff, len, err;
>> -
>> + int avail_wnd;
>>
>> /* Inconclusive MTU probe */
>> if (icsk->icsk_mtup.probe_size)
>> @@ -3166,17 +3169,25 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
>> return -EHOSTUNREACH; /* Routing failure or similar. */
>>
>> cur_mss = tcp_current_mss(sk);
>> + avail_wnd = tcp_wnd_end(tp) - TCP_SKB_CB(skb)->seq;
>>
>> /* If receiver has shrunk his window, and skb is out of
>> * new window, do not retransmit it. The exception is the
>> * case, when window is shrunk to zero. In this case
>> - * our retransmit serves as a zero window probe.
>> + * our retransmit of one segment serves as a zero window probe.
>> */
>> - if (!before(TCP_SKB_CB(skb)->seq, tcp_wnd_end(tp)) &&
>> - TCP_SKB_CB(skb)->seq != tp->snd_una)
>> - return -EAGAIN;
>> + if (avail_wnd <= 0) {
>> + if (TCP_SKB_CB(skb)->seq != tp->snd_una)
>> + return -EAGAIN;
>> + avail_wnd = cur_mss;
>> + }
>>
>> len = cur_mss * segs;
>> + if (len > avail_wnd) {
>> + len = rounddown(avail_wnd, cur_mss);
>> + if (!len)
>> + len = avail_wnd;
>> + }
>> if (skb->len > len) {
>> if (tcp_fragment(sk, TCP_FRAG_IN_RTX_QUEUE, skb, len,
>> cur_mss, GFP_ATOMIC))
>> @@ -3190,8 +3201,9 @@ int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs)
>> diff -= tcp_skb_pcount(skb);
>> if (diff)
>> tcp_adjust_pcount(sk, skb, diff);
>> - if (skb->len < cur_mss)
>> - tcp_retrans_try_collapse(sk, skb, cur_mss);
>> + avail_wnd = min_t(int, avail_wnd, cur_mss);
>> + if (skb->len < avail_wnd)
>> + tcp_retrans_try_collapse(sk, skb, avail_wnd);
>> }
>>
>> /* RFC3168, section 6.1.1.1. ECN fallback */
>> --
>> 1.8.3.1
>>
>
--
Li YongLong
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-11 10:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-11 7:49 [PATCH v3] tcp: make retransmitted SKB fit into the send window Yonglong Li
2022-07-11 9:06 ` Eric Dumazet
2022-07-11 9:34 ` Yonglong Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).