Browse Source

Call closed() method only when the connection is genuinely in the

TCP_CLOSED state (i.e. after the final FIN/ACK exchange), and has been
removed from the list of TCP connections.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
cc0b92652f
1 changed files with 19 additions and 14 deletions
  1. 19
    14
      src/net/tcp.c

+ 19
- 14
src/net/tcp.c View File

378
  * @v over	Failure indicator
378
  * @v over	Failure indicator
379
  */
379
  */
380
 void tcp_expired ( struct retry_timer *timer, int over ) {
380
 void tcp_expired ( struct retry_timer *timer, int over ) {
381
-	struct tcp_connection *conn;
382
-	conn = ( struct tcp_connection * ) container_of ( timer, 
383
-					struct tcp_connection, timer );
381
+	struct tcp_connection *conn =
382
+		container_of ( timer, struct tcp_connection, timer );
383
+
384
 	DBG ( "Timer expired in %s\n", tcp_states[conn->tcp_state] );
384
 	DBG ( "Timer expired in %s\n", tcp_states[conn->tcp_state] );
385
 	switch ( conn->tcp_state ) {
385
 	switch ( conn->tcp_state ) {
386
 	case TCP_SYN_SENT:
386
 	case TCP_SYN_SENT:
387
 		if ( over ) {
387
 		if ( over ) {
388
+			list_del ( &conn->list );
388
 			tcp_trans ( conn, TCP_CLOSED );
389
 			tcp_trans ( conn, TCP_CLOSED );
390
+			if ( conn->tcp_op->closed )
391
+				conn->tcp_op->closed ( conn, -ETIMEDOUT );
389
 			DBG ( "Timeout! Connection closed\n" );
392
 			DBG ( "Timeout! Connection closed\n" );
390
 			return;
393
 			return;
391
 		}
394
 		}
392
 		goto send_tcp_nomsg;
395
 		goto send_tcp_nomsg;
393
 	case TCP_SYN_RCVD:
396
 	case TCP_SYN_RCVD:
394
 		if ( over ) {
397
 		if ( over ) {
398
+			list_del ( &conn->list );
395
 			tcp_trans ( conn, TCP_CLOSED );
399
 			tcp_trans ( conn, TCP_CLOSED );
400
+			if ( conn->tcp_op->closed )
401
+				conn->tcp_op->closed ( conn, -ETIMEDOUT );
396
 			goto send_tcp_nomsg;
402
 			goto send_tcp_nomsg;
397
 		}
403
 		}
398
 		goto send_tcp_nomsg;
404
 		goto send_tcp_nomsg;
416
 		}
422
 		}
417
 		return;
423
 		return;
418
 	case TCP_TIME_WAIT:
424
 	case TCP_TIME_WAIT:
425
+		list_del ( &conn->list );
419
 		tcp_trans ( conn, TCP_CLOSED );
426
 		tcp_trans ( conn, TCP_CLOSED );
427
+		if ( conn->tcp_op->closed )
428
+			conn->tcp_op->closed ( conn, 0 );
420
 		return;
429
 		return;
421
 	}
430
 	}
422
 	/* Retransmit the data */
431
 	/* Retransmit the data */
496
 	case TCP_SYN_RCVD:
505
 	case TCP_SYN_RCVD:
497
 	case TCP_ESTABLISHED:
506
 	case TCP_ESTABLISHED:
498
 		tcp_trans ( conn, TCP_FIN_WAIT_1 );
507
 		tcp_trans ( conn, TCP_FIN_WAIT_1 );
499
-		if ( conn->tcp_op->closed )
500
-			conn->tcp_op->closed ( conn, CONN_SNDCLOSE ); /* TODO: Check! */
501
 		/* FIN consumes one byte on the snd stream */
508
 		/* FIN consumes one byte on the snd stream */
502
 //		conn->snd_una++;
509
 //		conn->snd_una++;
503
 		goto send_tcp_nomsg;
510
 		goto send_tcp_nomsg;
