Commit 795a7dfb authored by Menglong Dong's avatar Menglong Dong Committed by Jakub Kicinski

net: tcp: accept old ack during closing

For now, the packet with an old ack is not accepted if we are in
FIN_WAIT1 state, which can cause retransmission. Taking the following
case as an example:

    Client                               Server
      |                                    |
  FIN_WAIT1(Send FIN, seq=10)          FIN_WAIT1(Send FIN, seq=20, ack=10)
      |                                    |
      |                                Send ACK(seq=21, ack=11)
   Recv ACK(seq=21, ack=11)
      |
   Recv FIN(seq=20, ack=10)

In the case above, simultaneous close is happening, and the FIN and ACK
packet that send from the server is out of order. Then, the FIN will be
dropped by the client, as it has an old ack. Then, the server has to
retransmit the FIN, which can cause delay if the server has set the
SO_LINGER on the socket.

Old ack is accepted in the ESTABLISHED and TIME_WAIT state, and I think
it should be better to keep the same logic.

In this commit, we accept old ack in FIN_WAIT1/FIN_WAIT2/CLOSING/LAST_ACK
states. Maybe we should limit it to FIN_WAIT1 for now?
Signed-off-by: default avatarMenglong Dong <menglong8.dong@gmail.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20240126040519.1846345-1-menglong8.dong@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 67475eb9
...@@ -6699,17 +6699,21 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb) ...@@ -6699,17 +6699,21 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb)
return 0; return 0;
/* step 5: check the ACK field */ /* step 5: check the ACK field */
acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH | reason = tcp_ack(sk, skb, FLAG_SLOWPATH |
FLAG_UPDATE_TS_RECENT | FLAG_UPDATE_TS_RECENT |
FLAG_NO_CHALLENGE_ACK) > 0; FLAG_NO_CHALLENGE_ACK);
if (!acceptable) { if ((int)reason <= 0) {
if (sk->sk_state == TCP_SYN_RECV) if (sk->sk_state == TCP_SYN_RECV)
return 1; /* send one RST */ return 1; /* send one RST */
tcp_send_challenge_ack(sk); /* accept old ack during closing */
SKB_DR_SET(reason, TCP_OLD_ACK); if ((int)reason < 0) {
goto discard; tcp_send_challenge_ack(sk);
reason = -reason;
goto discard;
}
} }
SKB_DR_SET(reason, NOT_SPECIFIED);
switch (sk->sk_state) { switch (sk->sk_state) {
case TCP_SYN_RECV: case TCP_SYN_RECV:
tp->delivered++; /* SYN-ACK delivery isn't tracked in tcp_ack */ tp->delivered++; /* SYN-ACK delivery isn't tracked in tcp_ack */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment