Subject: [PATCH iproute2-next 00/11] ip stats: A new front-end for RTM_GETSTATS / RTM_SETSTATS

From: Petr Machata <[email-masked]>
Date: Fri, 22 Apr 2022 10:30:49 +0200

A new rtnetlink message, RTM_SETSTATS, has been added recently in kernel
commit ca0a53dcec94 ("Merge branch 'net-hw-counters-for-soft-devices'").

At the same time, RTM_GETSTATS has been around for a while. The users of
this API are spread in a couple different places: "ip link xstats" reads
stats from the IFLA_STATS_LINK_XSTATS and _XSTATS_SLAVE subgroups, "ip
link afstats" then reads IFLA_STATS_AF_SPEC.

Finally, to read IFLA_STATS_LINK_OFFLOAD_XSTATS, one would use ifstats.
This does not seem to be a good fit for IFLA_OFFLOAD_XSTATS_HW_S_INFO in
particular.

The obvious place to expose all these offload stats suites would be
under a new link subcommand "ip link offload_xstats", or similar, which
would then have syntax for both showing stats and setting them.

However, this looks like a good opportunity to introduce a new top-level
command, "ip stats", that would be the go-to place to access anything
backed by RTM_GETSTATS and RTM_SETSTATS.

This patchset therefore does the following:

- It adds the new "stats" infrastructure

- It adds specifically the ability to toggle and show the suites that
  were recently added to Linux, IFLA_OFFLOAD_XSTATS_HW_S_INFO and
  IFLA_OFFLOAD_XSTATS_L3_STATS.

- It adds support to dump IFLA_OFFLOAD_XSTATS_CPU_HIT, which was not
  available under "ip" at all.

- Does all this in a way that is easy to extend for new stats suites.

The patchset proceeds as follows:

- Patches #1 and #2 lay some groundwork and tweak existing code.

- Patch #3 adds the shell of the new "ip stats" command.

- Patch #4 adds "ip stats set" and the ability to toggle l3_stats in
  particular.

- Patch #5 adds "ip stats show", but no actual stats suites.

- Patches #6-#9 add support for showing individual stats suites:
  respectively, IFLA_STATS_LINK_64, IFLA_OFFLOAD_XSTATS_CPU_HIT,
  IFLA_OFFLOAD_XSTATS_HW_S_INFO and IFLA_OFFLOAD_XSTATS_L3_STATS.

- Patch #10 adds support for monitoring stats events to "ip monitor".

- Patch #11 adds man page verbiage for the above.

The plan is to contribute support for afstats and xstats in a follow-up
patch set.

Petr Machata (11):
  libnetlink: Add filtering to rtnl_statsdump_req_filter()
  ip: Publish functions for stats formatting
  ip: Add a new family of commands, "stats"
  ipstats: Add a "set" command
  ipstats: Add a shell of "show" command
  ipstats: Add a group "link"
  ipstats: Add a group "offload", subgroup "cpu_hit"
  ipstats: Add offload subgroup "hw_stats_info"
  ipstats: Add offload subgroup "l3_stats"
  ipmonitor: Add monitoring support for stats events
  man: Add man pages for the "stats" functions

 bridge/vlan.c         |    6 +-
 include/libnetlink.h  |   11 +-
 ip/Makefile           |    3 +-
 ip/ip.c               |    1 +
 ip/ip_common.h        |   31 +
 ip/ipaddress.c        |   33 +-
 ip/iplink.c           |    3 +-
 ip/iplink_xstats.c    |    3 +-
 ip/ipmonitor.c        |   16 +-
 ip/ipstats.c          | 1241 +++++++++++++++++++++++++++++++++++++++++
 lib/libnetlink.c      |   19 +-
 man/man8/ip-monitor.8 |    2 +-
 man/man8/ip-stats.8   |  160 ++++++
 man/man8/ip.8         |    7 +-
 misc/ifstat.c         |    2 +-
 15 files changed, 1512 insertions(+), 26 deletions(-)
 create mode 100644 ip/ipstats.c
 create mode 100644 man/man8/ip-stats.8

-- 
2.31.1