Browse Source

Changed the TCP state machines behaviour in the ESTABLISHED state

tags/v0.9.3
Nikhil Chandru Rao 18 years ago
parent
commit
3aff701001
1 changed files with 15 additions and 5 deletions
  1. 15
    5
      src/net/tcp.c

+ 15
- 5
src/net/tcp.c View File

314
 		if ( conn->tcp_lstate == TCP_CLOSE_WAIT ) {
314
 		if ( conn->tcp_lstate == TCP_CLOSE_WAIT ) {
315
 			conn->tcp_flags |= TCP_FIN;
315
 			conn->tcp_flags |= TCP_FIN;
316
 		}
316
 		}
317
+		if ( conn->tcp_lstate == TCP_ESTABLISHED ) {
318
+			conn->tcp_flags |= ( TCP_FIN | TCP_ACK );
319
+		}
317
 		break;
320
 		break;
318
 	default:
321
 	default:
319
 		DBG ( "TCP_INVALID state %d\n", conn->tcp_state );
322
 		DBG ( "TCP_INVALID state %d\n", conn->tcp_state );
909
 			      ntohl ( tcphdr->seq ), conn->rcv_nxt );
912
 			      ntohl ( tcphdr->seq ), conn->rcv_nxt );
910
 		}
913
 		}
911
 
914
 
912
-		/* Acknowledge new data */
913
-		conn->tcp_flags |= TCP_ACK;
914
-		if ( !( tcphdr->flags & TCP_ACK ) ) {
915
-			goto send_tcp_nomsg;
915
+		/* Send an ACK only if required to */
916
+		if ( conn->rcv_nxt <= ntohl ( tcphdr->seq ) ) {
917
+			/* Acknowledge new data */
918
+			conn->tcp_flags |= TCP_ACK;
919
+			if ( !( tcphdr->flags & TCP_ACK ) ) {
920
+				goto send_tcp_nomsg;
921
+			}
916
 		}
922
 		}
917
 	}
923
 	}
918
 
924
 
934
 
940
 
935
 	/* If the connection is in ESTABLISHED and it receives a FIN */
941
 	/* If the connection is in ESTABLISHED and it receives a FIN */
936
 	if ( conn->tcp_state == ESTABLISHED && ( tcphdr->flags & TCP_FIN ) ) {
942
 	if ( conn->tcp_state == ESTABLISHED && ( tcphdr->flags & TCP_FIN ) ) {
943
+		if ( tcphdr->flags & TCP_ACK ) {
944
+			tcp_trans ( conn, TCP_LAST_ACK );
945
+			goto send_tcp_nomsg;
946
+		}
937
 		tcp_trans ( conn, TCP_CLOSE_WAIT );
947
 		tcp_trans ( conn, TCP_CLOSE_WAIT );
938
-		conn->tcp_op->closed ( conn, CONN_SNDCLOSE );	
948
+//		conn->tcp_op->closed ( conn, CONN_SNDCLOSE );	
939
 		conn->rcv_nxt++;
949
 		conn->rcv_nxt++;
940
 		if ( ! ( tcphdr->flags & TCP_ACK ) ) {
950
 		if ( ! ( tcphdr->flags & TCP_ACK ) ) {
941
 			conn->tcp_flags |= TCP_ACK;
951
 			conn->tcp_flags |= TCP_ACK;

Loading…
Cancel
Save