| 1 |
#include <sys/socket.h> |
| 2 |
#include <sys/types.h> |
| 3 |
#include <sys/ioctl.h> |
| 4 |
#include <net/if.h> |
| 5 |
#include <linux/sockios.h> |
| 6 |
#include <ifaddrs.h> |
| 7 |
|
| 8 |
/* use kernel's ethtool.h */ |
| 9 |
|
| 10 |
#ifdef HAVE_LINUX_ETHTOOL_NEEDS_U64 |
| 11 |
#include <linux/types.h> |
| 12 |
typedef __u64 u64; |
| 13 |
typedef __u32 u32; |
| 14 |
typedef __u16 u16; |
| 15 |
typedef __u8 u8; |
| 16 |
#endif |
| 17 |
#include <linux/ethtool.h> |
| 18 |
|
| 19 |
/* structure for storing the interface names in the system */ |
| 20 |
|
| 21 |
struct ifname { |
| 22 |
struct ifname *ifn_next; |
| 23 |
char name [IF_NAMESIZE]; |
| 24 |
}; |
| 25 |
|
| 26 |
struct ifname *dot3stats_interface_name_list_get (struct ifname *, int *); |
| 27 |
void dot3stats_interface_name_list_free(struct ifname *list_head); |
| 28 |
int dot3stats_interface_ioctl_ifindex_get (int fd, const char *name); |
| 29 |
int _dot3Stats_ioctl_get(int fd, int which, struct ifreq *ifrq, const char* name); |
| 30 |
int interface_ioctl_dot3stats_get(dot3StatsTable_rowreq_ctx *rowreq_ctx, int fd, const char* name); |
| 31 |
int interface_ioctl_dot3stats_duplex_get(dot3StatsTable_rowreq_ctx *rowreq_ctx, int fd, const char* name); |
| 32 |
|
| 33 |
|
| 34 |
/* for maintainability */ |
| 35 |
|
| 36 |
#define INTEL_RECEIVE_ALIGN_ERRORS "rx_align_errors" |
| 37 |
#define BROADCOM_RECEIVE_ALIGN_ERRORS INTEL_RECEIVE_ALIGN_ERRORS |
| 38 |
|
| 39 |
#define INTEL_TRANSMIT_MULTIPLE_COLLISIONS "tx_multi_coll_ok" |
| 40 |
#define BROADCOM_TRANSMIT_MULTIPLE_COLLISIONS_BNX2 "tx_multi_collisions" |
| 41 |
#define BROADCOM_TRANSMIT_MULTIPLE_COLLISIONS_TG3 "tx_mult_collisions" |
| 42 |
#define DSA_TRANSMIT_MULTIPLE_COLLISIONS "multiple" |
| 43 |
|
| 44 |
#define INTEL_TRANSMIT_LATE_COLLISIONS "tx_abort_late_coll" |
| 45 |
#define BROADCOM_TRANSMIT_LATE_COLLISIONS "tx_late_collisions" |
| 46 |
#define DSA_TRANSMIT_LATE_COLLISIONS "late" |
| 47 |
|
| 48 |
#define INTEL_TRANSMIT_SINGLE_COLLISIONS "tx_single_coll_ok" |
| 49 |
#define BROADCOM_TRANSMIT_SINGLE_COLLISIONS "tx_single_collisions" |
| 50 |
#define DSA_TRANSMIT_SINGLE_COLLISIONS "single" |
| 51 |
|
| 52 |
#define BROADCOM_TRANSMIT_EXCESS_COLLISIONS_BNX2 "tx_excess_collisions" |
| 53 |
#define BROADCOM_TRANSMIT_EXCESS_COLLISIONS_TG3 "tx_excessive_collisions" |
| 54 |
#define DSA_TRANSMIT_EXCESS_COLLISIONS "excessive" |
| 55 |
|
| 56 |
#define DSA_RECEIVE_FCS_ERROR "in_fcs_error" |
| 57 |
|
| 58 |
#define DSA_TRANSMIT_DEFERRED "deferred" |
| 59 |
|
| 60 |
#define DOT3STATSALIGNMENTERRORS(x) strstr(x, INTEL_RECEIVE_ALIGN_ERRORS) |
| 61 |
#define DOT3STATSFCSERRORS(x) strstr(x, DSA_RECEIVE_FCS_ERROR) |
| 62 |
#define DOT3STATSDEFERREDTRANSMISSIONS(x) !strcmp(x, DSA_TRANSMIT_DEFERRED) |
| 63 |
|
| 64 |
#define DOT3STATSMULTIPLECOLLISIONFRAMES(x) (strstr(x, INTEL_TRANSMIT_MULTIPLE_COLLISIONS)) || \ |
| 65 |
(!strcmp(x, DSA_TRANSMIT_MULTIPLE_COLLISIONS)) || \ |
| 66 |
(strstr(x, BROADCOM_TRANSMIT_MULTIPLE_COLLISIONS_BNX2)) || \ |
| 67 |
(strstr(x, BROADCOM_TRANSMIT_MULTIPLE_COLLISIONS_TG3)) |
| 68 |
|
| 69 |
#define DOT3STATSLATECOLLISIONS(x) (strstr(x, INTEL_TRANSMIT_LATE_COLLISIONS)) || \ |
| 70 |
(!strcmp(x, DSA_TRANSMIT_LATE_COLLISIONS)) || \ |
| 71 |
(strstr(x, BROADCOM_TRANSMIT_LATE_COLLISIONS)) |
| 72 |
|
| 73 |
#define DOT3STATSSINGLECOLLISIONFRAMES(x) (strstr(x, INTEL_TRANSMIT_SINGLE_COLLISIONS)) || \ |
| 74 |
(!strcmp(x, DSA_TRANSMIT_SINGLE_COLLISIONS)) || \ |
| 75 |
(strstr(x, BROADCOM_TRANSMIT_SINGLE_COLLISIONS)) |
| 76 |
|
| 77 |
#define DOT3STATSEXCESSIVECOLLISIONS(x) (strstr(x, BROADCOM_TRANSMIT_EXCESS_COLLISIONS_BNX2)) || \ |
| 78 |
(strstr(x, BROADCOM_TRANSMIT_EXCESS_COLLISIONS_TG3)) || \ |
| 79 |
(!strcmp(x, DSA_TRANSMIT_EXCESS_COLLISIONS)) |