From owner-p4-projects@FreeBSD.ORG Fri Aug 15 17:27:43 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DA4D81065678; Fri, 15 Aug 2008 17:27:42 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E86E1065676 for ; Fri, 15 Aug 2008 17:27:42 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 642808FC1D for ; Fri, 15 Aug 2008 17:27:42 +0000 (UTC) (envelope-from rpaulo@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7FHRgXF026017 for ; Fri, 15 Aug 2008 17:27:42 GMT (envelope-from rpaulo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7FHRgrw026015 for perforce@freebsd.org; Fri, 15 Aug 2008 17:27:42 GMT (envelope-from rpaulo@FreeBSD.org) Date: Fri, 15 Aug 2008 17:27:42 GMT Message-Id: <200808151727.m7FHRgrw026015@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rpaulo@FreeBSD.org using -f From: Rui Paulo To: Perforce Change Reviews Cc: Subject: PERFORCE change 147475 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2008 17:27:43 -0000 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 @@ -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 @@ -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 @@ -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;