You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/12 05:38:42 UTC
(nuttx-apps) branch master updated (7bf20f1a8 -> 1f51bfe64)
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
from 7bf20f1a8 [wireless] add set/get pmksa api for fast-auth
new e25f89d2d app/netstatistics: Add net statistics api for user
new 1f51bfe64 apps/ipforward: fix ci check failure
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
examples/ipforward/ipforward.c | 18 ++--
include/netutils/netlib.h | 6 ++
netutils/netlib/CMakeLists.txt | 4 +
netutils/netlib/Makefile | 4 +
netutils/netlib/netlib_getifstatistics.c | 152 +++++++++++++++++++++++++++++++
5 files changed, 176 insertions(+), 8 deletions(-)
create mode 100644 netutils/netlib/netlib_getifstatistics.c
(nuttx-apps) 02/02: apps/ipforward: fix ci check failure
Posted by xi...@apache.org.
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-apps.git
commit 1f51bfe64dfa931d97137b0c7561c053e1d6078d
Author: meijian <me...@xiaomi.com>
AuthorDate: Thu Sep 12 11:12:43 2024 +0800
apps/ipforward: fix ci check failure
note: static declaration of 'chksum' follows non-static declaration
Signed-off-by: meijian <me...@xiaomi.com>
---
examples/ipforward/ipforward.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/examples/ipforward/ipforward.c b/examples/ipforward/ipforward.c
index 712c63d2b..45fa3e790 100644
--- a/examples/ipforward/ipforward.c
+++ b/examples/ipforward/ipforward.c
@@ -289,10 +289,11 @@ static int ipfwd_netconfig(FAR struct ipfwd_tun_s *tun, IPADDR_TYPE ipaddr,
}
/****************************************************************************
- * Name: Checksums
+ * Name: check_sum
****************************************************************************/
-static uint16_t chksum(uint16_t sum, FAR const uint8_t *data, uint16_t len)
+static uint16_t check_sum(uint16_t sum, FAR const uint8_t *data,
+ uint16_t len)
{
FAR const uint8_t *dataptr;
FAR const uint8_t *last_byte;
@@ -335,7 +336,7 @@ static uint16_t ipv4_chksum(FAR const uint8_t *buffer)
{
uint16_t sum;
- sum = chksum(0, buffer, IPv4_HDRLEN);
+ sum = check_sum(0, buffer, IPv4_HDRLEN);
return (sum == 0) ? 0xffff : htons(sum);
}
#endif
@@ -362,12 +363,12 @@ static uint16_t common_chksum(FAR uint8_t *buffer, uint8_t proto)
/* Sum IP source and destination addresses. */
- sum = chksum(sum, (FAR uint8_t *)&ipv6->srcipaddr,
- 2 * sizeof(net_ipv6addr_t));
+ sum = check_sum(sum, (FAR uint8_t *)&ipv6->srcipaddr,
+ 2 * sizeof(net_ipv6addr_t));
/* Sum IP payload data. */
- sum = chksum(sum, &buffer[IPv6_HDRLEN], upperlen);
+ sum = check_sum(sum, &buffer[IPv6_HDRLEN], upperlen);
return (sum == 0) ? 0xffff : htons(sum);
#else
FAR struct ipv4_hdr_s *ipv4 = (FAR struct ipv4_hdr_s *)buffer;
@@ -389,11 +390,12 @@ static uint16_t common_chksum(FAR uint8_t *buffer, uint8_t proto)
/* Sum IP source and destination addresses. */
- sum = chksum(sum, (FAR uint8_t *)&ipv4->srcipaddr, 2 * sizeof(in_addr_t));
+ sum = check_sum(sum, (FAR uint8_t *)&ipv4->srcipaddr,
+ 2 * sizeof(in_addr_t));
/* Sum IP payload data. */
- sum = chksum(sum, &buffer[IPv4_HDRLEN], upperlen);
+ sum = check_sum(sum, &buffer[IPv4_HDRLEN], upperlen);
return (sum == 0) ? 0xffff : htons(sum);
#endif
}
(nuttx-apps) 01/02: app/netstatistics: Add net statistics api for user
Posted by xi...@apache.org.
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-apps.git
commit e25f89d2d6ec3f588557aa0adc9f52324bbd7a01
Author: meijian <me...@xiaomi.com>
AuthorDate: Fri Sep 6 15:22:35 2024 +0800
app/netstatistics: Add net statistics api for user
Signed-off-by: meijian <me...@xiaomi.com>
---
include/netutils/netlib.h | 6 ++
netutils/netlib/CMakeLists.txt | 4 +
netutils/netlib/Makefile | 4 +
netutils/netlib/netlib_getifstatistics.c | 152 +++++++++++++++++++++++++++++++
4 files changed, 166 insertions(+)
diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h
index acab1ba01..b92c95696 100644
--- a/include/netutils/netlib.h
+++ b/include/netutils/netlib.h
@@ -58,6 +58,7 @@
#include <net/if.h>
#include <netinet/in.h>
+#include <nuttx/net/netdev.h>
#include <nuttx/net/netconfig.h>
/****************************************************************************
@@ -495,6 +496,11 @@ int netlib_set_ipv6dnsaddr(FAR const struct in6_addr *inaddr);
int netlib_set_mtu(FAR const char *ifname, int mtu);
+#if defined(CONFIG_NETDEV_STATISTICS)
+int netlib_getifstatistics(FAR const char *ifname,
+ FAR struct netdev_statistics_s *stat);
+#endif
+
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/netutils/netlib/CMakeLists.txt b/netutils/netlib/CMakeLists.txt
index 87958ffd6..068fa68fe 100644
--- a/netutils/netlib/CMakeLists.txt
+++ b/netutils/netlib/CMakeLists.txt
@@ -123,6 +123,10 @@ if(CONFIG_NETUTILS_NETLIB)
netlib_eaddrconv.c)
endif()
+ if(CONFIG_NETDEV_STATISTICS)
+ list(APPEND SRCS netlib_getifstatistics.c)
+ endif()
+
if(CONFIG_WIRELESS_PKTRADIO)
list(APPEND SRCS netlib_getproperties.c netlib_getnodeaddr.c
netlib_setnodeaddr.c)
diff --git a/netutils/netlib/Makefile b/netutils/netlib/Makefile
index a088160e6..dc8be99d2 100644
--- a/netutils/netlib/Makefile
+++ b/netutils/netlib/Makefile
@@ -91,6 +91,10 @@ CSRCS += netlib_getroute.c
endif
endif
+ifeq ($(CONFIG_NETDEV_STATISTICS),y)
+CSRCS += netlib_getifstatistics.c
+endif
+
# Netfilter connection support
ifeq ($(CONFIG_NETLINK_NETFILTER),y)
diff --git a/netutils/netlib/netlib_getifstatistics.c b/netutils/netlib/netlib_getifstatistics.c
new file mode 100644
index 000000000..a6ac33e6c
--- /dev/null
+++ b/netutils/netlib/netlib_getifstatistics.c
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * apps/netutils/netlib/netlib_getifstatistics.c
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <sys/types.h>
+
+#include "netutils/netlib.h"
+
+#ifdef CONFIG_NETDEV_STATISTICS
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Determines the size of an intermediate buffer that must be large enough
+ * to handle the longest line generated by this logic.
+ */
+
+#define PROCFS_LINELEN 80
+#define PROCFS_NET_PATH "/proc/net/"
+
+/* The form of the entry from the netstat file:
+ *
+ * wlan0 Link encap:Ethernet HWaddr 42:37:46:02:16:07 at UP mtu 1500
+ * inet addr:10.0.1.2 DRaddr:10.0.1.1 Mask:255.255.255.0
+ * inet6 DRaddr: ::
+ *
+ * RX: Received Fragment Errors Bytes
+ * 000008c1 00000000 00000000 331ca8
+ * IPv4 IPv6 ARP Dropped
+ * 000008a7 00000018 00000002 00000000
+ * TX: Queued Sent Errors Timeouts Bytes
+ * 00000973 00000973 00000000 00000000 1b8d3
+ * Total Errors: 00000000
+ */
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: netlib_getifstatistics
+ *
+ * Description:
+ * Read the DEV RX/TX statistics.
+ *
+ * Input Parameters:
+ * ifname - The interface to read.
+ * stat - The pointer to return dev statistics.
+ *
+ * Returned Value:
+ * 0 on success. A negated errno value is returned
+ * on any failure.
+ ****************************************************************************/
+
+int netlib_getifstatistics(FAR const char *ifname,
+ FAR struct netdev_statistics_s *stat)
+{
+ FAR FILE *stream;
+ char path[32];
+ char line[PROCFS_LINELEN];
+ int ret = OK;
+
+ snprintf(path, sizeof(path), "%s%s", PROCFS_NET_PATH, ifname);
+ ninfo("get statistics from %s \n", path);
+
+ stream = fopen(path, "r");
+ if (stream == NULL)
+ {
+ fprintf(stderr, "ERROR: Failed to open path:%s \n", path);
+ return -ENOTDIR;
+ }
+
+ while (fgets(line, sizeof(line), stream) != NULL)
+ {
+ /* Read RX header and next is the data */
+
+ if (strstr(line, "RX:") != NULL)
+ {
+ if (fgets(line, sizeof(line), stream) == NULL)
+ {
+ ret = -EINVAL;
+ break;
+ }
+
+ if (sscanf(line, "%" SCNx32 "%" SCNx32 "%" SCNx32 "%" SCNx64,
+ &stat->rx_packets,
+ &stat->rx_fragments,
+ &stat->rx_errors,
+ &stat->rx_bytes) <= 0)
+ {
+ ret = -EINVAL;
+ break;
+ }
+ }
+
+ /* Read TX header and next is the data */
+
+ if (strstr(line, "TX:") != NULL)
+ {
+ if (fgets(line, sizeof(line), stream) == NULL)
+ {
+ ret = -EINVAL;
+ break;
+ }
+
+ if (sscanf(line, "%" SCNx32 "%" SCNx32 "%" SCNx32 \
+ "%" SCNx32 "%" SCNx64,
+ &stat->tx_packets,
+ &stat->tx_done,
+ &stat->tx_errors,
+ &stat->tx_timeouts,
+ &stat->tx_bytes) <= 0)
+ {
+ ret = -EINVAL;
+ break;
+ }
+ }
+ }
+
+ fclose(stream);
+ return ret;
+}
+
+#endif /* CONFIG_NETDEV_STATISTICS */