This commit attempts remove some long standard confusion in naming and some actual problems that result from the naming confusion. The basic problem is the standard MTU does not include the size of the Ethernet header. For clarity, I changed the naming of most things called MTU to PKTSIZE. For example, CONFIG_NET_ETH_MTU is now CONFIG_NET_ETH_PKTSIZE.

This makes the user interface a little hostile.  People thing of an MTU of 1500 bytes, but the corresponding packet is really 1514 bytes (including the 14 byte Ethernet header).  A more friendly solution would configure the MTU (as before), but then derive the packet buffer size by adding the MAC header length.  Instead, we define the packet buffer size then derive the MTU.

The MTU is not common currency in networking.  On the wire, the only real issue is the MSS which is derived from MTU by subtracting the IP header and TCP header sizes (for the case of TCP).  Now it is derived for the PKTSIZE by subtracting the IP header, the TCP header, and the MAC header sizes.  So we should be all good and without the recurring 14 byte error in MTU's and MSS's.

Squashed commit of the following:

    Trivial update to fix some spacing issues.
    net/: Rename several macros containing _MTU to _PKTSIZE.
    net/: Rename CONFIG_NET_SLIP_MTU to CONFIG_NET_SLIP_PKTSIZE and similarly for CONFIG_NET_TUN_MTU.  These are not the MTU which does not include the size of the link layer header.  These are the full size of the packet buffer memory (minus any GUARD bytes).
    net/: Rename CONFIG_NET_6LOWPAN_MTU to CONFIG_NET_6LOWPAN_PKTSIZE and similarly for CONFIG_NET_TUN_MTU.  These are not the MTU which does not include the size of the link layer header.  These are the full size of the packet buffer memory (minus any GUARD bytes).
    net/: Rename CONFIG_NET_ETH_MTU to CONFIG_NET_ETH_PKTSIZE.  This is not the MTU which does not include the size of the link layer header.  This is the full size of the packet buffer memory (minus any GUARD bytes).
    net/: Rename the file d_mtu in the network driver structure to d_pktsize.  That value saved there is not the MTU.  The packetsize is the memory large enough to hold the maximum packet PLUS the size of the link layer header.  The MTU does not include the link layer header.
