]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipstats: Add a group "afstats", subgroup "mpls"
authorPetr Machata <petrm@nvidia.com>
Mon, 9 May 2022 13:59:56 +0000 (15:59 +0200)
committerDavid Ahern <dsahern@kernel.org>
Thu, 12 May 2022 17:08:10 +0000 (11:08 -0600)
Add a new group, "afstats", for showing counters from the
IFLA_STATS_AF_SPEC nest, and a subgroup "mpls" for the AF_MPLS
specifically.

For example:

 # ip -n ns0-NrdgY9sx stats show dev veth01 group afstats
 3: veth01: group afstats subgroup mpls
     RX: bytes packets errors dropped noroute
             0       0      0       0       0
     TX: bytes packets errors dropped
           108       1      0       0

Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/iplink.c
ip/ipstats.c

index c3ff8a5a224655e4801dc8fd943a14ba49e53e2b..d666234335b62e56e06a9e2c7d3ed8d5925078d5 100644 (file)
@@ -1555,7 +1555,6 @@ void print_mpls_link_stats(FILE *fp, const struct mpls_link_stats *stats,
        print_num(fp, cols[1], stats->tx_packets);
        print_num(fp, cols[2], stats->tx_errors);
        print_num(fp, cols[3], stats->tx_dropped);
-       fprintf(fp, "\n");
 }
 
 static void print_mpls_stats(FILE *fp, struct rtattr *attr)
@@ -1571,6 +1570,7 @@ static void print_mpls_stats(FILE *fp, struct rtattr *attr)
        stats = RTA_DATA(mrtb[MPLS_STATS_LINK]);
        fprintf(fp, "    mpls:\n");
        print_mpls_link_stats(fp, stats, "        ");
+       fprintf(fp, "\n");
 }
 
 static void print_af_stats_attr(FILE *fp, int ifindex, struct rtattr *attr)
index 5b9689f43cd58fb3990833c47d2ce75ba170ee84..5b9333e3e39f6e5f70d6beb13dcdd56fff097213 100644 (file)
@@ -589,9 +589,63 @@ static const struct ipstats_stat_desc ipstats_stat_desc_toplev_link = {
        .show = &ipstats_stat_desc_show_link,
 };
 
+static const struct ipstats_stat_desc ipstats_stat_desc_afstats_group;
+
+static void
+ipstats_stat_desc_pack_afstats(struct ipstats_stat_dump_filters *filters,
+                              const struct ipstats_stat_desc *desc)
+{
+       ipstats_stat_desc_enable_bit(filters, IFLA_STATS_AF_SPEC, 0);
+}
+
+static int
+ipstats_stat_desc_show_afstats_mpls(struct ipstats_stat_show_attrs *attrs,
+                                   const struct ipstats_stat_desc *desc)
+{
+       struct rtattr *mrtb[MPLS_STATS_MAX+1];
+       struct mpls_link_stats stats;
+       const struct rtattr *at;
+       int err;
+
+       at = ipstats_stat_show_get_attr(attrs, IFLA_STATS_AF_SPEC,
+                                       AF_MPLS, &err);
+       if (at == NULL)
+               return err;
+
+       parse_rtattr_nested(mrtb, MPLS_STATS_MAX, at);
+       if (mrtb[MPLS_STATS_LINK] == NULL)
+               return -ENOENT;
+
+       IPSTATS_RTA_PAYLOAD(stats, mrtb[MPLS_STATS_LINK]);
+
+       print_nl();
+       open_json_object("mpls_stats");
+       print_mpls_link_stats(stdout, &stats, "    ");
+       close_json_object();
+       return 0;
+}
+
+static const struct ipstats_stat_desc ipstats_stat_desc_afstats_mpls = {
+       .name = "mpls",
+       .kind = IPSTATS_STAT_DESC_KIND_LEAF,
+       .pack = &ipstats_stat_desc_pack_afstats,
+       .show = &ipstats_stat_desc_show_afstats_mpls,
+};
+
+static const struct ipstats_stat_desc *ipstats_stat_desc_afstats_subs[] = {
+       &ipstats_stat_desc_afstats_mpls,
+};
+
+static const struct ipstats_stat_desc ipstats_stat_desc_afstats_group = {
+       .name = "afstats",
+       .kind = IPSTATS_STAT_DESC_KIND_GROUP,
+       .subs = ipstats_stat_desc_afstats_subs,
+       .nsubs = ARRAY_SIZE(ipstats_stat_desc_afstats_subs),
+};
 static const struct ipstats_stat_desc *ipstats_stat_desc_toplev_subs[] = {
        &ipstats_stat_desc_toplev_link,
        &ipstats_stat_desc_offload_group,
+       &ipstats_stat_desc_afstats_group,
 };
 
 static const struct ipstats_stat_desc ipstats_stat_desc_toplev_group = {