Skip to contentSkip to conversation

tcp: add mss option support

PATCH In review Josef Bacik 2 participants 2 messages Feb 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: add mss option support

We were continuing to see transfer rates drop between datacenters that would result in timeouts, so I added the mss option and suddenly we went from ~200 kb/s to ~100mb/s. So seems like I probably should have started there rather than all these other options but whatever, now things are super awesome.

---
 grub-core/net/tcp.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
grub-core/net/tcp.c +14 -1
index 6902c10..2d1706e 100644
@@ -111,6 +111,7 @@ struct tcphdr
 
 enum
   {
+    TCP_MSS_OPT = 2,
     TCP_SCALE_OPT = 3,
     TCP_TIMESTAMP_OPT = 8,
   };
@@ -134,6 +135,12 @@ struct tcp_timestamp_opt
   grub_uint32_t tsecr;
 } GRUB_PACKED;
 
+struct tcp_mss_opt
+{
+  struct tcp_opt_hdr opt;
+  grub_uint16_t mss;
+} GRUB_PACKED;
+
 struct tcp_pseudohdr
 {
   grub_uint32_t src;
@@ -620,6 +627,7 @@ grub_net_tcp_open (char *server,
   struct tcphdr *tcph;
   struct tcp_scale_opt *scale;
   struct tcp_timestamp_opt *timestamp;
+  struct tcp_mss_opt *mss;
   int i;
   grub_uint8_t *nbd;
   grub_net_link_level_address_t ll_target_addr;
@@ -659,7 +667,7 @@ grub_net_tcp_open (char *server,
   socket->hook_data = hook_data;
 
   headersize = ALIGN_UP (sizeof (*tcph) + sizeof (*scale) +
-			 sizeof (*timestamp), 4);
+			 sizeof (*timestamp) + sizeof (*mss), 4);
   nb = grub_netbuff_alloc (headersize + 128);
   if (!nb)
     {
@@ -718,6 +726,11 @@ grub_net_tcp_open (char *server,
   timestamp->tsval = grub_cpu_to_be32 (grub_get_time_ms ());
   timestamp->tsecr = 0;
 
+  mss = (struct tcp_mss_opt *)(timestamp + 1);
+  mss->opt.kind = TCP_MSS_OPT;
+  mss->opt.length = sizeof (struct tcp_mss_opt);
+  mss->mss = grub_cpu_to_be16 (inf->card->mtu - 128 - sizeof (*tcph));
+
   tcph->checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
 						   &socket->inf->address,
 						   &socket->out_nla);
Signature · 1 line
2.5.0
#1 lore raw

+1 For the MSS option

I've actually submitted similar patch a while ago
http://lists.gnu.org/archive/html/grub-devel/2015-10/msg00120.html

Didn't have time to finish it at first, but then decided to back off until window scaling gets merged to follow generic way of declaring TCP options. But this is a must-have as it greatly improves netboot over http.

The one thing is missing from the above patch is that we are announcing our MSS but ignore peer's MSS and send them TCP packets close to L2 MTU. There may be the case when the peer might be a low-memory device with 1500 bytes MTU on the NIC, but 600 byte buffer in its software/firmware, so we might overflow it. You may adapt code from my patch for this if you like.

Quoted 76 lines · Josef Bacik

We were continuing to see transfer rates drop between datacenters that would
result in timeouts, so I added the mss option and suddenly we went from ~200
kb/s to ~100mb/s. So seems like I probably should have started there rather
than all these other options but whatever, now things are super awesome.

---
 grub-core/net/tcp.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
grub-core/net/tcp.c +14 -2
index 6902c10..2d1706e 100644
@@ -111,6 +111,7 @@ struct tcphdr
 
 enum
   {
+    TCP_MSS_OPT = 2,
     TCP_SCALE_OPT = 3,
     TCP_TIMESTAMP_OPT = 8,
   };
@@ -134,6 +135,12 @@ struct tcp_timestamp_opt
   grub_uint32_t tsecr;
 } GRUB_PACKED;
 
+struct tcp_mss_opt
+{
+  struct tcp_opt_hdr opt;
+  grub_uint16_t mss;
+} GRUB_PACKED;
+
 struct tcp_pseudohdr
 {
   grub_uint32_t src;
@@ -620,6 +627,7 @@ grub_net_tcp_open (char *server,
   struct tcphdr *tcph;
   struct tcp_scale_opt *scale;
   struct tcp_timestamp_opt *timestamp;
+  struct tcp_mss_opt *mss;
   int i;
   grub_uint8_t *nbd;
   grub_net_link_level_address_t ll_target_addr;
@@ -659,7 +667,7 @@ grub_net_tcp_open (char *server,
   socket->hook_data = hook_data;
 
   headersize = ALIGN_UP (sizeof (*tcph) + sizeof (*scale) +
-                        sizeof (*timestamp), 4);
+                        sizeof (*timestamp) + sizeof (*mss), 4);
   nb = grub_netbuff_alloc (headersize + 128);
   if (!nb)
     {
@@ -718,6 +726,11 @@ grub_net_tcp_open (char *server,
   timestamp->tsval = grub_cpu_to_be32 (grub_get_time_ms ());
   timestamp->tsecr = 0;
 
+  mss = (struct tcp_mss_opt *)(timestamp + 1);
+  mss->opt.kind = TCP_MSS_OPT;
+  mss->opt.length = sizeof (struct tcp_mss_opt);
+  mss->mss = grub_cpu_to_be16 (inf->card->mtu - 128 - sizeof (*tcph));
+
   tcph->checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
                                                   &socket->inf->address,
                                                   &socket->out_nla);
--

2.5.0

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel