Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Aug 2008 17:27:42 GMT
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 147475 for review
Message-ID:  <200808151727.m7FHRgrw026015@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147475

Change 147475 by rpaulo@rpaulo_epsilon on 2008/08/15 17:27:41

	Don't crash too often. ;-)
	Fill rcvtime on SYN.
	Implement more timers so that connections don't stay up forever.
	Cope with some rxmits.

Affected files ...

.. //depot/projects/soc2008/rpaulo-tcpad/dumper.c#12 edit
.. //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#15 edit
.. //depot/projects/soc2008/rpaulo-tcpad/timer.c#10 edit
.. //depot/projects/soc2008/rpaulo-tcpad/verify.c#11 edit

Differences ...

==== //depot/projects/soc2008/rpaulo-tcpad/dumper.c#12 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2008/rpaulo-tcpad/dumper.c#11 $
+ * $P4: //depot/projects/soc2008/rpaulo-tcpad/dumper.c#12 $
  */
 
 #include <assert.h>
@@ -188,4 +188,5 @@
 		p1 = p2;
 	}
 	free(head);
+	cp->pktshead = NULL;
 }

==== //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#15 (text+ko) ====

@@ -23,14 +23,16 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#14 $
+ * $P4: //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#15 $
  */
 
 #ifndef _TCPAD_H_
 #define _TCPAD_H_
 
 #define TCPAD_VERSION	"0.1"
-#define	TCPAD_MSL	30	/* sec. */
+#define	TCPAD_TCPMSL	30	/* sec. */
+#define	TCPAD_TCPETO	900	/* ESTABLISHED timeout */
+#define	TCPAD_TCPTO	240	/* other states timeout */
 
 /* Globals */
 pcap_t *p;

==== //depot/projects/soc2008/rpaulo-tcpad/timer.c#10 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2008/rpaulo-tcpad/timer.c#9 $
+ * $P4: //depot/projects/soc2008/rpaulo-tcpad/timer.c#10 $
  */
 
 #include <assert.h>
@@ -83,14 +83,29 @@
 {
         struct tcpc *cp, *cp_t;
 	int nc;
+	unsigned int maxtime;
 	static int prevnc;
+	struct tcpcb *tp;
 
 	nc = 0;
         LIST_FOREACH_SAFE(cp, &tcpchead, entries, cp_t) {
 		nc++;
-		if (cp->tcb.t_state == TCPS_TIME_WAIT &&
-		    (time(NULL) - cp->tcb.t_rcvtime >= 2 * TCPAD_MSL)) {
-			DPRINTF(DEBUG_TIMER, "2 MSL timer went off: %p\n",
+		if (cp == NULL)
+			break;
+		tp = &cp->tcb;
+		switch (tp->t_state) {
+		case TCPS_TIME_WAIT:
+			maxtime = 2 * TCPAD_TCPMSL;
+			break;
+		case TCPS_ESTABLISHED:
+			maxtime = TCPAD_TCPETO;
+			break;
+		default:
+			maxtime = TCPAD_TCPTO;
+			break;
+		}
+		if (tp->t_rcvtime && (time(NULL) - tp->t_rcvtime) >= maxtime) {
+			DPRINTF(DEBUG_TIMER, "timer went off: %p\n",
 			    cp);
 			LIST_REMOVE(cp, entries);
 			if (cp->pktshead)

==== //depot/projects/soc2008/rpaulo-tcpad/verify.c#11 (text+ko) ====

@@ -23,7 +23,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $P4: //depot/projects/soc2008/rpaulo-tcpad/verify.c#10 $
+ * $P4: //depot/projects/soc2008/rpaulo-tcpad/verify.c#11 $
  */
 
 #include <stdio.h>
@@ -117,6 +117,7 @@
 		tp->snd_wnd = th->th_win;
 		tp->snd_wl1 = th->th_seq;
 		tp->snd_wl2 = th->th_ack;
+		tp->t_rcvtime = time(NULL);
 		tcpad_verify_topts(topts, tp, th->th_flags,
 		    TCPAD_VERIFY_DIRECTION_OUT);
 	}
@@ -259,6 +260,7 @@
 		tp->irs = th->th_seq;
 		tp->rcv_nxt = tp->irs + 1;
 		tp->rcv_wnd = th->th_win;
+		tp->t_rcvtime = time(NULL);
 		tcpad_verify_topts(topts, tp, th->th_flags,
 		    TCPAD_VERIFY_DIRECTION_IN);
 	}
@@ -446,7 +448,8 @@
 					    SEQ_GEQ(th->th_seq + tlen,
 						tp->rcv_nxt + tp->rcv_wnd))
 						printf("strange seq\n");
-					else
+					/* cope with retransmissions */
+					else if (SEQ_GT(th->th_seq, tp->rcv_nxt))
 						tp->rcv_nxt += tlen;
 
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808151727.m7FHRgrw026015>