Skip to content

Commit

Permalink
IP forwarding: Move to separate directory. A few fixes from early tes…
Browse files Browse the repository at this point in the history
…ting; In TUN driver, do all polling on worker thread. Otherwise, the stack gets very deep.
  • Loading branch information
gregory-nutt committed Jul 8, 2017
1 parent 99ef7c6 commit 7258f1c
Show file tree
Hide file tree
Showing 20 changed files with 164 additions and 92 deletions.
35 changes: 1 addition & 34 deletions net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion net/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions net/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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


+-------------------------------------------------------------------++------------------------+
Expand Down
10 changes: 3 additions & 7 deletions net/devif/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion net/devif/devif_forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions net/devif/devif_initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#include <nuttx/net/netstats.h>
#include <nuttx/net/ip.h>

#include "devif/ip_forward.h"
#include "devif/devif.h"

/****************************************************************************
Expand Down Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion net/devif/ipv4_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion net/devif/ipv6_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion net/icmp/icmp_foward.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion net/icmpv6/icmpv6_forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 39 additions & 0 deletions net/ipforward/Kconfig
Original file line number Diff line number Diff line change
@@ -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 changes: 57 additions & 0 deletions net/ipforward/Make.defs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions net/devif/ip_forward.c → net/ipforward/ip_forward.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions net/devif/ip_forward.h → net/ipforward/ip_forward.h
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
};

/****************************************************************************
Expand Down Expand Up @@ -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 */
9 changes: 6 additions & 3 deletions net/devif/ipv4_forward.c → net/ipforward/ipv4_forward.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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. */
Expand Down
9 changes: 6 additions & 3 deletions net/devif/ipv6_forward.c → net/ipforward/ipv6_forward.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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. */
Expand Down
Loading

0 comments on commit 7258f1c

Please sign in to comment.