Browse Source

out_flags was being set but never used.

Use just random() to allocate initial sequence numbers; the previous
algorithm ended up with a high probability of zeroing the high word.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
43d601b678
1 changed files with 14 additions and 16 deletions
  1. 14
    16
      src/net/tcp.c

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

465
 	conn->timer.expired = tcp_expired;
465
 	conn->timer.expired = tcp_expired;
466
 
466
 
467
 	/* Send a SYN packet and transition to TCP_SYN_SENT */
467
 	/* Send a SYN packet and transition to TCP_SYN_SENT */
468
-	conn->snd_una = ( ( ( uint32_t ) random() ) << 16 ) & random();
468
+	conn->snd_una = random();
469
 	tcp_trans ( conn, TCP_SYN_SENT );
469
 	tcp_trans ( conn, TCP_SYN_SENT );
470
 	/* Allocate space for the packet */
470
 	/* Allocate space for the packet */
471
 	free_pkb ( conn->tx_pkb );
471
 	free_pkb ( conn->tx_pkb );
598
 	switch ( conn->tcp_state ) {
598
 	switch ( conn->tcp_state ) {
599
 	case TCP_LISTEN:
599
 	case TCP_LISTEN:
600
 		tcp_trans ( conn, TCP_SYN_SENT );
600
 		tcp_trans ( conn, TCP_SYN_SENT );
601
-		conn->snd_una = ( ( ( uint32_t ) random() ) << 16 ) & random();
601
+		conn->snd_una = random();
602
 		break;
602
 		break;
603
 	case TCP_ESTABLISHED:
603
 	case TCP_ESTABLISHED:
604
 	case TCP_CLOSE_WAIT:
604
 	case TCP_CLOSE_WAIT:
738
 	conn->snd_win = tcphdr->win;
738
 	conn->snd_win = tcphdr->win;
739
 
739
 
740
 	/* TCP State Machine */
740
 	/* TCP State Machine */
741
-	uint8_t out_flags = 0;
742
 	conn->tcp_lstate = conn->tcp_state;
741
 	conn->tcp_lstate = conn->tcp_state;
743
 	switch ( conn->tcp_state ) {
742
 	switch ( conn->tcp_state ) {
744
 	case TCP_CLOSED:
743
 	case TCP_CLOSED:
750
 			tcp_trans ( conn, TCP_SYN_RCVD );
749
 			tcp_trans ( conn, TCP_SYN_RCVD );
751
 			/* Synchronize the sequence numbers */
750
 			/* Synchronize the sequence numbers */
752
 			conn->rcv_nxt = ntohl ( tcphdr->seq ) + 1;
751
 			conn->rcv_nxt = ntohl ( tcphdr->seq ) + 1;
753
-			out_flags |= TCP_ACK;
752
+			conn->tcp_flags |= TCP_ACK;
754
 
753
 
755
 			/* Set the sequence number for the snd stream */
754
 			/* Set the sequence number for the snd stream */
756
-			conn->snd_una = ( ( ( uint32_t ) random() ) << 16 );
757
-			conn->snd_una &= random();
758
-			out_flags |= TCP_SYN;
755
+			conn->snd_una = random();
756
+			conn->tcp_flags |= TCP_SYN;
759
 
757
 
760
 			/* Send a SYN,ACK packet */
758
 			/* Send a SYN,ACK packet */
761
 			goto send_tcp_nomsg;
759
 			goto send_tcp_nomsg;
766
 		if ( tcphdr->flags & TCP_SYN ) {
764
 		if ( tcphdr->flags & TCP_SYN ) {
767
 			/* Synchronize the sequence number in rcv stream */
765
 			/* Synchronize the sequence number in rcv stream */
768
 			conn->rcv_nxt = ntohl ( tcphdr->seq ) + 1;
766
 			conn->rcv_nxt = ntohl ( tcphdr->seq ) + 1;
769
-			out_flags |= TCP_ACK;
767
+			conn->tcp_flags |= TCP_ACK;
770
 
768
 
771
 			if ( tcphdr->flags & TCP_ACK ) {
769
 			if ( tcphdr->flags & TCP_ACK ) {
772
 				tcp_trans ( conn, TCP_ESTABLISHED );
770
 				tcp_trans ( conn, TCP_ESTABLISHED );
776
 				 */
774
 				 */
777
 				conn->snd_una = ntohl ( tcphdr->ack );
775
 				conn->snd_una = ntohl ( tcphdr->ack );
778
 				conn->tcp_op->connected ( conn );
776
 				conn->tcp_op->connected ( conn );
779
-				out_flags |= TCP_ACK;
777
+				conn->tcp_flags |= TCP_ACK;
780
 				tcp_senddata ( conn );
778
 				tcp_senddata ( conn );
781
 				return;
779
 				return;
782
 			} else {
780
 			} else {
783
 				tcp_trans ( conn, TCP_SYN_RCVD );
781
 				tcp_trans ( conn, TCP_SYN_RCVD );
784
-				out_flags |= TCP_SYN;
782
+				conn->tcp_flags |= TCP_SYN;
785
 				goto send_tcp_nomsg;
783
 				goto send_tcp_nomsg;
786
 			}
784
 			}
787
 		}
785
 		}
811
 			tcp_trans ( conn, TCP_CLOSE_WAIT );
809
 			tcp_trans ( conn, TCP_CLOSE_WAIT );
812
 			/* FIN consumes one byte */
810
 			/* FIN consumes one byte */
813
 			conn->rcv_nxt++;
811
 			conn->rcv_nxt++;
814
-			out_flags |= TCP_ACK;
812
+			conn->tcp_flags |= TCP_ACK;
815
 			/* Send an acknowledgement */
813
 			/* Send an acknowledgement */
816
 			goto send_tcp_nomsg;
814
 			goto send_tcp_nomsg;
817
 		}
815
 		}
821
 	case TCP_FIN_WAIT_1:
819
 	case TCP_FIN_WAIT_1:
822
 		if ( tcphdr->flags & TCP_FIN ) {
820
 		if ( tcphdr->flags & TCP_FIN ) {
823
 			conn->rcv_nxt++;
821
 			conn->rcv_nxt++;
824
-			out_flags |= TCP_ACK;
822
+			conn->tcp_flags |= TCP_ACK;
825
 			conn->tcp_op->closed ( conn, CONN_SNDCLOSE );
823
 			conn->tcp_op->closed ( conn, CONN_SNDCLOSE );
826
 
824
 
827
 			if ( tcphdr->flags & TCP_ACK ) {
825
 			if ( tcphdr->flags & TCP_ACK ) {
842
 			tcp_trans ( conn, TCP_TIME_WAIT );
840
 			tcp_trans ( conn, TCP_TIME_WAIT );
843
 			/* FIN consumes one byte */
841
 			/* FIN consumes one byte */
844
 			conn->rcv_nxt++;
842
 			conn->rcv_nxt++;
845
-			out_flags |= TCP_ACK;
843
+			conn->tcp_flags |= TCP_ACK;
846
 			goto send_tcp_nomsg;
844
 			goto send_tcp_nomsg;
847
 		}
845
 		}
848
 		/* Packet might contain data */
846
 		/* Packet might contain data */
886
 			conn->tcp_op->newdata ( conn, pkb->data + hlen,
884
 			conn->tcp_op->newdata ( conn, pkb->data + hlen,
887
 						toack );
885
 						toack );
888
 		} else {
886
 		} else {
889
-			DBG ( "Unexpected sequence number %ld (wanted %ld)\n", 
887
+			DBG ( "Unexpected sequence number %lx (wanted %lx)\n", 
890
 			      ntohl ( tcphdr->seq ), conn->rcv_nxt );
888
 			      ntohl ( tcphdr->seq ), conn->rcv_nxt );
891
 		}
889
 		}
892
 
890
 
893
 		/* Acknowledge new data */
891
 		/* Acknowledge new data */
894
-		out_flags |= TCP_ACK;
892
+		conn->tcp_flags |= TCP_ACK;
895
 		if ( !( tcphdr->flags & TCP_ACK ) ) {
893
 		if ( !( tcphdr->flags & TCP_ACK ) ) {
896
 			goto send_tcp_nomsg;
894
 			goto send_tcp_nomsg;
897
 		}
895
 		}
918
 		conn->tcp_op->closed ( conn, CONN_SNDCLOSE );	
916
 		conn->tcp_op->closed ( conn, CONN_SNDCLOSE );	
919
 		conn->rcv_nxt++;
917
 		conn->rcv_nxt++;
920
 		if ( ! ( tcphdr->flags & TCP_ACK ) ) {
918
 		if ( ! ( tcphdr->flags & TCP_ACK ) ) {
921
-			out_flags |= TCP_ACK;
919
+			conn->tcp_flags |= TCP_ACK;
922
 			/* Send an acknowledgement */
920
 			/* Send an acknowledgement */
923
 			goto send_tcp_nomsg;
921
 			goto send_tcp_nomsg;
924
 		}
922
 		}

Loading…
Cancel
Save