diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c index 84d56061fe..943bbc5cb4 100644 --- a/net/devif/ipv6_input.c +++ b/net/devif/ipv6_input.c @@ -53,12 +53,6 @@ #include "devif/devif.h" #include "ipfrag/ipfrag.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define PAYLOAD ((FAR uint8_t *)TCPIPv6BUF) - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -273,9 +267,9 @@ static int ipv6_in(FAR struct net_driver_s *dev) /* Parse IPv6 extension headers (parsed but ignored) */ - payload = PAYLOAD; /* Assume payload starts right after IPv6 header */ - iphdrlen = IPv6_HDRLEN; /* Total length of the IPv6 header */ - nxthdr = ipv6->proto; /* Next header determined by IPv6 header prototype */ + payload = IPBUF(IPv6_HDRLEN); /* Assume payload starts right after IPv6 header */ + iphdrlen = IPv6_HDRLEN; /* Total length of the IPv6 header */ + nxthdr = ipv6->proto; /* Next header determined by IPv6 header prototype */ while (ipv6_exthdr(nxthdr)) { diff --git a/net/ipfrag/ipv4_frag.c b/net/ipfrag/ipv4_frag.c index 156493bcd3..acec0029a8 100644 --- a/net/ipfrag/ipv4_frag.c +++ b/net/ipfrag/ipv4_frag.c @@ -120,7 +120,7 @@ ipv4_fragin_getinfo(FAR struct iob_s *iob, static uint32_t ipv4_fragin_reassemble(FAR struct ip_fragsnode_s *node) { - FAR struct iob_s *head; + FAR struct iob_s *head = NULL; FAR struct ipv4_hdr_s *ipv4; FAR struct ip_fraglink_s *fraglink; diff --git a/net/ipfrag/ipv6_frag.c b/net/ipfrag/ipv6_frag.c index b39ae81687..c49cc2f0b5 100644 --- a/net/ipfrag/ipv6_frag.c +++ b/net/ipfrag/ipv6_frag.c @@ -171,7 +171,7 @@ static int32_t ipv6_fragin_getinfo(FAR struct iob_s *iob, static uint32_t ipv6_fragin_reassemble(FAR struct ip_fragsnode_s *node) { - FAR struct iob_s *head; + FAR struct iob_s *head = NULL; FAR struct ipv6_hdr_s *ipv6; FAR struct ip_fraglink_s *fraglink; diff --git a/net/nat/ipv4_nat.c b/net/nat/ipv4_nat.c index 8f615f9f8c..e38b0cd108 100644 --- a/net/nat/ipv4_nat.c +++ b/net/nat/ipv4_nat.c @@ -63,10 +63,6 @@ #define L4_HDR(ipv4) \ (FAR void *)((FAR uint8_t *)(ipv4) + (((ipv4)->vhl & IPv4_HLMASK) << 2)) -#define L4_HDRLEN(proto) \ - ((proto) == IP_PROTO_TCP ? TCP_HDRLEN : \ - (proto) == IP_PROTO_UDP ? UDP_HDRLEN : ICMP_HDRLEN) - #if defined(CONFIG_NET_TCP) # define L4_MAXHDRLEN TCP_HDRLEN #elif defined(CONFIG_NET_UDP) @@ -88,6 +84,41 @@ ipv4_nat_outbound_internal(FAR struct net_driver_s *dev, FAR struct ipv4_hdr_s *ipv4, enum nat_manip_type_e manip_type); +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ipv4_nat_l4_hdrlen + * + * Description: + * Get L4 header length + * + ****************************************************************************/ + +static inline uint16_t ipv4_nat_l4_hdrlen(uint8_t proto) +{ + switch (proto) + { +#ifdef CONFIG_NET_TCP + case IP_PROTO_TCP: + return TCP_HDRLEN; +#endif +#ifdef CONFIG_NET_UDP + case IP_PROTO_UDP: + return UDP_HDRLEN; +#endif +#ifdef CONFIG_NET_ICMP + case IP_PROTO_ICMP: + return ICMP_HDRLEN; +#endif + default: + DEBUGASSERT(false); + } + + return 0; +} + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -320,7 +351,8 @@ ipv4_nat_inbound_icmp(FAR struct ipv4_hdr_s *ipv4, /* Try backup origin L4 header for later checksum update. */ - inner_l4hdrlen = MIN(inner_l4len, L4_HDRLEN(inner->proto)); + inner_l4hdrlen = MIN(inner_l4len, + ipv4_nat_l4_hdrlen(inner->proto)); DEBUGASSERT((intptr_t)inner_l4 - (intptr_t)ipv4 + inner_l4hdrlen <= CONFIG_IOB_BUFSIZE); memcpy(inner_l4hdrbak, inner_l4, inner_l4hdrlen); @@ -541,7 +573,8 @@ ipv4_nat_outbound_icmp(FAR struct net_driver_s *dev, /* Try backup origin L4 header for later checksum update. */ - inner_l4hdrlen = MIN(inner_l4len, L4_HDRLEN(inner->proto)); + inner_l4hdrlen = MIN(inner_l4len, + ipv4_nat_l4_hdrlen(inner->proto)); DEBUGASSERT((intptr_t)inner_l4 - (intptr_t)ipv4 + inner_l4hdrlen <= CONFIG_IOB_BUFSIZE); memcpy(inner_l4hdrbak, inner_l4, inner_l4hdrlen);