nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone
8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Josef Bacik <jbacik@fb.com>
8e15ce
Date: Wed, 12 Aug 2015 08:57:55 -0700
8e15ce
Subject: [PATCH] tcp: add window scaling support
8e15ce
8e15ce
Sometimes we have to provision boxes across regions, such as California to
8e15ce
Sweden.  The http server has a 10 minute timeout, so if we can't get our 250mb
8e15ce
image transferred fast enough our provisioning fails, which is not ideal.  So
8e15ce
add tcp window scaling on open connections and set the window size to 1mb.  With
8e15ce
this change we're able to get higher sustained transfers between regions and can
8e15ce
transfer our image in well below 10 minutes.  Without this patch we'd time out
8e15ce
every time halfway through the transfer.  Thanks,
8e15ce
8e15ce
Signed-off-by: Josef Bacik <jbacik@fb.com>
8e15ce
---
8e15ce
 grub-core/net/tcp.c | 42 +++++++++++++++++++++++++++++-------------
8e15ce
 1 file changed, 29 insertions(+), 13 deletions(-)
8e15ce
8e15ce
diff --git a/grub-core/net/tcp.c b/grub-core/net/tcp.c
b35c50
index e8ad34b84d..7d4b822626 100644
8e15ce
--- a/grub-core/net/tcp.c
8e15ce
+++ b/grub-core/net/tcp.c
8e15ce
@@ -106,6 +106,18 @@ struct tcphdr
8e15ce
   grub_uint16_t urgent;
8e15ce
 } GRUB_PACKED;
8e15ce
 
8e15ce
+struct tcp_scale_opt {
8e15ce
+  grub_uint8_t kind;
8e15ce
+  grub_uint8_t length;
8e15ce
+  grub_uint8_t scale;
8e15ce
+} GRUB_PACKED;
8e15ce
+
8e15ce
+struct tcp_synhdr {
8e15ce
+  struct tcphdr tcphdr;
8e15ce
+  struct tcp_scale_opt scale_opt;
8e15ce
+  grub_uint8_t padding;
8e15ce
+};
8e15ce
+
8e15ce
 struct tcp_pseudohdr
8e15ce
 {
8e15ce
   grub_uint32_t src;
8e15ce
@@ -566,7 +578,7 @@ grub_net_tcp_open (char *server,
8e15ce
   grub_net_tcp_socket_t socket;
8e15ce
   static grub_uint16_t in_port = 21550;
8e15ce
   struct grub_net_buff *nb;
8e15ce
-  struct tcphdr *tcph;
8e15ce
+  struct tcp_synhdr *tcph;
8e15ce
   int i;
8e15ce
   grub_uint8_t *nbd;
8e15ce
   grub_net_link_level_address_t ll_target_addr;
8e15ce
@@ -635,20 +647,24 @@ grub_net_tcp_open (char *server,
8e15ce
     }
8e15ce
 
8e15ce
   tcph = (void *) nb->data;
8e15ce
+  grub_memset(tcph, 0, sizeof (*tcph));
8e15ce
   socket->my_start_seq = grub_get_time_ms ();
8e15ce
   socket->my_cur_seq = socket->my_start_seq + 1;
8e15ce
-  socket->my_window = 8192;
8e15ce
-  tcph->seqnr = grub_cpu_to_be32 (socket->my_start_seq);
8e15ce
-  tcph->ack = grub_cpu_to_be32_compile_time (0);
8e15ce
-  tcph->flags = grub_cpu_to_be16_compile_time ((5 << 12) | TCP_SYN);
8e15ce
-  tcph->window = grub_cpu_to_be16 (socket->my_window);
8e15ce
-  tcph->urgent = 0;
8e15ce
-  tcph->src = grub_cpu_to_be16 (socket->in_port);
8e15ce
-  tcph->dst = grub_cpu_to_be16 (socket->out_port);
8e15ce
-  tcph->checksum = 0;
8e15ce
-  tcph->checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
8e15ce
-						   &socket->inf->address,
8e15ce
-						   &socket->out_nla);
8e15ce
+  socket->my_window = 32768;
8e15ce
+  tcph->tcphdr.seqnr = grub_cpu_to_be32 (socket->my_start_seq);
8e15ce
+  tcph->tcphdr.ack = grub_cpu_to_be32_compile_time (0);
8e15ce
+  tcph->tcphdr.flags = grub_cpu_to_be16_compile_time ((6 << 12) | TCP_SYN);
8e15ce
+  tcph->tcphdr.window = grub_cpu_to_be16 (socket->my_window);
8e15ce
+  tcph->tcphdr.urgent = 0;
8e15ce
+  tcph->tcphdr.src = grub_cpu_to_be16 (socket->in_port);
8e15ce
+  tcph->tcphdr.dst = grub_cpu_to_be16 (socket->out_port);
8e15ce
+  tcph->tcphdr.checksum = 0;
8e15ce
+  tcph->scale_opt.kind = 3;
8e15ce
+  tcph->scale_opt.length = 3;
8e15ce
+  tcph->scale_opt.scale = 5;
8e15ce
+  tcph->tcphdr.checksum = grub_net_ip_transport_checksum (nb, GRUB_NET_IP_TCP,
8e15ce
+							  &socket->inf->address,
8e15ce
+							  &socket->out_nla);
8e15ce
 
8e15ce
   tcp_socket_register (socket);
8e15ce