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