Browse Source

Advertise a larger MSS to improve TCP performance.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
526d314266
2 changed files with 33 additions and 2 deletions
  1. 23
    1
      src/include/gpxe/tcp.h
  2. 10
    1
      src/net/tcp.c

+ 23
- 1
src/include/gpxe/tcp.h View File

27
 	uint16_t urg;		/* Urgent pointer */
27
 	uint16_t urg;		/* Urgent pointer */
28
 };
28
 };
29
 
29
 
30
+/**
31
+ * TCP MSS option
32
+ */
33
+struct tcp_mss_option {
34
+	uint8_t kind;
35
+	uint8_t length;
36
+	uint16_t mss;
37
+};
38
+
39
+/** Code for the TCP MSS option */
40
+#define TCP_OPTION_MSS 2
41
+
30
 /*
42
 /*
31
  * TCP flags
43
  * TCP flags
32
  */
44
  */
212
  * guess an arbitrary number that is empirically as large as possible
224
  * guess an arbitrary number that is empirically as large as possible
213
  * while avoiding retransmissions due to dropped packets.
225
  * while avoiding retransmissions due to dropped packets.
214
  */
226
  */
215
-#define TCP_WINDOW_SIZE	2048
227
+#define TCP_WINDOW_SIZE	4096
228
+
229
+/**
230
+ * Advertised TCP MSS
231
+ *
232
+ * We currently hardcode this to a reasonable value and hope that the
233
+ * sender uses path MTU discovery.  The alternative is breaking the
234
+ * abstraction layer so that we can find out the MTU from the IP layer
235
+ * (which would have to find out from the net device layer).
236
+ */
237
+#define TCP_MSS 1460
216
 
238
 
217
 /** TCP maximum segment lifetime
239
 /** TCP maximum segment lifetime
218
  *
240
  *

+ 10
- 1
src/net/tcp.c View File

229
 	struct tcp_application *app = conn->app;
229
 	struct tcp_application *app = conn->app;
230
 	struct pk_buff *pkb;
230
 	struct pk_buff *pkb;
231
 	struct tcp_header *tcphdr;
231
 	struct tcp_header *tcphdr;
232
+	struct tcp_mss_option *mssopt;
233
+	void *payload;
232
 	unsigned int flags;
234
 	unsigned int flags;
233
 	size_t len;
235
 	size_t len;
234
 	size_t seq_len;
236
 	size_t seq_len;
289
 		start_timer ( &conn->timer );
291
 		start_timer ( &conn->timer );
290
 
292
 
291
 	/* Fill up the TCP header */
293
 	/* Fill up the TCP header */
294
+	payload = pkb->data;
295
+	if ( flags & TCP_SYN ) {
296
+		mssopt = pkb_push ( pkb, sizeof ( *mssopt ) );
297
+		mssopt->kind = TCP_OPTION_MSS;
298
+		mssopt->length = sizeof ( *mssopt );
299
+		mssopt->mss = htons ( TCP_MSS );
300
+	}
292
 	tcphdr = pkb_push ( pkb, sizeof ( *tcphdr ) );
301
 	tcphdr = pkb_push ( pkb, sizeof ( *tcphdr ) );
293
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
302
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
294
 	tcphdr->src = conn->local_port;
303
 	tcphdr->src = conn->local_port;
295
 	tcphdr->dest = conn->peer.st_port;
304
 	tcphdr->dest = conn->peer.st_port;
296
 	tcphdr->seq = htonl ( conn->snd_seq );
305
 	tcphdr->seq = htonl ( conn->snd_seq );
297
 	tcphdr->ack = htonl ( conn->rcv_ack );
306
 	tcphdr->ack = htonl ( conn->rcv_ack );
298
-	tcphdr->hlen = ( ( sizeof ( *tcphdr ) / 4 ) << 4 );
307
+	tcphdr->hlen = ( ( payload - pkb->data ) << 2 );
299
 	tcphdr->flags = flags;
308
 	tcphdr->flags = flags;
300
 	tcphdr->win = htons ( TCP_WINDOW_SIZE );
309
 	tcphdr->win = htons ( TCP_WINDOW_SIZE );
301
 	tcphdr->csum = tcpip_chksum ( pkb->data, pkb_len ( pkb ) );
310
 	tcphdr->csum = tcpip_chksum ( pkb->data, pkb_len ( pkb ) );

Loading…
Cancel
Save