This commit is contained in:
Gregory Nutt
2018-07-04 14:10:40 -06:00
parent daa3fcc781
commit 22cd0d47fa
96 changed files with 275 additions and 271 deletions
+49 -48
View File
@@ -9,7 +9,8 @@
* Note: Network configuration options the netconfig.h should not be changed,
* but rather the per-project defconfig file.
*
* Copyright (C) 2007, 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2011, 2014-2015, 2017-2018 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* This logic was leveraged from uIP which also has a BSD-style license:
@@ -111,25 +112,25 @@
*/
#ifdef CONFIG_NET_SLIP
# ifndef CONFIG_NET_SLIP_MTU
# define CONFIG_NET_SLIP_MTU 296
# ifndef CONFIG_NET_SLIP_PKTSIZE
# define CONFIG_NET_SLIP_PKTSIZE 296
# endif
#endif
#ifdef CONFIG_NET_TUN
# ifndef CONFIG_NET_TUN_MTU
# define CONFIG_NET_TUN_MTU 296
# ifndef CONFIG_NET_TUN_PKTSIZE
# define CONFIG_NET_TUN_PKTSIZE 296
# endif
#endif
#ifdef CONFIG_NET_ETHERNET
# ifndef CONFIG_NET_ETH_MTU
# define CONFIG_NET_ETH_MTU 590
# ifndef CONFIG_NET_ETH_PKTSIZE
# define CONFIG_NET_ETH_PKTSIZE 590
# endif
#endif
#ifndef CONFIG_NET_6LOWPAN_MTU
# define CONFIG_NET_6LOWPAN_MTU 1294
#ifndef CONFIG_NET_6LOWPAN_PKTSIZE
# define CONFIG_NET_6LOWPAN_PKTSIZE 1294
#endif
/* We are supporting multiple network devices using different link layer
@@ -137,55 +138,55 @@
* structure.
*/
#define NET_LL_HDRLEN(d) ((d)->d_llhdrlen)
#define NET_DEV_MTU(d) ((d)->d_mtu)
#define NET_LL_HDRLEN(d) ((d)->d_llhdrlen)
#define NETDEV_PKTSIZE(d) ((d)->d_pktsize)
#ifdef CONFIG_NET_ETHERNET
# define _MIN_ETH_MTU CONFIG_NET_ETH_MTU
# define _MAX_ETH_MTU CONFIG_NET_ETH_MTU
# define _MIN_ETH_PKTSIZE CONFIG_NET_ETH_PKTSIZE
# define _MAX_ETH_PKTSIZE CONFIG_NET_ETH_PKTSIZE
#else
# define _MIN_ETH_MTU UINT16_MAX
# define _MAX_ETH_MTU 0
# define _MIN_ETH_PKTSIZE UINT16_MAX
# define _MAX_ETH_PKTSIZE 0
#endif
#ifdef CONFIG_NET_LOOPBACK
# define _MIN_LO_MTU MIN(_MIN_ETH_MTU,1518)
# define _MAX_LO_MTU MAX(_MAX_ETH_MTU,574)
# define _MIN_LO_PKTSIZE MIN(_MIN_ETH_PKTSIZE, 1518)
# define _MAX_LO_PKTSIZE MAX(_MAX_ETH_PKTSIZE, 574)
#else
# define _MIN_LO_MTU _MIN_ETH_MTU
# define _MAX_LO_MTU _MAX_ETH_MTU
# define _MIN_LO_PKTSIZE _MIN_ETH_PKTSIZE
# define _MAX_LO_PKTSIZE _MAX_ETH_PKTSIZE
#endif
#ifdef CONFIG_NET_SLIP
# define _MIN_SLIP_MTU MIN(_MIN_LO_MTU,CONFIG_NET_SLIP_MTU)
# define _MAX_SLIP_MTU MAX(_MAX_LO_MTU,CONFIG_NET_SLIP_MTU)
# define _MIN_SLIP_PKTSIZE MIN(_MIN_LO_PKTSIZE, CONFIG_NET_SLIP_PKTSIZE)
# define _MAX_SLIP_PKTSIZE MAX(_MAX_LO_PKTSIZE, CONFIG_NET_SLIP_PKTSIZE)
#else
# define _MIN_SLIP_MTU _MIN_LO_MTU
# define _MAX_SLIP_MTU _MAX_LO_MTU
# define _MIN_SLIP_PKTSIZE _MIN_LO_PKTSIZE
# define _MAX_SLIP_PKTSIZE _MAX_LO_PKTSIZE
#endif
#ifdef CONFIG_NET_TUN
# define _MIN_TUN_MTU MIN(_MIN_SLIP_MTU,CONFIG_NET_TUN_MTU)
# define _MAX_TUN_MTU MAX(_MAX_SLIP_MTU,CONFIG_NET_TUN_MTU)
# define _MIN_TUN_PKTSIZE MIN(_MIN_SLIP_PKTSIZE, CONFIG_NET_TUN_PKTSIZE)
# define _MAX_TUN_PKTSIZE MAX(_MAX_SLIP_PKTSIZE, CONFIG_NET_TUN_PKTSIZE)
#else
# define _MIN_TUN_MTU _MIN_SLIP_MTU
# define _MAX_TUN_MTU _MAX_SLIP_MTU
# define _MIN_TUN_PKTSIZE _MIN_SLIP_PKTSIZE
# define _MAX_TUN_PKTSIZE _MAX_SLIP_PKTSIZE
#endif
#ifdef CONFIG_NET_6LOWPAN
# define _MIN_6LOWPAN_MTU MIN(_MIN_TUN_MTU,CONFIG_NET_6LOWPAN_MTU)
# define _MAX_6LOWPAN_MTU MAX(_MAX_TUN_MTU,CONFIG_NET_6LOWPAN_MTU)
# define _MIN_6LOWPAN_PKTSIZE MIN(_MIN_TUN_PKTSIZE, CONFIG_NET_6LOWPAN_PKTSIZE)
# define _MAX_6LOWPAN_PKTSIZE MAX(_MAX_TUN_PKTSIZE, CONFIG_NET_6LOWPAN_PKTSIZE)
#else
# define _MIN_6LOWPAN_MTU _MIN_TUN_MTU
# define _MAX_6LOWPAN_MTU _MAX_TUN_MTU
# define _MIN_6LOWPAN_PKTSIZE _MIN_TUN_PKTSIZE
# define _MAX_6LOWPAN_PKTSIZE _MAX_TUN_PKTSIZE
#endif
#define MIN_NET_DEV_MTU _MIN_6LOWPAN_MTU
#define MAX_NET_DEV_MTU _MAX_6LOWPAN_MTU
#define MIN_NETDEV_PKTSIZE _MIN_6LOWPAN_PKTSIZE
#define MAX_NETDEV_PKTSIZE _MAX_6LOWPAN_PKTSIZE
/* For the loopback device, we will use the largest MTU */
# define NET_LO_MTU MAX_NET_DEV_MTU
# define NET_LO_PKTSIZE MAX_NETDEV_PKTSIZE
/* Layer 3/4 Configuration Options ******************************************/
@@ -240,29 +241,29 @@
#endif
/* The UDP maximum packet size. This is should not be to set to more
* than NET_DEV_MTU(d) - NET_LL_HDRLEN(dev) - __UDP_HDRLEN - IPv*_HDRLEN.
* than NETDEV_PKTSIZE(d) - NET_LL_HDRLEN(dev) - __UDP_HDRLEN - IPv*_HDRLEN.
*/
#define UDP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - __UDP_HDRLEN - (h))
#define UDP_MSS(d,h) (NETDEV_PKTSIZE(d) - NET_LL_HDRLEN(d) - __UDP_HDRLEN - (h))
#ifdef CONFIG_NET_ETHERNET
# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - __UDP_HDRLEN - (h))
# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_PKTSIZE - ETH_HDRLEN - __UDP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_6LOWPAN
# define IEEE802154_UDP_MSS(h) (CONFIG_NET_6LOWPAN_MTU - __UDP_HDRLEN - (h))
# define IEEE802154_UDP_MSS(h) (CONFIG_NET_6LOWPAN_PKTSIZE - __UDP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_LOOPBACK
# define LO_UDP_MSS(h) (NET_LO_MTU - __UDP_HDRLEN - (h))
# define LO_UDP_MSS(h) (NET_LO_PKTSIZE - __UDP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_SLIP
# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - __UDP_HDRLEN - (h))
# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_PKTSIZE - __UDP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_TUN
# define TUN_UDP_MSS(h) (CONFIG_NET_TUN_MTU - __UDP_HDRLEN - (h))
# define TUN_UDP_MSS(h) (CONFIG_NET_TUN_PKTSIZE - __UDP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_ETHERNET
@@ -405,7 +406,7 @@
#define TCP_MAXSYNRTX 5
/* The TCP maximum segment size. This is should not be set to more
* than NET_DEV_MTU(dev) - NET_LL_HDRLEN(dev) - IPvN_HDRLEN - __TCP_HDRLEN.
* than NETDEV_PKTSIZE(dev) - NET_LL_HDRLEN(dev) - IPvN_HDRLEN - __TCP_HDRLEN.
*
* In the case where there are multiple network devices with different
* link layer protocols, each network device may support a different UDP
@@ -414,28 +415,28 @@
* REVISIT: __TCP_HDRLEN is not really a constant!
*/
#define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - __TCP_HDRLEN - (h))
#define TCP_MSS(d,h) (NETDEV_PKTSIZE(d) - NET_LL_HDRLEN(d) - __TCP_HDRLEN - (h))
/* Get the smallest and largest MSS */
#ifdef CONFIG_NET_ETHERNET
# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - __TCP_HDRLEN - (h))
# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_PKTSIZE - ETH_HDRLEN - __TCP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_6LOWPAN
# define IEEE802154_TCP_MSS(h) (CONFIG_NET_6LOWPAN_MTU - __TCP_HDRLEN - (h))
# define IEEE802154_TCP_MSS(h) (CONFIG_NET_6LOWPAN_PKTSIZE - __TCP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_LOOPBACK
# define LO_TCP_MSS(h) (NET_LO_MTU - __TCP_HDRLEN - (h))
# define LO_TCP_MSS(h) (NET_LO_PKTSIZE - __TCP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_SLIP
# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - __TCP_HDRLEN - (h))
# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_PKTSIZE - __TCP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_TUN
# define TUN_TCP_MSS(h) (CONFIG_NET_TUN_MTU - __TCP_HDRLEN - (h))
# define TUN_TCP_MSS(h) (CONFIG_NET_TUN_PKTSIZE - __TCP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_ETHERNET
+1 -1
View File
@@ -245,7 +245,7 @@ struct net_driver_s
uint8_t d_ifindex; /* Device index */
#endif
uint16_t d_mtu; /* Maximum packet size */
uint16_t d_pktsize; /* Maximum packet size */
#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN) || \
defined(CONFIG_NET_BLUETOOTH) || defined(CONFIG_NET_IEEE802154)
+1 -1
View File
@@ -137,7 +137,7 @@ struct radiodev_properties_s
* driver must still provide its (single) reassembly buffer in d_buf;
* that buffer is still used for the case where the packet is not
* fragmented into many frames. In either case, the packet buffer will
* have a size of advertised MTU of the protocol, CONFIG_NET_6LOWPAN_MTU,
* have a size of advertised MTU of the protocol, CONFIG_NET_6LOWPAN_PKTSIZE,
* plus CONFIG_NET_GUARDSIZE and some additional overhead for reassembly
* state data.
*
+2 -2
View File
@@ -368,7 +368,7 @@ struct sixlowpan_reassbuf_s
* provides the full reassembly packet to the network.
*/
uint8_t rb_buf[CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE];
uint8_t rb_buf[CONFIG_NET_6LOWPAN_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Memory pool used to allocate this reassembly buffer */
@@ -467,7 +467,7 @@ struct sixlowpan_reassbuf_s
* - The io_flink field points to the next frame in the list (if enable)
* - The last frame in the list will have io_flink == NULL.
*
* An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE
* An non-NULL d_buf of size CONFIG_NET_6LOWPAN_PKTSIZE + CONFIG_NET_GUARDSIZE
* must also be provided. The frame will be decompressed and placed in
* the d_buf. Fragmented packets will also be reassembled in the d_buf as
* they are received (meaning for the driver, that two packet buffers are
+2 -2
View File
@@ -58,12 +58,12 @@
* threads. Default: 2048
* CONFIG_NET_SLIP_DEFPRIO - Provides the priority for SLIP RX and TX
* threads. Default 128.
* CONFIG_NET_NET_SLIP_MTU - Provides the size of the SLIP packet buffers.
* CONFIG_NET_NET_SLIP_PKTSIZE - Provides the size of the SLIP packet buffers.
* Default 296
*
* The Linux slip module hard-codes its MTU size to 296 (40 bytes for the
* IP+TPC headers plus 256 bytes of data). So you might as well set
* CONFIG_NET_SLIP_MTU to 296 as well.
* CONFIG_NET_SLIP_PKTSIZE to 296 as well.
*
* There may be an issue with this setting, however. I see that Linux
* uses a MTU of 296 and window of 256, but actually only sends 168 bytes