Commit 11b4296b authored by Nick Mathewson's avatar Nick Mathewson 🐻
Browse files

Marge changes from libevent evdns to our eventdns. Most are cosmetic, but one...

Marge changes from libevent evdns to our eventdns.  Most are cosmetic, but one or two are stability-related.  This should make it easier to push our changes back towards libevent.

svn:r8482
parent 564f2fae
......@@ -168,7 +168,7 @@ init_cache_map(void)
#ifdef USE_EVENTDNS
/** Helper: called by eventdns when eventdns wants to log something. */
static void
eventdns_log_cb(int warn, const char *msg)
evdns_log_cb(int warn, const char *msg)
{
if (!strcmpstart(msg, "Resolve requested for") &&
get_options()->SafeLogging) {
......@@ -202,8 +202,8 @@ dns_reset(void)
#ifdef USE_EVENTDNS
or_options_t *options = get_options();
if (! server_mode(options)) {
eventdns_clear_nameservers_and_suspend();
eventdns_search_clear();
evdns_clear_nameservers_and_suspend();
evdns_search_clear();
nameservers_configured = 0;
tor_free(resolv_conf_fname);
resolv_conf_mtime = 0;
......@@ -1387,7 +1387,7 @@ dns_launch_wildcard_checks(void)
/** Eventdns helper: return true iff the eventdns result <b>err</b> is
* a transient failure. */
static int
eventdns_err_is_transient(int err)
evdns_err_is_transient(int err)
{
switch (err)
{
......@@ -1442,7 +1442,7 @@ configure_nameservers(int force)
conf_fname = "/etc/resolv.conf";
#endif
eventdns_set_log_fn(eventdns_log_cb);
evdns_set_log_fn(evdns_log_cb);
if (conf_fname) {
if (stat(conf_fname, &st)) {
log_warn(LD_EXIT, "Unable to stat resolver configuration in '%s'",
......@@ -1455,13 +1455,13 @@ configure_nameservers(int force)
return 0;
}
if (nameservers_configured) {
eventdns_search_clear();
eventdns_clear_nameservers_and_suspend();
evdns_search_clear();
evdns_clear_nameservers_and_suspend();
}
log_info(LD_EXIT, "Parsing resolver configuration in '%s'", conf_fname);
if (eventdns_resolv_conf_parse(DNS_OPTIONS_ALL, conf_fname))
if (evdns_resolv_conf_parse(DNS_OPTIONS_ALL, conf_fname))
return -1;
if (eventdns_count_nameservers() == 0) {
if (evdns_count_nameservers() == 0) {
log_warn(LD_EXIT, "Unable to find any nameservers in '%s'.", conf_fname);
return -1;
}
......@@ -1469,26 +1469,26 @@ configure_nameservers(int force)
resolv_conf_fname = tor_strdup(conf_fname);
resolv_conf_mtime = st.st_mtime;
if (nameservers_configured)
eventdns_resume();
evdns_resume();
}
#ifdef MS_WINDOWS
else {
if (nameservers_configured) {
eventdns_search_clear();
eventdns_clear_nameservers_and_suspend();
evdns_search_clear();
evdns_clear_nameservers_and_suspend();
}
if (eventdns_config_windows_nameservers()) {
if (evdns_config_windows_nameservers()) {
log_warn(LD_EXIT,"Could not config nameservers.");
return -1;
}
if (eventdns_count_nameservers() == 0) {
if (evdns_count_nameservers() == 0) {
log_warn(LD_EXIT, "Unable to find any platform nameservers in "
"your Windows configuration. Perhaps you should list a "
"ServerDNSResolvConfFile file in your torrc?");
return -1;
}
if (nameservers_configured)
eventdns_resume();
evdns_resume();
tor_free(resolv_conf_fname);
resolv_conf_mtime = 0;
}
......@@ -1502,7 +1502,7 @@ configure_nameservers(int force)
* See eventdns.h for arguments; 'arg' holds the address we tried to resolve.
*/
static void
eventdns_callback(int result, char type, int count, int ttl, void *addresses,
evdns_callback(int result, char type, int count, int ttl, void *addresses,
void *arg)
{
char *string_address = arg;
......@@ -1554,7 +1554,7 @@ eventdns_callback(int result, char type, int count, int ttl, void *addresses,
escaped_safe_str(string_address));
}
} else {
if (eventdns_err_is_transient(result))
if (evdns_err_is_transient(result))
status = DNS_RESOLVE_FAILED_TRANSIENT;
}
dns_found_answer(string_address, is_reverse, addr, hostname, status, ttl);
......@@ -1583,13 +1583,13 @@ launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ)
if (r == 0) {
log_info(LD_EXIT, "Launching eventdns request for %s",
escaped_safe_str(exitconn->_base.address));
r = eventdns_resolve_ipv4(exitconn->_base.address, options,
eventdns_callback, addr);
r = evdns_resolve_ipv4(exitconn->_base.address, options,
evdns_callback, addr);
} else if (r == 1) {
log_info(LD_EXIT, "Launching eventdns reverse request for %s",
escaped_safe_str(exitconn->_base.address));
r = eventdns_resolve_reverse(&in, DNS_QUERY_NO_SEARCH,
eventdns_callback, addr);
r = evdns_resolve_reverse(&in, DNS_QUERY_NO_SEARCH,
evdns_callback, addr);
} else if (r == -1) {
log_warn(LD_BUG, "Somehow a malformed in-addr.arpa address reached here.");
}
......@@ -1598,7 +1598,7 @@ launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ)
log_warn(LD_EXIT, "eventdns rejected address %s: error %d.",
escaped_safe_str(addr), r);
if (exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE) {
if (eventdns_err_is_transient(r))
if (evdns_err_is_transient(r))
send_resolved_cell(exitconn, circ, RESOLVED_TYPE_ERROR_TRANSIENT);
else {
exitconn->address_ttl = DEFAULT_DNS_TTL;
......@@ -1658,7 +1658,7 @@ wildcard_increment_answer(const char *id)
/** Callback function when we get an answer (possibly failing) for a request
* for a (hopefully) nonexistent domain. */
static void
eventdns_wildcard_check_callback(int result, char type, int count, int ttl,
evdns_wildcard_check_callback(int result, char type, int count, int ttl,
void *addresses, void *arg)
{
static int notice_given = 0;
......@@ -1704,8 +1704,8 @@ launch_wildcard_check(int min_len, int max_len, const char *suffix)
strlcat(name, suffix, sizeof(name));
addr = tor_strdup(name);
r = eventdns_resolve_ipv4(name, DNS_QUERY_NO_SEARCH,
eventdns_wildcard_check_callback, addr);
r = evdns_resolve_ipv4(name, DNS_QUERY_NO_SEARCH,
evdns_wildcard_check_callback, addr);
if (r)
tor_free(addr);
}
......
......@@ -7,16 +7,16 @@
* reformat the whitespace, add Tor dependencies, or so on.
*
* TODO:
* - Support AAAA records
* - Have a way to query for AAAA and A records simultaneously.
* - Improve request API.
* - (Can we suppress cnames? Should we?)
* - Replace all externally visible magic numbers with #defined constants.
* - Write documentation for APIs of all external functions.
* - Have a way to query for AAAA and A records simultaneously.
* - Improve request API.
* - (Can we suppress cnames? Should we?)
* - Replace all externally visible magic numbers with #defined constants.
* - Write documentation for APIs of all external functions.
*/
/* Async DNS Library
* Adam Langley <agl@imperialviolet.org>
* http://www.imperialviolet.org/eventdns.html
* Public Domain code
*
* This software is Public Domain. To view a copy of the public domain dedication,
......@@ -25,7 +25,7 @@
*
* I ask and expect, but do not require, that all derivative works contain an
* attribution similar to:
* Parts developed by Adam Langley <agl@imperialviolet.org>
* Parts developed by Adam Langley <agl@imperialviolet.org>
*
* You may wish to replace the word "Parts" with something else depending on
* the amount of original code.
......@@ -59,16 +59,16 @@
* one of them. In increasing order of preference:
*
* DNS_USE_GETTIMEOFDAY_FOR_ID:
* Using the bottom 16 bits of the usec result from gettimeofday. This
* is a pretty poor solution but should work anywhere.
* Using the bottom 16 bits of the usec result from gettimeofday. This
* is a pretty poor solution but should work anywhere.
* DNS_USE_CPU_CLOCK_FOR_ID:
* Using the bottom 16 bits of the nsec result from the CPU's time
* counter. This is better, but may not work everywhere. Requires
* POSIX realtime support and you'll need to link against -lrt on
* glibc systems at least.
* Using the bottom 16 bits of the nsec result from the CPU's time
* counter. This is better, but may not work everywhere. Requires
* POSIX realtime support and you'll need to link against -lrt on
* glibc systems at least.
* DNS_USE_OPENSSL_FOR_ID:
* Uses the OpenSSL RAND_bytes call to generate the data. You must
* have seeded the pool before making any calls to this library.
* Uses the OpenSSL RAND_bytes call to generate the data. You must
* have seeded the pool before making any calls to this library.
*
* The library keeps track of the state of nameservers and will avoid
* them when they go down. Otherwise it will round robin between them.
......@@ -76,9 +76,9 @@
* Quick start guide:
* #include "eventdns.h"
* void callback(int result, char type, int count, int ttl,
* void *addresses, void *arg);
* eventdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
* eventdns_resolve("www.hostname.com", 0, callback, NULL);
* void *addresses, void *arg);
* evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
* evdns_resolve("www.hostname.com", 0, callback, NULL);
*
* When the lookup is complete the callback function is called. The
* first argument will be one of the DNS_ERR_* defines in eventdns.h.
......@@ -86,7 +86,7 @@
* DNS_IPv4_A, count will be the number of IP addresses, ttl is the time
* which the data can be cached for (in seconds), addresses will point
* to an array of uint32_t's and arg will be whatever you passed to
* eventdns_resolve.
* evdns_resolve.
*
* Searching:
*
......@@ -97,24 +97,24 @@
*
* Searching appears to be a single lookup from the point of view of the API,
* although many DNS queries may be generated from a single call to
* eventdns_resolve. Searching can also drastically slow down the resolution
* evdns_resolve. Searching can also drastically slow down the resolution
* of names.
*
* To disable searching:
* 1. Never set it up. If you never call eventdns_resolv_conf_parse or
* eventdns_search_add then no searching will occur.
* 1. Never set it up. If you never call evdns_resolv_conf_parse or
* evdns_search_add then no searching will occur.
*
* 2. If you do call eventdns_resolv_conf_parse then don't pass
* DNS_OPTION_SEARCH (or DNS_OPTIONS_ALL, which implies it).
* 2. If you do call evdns_resolv_conf_parse then don't pass
* DNS_OPTION_SEARCH (or DNS_OPTIONS_ALL, which implies it).
*
* 3. When calling eventdns_resolve, pass the DNS_QUERY_NO_SEARCH flag.
* 3. When calling evdns_resolve, pass the DNS_QUERY_NO_SEARCH flag.
*
* The order of searches depends on the number of dots in the name. If the
* number is greater than the ndots setting then the names is first tried
* globally. Otherwise each search domain is appended in turn.
*
* The ndots setting can either be set from a resolv.conf, or by calling
* eventdns_search_ndots_set.
* evdns_search_ndots_set.
*
* For example, with ndots set to 1 (the default) and a search domain list of
* ["myhome.net"]:
......@@ -126,20 +126,20 @@
*
* API reference:
*
* int eventdns_nameserver_add(unsigned long int address)
* int evdns_nameserver_add(unsigned long int address)
* Add a nameserver. The address should be an IP address in
* network byte order. The type of address is chosen so that
* it matches in_addr.s_addr.
* Returns non-zero on error.
*
* int eventdns_nameserver_ip_add(const char *ip_as_string)
* int evdns_nameserver_ip_add(const char *ip_as_string)
* This wraps the above function by parsing a string as an IP
* address and adds it as a nameserver.
* Returns non-zero on error
*
* int eventdns_resolve(const char *name, int flags,
* eventdns_callback_type callback,
* void *ptr)
* int evdns_resolve(const char *name, int flags,
* evdns_callback_type callback,
* void *ptr)
* Resolve a name. The name parameter should be a DNS name.
* The flags parameter should be 0, or DNS_QUERY_NO_SEARCH
* which disables searching for this query. (see defn of
......@@ -151,37 +151,37 @@
*
* Returns non-zero on error
*
* void eventdns_search_clear()
* void evdns_search_clear()
* Clears the list of search domains
*
* void eventdns_search_add(const char *domain)
* void evdns_search_add(const char *domain)
* Add a domain to the list of search domains
*
* void eventdns_search_ndots_set(int ndots)
* void evdns_search_ndots_set(int ndots)
* Set the number of dots which, when found in a name, causes
* the first query to be without any search domain.
*
* int eventdns_count_nameservers(void)
* int evdns_count_nameservers(void)
* Return the number of configured nameservers (not necessarily the
* number of running nameservers). This is useful for double-checking
* whether our calls to the various nameserver configuration functions
* have been successful.
*
* int eventdns_clear_nameservers_and_suspend(void)
* int evdns_clear_nameservers_and_suspend(void)
* Remove all currently configured nameservers, and suspend all pending
* resolves. Resolves will not necessarily be re-attempted until
* eventdns_resume() is called.
* evdns_resume() is called.
*
* int eventdns_resume(void)
* int evdns_resume(void)
* Re-attempt resolves left in limbo after an earlier call to
* eventdns_clear_nameservers_and_suspend().
* evdns_clear_nameservers_and_suspend().
*
* int eventdns_config_windows_nameservers(void)
* int evdns_config_windows_nameservers(void)
* Attempt to configure a set of nameservers based on platform settings on
* a win32 host. Preferentially tries to use GetNetworkParams; if that fails,
* looks in the registry. Returns 0 on success, nonzero on failure.
*
* int eventdns_resolv_conf_parse(int flags, const char *filename)
* int evdns_resolv_conf_parse(int flags, const char *filename)
* Parse a resolv.conf like file from the given filename.
*
* See the man page for resolv.conf for the format of this file.
......@@ -283,8 +283,8 @@
#include <arpa/inet.h>
#endif
#define EVENTDNS_LOG_DEBUG 0
#define EVENTDNS_LOG_WARN 1
#define EVDNS_LOG_DEBUG 0
#define EVDNS_LOG_WARN 1
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
......@@ -326,11 +326,11 @@ typedef unsigned int uint;
struct request {
u8 *request; // the dns packet data
unsigned int request_len;
u8 reissue_count;
u8 tx_count; // the number of times that this packet has been sent
u8 request_type; // TYPE_PTR or TYPE_A
int reissue_count;
int tx_count; // the number of times that this packet has been sent
unsigned int request_type; // TYPE_PTR or TYPE_A
void *user_pointer; // the pointer given to us for this request
eventdns_callback_type user_callback;
evdns_callback_type user_callback;
struct nameserver *ns; // the server which we last sent it
// elements used by the searching code
......@@ -350,8 +350,8 @@ struct request {
};
struct reply {
u8 type;
u8 have_answer;
unsigned int type;
unsigned int have_answer;
union {
struct {
u32 addrcount;
......@@ -395,8 +395,8 @@ static int global_requests_waiting = 0;
static int global_max_requests_inflight = 64;
static struct timeval global_timeout = {3, 0}; // 3 seconds
static u8 global_max_reissues = 1; // a reissue occurs when we get some errors from the server
static u8 global_max_retransmits = 3; // number of times we'll retransmit a request which timed out
static int global_max_reissues = 1; // a reissue occurs when we get some errors from the server
static int global_max_retransmits = 3; // number of times we'll retransmit a request which timed out
// number of timeouts in a row before we consider this server to be down
static int global_max_nameserver_timeout = 3;
......@@ -405,25 +405,26 @@ static int global_max_nameserver_timeout = 3;
static const struct timeval global_nameserver_timeouts[] = {{10, 0}, {60, 0}, {300, 0}, {900, 0}, {3600, 0}};
static const int global_nameserver_timeouts_length = sizeof(global_nameserver_timeouts)/sizeof(struct timeval);
const char *const eventdns_error_strings[] = {"no error", "The name server was unable to interpret the query", "The name server suffered an internal error", "The requested domain name does not exist", "The name server refused to reply to the request"};
const char *const evdns_error_strings[] = {"no error", "The name server was unable to interpret the query", "The name server suffered an internal error", "The requested domain name does not exist", "The name server refused to reply to the request"};
static struct nameserver *nameserver_pick(void);
static void eventdns_request_insert(struct request *req, struct request **head);
static void evdns_request_insert(struct request *req, struct request **head);
static void nameserver_ready_callback(int fd, short events, void *arg);
static int eventdns_transmit(void);
static int eventdns_request_transmit(struct request *req);
static int evdns_transmit(void);
static int evdns_request_transmit(struct request *req);
static void nameserver_send_probe(struct nameserver *const ns);
static void search_request_finished(struct request *const);
static int search_try_next(struct request *const req);
static int search_request_new(int type, const char *const name, int flags, eventdns_callback_type user_callback, void *user_arg);
static void eventdns_requests_pump_waiting_queue(void);
static int search_request_new(int type, const char *const name, int flags, evdns_callback_type user_callback, void *user_arg);
static void evdns_requests_pump_waiting_queue(void);
static u16 transaction_id_pick(void);
static struct request *request_new(int type, const char *name, int flags, eventdns_callback_type, void *ptr);
static struct request *request_new(int type, const char *name, int flags, evdns_callback_type, void *ptr);
static void request_submit(struct request *req);
#ifdef MS_WINDOWS
static int
last_error(int sock) {
last_error(int sock)
{
int optval, optvallen=sizeof(optval);
int err = WSAGetLastError();
if (err == WSAEWOULDBLOCK && sock >= 0) {
......@@ -437,11 +438,13 @@ last_error(int sock) {
}
static int
error_is_eagain(int err) {
error_is_eagain(int err)
{
return err == EAGAIN || err == WSAEWOULDBLOCK;
}
static int
inet_aton(const char *c, struct in_addr *addr) {
inet_aton(const char *c, struct in_addr *addr)
{
uint32_t r;
if (strcmp(c, "255.255.255.255") == 0) {
addr->s_addr = 0xffffffffu;
......@@ -465,7 +468,8 @@ inet_aton(const char *c, struct in_addr *addr) {
#ifndef NDEBUG
static const char *
debug_ntoa(u32 address) {
debug_ntoa(u32 address)
{
static char buf[32];
u32 a = ntohl(address);
sprintf(buf, "%d.%d.%d.%d",
......@@ -477,25 +481,26 @@ debug_ntoa(u32 address) {
}
#endif
static eventdns_debug_log_fn_type eventdns_log_fn = NULL;
static evdns_debug_log_fn_type evdns_log_fn = NULL;
void
eventdns_set_log_fn(eventdns_debug_log_fn_type fn) {
eventdns_log_fn = fn;
evdns_set_log_fn(evdns_debug_log_fn_type fn)
{
evdns_log_fn = fn;
}
#ifdef __GNUC__
#define EVENTDNS_LOG_CHECK __attribute__ ((format(printf, 2, 3)))
#define EVDNS_LOG_CHECK __attribute__ ((format(printf, 2, 3)))
#else
#define EVENTDNS_LOG_CHECK
#define EVDNS_LOG_CHECK
#endif
static void _eventdns_log(int warn, const char *fmt, ...) EVENTDNS_LOG_CHECK;
static void _evdns_log(int warn, const char *fmt, ...) EVDNS_LOG_CHECK;
static void
_eventdns_log(int warn, const char *fmt, ...) {
_evdns_log(int warn, const char *fmt, ...) {
va_list args;
static char buf[512];
if (!eventdns_log_fn)
if (!evdns_log_fn)
return;
va_start(args,fmt);
#ifdef MS_WINDOWS
......@@ -504,11 +509,11 @@ _eventdns_log(int warn, const char *fmt, ...) {
vsnprintf(buf, sizeof(buf), fmt, args);
#endif
buf[sizeof(buf)-1] = '\0';
eventdns_log_fn(warn, buf);
evdns_log_fn(warn, buf);
va_end(args);
}
#define log _eventdns_log
#define log _evdns_log
// This walks the list of inflight requests to find the
// one with a matching transaction id. Returns NULL on
......@@ -558,7 +563,7 @@ nameserver_probe_failed(struct nameserver *const ns) {
evtimer_set(&ns->timeout_event, nameserver_prod_callback, ns);
if (evtimer_add(&ns->timeout_event, (struct timeval *) timeout) < 0) {
log(EVENTDNS_LOG_WARN,
log(EVDNS_LOG_WARN,
"Error from libevent when adding timer event for %s",
debug_ntoa(ns->address));
// ???? Do more?
......@@ -574,12 +579,12 @@ nameserver_failed(struct nameserver *const ns, const char *msg) {
// then don't do anything
if (!ns->state) return;
log(EVENTDNS_LOG_WARN, "Nameserver %s has failed: %s",
log(EVDNS_LOG_WARN, "Nameserver %s has failed: %s",
debug_ntoa(ns->address), msg);
global_good_nameservers--;
assert(global_good_nameservers >= 0);
if (global_good_nameservers == 0) {
log(EVENTDNS_LOG_WARN, "All nameservers have failed");
log(EVDNS_LOG_WARN, "All nameservers have failed");
}
ns->state = 0;
......@@ -587,7 +592,7 @@ nameserver_failed(struct nameserver *const ns, const char *msg) {
evtimer_set(&ns->timeout_event, nameserver_prod_callback, ns);
if (evtimer_add(&ns->timeout_event, (struct timeval *) &global_nameserver_timeouts[0]) < 0) {
log(EVENTDNS_LOG_WARN,
log(EVDNS_LOG_WARN,
"Error from libevent when adding timer event for %s",
debug_ntoa(ns->address));
// ???? Do more?
......@@ -618,7 +623,7 @@ nameserver_failed(struct nameserver *const ns, const char *msg) {
static void
nameserver_up(struct nameserver *const ns) {
if (ns->state) return;
log(EVENTDNS_LOG_WARN, "Nameserver %s is back up",
log(EVDNS_LOG_WARN, "Nameserver %s is back up",
debug_ntoa(ns->address));
evtimer_del(&ns->timeout_event);
ns->state = 1;
......@@ -648,7 +653,7 @@ request_finished(struct request *const req, struct request **head) {
}
}
log(EVENTDNS_LOG_DEBUG, "Removing timeout for request %lx",
log(EVDNS_LOG_DEBUG, "Removing timeout for request %lx",
(unsigned long) req);
evtimer_del(&req->timeout_event);
......@@ -665,7 +670,7 @@ request_finished(struct request *const req, struct request **head) {
free(req);
eventdns_requests_pump_waiting_queue();
evdns_requests_pump_waiting_queue();
}
// This is called when a server returns a funny error code.
......@@ -698,7 +703,7 @@ request_reissue(struct request *req) {
// this function looks for space on the inflight queue and promotes
// requests from the waiting queue if it can.
static void
eventdns_requests_pump_waiting_queue(void) {
evdns_requests_pump_waiting_queue(void) {
while (global_requests_inflight < global_max_requests_inflight &&
global_requests_waiting) {
struct request *req;
......@@ -721,9 +726,9 @@ eventdns_requests_pump_waiting_queue(void) {
req->ns = nameserver_pick();
request_trans_id_set(req, transaction_id_pick());
eventdns_request_insert(req, &req_head);
eventdns_request_transmit(req);
eventdns_transmit();
evdns_request_insert(req, &req_head);
evdns_request_transmit(req);
evdns_transmit();
}
}
......@@ -986,7 +991,8 @@ transaction_id_pick(void) {
#ifdef DNS_USE_CPU_CLOCK_FOR_ID
struct timespec ts;
const u16 trans_id = ts.tv_nsec & 0xffff;
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts)) abort();
if (clock_gettime(CLOCK_MONOTONIC, &ts))
abort();
#endif
#ifdef DNS_USE_GETTIMEOFDAY_FOR_ID
......@@ -1087,7 +1093,7 @@ nameserver_write_waiting(struct nameserver *ns, char waiting) {
event_set(&ns->event, ns->socket, EV_READ | (waiting ? EV_WRITE : 0) | EV_PERSIST,
nameserver_ready_callback, ns);
if (event_add(&ns->event, NULL) < 0) {
log(EVENTDNS_LOG_WARN, "Error from libevent when adding event for %s",
log(EVDNS_LOG_WARN, "Error from libevent when adding event for %s",
debug_ntoa(ns->address));
// ???? Do more?
}
......@@ -1102,7 +1108,7 @@ nameserver_ready_callback(int fd, short events, void *arg) {
if (events & EV_WRITE) {
ns->choaked = 0;
if (!eventdns_transmit()) {
if (!evdns_transmit()) {
nameserver_write_waiting(ns, 0);
}
}
......@@ -1163,20 +1169,20 @@ dnsname_to_labels(u8 *const buf, const char *name, const int name_len) {
// length. The actual request may be smaller than the value returned
// here
static int
eventdns_request_len(const int name_len) {
evdns_request_len(const int name_len) {
return 96 + // length of the DNS standard header
name_len + 2 +
4; // space for the resource type
}
// build a dns request packet into buf. buf should be at least as long
// as eventdns_request_len told you it should be.
// as evdns_request_len told you it should be.
//
// Returns the amount of space used. Negative on error.
static int
eventdns_request_data_build(const char *const name, const int name_len, const u16 trans_id,
evdns_request_data_build(const char *const name, const int name_len, const u16 trans_id,
const u16 type, const u16 class,
u8 *const buf) {
u8 *const buf, size_t buf_len) {
int j = 0; // current offset into buf
u16 _t; // used by the macros
u8 *labels;
......@@ -1191,12 +1197,17 @@ eventdns_request_data_build(const char *const name, const int name_len, const u1
APPEND16(0); // no additional
labels = (u8 *) malloc(name_len + 2);
if (!labels) return -1;
if (labels == NULL)
return -1;
labels_len = dnsname_to_labels(labels, name, name_len);
if (labels_len < 0) {
free(labels);
return labels_len;
}
if (j + labels_len > buf_len) {
free(labels);
return (-1);
}
memcpy(buf + j, labels, labels_len);
j += labels_len;
free(labels);
......@@ -1211,12 +1222,12 @@ eventdns_request_data_build(const char *const name, const int name_len, const u1
// this is a libevent callback function which is called when a request
// has timed out.
static void
eventdns_request_timeout_callback(int fd, short events, void *arg) {
evdns_request_timeout_callback(int fd, short events, void *arg) {
struct request *const req = (struct request *) arg;
(void) fd;
(void) events;
log(EVENTDNS_LOG_DEBUG, "Request %lx timed out", (unsigned long) arg);