|
@@ -112,9 +112,9 @@ static inline __attribute__ (( always_inline )) void
|
112
|
112
|
tcp_dump_state ( struct tcp_connection *conn ) {
|
113
|
113
|
|
114
|
114
|
if ( conn->tcp_state != conn->prev_tcp_state ) {
|
115
|
|
- DBG ( "TCP %p transitioned from %s to %s\n", conn,
|
116
|
|
- tcp_state ( conn->prev_tcp_state ),
|
117
|
|
- tcp_state ( conn->tcp_state ) );
|
|
115
|
+ DBGC ( conn, "TCP %p transitioned from %s to %s\n", conn,
|
|
116
|
+ tcp_state ( conn->prev_tcp_state ),
|
|
117
|
+ tcp_state ( conn->tcp_state ) );
|
118
|
118
|
}
|
119
|
119
|
conn->prev_tcp_state = conn->tcp_state;
|
120
|
120
|
}
|
|
@@ -125,17 +125,17 @@ tcp_dump_state ( struct tcp_connection *conn ) {
|
125
|
125
|
* @v flags TCP flags
|
126
|
126
|
*/
|
127
|
127
|
static inline __attribute__ (( always_inline )) void
|
128
|
|
-tcp_dump_flags ( unsigned int flags ) {
|
|
128
|
+tcp_dump_flags ( struct tcp_connection *conn, unsigned int flags ) {
|
129
|
129
|
if ( flags & TCP_RST )
|
130
|
|
- DBG ( " RST" );
|
|
130
|
+ DBGC ( conn, " RST" );
|
131
|
131
|
if ( flags & TCP_SYN )
|
132
|
|
- DBG ( " SYN" );
|
|
132
|
+ DBGC ( conn, " SYN" );
|
133
|
133
|
if ( flags & TCP_PSH )
|
134
|
|
- DBG ( " PSH" );
|
|
134
|
+ DBGC ( conn, " PSH" );
|
135
|
135
|
if ( flags & TCP_FIN )
|
136
|
|
- DBG ( " FIN" );
|
|
136
|
+ DBGC ( conn, " FIN" );
|
137
|
137
|
if ( flags & TCP_ACK )
|
138
|
|
- DBG ( " ACK" );
|
|
138
|
+ DBGC ( conn, " ACK" );
|
139
|
139
|
}
|
140
|
140
|
|
141
|
141
|
/**
|
|
@@ -150,7 +150,7 @@ static struct tcp_connection * alloc_tcp ( void ) {
|
150
|
150
|
|
151
|
151
|
conn = calloc ( 1, sizeof ( *conn ) );
|
152
|
152
|
if ( conn ) {
|
153
|
|
- DBG ( "TCP %p allocated\n", conn );
|
|
153
|
+ DBGC ( conn, "TCP %p allocated\n", conn );
|
154
|
154
|
conn->tcp_state = conn->prev_tcp_state = TCP_CLOSED;
|
155
|
155
|
conn->snd_seq = random();
|
156
|
156
|
conn->timer.expired = tcp_expired;
|
|
@@ -176,7 +176,7 @@ static void free_tcp ( struct tcp_connection *conn ) {
|
176
|
176
|
stop_timer ( &conn->timer );
|
177
|
177
|
list_del ( &conn->list );
|
178
|
178
|
free ( conn );
|
179
|
|
- DBG ( "TCP %p freed\n", conn );
|
|
179
|
+ DBGC ( conn, "TCP %p freed\n", conn );
|
180
|
180
|
}
|
181
|
181
|
|
182
|
182
|
/**
|
|
@@ -191,7 +191,7 @@ static void tcp_associate ( struct tcp_connection *conn,
|
191
|
191
|
assert ( app->conn == NULL );
|
192
|
192
|
conn->app = app;
|
193
|
193
|
app->conn = conn;
|
194
|
|
- DBG ( "TCP %p associated with application %p\n", conn, app );
|
|
194
|
+ DBGC ( conn, "TCP %p associated with application %p\n", conn, app );
|
195
|
195
|
}
|
196
|
196
|
|
197
|
197
|
/**
|
|
@@ -206,8 +206,8 @@ static void tcp_disassociate ( struct tcp_connection *conn ) {
|
206
|
206
|
assert ( app->conn == conn );
|
207
|
207
|
conn->app = NULL;
|
208
|
208
|
app->conn = NULL;
|
209
|
|
- DBG ( "TCP %p disassociated from application %p\n",
|
210
|
|
- conn, app );
|
|
209
|
+ DBGC ( conn, "TCP %p disassociated from application %p\n",
|
|
210
|
+ conn, app );
|
211
|
211
|
}
|
212
|
212
|
}
|
213
|
213
|
|
|
@@ -236,11 +236,11 @@ static int tcp_senddata_conn ( struct tcp_connection *conn, int force_send ) {
|
236
|
236
|
/* Allocate space to the TX buffer */
|
237
|
237
|
pkb = alloc_pkb ( MAX_PKB_LEN );
|
238
|
238
|
if ( ! pkb ) {
|
239
|
|
- DBG ( "TCP %p could not allocate senddata buffer\n", conn );
|
|
239
|
+ DBGC ( conn, "TCP %p could not allocate data buffer\n", conn );
|
240
|
240
|
/* Start the retry timer so that we attempt to
|
241
|
241
|
* retransmit this packet later. (Start it
|
242
|
242
|
* unconditionally, since without a packet buffer we
|
243
|
|
- * can't can the senddata() callback, and so may not
|
|
243
|
+ * can't call the senddata() callback, and so may not
|
244
|
244
|
* be able to tell whether or not we have something
|
245
|
245
|
* that actually needs to be retransmitted).
|
246
|
246
|
*/
|
|
@@ -259,11 +259,15 @@ static int tcp_senddata_conn ( struct tcp_connection *conn, int force_send ) {
|
259
|
259
|
conn->tx_pkb = NULL;
|
260
|
260
|
}
|
261
|
261
|
|
|
262
|
+ /* Truncate payload length to fit transmit window */
|
|
263
|
+ len = pkb_len ( pkb );
|
|
264
|
+ if ( len > conn->snd_win )
|
|
265
|
+ len = conn->snd_win;
|
|
266
|
+
|
262
|
267
|
/* Calculate amount of sequence space that this transmission
|
263
|
268
|
* consumes. (SYN or FIN consume one byte, and we can never
|
264
|
269
|
* send both at once).
|
265
|
270
|
*/
|
266
|
|
- len = pkb_len ( pkb );
|
267
|
271
|
seq_len = len;
|
268
|
272
|
flags = TCP_FLAGS_SENDING ( conn->tcp_state );
|
269
|
273
|
assert ( ! ( ( flags & TCP_SYN ) && ( flags & TCP_FIN ) ) );
|
|
@@ -297,12 +301,12 @@ static int tcp_senddata_conn ( struct tcp_connection *conn, int force_send ) {
|
297
|
301
|
tcphdr->csum = tcpip_chksum ( pkb->data, pkb_len ( pkb ) );
|
298
|
302
|
|
299
|
303
|
/* Dump header */
|
300
|
|
- DBG ( "TCP %p TX %d->%d %08lx..%08lx %08lx %4zd", conn,
|
301
|
|
- ntohs ( tcphdr->src ), ntohs ( tcphdr->dest ),
|
302
|
|
- ntohl ( tcphdr->seq ), ( ntohl ( tcphdr->seq ) + seq_len ),
|
303
|
|
- ntohl ( tcphdr->ack ), len );
|
304
|
|
- tcp_dump_flags ( tcphdr->flags );
|
305
|
|
- DBG ( "\n" );
|
|
304
|
+ DBGC ( conn, "TCP %p TX %d->%d %08lx..%08lx %08lx %4zd",
|
|
305
|
+ conn, ntohs ( tcphdr->src ), ntohs ( tcphdr->dest ),
|
|
306
|
+ ntohl ( tcphdr->seq ), ( ntohl ( tcphdr->seq ) + seq_len ),
|
|
307
|
+ ntohl ( tcphdr->ack ), len );
|
|
308
|
+ tcp_dump_flags ( conn, tcphdr->flags );
|
|
309
|
+ DBGC ( conn, "\n" );
|
306
|
310
|
|
307
|
311
|
/* Transmit packet */
|
308
|
312
|
return tcpip_tx ( pkb, &tcp_protocol, &conn->peer );
|
|
@@ -359,10 +363,6 @@ int tcp_send ( struct tcp_application *app, const void *data, size_t len ) {
|
359
|
363
|
return -EINVAL;
|
360
|
364
|
}
|
361
|
365
|
|
362
|
|
- /* Truncate length to fit transmit window */
|
363
|
|
- if ( len > conn->snd_win )
|
364
|
|
- len = conn->snd_win;
|
365
|
|
-
|
366
|
366
|
/* Truncate length to fit packet buffer */
|
367
|
367
|
if ( len > pkb_available ( pkb ) )
|
368
|
368
|
len = pkb_available ( pkb );
|
|
@@ -385,8 +385,8 @@ static void tcp_expired ( struct retry_timer *timer, int over ) {
|
385
|
385
|
struct tcp_application *app = conn->app;
|
386
|
386
|
int graceful_close = TCP_CLOSED_GRACEFULLY ( conn->tcp_state );
|
387
|
387
|
|
388
|
|
- DBG ( "TCP %p timer %s in %s\n", conn,
|
389
|
|
- ( over ? "expired" : "fired" ), tcp_state ( conn->tcp_state ) );
|
|
388
|
+ DBGC ( conn, "TCP %p timer %s in %s\n", conn,
|
|
389
|
+ ( over ? "expired" : "fired" ), tcp_state ( conn->tcp_state ) );
|
390
|
390
|
|
391
|
391
|
assert ( ( conn->tcp_state == TCP_SYN_SENT ) ||
|
392
|
392
|
( conn->tcp_state == TCP_SYN_RCVD ) ||
|
|
@@ -485,10 +485,10 @@ static int tcp_rx_ack ( struct tcp_connection *conn, uint32_t ack,
|
485
|
485
|
|
486
|
486
|
/* Ignore duplicate or out-of-range ACK */
|
487
|
487
|
if ( ack_len > conn->snd_sent ) {
|
488
|
|
- DBG ( "TCP %p received ACK for [%08lx,%08lx), sent only "
|
489
|
|
- "[%08lx,%08lx)\n", conn, conn->snd_seq,
|
490
|
|
- ( conn->snd_seq + ack_len ), conn->snd_seq,
|
491
|
|
- ( conn->snd_seq + conn->snd_sent ) );
|
|
488
|
+ DBGC ( conn, "TCP %p received ACK for [%08lx,%08lx), "
|
|
489
|
+ "sent only [%08lx,%08lx)\n", conn, conn->snd_seq,
|
|
490
|
+ ( conn->snd_seq + ack_len ), conn->snd_seq,
|
|
491
|
+ ( conn->snd_seq + conn->snd_sent ) );
|
492
|
492
|
return -EINVAL;
|
493
|
493
|
}
|
494
|
494
|
|
|
@@ -643,13 +643,13 @@ static int tcp_rx ( struct pk_buff *pkb,
|
643
|
643
|
len = pkb_len ( pkb );
|
644
|
644
|
|
645
|
645
|
/* Dump header */
|
646
|
|
- DBG ( "TCP %p RX %d<-%d %08lx %08lx..%08lx %4zd", conn,
|
647
|
|
- ntohs ( tcphdr->dest ), ntohs ( tcphdr->src ),
|
648
|
|
- ntohl ( tcphdr->ack ), ntohl ( tcphdr->seq ),
|
649
|
|
- ( ntohl ( tcphdr->seq ) + len +
|
650
|
|
- ( ( tcphdr->flags & ( TCP_SYN | TCP_FIN ) ) ? 1 : 0 ) ), len );
|
651
|
|
- tcp_dump_flags ( tcphdr->flags );
|
652
|
|
- DBG ( "\n" );
|
|
646
|
+ DBGC ( conn, "TCP %p RX %d<-%d %08lx %08lx..%08lx %4zd",
|
|
647
|
+ conn, ntohs ( tcphdr->dest ), ntohs ( tcphdr->src ),
|
|
648
|
+ ntohl ( tcphdr->ack ), ntohl ( tcphdr->seq ),
|
|
649
|
+ ( ntohl ( tcphdr->seq ) + len +
|
|
650
|
+ ( ( tcphdr->flags & ( TCP_SYN | TCP_FIN ) ) ? 1 : 0 ) ), len);
|
|
651
|
+ tcp_dump_flags ( conn, tcphdr->flags );
|
|
652
|
+ DBGC ( conn, "\n" );
|
653
|
653
|
|
654
|
654
|
/* If no connection was found, create dummy connection for
|
655
|
655
|
* sending RST
|
|
@@ -731,22 +731,21 @@ static int tcp_bind ( struct tcp_connection *conn, uint16_t local_port ) {
|
731
|
731
|
if ( tcp_bind ( conn, htons ( try_port ) ) == 0 )
|
732
|
732
|
return 0;
|
733
|
733
|
}
|
734
|
|
- DBG ( "TCP %p could not bind: no free ports remaining\n",
|
735
|
|
- conn );
|
|
734
|
+ DBGC ( conn, "TCP %p could not bind: no free ports\n", conn );
|
736
|
735
|
return -EADDRINUSE;
|
737
|
736
|
}
|
738
|
737
|
|
739
|
738
|
/* Attempt bind to local port */
|
740
|
739
|
list_for_each_entry ( existing, &tcp_conns, list ) {
|
741
|
740
|
if ( existing->local_port == local_port ) {
|
742
|
|
- DBG ( "TCP %p could not bind: port %d in use\n",
|
743
|
|
- conn, ntohs ( local_port ) );
|
|
741
|
+ DBGC ( conn, "TCP %p could not bind: port %d in use\n",
|
|
742
|
+ conn, ntohs ( local_port ) );
|
744
|
743
|
return -EADDRINUSE;
|
745
|
744
|
}
|
746
|
745
|
}
|
747
|
746
|
conn->local_port = local_port;
|
748
|
747
|
|
749
|
|
- DBG ( "TCP %p bound to port %d\n", conn, ntohs ( local_port ) );
|
|
748
|
+ DBGC ( conn, "TCP %p bound to port %d\n", conn, ntohs ( local_port ) );
|
750
|
749
|
return 0;
|
751
|
750
|
}
|
752
|
751
|
|