@@ -18,7 +18,7 @@ static const char* error_messages[] = {
1818};
1919
2020/* Set this to output or record a trace of the TCP I/O. This is very noisy! */
21- #define TCP_TRACE 1
21+ #define TCP_TRACE 0
2222
2323bool tcp_state_receive_fin (ip_packet_t * encap_packet , tcp_segment_t * segment , tcp_conn_t * conn , const tcp_options_t * options , size_t len );
2424
@@ -333,8 +333,6 @@ tcp_conn_t* tcp_send_segment(tcp_conn_t *conn, uint32_t seq, uint8_t flags, cons
333333 return NULL ;
334334 }
335335
336- dprintf ("TCP send segment\n" );
337-
338336 ip_packet_t encap ;
339337 tcp_options_t options = { .mss = flags & TCP_SYN ? 1460 : 0 };
340338 uint16_t length = sizeof (tcp_segment_t ) + count + (flags & TCP_SYN ? 4 : 0 );
@@ -371,9 +369,7 @@ tcp_conn_t* tcp_send_segment(tcp_conn_t *conn, uint32_t seq, uint8_t flags, cons
371369 memcpy ((void * )packet -> payload + (flags & TCP_SYN ? 4 : 0 ), data , count );
372370
373371 packet -> checksum = htons (tcp_calculate_checksum (& encap , packet , length ));
374- dprintf ("TCP -> IP send packet\n" );
375372 ip_send_packet (encap .dst_ip , packet , length , PROTOCOL_TCP );
376- dprintf ("TCP -> IP send packet DONE\n" );
377373
378374 conn -> snd_nxt += count ;
379375 if (flags & (TCP_SYN | TCP_FIN )) {
@@ -935,7 +931,6 @@ bool tcp_state_time_wait(ip_packet_t* encap_packet, tcp_segment_t* segment, tcp_
935931 */
936932bool tcp_state_machine (ip_packet_t * encap_packet , tcp_segment_t * segment , tcp_conn_t * conn , const tcp_options_t * options , size_t len )
937933{
938- dprintf ("tcp_state_machine" );
939934 switch (conn -> state ) {
940935 case TCP_LISTEN :
941936 return tcp_state_listen (encap_packet , segment , conn , options , len );
@@ -971,25 +966,20 @@ bool tcp_state_machine(ip_packet_t* encap_packet, tcp_segment_t* segment, tcp_co
971966 */
972967void tcp_handle_packet ([[maybe_unused ]] ip_packet_t * encap_packet , tcp_segment_t * segment , size_t len )
973968{
974- dprintf ("tcp_handle_packet\n" );
975969 tcp_options_t options ;
976970 uint16_t our_checksum = tcp_calculate_checksum (encap_packet , segment , len );
977971 tcp_byte_order_in (segment );
978972 tcp_parse_options (segment , & options );
979973 if (our_checksum == segment -> checksum ) {
980- dprintf ("tcp with valid checksum\n" );
981974 tcp_conn_t * conn = tcp_find (* ((uint32_t * )(& encap_packet -> dst_ip )), * ((uint32_t * )(& encap_packet -> src_ip )), segment -> dst_port , segment -> src_port );
982975 if (conn ) {
983976 //tcp_dump_segment(true, conn, encap_packet, segment, &options, len, our_checksum);
984977 tcp_state_machine (encap_packet , segment , conn , & options , len );
985- } else {
986- dprintf ("tcp packet with no TCB\n" );
987978 }
988979 } else {
989980 dprintf ("tcp packet with invalid checksum\n" );
990981 //tcp_dump_segment(true, NULL, encap_packet, segment, &options, len, our_checksum);
991982 }
992- dprintf ("tcp_handle_packet done\n" );
993983}
994984
995985/**
@@ -1020,7 +1010,6 @@ void tcp_idle()
10201010 }
10211011 conn -> send_buffer_len -= amount_to_send ;
10221012 interrupts_on ();
1023- dprintf ("done send buffer resize down\n" );
10241013 }
10251014 } else if (conn -> state == TCP_TIME_WAIT && seq_gte (get_isn (), conn -> msl_time )) {
10261015 tcp_free (conn );
@@ -1094,8 +1083,6 @@ int tcp_connect(uint32_t target_addr, uint16_t target_port, uint16_t source_port
10941083 uint32_t isn = get_isn ();
10951084 unsigned char ip [4 ] = { 0 };
10961085
1097- dprintf ("tcp_connect() with isn=%d\n" , isn );
1098-
10991086 gethostaddr (ip );
11001087
11011088 conn .remote_addr = target_addr ;
@@ -1136,21 +1123,12 @@ int tcp_connect(uint32_t target_addr, uint16_t target_port, uint16_t source_port
11361123 conn .recv_buffer_spinlock = 0 ;
11371124 conn .send_buffer_spinlock = 0 ;
11381125
1139- dprintf ("tcp_connect() local port=%d\n" , conn .local_port );
1140-
11411126 tcp_set_state (& conn , TCP_SYN_SENT );
1142-
1143- dprintf ("tcp_connect() sending segment\n" );
1144-
11451127 tcp_send_segment (& conn , conn .snd_nxt , TCP_SYN , NULL , 0 );
1146-
1147- dprintf ("tcp_connect() setting hashmap\n" );
1148-
11491128 hashmap_set (tcb , & conn );
11501129
11511130 tcp_conn_t * new_conn = tcp_find (conn .local_addr , conn .remote_addr , conn .local_port , conn .remote_port );
11521131 if (new_conn ) {
1153- dprintf ("tcp_connect() setting conn fd\n" );
11541132 new_conn -> fd = tcp_allocate_fd (new_conn );
11551133 if (new_conn -> fd == -1 ) {
11561134 dprintf ("tcp_connect() allocation of fd failed\n" );
@@ -1197,7 +1175,6 @@ int tcp_close(tcp_conn_t* conn)
11971175
11981176int send (int socket , const void * buffer , uint32_t length )
11991177{
1200- dprintf ("send(): %d\n" , length );
12011178 tcp_conn_t * conn = tcp_find_by_fd (socket );
12021179 if (conn == NULL ) {
12031180 dprintf ("send(): invalid socket %d\n" , socket );
@@ -1211,7 +1188,6 @@ int send(int socket, const void* buffer, uint32_t length)
12111188 memcpy (conn -> send_buffer + conn -> send_buffer_len , buffer , length );
12121189 conn -> send_buffer_len += length ;
12131190 interrupts_on ();
1214- dprintf ("send(): done\n" );
12151191 return (int )length ;
12161192}
12171193
@@ -1224,18 +1200,14 @@ int connect(uint32_t target_addr, uint16_t target_port, uint16_t source_port, bo
12241200 }
12251201 return result ;
12261202 }
1227- dprintf ("connect(): tcp_connect() gave us fd %d\n" , result );
12281203 tcp_conn_t * conn = tcp_find_by_fd (result );
12291204 time_t start = time (NULL );
1230- dprintf ("Connect waiting: " );
12311205 while (conn && conn -> state < TCP_ESTABLISHED ) {
1232- dprintf ("." );
12331206 __asm__ volatile ("hlt" );
12341207 if (time (NULL ) - start > 10 ) {
12351208 return TCP_ERROR_CONNECTION_FAILED ;
12361209 }
12371210 };
1238- dprintf ("\nconnect(): socket state ESTABLISHED\n" );
12391211 return conn -> state == TCP_ESTABLISHED ? result : TCP_ERROR_CONNECTION_FAILED ;
12401212}
12411213
@@ -1262,7 +1234,6 @@ bool is_connected(int socket)
12621234
12631235int recv (int socket , void * buffer , uint32_t maxlen , bool blocking , uint32_t timeout )
12641236{
1265- //dprintf("recv(): socket=%d blocking=%d\n", socket, blocking);
12661237 tcp_conn_t * conn = tcp_find_by_fd (socket );
12671238 if (conn == NULL ) {
12681239 dprintf ("recv(): invalid socket\n" );
@@ -1273,7 +1244,6 @@ int recv(int socket, void* buffer, uint32_t maxlen, bool blocking, uint32_t time
12731244 }
12741245
12751246 if (blocking ) {
1276- //dprintf("recv(): start blocking wait\n");
12771247 time_t now = time (NULL );
12781248 while (conn -> recv_buffer_len == 0 || conn -> recv_buffer == NULL ) {
12791249 if (time (NULL ) - now > timeout || conn -> state != TCP_ESTABLISHED ) {
@@ -1284,7 +1254,6 @@ int recv(int socket, void* buffer, uint32_t maxlen, bool blocking, uint32_t time
12841254 if (conn -> recv_buffer_len > 0 && conn -> recv_buffer != NULL ) {
12851255 interrupts_off ();
12861256 /* There is buffered data to receive */
1287- //dprintf("recv buffer resize down\n");
12881257 size_t amount_to_recv = conn -> recv_buffer_len > maxlen ? maxlen : conn -> recv_buffer_len ;
12891258 memcpy (buffer , conn -> recv_buffer , amount_to_recv );
12901259 /* Resize recv buffer down */
0 commit comments