mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
IP forwarding: Remove some unnecessary data structure definitions.
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/mm/iob.h>
|
||||||
#include <nuttx/net/netdev.h>
|
#include <nuttx/net/netdev.h>
|
||||||
|
|
||||||
#include "ipforward/ipforward.h"
|
#include "ipforward/ipforward.h"
|
||||||
|
|||||||
@@ -44,16 +44,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <nuttx/net/ip.h>
|
|
||||||
#include <nuttx/net/udp.h>
|
|
||||||
#include <nuttx/net/tcp.h>
|
|
||||||
#include <nuttx/net/icmp.h>
|
|
||||||
#include <nuttx/net/icmpv6.h>
|
|
||||||
|
|
||||||
#include "udp/udp.h"
|
|
||||||
#include "tcp/tcp.h"
|
|
||||||
#include "icmpv6/icmpv6.h"
|
|
||||||
|
|
||||||
#undef HAVE_FWDALLOC
|
#undef HAVE_FWDALLOC
|
||||||
#ifdef CONFIG_NET_IPFORWARD
|
#ifdef CONFIG_NET_IPFORWARD
|
||||||
|
|
||||||
@@ -73,68 +63,10 @@
|
|||||||
# define CONFIG_NET_IPFORWARD_NSTRUCT 4
|
# define CONFIG_NET_IPFORWARD_NSTRUCT 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FWD_HEADER(fwd) (FAR union fwd_iphdr_u *)((fwd)->f_iob->io_data)
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* IPv4 + L2 header */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
struct fwd_ipv4hdr_u
|
|
||||||
{
|
|
||||||
struct ipv4_hdr_s l2;
|
|
||||||
union
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_NET_TCP
|
|
||||||
uint8_t pad[TCP_MAX_HDRLEN];
|
|
||||||
struct tcp_hdr_s tcp;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_UDP
|
|
||||||
struct udp_hdr_s udp;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_ICMPv6
|
|
||||||
struct icmp_hdr_s icmp;
|
|
||||||
#endif
|
|
||||||
} l3;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* IPv6 + L2 header */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
struct fwd_ipv6hdr_u
|
|
||||||
{
|
|
||||||
struct ipv6_hdr_s l2;
|
|
||||||
union
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_NET_TCP
|
|
||||||
uint8_t pad[TCP_MAX_HDRLEN];
|
|
||||||
struct tcp_hdr_s tcp;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_UDP
|
|
||||||
struct udp_hdr_s udp;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_ICMPv6
|
|
||||||
struct icmpv6_hdr_s icmpv6;
|
|
||||||
#endif
|
|
||||||
} l3;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* IPv4 or IPv6 + L2 header */
|
|
||||||
|
|
||||||
union fwd_iphdr_u
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
|
||||||
struct fwd_ipv4hdr_u ipv4;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
|
||||||
struct fwd_ipv6hdr_u ipv6;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
/* This is the send state structure */
|
/* This is the send state structure */
|
||||||
|
|
||||||
struct devif_callback_s; /* Forward refernce */
|
struct devif_callback_s; /* Forward refernce */
|
||||||
@@ -156,6 +88,9 @@ struct forward_s
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct ipv4_hdr_s; /* Forward reference */
|
||||||
|
struct ipv6_hdr_s; /* Forward reference */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ipfwd_initialize
|
* Name: ipfwd_initialize
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -44,10 +44,37 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/net/tcp.h>
|
||||||
|
#include <nuttx/net/udp.h>
|
||||||
|
#include <nuttx/net/icmp.h>
|
||||||
|
#include <nuttx/net/icmpv6.h>
|
||||||
|
|
||||||
#include "ipforward/ipforward.h"
|
#include "ipforward/ipforward.h"
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NETDEV_MULTINIC)
|
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NETDEV_MULTINIC)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
# define L2_MAXHDRLEN IPv6_HDRLEN
|
||||||
|
#else
|
||||||
|
# define L2_MAXHDRLEN IPv4_HDRLEN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_TCP)
|
||||||
|
# define L3_MAXHDRLEN TCP_MAX_HDRLEN
|
||||||
|
#elif defined(CONFIG_NET_UDP)
|
||||||
|
# define L3_MAXHDRLEN UDP_HDRLEN
|
||||||
|
#elif defined(CONFIG_NET_ICMPv6)
|
||||||
|
# define L3_MAXHDRLEN ICMPv6_HDRLEN
|
||||||
|
#elif defined(CONFIG_NET_ICMP)
|
||||||
|
# define L3_MAXHDRLEN ICMP_HDRLEN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAX_HDRLEN (L2_MAXHDRLEN + L3_MAXHDRLEN)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -84,7 +111,7 @@ void ipfwd_initialize(void)
|
|||||||
* the contiguous memory of the first IOB in the IOB chain.
|
* the contiguous memory of the first IOB in the IOB chain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(sizeof(union fwd_iphdr_u) <= CONFIG_IOB_BUFSIZE);
|
DEBUGASSERT(MAX_HDRLEN <= CONFIG_IOB_BUFSIZE);
|
||||||
|
|
||||||
/* Add all pre-allocated forwarding structures to the free list */
|
/* Add all pre-allocated forwarding structures to the free list */
|
||||||
|
|
||||||
|
|||||||
@@ -144,8 +144,6 @@ static inline void forward_ipselect(FAR struct forward_s *fwd)
|
|||||||
#ifdef CONFIG_NET_ETHERNET
|
#ifdef CONFIG_NET_ETHERNET
|
||||||
static inline bool ipfwd_addrchk(FAR struct forward_s *fwd)
|
static inline bool ipfwd_addrchk(FAR struct forward_s *fwd)
|
||||||
{
|
{
|
||||||
FAR union fwd_iphdr_u *iphdr;
|
|
||||||
|
|
||||||
DEBUGASSERT(fwd != NULL && fwd->f_iob != NULL && fwd->f_dev != NULL);
|
DEBUGASSERT(fwd != NULL && fwd->f_iob != NULL && fwd->f_dev != NULL);
|
||||||
|
|
||||||
/* REVISIT: Could the MAC address not also be in a routing table? */
|
/* REVISIT: Could the MAC address not also be in a routing table? */
|
||||||
@@ -157,15 +155,14 @@ static inline bool ipfwd_addrchk(FAR struct forward_s *fwd)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
iphdr = FWD_HEADER(fwd);
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
if (fwd->f_domain == PF_INET)
|
if (fwd->f_domain == PF_INET)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if !defined(CONFIG_NET_ARP_IPIN) && !defined(CONFIG_NET_ARP_SEND)
|
#if !defined(CONFIG_NET_ARP_IPIN) && !defined(CONFIG_NET_ARP_SEND)
|
||||||
return (arp_find(iphdr->ipv4.l2.destipaddr) != NULL);
|
FAR stuct ipv4_hdr_s *ipv4 = (FAR stuct ipv4_hdr_s *)fwd->f_iob->io_data;
|
||||||
|
return (arp_find(ipv4->destipaddr) != NULL);
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
@@ -178,7 +175,8 @@ static inline bool ipfwd_addrchk(FAR struct forward_s *fwd)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if !defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
#if !defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||||
return (neighbor_findentry(iphdr->ipv6.l2.destipaddr) != NULL);
|
FAR stuct ipv6_hdr_s *ipv4 = (FAR stuct ipv6_hdr_s *)fwd->f_iob->io_data;
|
||||||
|
return (neighbor_findentry(ipv6->destipaddr) != NULL);
|
||||||
#else
|
#else
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user