aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Machata <petrm@nvidia.com>2022-05-09 15:59:56 +0200
committerDavid Ahern <dsahern@kernel.org>2022-05-12 11:08:10 -0600
commit5ed8fd9d514422771d283607fac523d8baef1179 (patch)
tree155a0561896b8c8ceafbf2dee643ba903b26dbf8
parentdff392fd86ee6085737560c88875b35628888e91 (diff)
downloadiproute2-5ed8fd9d514422771d283607fac523d8baef1179.tar.gz
ipstats: Add a group "afstats", subgroup "mpls"
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>
-rw-r--r--ip/iplink.c2
-rw-r--r--ip/ipstats.c54
2 files changed, 55 insertions, 1 deletions
diff --git a/ip/iplink.c b/ip/iplink.c
index c3ff8a5a2..d66623433 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -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)
diff --git a/ip/ipstats.c b/ip/ipstats.c
index 5b9689f43..5b9333e3e 100644
--- a/ip/ipstats.c
+++ b/ip/ipstats.c
@@ -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 = {