Add interface to retrieve link statistics
This commit adds an interface to get the statistics (64-bits) from CAN interface. See more information from /usr/include/linux/if_link.h where defines the struct rtnl_link_stats64. Compare to the rtnl_link_stats, rtnl_link_stats64 was introduced since linux kernel 2.6. After that the rtnl_link_stats is synchronous with struct rtnl_link_stats64 by truncating each member from 64 bits to 32 bits. Actually, the struct rtnl_link_stats is kept for compatibility. Signed-off-by: Leo Ruan <tingquan.ruan@cn.bosch.com> Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>pull/106/head^2
parent
6f13cefafe
commit
9679a3f50a
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <can_netlink.h>
|
||||
|
||||
struct rtnl_link_stats64; /* from <linux/if_link.h> */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
@ -50,6 +52,7 @@ int can_get_clock(const char *name, struct can_clock *clock);
|
|||
int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc);
|
||||
int can_get_berr_counter(const char *name, struct can_berr_counter *bc);
|
||||
int can_get_device_stats(const char *name, struct can_device_stats *cds);
|
||||
int can_get_link_stats(const char *name, struct rtnl_link_stats64 *rls);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <linux/if_link.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/netlink.h>
|
||||
|
||||
|
|
@ -54,6 +55,7 @@
|
|||
#define GET_BITTIMING_CONST 6
|
||||
#define GET_BERR_COUNTER 7
|
||||
#define GET_XSTATS 8
|
||||
#define GET_LINK_STATS 9
|
||||
|
||||
struct get_req {
|
||||
struct nlmsghdr n;
|
||||
|
|
@ -408,6 +410,16 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
|
|||
else
|
||||
continue;
|
||||
|
||||
if (acquire == GET_LINK_STATS) {
|
||||
if (!tb[IFLA_STATS64]) {
|
||||
fprintf(stderr, "no link statistics (64-bit) found\n");
|
||||
} else {
|
||||
memcpy(res, RTA_DATA(tb[IFLA_STATS64]), sizeof(struct rtnl_link_stats64));
|
||||
ret = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tb[IFLA_LINKINFO])
|
||||
parse_rtattr_nested(linkinfo,
|
||||
IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
|
||||
|
|
@ -1157,3 +1169,29 @@ int can_get_device_stats(const char *name, struct can_device_stats *cds)
|
|||
{
|
||||
return get_link(name, GET_XSTATS, cds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup extern
|
||||
* can_get_link_statistics - get RX/TX statistics (64 bits version)
|
||||
*
|
||||
* @param name name of the can device. This is the netdev name, as ip link shows
|
||||
* in your system. usually it contains prefix "can" and the number of the can
|
||||
* line. e.g. "can0"
|
||||
* @param rls pointer to the rtnl_link_stats64 struct which is from if_link.h.
|
||||
*
|
||||
* This one gets the current rtnl_link_stats64. Compares to the rtnl_link_stats,
|
||||
* The rtnl_link_stats64 is introduced since linux kernel 2.6. After that the
|
||||
* rtnl_link_stats is synchronous with struct rtnl_link_stats64 by truncating
|
||||
* each member from 64 bits to 32 bits. actually, the struct rtnl_link_stats
|
||||
* is kept for compatibility.
|
||||
*
|
||||
* Please see struct rtnl_link_stats64 (/usr/include/linux/if_link.h) for more
|
||||
* information.
|
||||
*
|
||||
* @return 0 if success
|
||||
* @return -1 if failed
|
||||
*/
|
||||
int can_get_link_stats(const char *name, struct rtnl_link_stats64 *rls)
|
||||
{
|
||||
return get_link(name, GET_LINK_STATS, rls);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue