From 90b03e1746a7d19dc5ca2b17a7228231315f9839 Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Mon, 6 Jun 2011 15:06:08 +0000
Subject: [PATCH] Fix minimum MTU... must be at lest 576

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3674 42af7a65-404d-4744-a932-0658087f49c3
---
 TODO                                     | 15 +++++++++++++--
 arch/arm/src/lpc17xx/lpc17_emacram.h     |  2 +-
 arch/arm/src/lpc17xx/lpc17_ethernet.c    |  3 ++-
 configs/olimex-lpc1766stk/ftpc/defconfig |  4 ++--
 include/net/uip/uip-arch.h               |  2 +-
 include/net/uip/uipopt.h                 | 12 ++++++++++++
 6 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/TODO b/TODO
index 4752637277..7345d5b608 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-NuttX TODO List (Last updated May 31, 2011)
+NuttX TODO List (Last updated June 6, 2011)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 nuttx/
@@ -10,7 +10,7 @@ nuttx/
   (1)  pthreads (sched/)
   (1)  C++ Support
   (5)  Binary loaders (binfmt/)
- (15)  Network (net/, drivers/net)
+ (16)  Network (net/, drivers/net)
   (2)  USB (drivers/usbdev, drivers/usbhost)
   (6)  Libraries (lib/)
  (13)  File system/Generic drivers (fs/, drivers/)
@@ -333,6 +333,17 @@ o Network (net/, drivers/net)
                the mechanism for leaving and joining groups is hidden behind a wrapper
                function so that little of this incompatibilities need be exposed.
 
+  Description: Many configurations have the MTU (CONFIG_NET_BUFSIZE) set to very small
+               numbers, less then the minimum MTU size that must be supported -- 576.
+               This can cause problems in some networks:  CONFIG_NET_BUFSIZE should
+               be set to at least 576 in all defconfig files.
+
+               The symptoms of using very small MTU sizes can be very strange.  With
+               Ubuntu 9.x and vsFtpd was that the total packet size did *not match* the
+               packet size in the IP header.  This then caused a TCP checksum failure
+               and the packet was rejected.
+  Status:      Open
+  Priority:    Low... fix defconfig files as necessary.
 o USB (drivers/usbdev, drivers/usbhost)
   ^^^^^^^^^^^^^^^^^^^^
 
diff --git a/arch/arm/src/lpc17xx/lpc17_emacram.h b/arch/arm/src/lpc17xx/lpc17_emacram.h
index 98eaa91b97..3561b72ba8 100755
--- a/arch/arm/src/lpc17xx/lpc17_emacram.h
+++ b/arch/arm/src/lpc17xx/lpc17_emacram.h
@@ -209,7 +209,7 @@
 #define LPC17_PKTMEM_SIZE     (LPC17_EMACRAM_SIZE-LPC17_DESCTAB_SIZE)
 #define LPC17_PKTMEM_END      (LPC17_EMACRAM_BASE+LPC17_PKTMEM_SIZE)
 
-#define LPC17_MAXPACKET_SIZE  ((CONFIG_NET_BUFSIZE + 3 + 2) & ~3)
+#define LPC17_MAXPACKET_SIZE  ((CONFIG_NET_BUFSIZE + CONFIG_NET_GUARDSIZE + 3) & ~3)
 #define LPC17_NTXPKTS         CONFIG_NET_NTXDESC
 #define LPC17_NRXPKTS         CONFIG_NET_NRXDESC
 
diff --git a/arch/arm/src/lpc17xx/lpc17_ethernet.c b/arch/arm/src/lpc17xx/lpc17_ethernet.c
index 3efa3df03b..de015bcb94 100644
--- a/arch/arm/src/lpc17xx/lpc17_ethernet.c
+++ b/arch/arm/src/lpc17xx/lpc17_ethernet.c
@@ -53,6 +53,7 @@
 #include <nuttx/mii.h>
 
 #include <net/uip/uip.h>
+#include <net/uip/uipopt.h>
 #include <net/uip/uip-arp.h>
 #include <net/uip/uip-arch.h>
 
@@ -809,7 +810,7 @@ static void lpc17_rxdone(struct lpc17_driver_s *priv)
        * imply that the packet is too big.
        */
  
-      /* else */ if (pktlen > CONFIG_NET_BUFSIZE+2)
+      /* else */ if (pktlen > CONFIG_NET_BUFSIZE + CONFIG_NET_GUARDSIZE)
         {
           nlldbg("Too big. considx: %08x prodidx: %08x pktlen: %d rxstat: %08x\n",
                  considx, prodidx, pktlen, *rxstat);
diff --git a/configs/olimex-lpc1766stk/ftpc/defconfig b/configs/olimex-lpc1766stk/ftpc/defconfig
index 2ba0a0277e..5d01d7e86d 100755
--- a/configs/olimex-lpc1766stk/ftpc/defconfig
+++ b/configs/olimex-lpc1766stk/ftpc/defconfig
@@ -207,7 +207,7 @@ CONFIG_PHY_KS8721=y
 CONFIG_PHY_AUTONEG=y
 CONFIG_PHY_SPEED100=n
 CONFIG_PHY_FDUPLEX=y
-CONFIG_NET_EMACRAM_SIZE=8192
+CONFIG_NET_EMACRAM_SIZE=8448
 CONFIG_NET_NTXDESC=7
 CONFIG_NET_NRXDESC=7
 CONFIG_NET_REGDEBUG=n
@@ -551,7 +551,7 @@ CONFIG_NET=y
 CONFIG_NET_IPv6=n
 CONFIG_NSOCKET_DESCRIPTORS=16
 CONFIG_NET_SOCKOPTS=y
-CONFIG_NET_BUFSIZE=562
+CONFIG_NET_BUFSIZE=576
 CONFIG_NET_TCP=y
 CONFIG_NET_TCP_CONNS=16
 CONFIG_NET_NTCP_READAHEAD_BUFFERS=16
diff --git a/include/net/uip/uip-arch.h b/include/net/uip/uip-arch.h
index 2cbe7239c6..3cb2904ea3 100644
--- a/include/net/uip/uip-arch.h
+++ b/include/net/uip/uip-arch.h
@@ -117,7 +117,7 @@ struct uip_driver_s
 #ifdef CONFIG_NET_MULTIBUFFER
   uint8_t *d_buf;
 #else
-  uint8_t d_buf[CONFIG_NET_BUFSIZE + 2];
+  uint8_t d_buf[CONFIG_NET_BUFSIZE + CONFIG_NET_GUARDSIZE];
 #endif
 
   /* d_appdata points to the location where application data can be read from
diff --git a/include/net/uip/uipopt.h b/include/net/uip/uipopt.h
index f6aff58bd3..a0ba62ee10 100644
--- a/include/net/uip/uipopt.h
+++ b/include/net/uip/uipopt.h
@@ -134,6 +134,18 @@
 
 #define UIP_REASS_MAXAGE (20*10) /* 20 seconds */
 
+/* Network drivers often receive packets with garbage at the end
+ * and are longer than the size of packet in the TCP header.  The
+ * following "fudge" factor increases the size of the I/O buffering
+ * by a small amount to allocate slightly oversize packets.  After
+ * receipt, the packet size will be chopped down to the size indicated
+ * in the TCP header.
+ */
+
+#ifndef CONFIG_NET_GUARDSIZE
+#  define CONFIG_NET_GUARDSIZE 2
+#endif
+
 /* ICMP configuration options */
 
 #if !defined(CONFIG_NET_ICMP) || defined(CONFIG_DISABLE_CLOCK)
-- 
GitLab