+} /* void check_ignorelist_and_submit */
+
+#define COPY_RTNL_LINK_VALUE(dst_stats, src_stats, value_name) \
+ (dst_stats)->value_name = (src_stats)->value_name
+
+#define COPY_RTNL_LINK_STATS(dst_stats, src_stats) \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_packets); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_packets); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_bytes); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_bytes); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_dropped); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_dropped); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, multicast); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, collisions); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_length_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_over_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_crc_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_frame_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_fifo_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, rx_missed_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_aborted_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_carrier_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_fifo_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_heartbeat_errors); \
+ COPY_RTNL_LINK_VALUE (dst_stats, src_stats, tx_window_errors)
+
+#ifdef HAVE_RTNL_LINK_STATS64
+static void check_ignorelist_and_submit64 (const char *dev,
+ struct rtnl_link_stats64 *stats)
+{
+ struct ir_link_stats_storage_s s;
+
+ COPY_RTNL_LINK_STATS (&s, stats);
+
+ check_ignorelist_and_submit (dev, &s);
+}
+#endif
+
+static void check_ignorelist_and_submit32 (const char *dev,
+ struct rtnl_link_stats *stats)
+{
+ struct ir_link_stats_storage_s s;
+
+ COPY_RTNL_LINK_STATS(&s, stats);
+
+ check_ignorelist_and_submit (dev, &s);
+}
+
+static int link_filter_cb (const struct nlmsghdr *nlh,
+ void *args __attribute__((unused)))
+{
+ struct ifinfomsg *ifm = mnl_nlmsg_get_payload (nlh);
+ struct nlattr *attr;
+ const char *dev = NULL;
+ union ir_link_stats_u stats;
+
+ if (nlh->nlmsg_type != RTM_NEWLINK)
+ {
+ ERROR ("netlink plugin: link_filter_cb: Don't know how to handle type %i.",
+ nlh->nlmsg_type);
+ return MNL_CB_ERROR;
+ }
+
+ /* Scan attribute list for device name. */
+ mnl_attr_for_each (attr, nlh, sizeof (*ifm))
+ {
+ if (mnl_attr_get_type (attr) != IFLA_IFNAME)
+ continue;
+
+ if (mnl_attr_validate (attr, MNL_TYPE_STRING) < 0)
+ {
+ ERROR ("netlink plugin: link_filter_cb: IFLA_IFNAME mnl_attr_validate failed.");
+ return MNL_CB_ERROR;
+ }
+
+ dev = mnl_attr_get_str (attr);
+ if (update_iflist (ifm, dev) < 0)
+ return MNL_CB_ERROR;
+ break;
+ }
+
+ if (dev == NULL)
+ {
+ ERROR ("netlink plugin: link_filter_cb: dev == NULL");
+ return MNL_CB_ERROR;
+ }
+#ifdef HAVE_RTNL_LINK_STATS64
+ mnl_attr_for_each (attr, nlh, sizeof (*ifm))
+ {
+ if (mnl_attr_get_type (attr) != IFLA_STATS64)
+ continue;
+
+ if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (*stats.stats64)) < 0)
+ {
+ ERROR ("netlink plugin: link_filter_cb: IFLA_STATS64 mnl_attr_validate2 failed.");
+ return MNL_CB_ERROR;
+ }
+ stats.stats64 = mnl_attr_get_payload (attr);
+
+ check_ignorelist_and_submit64 (dev, stats.stats64);
+
+ return MNL_CB_OK;
+ }
+#endif
+ mnl_attr_for_each (attr, nlh, sizeof (*ifm))
+ {
+ if (mnl_attr_get_type (attr) != IFLA_STATS)
+ continue;
+
+ if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (*stats.stats32)) < 0)
+ {
+ ERROR ("netlink plugin: link_filter_cb: IFLA_STATS mnl_attr_validate2 failed.");
+ return MNL_CB_ERROR;
+ }
+ stats.stats32 = mnl_attr_get_payload (attr);
+
+ check_ignorelist_and_submit32 (dev, stats.stats32);
+
+ return MNL_CB_OK;
+ }
+
+ DEBUG ("netlink plugin: link_filter: No statistics for interface %s.", dev);
+ return MNL_CB_OK;
+
+} /* int link_filter_cb */
+
+#if HAVE_TCA_STATS2
+static int qos_attr_cb (const struct nlattr *attr, void *data)
+{
+ struct gnet_stats_basic **bs = (struct gnet_stats_basic **)data;
+
+ /* skip unsupported attribute in user-space */
+ if (mnl_attr_type_valid (attr, TCA_STATS_MAX) < 0)
+ return MNL_CB_OK;
+
+ if (mnl_attr_get_type (attr) == TCA_STATS_BASIC)
+ {
+ if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (**bs)) < 0)
+ {
+ ERROR ("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 failed.");
+ return MNL_CB_ERROR;
+ }
+ *bs = mnl_attr_get_payload (attr);
+ return MNL_CB_STOP;
+ }
+
+ return MNL_CB_OK;
+} /* qos_attr_cb */
+#endif