diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index 5e987cf65c..793dd0cb5e 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -81,11 +81,29 @@ * can be found. For Ethernet, this should be set to 14. For SLIP, this * should be set to 0. * - * If CONFIG_NET_MULTILINK is defined, then mutliple link protocols are + * If CONFIG_NET_MULTILINK is defined, then multiple link protocols are * supported concurrently. In this case, the size of link layer header * varies and is obtained from the network device structure. + * + * Support is also provided to select different MTU sizes for each different + * link layer protocol. A better solution would be to support device-by- + * device MTU sizes. This minimum support is require to support the + * optimal SLIP MTU of 296 bytes and the standard Ethernet MTU of 1500 + * bytes. */ +#ifdef CONFIG_NET_SLIP +# ifndef CONFIG_NET_SLIP_MTU +# define CONFIG_NET_SLIP_MTU 590 +# endif +#endif + +#ifdef CONFIG_NET_ETHERNET +# ifndef CONFIG_NET_ETH_MTU +# define CONFIG_NET_ETH_MTU 590 +# endif +#endif + #if defined(CONFIG_NET_MULTILINK) /* We are supporting multiple network devices using different link layer * protocols. Get the size of the link layer header from the device @@ -188,7 +206,7 @@ #endif /* The UDP maximum packet size. This is should not be to set to more - * than CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(dev) - IPUDP_HDRLEN. + * than NET_LL_MTU(d) - NET_LL_HDRLEN(dev) - IPUDP_HDRLEN. */ #define UDP_MSS(d) (CONFIG_NET_ETH_MTU - NET_LL_HDRLEN(d) - IPUDP_HDRLEN) @@ -332,17 +350,6 @@ /* General configuration options */ -/* The size of the uIP packet buffer. - * - * The uIP packet buffer should not be smaller than 60 bytes, and does - * not need to be larger than 1500 bytes. Lower size results in lower - * TCP throughput, larger size results in higher TCP throughput. - */ - -#ifndef CONFIG_NET_BUFSIZE -# define CONFIG_NET_BUFSIZE 400 -#endif - /* Delay after receive to catch a following packet. No delay should be * required if TCP/IP read-ahead buffering is enabled. */ diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 8e6f1b6ebb..d5135738d3 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -131,7 +131,7 @@ struct net_driver_s #ifdef CONFIG_NET_MULTIBUFFER uint8_t *d_buf; #else - uint8_t d_buf[CONFIG_NET_BUFSIZE + CONFIG_NET_GUARDSIZE]; + uint8_t d_buf[MAX_NET_LL_MTU + CONFIG_NET_GUARDSIZE]; #endif /* d_appdata points to the location where application data can be read from diff --git a/net/Kconfig b/net/Kconfig index 526eb37224..53f2f93e61 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -47,25 +47,38 @@ config NET_PROMISCUOUS Force the Ethernet driver to operate in promiscuous mode (if supported by the Ethernet driver). -config NET_BUFSIZE - int "Network packet buffer size (MTU)" - default 1294 if !NET_SLIP && NET_IPv6 - default 590 if !NET_SLIP && !NET_IPv6 - default 296 if NET_SLIP && !NET_IPv6 +config NET_ETH_MTU + int "Ethernet packet buffer size (MTU)" + default 1294 if NET_IPv6 + default 590 if !NET_IPv6 + depends on NET_ETHERNET + range 590 1518 ---help--- Packet buffer size. This size includes the TCP/UDP payload plus the - size of TCP/UDP header, the IP header, and the Ethernet header - (assuming that the Ethernet transport is used). This value is - normally referred to as the MTU (Maximum Transmission Unit); the - payload is the MSS (Maximum Segment Size). + size of TCP/UDP header, the IP header, and the Ethernet header. + This value is normally referred to as the MTU (Maximum Transmission + Unit); the payload is the MSS (Maximum Segment Size). IPv4 hosts are required to be able to handle an MSS of at least 536 octets, resulting in a minimum buffer size of 536+20+20+14 = - 590 (For SLIP 256+20+20 = 296). + 590. IPv6 hosts are required to be able to handle an MSS of 1220 octets, resulting in a minimum buffer size of of 1220+20+40+14 = 1294 +config NET_SLIP_MTU + int # "SLIP packet buffer size (MTU)" + default 296 + depends on NET_SLIP + range 296 1518 + ---help--- + Packet buffer size. This size includes the TCP/UDP payload plus the + size of TCP/UDP header and the IP header. This value is normally + referred to as the MTU (Maximum Transmission Unit); the payload + payload is the MSS (Maximum Segment Size). SLIP is required to + support at lest 256+20+20 = 296. Values other than 296 are not + recommended. + config NET_RECEIVE_WINDOW int "Receive window size" default 1220 if !NET_SLIP && NET_IPv6 @@ -115,10 +128,6 @@ config NET_SLIP at least one IP protocol selected and the following additional network settings: NET_NOINTS and NET_MULTIBUFFER. - NET_BUFSIZE *must* be set to 296. Other optional configuration - settings that affect the SLIP driver: NET_STATISTICS. - Default: Ethernet - SLIP supports point-to-point IP communications over a serial port. The default data link layer for uIP is Ethernet. If NET_SLIP is defined in the NuttX configuration file, then SLIP will be supported. diff --git a/net/devif/devif_input.c b/net/devif/devif_input.c index 03b5f64cad..c601405622 100644 --- a/net/devif/devif_input.c +++ b/net/devif/devif_input.c @@ -113,7 +113,7 @@ /* IP fragment re-assembly */ #define IP_MF 0x20 -#define TCP_REASS_BUFSIZE (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(dev)) +#define TCP_REASS_BUFSIZE (NET_LL_MTU(dev) - NET_LL_HDRLEN(dev)) #define TCP_REASS_LASTFRAG 0x01 /**************************************************************************** diff --git a/net/devif/devif_iobsend.c b/net/devif/devif_iobsend.c index 424cd94ec4..6d00ebcf43 100644 --- a/net/devif/devif_iobsend.c +++ b/net/devif/devif_iobsend.c @@ -99,7 +99,7 @@ void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *iob, unsigned int len, unsigned int offset) { - DEBUGASSERT(dev && len > 0 && len < CONFIG_NET_BUFSIZE); + DEBUGASSERT(dev && len > 0 && len < NET_LL_MTU(dev)); /* Copy the data from the I/O buffer chain to the device buffer */ diff --git a/net/devif/devif_pktsend.c b/net/devif/devif_pktsend.c index 5c453fb4d1..ef8e335233 100644 --- a/net/devif/devif_pktsend.c +++ b/net/devif/devif_pktsend.c @@ -99,7 +99,7 @@ void devif_pkt_send(FAR struct net_driver_s *dev, FAR const void *buf, unsigned int len) { - DEBUGASSERT(dev && len > 0 && len < CONFIG_NET_BUFSIZE); + DEBUGASSERT(dev && len > 0 && len < NET_LL_MTU(dev)); /* Copy the data into the device packet buffer */ diff --git a/net/devif/devif_send.c b/net/devif/devif_send.c index 41ecd33616..60eaadd1ed 100644 --- a/net/devif/devif_send.c +++ b/net/devif/devif_send.c @@ -94,7 +94,7 @@ void devif_send(struct net_driver_s *dev, const void *buf, int len) { - DEBUGASSERT(dev && len > 0 && len < CONFIG_NET_BUFSIZE); + DEBUGASSERT(dev && len > 0 && len < NET_LL_MTU(dev)); memcpy(dev->d_snddata, buf, len); dev->d_sndlen = len; diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 1af66029bb..a703584788 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -316,8 +316,12 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd, case SIOCGIFMTU: /* Get MTU size */ { - req->ifr_mtu = CONFIG_NET_BUFSIZE; - ret = OK; + dev = netdev_ifrdev(req); + if (dev) + { + req->ifr_mtu = NET_LL_MTU(dev); + ret = OK; + } } break; diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index c148a44b04..2f513654d4 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -31,7 +31,7 @@ config NET_TCP_REASSEMBLY This features requires an additional amount of RAM to hold the reassembly buffer and the reassembly code size is approximately 700 bytes. The reassembly buffer is of the same size as the d_buf buffer - (configured by CONFIG_NET_BUFSIZE). + (configured by CONFIG_NET_xxx_MTU). Note: IP packet reassembly is not heavily tested (and, hence, EXPERIMENTAL). diff --git a/net/utils/net_chksum.c b/net/utils/net_chksum.c index 1fc85a7c22..c32c7ade57 100644 --- a/net/utils/net_chksum.c +++ b/net/utils/net_chksum.c @@ -128,7 +128,7 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto) /* Verify some minimal assumptions */ - if (upper_layer_len > CONFIG_NET_BUFSIZE) + if (upper_layer_len > NET_LL_MTU(dev)) { return 0; }