From 54d82b0699a07b1af32a46e229ed37331e38d3a2 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Fri, 22 Apr 2022 10:30:52 +0200 Subject: [PATCH] ip: Add a new family of commands, "stats" Add a core of a new frontend tool for interfacing with the RTM_*STATS family of messages. The following patches will add subcommands for showing and setting individual statistics suites. Note that in this patch, "ip stats" is made to be an invalid command line. This will be changed in later patches to default to "show" when that is introduced. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Signed-off-by: David Ahern --- ip/Makefile | 3 ++- ip/ip.c | 1 + ip/ip_common.h | 1 + ip/ipstats.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ip/ipstats.c diff --git a/ip/Makefile b/ip/Makefile index e06a7c846..6c2e07204 100644 --- a/ip/Makefile +++ b/ip/Makefile @@ -12,7 +12,8 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o ipmacsec.o ipila.o \ ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \ ipnexthop.o ipmptcp.o iplink_bareudp.o iplink_wwan.o ipioam6.o \ - iplink_amt.o iplink_batadv.o iplink_gtp.o iplink_virt_wifi.o + iplink_amt.o iplink_batadv.o iplink_gtp.o iplink_virt_wifi.o \ + ipstats.o RTMONOBJ=rtmon.o diff --git a/ip/ip.c b/ip/ip.c index c784f8191..82282babd 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -123,6 +123,7 @@ static const struct cmd { { "mptcp", do_mptcp }, { "ioam", do_ioam6 }, { "help", do_help }, + { "stats", do_ipstats }, { 0 } }; diff --git a/ip/ip_common.h b/ip/ip_common.h index 51a7edc71..53866d7ac 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -90,6 +90,7 @@ int do_seg6(int argc, char **argv); int do_ipnh(int argc, char **argv); int do_mptcp(int argc, char **argv); int do_ioam6(int argc, char **argv); +int do_ipstats(int argc, char **argv); int iplink_get(char *name, __u32 filt_mask); int iplink_ifla_xstats(int argc, char **argv); diff --git a/ip/ipstats.c b/ip/ipstats.c new file mode 100644 index 000000000..099e18a21 --- /dev/null +++ b/ip/ipstats.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include "utils.h" +#include "ip_common.h" + +static int do_help(void) +{ + fprintf(stderr, + "Usage: ip stats help\n" + ); + + return 0; +} + +int do_ipstats(int argc, char **argv) +{ + int rc; + + if (argc == 0) { + do_help(); + rc = -1; + } else if (strcmp(*argv, "help") == 0) { + do_help(); + rc = 0; + } else { + fprintf(stderr, "Command \"%s\" is unknown, try \"ip stats help\".\n", + *argv); + rc = -1; + } + + return rc; +} -- 2.47.2