[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ae995f60da050d62842b4657e160be47b0786678.1650615982.git.petrm@nvidia.com>
Date: Fri, 22 Apr 2022 10:30:59 +0200
From: Petr Machata <petrm@...dia.com>
To: <netdev@...r.kernel.org>
CC: David Ahern <dsahern@...il.com>,
Stephen Hemminger <stephen@...workplumber.org>,
Ido Schimmel <idosch@...dia.com>,
Petr Machata <petrm@...dia.com>
Subject: [PATCH iproute2-next 10/11] ipmonitor: Add monitoring support for stats events
Toggles and offloads of HW statistics cause emission of and RTM_NEWSTATS
event. Add support to "ip monitor" for these events.
Signed-off-by: Petr Machata <petrm@...dia.com>
Reviewed-by: Ido Schimmel <idosch@...dia.com>
---
ip/ip_common.h | 1 +
ip/ipmonitor.c | 16 +++++++++++++++-
ip/ipstats.c | 20 ++++++++++++++++++++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/ip/ip_common.h b/ip/ip_common.h
index 8b0a6426..9eeeb387 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -57,6 +57,7 @@ int print_nexthop_bucket(struct nlmsghdr *n, void *arg);
void netns_map_init(void);
void netns_nsid_socket_init(void);
int print_nsid(struct nlmsghdr *n, void *arg);
+int ipstats_print(struct nlmsghdr *n, void *arg);
char *get_name_from_nsid(int nsid);
int get_netnsid_from_name(const char *name);
int set_netnsid_from_name(const char *name, int nsid);
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 0badda4e..a4326d2a 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -34,7 +34,7 @@ static void usage(void)
"Usage: ip monitor [ all | OBJECTS ] [ FILE ] [ label ] [ all-nsid ]\n"
" [ dev DEVICE ]\n"
"OBJECTS := address | link | mroute | neigh | netconf |\n"
- " nexthop | nsid | prefix | route | rule\n"
+ " nexthop | nsid | prefix | route | rule | stats\n"
"FILE := file FILENAME\n");
exit(-1);
}
@@ -158,6 +158,11 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
print_nsid(n, arg);
return 0;
+ case RTM_NEWSTATS:
+ print_headers(fp, "[STATS]", ctrl);
+ ipstats_print(n, arg);
+ return 0;
+
case NLMSG_ERROR:
case NLMSG_NOOP:
case NLMSG_DONE:
@@ -185,6 +190,7 @@ int do_ipmonitor(int argc, char **argv)
int lprefix = 0;
int lneigh = 0;
int lnetconf = 0;
+ int lstats = 0;
int lrule = 0;
int lnsid = 0;
int ifindex = 0;
@@ -253,6 +259,9 @@ int do_ipmonitor(int argc, char **argv)
} else if (matches(*argv, "nexthop") == 0) {
lnexthop = 1;
groups = 0;
+ } else if (strcmp(*argv, "stats") == 0) {
+ lstats = 1;
+ groups = 0;
} else if (strcmp(*argv, "all") == 0) {
prefix_banner = 1;
} else if (matches(*argv, "all-nsid") == 0) {
@@ -349,6 +358,11 @@ int do_ipmonitor(int argc, char **argv)
exit(1);
}
+ if (lstats && rtnl_add_nl_group(&rth, RTNLGRP_STATS) < 0) {
+ fprintf(stderr, "Failed to add stats group to list\n");
+ exit(1);
+ }
+
if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)
exit(1);
diff --git a/ip/ipstats.c b/ip/ipstats.c
index 29ca0731..39ddca01 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -1219,3 +1219,23 @@ int do_ipstats(int argc, char **argv)
return rc;
}
+
+int ipstats_print(struct nlmsghdr *n, void *arg)
+{
+ struct ipstats_stat_enabled_one one = {
+ .desc = &ipstats_stat_desc_offload_hw_s_info,
+ };
+ struct ipstats_stat_enabled enabled = {
+ .enabled = &one,
+ .nenabled = 1,
+ };
+ FILE *fp = arg;
+ int rc;
+
+ rc = ipstats_process_ifsm(n, &enabled);
+ if (rc)
+ return rc;
+
+ fflush(fp);
+ return 0;
+}
--
2.31.1
Powered by blists - more mailing lists