#endif
};
+#ifdef HAVE_IFLA_VF_STATS
typedef struct vf_stats_s {
struct ifla_vf_mac *vf_mac;
uint32_t vlan;
uint64_t tx_dropped;
#endif
} vf_stats_t;
+#endif
typedef struct ir_ignorelist_s {
char *device;
return ir_ignorelist_invert;
} /* int check_ignorelist */
+#ifdef HAVE_IFLA_VF_STATS
static void submit_one_gauge(const char *dev, const char *type,
const char *type_instance, gauge_t value) {
value_list_t vl = VALUE_LIST_INIT;
plugin_dispatch_values(&vl);
} /* void submit_one_gauge */
+#endif
static void submit_one(const char *dev, const char *type,
const char *type_instance, derive_t value) {
check_ignorelist_and_submit(dev, &s);
}
+#ifdef HAVE_IFLA_VF_STATS
static void vf_info_submit(const char *dev, vf_stats_t *vf_stats) {
if (vf_stats->vf_mac == NULL) {
ERROR("netlink plugin: vf_info_submit: failed to get VF macaddress, "
return MNL_CB_OK;
} /* int vf_info_attr_cb */
+#endif /* HAVE_IFLA_VF_STATS */
static int link_filter_cb(const struct nlmsghdr *nlh,
void *args __attribute__((unused))) {
struct nlattr *attr;
const char *dev = NULL;
union ir_link_stats_u stats;
+#ifdef HAVE_IFLA_VF_STATS
uint32_t num_vfs = 0;
+#endif
bool stats_done = false;
if (nlh->nlmsg_type != RTM_NEWLINK) {
return MNL_CB_OK;
}
+#ifdef HAVE_IFLA_VF_STATS
if (collect_vf_stats) {
mnl_attr_for_each(attr, nlh, sizeof(*ifm)) {
if (mnl_attr_get_type(attr) != IFLA_NUM_VF)
break;
}
}
+#endif
+
#ifdef HAVE_RTNL_LINK_STATS64
mnl_attr_for_each(attr, nlh, sizeof(*ifm)) {
if (mnl_attr_get_type(attr) != IFLA_STATS64)
if (stats_done == false)
DEBUG("netlink plugin: link_filter: No statistics for interface %s.", dev);
#endif
+
+#ifdef HAVE_IFLA_VF_STATS
if (num_vfs == 0)
return MNL_CB_OK;
}
break;
}
+#endif
return MNL_CB_OK;
} /* int link_filter_cb */
key, fields_num);
status = -1;
} else {
+#ifdef HAVE_IFLA_VF_STATS
if (IS_TRUE(fields[0]))
collect_vf_stats = true;
else
collect_vf_stats = false;
+#else
+ WARNING("netlink plugin: VF statistics not supported on this system.");
+#endif
status = 0;
}
}
rt = mnl_nlmsg_put_extra_header(nlh, sizeof(*rt));
rt->rtgen_family = AF_PACKET;
+#ifdef HAVE_IFLA_VF_STATS
if (collect_vf_stats &&
mnl_attr_put_u32_check(nlh, sizeof(buf), IFLA_EXT_MASK,
RTEXT_FILTER_VF) == 0) {
ERROR("netlink plugin: FAILED to set RTEXT_FILTER_VF");
return -1;
}
+#endif
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
ERROR("netlink plugin: ir_read: rtnl_wilddump_request failed.");
#include "netlink.c" /* sic */
#include "testing.h"
+#ifdef HAVE_IFLA_VF_STATS
static vf_stats_t g_test_res;
static char g_instance[512];
static int g_type_valid;
void *mnl_attr_get_payload(__attribute__((unused)) const struct nlattr *attr) {
return g_test_payload;
}
+#else /* HAVE_IFLA_VF_STATS */
+int plugin_dispatch_values_nl_test(__attribute__((unused))
+ value_list_t const *vl) {
+ return 0;
+}
+#endif
/* end mock functions */
+#ifdef HAVE_IFLA_VF_STATS
DEF_TEST(plugin_nl_config) {
EXPECT_EQ_INT(0, collect_vf_stats);
int ret = ir_config("CollectVFStats", "true");
return 0;
}
+#endif
DEF_TEST(ignorelist_test) {
ir_ignorelist_invert = 1;
return 0;
}
+#ifdef HAVE_IFLA_VF_STATS
DEF_TEST(vf_submit_test) {
const char *test_dev = "eth0";
vf_stats_t test_stats;
return 0;
}
+#endif /* HAVE_IFLA_VF_STATS */
int main(void) {
+#ifdef HAVE_IFLA_VF_STATS
RUN_TEST(plugin_nl_config);
+#endif
RUN_TEST(ignorelist_test);
+#ifdef HAVE_IFLA_VF_STATS
RUN_TEST(vf_submit_test);
RUN_TEST(vf_info_attr_cb_test);
+#endif
END_TEST;
}