X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/ff3b058ac51e9caf5cf1fd310b8a401a97a85582..e9b008053cd96b7893d720265d1afef0d6405945:/src/sar.c diff --git a/src/sar.c b/src/sar.c index 545c890..db9268a 100644 --- a/src/sar.c +++ b/src/sar.c @@ -5,7 +5,7 @@ * * srvx is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -24,6 +24,10 @@ #include "log.h" #include "timeq.h" +#if defined(HAVE_NETINET_IN_H) +# include /* sockaddr_in6 on some BSDs */ +#endif + static const char hexdigits[] = "0123456789abcdef"; struct dns_rr; @@ -255,7 +259,7 @@ sar_request_fail(struct sar_request *req, unsigned int rcode) sar_request_abort(req); } -static time_t next_sar_timeout; +static unsigned long next_sar_timeout; static void sar_timeout_cb(void *data) @@ -285,7 +289,7 @@ sar_timeout_cb(void *data) } static void -sar_check_timeout(time_t when) +sar_check_timeout(unsigned long when) { if (!next_sar_timeout || when < next_sar_timeout) { timeq_del(0, sar_timeout_cb, NULL, TIMEQ_IGNORE_WHEN | TIMEQ_IGNORE_DATA); @@ -628,7 +632,7 @@ sar_fd_readable(struct io_fd *fd) sprintf(id_text, "%d", hdr.id); req = dict_find(sar_requests, id_text, NULL); - log_module(sar_log, LOG_DEBUG, "sar_fd_readable(%p): hdr {id=%d, flags=0x%x, qdcount=%d, ancount=%d, nscount=%d, arcount=%d} -> req %p", fd, hdr.id, hdr.flags, hdr.qdcount, hdr.ancount, hdr.nscount, hdr.arcount, req); + log_module(sar_log, LOG_DEBUG, "sar_fd_readable(%p): hdr {id=%d, flags=0x%x, qdcount=%d, ancount=%d, nscount=%d, arcount=%d} -> req %p", (void*)fd, hdr.id, hdr.flags, hdr.qdcount, hdr.ancount, hdr.nscount, hdr.arcount, (void*)req); if (!req || !req->retries || !(hdr.flags & REQ_FLAG_QR)) { ns->resp_ignored++; return; @@ -1031,7 +1035,7 @@ sar_services_load_file(const char *etc_services) /* Set up canonical name-indexed service entry. */ canon = sar_service_byname(name, 1); if (canon->protos[proto].valid) { - log_module(sar_log, LOG_ERROR, "Service %s/%s listed twice.", name, port); + /* log_module(sar_log, LOG_ERROR, "Service %s/%s listed twice.", name, port); who cares? */ continue; } canon->protos[proto].canon = NULL; @@ -1076,8 +1080,19 @@ sar_services_init(const char *etc_services) struct service_byname *byname; unsigned int ii; + /* Forget old services dicts and allocate new ones. */ + dict_delete(services_byname); + services_byname = dict_new(); + dict_set_free_data(services_byname, free); + + dict_delete(services_byport); + services_byport = dict_new(); + dict_set_free_data(services_byport, free); + + /* Load the list from the services file. */ sar_services_load_file(etc_services); + /* Mark well-known services as using DNS-SD SRV records. */ for (ii = 0; tcp_srvs[ii]; ++ii) { byname = sar_service_byname(tcp_srvs[ii], 1); byname->protos[SERVICE_TCP].srv = 1; @@ -1122,7 +1137,7 @@ sar_getaddr_append(struct sar_getaddr_state *state, struct addrinfo *ai, int cop { unsigned int count; - log_module(sar_log, LOG_DEBUG, "sar_getaddr_append({full_name=%s}, ai=%p, copy=%d)", state->full_name, ai, copy); + log_module(sar_log, LOG_DEBUG, "sar_getaddr_append({full_name=%s}, ai=%p, copy=%d)", state->full_name, (void*)ai, copy); /* Set the appropriate pointer to the new element(s). */ if (state->ai_tail) @@ -1561,7 +1576,6 @@ sar_getname(const struct sockaddr *sa, unsigned int salen, int flags, sar_name_c if (flags & SNI_NUMERICHOST) { const char *servname; - unsigned int len; char host[SAR_NTOP_MAX], servbuf[16]; /* If appropriate, try to look up service name. */ @@ -1655,6 +1669,9 @@ ipv4_pton(struct sockaddr *sa, UNUSED_ARG(unsigned int socklen), unsigned int *b if (!pos) return 0; sa->sa_family = AF_INET; +#if defined(HAVE_SOCKADDR_SA_LEN) + sa->sa_len = sizeof(struct sockaddr_in); +#endif return pos; } @@ -1888,6 +1905,9 @@ ipv6_pton(struct sockaddr *sa, UNUSED_ARG(unsigned int socklen), unsigned int *b sin6->sin6_addr.s6_addr[cpos + jj] = 0; } sa->sa_family = AF_INET6; +#if defined(HAVE_SOCKADDR_SA_LEN) + sa->sa_len = sizeof(struct sockaddr_in6); +#endif return pos; } @@ -1995,6 +2015,8 @@ sar_cleanup(void) dict_delete(services_byport); dict_delete(sar_nameservers); dict_delete(sar_requests); + free_string_list(conf.sar_search); + free_string_list(conf.sar_nslist); } static void @@ -2028,12 +2050,6 @@ sar_init(void) sar_nameservers = dict_new(); dict_set_free_data(sar_nameservers, free); - services_byname = dict_new(); - dict_set_free_data(services_byname, free); - - services_byport = dict_new(); - dict_set_free_data(services_byport, free); - sar_register_helper(&sar_ipv4_helper); #if defined(AF_INET6) sar_register_helper(&sar_ipv6_helper);