mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
IP forwarding: Remove some unnecessary data structure definitions.
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/mm/iob.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
|
||||
#include "ipforward/ipforward.h"
|
||||
|
||||
@@ -44,16 +44,6 @@
|
||||
|
||||
#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
|
||||
#ifdef CONFIG_NET_IPFORWARD
|
||||
|
||||
@@ -73,68 +63,10 @@
|
||||
# define CONFIG_NET_IPFORWARD_NSTRUCT 4
|
||||
#endif
|
||||
|
||||
#define FWD_HEADER(fwd) (FAR union fwd_iphdr_u *)((fwd)->f_iob->io_data)
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
|
||||
struct devif_callback_s; /* Forward refernce */
|
||||
@@ -156,6 +88,9 @@ struct forward_s
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
struct ipv4_hdr_s; /* Forward reference */
|
||||
struct ipv6_hdr_s; /* Forward reference */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ipfwd_initialize
|
||||
*
|
||||
|
||||
@@ -44,10 +44,37 @@
|
||||
#include <errno.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"
|
||||
|
||||
#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
|
||||
****************************************************************************/
|
||||
@@ -84,7 +111,7 @@ void ipfwd_initialize(void)
|
||||
* 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 */
|
||||
|
||||
|
||||
@@ -144,8 +144,6 @@ static inline void forward_ipselect(FAR struct forward_s *fwd)
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
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);
|
||||
|
||||
/* 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
|
||||
|
||||
iphdr = FWD_HEADER(fwd);
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
if (fwd->f_domain == PF_INET)
|
||||
#endif
|
||||
{
|
||||
#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
|
||||
return true;
|
||||
#endif
|
||||
@@ -178,7 +175,8 @@ static inline bool ipfwd_addrchk(FAR struct forward_s *fwd)
|
||||
#endif
|
||||
{
|
||||
#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
|
||||
return true;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user