Subject: Re: Odd crashes in tcp_output (2.0ish)
To: Greg Troxel <gdt@ir.bbn.com>
From: Charles M. Hannum <abuse@spamalicious.com>
List: tech-net
Date: 01/26/2005 18:08:15
--Boundary-00=_Py99BtcbJziROre
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I think this should fix the problem, though I haven't actually tested it...

--Boundary-00=_Py99BtcbJziROre
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="tstamp.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="tstamp.diff"

Index: tcp_input.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/tcp_input.c,v
retrieving revision 1.212
diff -u -r1.212 tcp_input.c
--- tcp_input.c	21 Dec 2004 05:51:31 -0000	1.212
+++ tcp_input.c	26 Jan 2005 18:08:20 -0000
@@ -1495,6 +1495,16 @@
 		if (tcp_dooptions(tp, optp, optlen, th, m, toff, &opti) < 0)
 			goto drop;
 
+	if (opti.ts_present && opti.ts_ecr) {
+		/*
+		 * Calculate the RTT from the returned time stamp and the
+		 * connection's time base.  If the time stamp is later than
+		 * the current time, the RTT will be negative and we will
+		 * fall back to non-1323 RTT calculation.
+		 */
+		opti.ts_ecr = TCP_TIMESTAMP(tp) - opti.ts_ecr + 1;
+	}
+
 	/*
 	 * Header prediction: check for the two common cases
 	 * of a uni-directional data xfer.  If the packet has
@@ -1536,9 +1546,8 @@
 				 * this is a pure ack for outstanding data.
 				 */
 				++tcpstat.tcps_predack;
-				if (opti.ts_present && opti.ts_ecr)
-					tcp_xmit_timer(tp,
-					  TCP_TIMESTAMP(tp) - opti.ts_ecr + 1);
+				if (opti.ts_present && opti.ts_ecr > 0)
+					tcp_xmit_timer(tp, opti.ts_ecr);
 				else if (tp->t_rtttime &&
 				    SEQ_GT(th->th_ack, tp->t_rtseq))
 					tcp_xmit_timer(tp,
@@ -2166,8 +2175,8 @@
 		 * timer backoff (cf., Phil Karn's retransmit alg.).
 		 * Recompute the initial retransmit timer.
 		 */
-		if (opti.ts_present && opti.ts_ecr)
-			tcp_xmit_timer(tp, TCP_TIMESTAMP(tp) - opti.ts_ecr + 1);
+		if (opti.ts_present && opti.ts_ecr > 0)
+			tcp_xmit_timer(tp, opti.ts_ecr);
 		else if (tp->t_rtttime && SEQ_GT(th->th_ack, tp->t_rtseq))
 			tcp_xmit_timer(tp, tcp_now - tp->t_rtttime);
 

--Boundary-00=_Py99BtcbJziROre--