diff --git a/net/devif/devif_forward.c b/net/devif/devif_forward.c index 4f93ee3cbbb..8a1a1bd855c 100644 --- a/net/devif/devif_forward.c +++ b/net/devif/devif_forward.c @@ -41,6 +41,7 @@ #include #include +#include #include #include "ipforward/ipforward.h" diff --git a/net/ipforward/ipforward.h b/net/ipforward/ipforward.h index 52069b80abe..a267c1f9016 100644 --- a/net/ipforward/ipforward.h +++ b/net/ipforward/ipforward.h @@ -44,16 +44,6 @@ #include -#include -#include -#include -#include -#include - -#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 * diff --git a/net/ipforward/ipfwd_alloc.c b/net/ipforward/ipfwd_alloc.c index 01e34099e47..e2265db19ff 100644 --- a/net/ipforward/ipfwd_alloc.c +++ b/net/ipforward/ipfwd_alloc.c @@ -44,10 +44,37 @@ #include #include +#include +#include +#include +#include + #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 */ diff --git a/net/ipforward/ipfwd_forward.c b/net/ipforward/ipfwd_forward.c index c7e1156b105..962713425e4 100644 --- a/net/ipforward/ipfwd_forward.c +++ b/net/ipforward/ipfwd_forward.c @@ -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