2015-11-27 23:39:14 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/procfs/netdev_statistics.c
|
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* 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
|
2015-11-27 23:39:14 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-11-27 23:39:14 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* 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.
|
2015-11-27 23:39:14 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2020-11-13 06:58:29 +01:00
|
|
|
#include <inttypes.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2015-11-27 23:39:14 +01:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <netinet/ether.h>
|
|
|
|
|
|
|
|
#include <nuttx/net/netdev.h>
|
2017-04-03 23:25:36 +02:00
|
|
|
#include <nuttx/net/sixlowpan.h>
|
2015-11-27 23:39:14 +01:00
|
|
|
|
2023-10-23 11:18:09 +02:00
|
|
|
#include "inet/inet.h"
|
2015-11-27 23:39:14 +01:00
|
|
|
#include "netdev/netdev.h"
|
2016-01-09 22:56:08 +01:00
|
|
|
#include "utils/utils.h"
|
2015-11-27 23:39:14 +01:00
|
|
|
#include "procfs/procfs.h"
|
|
|
|
|
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \
|
|
|
|
!defined(CONFIG_FS_PROCFS_EXCLUDE_NET)
|
|
|
|
|
2023-10-23 11:18:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
# define NETSTAT_IPv6_IDX 2
|
|
|
|
#else
|
|
|
|
# define NETSTAT_IPv6_IDX 1
|
|
|
|
#endif
|
|
|
|
|
2015-11-27 23:39:14 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile);
|
2017-05-18 09:30:12 +02:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
static int netprocfs_inet4addresses(FAR struct netprocfs_file_s *netfile);
|
|
|
|
#endif
|
2017-04-09 19:06:21 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-05-18 09:30:12 +02:00
|
|
|
static int netprocfs_inet6address(FAR struct netprocfs_file_s *netfile);
|
|
|
|
static int netprocfs_inet6draddress(FAR struct netprocfs_file_s *netfile);
|
2017-04-09 19:06:21 +02:00
|
|
|
#endif
|
2017-08-21 17:31:12 +02:00
|
|
|
#if !defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6)
|
|
|
|
static int netprocfs_blank_line(FAR struct netprocfs_file_s *netfile);
|
|
|
|
#endif
|
2015-11-27 23:39:14 +01:00
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
2020-11-13 06:57:26 +01:00
|
|
|
static int netprocfs_rxstatistics_header(
|
|
|
|
FAR struct netprocfs_file_s *netfile);
|
2015-11-27 23:39:14 +01:00
|
|
|
static int netprocfs_rxstatistics(FAR struct netprocfs_file_s *netfile);
|
|
|
|
static int netprocfs_rxpackets_header(FAR struct netprocfs_file_s *netfile);
|
|
|
|
static int netprocfs_rxpackets(FAR struct netprocfs_file_s *netfile);
|
2020-11-13 06:57:26 +01:00
|
|
|
static int netprocfs_txstatistics_header(
|
|
|
|
FAR struct netprocfs_file_s *netfile);
|
2015-11-27 23:39:14 +01:00
|
|
|
static int netprocfs_txstatistics(FAR struct netprocfs_file_s *netfile);
|
|
|
|
static int netprocfs_errors(FAR struct netprocfs_file_s *netfile);
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Line generating functions */
|
|
|
|
|
2017-08-11 22:50:39 +02:00
|
|
|
static const linegen_t g_netstat_linegen[] =
|
2015-11-27 23:39:14 +01:00
|
|
|
{
|
2017-05-18 09:30:12 +02:00
|
|
|
netprocfs_linklayer
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
, netprocfs_inet4addresses
|
|
|
|
#endif
|
2017-04-09 19:06:21 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2023-10-23 11:18:09 +02:00
|
|
|
# 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
|
2017-05-18 09:30:12 +02:00
|
|
|
, netprocfs_inet6address
|
2023-10-23 11:18:09 +02:00
|
|
|
# endif
|
2017-05-18 09:30:12 +02:00
|
|
|
, netprocfs_inet6draddress
|
2017-04-09 19:06:21 +02:00
|
|
|
#endif
|
2017-08-21 17:31:12 +02:00
|
|
|
#if !defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6)
|
|
|
|
, netprocfs_blank_line
|
|
|
|
#endif
|
|
|
|
|
2015-11-27 23:39:14 +01:00
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
|
|
|
, netprocfs_rxstatistics_header,
|
|
|
|
netprocfs_rxstatistics,
|
|
|
|
netprocfs_rxpackets_header,
|
|
|
|
netprocfs_rxpackets,
|
|
|
|
netprocfs_txstatistics_header,
|
|
|
|
netprocfs_txstatistics,
|
|
|
|
netprocfs_errors
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
};
|
|
|
|
|
2017-08-11 22:50:39 +02:00
|
|
|
#define NSTAT_LINES (sizeof(g_netstat_linegen) / sizeof(linegen_t))
|
2015-11-27 23:39:14 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-21 17:31:12 +02:00
|
|
|
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
|
|
|
|
static int netprocfs_radio_linklayer(FAR struct netprocfs_file_s *netfile,
|
2017-08-02 01:21:13 +02:00
|
|
|
int len)
|
|
|
|
{
|
|
|
|
FAR struct netdev_varaddr_s *addr;
|
|
|
|
FAR struct net_driver_s *dev;
|
2020-01-31 16:15:01 +01:00
|
|
|
#if RADIO_MAX_ADDRLEN > 1
|
2018-11-11 21:28:15 +01:00
|
|
|
int i;
|
2018-12-02 00:27:32 +01:00
|
|
|
#endif
|
2017-08-02 01:21:13 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
2017-08-19 16:48:52 +02:00
|
|
|
addr = &dev->d_mac.radio;
|
2017-08-02 01:21:13 +02:00
|
|
|
|
2017-08-21 17:31:12 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2017-08-02 01:21:13 +02:00
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:6LoWPAN HWaddr ",
|
|
|
|
dev->d_ifname);
|
2017-08-21 17:31:12 +02:00
|
|
|
#else
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:Raw HWaddr ",
|
|
|
|
dev->d_ifname);
|
|
|
|
#endif
|
2017-08-02 01:21:13 +02:00
|
|
|
|
2018-11-11 21:28:15 +01:00
|
|
|
if (addr->nv_addrlen < 1 || addr->nv_addrlen > RADIO_MAX_ADDRLEN)
|
2017-08-02 01:21:13 +02:00
|
|
|
{
|
2018-11-20 15:05:18 +01:00
|
|
|
nwarn("WARNING: Bad or undefined node address: %u\n",
|
|
|
|
addr->nv_addrlen);
|
|
|
|
|
2018-11-11 21:28:15 +01:00
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"--");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%02x", addr->nv_addr[0]);
|
|
|
|
|
2018-11-26 01:42:39 +01:00
|
|
|
#if RADIO_MAX_ADDRLEN > 1 /* Avoids a warning */
|
2018-11-20 15:05:18 +01:00
|
|
|
for (i = 1; i < addr->nv_addrlen; i++)
|
2018-11-11 21:28:15 +01:00
|
|
|
{
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
":%02x", addr->nv_addr[i]);
|
|
|
|
}
|
2018-11-26 01:42:39 +01:00
|
|
|
#endif
|
2017-08-02 01:21:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-01-13 19:08:45 +01:00
|
|
|
/****************************************************************************
|
2015-11-27 23:39:14 +01:00
|
|
|
* Name: netprocfs_linklayer
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR const char *status;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
|
|
|
|
/* Get the interface status: RUNNING, UP, or DOWN */
|
|
|
|
|
|
|
|
if ((dev->d_flags & IFF_RUNNING) != 0)
|
|
|
|
{
|
|
|
|
status = "RUNNING";
|
|
|
|
}
|
|
|
|
else if ((dev->d_flags & IFF_UP) != 0)
|
|
|
|
{
|
|
|
|
status = "UP";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = "DOWN";
|
|
|
|
}
|
|
|
|
|
2017-08-08 23:26:09 +02:00
|
|
|
/* Select the output appropriate for the link type associated with
|
|
|
|
* this device.
|
2015-11-27 23:39:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
switch (dev->d_lltype)
|
|
|
|
{
|
2018-08-21 17:08:29 +02:00
|
|
|
#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_DRIVERS_IEEE80211)
|
2015-11-27 23:39:14 +01:00
|
|
|
case NET_LL_ETHERNET:
|
2018-08-21 17:08:29 +02:00
|
|
|
case NET_LL_IEEE80211:
|
2022-08-01 11:17:23 +02:00
|
|
|
{
|
|
|
|
char hwaddr[20];
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:Ethernet HWaddr %s",
|
|
|
|
dev->d_ifname,
|
|
|
|
ether_ntoa_r(&dev->d_mac.ether, hwaddr));
|
|
|
|
}
|
2015-11-27 23:39:14 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2017-08-21 17:31:12 +02:00
|
|
|
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
|
2017-04-03 23:25:36 +02:00
|
|
|
case NET_LL_IEEE802154:
|
2017-08-02 01:21:13 +02:00
|
|
|
case NET_LL_PKTRADIO:
|
2017-04-03 23:25:36 +02:00
|
|
|
{
|
2017-08-21 17:31:12 +02:00
|
|
|
len += netprocfs_radio_linklayer(netfile, len);
|
2017-04-03 23:25:36 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-08-21 17:31:12 +02:00
|
|
|
#endif /* CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */
|
2017-04-03 23:25:36 +02:00
|
|
|
|
2015-11-27 23:39:14 +01:00
|
|
|
#ifdef CONFIG_NET_LOOPBACK
|
|
|
|
case NET_LL_LOOPBACK:
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:Local Loopback",
|
|
|
|
dev->d_ifname);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_SLIP
|
|
|
|
case NET_LL_SLIP:
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:SLIP", dev->d_ifname);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_PPP
|
|
|
|
case NET_LL_PPP:
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:P-t-P", dev->d_ifname);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_TUN
|
|
|
|
case NET_LL_TUN:
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:TUN", dev->d_ifname);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"%s\tLink encap:UNSPEC", dev->d_ifname);
|
|
|
|
}
|
|
|
|
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
2023-04-27 04:17:53 +02:00
|
|
|
" at %s", status);
|
|
|
|
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
" mtu %d\n", (dev->d_pktsize - dev->d_llhdrlen));
|
2015-11-27 23:39:14 +01:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-05-18 09:30:12 +02:00
|
|
|
* Name: netprocfs_inet4addresses
|
2015-11-27 23:39:14 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-18 09:30:12 +02:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
static int netprocfs_inet4addresses(FAR struct netprocfs_file_s *netfile)
|
2015-11-27 23:39:14 +01:00
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
struct in_addr addr;
|
|
|
|
int len = 0;
|
2022-08-01 11:17:23 +02:00
|
|
|
char inetaddr[INET_ADDRSTRLEN];
|
2015-11-27 23:39:14 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
|
|
|
|
/* Show the IPv4 address */
|
|
|
|
|
|
|
|
addr.s_addr = dev->d_ipaddr;
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
2022-08-01 11:17:23 +02:00
|
|
|
"\tinet addr:%s ", inet_ntoa_r(addr, inetaddr,
|
|
|
|
sizeof(inetaddr)));
|
2024-01-22 03:20:46 +01:00
|
|
|
#ifdef CONFIG_NET_ARP_ACD
|
|
|
|
if (dev->d_acd.conflict_flag == ARP_ACD_ADDRESS_CONFLICT)
|
|
|
|
{
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
|
|
|
"(conflict!) ");
|
|
|
|
}
|
|
|
|
#endif
|
2015-11-27 23:39:14 +01:00
|
|
|
|
|
|
|
/* Show the IPv4 default router address */
|
|
|
|
|
|
|
|
addr.s_addr = dev->d_draddr;
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
2022-08-01 11:17:23 +02:00
|
|
|
"DRaddr:%s ", inet_ntoa_r(addr, inetaddr,
|
|
|
|
sizeof(inetaddr)));
|
2015-11-27 23:39:14 +01:00
|
|
|
|
|
|
|
/* Show the IPv4 network mask */
|
|
|
|
|
|
|
|
addr.s_addr = dev->d_netmask;
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
2017-07-08 19:39:59 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
"Mask:%s\n", /* IPv6 addresses will follow */
|
|
|
|
#else
|
|
|
|
"Mask:%s\n\n", /* Double space at end of device description */
|
|
|
|
#endif
|
2022-08-01 11:17:23 +02:00
|
|
|
inet_ntoa_r(addr, inetaddr, sizeof(inetaddr)));
|
2017-07-08 19:39:59 +02:00
|
|
|
|
2017-05-18 09:30:12 +02:00
|
|
|
return len;
|
|
|
|
}
|
2015-11-27 23:39:14 +01:00
|
|
|
#endif
|
|
|
|
|
2017-05-18 09:30:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_inet6address
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-27 23:39:14 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-05-18 09:30:12 +02:00
|
|
|
static int netprocfs_inet6address(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
char addrstr[INET6_ADDRSTRLEN];
|
|
|
|
uint8_t preflen;
|
2023-10-23 11:18:09 +02:00
|
|
|
int idx = netfile->lineno - NETSTAT_IPv6_IDX;
|
2017-05-18 09:30:12 +02:00
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
|
2023-10-23 11:18:09 +02:00
|
|
|
#ifdef CONFIG_NETDEV_MULTIPLE_IPv6
|
|
|
|
if (net_ipv6addr_cmp(dev->d_ipv6[idx].addr, g_ipv6_unspecaddr))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-11-27 23:39:14 +01:00
|
|
|
/* Convert the 128 network mask to a human friendly prefix length */
|
|
|
|
|
2023-10-23 11:18:09 +02:00
|
|
|
preflen = net_ipv6_mask2pref(dev->d_ipv6[idx].mask);
|
2015-11-27 23:39:14 +01:00
|
|
|
|
|
|
|
/* Show the assigned IPv6 address */
|
|
|
|
|
2023-10-23 11:18:09 +02:00
|
|
|
if (inet_ntop(AF_INET6, dev->d_ipv6[idx].addr, addrstr, INET6_ADDRSTRLEN))
|
2015-11-27 23:39:14 +01:00
|
|
|
{
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
2017-07-08 19:39:59 +02:00
|
|
|
"\tinet6 addr: %s/%d\n", addrstr, preflen);
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:06:21 +02:00
|
|
|
return len;
|
|
|
|
}
|
2017-05-18 09:30:12 +02:00
|
|
|
#endif
|
2017-04-09 19:06:21 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-05-18 09:30:12 +02:00
|
|
|
* Name: netprocfs_inet6draddress
|
2017-04-09 19:06:21 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-05-18 09:30:12 +02:00
|
|
|
static int netprocfs_inet6draddress(FAR struct netprocfs_file_s *netfile)
|
2017-04-09 19:06:21 +02:00
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
char addrstr[INET6_ADDRSTRLEN];
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
|
|
|
|
/* Show the IPv6 default router address */
|
2015-11-27 23:39:14 +01:00
|
|
|
|
|
|
|
if (inet_ntop(AF_INET6, dev->d_ipv6draddr, addrstr, INET6_ADDRSTRLEN))
|
|
|
|
{
|
|
|
|
len += snprintf(&netfile->line[len], NET_LINELEN - len,
|
2023-10-23 11:18:09 +02:00
|
|
|
"\tinet6 DRaddr: %s\n\n", addrstr);
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2017-04-09 19:06:21 +02:00
|
|
|
#endif
|
2015-11-27 23:39:14 +01:00
|
|
|
|
2017-08-21 17:31:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_blank_line
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if !defined(CONFIG_NET_IPv4) && !defined(CONFIG_NET_IPv6)
|
|
|
|
static int netprocfs_blank_line(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
netfile->line[0] = '\n';
|
|
|
|
netfile->line[1] = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-11-27 23:39:14 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_rxstatistics_header
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
2020-11-13 06:57:26 +01:00
|
|
|
static int netprocfs_rxstatistics_header(
|
|
|
|
FAR struct netprocfs_file_s *netfile)
|
2015-11-27 23:39:14 +01:00
|
|
|
{
|
|
|
|
DEBUGASSERT(netfile != NULL);
|
2024-09-02 09:51:53 +02:00
|
|
|
return snprintf(netfile->line, NET_LINELEN , "\tRX: %-8s %-8s %-8s %-8s\n",
|
|
|
|
"Received", "Fragment", "Errors", "Bytes");
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_rxstatistics
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
|
|
|
static int netprocfs_rxstatistics(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
FAR struct netdev_statistics_s *stats;
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
stats = &dev->d_statistics;
|
|
|
|
|
2024-09-02 09:51:53 +02:00
|
|
|
return snprintf(netfile->line, NET_LINELEN, \
|
|
|
|
"\t %08lx %08lx %08lx %-16llx\n",
|
2015-11-27 23:39:14 +01:00
|
|
|
(unsigned long)stats->rx_packets,
|
|
|
|
(unsigned long)stats->rx_fragments,
|
2024-09-02 09:51:53 +02:00
|
|
|
(unsigned long)stats->rx_errors,
|
|
|
|
(unsigned long long)stats->rx_bytes);
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_rxpackets_header
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
|
|
|
static int netprocfs_rxpackets_header(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
FAR char *fmt;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL);
|
|
|
|
|
|
|
|
fmt = "\t "
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
"%-8s "
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
"%-8s "
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
"%-8s "
|
|
|
|
#endif
|
|
|
|
"%-8s\n";
|
|
|
|
|
|
|
|
return snprintf(netfile->line, NET_LINELEN, fmt
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
, "IPv4"
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
, "IPv6"
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
, "ARP"
|
|
|
|
#endif
|
|
|
|
, "Dropped");
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_rxpackets
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
|
|
|
static int netprocfs_rxpackets(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
FAR struct netdev_statistics_s *stats;
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR char *fmt;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
stats = &dev->d_statistics;
|
|
|
|
|
|
|
|
fmt = "\t "
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
"%08lx "
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
"%08lx "
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
"%08lx "
|
|
|
|
#endif
|
|
|
|
"%08lx\n";
|
|
|
|
|
|
|
|
return snprintf(netfile->line, NET_LINELEN, fmt
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
, (unsigned long)stats->rx_ipv4
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
, (unsigned long)stats->rx_ipv6
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
|
|
|
, (unsigned long)stats->rx_arp
|
|
|
|
#endif
|
|
|
|
, (unsigned long)stats->rx_dropped);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_txstatistics_header
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
2020-11-13 06:57:26 +01:00
|
|
|
static int netprocfs_txstatistics_header(
|
|
|
|
FAR struct netprocfs_file_s *netfile)
|
2015-11-27 23:39:14 +01:00
|
|
|
{
|
|
|
|
DEBUGASSERT(netfile != NULL);
|
|
|
|
|
2024-09-02 09:51:53 +02:00
|
|
|
return snprintf(netfile->line, NET_LINELEN,
|
|
|
|
"\tTX: %-8s %-8s %-8s %-8s %-8s\n",
|
|
|
|
"Queued", "Sent", "Errors", "Timeouts", "Bytes");
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_txstatistics
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
|
|
|
static int netprocfs_txstatistics(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
FAR struct netdev_statistics_s *stats;
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
stats = &dev->d_statistics;
|
|
|
|
|
2020-11-13 06:57:26 +01:00
|
|
|
return snprintf(netfile->line, NET_LINELEN,
|
2024-09-02 09:51:53 +02:00
|
|
|
"\t %08lx %08lx %08lx %08lx %-16llx \n",
|
2015-11-27 23:39:14 +01:00
|
|
|
(unsigned long)stats->tx_packets,
|
|
|
|
(unsigned long)stats->tx_done,
|
|
|
|
(unsigned long)stats->tx_errors,
|
2024-09-02 09:51:53 +02:00
|
|
|
(unsigned long)stats->tx_timeouts,
|
|
|
|
(unsigned long long)stats->tx_bytes);
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_errors
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_STATISTICS
|
|
|
|
static int netprocfs_errors(FAR struct netprocfs_file_s *netfile)
|
|
|
|
{
|
|
|
|
FAR struct netdev_statistics_s *stats;
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
|
|
|
|
DEBUGASSERT(netfile != NULL && netfile->dev != NULL);
|
|
|
|
dev = netfile->dev;
|
|
|
|
stats = &dev->d_statistics;
|
|
|
|
|
2020-11-13 06:58:29 +01:00
|
|
|
return snprintf(netfile->line, NET_LINELEN,
|
|
|
|
"\tTotal Errors: %08" PRIx32 "\n\n",
|
2020-01-13 23:41:09 +01:00
|
|
|
stats->errors);
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NETDEV_STATISTICS */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netprocfs_read_devstats
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read and format network device statistics.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - A reference to the network procfs file structure
|
|
|
|
* buffer - The user-provided buffer into which device 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_devstats(FAR struct netprocfs_file_s *priv,
|
|
|
|
FAR char *buffer, size_t buflen)
|
|
|
|
{
|
2017-08-11 22:50:39 +02:00
|
|
|
return netprocfs_read_linegen(priv, buffer, buflen, g_netstat_linegen,
|
|
|
|
NSTAT_LINES);
|
2015-11-27 23:39:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_PROCFS &&
|
|
|
|
* !CONFIG_FS_PROCFS_EXCLUDE_NET */
|