Skip to content

Commit

Permalink
bonding: add support for xstats and export 3ad stats
Browse files Browse the repository at this point in the history
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: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Nikolay Aleksandrov authored and David S. Miller committed Jan 22, 2019
1 parent 267c095 commit a258aea
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
83 changes: 83 additions & 0 deletions drivers/net/bonding/bond_3ad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
71 changes: 71 additions & 0 deletions drivers/net/bonding/bond_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions include/net/bond_3ad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

24 changes: 24 additions & 0 deletions include/uapi/linux/if_bonding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

/*
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/if_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a258aea

Please sign in to comment.