]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipmonitor: Add monitoring support for stats events
authorPetr Machata <petrm@nvidia.com>
Fri, 22 Apr 2022 08:30:59 +0000 (10:30 +0200)
committerDavid Ahern <dsahern@kernel.org>
Thu, 28 Apr 2022 02:12:48 +0000 (20:12 -0600)
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@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ip_common.h
ip/ipmonitor.c
ip/ipstats.c

index 8b0a64262ffd2c6f7e0971be8bacfcdd15243315..9eeeb38772b429986a6b4f3e13189454fee97014 100644 (file)
@@ -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);
index 0badda4e7812a04d07570991f0814a2497c8928a..a4326d2ae3aad9c9b8b7fa0b2f6481a1badad919 100644 (file)
@@ -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);
 
index 29ca0731843cec986279d95dcb2d2c55a1eb59fe..39ddca01f3ef011032b6afba31d85ed7124dda7f 100644 (file)
@@ -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;
+}