Skip to content

Commit e60a426

Browse files
committed
Merge branch 'mpls-packet-stats'
Robert Shearman says: ==================== mpls: Packet stats This patchset records per-interface packet stats in the MPLS forwarding path and exports them using a nest of attributes root at a new IFLA_STATS_AF_SPEC attribute as part of RTM_GETSTATS messages: [IFLA_STATS_AF_SPEC] -> [AF_MPLS] -> [MPLS_STATS_LINK] -> struct mpls_link_stats The first patch adds the rtnl infrastructure for this, including a new callbacks to per-AF ops of fill_stats_af and get_stats_af_size. The second patch records MPLS stats and makes use of the infrastructure to export them. The rtnl infrastructure could also be used to export IPv6 stats in the future. Changes in v2: - make incrementing IPv6 stats in mpls_stats_inc_outucastpkts conditional on CONFIG_IPV6 to fix build with CONFIG_IPV6=n ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 55f78fc + 27d6910 commit e60a426

File tree

7 files changed

+307
-28
lines changed

7 files changed

+307
-28
lines changed

include/net/rtnetlink.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ struct rtnl_af_ops {
139139
const struct nlattr *attr);
140140
int (*set_link_af)(struct net_device *dev,
141141
const struct nlattr *attr);
142+
143+
int (*fill_stats_af)(struct sk_buff *skb,
144+
const struct net_device *dev);
145+
size_t (*get_stats_af_size)(const struct net_device *dev);
142146
};
143147

144148
void __rtnl_af_unregister(struct rtnl_af_ops *ops);

include/uapi/linux/if_link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ enum {
847847
IFLA_STATS_LINK_XSTATS,
848848
IFLA_STATS_LINK_XSTATS_SLAVE,
849849
IFLA_STATS_LINK_OFFLOAD_XSTATS,
850+
IFLA_STATS_AF_SPEC,
850851
__IFLA_STATS_MAX,
851852
};
852853

include/uapi/linux/mpls.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,34 @@ struct mpls_label {
4343

4444
#define MPLS_LABEL_FIRST_UNRESERVED 16 /* RFC3032 */
4545

46+
/* These are embedded into IFLA_STATS_AF_SPEC:
47+
* [IFLA_STATS_AF_SPEC]
48+
* -> [AF_MPLS]
49+
* -> [MPLS_STATS_xxx]
50+
*
51+
* Attributes:
52+
* [MPLS_STATS_LINK] = {
53+
* struct mpls_link_stats
54+
* }
55+
*/
56+
enum {
57+
MPLS_STATS_UNSPEC, /* also used as 64bit pad attribute */
58+
MPLS_STATS_LINK,
59+
__MPLS_STATS_MAX,
60+
};
61+
62+
#define MPLS_STATS_MAX (__MPLS_STATS_MAX - 1)
63+
64+
struct mpls_link_stats {
65+
__u64 rx_packets; /* total packets received */
66+
__u64 tx_packets; /* total packets transmitted */
67+
__u64 rx_bytes; /* total bytes received */
68+
__u64 tx_bytes; /* total bytes transmitted */
69+
__u64 rx_errors; /* bad packets received */
70+
__u64 tx_errors; /* packet transmit problems */
71+
__u64 rx_dropped; /* packet dropped on receive */
72+
__u64 tx_dropped; /* packet dropped on transmit */
73+
__u64 rx_noroute; /* no route for packet dest */
74+
};
75+
4676
#endif /* _UAPI_MPLS_H */

net/core/rtnetlink.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,39 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
38293829
*idxattr = 0;
38303830
}
38313831

3832+
if (stats_attr_valid(filter_mask, IFLA_STATS_AF_SPEC, *idxattr)) {
3833+
struct rtnl_af_ops *af_ops;
3834+
3835+
*idxattr = IFLA_STATS_AF_SPEC;
3836+
attr = nla_nest_start(skb, IFLA_STATS_AF_SPEC);
3837+
if (!attr)
3838+
goto nla_put_failure;
3839+
3840+
list_for_each_entry(af_ops, &rtnl_af_ops, list) {
3841+
if (af_ops->fill_stats_af) {
3842+
struct nlattr *af;
3843+
int err;
3844+
3845+
af = nla_nest_start(skb, af_ops->family);
3846+
if (!af)
3847+
goto nla_put_failure;
3848+
3849+
err = af_ops->fill_stats_af(skb, dev);
3850+
3851+
if (err == -ENODATA)
3852+
nla_nest_cancel(skb, af);
3853+
else if (err < 0)
3854+
goto nla_put_failure;
3855+
3856+
nla_nest_end(skb, af);
3857+
}
3858+
}
3859+
3860+
nla_nest_end(skb, attr);
3861+
3862+
*idxattr = 0;
3863+
}
3864+
38323865
nlmsg_end(skb, nlh);
38333866

38343867
return 0;
@@ -3885,6 +3918,23 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev,
38853918
if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_OFFLOAD_XSTATS, 0))
38863919
size += rtnl_get_offload_stats_size(dev);
38873920

3921+
if (stats_attr_valid(filter_mask, IFLA_STATS_AF_SPEC, 0)) {
3922+
struct rtnl_af_ops *af_ops;
3923+
3924+
/* for IFLA_STATS_AF_SPEC */
3925+
size += nla_total_size(0);
3926+
3927+
list_for_each_entry(af_ops, &rtnl_af_ops, list) {
3928+
if (af_ops->get_stats_af_size) {
3929+
size += nla_total_size(
3930+
af_ops->get_stats_af_size(dev));
3931+
3932+
/* for AF_* */
3933+
size += nla_total_size(0);
3934+
}
3935+
}
3936+
}
3937+
38883938
return size;
38893939
}
38903940

0 commit comments

Comments
 (0)