luojun1234 commented on code in PR #8059:
URL: https://github.com/apache/nuttx/pull/8059#discussion_r1070184308


##########
net/ipfrag/ipfrag.c:
##########
@@ -0,0 +1,1284 @@
+/****************************************************************************
+ * net/ipfrag/ipfrag.c
+ * Handling incoming IPv4 and IPv6 fragment input
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#if (defined(CONFIG_NET_IPv4) || defined(CONFIG_NET_IPv6)) &&   \
+    defined(CONFIG_NET_IPFRAG)
+
+#include <sys/ioctl.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <debug.h>
+#include <string.h>
+#include <errno.h>
+#include <netinet/in.h>
+#include <net/if.h>
+
+#include <nuttx/nuttx.h>
+#include <nuttx/wqueue.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/net/netconfig.h>
+#include <nuttx/net/netdev.h>
+#include <nuttx/net/netstats.h>
+#include <nuttx/net/ip.h>
+#include <nuttx/net/ipv6ext.h>
+
+#include "netdev/netdev.h"
+#include "inet/inet.h"
+#include "icmp/icmp.h"
+#include "icmpv6/icmpv6.h"
+#include "ipfrag.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define GOTO_IF(expression, to) \
+if (expression) \
+  { \
+    goto to;  \
+  } \
+
+#define UPDATE_IOB(iob, off, len) \
+do  \
+  { \
+    iob->io_offset = off; \
+    iob->io_len    = len; \
+    iob->io_pktlen = len; \
+  } while (0);  \
+
+/* Defined the minimal timeout interval to avoid triggering timeout timer
+ * too frequently, default: 0.5 seconds.
+ */
+
+#define REASSEMBLY_TIMEOUT_MINIMAL      5
+
+#if CONFIG_NET_IPFRAG_REASS_MAXAGE < REASSEMBLY_TIMEOUT_MINIMAL
+#  define REASSEMBLY_TIMEOUT            REASSEMBLY_TIMEOUT_MINIMAL
+#else
+#  define REASSEMBLY_TIMEOUT            CONFIG_NET_IPFRAG_REASS_MAXAGE
+#endif
+
+#define REASSEMBLY_TIMEOUT_MINIMALTICKS DSEC2TICK(REASSEMBLY_TIMEOUT_MINIMAL)
+#define REASSEMBLY_TIMEOUT_TICKS        DSEC2TICK(REASSEMBLY_TIMEOUT)
+
+#define IPFRAGWORK                      LPWORK
+
+/* Helper macro to count I/O buffer count for a given I/O buffer chain */
+
+#define IOBUF_CNT(ptr)    ((ptr->io_pktlen + CONFIG_IOB_BUFSIZE - 1)/ \
+                          CONFIG_IOB_BUFSIZE)
+
+/* The maximum I/O buffer occupied by fragment reassembly cache */
+
+#define REASSEMBLY_MAXOCCUPYIOB        CONFIG_IOB_NBUFFERS / 5
+
+/* Deciding whether to fragment outgoing packets which target is to ourself */
+
+#define LOOPBACK_IPFRAME_NOFRAGMENT    0
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* A timeout timer used to start a worker which is used to check
+ * whether the assembly time of those fragments within one node is expired,
+ * if so, free all resources of this node.
+ */
+
+static struct wdog_s  g_wdfragtimeout;
+
+/* Reassembly timeout work */
+
+static struct work_s  g_wkfragtimeout;
+
+/* Remember the number of I/O buffers currently in reassembly cache */
+
+static uint8_t        g_bufoccupy;
+
+/* Queue header definition, it links all fragments of all NICs by ascending
+ * ipid.
+ */
+
+static sq_queue_t     g_assemblyhead_ipid;
+
+/* Queue header definition, which connects all fragments of all NICs in order
+ * of addition time.
+ */
+
+static sq_queue_t     g_assemblyhead_time;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* Only one thread can access g_assemblyhead_ipid and g_assemblyhead_time
+ * at a time.
+ */
+
+sem_t                 g_ipfrag_mutex = SEM_INITIALIZER(1);

Review Comment:
   Many places in the nuttx network protocol stack use semaphores instead of 
mutex, must it be changed to mutex here?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to