This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e3a6c16944ef1b1ea92c9c727efd987a8ee410b6
Author: chao an <[email protected]>
AuthorDate: Tue Feb 7 16:15:57 2023 +0800

    net/ip: fix compile break if disable NET_TCP
    
    1.
    ipfrag/ipv4_frag.c: In function ‘ipv4_fragin’:
    ipfrag/ipv4_frag.c:184:22: warning: ‘head’ may be used uninitialized in 
this function [-Wmaybe-uninitialized]
      184 |   ipv4->len[1] = head->io_pktlen & 0xff;
          |                  ~~~~^~~~~~~~~~~
    ipfrag/ipv4_frag.c:123:21: note: ‘head’ was declared here
      123 |   FAR struct iob_s *head;
          |                     ^~~~
    
    2.
    devif/ipv6_input.c: In function ‘ipv6_in’:
    devif/ipv6_input.c:60:33: error: ‘TCPIPv6BUF’ undeclared (first use in this 
function); did you mean ‘UDPIPv6BUF’?
       60 | #define PAYLOAD ((FAR uint8_t *)TCPIPv6BUF)
          |                                 ^~~~~~~~~~
    
    3.
    nat/ipv4_nat.c: In function ‘ipv4_nat_inbound_icmp’:
    nat/ipv4_nat.c:67:30: error: ‘TCP_HDRLEN’ undeclared (first use in this 
function); did you mean ‘UDP_HDRLEN’?
       67 |   ((proto) == IP_PROTO_TCP ? TCP_HDRLEN : \
          |                              ^~~~~~~~~~
    nat/ipv4_nat.c:323:47: note: in expansion of macro ‘L4_HDRLEN’
      323 |             inner_l4hdrlen = MIN(inner_l4len, 
L4_HDRLEN(inner->proto));
          |                                               ^~~~~~~~~
    
    Signed-off-by: chao an <[email protected]>
---
 net/devif/ipv6_input.c | 12 +++---------
 net/ipfrag/ipv4_frag.c |  2 +-
 net/ipfrag/ipv6_frag.c |  2 +-
 net/nat/ipv4_nat.c     | 45 +++++++++++++++++++++++++++++++++++++++------
 4 files changed, 44 insertions(+), 17 deletions(-)

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);

Reply via email to