511
 		list_del ( &conn->list );
518
 		list_del ( &conn->list );
512
 		tcp_trans ( conn, TCP_CLOSED );
519
 		tcp_trans ( conn, TCP_CLOSED );
513
 		if ( conn->tcp_op->closed )
520
 		if ( conn->tcp_op->closed )
514
-			conn->tcp_op->closed ( conn, CONN_SNDCLOSE );
521
+			conn->tcp_op->closed ( conn, 0 );
515
 		return 0;
522
 		return 0;
516
 	case TCP_CLOSE_WAIT:
523
 	case TCP_CLOSE_WAIT:
517
 		tcp_trans ( conn, TCP_LAST_ACK );
524
 		tcp_trans ( conn, TCP_LAST_ACK );
518
-		if ( conn->tcp_op->closed )
519
-			conn->tcp_op->closed ( conn, CONN_SNDCLOSE ); /* TODO: Check! */
520
 		/* FIN consumes one byte on the snd stream */
525
 		/* FIN consumes one byte on the snd stream */
521
 //		conn->snd_una++;
526
 //		conn->snd_una++;
522
 		goto send_tcp_nomsg;
527
 		goto send_tcp_nomsg;
715
 		    struct sockaddr_tcpip *st_dest __unused ) {
720
 		    struct sockaddr_tcpip *st_dest __unused ) {
716
 	struct tcp_connection *conn;
721
 	struct tcp_connection *conn;
717
 	struct tcp_header *tcphdr;
722
 	struct tcp_header *tcphdr;
718
-	uint32_t acked, toack;
719
-	int hlen;
723
+	int32_t acked, toack;
724
+	unsigned int hlen;
720
 	int rc;
725
 	int rc;
721
 
726
 
722
 	/* Sanity check */
727
 	/* Sanity check */
817
 		if ( tcphdr->flags & TCP_RST ) {
822
 		if ( tcphdr->flags & TCP_RST ) {
818
 			tcp_trans ( conn, TCP_LISTEN );
823
 			tcp_trans ( conn, TCP_LISTEN );
819
 			if ( conn->tcp_op->closed )
824
 			if ( conn->tcp_op->closed )
820
-				conn->tcp_op->closed ( conn, CONN_RESTART );
825
+				conn->tcp_op->closed ( conn, -ECONNRESET );
821
 			rc = 0;
826
 			rc = 0;
822
 			goto done;
827
 			goto done;
823
 		}
828
 		}
855
 		if ( tcphdr->flags & TCP_FIN ) {
860
 		if ( tcphdr->flags & TCP_FIN ) {
856
 			conn->rcv_nxt++;
861
 			conn->rcv_nxt++;
857
 			conn->tcp_flags |= TCP_ACK;
862
 			conn->tcp_flags |= TCP_ACK;
858
-			if ( conn->tcp_op->closed )
859
-				conn->tcp_op->closed ( conn, CONN_SNDCLOSE );
860
-
861
 			if ( tcphdr->flags & TCP_ACK ) {
863
 			if ( tcphdr->flags & TCP_ACK ) {
862
 				tcp_trans ( conn, TCP_TIME_WAIT );
864
 				tcp_trans ( conn, TCP_TIME_WAIT );
863
 			} else {
865
 			} else {
898
 		break;
900
 		break;
899
 	case TCP_LAST_ACK:
901
 	case TCP_LAST_ACK:
900
 		if ( tcphdr->flags & TCP_ACK ) {
902
 		if ( tcphdr->flags & TCP_ACK ) {
903
+			list_del ( &conn->list );
901
 			tcp_trans ( conn, TCP_CLOSED );
904
 			tcp_trans ( conn, TCP_CLOSED );
905
+			if ( conn->tcp_op->closed )
906
+				conn->tcp_op->closed ( conn, 0 );
902
 			rc = 0;
907
 			rc = 0;
903
 			goto done;
908
 			goto done;
904
 		}
909
 		}

Loading…
Cancel
Save