net/procfs: Add support to provide MLD stats at /proc/net/mld. net/mld: Fix a couple more bugs found in further MLD testing.

This commit is contained in:
Gregory Nutt 2018-11-06 10:42:53 -06:00
parent 12a500fcb6
commit f58e7976df
9 changed files with 370 additions and 26 deletions

View file

@ -381,11 +381,12 @@ struct mld_stats_s
net_stats_t report_sched; /* Unsolicited REPORT packets scheduled */
net_stats_t done_sched; /* DONE packets scheduled */
net_stats_t query_sent; /* General QUERY packets sent */
net_stats_t report_sent; /* Unsolicited REPORT packets sent */
net_stats_t v1report_sent; /* Version 1 REPORT packets sent */
net_stats_t v2report_sent; /* Version 2 REPORT packets sent */
net_stats_t done_sent; /* DONE packets sent */
net_stats_t gmq_query_received; /* General multicast QUERY received */
net_stats_t gm_query_received; /* General multicast QUERY received */
net_stats_t mas_query_received; /* Multicast Address Specific QUERY received */
net_stats_t massq_query_received; /* Multicast Address and Source Specific QUERY received */
net_stats_t mass_query_received; /* Multicast Address and Source Specific QUERY received */
net_stats_t ucast_query_received; /* Unicast query received */
net_stats_t bad_query_received; /* Unhandled query received */
net_stats_t v1report_received; /* Version 1 REPORT packets received */

View file

@ -126,8 +126,8 @@
/* Group flags */
#define MLD_QUERIER (1 << 0) /* Querier */
#define MLD_STARTUP (1 << 2) /* Startup unsolicited Reports */
#define MLD_V1COMPAT (1 << 3) /* Version 1 compatibility mode */
#define MLD_STARTUP (1 << 1) /* Startup unsolicited Reports */
#define MLD_V1COMPAT (1 << 2) /* Version 1 compatibility mode */
#define MLD_LASTREPORT (1 << 3) /* We were the last to report */
#define MLD_SCHEDMSG (1 << 4) /* Outgoing message scheduled */
#define MLD_WAITMSG (1 << 5) /* Block until message sent */

View file

