Browse Source

Advertise a larger MSS to improve TCP performance.

tags/v0.9.3
Michael Brown 18 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,6 +27,18 @@ struct tcp_header {
27 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 43
  * TCP flags
32 44
  */
@@ -212,7 +224,17 @@ struct tcp_header {
212 224
  * guess an arbitrary number that is empirically as large as possible
213 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 239
 /** TCP maximum segment lifetime
218 240
  *

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

@@ -229,6 +229,8 @@ static int tcp_senddata_conn ( struct tcp_connection *conn, int force_send ) {
229 229
 	struct tcp_application *app = conn->app;
230 230
 	struct pk_buff *pkb;
231 231
 	struct tcp_header *tcphdr;
232
+	struct tcp_mss_option *mssopt;
233
+	void *payload;
232 234
 	unsigned int flags;
233 235
 	size_t len;
234 236
 	size_t seq_len;
@@ -289,13 +291,20 @@ static int tcp_senddata_conn ( struct tcp_connection *conn, int force_send ) {
289 291
 		start_timer ( &conn->timer );
290 292
 
291 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 301
 	tcphdr = pkb_push ( pkb, sizeof ( *tcphdr ) );
293 302
 	memset ( tcphdr, 0, sizeof ( *tcphdr ) );
294 303
 	tcphdr->src = conn->local_port;
295 304
 	tcphdr->dest = conn->peer.st_port;
296 305
 	tcphdr->seq = htonl ( conn->snd_seq );
297 306
 	tcphdr->ack = htonl ( conn->rcv_ack );
298
-	tcphdr->hlen = ( ( sizeof ( *tcphdr ) / 4 ) << 4 );
307
+	tcphdr->hlen = ( ( payload - pkb->data ) << 2 );
299 308
 	tcphdr->flags = flags;
300 309
 	tcphdr->win = htons ( TCP_WINDOW_SIZE );
301 310
 	tcphdr->csum = tcpip_chksum ( pkb->data, pkb_len ( pkb ) );

Loading…
Cancel
Save