From c4377c1e3d97ae0641bf740dc90a59633b319fd1 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 2 Dec 2006 19:11:22 +0100 Subject: [PATCH] dns plugin: Improved config checks for the pthread library. The checks for the pthread-library have been extended to match the other libraries being used. The dns plugin (in particular `utils_dns.c') has been verified to build without `libpcap' being present. --- configure.in | 33 ++++++++++------- src/dns.c | 65 +++++++++++++++------------------ src/utils_dns.c | 96 +++++++++++++++++++++++++++++++------------------ src/utils_dns.h | 11 +++++- 4 files changed, 121 insertions(+), 84 deletions(-) diff --git a/configure.in b/configure.in index 348552ec..69c6aa91 100644 --- a/configure.in +++ b/configure.in @@ -276,9 +276,13 @@ AC_CHECK_HEADERS(stdarg.h) AC_CHECK_HEADERS(regex.h) # For the dns plugin +AC_CHECK_HEADERS(arpa/nameser.h arpa/nameser_compat.h) AC_CHECK_HEADERS(arpa/nameser.h) -AC_CHECK_HEADERS(pthread.h) + +AC_CHECK_HEADERS(net/if_arp.h) AC_CHECK_HEADERS(net/if_ppp.h) +AC_CHECK_HEADERS(netinet/if_ether.h) +AC_CHECK_HEADERS(netinet/udp.h) dnl Checking for libraries AC_CHECK_LIB(m, ext) @@ -497,24 +501,28 @@ AC_DEFINE_UNQUOTED(COLLECT_RRDTOOL, [$collect_rrdtool], [Wether or not to use rrdtool library]) AM_CONDITIONAL(BUILD_WITH_RRDTOOL, test "x$with_rrdtool" = "xyes") -with_pthread="yes" -AC_ARG_WITH(pthread, [AS_HELP_STRING([--with-pthread=@<:@=PREFIX@:>@], [Path to pthread (experimental).])], -[ if test "x$withval" != "xno" && test "x$withval" != "xyes" +AC_ARG_WITH(libpthread, [AS_HELP_STRING([--with-libpthread=@<:@=PREFIX@:>@], [Path to libpthread.])], +[ if test "x$withval" != "xno" -a "x$withval" != "xyes" then LDFLAGS="$LDFLAGS -L$withval/lib" CPPFLAGS="$CPPFLAGS -I$withval/include" - with_pthread="yes" + with_libpthread="yes" + else + if test "x$withval" = "xno" + then + with_libpthread="no (disabled)" + fi fi -], [with_pthread="no"]) -if test "x$with_pthread" = "xyes" +], [with_libpthread="no"]) +if test "x$with_libpthread" = "xyes" then - AC_CHECK_LIB(pthread, pthread_create, [with_pthread="yes"], [with_pthread="no (libpthread not found)"], []) + AC_CHECK_LIB(pthread, pthread_create, [with_libpthread="yes"], [with_libpthread="no (libpthread not found)"], []) fi -if test "x$with_pthread" = "xyes" +if test "x$with_libpthread" = "xyes" then - AC_CHECK_HEADERS(pthread.h,, [with_pthread="no (pthread.h not found)"]) + AC_CHECK_HEADERS(pthread.h,, [with_libpthread="no (pthread.h not found)"]) fi -if test "x$with_pthread" = "xyes" +if test "x$with_libpthread" = "xyes" then collect_pthread=1 else @@ -522,7 +530,7 @@ else fi AC_DEFINE_UNQUOTED(HAVE_LIBPTHREAD, [$collect_pthread], [Wether or not to use pthread (POSIX threads) library]) -AM_CONDITIONAL(BUILD_WITH_LIBPTHREAD, test "x$with_pthread" = "xyes") +AM_CONDITIONAL(BUILD_WITH_LIBPTHREAD, test "x$with_libpthread" = "xyes") if test "$ac_system" = "Solaris" then @@ -1003,6 +1011,7 @@ Configuration: libkstat . . . . . $with_kstat libmysql . . . . . $with_libmysql libpcap . . . . . . $with_libpcap + libpthread . . . . $with_libpthread Features: debug . . . . . . . $enable_debug diff --git a/src/dns.c b/src/dns.c index 61b5a1bd..b2039a72 100644 --- a/src/dns.c +++ b/src/dns.c @@ -25,30 +25,23 @@ #include "plugin.h" #include "configfile.h" #include "utils_debug.h" - -#if HAVE_PTHREAD_H -# include -#endif - -#if HAVE_SYS_POLL_H -# include -#endif +#include "utils_dns.h" #define MODULE_NAME "dns" -#if HAVE_LIBPCAP -# define NAMED_HAVE_CONFIG 1 -#else -# define NAMED_HAVE_CONFIG 0 -#endif - -#if HAVE_LIBPCAP && HAVE_PTHREAD_H -# include "utils_dns.h" -# define NAMED_HAVE_READ 1 +#if HAVE_LIBPCAP && HAVE_LIBPTHREAD +# include +# include +# include +# define DNS_HAVE_READ 1 #else -# define NAMED_HAVE_READ 0 +# define DNS_HAVE_READ 0 #endif +/* + * Private data types + */ +#if DNS_HAVE_READ struct counter_list_s { unsigned int key; @@ -56,7 +49,11 @@ struct counter_list_s struct counter_list_s *next; }; typedef struct counter_list_s counter_list_t; +#endif +/* + * Private variables + */ static char *traffic_file = "dns/dns_traffic.rrd"; static char *qtype_file = "dns/qtype-%s.rrd"; static char *opcode_file = "dns/opcode-%s.rrd"; @@ -92,9 +89,7 @@ static char *rcode_ds_def[] = }; static int rcode_ds_num = 1; -/* FIXME: Wouldn't other defines be better? -octo */ -#if NAMED_HAVE_CONFIG -#if HAVE_LIBPCAP +#if DNS_HAVE_READ static char *config_keys[] = { "Interface", @@ -102,10 +97,7 @@ static char *config_keys[] = NULL }; static int config_keys_num = 2; -#endif /* HAVE_LIBPCAP */ -#endif /* NAMED_HAVE_CONFIG */ -#if HAVE_LIBPCAP #define PCAP_SNAPLEN 1460 static char *pcap_device = NULL; @@ -114,9 +106,7 @@ static unsigned int tr_responses; static counter_list_t *qtype_list; static counter_list_t *opcode_list; static counter_list_t *rcode_list; -#endif -#if HAVE_PTHREAD_H static pthread_t listen_thread; static int listen_thread_init = 0; /* The `traffic' mutex if for `tr_queries' and `tr_responses' */ @@ -124,8 +114,12 @@ static pthread_mutex_t traffic_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t qtype_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t opcode_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t rcode_mutex = PTHREAD_MUTEX_INITIALIZER; -#endif +#endif /* DNS_HAVE_READ */ +/* + * Private functions + */ +#if DNS_HAVE_READ static counter_list_t *counter_list_search (counter_list_t **list, unsigned int key) { counter_list_t *entry; @@ -197,10 +191,8 @@ static void counter_list_add (counter_list_t **list, DBG ("return ()"); } -#if NAMED_HAVE_CONFIG static int dns_config (char *key, char *value) { -#if HAVE_LIBPCAP if (strcasecmp (key, "Interface") == 0) { if (pcap_device != NULL) @@ -219,9 +211,7 @@ static int dns_config (char *key, char *value) } return (0); -#endif /* HAVE_LIBPCAP */ } -#endif /* NAMED_HAVE_CONFIG */ static void dns_child_callback (const rfc1035_header_t *dns) { @@ -358,11 +348,11 @@ static void *dns_child_loop (void *dummy) return (NULL); } /* static void dns_child_loop (void) */ +#endif /* DNS_HAVE_READ */ static void dns_init (void) { -#if HAVE_LIBPCAP -#if HAVE_PTHREAD_H +#if DNS_HAVE_READ /* clean up an old thread */ int status; @@ -384,8 +374,7 @@ static void dns_init (void) } listen_thread_init = 1; -#endif -#endif +#endif /* DNS_HAVE_READ */ } static void traffic_write (char *host, char *inst, char *val) @@ -436,6 +425,7 @@ static void opcode_write (char *host, char *inst, char *val) rrd_update_file (host, file, val, opcode_ds_def, opcode_ds_num); } +#if DNS_HAVE_READ static void traffic_submit (unsigned int queries, unsigned int replies) { char buffer[64]; @@ -496,7 +486,6 @@ static void opcode_submit (int opcode, unsigned int counter) plugin_submit ("dns_opcode", inst, buffer); } -#if NAMED_HAVE_READ static void dns_read (void) { unsigned int keys[T_MAX]; @@ -560,7 +549,7 @@ static void dns_read (void) rcode_submit (keys[i], values[i]); } } -#else /* if !NAMED_HAVE_READ */ +#else /* if !DNS_HAVE_READ */ # define dns_read NULL #endif @@ -571,7 +560,9 @@ void module_register (void) plugin_register ("dns_qtype", NULL, NULL, qtype_write); plugin_register ("dns_rcode", NULL, NULL, rcode_write); plugin_register ("dns_opcode", NULL, NULL, opcode_write); +#if DNS_HAVE_READ cf_register (MODULE_NAME, dns_config, config_keys, config_keys_num); +#endif } #undef MODULE_NAME diff --git a/src/utils_dns.c b/src/utils_dns.c index 19afe55e..2f6c1912 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -33,39 +33,62 @@ * Florian octo Forster */ -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __APPLE__ -#include -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include +#include "collectd.h" + +#if HAVE_NETINET_IN_H +# include +#endif +#if HAVE_PCAP_H +# include +#endif +#if HAVE_ARPA_INET_H +# include +#endif + +#if HAVE_ARPA_NAMESER_H +# include +#elif HAVE_ARPA_NAMESER_COMPAT_H +# include +#endif + +#if HAVE_NET_IF_ARP_H +# include +#endif +#if HAVE_NET_IF_H +# include +#endif +#if HAVE_NETINET_IF_ETHER_H +# include +#endif +#if HAVE_NET_IF_PPP_H +# include +#endif + +#if HAVE_SYS_SOCKET_H +# include +#endif +#if HAVE_NETDB_H +# include +#endif + +#if HAVE_NETINET_IN_SYSTM_H +# include +#endif +#if HAVE_NETINET_IN_H +# include +#endif +#if HAVE_NETINET_IP_H +# include +#endif +#ifdef HAVE_NETINET_IP_VAR_H +# include +#endif +#if HAVE_NETINET_IP6_H +# include +#endif +#if HAVE_NETINET_UDP_H +# include +#endif #define PCAP_SNAPLEN 1460 #ifndef ETHER_HDR_LEN @@ -80,7 +103,6 @@ # define ETHERTYPE_IPV6 0x86DD #endif -#include #ifndef PPP_ADDRESS_VAL # define PPP_ADDRESS_VAL 0xff /* The address byte value */ #endif @@ -126,7 +148,9 @@ int qtype_counts[T_MAX]; int opcode_counts[OP_MAX]; int qclass_counts[C_MAX]; +#if HAVE_PCAP_H static pcap_t *pcap_obj = NULL; +#endif static ip_list_t *IgnoreList = NULL; @@ -232,10 +256,12 @@ static void in6_addr_from_buffer (struct in6_addr *ia, } } /* void in6_addr_from_buffer */ +#if HAVE_PCAP_H void dnstop_set_pcap_obj (pcap_t *po) { pcap_obj = po; } +#endif void dnstop_set_callback (void (*cb) (const rfc1035_header_t *)) { @@ -568,6 +594,7 @@ handle_ether(const u_char * pkt, int len) } /* public function */ +#if HAVE_PCAP_H void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt) { int status; @@ -615,6 +642,7 @@ void handle_pcap(u_char *udata, const struct pcap_pkthdr *hdr, const u_char *pkt query_count_total++; last_ts = hdr->ts; } +#endif const char *qtype_str(int t) { diff --git a/src/utils_dns.h b/src/utils_dns.h index 6a613a78..b3f08acd 100644 --- a/src/utils_dns.h +++ b/src/utils_dns.h @@ -33,8 +33,13 @@ * Florian octo Forster */ +#include "config.h" + #include -#include + +#if HAVE_PCAP_H +# include +#endif #define T_MAX 65536 #define OP_MAX 16 @@ -68,11 +73,15 @@ extern int qtype_counts[T_MAX]; extern int opcode_counts[OP_MAX]; extern int qclass_counts[C_MAX]; +#if HAVE_PCAP_H void dnstop_set_pcap_obj (pcap_t *po); +#endif void dnstop_set_callback (void (*cb) (const rfc1035_header_t *)); void ignore_list_add_name (const char *name); +#if HAVE_PCAP_H void handle_pcap (u_char * udata, const struct pcap_pkthdr *hdr, const u_char * pkt); +#endif const char *qtype_str(int t); const char *opcode_str(int o); -- 2.30.2