PERFORCE change 143791 for review

Rui Paulo rpaulo at FreeBSD.org
Thu Jun 19 23:00:33 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=143791

Change 143791 by rpaulo at 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) {


More information about the p4-projects mailing list