Commit a258aeac authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

bonding: add support for xstats and export 3ad stats

This patch adds support for extended statistics (xstats) call to the
bonding. The first user would be the 3ad code which counts the following
events:
 - LACPDU Rx/Tx
 - LACPDU unknown type Rx
 - LACPDU illegal Rx
 - Marker Rx/Tx
 - Marker response Rx/Tx
 - Marker unknown type Rx

All of these are exported via netlink as separate attributes to be
easily extensible as we plan to add more in the future.
Similar to how the bridge and other xstats exports, the structure
inside is:
 [ IFLA_STATS_LINK_XSTATS ]
   -> [ LINK_XSTATS_TYPE_BOND ]
        -> [ BOND_XSTATS_3AD ]
             -> [ 3ad stats attributes ]

With this structure it's easy to add more stat types later.
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 267c095a
......@@ -31,6 +31,7 @@
#include <net/net_namespace.h>
#include <net/bonding.h>
#include <net/bond_3ad.h>
#include <net/netlink.h>
/* General definitions */
#define AD_SHORT_TIMEOUT 1
......@@ -2696,3 +2697,85 @@ void bond_3ad_update_lacp_rate(struct bonding *bond)
}
spin_unlock_bh(&bond->mode_lock);
}
void bond_3ad_stats_add(struct slave *slave, struct bond_3ad_stats *stats)
{
struct bond_3ad_stats *rstats = &SLAVE_AD_INFO(slave)->stats;
u64 stat;
atomic64_add(atomic64_read(&rstats->lacpdu_rx), &stats->lacpdu_rx);
atomic64_add(atomic64_read(&rstats->lacpdu_tx), &stats->lacpdu_tx);
stat = atomic64_read(&rstats->lacpdu_unknown_rx);
atomic64_add(stat, &stats->lacpdu_unknown_rx);
stat = atomic64_read(&rstats->lacpdu_illegal_rx);
atomic64_add(stat, &stats->lacpdu_illegal_rx);
atomic64_add(atomic64_read(&rstats->marker_rx), &stats->marker_rx);
atomic64_add(atomic64_read(&rstats->marker_tx), &stats->marker_tx);
stat = atomic64_read(&rstats->marker_resp_rx);
atomic64_add(stat, &stats->marker_resp_rx);
stat = atomic64_read(&rstats->marker_resp_tx);
atomic64_add(stat, &stats->marker_resp_tx);
stat = atomic64_read(&rstats->marker_unknown_rx);
atomic64_add(stat, &stats->marker_unknown_rx);
}
size_t bond_3ad_stats_size(void)
{
return nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_RX */
nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_TX */
nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_UNKNOWN_RX */
nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_LACPDU_ILLEGAL_RX */
nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RX */
nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_TX */
nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RESP_RX */
nla_total_size_64bit(sizeof(u64)) + /* BOND_3AD_STAT_MARKER_RESP_TX */
nla_total_size_64bit(sizeof(u64)); /* BOND_3AD_STAT_MARKER_UNKNOWN_RX */
}
int bond_3ad_stats_fill(struct sk_buff *skb, struct bond_3ad_stats *stats)
{
u64 val;
val = atomic64_read(&stats->lacpdu_rx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_RX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->lacpdu_tx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_TX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->lacpdu_unknown_rx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_UNKNOWN_RX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->lacpdu_illegal_rx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_LACPDU_ILLEGAL_RX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->marker_rx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->marker_tx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_TX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->marker_resp_rx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RESP_RX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->marker_resp_tx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_RESP_TX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
val = atomic64_read(&stats->marker_unknown_rx);
if (nla_put_u64_64bit(skb, BOND_3AD_STAT_MARKER_UNKNOWN_RX, val,
BOND_3AD_STAT_PAD))
return -EMSGSIZE;
return 0;
}
......@@ -675,6 +675,75 @@ static int bond_fill_info(struct sk_buff *skb,
return -EMSGSIZE;
}
static size_t bond_get_linkxstats_size(const struct net_device *dev, int attr)
{
switch (attr) {
case IFLA_STATS_LINK_XSTATS:
case IFLA_STATS_LINK_XSTATS_SLAVE:
break;
default:
return 0;
}
return bond_3ad_stats_size() + nla_total_size(0);
}
static int bond_fill_linkxstats(struct sk_buff *skb,
const struct net_device *dev,
int *prividx, int attr)
{
struct nlattr *nla __maybe_unused;
struct slave *slave = NULL;
struct nlattr *nest, *nest2;
struct bonding *bond;
switch (attr) {
case IFLA_STATS_LINK_XSTATS:
bond = netdev_priv(dev);
break;
case IFLA_STATS_LINK_XSTATS_SLAVE:
slave = bond_slave_get_rtnl(dev);
if (!slave)
return 0;
bond = slave->bond;
break;
default:
return -EINVAL;
}
nest = nla_nest_start(skb, LINK_XSTATS_TYPE_BOND);
if (!nest)
return -EMSGSIZE;
if (BOND_MODE(bond) == BOND_MODE_8023AD) {
struct bond_3ad_stats stats;
struct list_head *iter;
memset(&stats, 0, sizeof(stats));
if (slave) {
bond_3ad_stats_add(slave, &stats);
} else {
bond_for_each_slave(bond, slave, iter)
bond_3ad_stats_add(slave, &stats);
}
nest2 = nla_nest_start(skb, BOND_XSTATS_3AD);
if (!nest2) {
nla_nest_end(skb, nest);
return -EMSGSIZE;
}
if (bond_3ad_stats_fill(skb, &stats)) {
nla_nest_cancel(skb, nest2);
nla_nest_end(skb, nest);
return -EMSGSIZE;
}
nla_nest_end(skb, nest2);
}
nla_nest_end(skb, nest);
return 0;
}
struct rtnl_link_ops bond_link_ops __read_mostly = {
.kind = "bond",
.priv_size = sizeof(struct bonding),
......@@ -689,6 +758,8 @@ struct rtnl_link_ops bond_link_ops __read_mostly = {
.get_num_tx_queues = bond_get_num_tx_queues,
.get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
as for TX queues */
.fill_linkxstats = bond_fill_linkxstats,
.get_linkxstats_size = bond_get_linkxstats_size,
.slave_maxtype = IFLA_BOND_SLAVE_MAX,
.slave_policy = bond_slave_policy,
.slave_changelink = bond_slave_changelink,
......
......@@ -321,5 +321,8 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
int bond_3ad_set_carrier(struct bonding *bond);
void bond_3ad_update_lacp_rate(struct bonding *bond);
void bond_3ad_update_ad_actor_settings(struct bonding *bond);
void bond_3ad_stats_add(struct slave *slave, struct bond_3ad_stats *stats);
int bond_3ad_stats_fill(struct sk_buff *skb, struct bond_3ad_stats *stats);
size_t bond_3ad_stats_size(void);
#endif /* _NET_BOND_3AD_H */
......@@ -117,6 +117,30 @@ struct ad_info {
__u8 partner_system[ETH_ALEN];
};
/* Embedded inside LINK_XSTATS_TYPE_BOND */
enum {
BOND_XSTATS_UNSPEC,
BOND_XSTATS_3AD,
__BOND_XSTATS_MAX
};
#define BOND_XSTATS_MAX (__BOND_XSTATS_MAX - 1)
/* Embedded inside BOND_XSTATS_3AD */
enum {
BOND_3AD_STAT_LACPDU_RX,
BOND_3AD_STAT_LACPDU_TX,
BOND_3AD_STAT_LACPDU_UNKNOWN_RX,
BOND_3AD_STAT_LACPDU_ILLEGAL_RX,
BOND_3AD_STAT_MARKER_RX,
BOND_3AD_STAT_MARKER_TX,
BOND_3AD_STAT_MARKER_RESP_RX,
BOND_3AD_STAT_MARKER_RESP_TX,
BOND_3AD_STAT_MARKER_UNKNOWN_RX,
BOND_3AD_STAT_PAD,
__BOND_3AD_STAT_MAX
};
#define BOND_3AD_STAT_MAX (__BOND_3AD_STAT_MAX - 1)
#endif /* _LINUX_IF_BONDING_H */
/*
......
......@@ -925,6 +925,7 @@ enum {
enum {
LINK_XSTATS_TYPE_UNSPEC,
LINK_XSTATS_TYPE_BRIDGE,
LINK_XSTATS_TYPE_BOND,
__LINK_XSTATS_TYPE_MAX
};
#define LINK_XSTATS_TYPE_MAX (__LINK_XSTATS_TYPE_MAX - 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment