mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 03:45:50 +08:00
net/procfs: Support printing multiple IPv6 address per netdev
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
@@ -61,6 +61,14 @@
|
|||||||
# define CONFIG_C99_BOOL 1
|
# define CONFIG_C99_BOOL 1
|
||||||
#endif
|
#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 */
|
/* ISO C/C++11 atomic types support */
|
||||||
|
|
||||||
#undef CONFIG_HAVE_ATOMICS
|
#undef CONFIG_HAVE_ATOMICS
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <nuttx/net/netdev.h>
|
#include <nuttx/net/netdev.h>
|
||||||
#include <nuttx/net/sixlowpan.h>
|
#include <nuttx/net/sixlowpan.h>
|
||||||
|
|
||||||
|
#include "inet/inet.h"
|
||||||
#include "netdev/netdev.h"
|
#include "netdev/netdev.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "procfs/procfs.h"
|
#include "procfs/procfs.h"
|
||||||
@@ -43,6 +44,16 @@
|
|||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \
|
||||||
!defined(CONFIG_FS_PROCFS_EXCLUDE_NET)
|
!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
|
* Private Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -83,7 +94,13 @@ static const linegen_t g_netstat_linegen[] =
|
|||||||
, netprocfs_inet4addresses
|
, netprocfs_inet4addresses
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_NET_IPv6
|
#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
|
, netprocfs_inet6address
|
||||||
|
# endif
|
||||||
, netprocfs_inet6draddress
|
, netprocfs_inet6draddress
|
||||||
#endif
|
#endif
|
||||||
#if !defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6)
|
#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;
|
FAR struct net_driver_s *dev;
|
||||||
char addrstr[INET6_ADDRSTRLEN];
|
char addrstr[INET6_ADDRSTRLEN];
|
||||||
uint8_t preflen;
|
uint8_t preflen;
|
||||||
|
int idx = netfile->lineno - NETSTAT_IPv6_IDX;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
||||||
dev = netfile->dev;
|
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 */
|
/* 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 */
|
/* 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,
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
||||||
"\tinet6 addr: %s/%d\n", addrstr, preflen);
|
"\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;
|
FAR struct net_driver_s *dev;
|
||||||
char addrstr[INET6_ADDRSTRLEN];
|
char addrstr[INET6_ADDRSTRLEN];
|
||||||
uint8_t preflen;
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
||||||
dev = netfile->dev;
|
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 */
|
/* Show the IPv6 default router address */
|
||||||
|
|
||||||
if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
|
if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
|
||||||
{
|
{
|
||||||
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
||||||
"\tinet6 DRaddr: %s/%d\n\n", addrstr, preflen);
|
"\tinet6 DRaddr: %s\n\n", addrstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
|||||||
Reference in New Issue
Block a user