Index: sys/netinet/tcp_input.c =================================================================== --- sys/netinet/tcp_input.c +++ sys/netinet/tcp_input.c @@ -3191,15 +3191,9 @@ * when trimming from the head. */ tcp_seq temp = save_start; - if (tlen || (th->th_seq != tp->rcv_nxt)) { - /* - * We add the th_seq != rcv_nxt to - * catch the case of a stand alone out - * of order FIN. - */ - thflags = tcp_reass(tp, th, &temp, &tlen, m); - tp->t_flags |= TF_ACKNOW; - } + + thflags = tcp_reass(tp, th, &temp, &tlen, m); + tp->t_flags |= TF_ACKNOW; } if ((tp->t_flags & TF_SACK_PERMIT) && (save_tlen > 0) && Index: sys/netinet/tcp_reass.c =================================================================== --- sys/netinet/tcp_reass.c +++ sys/netinet/tcp_reass.c @@ -571,6 +571,7 @@ * the rcv_nxt <-> rcv_wnd but thats * already done for us by the caller. */ +strip_fin: #ifdef TCP_REASS_COUNTERS counter_u64_add(tcp_zero_input, 1); #endif @@ -579,6 +580,19 @@ tcp_reass_log_dump(tp); #endif return (0); + } else if ((*tlenp == 0) && + (th->th_flags & TH_FIN) && + !TCPS_HAVEESTABLISHED(tp->t_state)) { + /* + * We have not established, and we + * have a FIN and no data. Lets treat + * this as the same as if the FIN were + * not present. We don't want to save + * the FIN bit in a reassembly buffer + * we want to get established first before + * we do that (the peer will retransmit). + */ + goto strip_fin; } /* * Will it fit? Index: sys/netinet/tcp_stacks/bbr.c =================================================================== --- sys/netinet/tcp_stacks/bbr.c +++ sys/netinet/tcp_stacks/bbr.c @@ -8320,15 +8320,9 @@ * trimming from the head. */ tcp_seq temp = save_start; - if (tlen || (th->th_seq != tp->rcv_nxt)) { - /* - * We add the th_seq != rcv_nxt to - * catch the case of a stand alone out - * of order FIN. - */ - thflags = tcp_reass(tp, th, &temp, &tlen, m); - tp->t_flags |= TF_ACKNOW; - } + + thflags = tcp_reass(tp, th, &temp, &tlen, m); + tp->t_flags |= TF_ACKNOW; } if ((tp->t_flags & TF_SACK_PERMIT) && (save_tlen > 0) && Index: sys/netinet/tcp_stacks/rack.c =================================================================== --- sys/netinet/tcp_stacks/rack.c +++ sys/netinet/tcp_stacks/rack.c @@ -10235,15 +10235,10 @@ * trimming from the head. */ tcp_seq temp = save_start; - if (tlen || (th->th_seq != tp->rcv_nxt)) { - /* - * We add the th_seq != rcv_nxt to - * catch the case of a stand alone out - * of order FIN. - */ - thflags = tcp_reass(tp, th, &temp, &tlen, m); - tp->t_flags |= TF_ACKNOW; - } + + thflags = tcp_reass(tp, th, &temp, &tlen, m); + tp->t_flags |= TF_ACKNOW; + } if ((tp->t_flags & TF_SACK_PERMIT) && (save_tlen > 0) && Index: sys/netinet/tcp_usrreq.c =================================================================== --- sys/netinet/tcp_usrreq.c +++ sys/netinet/tcp_usrreq.c @@ -2647,22 +2647,6 @@ tcp_state_change(tp, TCPS_LAST_ACK); break; } - if ((tp->t_state == TCPS_LAST_ACK) && - (tp->t_flags & TF_SENTFIN)) { - /* - * If we have reached LAST_ACK, and - * we sent a FIN (e.g. via MSG_EOR), then - * we really should move to either FIN_WAIT_1 - * or FIN_WAIT_2 depending on snd_max/snd_una. - */ - if (tp->snd_una == tp->snd_max) { - /* The FIN is acked */ - tcp_state_change(tp, TCPS_FIN_WAIT_2); - } else { - /* The FIN is still outstanding */ - tcp_state_change(tp, TCPS_FIN_WAIT_1); - } - } if (tp->t_state >= TCPS_FIN_WAIT_2) { soisdisconnected(tp->t_inpcb->inp_socket); /* Prevent the connection hanging in FIN_WAIT_2 forever. */