git: d730ffcd6ad3 - stable/13 - tcp: Undo the consumption of sequence space by FIN in case of a transient error.

From: Richard Scheffenegger <rscheff_at_FreeBSD.org>
Date: Thu, 11 Jan 2024 00:41:27 UTC
The branch stable/13 has been updated by rscheff:

URL: https://cgit.FreeBSD.org/src/commit/?id=d730ffcd6ad3da47d9a1af00a534a78861280f54

commit d730ffcd6ad3da47d9a1af00a534a78861280f54
Author:     Richard Scheffenegger <rscheff@FreeBSD.org>
AuthorDate: 2022-07-14 00:49:10 +0000
Commit:     Richard Scheffenegger <rscheff@FreeBSD.org>
CommitDate: 2024-01-11 00:38:36 +0000

    tcp: Undo the consumption of sequence space by FIN in case of a transient error.
    
    If an error occurs while processing a TCP segment with some data and the FIN
    flag, the back out of the sequence number advance does not take into account the
    increase by 1 due to the FIN flag.
    
    Reviewed By: jch, gnn, #transport, tuexen
    Sponsored by: NetApp, Inc.
    Differential Revision: https://reviews.freebsd.org/D2970
    
    (cherry picked from commit 66605ff791b12a2c3bb4570379db0e14d29fca4c)
---
 sys/netinet/tcp_output.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c
index 3ed4d34fd061..3e1a2320f331 100644
--- a/sys/netinet/tcp_output.c
+++ b/sys/netinet/tcp_output.c
@@ -1684,8 +1684,13 @@ timer:
 				tp->sackhint.sack_bytes_rexmit -= len;
 				KASSERT(tp->sackhint.sack_bytes_rexmit >= 0,
 				    ("sackhint bytes rtx >= 0"));
-			} else
+				KASSERT((flags & TH_FIN) == 0,
+				    ("error while FIN with SACK rxmit"));
+			} else {
 				tp->snd_nxt -= len;
+				if (flags & TH_FIN)
+					tp->snd_nxt--;
+			}
 		}
 		SOCKBUF_UNLOCK_ASSERT(&so->so_snd);	/* Check gotos. */
 		switch (error) {