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
+2 -2
View File
@@ -341,7 +341,7 @@ struct dm9x_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* At present, only a single DM90x0 device is supported. */
@@ -908,7 +908,7 @@ static void dm9x_receive(FAR struct dm9x_driver_s *priv)
/* Also check if the packet is a valid size for the network configuration */
else if (rx.desc.rx_len < ETH_HDRLEN || rx.desc.rx_len > (CONFIG_NET_ETH_MTU + 2))
else if (rx.desc.rx_len < ETH_HDRLEN || rx.desc.rx_len > (CONFIG_NET_ETH_PKTSIZE + 2))
{
nerr("ERROR: RX length error\n");
NETDEV_RXERRORS(&priv->dm_dev);
+8 -8
View File
@@ -107,10 +107,10 @@
# define CONFIG_ENC28J60_NINTERFACES 1
#endif
/* CONFIG_NET_ETH_MTU must always be defined */
/* CONFIG_NET_ETH_PKTSIZE must always be defined */
#if !defined(CONFIG_NET_ETH_MTU) && (CONFIG_NET_ETH_MTU <= MAX_FRAMELEN)
# error "CONFIG_NET_ETH_MTU is not valid for the ENC28J60"
#if !defined(CONFIG_NET_ETH_PKTSIZE) && (CONFIG_NET_ETH_PKTSIZE <= MAX_FRAMELEN)
# error "CONFIG_NET_ETH_PKTSIZE is not valid for the ENC28J60"
#endif
/* We need to have the work queue to handle SPI interrupts */
@@ -159,7 +159,7 @@
/* Packet memory layout */
#define ALIGNED_BUFSIZE ((CONFIG_NET_ETH_MTU + 255) & ~255)
#define ALIGNED_BUFSIZE ((CONFIG_NET_ETH_PKTSIZE + 255) & ~255)
/* Work around Errata #5 (spurious reset of ERXWRPT to 0) by placing the RX
* FIFO at the beginning of packet memory.
@@ -265,7 +265,7 @@ struct enc_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Driver status structure */
@@ -1555,7 +1555,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv)
/* Check for a usable packet length (4 added for the CRC) */
else if (pktlen > (CONFIG_NET_ETH_MTU + 4) || pktlen <= (ETH_HDRLEN + 4))
else if (pktlen > (CONFIG_NET_ETH_PKTSIZE + 4) || pktlen <= (ETH_HDRLEN + 4))
{
nerr("ERROR: Bad packet size dropped (%d)\n", pktlen);
NETDEV_RXERRORS(&priv->dev);
@@ -2568,8 +2568,8 @@ static int enc_reset(FAR struct enc_driver_s *priv)
/* Set the maximum packet size which the controller will accept */
enc_wrbreg(priv, ENC_MAMXFLL, CONFIG_NET_ETH_MTU & 0xff);
enc_wrbreg(priv, ENC_MAMXFLH, CONFIG_NET_ETH_MTU >> 8);
enc_wrbreg(priv, ENC_MAMXFLL, CONFIG_NET_ETH_PKTSIZE & 0xff);
enc_wrbreg(priv, ENC_MAMXFLH, CONFIG_NET_ETH_PKTSIZE >> 8);
/* Configure LEDs (No, just use the defaults for now) */
/* enc_wrphy(priv, ENC_PHLCON, ??); */
+7 -7
View File
@@ -113,10 +113,10 @@
# define CONFIG_ENCX24J600_NINTERFACES 1
#endif
/* CONFIG_NET_ETH_MTU must always be defined */
/* CONFIG_NET_ETH_PKTSIZE must always be defined */
#if !defined(CONFIG_NET_ETH_MTU) && (CONFIG_NET_ETH_MTU <= MAX_FRAMELEN)
# error "CONFIG_NET_ETH_MTU is not valid for the ENCX24J600"
#if !defined(CONFIG_NET_ETH_PKTSIZE) && (CONFIG_NET_ETH_PKTSIZE <= MAX_FRAMELEN)
# error "CONFIG_NET_ETH_PKTSIZE is not valid for the ENCX24J600"
#endif
/* We need to have the work queue to handle SPI interrupts */
@@ -169,7 +169,7 @@
/* Packet memory layout */
#define PKTMEM_ALIGNED_BUFSIZE ((CONFIG_NET_ETH_MTU + 1) & ~1)
#define PKTMEM_ALIGNED_BUFSIZE ((CONFIG_NET_ETH_PKTSIZE + 1) & ~1)
#define PKTMEM_RX_START (PKTMEM_START + PKTMEM_SIZE / 2) /* Followed by RX buffer */
#define PKTMEM_RX_SIZE (PKTMEM_SIZE - PKTMEM_RX_START)
#define PKTMEM_RX_END (PKTMEM_START + PKTMEM_SIZE) /* RX buffer goes to the end of SRAM */
@@ -274,7 +274,7 @@ struct enc_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Driver status structure */
@@ -1695,7 +1695,7 @@ static void enc_pktif(FAR struct enc_driver_s *priv)
/* Check for a usable packet length (4 added for the CRC) */
else if (pktlen > (CONFIG_NET_ETH_MTU + 4) || pktlen <= (ETH_HDRLEN + 4))
else if (pktlen > (CONFIG_NET_ETH_PKTSIZE + 4) || pktlen <= (ETH_HDRLEN + 4))
{
nerr("ERROR: Bad packet size dropped (%d)\n", pktlen);
@@ -2748,7 +2748,7 @@ static int enc_reset(FAR struct enc_driver_s *priv)
/* Set the maximum packet size which the controller will accept */
enc_wrreg(priv, ENC_MAMXFL, CONFIG_NET_ETH_MTU + 4);
enc_wrreg(priv, ENC_MAMXFL, CONFIG_NET_ETH_PKTSIZE + 4);
ret = enc_waitreg(priv, ENC_ESTAT, ESTAT_PHYLNK, ESTAT_PHYLNK);
+1 -1
View File
@@ -188,7 +188,7 @@ struct ftmac100_driver_s
/* A single packet buffer is used */
static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Driver state structure. */
+1 -1
View File
@@ -108,7 +108,7 @@ struct lo_driver_s
****************************************************************************/
static struct lo_driver_s g_loopback;
static uint8_t g_iobuffer[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
static uint8_t g_iobuffer[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/****************************************************************************
* Private Function Prototypes
+1 -1
View File
@@ -144,7 +144,7 @@ struct skel_driver_s
* allocated dynamically in cases where more than one are needed.
*/
static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE];
static uint8_t g_pktbuf[MAX_NETDEV_PKTSIZE + CONFIG_NET_GUARDSIZE];
/* Driver state structure */
+8 -8
View File
@@ -88,7 +88,7 @@
/* 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 of data:
@@ -97,10 +97,10 @@
* transfers to 128 bytes (possibly by modifying the tcp_mss() macro).
*/
#if CONFIG_NET_SLIP_MTU < 296
# error "CONFIG_NET_SLIP_MTU >= 296 is required"
#elif CONFIG_NET_SLIP_MTU > 296
# warning "CONFIG_NET_SLIP_MTU == 296 is optimal"
#if CONFIG_NET_SLIP_PKTSIZE < 296
# error "CONFIG_NET_SLIP_PKTSIZE >= 296 is required"
#elif CONFIG_NET_SLIP_PKTSIZE > 296
# warning "CONFIG_NET_SLIP_PKTSIZE == 296 is optimal"
#endif
/* CONFIG_NET_SLIP_NINTERFACES determines the number of physical interfaces
@@ -146,8 +146,8 @@ struct slip_driver_s
/* This holds the information visible to the NuttX network */
struct net_driver_s dev; /* Interface understood by the network */
uint8_t rxbuf[CONFIG_NET_SLIP_MTU + 2];
uint8_t txbuf[CONFIG_NET_SLIP_MTU + 2];
uint8_t rxbuf[CONFIG_NET_SLIP_PKTSIZE + 2];
uint8_t txbuf[CONFIG_NET_SLIP_PKTSIZE + 2];
};
/****************************************************************************
@@ -626,7 +626,7 @@ static inline void slip_receive(FAR struct slip_driver_s *priv)
default:
{
if (priv->rxlen < CONFIG_NET_SLIP_MTU+2)
if (priv->rxlen < CONFIG_NET_SLIP_PKTSIZE+2)
{
priv->rxbuf[priv->rxlen++] = ch;
}
+3 -3
View File
@@ -133,9 +133,9 @@ struct tun_device_s
bool read_wait;
uint8_t read_buf[CONFIG_NET_TUN_MTU];
uint8_t read_buf[CONFIG_NET_TUN_PKTSIZE];
size_t read_d_len;
uint8_t write_buf[CONFIG_NET_TUN_MTU];
uint8_t write_buf[CONFIG_NET_TUN_PKTSIZE];
size_t write_d_len;
sem_t waitsem;
@@ -1338,7 +1338,7 @@ static ssize_t tun_write(FAR struct file *filep, FAR const char *buffer,
net_lock();
if (buflen > CONFIG_NET_TUN_MTU)
if (buflen > CONFIG_NET_TUN_PKTSIZE)
{
ret = -EINVAL;
}
+9 -9
View File
@@ -79,7 +79,7 @@
#define CONFIG_RNDIS_NWRREQS (2)
#define RNDIS_PACKET_HDR_SIZE (sizeof(struct rndis_packet_msg))
#define CONFIG_RNDIS_BULKIN_REQLEN (CONFIG_NET_ETH_MTU + RNDIS_PACKET_HDR_SIZE)
#define CONFIG_RNDIS_BULKIN_REQLEN (CONFIG_NET_ETH_PKTSIZE + RNDIS_PACKET_HDR_SIZE)
#define CONFIG_RNDIS_BULKOUT_REQLEN CONFIG_RNDIS_BULKIN_REQLEN
#define RNDIS_NCONFIGS (1)
@@ -100,7 +100,7 @@
#define RNDIS_MAXSTRLEN (RNDIS_MXDESCLEN-2)
#define RNDIS_CTRLREQ_LEN (512)
#define RNDIS_BUFFER_SIZE CONFIG_NET_ETH_MTU
#define RNDIS_BUFFER_SIZE CONFIG_NET_ETH_PKTSIZE
#define RNDIS_BUFFER_COUNT 4
/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */
@@ -401,14 +401,14 @@ static const uint32_t g_rndis_supported_oids[] =
static const struct rndis_oid_value_s g_rndis_oid_values[] =
{
{RNDIS_OID_GEN_SUPPORTED_LIST, sizeof(g_rndis_supported_oids), 0, g_rndis_supported_oids},
{RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE, 4, CONFIG_NET_ETH_MTU, NULL},
{RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE, 4, CONFIG_NET_ETH_PKTSIZE, NULL},
#ifdef CONFIG_USBDEV_DUALSPEED
{RNDIS_OID_GEN_LINK_SPEED, 4, 100000, NULL},
#else
{RNDIS_OID_GEN_LINK_SPEED, 4, 2000000, NULL},
#endif
{RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE, 4, CONFIG_NET_ETH_MTU, NULL},
{RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE, 4, CONFIG_NET_ETH_MTU, NULL},
{RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE, 4, CONFIG_NET_ETH_PKTSIZE, NULL},
{RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE, 4, CONFIG_NET_ETH_PKTSIZE, NULL},
{RNDIS_OID_GEN_VENDOR_ID, 4, 0x00FFFFFF, NULL},
{RNDIS_OID_GEN_VENDOR_DESCRIPTION, 6, 0, "RNDIS"},
{RNDIS_OID_GEN_CURRENT_PACKET_FILTER, 4, 0, NULL},
@@ -651,7 +651,7 @@ static bool rndis_allocnetreq(FAR struct rndis_dev_s *priv)
if (priv->net_req)
{
priv->netdev.d_buf = &priv->net_req->req->buf[RNDIS_PACKET_HDR_SIZE];
priv->netdev.d_len = CONFIG_NET_ETH_MTU;
priv->netdev.d_len = CONFIG_NET_ETH_PKTSIZE;
}
leave_critical_section(flags);
@@ -761,7 +761,7 @@ static void rndis_giverxreq(FAR struct rndis_dev_s *priv)
priv->net_req = priv->rx_req;
priv->netdev.d_buf = &priv->net_req->req->buf[RNDIS_PACKET_HDR_SIZE];
priv->netdev.d_len = CONFIG_NET_ETH_MTU;
priv->netdev.d_len = CONFIG_NET_ETH_PKTSIZE;
priv->rx_req = NULL;
}
@@ -1247,7 +1247,7 @@ static inline int rndis_recvpacket(FAR struct rndis_dev_s *priv,
/* Check if the received packet exceeds request buffer */
if ((RNDIS_PACKET_HDR_SIZE + index + copysize) <= CONFIG_NET_ETH_MTU)
if ((RNDIS_PACKET_HDR_SIZE + index + copysize) <= CONFIG_NET_ETH_PKTSIZE)
{
memcpy(&priv->rx_req->req->buf[RNDIS_PACKET_HDR_SIZE + index], reqbuf,
copysize);
@@ -1264,7 +1264,7 @@ static inline int rndis_recvpacket(FAR struct rndis_dev_s *priv,
{
/* Check for a usable packet length (4 added for the CRC) */
if (priv->current_rx_datagram_size > (CONFIG_NET_ETH_MTU + 4) ||
if (priv->current_rx_datagram_size > (CONFIG_NET_ETH_PKTSIZE + 4) ||
priv->current_rx_datagram_size <= (ETH_HDRLEN + 4))
{
uerr("ERROR: Bad packet size dropped (%d)\n",
+1 -1
View File
@@ -75,7 +75,7 @@
* len should not exceed 1400 bytes
*/
#define MAX_CHUNK_LEN (CONFIG_NET_ETH_MTU > 1500 ? 1400 : CONFIG_NET_ETH_MTU - 100)
#define MAX_CHUNK_LEN (CONFIG_NET_ETH_PKTSIZE > 1500 ? 1400 : CONFIG_NET_ETH_PKTSIZE - 100)
/* Helper to get iw_event size */
+1 -1
View File
@@ -166,7 +166,7 @@ int bcmf_netdev_alloc_tx_frame(FAR struct bcmf_dev_s *priv)
/* Allocate frame for TX */
priv->cur_tx_frame = bcmf_bdc_allocate_frame(priv, MAX_NET_DEV_MTU, true);
priv->cur_tx_frame = bcmf_bdc_allocate_frame(priv, MAX_NETDEV_PKTSIZE, true);
if (!priv->cur_tx_frame)
{
wlerr("ERROR: Cannot allocate TX frame\n");
+1 -1
View File
@@ -976,7 +976,7 @@ struct bcmf_sdio_frame *bcmf_sdio_allocate_frame(FAR struct bcmf_dev_s *priv,
sframe = container_of(entry, struct bcmf_sdio_frame, list_entry);
sframe->header.len = HEADER_SIZE + MAX_NET_DEV_MTU;
sframe->header.len = HEADER_SIZE + MAX_NETDEV_PKTSIZE;
sframe->header.base = sframe->data;
sframe->header.data = sframe->data;
sframe->tx = tx;
+1 -1
View File
@@ -115,7 +115,7 @@ struct bcmf_sdio_frame
struct bcmf_frame_s header;
bool tx;
dq_entry_t list_entry;
uint8_t data[HEADER_SIZE + MAX_NET_DEV_MTU +
uint8_t data[HEADER_SIZE + MAX_NETDEV_PKTSIZE +
CONFIG_NET_GUARDSIZE];
};
+1 -1
View File
@@ -412,7 +412,7 @@ struct bcmf_frame_s *bcmf_sdpcm_alloc_frame(FAR struct bcmf_dev_s *priv,
header_len += 2; /* Data frames need alignment padding */
}
if (len + header_len > MAX_NET_DEV_MTU + HEADER_SIZE ||
if (len + header_len > MAX_NETDEV_PKTSIZE + HEADER_SIZE ||
len > len + header_len)
{
wlerr("Invalid size %d\n", len);