Merge branch 'pull/collectd-4.1' into collectd-4.1
authorFlorian Forster <octo@huhu.verplant.org>
Wed, 26 Sep 2007 15:18:31 +0000 (17:18 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Wed, 26 Sep 2007 15:18:31 +0000 (17:18 +0200)
ChangeLog
configure.in
src/Makefile.am
src/netlink.c

index 66d339d..3f16c8e 100644 (file)
--- 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.
index a13b79c..54d38d5 100644 (file)
@@ -773,9 +773,11 @@ AC_ARG_WITH(libcurl, [AS_HELP_STRING([--with-libcurl@<:@=PREFIX@:>@], [Path to l
                if test -f "$withval" && test -x "$withval"
                then
                        with_curl_config="$withval"
+                       with_libcurl="yes"
                else if test -x "$withval/bin/curl-config"
                then
                        with_curl_config="$withval/bin/curl-config"
+                       with_libcurl="yes"
                fi; fi
                with_libcurl="yes"
        fi; fi
@@ -1225,29 +1227,67 @@ else
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBIPTC, test "x$with_libiptc" = "xyes")
 
+with_snmp_config="net-snmp-config"
+with_snmp_cflags=""
+with_snmp_libs=""
 AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])],
 [
-       if test "x$withval" != "xno" && test "x$withval" != "xyes"
+       if test "x$withval" = "xno"
+       then
+               with_libnetsnmp="no"
+       else if "x$withval" = "xyes"
        then
-               LDFLAGS="$LDFLAGS -L$withval/lib"
-               CPPFLAGS="$CPPFLAGS -I$withval/include"
                with_libnetsnmp="yes"
-       fi
+       else
+               if test -x "$withval"
+               then
+                       with_snmp_config="$withval"
+                       with_libnetsnmp="yes"
+               else
+                       with_snmp_config="$withval/bin/net-snmp-config"
+                       with_libnetsnmp="yes"
+               fi
+       fi; fi
 ],
 [with_libnetsnmp="yes"])
 if test "x$with_libnetsnmp" = "xyes"
 then
-       AC_CHECK_LIB(netsnmp, init_snmp,
-       [
-               AC_DEFINE(HAVE_LIBSNMP, 1, [Define to 1 if you have the Net-SNMP library (-lnetsnmp).])
-       ], [with_libnetsnmp="no (libnetsnmp not found)"])
+       with_snmp_cflags=`$with_snmp_config --cflags 2>/dev/null`
+       snmp_config_status=$?
+
+       if test $snmp_config_status -ne 0
+       then
+               with_libnetsnmp="no ($with_snmp_config failed)"
+       else
+               SAVE_CFLAGS=$CFLAGS
+               CFLAGS="$CFLAGS $with_snmp_cflags"
+               
+               AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
+
+               CFLAGS="$SAVE_CFLAGS"
+       fi
 fi
 if test "x$with_libnetsnmp" = "xyes"
 then
-       AC_CHECK_HEADERS(net-snmp/net-snmp-config.h,
-       [
-               AC_DEFINE(HAVE_NET_SNMP_NET_SNMP_CONFIG_H, 1, [Define to 1 if you have the <net-snmp/net-snmp-config.h> header file.])
-       ], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
+       with_snmp_libs=`$with_snmp_config --libs 2>/dev/null`
+       snmp_config_status=$?
+
+       if test $snmp_config_status -ne 0
+       then
+               with_libnetsnmp="no ($with_snmp_config failed)"
+       else
+               AC_CHECK_LIB(netsnmp, init_snmp,
+               [with_libnetsnmp="yes"],
+               [with_libnetsnmp="no (libnetsnmp not found)"],
+               [$with_snmp_libs])
+       fi
+fi
+if test "x$with_libnetsnmp" = "xyes"
+then
+       BUILD_WITH_LIBSNMP_CFLAGS="$with_snmp_cflags"
+       BUILD_WITH_LIBSNMP_LIBS="$with_snmp_libs"
+       AC_SUBST(BUILD_WITH_LIBSNMP_CFLAGS)
+       AC_SUBST(BUILD_WITH_LIBSNMP_LIBS)
 fi
 AM_CONDITIONAL(BUILD_WITH_LIBNETSNMP, test "x$with_libnetsnmp" = "xyes")
 
@@ -1443,6 +1483,43 @@ then
 #include <sys/socket.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>])
+       AC_CHECK_HEADERS(linux/gen_stats.h linux/pkt_sched.h, [], [],
+[#include <stdio.h>
+#include <sys/types.h>
+#include <asm/types.h>
+#include <sys/socket.h>])
+
+       AC_COMPILE_IFELSE(
+[#include <stdio.h>
+#include <sys/types.h>
+#include <asm/types.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+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 <stdio.h>
+#include <sys/types.h>
+#include <asm/types.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+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
index 16094f7..f988a0f 100644 (file)
@@ -466,11 +466,14 @@ if BUILD_PLUGIN_SNMP
 pkglib_LTLIBRARIES += snmp.la
 snmp_la_SOURCES = snmp.c
 snmp_la_LDFLAGS = -module -avoid-version
+snmp_la_CFLAGS =
+snmp_la_LIBADD =
 if BUILD_WITH_LIBNETSNMP
-snmp_la_LDFLAGS += -lnetsnmp
+snmp_la_CFLAGS += $(BUILD_WITH_LIBSNMP_CFLAGS)
+snmp_la_LIBADD += $(BUILD_WITH_LIBSNMP_LIBS)
 endif
 if BUILD_WITH_LIBPTHREAD
-snmp_la_LDFLAGS += -lpthread
+snmp_la_LIBADD += -lpthread
 endif
 collectd_LDADD += "-dlopen" snmp.la
 collectd_DEPENDENCIES += snmp.la
index 073efe9..8c883f6 100644 (file)
 
 #include <asm/types.h>
 #include <sys/socket.h>
+
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
-#include <linux/gen_stats.h>
+#if HAVE_LINUX_GEN_STATS_H
+# include <linux/gen_stats.h>
+#endif
+#if HAVE_LINUX_PKT_SCHED_H
+# include <linux/pkt_sched.h>
+#endif
 
 #if HAVE_LIBNETLINK_H
 # include <libnetlink.h>
@@ -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 */