iproute2: show counter of carrier on<->off transitions

This patch allows to display the current counter of carrier on<->off
transitions (IFLA_CARRIER_CHANGES, see kernel commit "expose number of
carrier on/off changes"):

  ip -s -s link show dev eth0
  32: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
    link/ether ................. brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    125552461  258881   0       0       0       10150
    RX errors: length  crc     frame   fifo    missed
               0        0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    40426119   224444   0       0       0       0
    TX errors: aborted fifo    window  heartbeat transns
               0        0       0       0        3

Tested:
  - kernel with patch "net-sysfs: expose number of carrier on/off
    changes": see "transns" column above
  - kernel wthout the patch: "transns" not displayed (as expected)

Signed-off-by: David Decotigny <decot@googlers.com>
This commit is contained in:
david decotigny 2014-05-05 20:38:18 -07:00 committed by Stephen Hemminger
parent ac74bd2a71
commit 30b557929f

View File

@ -313,7 +313,8 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
}
}
static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s) {
static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
const struct rtattr *carrier_changes) {
fprintf(fp, "%s", _SL_);
fprintf(fp, " RX: bytes packets errors dropped overrun mcast %s%s",
s->rx_compressed ? "compressed" : "", _SL_);
@ -352,16 +353,23 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s) {
(uint64_t)s->tx_compressed);
if (show_stats > 1) {
fprintf(fp, "%s", _SL_);
fprintf(fp, " TX errors: aborted fifo window heartbeat%s", _SL_);
fprintf(fp, " %-7"PRIu64" %-7"PRIu64" %-7"PRIu64" %-7"PRIu64"",
fprintf(fp, " TX errors: aborted fifo window heartbeat");
if (carrier_changes)
fprintf(fp, " transns");
fprintf(fp, _SL_);
fprintf(fp, " %-7"PRIu64" %-7"PRIu64" %-7"PRIu64" %-8"PRIu64"",
(uint64_t)s->tx_aborted_errors,
(uint64_t)s->tx_fifo_errors,
(uint64_t)s->tx_window_errors,
(uint64_t)s->tx_heartbeat_errors);
if (carrier_changes)
fprintf(fp, " %-7u",
*(uint32_t*)RTA_DATA(carrier_changes));
}
}
static void print_link_stats(FILE *fp, const struct rtnl_link_stats *s)
static void print_link_stats(FILE *fp, const struct rtnl_link_stats *s,
const struct rtattr *carrier_changes)
{
fprintf(fp, "%s", _SL_);
fprintf(fp, " RX: bytes packets errors dropped overrun mcast %s%s",
@ -394,13 +402,19 @@ static void print_link_stats(FILE *fp, const struct rtnl_link_stats *s)
fprintf(fp, " %-7u", s->tx_compressed);
if (show_stats > 1) {
fprintf(fp, "%s", _SL_);
fprintf(fp, " TX errors: aborted fifo window heartbeat%s", _SL_);
fprintf(fp, " %-7u %-7u %-7u %-7u",
fprintf(fp, " TX errors: aborted fifo window heartbeat");
if (carrier_changes)
fprintf(fp, " transns");
fprintf(fp, _SL_);
fprintf(fp, " %-7u %-7u %-7u %-8u",
s->tx_aborted_errors,
s->tx_fifo_errors,
s->tx_window_errors,
s->tx_heartbeat_errors
);
if (carrier_changes)
fprintf(fp, " %-7u",
*(uint32_t*)RTA_DATA(carrier_changes));
}
}
@ -522,9 +536,11 @@ int print_linkinfo(const struct sockaddr_nl *who,
if (do_link && show_stats) {
if (tb[IFLA_STATS64])
print_link_stats64(fp, RTA_DATA(tb[IFLA_STATS64]));
print_link_stats64(fp, RTA_DATA(tb[IFLA_STATS64]),
tb[IFLA_CARRIER_CHANGES]);
else if (tb[IFLA_STATS])
print_link_stats(fp, RTA_DATA(tb[IFLA_STATS]));
print_link_stats(fp, RTA_DATA(tb[IFLA_STATS]),
tb[IFLA_CARRIER_CHANGES]);
}
if (do_link && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) {