IP forwarding: Move to separate directory. A few fixes from early testing; In TUN driver, do all polling on worker thread. Otherwise, the stack gets very deep.

This commit is contained in:
Gregory Nutt
2017-07-07 18:33:06 -06:00
parent 99ef7c6669
commit 7258f1cbfc
20 changed files with 164 additions and 92 deletions
+1 -34
View File
@@ -284,40 +284,7 @@ menuconfig NET_IPv6
source "net/neighbor/Kconfig"
source "net/sixlowpan/Kconfig"
config NET_IPFORWARD
bool "Enable L2 forwarding"
default n
---help---
Enable forwarding of packets. Packets received with IP addresses
that are not supported by this platform will be forwarded to the
appropriate network device. Routing table support may be required.
config NET_IPFORWARD_BROADCAST
bool "Forward broadcast/multicast packets"
default n
depends on NET_IPFORWARD && NETDEV_MULTINIC
---help---
If selected, broadcast packets received on one network device will
be forwarded though other network devices.
config NET_IPFORWARD_NSTRUCT
int "Number of pre-allocated forwarding structures"
default 4
depends on NET_IPFORWARD && NETDEV_MULTINIC
---help---
When packets are forwarded from on device to another, a structure
must be allocated to hold the state of forwarding across several
asynchronous events. Those structures are pre-allocated for
minimal, deterministic performance and to prevent hogging of memory
(of course, that means that this value must be carefully selected
for your application). This setting defines the number of such pre-
allocated structures.
NOTE: This setting effectively puts a maximum on the number of
packets that may be waiting to be forwarded from one network device
to another. CONFIG_IOB_NBUFFERS also limits the forward because the
payload of the packet (up to the MSS) is retain in IOBs.
source "net/ipforward/Kconfig"
endmenu # Internet Protocol Selection
+2 -1
View File
@@ -1,7 +1,7 @@
############################################################################
# net/Makefile
#
# Copyright (C) 2007, 2008, 2011-2016 Gregory Nutt. All rights reserved.
# Copyright (C) 2007, 2008, 2011-2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -68,6 +68,7 @@ include tcp/Make.defs
include udp/Make.defs
include sixlowpan/Make.defs
include devif/Make.defs
include ipforward/Make.defs
include loopback/Make.defs
include route/Make.defs
include procfs/Make.defs
+16 -15
View File
@@ -8,21 +8,22 @@ Directory Structure
|
`- net/
|
+- arp - Address resolution protocol (IPv4)
+- devif - Stack/device interface layer
+- icmp - Internet Control Message Protocol (IPv4)
+- icmpv6 - Internet Control Message Protocol (IPv6)
+- local - Unix domain (local) sockets
+- loopback - Local loopback
+- neighbor - Neighbor Discovery Protocol (IPv6)
+- netdev - Socket network device interface
+- pkt - "Raw" packet socket support
+- socket - BSD socket interface
+- route - Routing table support
+- tcp - Transmission Control Protocol
+- udp - User Datagram Protocol
+- usrsock - User socket API for user-space networking stack
`- utils - Miscellaneous utility functions
+- arp - Address resolution protocol (IPv4)
+- devif - Stack/device interface layer
+- icmp - Internet Control Message Protocol (IPv4)
+- icmpv6 - Internet Control Message Protocol (IPv6)
+- ipforward - IP forwarding logic
+- local - Unix domain (local) sockets
+- loopback - Local loopback
+- neighbor - Neighbor Discovery Protocol (IPv6)
+- netdev - Socket network device interface
+- pkt - "Raw" packet socket support
+- socket - BSD socket interface
+- route - Routing table support
+- tcp - Transmission Control Protocol
+- udp - User Datagram Protocol
+- usrsock - User socket API for user-space networking stack
`- utils - Miscellaneous utility functions
+-------------------------------------------------------------------++------------------------+
+3 -7
View File
@@ -42,21 +42,17 @@ NET_CSRCS += devif_callback.c
ifeq ($(CONFIG_NET_IPv4),y)
NET_CSRCS += ipv4_input.c
ifeq ($(CONFIG_NET_IPFORWARD),y)
NET_CSRCS += ipv4_forward.c
endif
endif
ifeq ($(CONFIG_NET_IPv6),y)
NET_CSRCS += ipv6_input.c
ifeq ($(CONFIG_NET_IPFORWARD),y)
NET_CSRCS += ipv6_forward.c
endif
endif
# IP forwarding
ifeq ($(CONFIG_NET_IPFORWARD),y)
ifeq ($(CONFIG_NETDEV_MULTINIC),y)
NET_CSRCS += ip_forward.c devif_forward.c
NET_CSRCS += devif_forward.c
endif
endif
+1 -1
View File
@@ -43,7 +43,7 @@
#include <nuttx/net/netdev.h>
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NETDEV_MULTINIC)
-7
View File
@@ -50,7 +50,6 @@
#include <nuttx/net/netstats.h>
#include <nuttx/net/ip.h>
#include "devif/ip_forward.h"
#include "devif/devif.h"
/****************************************************************************
@@ -168,11 +167,5 @@ void devif_initialize(void)
/* Initialize callback support */
devif_callback_init();
#ifdef HAVE_FWDALLOC
/* Initialize IP forwarding support */
ip_forward_initialize();
#endif
}
#endif /* CONFIG_NET */
+1 -1
View File
@@ -99,7 +99,7 @@
#include "icmp/icmp.h"
#include "igmp/igmp.h"
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
/****************************************************************************
+1 -1
View File
@@ -100,7 +100,7 @@
#include "icmpv6/icmpv6.h"
#include "netdev/netdev.h"
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
/****************************************************************************
+1 -1
View File
@@ -49,7 +49,7 @@
#include <nuttx/net/ip.h>
#include <nuttx/net/netstats.h>
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
#include "netdev/netdev.h"
#include "arp/arp.h"
+1 -1
View File
@@ -49,7 +49,7 @@
#include <nuttx/net/ip.h>
#include <nuttx/net/netstats.h>
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
#include "netdev/netdev.h"
#include "arp/arp.h"
+39
View File
@@ -0,0 +1,39 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config NET_IPFORWARD
bool "Enable L2 forwarding"
default n
---help---
Enable forwarding of packets. Packets received with IP addresses
that are not supported by this platform will be forwarded to the
appropriate network device. Routing table support may be required.
config NET_IPFORWARD_BROADCAST
bool "Forward broadcast/multicast packets"
default n
depends on NET_IPFORWARD && NETDEV_MULTINIC
---help---
If selected, broadcast packets received on one network device will
be forwarded though other network devices.
config NET_IPFORWARD_NSTRUCT
int "Number of pre-allocated forwarding structures"
default 4
depends on NET_IPFORWARD && NETDEV_MULTINIC
---help---
When packets are forwarded from on device to another, a structure
must be allocated to hold the state of forwarding across several
asynchronous events. Those structures are pre-allocated for
minimal, deterministic performance and to prevent hogging of memory
(of course, that means that this value must be carefully selected
for your application). This setting defines the number of such pre-
allocated structures.
NOTE: This setting effectively puts a maximum on the number of
packets that may be waiting to be forwarded from one network device
to another. CONFIG_IOB_NBUFFERS also limits the forward because the
payload of the packet (up to the MSS) is retain in IOBs.
+57
View File
@@ -0,0 +1,57 @@
############################################################################
# net/ipforward/Make.defs
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
# IP forwarding source files
ifeq ($(CONFIG_NET_IPFORWARD),y)
ifeq ($(CONFIG_NET_IPv4),y)
NET_CSRCS += ipv4_forward.c
endif
ifeq ($(CONFIG_NET_IPv6),y)
NET_CSRCS += ipv6_forward.c
endif
ifeq ($(CONFIG_NETDEV_MULTINIC),y)
NET_CSRCS += ip_forward.c
endif
# Include IP forwaring build support
DEPPATH += --dep-path ipforward
VPATH += :ipforward
endif
@@ -1,5 +1,5 @@
/****************************************************************************
* net/devif/ip_forward.c
* net/ipforward/ip_forward.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -44,7 +44,7 @@
#include <errno.h>
#include <debug.h>
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NETDEV_MULTINIC)
@@ -1,5 +1,5 @@
/****************************************************************************
* net/devif/ip_forward.h
* net/ipforward/ip_forward.h
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -33,8 +33,8 @@
*
****************************************************************************/
#ifndef __NET_DEVIF_IP_FORWARD_H
#define __NET_DEVIF_IP_FORWARD_H
#ifndef __NET_IPFORWARD_IP_FORWARD_H
#define __NET_IPFORWARD_IP_FORWARD_H
/****************************************************************************
* Included Files
@@ -163,6 +163,9 @@ struct forward_s
FAR struct iob_s *f_iob; /* IOB chain containing the packet */
FAR struct devif_callback_s *f_cb; /* Reference to callback instance */
union fwd_conn_u f_conn; /* Protocol-specific connection struct */
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
uint8_t f_domain; /* Domain: PF_INET or PF_INET6 */
#endif
};
/****************************************************************************
@@ -356,4 +359,4 @@ int ipv6_forward(FAR struct net_driver_s *dev, FAR struct ipv6_hdr_s *ipv6);
#endif
#endif /* CONFIG_NET_IPFORWARD */
#endif /* __NET_DEVIF_IP_FORWARD_H */
#endif /* __NET_IPFORWARD_IP_FORWARD_H */
@@ -1,5 +1,5 @@
/****************************************************************************
* net/devif/ipv4_forward.c
* net/ipforward/ipv4_forward.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -54,7 +54,7 @@
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "icmp/icmp.h"
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NET_IPv4)
@@ -297,7 +297,10 @@ static int ipv4_dev_forward(FAR struct net_driver_s *dev,
/* Initialize the easy stuff in the forwarding structure */
fwd->f_dev = fwddev; /* Forwarding device */
fwd->f_dev = fwddev; /* Forwarding device */
#ifdef CONFIG_NET_IPv5
fwd->f_domain = PF_INET; /* IPv64 address domain */
#endif
#ifdef CONFIG_DEBUG_NET_WARN
/* Get the size of the IPv4 + L3 header. */
@@ -1,5 +1,5 @@
/****************************************************************************
* net/devif/ipv6_forward.c
* net/ipforward/ipv6_forward.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -53,7 +53,7 @@
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "icmpv6/icmpv6.h"
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NET_IPv6)
@@ -408,7 +408,10 @@ static int ipv6_dev_forward(FAR struct net_driver_s *dev,
/* Initialize the easy stuff in the forwarding structure */
fwd->f_dev = fwddev; /* Forwarding device */
fwd->f_dev = fwddev; /* Forwarding device */
#ifdef CONFIG_NET_IPv4
fwd->f_domain = PF_INET6; /* IPv6 address domain */
#endif
#ifdef CONFIG_DEBUG_NET_WARN
/* Get the size of the IPv6 + L3 header. */
+7
View File
@@ -47,6 +47,7 @@
#include "socket/socket.h"
#include "devif/devif.h"
#include "netdev/netdev.h"
#include "ipforward/ip_forward.h"
#include "arp/arp.h"
#include "sixlowpan/sixlowpan.h"
#include "neighbor/neighbor.h"
@@ -112,6 +113,12 @@ void net_setup(void)
devif_initialize();
#ifdef HAVE_FWDALLOC
/* Initialize IP forwarding support */
ip_forward_initialize();
#endif
#ifdef CONFIG_NET_PKT
/* Initialize packet socket support */
+4 -2
View File
@@ -807,8 +807,10 @@ void tcp_send(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
* send to complete.
*
* Input Parameters:
* fwd - An initialized instance of the common forwarding structure that
* includes everything needed to perform the forwarding operation.
* domain - Either PF_INET or PF_INET6
* fwd - An initialized instance of the common forwarding structure
* that includes everything needed to perform the forwarding
* operation.
*
* Returned Value:
* Zero is returned if the packet was successfully forwarded; A negated
+5 -5
View File
@@ -50,7 +50,7 @@
#include <nuttx/net/ip.h>
#include <nuttx/net/netstats.h>
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
#include "netdev/netdev.h"
#include "arp/arp.h"
@@ -89,7 +89,7 @@ static inline void forward_ipselect(FAR struct forward_s *fwd)
{
/* Which domain the connection support */
if (fwd->f_conn.tcp.domain == PF_INET)
if (fwd->f_domain == PF_INET)
{
/* Select the IPv4 domain */
@@ -151,7 +151,7 @@ static inline bool tcp_forward_addrchck(FAR struct forward_s *fwd)
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET)
if (fwd->f_domain == PF_INET)
#endif
{
#if !defined(CONFIG_NET_ARP_IPIN) && !defined(CONFIG_NET_ARP_SEND)
@@ -207,7 +207,7 @@ static void tcp_dropstats(FAR struct forward_s *fwd)
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (fwd->f_conn.tcp.domain == PF_INET)
if (fwd->f_domain == PF_INET)
#endif
{
g_netstats.ipv4.drop++;
@@ -389,7 +389,7 @@ int tcp_forward(FAR struct forward_s *fwd)
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if ((iphdr->ipv4.l2.vhl & IP_VERSION_MASK) == IPv4_VERSION)
if (fwd->f_domain == PF_INET)
#endif
{
FAR struct ipv4_hdr_s *ipv4 = &iphdr->ipv4.l2;
+4 -4
View File
@@ -49,7 +49,7 @@
#include <nuttx/net/ip.h>
#include <nuttx/net/netstats.h>
#include "devif/ip_forward.h"
#include "ipforward/ip_forward.h"
#include "devif/devif.h"
#include "netdev/netdev.h"
#include "arp/arp.h"
@@ -90,7 +90,7 @@ static inline void forward_ipselect(FAR struct forward_s *fwd)
/* Select IPv4 or IPv6 */
if ((iphdr->ipv4.l2.vhl & IP_VERSION_MASK) == IPv4_VERSION)
if (fwd->f_domain == PF_INET)
{
udp_ipv4_select(fwd->f_dev);
}
@@ -151,7 +151,7 @@ static inline bool udp_forward_addrchk(FAR struct forward_s *fwd)
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if ((iphdr->ipv4.l2.vhl & IP_VERSION_MASK) == IPv4_VERSION)
if (fwd->f_domain == PF_INET)
#endif
{
#if !defined(CONFIG_NET_ARP_IPIN) && !defined(CONFIG_NET_ARP_SEND)
@@ -209,7 +209,7 @@ static void udp_dropstats(FAR struct forward_s *fwd)
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if ((iphdr->ipv4.l2.vhl & IP_VERSION_MASK) == IPv4_VERSION)
if (fwd->f_domain == PF_INET)
#endif
{
g_netstats.ipv4.drop++;