pkarashchenko commented on code in PR #7616:
URL: https://github.com/apache/nuttx/pull/7616#discussion_r1037680443


##########
include/nuttx/net/ip.h:
##########
@@ -238,6 +238,51 @@ extern "C"
  * Public Function Prototypes
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: net_iphdrsize
+ *
+ * Description:
+ *   Return the size of the IP header
+ *
+ * Input Parameters:
+ *   domain  - IP domain: PF_INET or PF_INET6
+ *   l4size  - L4 additional header size
+ *
+ * Returned Value:
+ *   The size of the combined L3 + L4 headers is returned.
+ *
+ ****************************************************************************/
+
+static inline uint16_t net_iphdrsize(uint8_t domain, uint16_t l4size)

Review Comment:
   We are introducing inline to common code again :(



##########
net/can/can_recvmsg.c:
##########
@@ -122,6 +122,7 @@ static inline void can_add_recvlen(FAR struct 
can_recvfrom_s *pstate,
 static size_t can_recvfrom_newdata(FAR struct net_driver_s *dev,
                                  FAR struct can_recvfrom_s *pstate)

Review Comment:
   ```suggestion
   static size_t can_recvfrom_newdata(FAR struct net_driver_s *dev,
                                      FAR struct can_recvfrom_s *pstate)
   ```



##########
net/devif/devif_send.c:
##########
@@ -65,10 +65,23 @@
  *
  ****************************************************************************/
 
-void devif_send(struct net_driver_s *dev, const void *buf, int len)
+void devif_send(struct net_driver_s *dev, const void *buf,
+                int len, unsigned int offset)
 {
-  DEBUGASSERT(dev != NULL && len > 0 && len < NETDEV_PKTSIZE(dev));
+  unsigned int limit = NETDEV_PKTSIZE(dev) -
+                       CONFIG_NET_LL_GUARDSIZE - offset;
 
-  memcpy(dev->d_appdata, buf, len);
-  dev->d_sndlen = len;
+  if (dev == NULL || len == 0 || len > limit)
+    {
+      nerr("ERROR: devif_send fail: %p, sndlen: %u, pktlen: %u\n",
+            dev, len, limit);

Review Comment:
   ```suggestion
         nerr("ERROR: devif_send fail: %p, sndlen: %u, pktlen: %u\n",
              dev, len, limit);
   ```



##########
net/pkt/pkt_input.c:
##########
@@ -65,10 +67,10 @@
  *
  ****************************************************************************/
 
-int pkt_input(struct net_driver_s *dev)
+static int pkt_in(struct net_driver_s *dev)

Review Comment:
   ```suggestion
   static int pkt_in(FAR struct net_driver_s *dev)
   ```



##########
net/udp/udp_recvfrom.c:
##########
@@ -208,44 +181,34 @@ static inline void udp_readahead(struct udp_recvfrom_s 
*pstate)
 
   if ((iob = iob_peek_queue(&conn->readahead)) != NULL)
     {
-      FAR struct iob_s *tmp;
-#ifdef CONFIG_NET_IPv6
-      uint8_t srcaddr[sizeof(struct sockaddr_in6)];
-#else
-      uint8_t srcaddr[sizeof(struct sockaddr_in)];
-#endif
+      int recvlen = pstate->ir_msg->msg_iov->iov_len;
       uint8_t src_addr_size;
-      uint8_t offset  = 0;
-      uint8_t ifindex = 0;
+      uint8_t offset = 0;
+      FAR void *srcaddr;
+      uint8_t ifindex;
 
       DEBUGASSERT(iob->io_pktlen > 0);
 
-      /* Transfer that buffered data from the I/O buffer chain into
-       * the user buffer.
-       */
-
-      recvlen = iob_copyout(&src_addr_size, iob, sizeof(uint8_t), offset);
-      offset += sizeof(uint8_t);
-      if (recvlen != sizeof(uint8_t))
-        {
-          goto out;
-        }
-
-      recvlen = iob_copyout(srcaddr, iob, src_addr_size, offset);
-      offset += src_addr_size;
-      if (recvlen != src_addr_size)
-        {
-          goto out;
-        }
+      /* Unflatten saved connection information */
 
 #ifdef CONFIG_NETDEV_IFINDEX
-      recvlen = iob_copyout(&ifindex, iob, sizeof(uint8_t), offset);
-      offset += sizeof(uint8_t);
-      if (recvlen != sizeof(uint8_t))
-        {
-          goto out;
-        }
+      ifindex = iob->io_data[offset++];
+#else
+      ifindex = 0;
 #endif
+      src_addr_size = iob->io_data[offset++];
+      srcaddr = &iob->io_data[offset];
+
+      /* Copy to user */
+
+      recvlen = iob_copyout(pstate->ir_msg->msg_iov->iov_base,
+                           iob, recvlen, 0);

Review Comment:
   ```suggestion
         recvlen = iob_copyout(pstate->ir_msg->msg_iov->iov_base,
                               iob, recvlen, 0);
   ```



##########
net/can/can_callback.c:
##########
@@ -149,6 +133,34 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
 
       if ((flags & CAN_NEWDATA) != 0)
         {
+#ifdef CONFIG_NET_TIMESTAMP
+          /* TIMESTAMP sockopt is activated,
+           * create timestamp and copy to iob
+           */
+
+          if (conn->timestamp)
+            {
+              struct timespec ts;
+              FAR struct timeval *tv = (FAR struct timeval *)&ts;
+              uint16_t len = sizeof(struct timeval);
+
+              clock_systime_timespec(&ts);
+              tv->tv_usec = ts.tv_nsec / 1000;
+
+              len = iob_trycopyin(dev->d_iob,
+                                  (FAR uint8_t *)tv, len, 0, false);
+              if (len != sizeof(struct timeval))

Review Comment:
   ```suggestion
                 struct timeval tv;
                 FAR struct timespec *ts = (FAR struct timespec *)&tv;
                 int len;
   
                 clock_systime_timespec(ts);
                 tv.tv_usec = ts->tv_nsec / 1000;
   
                 len = iob_trycopyin(dev->d_iob, (FAR uint8_t *)&tv,
                                     sizeof(struct timeval), 0, false);
                 if (len != sizeof(struct timeval))
   ```



##########
mm/iob/Kconfig:
##########
@@ -41,7 +41,7 @@ config IOB_HEADSIZE
 
 config IOB_ALIGNMENT
        int "Alignment size of each I/O buffer"
-       default 1
+       default 4

Review Comment:
   why default alignment is changed?



##########
include/nuttx/net/netdev.h:
##########
@@ -802,4 +936,88 @@ void net_incr32(FAR uint8_t *op32, uint16_t op16);
 
 int netdev_lladdrsize(FAR struct net_driver_s *dev);
 
+/****************************************************************************
+ * Name: netdev_iob_prepare
+ *
+ * Description:
+ *   Prepare data buffer for a given NIC
+ *   The iob offset will be updated to l2 gruard size by default:
+ *  ----------------------------------------------------------------
+ *  |                     iob entry                                |
+ *  ---------------------------------------------------------------|
+ *  |<--- CONFIG_NET_LL_GUARDSIZE -->|<--- io_len/io_pktlen(0) --->|
+ *  ---------------------------------------------------------------|
+ *
+ * Assumptions:
+ *   The caller has locked the network.
+ *
+ * Returned Value:
+ *   A non-zero copy is returned on success.
+ *
+ ****************************************************************************/
+
+int netdev_iob_prepare(FAR struct net_driver_s *dev, bool throttled,
+                          unsigned int timeout);

Review Comment:
   ```suggestion
   int netdev_iob_prepare(FAR struct net_driver_s *dev, bool throttled,
                          unsigned int timeout);
   ```



##########
net/arp/arp.h:
##########
@@ -81,8 +81,11 @@
 
 /* This is a helper pointer for accessing the contents of the IP header */
 
-#define ARPBUF    ((FAR struct arp_hdr_s *)&dev->d_buf[ETH_HDRLEN])
-#define ARPIPBUF  ((FAR struct arp_iphdr_s *)&dev->d_buf[ETH_HDRLEN])
+#define ARPBUF    ((FAR void *)(dev->d_iob ? \

Review Comment:
   Why do we need `void *` cast?



##########
net/devif/devif_pktsend.c:
##########
@@ -83,16 +55,25 @@
 void devif_pkt_send(FAR struct net_driver_s *dev, FAR const void *buf,
                     unsigned int len)
 {
-  DEBUGASSERT(dev && len > 0 && len < NETDEV_PKTSIZE(dev));
+  unsigned int limit = NETDEV_PKTSIZE(dev) -
+                       CONFIG_NET_LL_GUARDSIZE;
 
-  /* Copy the data into the device packet buffer */
+  if (dev == NULL || len == 0 || len > limit)
+    {
+      nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
+            dev, len, limit);

Review Comment:
   ```suggestion
         nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
              dev, len, limit);
   ```



##########
net/devif/devif_cansend.c:
##########
@@ -83,16 +55,25 @@
 void devif_can_send(FAR struct net_driver_s *dev, FAR const void *buf,
                     unsigned int len)
 {
-  DEBUGASSERT(dev && len > 0 && len <= NETDEV_PKTSIZE(dev));
+  unsigned int limit = NETDEV_PKTSIZE(dev) -
+                       CONFIG_NET_LL_GUARDSIZE;
 
-  /* Copy the data into the device packet buffer */
+  if (dev == NULL || len == 0 || len > limit)
+    {
+      nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
+            dev, len, limit);
+      return;
+    }
 
-  memcpy(dev->d_buf, buf, len);
+  iob_update_pktlen(dev->d_iob, 0);
 
-  /* Set the number of bytes to send */
+  /* Copy the data into the device packet buffer and set the number of
+   * bytes to send
+   */
 
-  dev->d_len    = len;
-  dev->d_sndlen = len;
+  dev->d_sndlen = (iob_copyin(dev->d_iob, buf, len, 0, false) == len) ?

Review Comment:
   ```suggestion
     dev->d_sndlen = iob_copyin(dev->d_iob, buf, len, 0, false) == len ?
   ```



##########
net/devif/devif_cansend.c:
##########
@@ -83,16 +55,25 @@
 void devif_can_send(FAR struct net_driver_s *dev, FAR const void *buf,
                     unsigned int len)
 {
-  DEBUGASSERT(dev && len > 0 && len <= NETDEV_PKTSIZE(dev));
+  unsigned int limit = NETDEV_PKTSIZE(dev) -
+                       CONFIG_NET_LL_GUARDSIZE;
 
-  /* Copy the data into the device packet buffer */
+  if (dev == NULL || len == 0 || len > limit)
+    {
+      nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
+            dev, len, limit);

Review Comment:
   ```suggestion
         nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
              dev, len, limit);
   ```



##########
net/devif/devif_send.c:
##########
@@ -65,10 +65,23 @@
  *
  ****************************************************************************/
 
-void devif_send(struct net_driver_s *dev, const void *buf, int len)
+void devif_send(struct net_driver_s *dev, const void *buf,

Review Comment:
   ```suggestion
   void devif_send(FAR struct net_driver_s *dev, FAR const void *buf,
   ```



##########
net/devif/devif_pktsend.c:
##########
@@ -83,16 +55,25 @@
 void devif_pkt_send(FAR struct net_driver_s *dev, FAR const void *buf,
                     unsigned int len)
 {
-  DEBUGASSERT(dev && len > 0 && len < NETDEV_PKTSIZE(dev));
+  unsigned int limit = NETDEV_PKTSIZE(dev) -
+                       CONFIG_NET_LL_GUARDSIZE;
 
-  /* Copy the data into the device packet buffer */
+  if (dev == NULL || len == 0 || len > limit)
+    {
+      nerr("ERROR: devif_pkt_send fail: %p, sndlen: %u, pktlen: %u\n",
+            dev, len, limit);
+      return;
+    }
 
-  memcpy(dev->d_buf, buf, len);
+  iob_update_pktlen(dev->d_iob, 0);
 
-  /* Set the number of bytes to send */
+  /* Copy the data into the device packet buffer and set the number of
+   * bytes to send
+   */
 
-  dev->d_len    = len;
-  dev->d_sndlen = len;
+  dev->d_sndlen = (iob_copyin(dev->d_iob, buf, len, 0, false) == len) ?

Review Comment:
   ```suggestion
     dev->d_sndlen = iob_copyin(dev->d_iob, buf, len, 0, false) == len ?
   ```



##########
net/devif/devif_iobsend.c:
##########
@@ -53,19 +53,77 @@
  ****************************************************************************/
 
 void devif_iob_send(FAR struct net_driver_s *dev, FAR struct iob_s *iob,
-                    unsigned int len, unsigned int offset)
+                    unsigned int len, unsigned int offset,
+                    unsigned int target_offset)
 {
-  if (dev == NULL || len == 0 || len >= NETDEV_PKTSIZE(dev))
+  unsigned int limit = NETDEV_PKTSIZE(dev) -
+                       NET_LL_HDRLEN(dev) - target_offset;
+  unsigned int copyin;
+  int ret;
+
+  if (dev == NULL || len == 0 || len > limit)
     {
-      nerr("devif_iob_send error, %p, send len: %u, pkt len: %u\n",
-                                          dev, len, NETDEV_PKTSIZE(dev));
+      if (dev->d_iob == NULL)
+        {
+          iob_free_chain(iob);
+        }
+
+      nerr("devif_iob_send error, %p, send len: %u, limit len: %u\n",
+            dev, len, limit);

Review Comment:
   ```suggestion
         nerr("devif_iob_send error, %p, send len: %u, limit len: %u\n",
              dev, len, limit);
   ```



##########
net/icmp/icmp_reply.c:
##########
@@ -119,20 +119,75 @@ void icmp_reply(FAR struct net_driver_s *dev, int type, 
int code)
   if (datalen > ICMP_MAXMSGLEN - ipicmplen)
     {
       datalen = ICMP_MAXMSGLEN - ipicmplen;
+      iob_trimtail(dev->d_iob, dev->d_iob->io_pktlen - datalen);
     }
 
-  dev->d_len = ipicmplen + datalen;
+  /* Save the original datagram */
+
+  if (CONFIG_IOB_BUFSIZE >= datalen + ipicmplen +
+                           CONFIG_NET_LL_GUARDSIZE)
+    {
+      /* Reuse current iob */
+
+      memmove((FAR char *)ipv4 + ipicmplen, ipv4, datalen);
+
+      /* Skip icmp header from iob */
+
+      iob_update_pktlen(dev->d_iob, datalen + ipicmplen);
+    }
+  else
+    {
+      FAR struct iob_s *iob;
+
+      /* Save the original datagram to iob chain */
+
+      iob = dev->d_iob;
+      dev->d_iob = NULL;
+
+      /* Re-prepare device buffer */
 
-  /* Copy fields from original packet */
+      if (netdev_iob_prepare(dev, false, 0) != OK)
+        {
+          dev->d_len = 0;
+          dev->d_iob = iob;
+          netdev_iob_release(dev);
+          return;
+        }
 
-  memmove(icmp + 1, ipv4, datalen);
+      /* Copy ipv4 header to device buffer */
+
+      if (iob_trycopyin(dev->d_iob, (FAR void *)ipv4,

Review Comment:
   ```suggestion
         if (iob_trycopyin(dev->d_iob, ipv4,
   ```



##########
net/devif/devif_send.c:
##########
@@ -65,10 +65,23 @@
  *
  ****************************************************************************/
 
-void devif_send(struct net_driver_s *dev, const void *buf, int len)
+void devif_send(struct net_driver_s *dev, const void *buf,
+                int len, unsigned int offset)
 {
-  DEBUGASSERT(dev != NULL && len > 0 && len < NETDEV_PKTSIZE(dev));
+  unsigned int limit = NETDEV_PKTSIZE(dev) -
+                       CONFIG_NET_LL_GUARDSIZE - offset;
 
-  memcpy(dev->d_appdata, buf, len);
-  dev->d_sndlen = len;
+  if (dev == NULL || len == 0 || len > limit)
+    {
+      nerr("ERROR: devif_send fail: %p, sndlen: %u, pktlen: %u\n",
+            dev, len, limit);
+      return;
+    }
+
+  iob_update_pktlen(dev->d_iob, offset);
+
+  /* Copy in iob to target device buffer */
+
+  dev->d_sndlen = (iob_copyin(dev->d_iob, buf, len, offset, false) == len) ?

Review Comment:
   ```suggestion
     dev->d_sndlen = iob_copyin(dev->d_iob, buf, len, offset, false) == len ?
   ```



##########
net/icmp/icmp_reply.c:
##########
@@ -119,20 +119,75 @@ void icmp_reply(FAR struct net_driver_s *dev, int type, 
int code)
   if (datalen > ICMP_MAXMSGLEN - ipicmplen)
     {
       datalen = ICMP_MAXMSGLEN - ipicmplen;
+      iob_trimtail(dev->d_iob, dev->d_iob->io_pktlen - datalen);
     }
 
-  dev->d_len = ipicmplen + datalen;
+  /* Save the original datagram */
+
+  if (CONFIG_IOB_BUFSIZE >= datalen + ipicmplen +
+                           CONFIG_NET_LL_GUARDSIZE)
+    {
+      /* Reuse current iob */
+
+      memmove((FAR char *)ipv4 + ipicmplen, ipv4, datalen);
+
+      /* Skip icmp header from iob */
+
+      iob_update_pktlen(dev->d_iob, datalen + ipicmplen);
+    }
+  else
+    {
+      FAR struct iob_s *iob;
+
+      /* Save the original datagram to iob chain */
+
+      iob = dev->d_iob;
+      dev->d_iob = NULL;
+
+      /* Re-prepare device buffer */
 
-  /* Copy fields from original packet */
+      if (netdev_iob_prepare(dev, false, 0) != OK)
+        {
+          dev->d_len = 0;
+          dev->d_iob = iob;
+          netdev_iob_release(dev);
+          return;
+        }
 
-  memmove(icmp + 1, ipv4, datalen);
+      /* Copy ipv4 header to device buffer */
+
+      if (iob_trycopyin(dev->d_iob, (FAR void *)ipv4,
+                        IPv4_HDRLEN, 0, false) != IPv4_HDRLEN)
+        {
+          dev->d_len = 0;
+          netdev_iob_release(dev);
+          iob_free_chain(iob);
+          return;
+        }
+
+      /* Skip icmp header from iob */
+
+      iob_update_pktlen(dev->d_iob, dev->d_iob->io_pktlen +
+                                    sizeof(struct icmp_hdr_s));
+
+      /* Concat new icmp packet before original datagram */
+
+      iob_concat(dev->d_iob, iob);
+
+      /* IPv4 header to new iob */
+
+      ipv4 = IPBUF(0);
+    }
+
+  dev->d_len = ipicmplen + datalen;
 
   ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_ICMP,
                     &dev->d_ipaddr, (FAR in_addr_t *)ipv4->srcipaddr,
                     IP_TTL_DEFAULT, NULL);
 
   /* Initialize the ICMP header */
 
+  icmp = (FAR struct icmp_hdr_s *)(ipv4 + 1);
   icmp->type        = type;

Review Comment:
   ```suggestion
     icmp              = (FAR struct icmp_hdr_s *)(ipv4 + 1);
     icmp->type        = type;
   ```



##########
net/icmpv6/icmpv6_reply.c:
##########
@@ -108,6 +108,64 @@ void icmpv6_reply(FAR struct net_driver_s *dev, int type, 
int code, int data)
   if (datalen > ICMPv6_MINMTULEN - ipicmplen)
     {
       datalen = ICMPv6_MINMTULEN - ipicmplen;
+      iob_trimtail(dev->d_iob, dev->d_iob->io_pktlen - datalen);
+    }
+
+  /* Save the original datagram */
+
+  if (CONFIG_IOB_BUFSIZE >= datalen + ipicmplen +
+                            CONFIG_NET_LL_GUARDSIZE)
+    {
+      /* Reuse current iob */
+
+      memmove((FAR char *)ipv6 + ipicmplen, ipv6, datalen);
+
+      /* Skip icmp header from iob */
+
+      iob_update_pktlen(dev->d_iob, datalen + ipicmplen);
+    }
+  else
+    {
+      FAR struct iob_s *iob;
+
+      /* Save the original datagram to iob chain */
+
+      iob = dev->d_iob;
+      dev->d_iob = NULL;
+
+      /* Re-prepare device buffer */
+
+      if (netdev_iob_prepare(dev, false, 0) != OK)
+        {
+          dev->d_len = 0;
+          dev->d_iob = iob;
+          netdev_iob_release(dev);
+          return;
+        }
+
+      /* Copy ipv4 header to device buffer */
+
+      if (iob_trycopyin(dev->d_iob, (FAR void *)ipv6,

Review Comment:
   ```suggestion
         if (iob_trycopyin(dev->d_iob, ipv6,
   ```



##########
net/icmpv6/icmpv6_reply.c:
##########
@@ -117,6 +175,7 @@ void icmpv6_reply(FAR struct net_driver_s *dev, int type, 
int code, int data)
 
   /* Initialize the ICMPv6 header */
 
+  icmpv6 = (FAR struct icmpv6_hdr_s *)(ipv6 + 1);
   icmpv6->type    = type;

Review Comment:
   ```suggestion
     icmpv6          = (FAR struct icmpv6_hdr_s *)(ipv6 + 1);
     icmpv6->type    = type;
   ```



##########
net/icmp/icmp_sendmsg.c:
##########
@@ -125,7 +129,7 @@ static void sendto_request(FAR struct net_driver_s *dev,
   /* Calculate the ICMP checksum. */
 
   icmp->icmpchksum  = 0;
-  icmp->icmpchksum  = ~(icmp_chksum(dev, pstate->snd_buflen));
+  icmp->icmpchksum  = ~(icmp_chksum_iob(dev->d_iob));

Review Comment:
   ```suggestion
     icmp->icmpchksum  = ~icmp_chksum_iob(dev->d_iob);
   ```



##########
net/icmpv6/icmpv6_input.c:
##########
@@ -87,82 +87,32 @@ static uint16_t icmpv6_datahandler(FAR struct net_driver_s 
*dev,
                                    unsigned int iplen)
 {
   FAR struct ipv6_hdr_s *ipv6;
-  FAR struct icmpv6_hdr_s *icmpv6;
-  FAR struct iob_s *iob;
   struct sockaddr_in6 inaddr;
-  uint16_t offset;
+  FAR struct iob_s *iob;
   uint16_t buflen;
-  uint8_t addrsize;
   int ret;
 
-  /* Try to allocate on I/O buffer to start the chain without waiting (and
-   * throttling as necessary).  If we would have to wait, then drop the
-   * packet.
-   */
-
-  iob = iob_tryalloc(true);
-  if (iob == NULL)
-    {
-      nerr("ERROR: Failed to create new I/O buffer chain\n");
-      goto drop;
-    }
-
   /* Put the IPv6 address at the beginning of the read-ahead buffer */
 
+  iob               = dev->d_iob;

Review Comment:
   ```suggestion
     iob                = dev->d_iob;
   ```



##########
net/pkt/pkt_input.c:
##########
@@ -109,4 +111,38 @@ int pkt_input(struct net_driver_s *dev)
   return ret;
 }
 
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pkt_input
+ *
+ * Description:
+ *   Handle incoming packet input
+ *
+ * Input Parameters:
+ *   dev - The device driver structure containing the received packet
+ *
+ * Returned Value:
+ *   OK     The packet has been processed  and can be deleted
+ *  -EAGAIN There is a matching connection, but could not dispatch the packet
+ *          yet.  Useful when a packet arrives before a recv call is in
+ *          place.
+ *
+ * Assumptions:
+ *   The network is locked.
+ *
+ ****************************************************************************/
+
+int pkt_input(struct net_driver_s *dev)

Review Comment:
   ```suggestion
   int pkt_input(FAR struct net_driver_s *dev)
   ```



##########
net/udp/udp_recvfrom.c:
##########
@@ -126,19 +126,19 @@ static void udp_recvpktinfo(FAR struct udp_recvfrom_s 
*pstate,
  *   Copy the read data from the packet
  *
  * Input Parameters:
- *   dev      The structure of the network driver that generated the event.
+ *   dev      The structure of the network driver that generated the event
  *   pstate   recvfrom state structure
  *
  * Returned Value:
- *   The number of bytes taken from the packet.
+ *   None.
  *
  * Assumptions:
  *   The network is locked.
  *
  ****************************************************************************/
 
-static size_t udp_recvfrom_newdata(FAR struct net_driver_s *dev,
-                                   FAR struct udp_recvfrom_s *pstate)
+static inline size_t udp_recvfrom_newdata(FAR struct net_driver_s *dev,

Review Comment:
   maybe we can omit `inline`



##########
net/udp/udp.h:
##########
@@ -185,6 +186,39 @@ extern "C"
  * Public Function Prototypes
  ****************************************************************************/
 
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: udpip_hdrsize
+ *
+ * Description:
+ *   Get the total size of L3 and L4 UDP header
+ *
+ * Input Parameters:
+ *   conn     The connection structure associated with the socket
+ *
+ * Returned Value:
+ *   the total size of L3 and L4 TCP header
+ *
+ ****************************************************************************/
+
+static inline uint16_t udpip_hdrsize(FAR struct udp_conn_s *conn)
+{
+  uint16_t hdrsize = sizeof(struct udp_hdr_s);
+
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+  return net_iphdrsize(conn->domain, hdrsize);
+#elif defined(CONFIG_NET_IPv6)
+  UNUSED(conn);
+  return net_iphdrsize(PF_INET6, hdrsize);
+#else
+  UNUSED(conn);
+  return net_iphdrsize(PF_INET, hdrsize);
+#endif
+}

Review Comment:
   Maybe can be changed to `define`?



##########
net/tcp/tcp.h:
##########
@@ -385,6 +386,39 @@ extern "C"
 {
 #endif
 
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: tcpip_hdrsize
+ *
+ * Description:
+ *   Get the total size of L3 and L4 TCP header
+ *
+ * Input Parameters:
+ *   conn     The connection structure associated with the socket
+ *
+ * Returned Value:
+ *   the total size of L3 and L4 TCP header
+ *
+ ****************************************************************************/
+
+static inline uint16_t tcpip_hdrsize(FAR struct tcp_conn_s *conn)
+{
+  uint16_t hdrsize = sizeof(struct tcp_hdr_s);
+
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+  return net_iphdrsize(conn->domain, hdrsize);
+#elif defined(CONFIG_NET_IPv6)
+  UNUSED(conn);
+  return net_iphdrsize(PF_INET6, hdrsize);
+#else
+  UNUSED(conn);
+  return net_iphdrsize(PF_INET, hdrsize);
+#endif
+}

Review Comment:
   Maybe can be changed to `define`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to