@ -79,9 +79,9 @@ static void mld_mcastmac(FAR const net_ipv6addr_t ipaddr, FAR uint8_t *mac)
mac[0] = 0x33;
mac[1] = 0x33;
mac[2] = ipaddr8[12]; /* Bits: 96-103 */
mac[2] = ipaddr8[13]; /* Bits: 104-111 */
mac[2] = ipaddr8[14]; /* Bits: 112-119 */
mac[2] = ipaddr8[15]; /* Bits: 120-127 */
mac[3] = ipaddr8[13]; /* Bits: 104-111 */
mac[4] = ipaddr8[14]; /* Bits: 112-119 */
mac[5] = ipaddr8[15]; /* Bits: 120-127 */
mldinfo("Mcast MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

View file

@ -367,7 +367,7 @@ int mld_query(FAR struct net_driver_s *dev,
/* This is the general query */
mldinfo("General multicast query\n");
MLD_STATINCR(g_netstats.mld.gmq_query_received);
MLD_STATINCR(g_netstats.mld.gm_query_received);
/* Two passes through the member list. On the first, just check if we
* are still the querier for the qroup.
@ -477,7 +477,7 @@ int mld_query(FAR struct net_driver_s *dev,
else
{
mldinfo("Multicast Address and Source Specific Query\n");
MLD_STATINCR(g_netstats.mld.massq_query_received);
MLD_STATINCR(g_netstats.mld.mass_query_received);
}
/* Check MLDv1 compatibility mode */

View file

@ -265,7 +265,7 @@ void mld_send(FAR struct net_driver_s *dev, FAR struct mld_group_s *group,
* encoded and must follow the rules for MLDv1.
*/
memset(query, 0, sizeof(struct mld_mcast_listen_report_v1_s));
memset(query, 0, sizeof(struct mld_mcast_listen_query_s));
net_ipv6addr_hdrcopy(query->grpaddr, &group->grpaddr);
query->type = ICMPV6_MCAST_LISTEN_QUERY;
query->mrc = MLD_QRESP_MSEC;
@ -303,7 +303,7 @@ void mld_send(FAR struct net_driver_s *dev, FAR struct mld_group_s *group,
report->chksum = ~icmpv6_chksum(dev, MLD_HDRLEN);
SET_MLD_LASTREPORT(group->flags); /* Remember we were the last to report */
MLD_STATINCR(g_netstats.mld.report_sent);
MLD_STATINCR(g_netstats.mld.v1report_sent);
}
break;
@ -328,7 +328,7 @@ void mld_send(FAR struct net_driver_s *dev, FAR struct mld_group_s *group,
report->chksum = ~icmpv6_chksum(dev, MLD_HDRLEN);
SET_MLD_LASTREPORT(group->flags); /* Remember we were the last to report */
MLD_STATINCR(g_netstats.mld.report_sent);
MLD_STATINCR(g_netstats.mld.v2report_sent);
}
break;

View file

@ -45,6 +45,9 @@ NET_CSRCS += net_procfs.c netdev_statistics.c
ifeq ($(CONFIG_NET_STATISTICS),y)
NET_CSRCS += net_statistics.c
ifeq ($(CONFIG_NET_MLD),y)
NET_CSRCS += net_mld.c
endif
endif
# Routing table

269
net/procfs/net_mld.c Normal file
View file

@ -0,0 +1,269 @@
/****************************************************************************
* net/procfs/net_mld.c
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* Output format:
*
* Joins: xxxx Leaves: xxxx
* Sent Sched Sent
* Queries: xxxx xxxx
* Reports:
* Ver 1: ---- xxxx
* Ver 2: xxxx xxxx
* Done: xxxx xxxx
* Received:
* Queries:
* Gen: xxxx
* MAS: xxxx
* MASSQ: xxxx
* Ucast: xxxx
* Bad: xxxx
* Reports:
* Ver 1: xxxx
* Ver 2: xxxx
* Done: xxxx
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <debug.h>
#include <nuttx/net/netstats.h>
#include "procfs/procfs.h"
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \
!defined(CONFIG_FS_PROCFS_EXCLUDE_NET) && defined(CONFIG_NET_STATISTICS)
#if defined(CONFIG_NET_ICMPv6) || defined(CONFIG_NET_MLD)
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* Line generating functions */
static int netprocfs_joinleave(FAR struct netprocfs_file_s *netfile);
static int netprocfs_queries_sent(FAR struct netprocfs_file_s *netfile);
static int netprocfs_reports_sent(FAR struct netprocfs_file_s *netfile);
static int netprocfs_done_sent(FAR struct netprocfs_file_s *netfile);
static int netprocfs_queries_received_1(FAR struct netprocfs_file_s *netfile);
static int netprocfs_queries_received_2(FAR struct netprocfs_file_s *netfile);
static int netprocfs_reports_received(FAR struct netprocfs_file_s *netfile);
static int netprocfs_done_received(FAR struct netprocfs_file_s *netfile);
/****************************************************************************
* Private Data
****************************************************************************/
/* Line generating functions */
static const linegen_t g_mld_linegen[] =
{
netprocfs_joinleave,
netprocfs_queries_sent,
netprocfs_reports_sent,
netprocfs_done_sent,
netprocfs_queries_received_1,
netprocfs_queries_received_2,
netprocfs_reports_received,
netprocfs_done_received
};
#define NSTAT_LINES (sizeof(g_mld_linegen) / sizeof(linegen_t))
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: netprocfs_joinleave
****************************************************************************/
static int netprocfs_joinleave(FAR struct netprocfs_file_s *netfile)
{
int len;
len = snprintf(netfile->line, NET_LINELEN, "Joins: %04x ",
g_netstats.mld.joins);
len += snprintf(&netfile->line[len], NET_LINELEN - len, "Leaves: %04x\n",
g_netstats.mld.leaves);
return len;
}
/****************************************************************************
* Name: netprocfs_queries_sent
****************************************************************************/
static int netprocfs_queries_sent(FAR struct netprocfs_file_s *netfile)
{
int len;
len = snprintf(netfile->line, NET_LINELEN, "Sent Sched Sent\n");
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Queries: %04x %04x\n",
g_netstats.mld.query_sched, g_netstats.mld.query_sent);
return len;
}
/****************************************************************************
* Name: netprocfs_reports_sent
****************************************************************************/
static int netprocfs_reports_sent(FAR struct netprocfs_file_s *netfile)
{
int len;
len = snprintf(netfile->line, NET_LINELEN, " Reports:\n");
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Ver 1: ---- %04x\n",
g_netstats.mld.v1report_sent);
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Ver 2: %04x %04x\n",
g_netstats.mld.report_sched, g_netstats.mld.v2report_sent);
return len;
}
/****************************************************************************
* Name: netprocfs_done_sent
****************************************************************************/
static int netprocfs_done_sent(FAR struct netprocfs_file_s *netfile)
{
return snprintf(netfile->line, NET_LINELEN, " Done: %04x %04x\n",
g_netstats.mld.done_sched, g_netstats.mld.done_sent);
}
/****************************************************************************
* Name: netprocfs_queries_received_1 and _2
****************************************************************************/
static int netprocfs_queries_received_1(FAR struct netprocfs_file_s *netfile)
{
int len;
len = snprintf(netfile->line, NET_LINELEN, "Received:\n");
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Queries:\n");
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Gen: %04x\n",
g_netstats.mld.gm_query_received);
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" MAS: %04x\n",
g_netstats.mld.mas_query_received);
return len;
}
static int netprocfs_queries_received_2(FAR struct netprocfs_file_s *netfile)
{
int len;
len = snprintf(netfile->line, NET_LINELEN,
" MASS: %04x\n",
g_netstats.mld.mass_query_received);
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Ucast: %04x\n",
g_netstats.mld.ucast_query_received);
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Bad: %04x\n",
g_netstats.mld.bad_query_received);
return len;
}
/****************************************************************************
* Name: netprocfs_reports_received
****************************************************************************/
static int netprocfs_reports_received(FAR struct netprocfs_file_s *netfile)
{
int len;
len = snprintf(netfile->line, NET_LINELEN, " Reports:\n");
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Ver 1: %04x\n",
g_netstats.mld.v1report_received);
len += snprintf(&netfile->line[len], NET_LINELEN - len,
" Ver 2: %04x\n",
g_netstats.mld.v2report_received);
return len;
}
/****************************************************************************
* Name: netprocfs_done_received
****************************************************************************/
static int netprocfs_done_received(FAR struct netprocfs_file_s *netfile)
{
return snprintf(netfile->line, NET_LINELEN , " Done: %04x\n",
g_netstats.mld.done_received);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: netprocfs_read_mldstats
*
* Description:
* Read and format MLD statistics.
*
* Input Parameters:
* priv - A reference to the network procfs file structure
* buffer - The user-provided buffer into which network status will be
* returned.
* bulen - The size in bytes of the user provided buffer.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned
* on failure.
*
****************************************************************************/
ssize_t netprocfs_read_mldstats(FAR struct netprocfs_file_s *priv,
FAR char *buffer, size_t buflen)
{
return netprocfs_read_linegen(priv, buffer, buflen, g_mld_linegen, NSTAT_LINES);
}
#endif /* CONFIG_NET_ICMPv6 || CONFIG_NET_MLD */
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS &&
* !CONFIG_FS_PROCFS_EXCLUDE_NET */

View file

@ -71,18 +71,23 @@
/* Directory entry indices */
#if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_ROUTE)
# define STAT_INDEX 0
# define ROUTE_INDEX 1
# define DEV_INDEX 2
#elif defined(CONFIG_NET_STATISTICS)
# define STAT_INDEX 0
# define DEV_INDEX 1
#elif defined(CONFIG_NET_ROUTE)
# define ROUTE_INDEX 0
# define DEV_INDEX 1
#ifdef CONFIG_NET_STATISTICS
# define STAT_INDEX 0
# ifdef CONFIG_NET_MLD
# define MLD_INDEX 1
# define _ROUTE_INDEX 2
# else
# define _ROUTE_INDEX 1
# endif
#else
# define DEV_INDEX 0
# 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
#endif
/****************************************************************************
@ -176,6 +181,16 @@ static int netprocfs_open(FAR struct file *filep, FAR const char *relpath,
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
#ifdef CONFIG_NET_ROUTE
@ -295,6 +310,14 @@ static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer,
nreturned = netprocfs_read_netstats(priv, buffer, buflen);
break;
#ifdef CONFIG_NET_MLD
case NETPROCFS_SUBDIR_MLD:
/* Show the MLD statistics */
nreturned = netprocfs_read_mldstats(priv, buffer, buflen);
break;
#endif
#endif
#ifdef CONFIG_NET_ROUTE
@ -408,11 +431,14 @@ static int netprocfs_opendir(FAR const char *relpath,
ndevs = netdev_count();
/* Initialze base structure components */
/* Initialize base structure components */
level1->base.nentries = ndevs;
#ifdef CONFIG_NET_STATISTICS
level1->base.nentries++;
#ifdef CONFIG_NET_MLD
level1->base.nentries++;
#endif
#endif
#ifdef CONFIG_NET_ROUTE
level1->base.nentries++;
@ -501,7 +527,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
}
#ifdef CONFIG_NET_STATISTICS
else if (index == STAT_INDEX)
if (index == STAT_INDEX)
{
/* Copy the network statistics directory entry */
@ -509,6 +535,16 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
strncpy(dir->fd_dir.d_name, "stat", NAME_MAX + 1);
}
else
#ifdef CONFIG_NET_MLD
if (index == MLD_INDEX)
{
/* Copy the MLD directory entry */
dir->fd_dir.d_type = DTYPE_FILE;
strncpy(dir->fd_dir.d_name, "mld", NAME_MAX + 1);
}
else
#endif
#endif
#ifdef CONFIG_NET_ROUTE
if (index == ROUTE_INDEX)
@ -631,6 +667,15 @@ static int netprocfs_stat(FAR const char *relpath, FAR struct stat *buf)
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
}
else
#ifdef CONFIG_NET_MLD
/* Check for MLD statistics "net/mld" */
if (strcmp(relpath, "net/mld") == 0)
{
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
}
else
#endif
#endif
#ifdef CONFIG_NET_ROUTE
/* Check for network statistics "net/stat" */

