From 5d26a6607fc53f416e42dccbc3fcda5d9b142625 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 15 Sep 2007 10:48:25 +0200 Subject: [PATCH] netlink plugin: Fix build issues under Debian Sarge or generally older Linux versions. --- ChangeLog | 2 ++ configure.in | 37 +++++++++++++++++++++++++++++++++++++ src/netlink.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66d339da..3f16c8ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ yyyy-mm-dd, Version 4.1.2 * apcups plugin: Fix reporting of the `load percent' data. + * netlink plugin: Build issues under some older versions of the Linux + includes (i. e. Debian Sarge) have been fixed. 2007-09-12, Version 4.1.1 * Build system: The detection of `libnetlink' has been improved. diff --git a/configure.in b/configure.in index 38373ac0..44d7cfcc 100644 --- a/configure.in +++ b/configure.in @@ -1438,6 +1438,43 @@ then #include #include #include ]) + AC_CHECK_HEADERS(linux/gen_stats.h linux/pkt_sched.h, [], [], +[#include +#include +#include +#include ]) + + AC_COMPILE_IFELSE( +[#include +#include +#include +#include +#include +#include + +int main (void) +{ + int retval = TCA_STATS2; + return (retval); +}], + [AC_DEFINE([HAVE_TCA_STATS2], 1, [True if the enum-member TCA_STATS2 exists])] + []); + + AC_COMPILE_IFELSE( +[#include +#include +#include +#include +#include +#include + +int main (void) +{ + int retval = TCA_STATS; + return (retval); +}], + [AC_DEFINE([HAVE_TCA_STATS], 1, [True if the enum-member TCA_STATS exists])] + []); CFLAGS="$SAVE_CFLAGS" fi diff --git a/src/netlink.c b/src/netlink.c index 073efe9e..8c883f67 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -25,9 +25,15 @@ #include #include + #include #include -#include +#if HAVE_LINUX_GEN_STATS_H +# include +#endif +#if HAVE_LINUX_PKT_SCHED_H +# include +#endif #if HAVE_LIBNETLINK_H # include @@ -198,8 +204,8 @@ static void submit_two (const char *dev, const char *type, plugin_dispatch_values (type, &vl); } /* void submit_two */ -static int link_filter (const struct sockaddr_nl *sa, struct nlmsghdr *nmh, - void *args) +static int link_filter (const struct sockaddr_nl *sa, + const struct nlmsghdr *nmh, void *args) { struct ifinfomsg *msg; int msg_len; @@ -305,8 +311,8 @@ static int link_filter (const struct sockaddr_nl *sa, struct nlmsghdr *nmh, return (0); } /* int link_filter */ -static int qos_filter (const struct sockaddr_nl *sa, struct nlmsghdr *nmh, - void *args) +static int qos_filter (const struct sockaddr_nl *sa, + const struct nlmsghdr *nmh, void *args) { struct tcmsg *msg; int msg_len; @@ -399,6 +405,7 @@ static int qos_filter (const struct sockaddr_nl *sa, struct nlmsghdr *nmh, if (check_ignorelist (dev, tc_type, tc_inst)) return (0); +#if HAVE_TCA_STATS2 if (attrs[TCA_STATS2]) { struct rtattr *attrs_stats[TCA_STATS_MAX + 1]; @@ -423,6 +430,35 @@ static int qos_filter (const struct sockaddr_nl *sa, struct nlmsghdr *nmh, submit_one (dev, "ipt_packets", type_instance, bs.packets); } } +#endif /* TCA_STATS2 */ +#if HAVE_TCA_STATS && HAVE_TCA_STATS2 + else +#endif +#if HAVE_TCA_STATS + if (attrs[TCA_STATS] != NULL) + { + struct tc_stats ts; + char type_instance[DATA_MAX_NAME_LEN]; + + snprintf (type_instance, sizeof (type_instance), "%s-%s", + tc_type, tc_inst); + type_instance[sizeof (type_instance) - 1] = '\0'; + + memset(&ts, '\0', sizeof (ts)); + memcpy(&ts, RTA_DATA (attrs[TCA_STATS]), + MIN (RTA_PAYLOAD (attrs[TCA_STATS]), sizeof (ts))); + + submit_one (dev, "ipt_bytes", type_instance, ts.bytes); + submit_one (dev, "ipt_packets", type_instance, ts.packets); + } +#endif /* TCA_STATS */ +#if HAVE_TCA_STATS || HAVE_TCA_STATS2 + else +#endif + { + DEBUG ("netlink plugin: qos_filter: Have neither TCA_STATS2 nor " + "TCA_STATS."); + } return (0); } /* int qos_filter */ -- 2.30.2