Networking: Rethink last fix. We can make this less protocol dependent.

This commit is contained in:
Gregory Nutt 2017-08-23 15:30:56 -06:00
parent 394a340da0
commit e89edd6784
2 changed files with 68 additions and 40 deletions

View File

@ -9,7 +9,7 @@
* Note: Network configuration options the netconfig.h should not be changed,
* but rather the per-project defconfig file.
*
* Copyright (C) 2007, 2011, 2014-2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* This logic was leveraged from uIP which also has a BSD-style license:
@ -70,6 +70,34 @@
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/* Try to eliminate dependencies on other header files. This should not harm
* portability because these are well-known constants anyway.
*/
#ifdef IPv4_HDRLEN
# define __IPv4_HDRLEN IPv4_HDRLEN
#else
# define __IPv4_HDRLEN 20
#endif
#ifdef IPv6_HDRLEN
# define __IPv6_HDRLEN IPv6_HDRLEN
#else
# define __IPv6_HDRLEN 40
#endif
#ifdef UDP_HDRLEN
# define __UDP_HDRLEN UDP_HDRLEN
#else
# define __UDP_HDRLEN 8
#endif
#ifdef TCP_HDRLEN
# define __TCP_HDRLEN TCP_HDRLEN
#else
# define __TCP_HDRLEN 20 /* REVISIT: Not really a constant */
#endif
/* Layer 2 Configuration Options ********************************************/
/* The default data link laye is Ethernet. If CONFIG_NET_SLIP is defined in
@ -242,29 +270,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 NET_DEV_MTU(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) (NET_DEV_MTU(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_MTU - 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_MTU - __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_MTU - __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_MTU - __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_MTU - __UDP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_ETHERNET
@ -326,25 +354,25 @@
#endif
#ifdef CONFIG_NET_IPv4
# define UDP_IPv4_MSS(d) UDP_MSS(d,IPv4_HDRLEN)
# define ETH_IPv4_UDP_MSS ETH_UDP_MSS(IPv4_HDRLEN)
# define SLIP_IPv4_UDP_MSS SLIP_UDP_MSS(IPv4_HDRLEN)
# define TUN_IPv4_UDP_MSS TUN_UDP_MSS(IPv4_HDRLEN)
# define UDP_IPv4_MSS(d) UDP_MSS(d,__IPv4_HDRLEN)
# define ETH_IPv4_UDP_MSS ETH_UDP_MSS(__IPv4_HDRLEN)
# define SLIP_IPv4_UDP_MSS SLIP_UDP_MSS(__IPv4_HDRLEN)
# define TUN_IPv4_UDP_MSS TUN_UDP_MSS(__IPv4_HDRLEN)
# define MIN_IPv4_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN)
# define MIN_UDP_MSS __MIN_UDP_MSS(IPv4_HDRLEN)
# define MIN_IPv4_UDP_MSS __MIN_UDP_MSS(__IPv4_HDRLEN)
# define MIN_UDP_MSS __MIN_UDP_MSS(__IPv4_HDRLEN)
# undef MAX_UDP_MSS
# define MAX_IPv4_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN)
# define MAX_UDP_MSS __MAX_UDP_MSS(IPv4_HDRLEN)
# define MAX_IPv4_UDP_MSS __MAX_UDP_MSS(__IPv4_HDRLEN)
# define MAX_UDP_MSS __MAX_UDP_MSS(__IPv4_HDRLEN)
#endif
/* If IPv6 is support, it will have the smaller MSS */
#ifdef CONFIG_NET_IPv6
# undef MIN_UDP_MSS
# define MIN_IPv6_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN)
# define MIN_UDP_MSS __MIN_UDP_MSS(IPv6_HDRLEN)
# define MIN_IPv6_UDP_MSS __MIN_UDP_MSS(__IPv6_HDRLEN)
# define MIN_UDP_MSS __MIN_UDP_MSS(__IPv6_HDRLEN)
#endif
/* TCP configuration options */
@ -407,37 +435,37 @@
#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 NET_DEV_MTU(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
* MSS value. Here we arbitrarily select the minimum MSS for that case.
*
* REVISIT: TCP_HDRLEN is not really a constant!
* 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) (NET_DEV_MTU(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_MTU - 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_MTU - __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_MTU - __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_MTU - __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_MTU - __TCP_HDRLEN - (h))
#endif
#ifdef CONFIG_NET_ETHERNET
@ -499,32 +527,32 @@
#endif
/* If IPv4 is supported, it will have the larger MSS.
* NOTE: MSS calcuation excludes the TCP_HDRLEN.
* NOTE: MSS calcuation excludes the __TCP_HDRLEN.
*/
#ifdef CONFIG_NET_IPv6
# define TCP_IPv6_MSS(d) TCP_MSS(d,IPv6_HDRLEN)
# define ETH_IPv6_TCP_MSS ETH_TCP_MSS(IPv6_HDRLEN)
# define SLIP_IPv6_TCP_MSS SLIP_TCP_MSS(IPv6_HDRLEN)
# define TUN_IPv6_TCP_MSS TUN_TCP_MSS(IPv6_HDRLEN)
# define MAX_TCP_MSS __MAX_TCP_MSS(IPv6_HDRLEN)
# define TCP_IPv6_MSS(d) TCP_MSS(d,__IPv6_HDRLEN)
# define ETH_IPv6_TCP_MSS ETH_TCP_MSS(__IPv6_HDRLEN)
# define SLIP_IPv6_TCP_MSS SLIP_TCP_MSS(__IPv6_HDRLEN)
# define TUN_IPv6_TCP_MSS TUN_TCP_MSS(__IPv6_HDRLEN)
# define MAX_TCP_MSS __MAX_TCP_MSS(__IPv6_HDRLEN)
#endif
#ifdef CONFIG_NET_IPv4
# define TCP_IPv4_MSS(d) TCP_MSS(d,IPv4_HDRLEN)
# define ETH_IPv4_TCP_MSS ETH_TCP_MSS(IPv4_HDRLEN)
# define SLIP_IPv4_TCP_MSS SLIP_TCP_MSS(IPv4_HDRLEN)
# define TUN_IPv4_TCP_MSS TUN_TCP_MSS(IPv4_HDRLEN)
# define MIN_TCP_MSS __MIN_TCP_MSS(IPv4_HDRLEN)
# define TCP_IPv4_MSS(d) TCP_MSS(d,__IPv4_HDRLEN)
# define ETH_IPv4_TCP_MSS ETH_TCP_MSS(__IPv4_HDRLEN)
# define SLIP_IPv4_TCP_MSS SLIP_TCP_MSS(__IPv4_HDRLEN)
# define TUN_IPv4_TCP_MSS TUN_TCP_MSS(__IPv4_HDRLEN)
# define MIN_TCP_MSS __MIN_TCP_MSS(__IPv4_HDRLEN)
# undef MAX_TCP_MSS
# define MAX_TCP_MSS __MAX_TCP_MSS(IPv4_HDRLEN)
# define MAX_TCP_MSS __MAX_TCP_MSS(__IPv4_HDRLEN)
#endif
/* If IPv6 is supported, it will have the smaller MSS */
#ifdef CONFIG_NET_IPv6
# undef MIN_TCP_MSS
# define MIN_TCP_MSS __MIN_TCP_MSS(IPv6_HDRLEN)
# define MIN_TCP_MSS __MIN_TCP_MSS(__IPv6_HDRLEN)
#endif
/* The size of the advertised receiver's window.

View File

@ -50,9 +50,9 @@
#include <net/if.h>
#include <net/ethernet.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/arp.h>
#include <nuttx/net/tcp.h>
#include "utils/utils.h"
#include "igmp/igmp.h"