View file

@ -71,6 +71,9 @@ enum netprocfs_entry_e
NETPROCFS_SUBDIR_DEV = 0 /* Multiple instances, e.g. /proc/net/eth0 */
#ifdef CONFIG_NET_STATISTICS
, NETPROCFS_SUBDIR_STAT /* /proc/net/stat */
#ifdef CONFIG_NET_MLD
, NETPROCFS_SUBDIR_MLD /* /proc/net/mld */
#endif
#endif
#ifdef CONFIG_NET_ROUTE
, NETPROCFS_SUBDIR_ROUTE /* /proc/net/route */
@ -169,6 +172,29 @@ ssize_t netprocfs_read_netstats(FAR struct netprocfs_file_s *priv,
FAR char *buffer, size_t buflen);
#endif
/****************************************************************************
* Name: netprocfs_read_mldstats
*
* Description:
* Read and format MLD statistics.
*
* Input Parameters:
* priv - A reference to the network procfs file structure
* buffer - The user-provided buffer into which network status will be
* returned.
* bulen - The size in bytes of the user provided buffer.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned
* on failure.
*
****************************************************************************/
#if defined(CONFIG_NET_STATISTICS) && defined(CONFIG_NET_MLD)
ssize_t netprocfs_read_mldstats(FAR struct netprocfs_file_s *priv,
FAR char *buffer, size_t buflen);
#endif
/****************************************************************************
* Name: netprocfs_read_routes
*