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

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

commit 7f421a46ca8871d70f0f76f30a1b98e3a53cb1d5
Author: Zhe Weng <[email protected]>
AuthorDate: Mon Oct 23 17:18:09 2023 +0800

    net/procfs: Support printing multiple IPv6 address per netdev
    
    Signed-off-by: Zhe Weng <[email protected]>
---
 include/nuttx/compiler.h       |  8 ++++++++
 net/procfs/netdev_statistics.c | 36 ++++++++++++++++++++++++++++--------
 2 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h
index a71b34d2d8..74edd9f212 100644
--- a/include/nuttx/compiler.h
+++ b/include/nuttx/compiler.h
@@ -61,6 +61,14 @@
 #  define CONFIG_C99_BOOL 1
 #endif
 
+/* ISO C99 supports Designated initializers */
+
+#undef CONFIG_DESIGNATED_INITIALIZERS
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#  define CONFIG_DESIGNATED_INITIALIZERS 1
+#endif
+
 /* ISO C/C++11 atomic types support */
 
 #undef CONFIG_HAVE_ATOMICS
diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c
index fdc6ea5ab8..e62fd59830 100644
--- a/net/procfs/netdev_statistics.c
+++ b/net/procfs/netdev_statistics.c
@@ -36,6 +36,7 @@
 #include <nuttx/net/netdev.h>
 #include <nuttx/net/sixlowpan.h>
 
+#include "inet/inet.h"
 #include "netdev/netdev.h"
 #include "utils/utils.h"
 #include "procfs/procfs.h"
@@ -43,6 +44,16 @@
 #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \
     !defined(CONFIG_FS_PROCFS_EXCLUDE_NET)
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_IPv4
+#  define NETSTAT_IPv6_IDX 2
+#else
+#  define NETSTAT_IPv6_IDX 1
+#endif
+
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
@@ -83,7 +94,13 @@ static const linegen_t g_netstat_linegen[] =
   , netprocfs_inet4addresses
 #endif
 #ifdef CONFIG_NET_IPv6
+#  if defined(CONFIG_NETDEV_MULTIPLE_IPv6) && \
+      defined(CONFIG_DESIGNATED_INITIALIZERS)
+  , [NETSTAT_IPv6_IDX ... NETSTAT_IPv6_IDX + CONFIG_NETDEV_MAX_IPv6_ADDR - 1]
+  = netprocfs_inet6address
+#  else
   , netprocfs_inet6address
+#  endif
   , netprocfs_inet6draddress
 #endif
 #if !defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6)
@@ -309,18 +326,26 @@ static int netprocfs_inet6address(FAR struct 
netprocfs_file_s *netfile)
   FAR struct net_driver_s *dev;
   char addrstr[INET6_ADDRSTRLEN];
   uint8_t preflen;
+  int idx = netfile->lineno - NETSTAT_IPv6_IDX;
   int len = 0;
 
   DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
   dev = netfile->dev;
 
+#ifdef CONFIG_NETDEV_MULTIPLE_IPv6
+  if (net_ipv6addr_cmp(dev->d_ipv6[idx].addr, g_ipv6_unspecaddr))
+    {
+      return 0;
+    }
+#endif
+
   /* Convert the 128 network mask to a human friendly prefix length */
 
-  preflen = net_ipv6_mask2pref(dev->d_ipv6netmask);
+  preflen = net_ipv6_mask2pref(dev->d_ipv6[idx].mask);
 
   /* Show the assigned IPv6 address */
 
-  if (inet_ntop(AF_INET6, dev->d_ipv6addr, addrstr, INET6_ADDRSTRLEN))
+  if (inet_ntop(AF_INET6, dev->d_ipv6[idx].addr, addrstr, INET6_ADDRSTRLEN))
     {
       len += snprintf(&netfile->line[len], NET_LINELEN - len,
                       "\tinet6 addr: %s/%d\n", addrstr, preflen);
@@ -339,22 +364,17 @@ static int netprocfs_inet6draddress(FAR struct 
netprocfs_file_s *netfile)
 {
   FAR struct net_driver_s *dev;
   char addrstr[INET6_ADDRSTRLEN];
-  uint8_t preflen;
   int len = 0;
 
   DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
   dev = netfile->dev;
 
-  /* Convert the 128 network mask to a human friendly prefix length */
-
-  preflen = net_ipv6_mask2pref(dev->d_ipv6netmask);
-
   /* Show the IPv6 default router address */
 
   if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
     {
       len += snprintf(&netfile->line[len], NET_LINELEN - len,
-                      "\tinet6 DRaddr: %s/%d\n\n", addrstr, preflen);
+                      "\tinet6 DRaddr: %s\n\n", addrstr);
     }
 
   return len;

Reply via email to