Networking: With these changes, I can ping the local loopback device from the simulator

This commit is contained in:
Gregory Nutt 2015-08-24 13:49:12 -06:00
parent 0b012c7978
commit 933d74e5c1
15 changed files with 135 additions and 72 deletions

2
arch

@ -1 +1 @@
Subproject commit c50e6b0277974daf54f97105c5ad99057b0ad1aa
Subproject commit 1ffc0ecc02112a9d813dc9f95f2a8ecac4d8c6d8

@ -1 +1 @@
Subproject commit 71ee5a6c640704517a24c3cbbb100caeba5a78ca
Subproject commit e1e1873700ffda7aeb632e2b1234333d88ce3457

View File

@ -6,8 +6,9 @@
comment "General Ethernet MAC Driver Options"
config NETDEV_LOOPBACK
bool "Local loopback support"
default n
bool
default n if !NET_LOOPBACK
default y if NET_LOOPBACK
select NET_NOINTS
depends on EXPERIMENTAL
---help---
@ -315,23 +316,6 @@ config NET_SLIP_DEFPRIO
---help---
Provides the priority for SLIP RX and TX threads.
config NET_SLIP_MTU
int "Packet size (MTU)"
default 296
---help---
Provides the size of the SLIP packet buffers.
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.
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: 40 + 128. I believe that is to allow for the 2x
worst cast packet expansion. Ideally we would like to advertise the
256 MSS, but restrict transfers to 128 bytes (possibly by modifying
the tcp_mss() macro).
config NET_SLIP_NINTERFACES
int "Number of SLIP interfaces"
default 1

View File

@ -38,7 +38,7 @@
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_NET) && defined(CONFIG_NETDEV_LOOBACK)
#if defined(CONFIG_NET) && defined(CONFIG_NETDEV_LOOPBACK)
#include <stdint.h>
#include <stdbool.h>
@ -81,7 +81,8 @@
/* This is a helper pointer for accessing the contents of the Ethernet header */
#define BUF ((struct eth_hdr_s *)priv->lo_dev.d_buf)
#define IPv4BUF ((FAR struct ipv4_hdr_s *)priv->lo_dev.d_buf)
#define IPv6BUF ((FAR struct ipv6_hdr_s *)priv->lo_dev.d_buf)
/****************************************************************************
* Private Types
@ -121,7 +122,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv);
static int lo_txpoll(FAR struct net_driver_s *dev);
static inline void lo_poll(FAR struct lo_driver_s *priv);
static void lo_poll_work(FAR void *arg);
static void lo_poll_expiry(int argc, uint32_t arg, ...);
static void lo_poll_expiry(int argc, wdparm_t arg, ...);
/* NuttX callback functions */
@ -169,7 +170,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv)
/* We only accept IP packets of the configured type and ARP packets */
#ifdef CONFIG_NET_IPv4
if (BUF->type == HTONS(ETHTYPE_IP))
if ((IPv4BUF->vhl & IP_VERSION_MASK) == IPv4_VERSION)
{
nllvdbg("IPv4 frame\n");
ipv4_input(&priv->lo_dev);
@ -190,7 +191,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv)
else
#endif
#ifdef CONFIG_NET_IPv6
if (BUF->type == HTONS(ETHTYPE_IP6))
if ((IPv6BUF->vtc & IP_VERSION_MASK) == IPv46VERSION)
{
nllvdbg("Iv6 frame\n");
ipv6_input(&priv->lo_dev);
@ -211,7 +212,7 @@ static void lo_loopback(FAR struct lo_driver_s *priv)
else
#endif
{
ndbg("WARNING: Unrecognized packet type dropped: %04x\n", BUF->type);
ndbg("WARNING: Unrecognized packet type dropped: %04x\n", IPv4BUF->type);
}
}
@ -331,7 +332,7 @@ static void lo_poll_work(FAR void *arg)
*
****************************************************************************/
static void lo_poll_expiry(int argc, uint32_t arg, ...)
static void lo_poll_expiry(int argc, wdparm_t arg, ...)
{
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg;
@ -390,7 +391,7 @@ static int lo_ifup(FAR struct net_driver_s *dev)
/* Set and activate a timer process */
(void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, (uint32_t)priv);
(void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, (wdparm_t)priv);
priv->lo_bifup = true;
return OK;
@ -615,7 +616,7 @@ int localhost_initialize(void)
priv->lo_dev.d_addmac = lo_addmac; /* Add multicast MAC address */
priv->lo_dev.d_rmmac = lo_rmmac; /* Remove multicast MAC address */
#endif
priv->lo_dev.d_private = (void*)g_loopback; /* Used to recover private state from dev */
priv->lo_dev.d_private = (void*)priv; /* Used to recover private state from dev */
/* Create a watchdog for timing polling for and timing of transmissions */
@ -630,18 +631,18 @@ int localhost_initialize(void)
/* Set the local loopback IP address */
#ifdef CONFIG_NET_IPv4
net_ipv4addr_copy(dev->d_ipaddr, g_lo_ipv4addr);
net_ipv4addr_copy(dev->d_draddr, g_lo_ipv4addr);
net_ipv4addr_copy(dev->d_netmask, g_lo_ipv4mask);
net_ipv4addr_copy(priv->lo_dev.d_ipaddr, g_lo_ipv4addr);
net_ipv4addr_copy(priv->lo_dev.d_draddr, g_lo_ipv4addr);
net_ipv4addr_copy(priv->lo_dev.d_netmask, g_lo_ipv4mask);
#endif
#ifdef CONFIG_NET_IPv6
net_ipv6addr_hdrcopy(dev->d_ipv6addr, g_lo_ipv6addr)
net_ipv6addr_hdrcopy(dev->d_ipv6draddr, g_lo_ipv6addr)
net_ipv6addr_hdrcopy(dev->d_ipv6netmask, g_ipv6_allzeroaddr)
net_ipv6addr_copy(priv->lo_dev.d_ipv6addr, g_lo_ipv6addr)
net_ipv6addr_copy(priv->lo_dev.d_ipv6draddr, g_lo_ipv6addr)
net_ipv6addr_copy(priv->lo_dev.d_ipv6netmask, g_ipv6_allzeroaddr)
#endif
/* Put the network in the UP state */
return lo_ifup(&priv->lo_dev);
}
#endif /* CONFIG_NET && CONFIG_NETDEV_LOOBACK */
#endif /* CONFIG_NET && CONFIG_NETDEV_LOOPBACK */

