svn commit: r246999 - stable/7/sys/netinet

Mark Johnston markj at FreeBSD.org
Tue Feb 19 16:40:39 UTC 2013


Author: markj
Date: Tue Feb 19 16:40:38 2013
New Revision: 246999
URL: http://svnweb.freebsd.org/changeset/base/246999

Log:
  MFC r239672 (by rrs):
    This small change takes care of a race condition
    that can occur when both sides close at the same time.
    If that occurs, without this fix the connection enters
    FIN1 on both sides and they will forever send FIN|ACK at
    each other until the connection times out. This is because
    we stopped processing the FIN|ACK and thus did not advance
    the sequence and so never ACK'd each others FIN. This
    fix adjusts it so we *do* process the FIN properly and
    the race goes away ;-)
  
  Approved by:	rrs
  Approved by:	emaste (co-mentor)

Modified:
  stable/7/sys/netinet/tcp_input.c
Directory Properties:
  stable/7/sys/   (props changed)

Modified: stable/7/sys/netinet/tcp_input.c
==============================================================================
--- stable/7/sys/netinet/tcp_input.c	Tue Feb 19 16:40:16 2013	(r246998)
+++ stable/7/sys/netinet/tcp_input.c	Tue Feb 19 16:40:38 2013	(r246999)
@@ -1803,6 +1803,16 @@ tcp_do_segment(struct mbuf *m, struct tc
 						}
 					} else
 						tp->snd_cwnd += tp->t_maxseg;
+					if ((thflags & TH_FIN) &&
+					    (TCPS_HAVERCVDFIN(tp->t_state) == 0)) {
+						/* 
+						 * If its a fin we need to process
+						 * it to avoid a race where both
+						 * sides enter FIN-WAIT and send FIN|ACK
+						 * at the same time.
+						 */
+						break;
+					}
 					(void) tcp_output(tp);
 					goto drop;
 				} else if (tp->t_dupacks == tcprexmtthresh) {
@@ -1846,6 +1856,16 @@ tcp_do_segment(struct mbuf *m, struct tc
 					}
 					tp->snd_nxt = th->th_ack;
 					tp->snd_cwnd = tp->t_maxseg;
+					if ((thflags & TH_FIN) &&
+					    (TCPS_HAVERCVDFIN(tp->t_state) == 0)) {
+						/* 
+						 * If its a fin we need to process
+						 * it to avoid a race where both
+						 * sides enter FIN-WAIT and send FIN|ACK
+						 * at the same time.
+						 */
+						break;
+					}
 					(void) tcp_output(tp);
 					KASSERT(tp->snd_limited <= 2,
 					    ("%s: tp->snd_limited too big",
@@ -1871,6 +1891,16 @@ tcp_do_segment(struct mbuf *m, struct tc
 					    (tp->snd_nxt - tp->snd_una) +
 					    (tp->t_dupacks - tp->snd_limited) *
 					    tp->t_maxseg;
+					if ((thflags & TH_FIN) &&
+					    (TCPS_HAVERCVDFIN(tp->t_state) == 0)) {
+						/* 
+						 * If its a fin we need to process
+						 * it to avoid a race where both
+						 * sides enter FIN-WAIT and send FIN|ACK
+						 * at the same time.
+						 */
+						break;
+					}
 					(void) tcp_output(tp);
 					sent = tp->snd_max - oldsndmax;
 					if (sent > tp->t_maxseg) {


More information about the svn-src-stable-7 mailing list