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
+13 -11
View File
@@ -37,8 +37,8 @@ config NET_PROMISCUOUS
menu "Driver buffer configuration"
config NET_ETH_MTU
int "Ethernet packet buffer size (MTU)"
config NET_ETH_PKTSIZE
int "Ethernet packet buffer size"
default 1294 if NET_IPv6
default 590 if !NET_IPv6
depends on NET_ETHERNET
@@ -46,8 +46,9 @@ config NET_ETH_MTU
---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.
This value is normally referred to as the MTU (Maximum Transmission
Unit); the payload is the MSS (Maximum Segment Size).
This value is related to the MTU (Maximum Transmission Unit), except
that it includes the size of the link layer header; 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 =
@@ -56,23 +57,24 @@ config NET_ETH_MTU
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)"
config NET_SLIP_PKTSIZE
int # "SLIP packet buffer size"
default 296
depends on NET_SLIP
range 296 1518
---help---
Provides the size of the SLIP packet buffers. 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).
This value is related to the MTU (Maximum Transmission Unit), except
that it includes the size of the link layer header; the payload is
the MSS (Maximum Segment Size).
SLIP is required to support at least 256+20+20 = 296. Values other than
296 are not recommended.
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.
set 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
@@ -179,8 +181,8 @@ config TUN_NINTERFACES
interfaces to support.
Default: 1
config NET_TUN_MTU
int "TUN packet buffer size (MTU)"
config NET_TUN_PKTSIZE
int "TUN packet buffer size"
default 296
range 296 1518
+1 -1
View File
@@ -81,7 +81,7 @@ void devif_forward(FAR struct forward_s *fwd)
/* Copy the IOB chain that contains the L3L3 headers and any data payload */
DEBUGASSERT(offset + fwd->f_iob->io_pktlen <= NET_DEV_MTU(fwd->f_dev));
DEBUGASSERT(offset + fwd->f_iob->io_pktlen <= NETDEV_PKTSIZE(fwd->f_dev));
ret = iob_copyout(&fwd->f_dev->d_buf[offset], fwd->f_iob,
fwd->f_iob->io_pktlen, 0);
+1 -1
View File
@@ -70,7 +70,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 < NET_DEV_MTU(dev));
DEBUGASSERT(dev && len > 0 && len < NETDEV_PKTSIZE(dev));
/* Copy the data from the I/O buffer chain to the device buffer */
+1 -1
View File
@@ -98,7 +98,7 @@
void devif_pkt_send(FAR struct net_driver_s *dev, FAR const void *buf,
unsigned int len)
{
DEBUGASSERT(dev && len > 0 && len < NET_DEV_MTU(dev));
DEBUGASSERT(dev && len > 0 && len < NETDEV_PKTSIZE(dev));
/* Copy the data into the device packet buffer */
+1 -1
View File
@@ -67,7 +67,7 @@
void devif_send(struct net_driver_s *dev, const void *buf, int len)
{
DEBUGASSERT(dev != NULL && len > 0 && len < NET_DEV_MTU(dev));
DEBUGASSERT(dev != NULL && len > 0 && len < NETDEV_PKTSIZE(dev));
memcpy(dev->d_appdata, buf, len);
dev->d_sndlen = len;
+1 -1
View File
@@ -125,7 +125,7 @@
*/
#define IP_MF 0x20 /* See IP_FLAG_MOREFRAGS */
#define IPv4_REASS_BUFSIZE (CONFIG_NET_ETH_MTU - ETH_HDRLEN)
#define IPv4_REASS_BUFSIZE (CONFIG_NET_ETH_PKTSIZE - ETH_HDRLEN)
#define IPv4_REASS_LASTFRAG 0x01
/****************************************************************************
+1 -1
View File
@@ -209,7 +209,7 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev)
mtu->opttype = ICMPv6_OPT_MTU;
mtu->optlen = 1;
mtu->reserved = 0;
mtu->mtu = HTONL(CONFIG_NET_ETH_MTU);
mtu->mtu = HTONL(CONFIG_NET_ETH_PKTSIZE - ETH_HDRLEN);
/* Set up the prefix option */
+1 -1
View File
@@ -221,7 +221,7 @@ static int ipv4_dev_forward(FAR struct net_driver_s *dev,
* We provide no support for fragmenting forwarded packets.
*/
if (NET_LL_HDRLEN(fwddev) + dev->d_len > NET_DEV_MTU(fwddev))
if (NET_LL_HDRLEN(fwddev) + dev->d_len > NETDEV_PKTSIZE(fwddev))
{
nwarn("WARNING: Packet > MTU... Dropping\n");
ret = -EFBIG;
+1 -1
View File
@@ -362,7 +362,7 @@ static int ipv6_dev_forward(FAR struct net_driver_s *dev,
* MTU. We provide no support for fragmenting forwarded packets.
*/
if (NET_LL_HDRLEN(fwddev) + dev->d_len > NET_DEV_MTU(fwddev))
if (NET_LL_HDRLEN(fwddev) + dev->d_len > NETDEV_PKTSIZE(fwddev))
{
nwarn("WARNING: Packet > MTU... Dropping\n");
ret = -EFBIG;
+1 -1
View File
@@ -889,7 +889,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
dev = netdev_ifr_dev(req);
if (dev)
{
req->ifr_mtu = NET_DEV_MTU(dev);
req->ifr_mtu = NETDEV_PKTSIZE(dev);
ret = OK;
}
}
+7 -7
View File
@@ -268,7 +268,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
#ifdef CONFIG_NET_LOOPBACK
case NET_LL_LOOPBACK: /* Local loopback */
dev->d_llhdrlen = 0;
dev->d_mtu = NET_LO_MTU;
dev->d_pktsize = NET_LO_PKTSIZE;
devfmt = NETDEV_LO_FORMAT;
break;
#endif
@@ -276,7 +276,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
#ifdef CONFIG_NET_ETHERNET
case NET_LL_ETHERNET: /* Ethernet */
dev->d_llhdrlen = ETH_HDRLEN;
dev->d_mtu = CONFIG_NET_ETH_MTU;
dev->d_pktsize = CONFIG_NET_ETH_PKTSIZE;
devfmt = NETDEV_ETH_FORMAT;
break;
#endif
@@ -284,7 +284,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
#ifdef CONFIG_DRIVERS_IEEE80211
case NET_LL_IEEE80211: /* IEEE 802.11 */
dev->d_llhdrlen = ETH_HDRLEN;
dev->d_mtu = CONFIG_NET_ETH_MTU;
dev->d_pktsize = CONFIG_NET_ETH_PKTSIZE;
devfmt = NETDEV_WLAN_FORMAT;
break;
#endif
@@ -293,7 +293,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
case NET_LL_BLUETOOTH: /* Bluetooth */
dev->d_llhdrlen = BLUETOOTH_MAX_HDRLEN; /* Determined at runtime */
#ifdef CONFIG_NET_6LOWPAN
dev->d_mtu = CONFIG_NET_6LOWPAN_MTU;
dev->d_pktsize = CONFIG_NET_6LOWPAN_PKTSIZE;
#endif
devfmt = NETDEV_BNEP_FORMAT;
break;
@@ -304,7 +304,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
case NET_LL_PKTRADIO: /* Non-IEEE 802.15.4 packet radio */
dev->d_llhdrlen = 0; /* Determined at runtime */
#ifdef CONFIG_NET_6LOWPAN
dev->d_mtu = CONFIG_NET_6LOWPAN_MTU;
dev->d_pktsize = CONFIG_NET_6LOWPAN_PKTSIZE;
#endif
devfmt = NETDEV_WPAN_FORMAT;
break;
@@ -313,7 +313,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
#ifdef CONFIG_NET_SLIP
case NET_LL_SLIP: /* Serial Line Internet Protocol (SLIP) */
dev->d_llhdrlen = 0;
dev->d_mtu = CONFIG_NET_SLIP_MTU;
dev->d_pktsize = CONFIG_NET_SLIP_PKTSIZE;
devfmt = NETDEV_SLIP_FORMAT;
break;
#endif
@@ -322,7 +322,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
case NET_LL_TUN: /* Virtual Network Device (TUN) */
dev->d_llhdrlen = 0; /* This will be overwritten by tun_ioctl
* if used as a TAP (layer 2) device */
dev->d_mtu = CONFIG_NET_TUN_MTU;
dev->d_pktsize = CONFIG_NET_TUN_PKTSIZE;
devfmt = NETDEV_TUN_FORMAT;
break;
#endif
+4 -3
View File
@@ -287,15 +287,16 @@ config NET_6LOWPAN_MAX_MACTRANSMITS
layer should resend packets if no link-layer ACK wasreceived. This
only makes sense with the csma_driver.
config NET_6LOWPAN_MTU
config NET_6LOWPAN_PKTSIZE
int "6LoWPAN packet buffer size"
default 1294
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.
This value is normally referred to as the MTU (Maximum Transmission
Unit); the payload is the MSS (Maximum Segment Size).
This value is related to the MTU (Maximum Transmission Unit), except
that it includes the size of the link layer header; the payload is
the MSS (Maximum Segment Size).
NOTE that this option depends on fragmentation support. By
supporting fragmentation, we can handle quite large "logical" packet
+1 -1
View File
@@ -95,7 +95,7 @@ Optimal 6LoWPAN Configuration
5. IOBs: Must be big enough to hold one IEEE802.15.4 frame (typically 127).
There must be enough IOBs to decompose the largest IPv6 packet
(CONFIG_NET_6LOWPAN_MTU, default 1294, plus per frame overhead).
(CONFIG_NET_6LOWPAN_PKTSIZE, default 1294, plus per frame overhead).
Fragmentation Headers
---------------------
+1 -1
View File
@@ -84,7 +84,7 @@
* won't work unless there are a few more.
*/
#if CONFIG_NET_6LOWPAN_MTU > (CONFIG_IOB_BUFSIZE * CONFIG_IOB_NBUFFERS)
#if CONFIG_NET_6LOWPAN_PKTSIZE > (CONFIG_IOB_BUFSIZE * CONFIG_IOB_NBUFFERS)
# error Not enough IOBs to hold one full 6LoWPAN packet
#endif
+7 -7
View File
@@ -340,9 +340,9 @@ static int sixlowpan_frame_process(FAR struct radio_driver_s *radio,
/* Drop the packet if it cannot fit into the d_buf */
if (fragsize > CONFIG_NET_6LOWPAN_MTU)
if (fragsize > CONFIG_NET_6LOWPAN_PKTSIZE)
{
nwarn("WARNING: Reassembled packet size exeeds CONFIG_NET_6LOWPAN_MTU\n");
nwarn("WARNING: Reassembled packet size exeeds CONFIG_NET_6LOWPAN_PKTSIZE\n");
return -ENOSPC;
}
@@ -521,10 +521,10 @@ static int sixlowpan_frame_process(FAR struct radio_driver_s *radio,
*/
paysize = iob->io_len - g_frame_hdrlen;
if (paysize > CONFIG_NET_6LOWPAN_MTU)
if (paysize > CONFIG_NET_6LOWPAN_PKTSIZE)
{
nwarn("WARNING: Packet dropped due to payload (%u) > packet buffer (%u)\n",
paysize, CONFIG_NET_6LOWPAN_MTU);
paysize, CONFIG_NET_6LOWPAN_PKTSIZE);
ret = -ENOSPC;
goto errout_with_reass;
}
@@ -532,11 +532,11 @@ static int sixlowpan_frame_process(FAR struct radio_driver_s *radio,
/* Sanity-check size of incoming packet to avoid buffer overflow */
reqsize = g_uncomp_hdrlen + (fragoffset << 3) + paysize;
if (reqsize > CONFIG_NET_6LOWPAN_MTU)
if (reqsize > CONFIG_NET_6LOWPAN_PKTSIZE)
{
nwarn("WARNING: Required buffer size: %u+%u+%u=%u Available=%u\n",
g_uncomp_hdrlen, (fragoffset << 3), paysize,
reqsize, CONFIG_NET_6LOWPAN_MTU);
reqsize, CONFIG_NET_6LOWPAN_PKTSIZE);
ret = -ENOMEM;
goto errout_with_reass;
}
@@ -667,7 +667,7 @@ static int sixlowpan_dispatch(FAR struct radio_driver_s *radio)
* - 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
+1 -1
View File
@@ -140,7 +140,7 @@ static uint16_t sixlowpan_tcp_chksum(FAR const struct ipv6tcp_hdr_s *ipv6tcp,
/* Verify some minimal assumptions */
if (upperlen > CONFIG_NET_6LOWPAN_MTU)
if (upperlen > CONFIG_NET_6LOWPAN_PKTSIZE)
{
return 0;
}
+1 -1
View File
@@ -95,7 +95,7 @@ static uint16_t sixlowpan_udp_chksum(FAR const struct ipv6udp_hdr_s *ipv6udp,
/* Verify some minimal assumptions */
if (upperlen > CONFIG_NET_6LOWPAN_MTU)
if (upperlen > CONFIG_NET_6LOWPAN_PKTSIZE)
{
return 0;
}
+1 -1
View File
@@ -102,7 +102,7 @@ uint16_t tcp_get_recvwindow(FAR struct net_driver_s *dev)
* is the minimum size.
*/
mss = dev->d_mtu - (NET_LL_HDRLEN(dev) + iplen + TCP_HDRLEN);
mss = dev->d_pktsize - (NET_LL_HDRLEN(dev) + iplen + TCP_HDRLEN);
#ifdef CONFIG_NET_TCP_READAHEAD
/* Update the TCP received window based on read-ahead I/O buffer
+2 -2
View File
@@ -93,7 +93,7 @@ uint16_t ipv4_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
/* Verify some minimal assumptions */
if (upperlen > NET_DEV_MTU(dev))
if (upperlen > NETDEV_PKTSIZE(dev))
{
return 0;
}
@@ -146,7 +146,7 @@ uint16_t ipv6_upperlayer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
/* Verify some minimal assumptions */
if (upperlen > NET_DEV_MTU(dev))
if (upperlen > NETDEV_PKTSIZE(dev))
{
return 0;
}