View File

@ -149,13 +149,13 @@ static inline void skel_txtimeout_process(FAR struct skel_driver_s *priv);
#ifdef CONFIG_NET_NOINTS
static void skel_txtimeout_work(FAR void *arg);
#endif
static void skel_txtimeout_expiry(int argc, uint32_t arg, ...);
static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...);
static inline void skel_poll_process(FAR struct skel_driver_s *priv);
#ifdef CONFIG_NET_NOINTS
static void skel_poll_work(FAR void *arg);
#endif
static void skel_poll_expiry(int argc, uint32_t arg, ...);
static void skel_poll_expiry(int argc, wdparm_t arg, ...);
/* NuttX callback functions */
@ -216,7 +216,7 @@ static int skel_transmit(FAR struct skel_driver_s *priv)
/* Setup the TX timeout watchdog (perhaps restarting the timer) */
(void)wd_start(priv->sk_txtimeout, skeleton_TXTIMEOUT,
skel_txtimeout_expiry, 1, (uint32_t)priv);
skel_txtimeout_expiry, 1, (wdparm_t)priv);
return OK;
}
@ -666,7 +666,7 @@ static void skel_txtimeout_work(FAR void *arg)
*
****************************************************************************/
static void skel_txtimeout_expiry(int argc, uint32_t arg, ...)
static void skel_txtimeout_expiry(int argc, wdparm_t arg, ...)
{
FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg;
@ -726,7 +726,8 @@ static inline void skel_poll_process(FAR struct skel_driver_s *priv)
/* Setup the watchdog poll timer again */
(void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, priv);
(void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1,
(wdparm_t)priv);
}
/****************************************************************************
@ -778,7 +779,7 @@ static void skel_poll_work(FAR void *arg)
*
****************************************************************************/
static void skel_poll_expiry(int argc, uint32_t arg, ...)
static void skel_poll_expiry(int argc, wdparm_t arg, ...)
{
FAR struct skel_driver_s *priv = (FAR struct skel_driver_s *)arg;
@ -854,7 +855,8 @@ static int skel_ifup(FAR struct net_driver_s *dev)
/* Set and activate a timer process */
(void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1, (uint32_t)priv);
(void)wd_start(priv->sk_txpoll, skeleton_WDDELAY, skel_poll_expiry, 1,
(wdparm_t)priv);
/* Enable the Ethernet interrupt */

View File

@ -62,6 +62,12 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* IP Version Mask (bits 0-3 of first byte) */
#define IP_VERSION_MASK 0x70
#define IPv4_VERSION 0x40
#define IPv6_VERSION 0x60
/* Values for the IP protocol field */
#define IP_PROTO_ICMP 1

View File

@ -49,7 +49,7 @@
#include <nuttx/net/netconfig.h>
#include <nuttx/net/ip.h>
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
/****************************************************************************
* Public Type Definitions
@ -90,10 +90,31 @@ EXTERN const net_ipv6addr_t g_lo_ipv6addr;
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Function: localhost_initialize
*
* Description:
* Initialize the Ethernet controller and driver
*
* Parameters:
* intf - In the case where there are multiple EMACs, this value
* identifies which EMAC is to be initialized.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/
#ifdef CONFIG_NETDEV_LOOPBACK
int localhost_initialize(void);
#endif /* CONFIG_NETDEV_LOOPBACK */
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_NETDEV_LOOPBACK */
#endif /* CONFIG_NET_LOOPBACK */
#endif /* __INCLUDE_NUTTX_NET_LOOPBACK_H */

View File

@ -136,6 +136,10 @@
# define MIN_NET_DEV_MTU _MIN_SLIP_MTU
# define MAX_NET_DEV_MTU _MAX_SLIP_MTU
/* For the loopback device, we will use the largest representable MTU */
# define NET_LO_MTU UINT16_MAX
#elif defined(CONFIG_NET_SLIP)
/* There is no link layer header with SLIP */
@ -156,6 +160,20 @@
# define MIN_NET_DEV_MTU CONFIG_NET_ETH_MTU
# define MAX_NET_DEV_MTU CONFIG_NET_ETH_MTU
#elif defined(CONFIG_NET_LOOPBACK)
/* Force the loopback MTU to some reasonable size. We could do something smarter, but
* The case where the local loopback device is the only device is very unusal.
*/
# define NET_LO_MTU 1518
/* Assume standard Ethernet link layer header */
# define NET_LL_HDRLEN(d) 0
# define NET_DEV_MTU(d) NET_LO_MTU
# define MIN_NET_DEV_MTU NET_LO_MTU
# define MAX_NET_DEV_MTU NET_LO_MTU
#else
/* Perhaps only Unix domain sockets of the loopback device */
@ -166,10 +184,6 @@
#endif /* MULTILINK or SLIP or ETHERNET */
/* For the loopback device, we will use the largest representable MTU */
#define NET_LO_MTU UINT16_MAX
/* Layer 3/4 Configuration Options ******************************************/
/* IP configuration options */
@ -230,9 +244,12 @@
/* If Ethernet is supported, then it will have the smaller MSS */
#ifdef CONFIG_NET_SLIP
#if defined(CONFIG_NET_SLIP)
# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - (h))
# define __MIN_UDP_MSS(h) SLIP_UDP_MSS(h)
#elif defined(CONFIG_NET_LOOPBACK)
# define LO_UDP_MSS(h) (NET_LO_MTU - (h))
# define __MIN_UDP_MSS(h) LO_UDP_MSS(h)
#endif
#ifdef CONFIG_NET_ETHERNET
@ -354,9 +371,12 @@
/* If Ethernet is supported, then it will have the smaller MSS */
#ifdef CONFIG_NET_SLIP
#if defined(CONFIG_NET_SLIP)
# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - (h))
# define __MIN_TCP_MSS(h) SLIP_TCP_MSS(h)
#elif defined(CONFIG_NET_LOOPBACK)
# define LO_TCP_MSS(h) (NET_LO_MTU - (h))
# define __MIN_TCP_MSS(h) LO_TCP_MSS(h)
#endif
#ifdef CONFIG_NET_ETHERNET
@ -433,11 +453,16 @@
# define NET_DEV_RCVWNDO(d) CONFIG_NET_SLIP_TCP_RECVWNDO
#else /* if defined(CONFIG_NET_ETHERNET) */
#elif defined(CONFIG_NET_ETHERNET)
/* Only Ethernet.. use the configured SLIP receive window size */
# define NET_DEV_RCVWNDO(d) CONFIG_NET_ETH_TCP_RECVWNDO
#else /* if defined(CONFIG_NET_LOOPBACK) */
/* Only loal loopback.. use the fixed loopback receive window size */
# define NET_DEV_RCVWNDO(d) NET_LO_TCP_RECVWNDO
#endif /* MULTILINK or SLIP or ETHERNET */
/* How long a connection should stay in the TIME_WAIT state.

View File

@ -74,7 +74,7 @@
*
****************************************************************************/
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
static bool lib_lo_ipv4match(FAR const void *addr, socklen_t len, int type)
{
FAR struct in_addr *ipv4addr;
@ -108,7 +108,7 @@ static bool lib_lo_ipv4match(FAR const void *addr, socklen_t len, int type)
*
****************************************************************************/
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
static bool lib_lo_ipv6match(FAR const void *addr, socklen_t len, int type)
{
FAR struct in_addr6 *ipv6addr;
@ -146,7 +146,7 @@ static bool lib_lo_ipv6match(FAR const void *addr, socklen_t len, int type)
*
****************************************************************************/
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
static int lib_localhost(FAR const void *addr, socklen_t len, int type,
FAR struct hostent *host, FAR char *buf,
size_t buflen, int *h_errnop)
@ -395,7 +395,7 @@ int gethostbyaddr_r(FAR const void *addr, socklen_t len, int type,
*h_errnop = 0;
}
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
/* Check for the local loopback address */
if (lib_localhost(addr, len, type, host, but, buflen, h_errnop) == 0)

View File

@ -231,7 +231,7 @@ static int lib_numeric_address(FAR const char *name, FAR struct hostent *host,
*
****************************************************************************/
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
static int lib_localhost(FAR const char *name, FAR struct hostent *host,
FAR char *buf, size_t buflen)
{
@ -740,7 +740,7 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
return OK;
}
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
/* Check for the local loopback host name */
if (lib_localhost(name, host, buf, buflen) == 0)

View File

@ -85,12 +85,25 @@ config NET_SLIP_MTU
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.
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).
SLIP is required to support at lest 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.
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: 40 + 128. I believe that is to allow for the 2x
worst cast packet expansion. Ideally we would like to advertise the
256 MSS, but restrict transfers to 128 bytes (possibly by modifying
the tcp_mss() macro).
config NET_SLIP_TCP_RECVWNDO
int "SLIP TCP receive window size"
@ -150,6 +163,15 @@ config NET_ETHERNET
no need to define anything special in the configuration file to use
Ethernet -- it is the default).
config NET_LOOPBACK
bool "Local loopback"
default n
depends on EXPERIMENTAL
---help---
Add support for the local network loopback device, lo. Any additional
networking devices that are enabled must be compatible with
CONFIG_NET_NOINTS.
config NET_SLIP
bool "SLIP support"
default n

View File

@ -33,7 +33,7 @@
#
############################################################################
ifeq ($(CONFIG_NETDEV_LOOPBACK),y)
ifeq ($(CONFIG_NET_LOOPBACK),y)
# Local loopback support

View File

@ -43,7 +43,7 @@
#include "loopback/loopback.h"
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
/****************************************************************************
* Public Data
@ -67,4 +67,4 @@ const net_ipv6addr_t g_lo_ipv6addr =
* Public Functions
****************************************************************************/
#endif /* CONFIG_NETDEV_LOOPBACK */
#endif /* CONFIG_NET_LOOPBACK */

View File

@ -42,7 +42,7 @@
#include <nuttx/config.h>
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
/****************************************************************************
* Pre-processor Definitions
@ -68,5 +68,5 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
#endif /* CONFIG_NETDEV_LOOPBACK */
#endif /* CONFIG_NET_LOOPBACK */
#endif /* __NET_LOOPBACK_LOOBACK_H */

View File

@ -68,8 +68,10 @@
#if defined(CONFIG_NET_SLIP)
# define NETDEV_DEFAULT_FORMAT NETDEV_SLIP_FORMAT
#else /* if defined(CONFIG_NET_ETHERNET) */
#elif defined(CONFIG_NET_ETHERNET)
# define NETDEV_DEFAULT_FORMAT NETDEV_ETH_FORMAT
#else /* if defined(CONFIG_NET_LOOPBACK) */
# define NETDEV_DEFAULT_FORMAT NETDEV_LO_FORMAT
#endif
/****************************************************************************
@ -191,7 +193,7 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
switch (lltype)
{
#ifdef CONFIG_NETDEV_LOOPBACK
#ifdef CONFIG_NET_LOOPBACK
case NET_LL_LOOPBACK: /* Local loopback */
dev->d_llhdrlen = 0;
dev->d_mtu = NET_LO_MTU;