anchao commented on code in PR #6997:
URL: https://github.com/apache/incubator-nuttx/pull/6997#discussion_r964382987


##########
net/procfs/net_procfs.c:
##########
@@ -155,44 +214,31 @@ static int netprocfs_open(FAR struct file *filep, FAR 
const char *relpath,
       return -EACCES;
     }
 
-#ifdef CONFIG_NET_STATISTICS
-  /* "net/stat" is an acceptable value for the relpath only if network layer
-   * statistics are enabled.
-   */
-
-  if (strcmp(relpath, "net/stat") == 0)
-    {
-      entry = NETPROCFS_SUBDIR_STAT;
-      dev   = NULL;
-    }
-  else
-#ifdef CONFIG_NET_MLD
-  /* "net/mld" is an acceptable value for the relpath only if MLD is
-   * enabled.
-   */
-
-  if (strcmp(relpath, "net/mld") == 0)
-    {
-      entry = NETPROCFS_SUBDIR_MLD;
-      dev   = NULL;
-    }
-  else
-#endif
-#endif
+  entry = NETPROCFS_SUBDIR_DEV;
 
-#ifdef CONFIG_NET_ROUTE
-  /* "net/route" is an acceptable value for the relpath only if routing
-   * table support is initialized.
-   */
+  /* For each net entries */
 
-  if (fnmatch("net/route/**", relpath, 0) == 0)
+  for (i = 0; i < ARRAY_SIZE(g_net_entries); i++)
     {
-      /* Use the /net/route directory */
+      if (strcmp(relpath + 4, g_net_entries[i].name))

Review Comment:
   Done



##########
net/procfs/net_procfs.c:
##########
@@ -52,26 +52,44 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Directory entry indices */
+#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
 
+/****************************************************************************
+ * Private Type Definitions
+ ****************************************************************************/
+
+/* Read statistics function type */
+
+typedef ssize_t (*read_stat_t)(FAR struct netprocfs_file_s *priv,
+                               FAR char *buffer, size_t buflen);
+
+/* Describes the /net directory entries */
+
+enum netprocfs_entry_e
+{
+  NETPROCFS_SUBDIR_DEV = 0    /* Multiple instances, e.g. /proc/net/eth0 */
 #ifdef CONFIG_NET_STATISTICS
-#  define STAT_INDEX     0
+  , NETPROCFS_SUBDIR_STAT     /* /proc/net/stat */
 #  ifdef CONFIG_NET_MLD
-#    define MLD_INDEX    1
-#    define _ROUTE_INDEX 2
-#  else
-#    define _ROUTE_INDEX 1
+  , NETPROCFS_SUBDIR_MLD      /* /proc/net/mld */
 #  endif
-#else
-#  define _ROUTE_INDEX   0
 #endif
-
 #ifdef CONFIG_NET_ROUTE
-#  define ROUTE_INDEX    _ROUTE_INDEX
-#  define DEV_INDEX      (_ROUTE_INDEX + 1)
-#else
-#  define DEV_INDEX      _ROUTE_INDEX
+  , NETPROCFS_SUBDIR_ROUTE    /* /proc/net/route */
 #endif
+};
+
+struct netprocfs_entry_s
+{
+  enum netprocfs_entry_e                  index; /* Directory entry index */
+  uint8_t                                 type;  /* Type of file */
+  FAR char                               *name;  /* File name */

Review Comment:
   Done



##########
net/procfs/net_procfs.c:
##########
@@ -155,44 +214,31 @@ static int netprocfs_open(FAR struct file *filep, FAR 
const char *relpath,
       return -EACCES;
     }
 
-#ifdef CONFIG_NET_STATISTICS
-  /* "net/stat" is an acceptable value for the relpath only if network layer
-   * statistics are enabled.
-   */
-
-  if (strcmp(relpath, "net/stat") == 0)
-    {
-      entry = NETPROCFS_SUBDIR_STAT;
-      dev   = NULL;
-    }
-  else
-#ifdef CONFIG_NET_MLD
-  /* "net/mld" is an acceptable value for the relpath only if MLD is
-   * enabled.
-   */
-
-  if (strcmp(relpath, "net/mld") == 0)
-    {
-      entry = NETPROCFS_SUBDIR_MLD;
-      dev   = NULL;
-    }
-  else
-#endif
-#endif
+  entry = NETPROCFS_SUBDIR_DEV;
 
-#ifdef CONFIG_NET_ROUTE
-  /* "net/route" is an acceptable value for the relpath only if routing
-   * table support is initialized.
-   */
+  /* For each net entries */
 
-  if (fnmatch("net/route/**", relpath, 0) == 0)
+  for (i = 0; i < ARRAY_SIZE(g_net_entries); i++)
     {
-      /* Use the /net/route directory */
+      if (strcmp(relpath + 4, g_net_entries[i].name))
+        {
+          continue;
+        }
 
-      return net_procfs_routeoperations.open(filep, relpath, oflags, mode);
+      if (g_net_entries[i].type == DTYPE_FILE)
+        {
+          entry = g_net_entries[i].index;
+          dev = NULL;

Review Comment:
   Done



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