clatd: Fix packet corruption seen with GRO packets

MTU serves a dual purpose for CLAT. The segment size of the packet
ring is based on the MAXMTU apart from the interface MTU itself.

GRO coalesce happens on the receive path which is not affected by
the MTU (transmit). In other words, increasing the MAXMTU does not
affect if a GRO coalesced packet is delivered to CLAT.
It only affects the amount of data being read from the TPacket ring.

Introduce a new parameter MAXMRU which handles the increased MRU
to account for GRO packets. Increase the ring size to compensate
for the larger segments to maintain the same throughput as earlier.

Change-Id: I30057970973b99181505e698f64e7fa5aa0a27d9
diff --git a/clatd.h b/clatd.h
index f421f46..126a31c 100644
--- a/clatd.h
+++ b/clatd.h
@@ -21,7 +21,8 @@
 #include <sys/uio.h>
 
 #define MAXMTU 1500
-#define PACKETLEN (MAXMTU+sizeof(struct tun_pi))
+#define MAXMRU 65536
+#define PACKETLEN (MAXMRU+sizeof(struct tun_pi))
 #define CLATD_VERSION "1.4"
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/clatd_test.cpp b/clatd_test.cpp
index 6e374d2..d67113f 100644
--- a/clatd_test.cpp
+++ b/clatd_test.cpp
@@ -486,7 +486,7 @@
 
 void check_translated_packet(const uint8_t *original, size_t original_len,
                              const uint8_t *expected, size_t expected_len, const char *msg) {
-  uint8_t translated[MAXMTU];
+  uint8_t translated[MAXMRU];
   size_t translated_len = sizeof(translated);
   do_translate_packet(original, original_len, translated, &translated_len, msg);
   EXPECT_EQ(expected_len, translated_len) << msg << ": Translated packet length incorrect\n";
@@ -505,12 +505,12 @@
   }
 
   // Sanity check that reassembling the original and translated fragments produces valid packets.
-  uint8_t reassembled[MAXMTU];
+  uint8_t reassembled[MAXMRU];
   size_t reassembled_len = sizeof(reassembled);
   reassemble_packet(original, original_lengths, numfragments, reassembled, &reassembled_len, msg);
   check_packet(reassembled, reassembled_len, msg);
 
-  uint8_t translated[MAXMTU];
+  uint8_t translated[MAXMRU];
   size_t translated_len = sizeof(translated);
   do_translate_packet(reassembled, reassembled_len, translated, &translated_len, msg);
   check_packet(translated, translated_len, msg);
@@ -772,7 +772,7 @@
   check_packet(ipv6_ping, sizeof(ipv6_ping), "IPv6 ping sanity check");
 
   // Sanity checks reassemble_packet.
-  uint8_t reassembled[MAXMTU];
+  uint8_t reassembled[MAXMRU];
   size_t total_length = sizeof(reassembled);
   reassemble_packet(kIPv4Fragments, kIPv4FragLengths, ARRAYSIZE(kIPv4Fragments),
                     reassembled, &total_length, "Reassembly sanity check");
@@ -898,7 +898,7 @@
 
 void check_translate_checksum_neutral(const uint8_t *original, size_t original_len,
                                       size_t expected_len, const char *msg) {
-  uint8_t translated[MAXMTU];
+  uint8_t translated[MAXMRU];
   size_t translated_len = sizeof(translated);
   do_translate_packet(original, original_len, translated, &translated_len, msg);
   EXPECT_EQ(expected_len, translated_len) << msg << ": Translated packet length incorrect\n";
diff --git a/ring.h b/ring.h
index 9e517be..20d2f98 100644
--- a/ring.h
+++ b/ring.h
@@ -27,10 +27,10 @@
 
 // Frame size. Must be a multiple of TPACKET_ALIGNMENT (=16)
 // Why the 16? http://lxr.free-electrons.com/source/net/packet/af_packet.c?v=3.4#L1764
-#define TP_FRAME_SIZE (TPACKET_ALIGN(MAXMTU) + TPACKET_ALIGN(TPACKET2_HDRLEN) + 16)
+#define TP_FRAME_SIZE (TPACKET_ALIGN(MAXMRU) + TPACKET_ALIGN(TPACKET2_HDRLEN) + 16)
 
 // Block size. Must be a multiple of the page size, and a power of two for efficient memory use.
-#define TP_BLOCK_SIZE 65536
+#define TP_BLOCK_SIZE 2686976
 
 // In order to save memory, our frames are not an exact divider of the block size. Therefore, the
 // mmaped region will have gaps corresponding to the empty space at the end of each block.