#include "common.h"
#include "plugin.h"
-#include <poll.h>
#include "utils_dns.h"
+#include <poll.h>
#include <pcap.h>
static int select_numeric_qtype = 1;
#define PCAP_SNAPLEN 1460
-static char *pcap_device = NULL;
+static char *pcap_device;
static derive_t tr_queries;
static derive_t tr_responses;
static counter_list_t *rcode_list;
static pthread_t listen_thread;
-static int listen_thread_init = 0;
+static int listen_thread_init;
/* The `traffic' mutex if for `tr_queries' and `tr_responses' */
static pthread_mutex_t traffic_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t qtype_mutex = PTHREAD_MUTEX_INITIALIZER;
if (entry->key == key)
break;
- return (entry);
+ return entry;
}
static counter_list_t *counter_list_create(counter_list_t **list,
entry = calloc(1, sizeof(*entry));
if (entry == NULL)
- return (NULL);
+ return NULL;
entry->key = key;
entry->value = value;
last->next = entry;
}
- return (entry);
+ return entry;
}
static void counter_list_add(counter_list_t **list, unsigned int key,
if (pcap_device != NULL)
free(pcap_device);
if ((pcap_device = strdup(value)) == NULL)
- return (1);
+ return 1;
} else if (strcasecmp(key, "IgnoreSource") == 0) {
if (value != NULL)
ignore_list_add_name(value);
else
select_numeric_qtype = 1;
} else {
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
static void dns_child_callback(const rfc1035_header_t *dns) {
ERROR("dns plugin: Opening interface `%s' "
"failed: %s",
(pcap_device != NULL) ? pcap_device : "any", pcap_error);
- return (PCAP_ERROR);
+ return PCAP_ERROR;
}
status = pcap_compile(pcap_obj, &fp, "udp port 53", 1, 0);
if (status < 0) {
ERROR("dns plugin: pcap_compile failed: %s", pcap_statustostr(status));
- return (status);
+ return status;
}
status = pcap_setfilter(pcap_obj, &fp);
if (status < 0) {
ERROR("dns plugin: pcap_setfilter failed: %s", pcap_statustostr(status));
- return (status);
+ return status;
}
DEBUG("dns plugin: PCAP object created.");
status = PCAP_ERROR_IFACE_NOT_UP;
pcap_close(pcap_obj);
- return (status);
+ return status;
} /* int dns_run_pcap_loop */
static int dns_sleep_one_interval(void) /* {{{ */
if ((errno == EINTR) || (errno == EAGAIN))
continue;
- return (errno);
+ return errno;
}
- return (0);
+ return 0;
} /* }}} int dns_sleep_one_interval */
static void *dns_child_loop(__attribute__((unused)) void *dummy) /* {{{ */
ERROR("dns plugin: PCAP returned error %s.", pcap_statustostr(status));
listen_thread_init = 0;
- return (NULL);
+ return NULL;
} /* }}} void *dns_child_loop */
static int dns_init(void) {
pthread_mutex_unlock(&traffic_mutex);
if (listen_thread_init != 0)
- return (-1);
+ return -1;
status = plugin_thread_create(&listen_thread, NULL, dns_child_loop, (void *)0,
"dns listen");
if (status != 0) {
- char errbuf[1024];
- ERROR("dns plugin: pthread_create failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
- return (-1);
+ ERROR("dns plugin: pthread_create failed: %s", STRERRNO);
+ return -1;
}
listen_thread_init = 1;
}
#endif
- return (0);
+ return 0;
} /* int dns_init */
static void submit_derive(const char *type, const char *type_instance,
submit_derive("dns_rcode", rcode_str(keys[i]), values[i]);
}
- return (0);
+ return 0;
} /* int dns_read */
void module_register(void) {