Date: Thu, 19 Jun 2008 23:00:32 GMT From: Rui Paulo <rpaulo@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 143791 for review Message-ID: <200806192300.m5JN0W3L086107@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=143791 Change 143791 by rpaulo@rpaulo_epsilon on 2008/06/19 22:59:31 Add last bits of basic FSM processing. Affected files ... .. //depot/projects/soc2008/rpaulo-tcpad/handler.c#8 edit Differences ... ==== //depot/projects/soc2008/rpaulo-tcpad/handler.c#8 (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/handler.c#7 $ + * $P4: //depot/projects/soc2008/rpaulo-tcpad/handler.c#8 $ */ #include <stdio.h> @@ -129,32 +129,42 @@ cp->pktshead = rcp->pktshead; dumper_addpkt(cp->pktshead, ph, bytes); } else if ((tcp->th_flags & TH_FLAGS) == TH_ACK) { + if (cp == NULL || rcp == NULL) + return; - if (cp) { - dumper_addpkt(cp->pktshead, ph, bytes); - if (cp->tcpstate == TCPS_SYN_SENT || - cp->tcpstate == TCPS_SYN_RECEIVED) { - cp->tcpstate = TCPS_ESTABLISHED; - rcp->tcpstate = TCPS_ESTABLISHED; - DPRINTF("established\n"); - print_packet(bytes, linkhlen); - } - if (cp->tcpstate == TCPS_FIN_WAIT_1) { - cp->tcpstate = TCPS_FIN_WAIT_2; - rcp->tcpstate = TCPS_CLOSE_WAIT; - print_packet(bytes, linkhlen); - } + dumper_addpkt(cp->pktshead, ph, bytes); + if (cp->tcpstate == TCPS_SYN_SENT || + cp->tcpstate == TCPS_SYN_RECEIVED) { + cp->tcpstate = TCPS_ESTABLISHED; + rcp->tcpstate = TCPS_ESTABLISHED; + DPRINTF("established\n"); + print_packet(bytes, linkhlen); + } + if (cp->tcpstate == TCPS_ESTABLISHED && + rcp->tcpstate == TCPS_FIN_WAIT_1) { + printf("first ack\n"); + cp->tcpstate = TCPS_CLOSE_WAIT; + rcp->tcpstate = TCPS_FIN_WAIT_2; + } + if (cp->tcpstate == TCPS_LAST_ACK) { + cp->tcpstate = TCPS_TIME_WAIT; + printf("connection down\n"); } } else if ((tcp->th_flags & TH_FLAGS) == (TH_FIN|TH_ACK)) { - if (cp) { - dumper_addpkt(cp->pktshead, ph, bytes); - if (cp->tcpstate == TCPS_ESTABLISHED) { - cp->tcpstate = TCPS_FIN_WAIT_1; - rcp->tcpstate = TCPS_CLOSE_WAIT; - DPRINTF("fin_wait_1\n"); - print_packet(bytes, linkhlen); - dumper_error(p, "test.cap", cp->pktshead); - } + if (cp == NULL || rcp == NULL) + return; + + dumper_addpkt(cp->pktshead, ph, bytes); + if (cp->tcpstate == TCPS_ESTABLISHED) { + cp->tcpstate = TCPS_FIN_WAIT_1; + DPRINTF("fin_wait_1\n"); + print_packet(bytes, linkhlen); + } + if (cp->tcpstate == TCPS_CLOSE_WAIT && + rcp->tcpstate == TCPS_FIN_WAIT_2) { + printf("last_ack\n"); + cp->tcpstate = TCPS_TIME_WAIT; + rcp->tcpstate = TCPS_LAST_ACK; } } else if ((tcp->th_flags & TH_FLAGS) == (TH_RST|TH_ACK)) { if (rcp && rcp->tcpstate == TCPS_SYN_SENT) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806192300.m5JN0W3L086107>