#include "collectd.h"
-#include "common.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include <asm/types.h>
uint64_t tx_dropped;
uint64_t multicast;
uint64_t collisions;
+ uint64_t rx_nohandler;
uint64_t rx_length_errors;
uint64_t rx_over_errors;
};
static int ir_ignorelist_invert = 1;
-static ir_ignorelist_t *ir_ignorelist_head = NULL;
+static ir_ignorelist_t *ir_ignorelist_head;
static struct mnl_socket *nl;
-static char **iflist = NULL;
-static size_t iflist_len = 0;
+static char **iflist;
+static size_t iflist_len;
static const char *config_keys[] = {"Interface", "VerboseInterface",
"QDisc", "Class",
submit_two(dev, "if_dropped", NULL, stats->rx_dropped, stats->tx_dropped);
submit_one(dev, "if_multicast", NULL, stats->multicast);
submit_one(dev, "if_collisions", NULL, stats->collisions);
+#if defined(HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER) || \
+ defined(HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER)
+ submit_one(dev, "if_rx_nohandler", NULL, stats->rx_nohandler);
+#endif
submit_one(dev, "if_rx_errors", "length", stats->rx_length_errors);
submit_one(dev, "if_rx_errors", "over", stats->rx_over_errors);
struct ir_link_stats_storage_s s;
COPY_RTNL_LINK_STATS(&s, stats);
+#ifdef HAVE_STRUCT_RTNL_LINK_STATS64_RX_NOHANDLER
+ COPY_RTNL_LINK_VALUE(&s, stats, rx_nohandler);
+#endif
check_ignorelist_and_submit(dev, &s);
}
struct ir_link_stats_storage_s s;
COPY_RTNL_LINK_STATS(&s, stats);
+#ifdef HAVE_STRUCT_RTNL_LINK_STATS_RX_NOHANDLER
+ COPY_RTNL_LINK_VALUE(&s, stats, rx_nohandler);
+#endif
check_ignorelist_and_submit(dev, &s);
}
if (mnl_attr_get_type(attr) != IFLA_STATS64)
continue;
- if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats64)) < 0) {
- char errbuf[1024];
- ERROR("netlink plugin: link_filter_cb: IFLA_STATS64 mnl_attr_validate2 "
- "failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ uint16_t attr_len = mnl_attr_get_payload_len(attr);
+ if (attr_len < sizeof(*stats.stats64)) {
+ ERROR("netlink plugin: link_filter_cb: IFLA_STATS64 attribute has "
+ "insufficient data.");
return MNL_CB_ERROR;
}
stats.stats64 = mnl_attr_get_payload(attr);
if (mnl_attr_get_type(attr) != IFLA_STATS)
continue;
- if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*stats.stats32)) < 0) {
- char errbuf[1024];
- ERROR("netlink plugin: link_filter_cb: IFLA_STATS mnl_attr_validate2 "
- "failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ uint16_t attr_len = mnl_attr_get_payload_len(attr);
+ if (attr_len < sizeof(*stats.stats32)) {
+ ERROR("netlink plugin: link_filter_cb: IFLA_STATS attribute has "
+ "insufficient data.");
return MNL_CB_ERROR;
}
stats.stats32 = mnl_attr_get_payload(attr);
if (mnl_attr_get_type(attr) == TCA_STATS_BASIC) {
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->bs)) < 0) {
- char errbuf[1024];
ERROR("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 "
"failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return MNL_CB_ERROR;
}
q_stats->bs = mnl_attr_get_payload(attr);
const char *tc_type;
char tc_inst[DATA_MAX_NAME_LEN];
- _Bool stats_submitted = 0;
+ bool stats_submitted = false;
if (nlh->nlmsg_type == RTM_NEWQDISC)
tc_type = "qdisc";
if ((tm->tcm_ifindex >= 0) && ((size_t)tm->tcm_ifindex >= iflist_len)) {
ERROR("netlink plugin: qos_filter_cb: tm->tcm_ifindex = %i "
- ">= iflist_len = %zu",
+ ">= iflist_len = %" PRIsz,
tm->tcm_ifindex, iflist_len);
return MNL_CB_ERROR;
}
if (q_stats.bs != NULL || q_stats.qs != NULL) {
char type_instance[DATA_MAX_NAME_LEN];
- stats_submitted = 1;
+ stats_submitted = true;
- snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst);
+ int r = snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type,
+ tc_inst);
+ if ((size_t)r >= sizeof(type_instance)) {
+ ERROR("netlink plugin: type_instance truncated to %zu bytes, need %d",
+ sizeof(type_instance), r);
+ return MNL_CB_ERROR;
+ }
if (q_stats.bs != NULL) {
submit_one(dev, "ipt_bytes", type_instance, q_stats.bs->bytes);
continue;
if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*ts)) < 0) {
- char errbuf[1024];
ERROR("netlink plugin: qos_filter_cb: TCA_STATS mnl_attr_validate2 "
"failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
return MNL_CB_ERROR;
}
ts = mnl_attr_get_payload(attr);
if (!stats_submitted && ts != NULL) {
char type_instance[DATA_MAX_NAME_LEN];
- snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst);
+ int r = snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type,
+ tc_inst);
+ if ((size_t)r >= sizeof(type_instance)) {
+ ERROR("netlink plugin: type_instance truncated to %zu bytes, need %d",
+ sizeof(type_instance), r);
+ return MNL_CB_ERROR;
+ }
submit_one(dev, "ipt_bytes", type_instance, ts->bytes);
submit_one(dev, "ipt_packets", type_instance, ts->packets);
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
if (ret < 0) {
- char errbuf[1024];
- ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s", STRERRNO);
return (-1);
}
continue;
}
- DEBUG("netlink plugin: ir_read: querying %s from %s (%zu).",
+ DEBUG("netlink plugin: ir_read: querying %s from %s (%" PRIsz ").",
type_name[type_index], iflist[ifindex], ifindex);
nlh = mnl_nlmsg_put_header(buf);
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
if (ret < 0) {
- char errbuf[1024];
ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ STRERRNO);
continue;
}
} /* for (type_index) */