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) ...@@ -168,7 +168,7 @@ init_cache_map(void)
#ifdef USE_EVENTDNS #ifdef USE_EVENTDNS
/** Helper: called by eventdns when eventdns wants to log something. */ /** Helper: called by eventdns when eventdns wants to log something. */
static void static void
eventdns_log_cb(int warn, const char *msg) evdns_log_cb(int warn, const char *msg)
{ {
if (!strcmpstart(msg, "Resolve requested for") && if (!strcmpstart(msg, "Resolve requested for") &&
get_options()->SafeLogging) { get_options()->SafeLogging) {
...@@ -202,8 +202,8 @@ dns_reset(void) ...@@ -202,8 +202,8 @@ dns_reset(void)
#ifdef USE_EVENTDNS #ifdef USE_EVENTDNS
or_options_t *options = get_options(); or_options_t *options = get_options();
if (! server_mode(options)) { if (! server_mode(options)) {
eventdns_clear_nameservers_and_suspend(); evdns_clear_nameservers_and_suspend();
eventdns_search_clear(); evdns_search_clear();
nameservers_configured = 0; nameservers_configured = 0;
tor_free(resolv_conf_fname); tor_free(resolv_conf_fname);
resolv_conf_mtime = 0; resolv_conf_mtime = 0;
...@@ -1387,7 +1387,7 @@ dns_launch_wildcard_checks(void) ...@@ -1387,7 +1387,7 @@ dns_launch_wildcard_checks(void)
/** Eventdns helper: return true iff the eventdns result <b>err</b> is /** Eventdns helper: return true iff the eventdns result <b>err</b> is
* a transient failure. */ * a transient failure. */
static int static int
eventdns_err_is_transient(int err) evdns_err_is_transient(int err)
{ {
switch (err) switch (err)
{ {
...@@ -1442,7 +1442,7 @@ configure_nameservers(int force) ...@@ -1442,7 +1442,7 @@ configure_nameservers(int force)
conf_fname = "/etc/resolv.conf"; conf_fname = "/etc/resolv.conf";
#endif #endif
eventdns_set_log_fn(eventdns_log_cb); evdns_set_log_fn(evdns_log_cb);
if (conf_fname) { if (conf_fname) {
if (stat(conf_fname, &st)) { if (stat(conf_fname, &st)) {
log_warn(LD_EXIT, "Unable to stat resolver configuration in '%s'", log_warn(LD_EXIT, "Unable to stat resolver configuration in '%s'",
...@@ -1455,13 +1455,13 @@ configure_nameservers(int force) ...@@ -1455,13 +1455,13 @@ configure_nameservers(int force)
return 0; return 0;
} }
if (nameservers_configured) { if (nameservers_configured) {
eventdns_search_clear(); evdns_search_clear();
eventdns_clear_nameservers_and_suspend(); evdns_clear_nameservers_and_suspend();
} }
log_info(LD_EXIT, "Parsing resolver configuration in '%s'", conf_fname); 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; 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); log_warn(LD_EXIT, "Unable to find any nameservers in '%s'.", conf_fname);
return -1; return -1;
} }
...@@ -1469,26 +1469,26 @@ configure_nameservers(int force) ...@@ -1469,26 +1469,26 @@ configure_nameservers(int force)
resolv_conf_fname = tor_strdup(conf_fname); resolv_conf_fname = tor_strdup(conf_fname);
resolv_conf_mtime = st.st_mtime; resolv_conf_mtime = st.st_mtime;
if (nameservers_configured) if (nameservers_configured)
eventdns_resume(); evdns_resume();
} }
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
else { else {
if (nameservers_configured) { if (nameservers_configured) {
eventdns_search_clear(); evdns_search_clear();
eventdns_clear_nameservers_and_suspend(); evdns_clear_nameservers_and_suspend();
} }
if (eventdns_config_windows_nameservers()) { if (evdns_config_windows_nameservers()) {
log_warn(LD_EXIT,"Could not config nameservers."); log_warn(LD_EXIT,"Could not config nameservers.");
return -1; return -1;
} }
if (eventdns_count_nameservers() == 0) { if (evdns_count_nameservers() == 0) {
log_warn(LD_EXIT, "Unable to find any platform nameservers in " log_warn(LD_EXIT, "Unable to find any platform nameservers in "
"your Windows configuration. Perhaps you should list a " "your Windows configuration. Perhaps you should list a "
"ServerDNSResolvConfFile file in your torrc?"); "ServerDNSResolvConfFile file in your torrc?");
return -1; return -1;
} }
if (nameservers_configured) if (nameservers_configured)
eventdns_resume(); evdns_resume();
tor_free(resolv_conf_fname); tor_free(resolv_conf_fname);
resolv_conf_mtime = 0; resolv_conf_mtime = 0;
} }
...@@ -1502,7 +1502,7 @@ configure_nameservers(int force) ...@@ -1502,7 +1502,7 @@ configure_nameservers(int force)
* See eventdns.h for arguments; 'arg' holds the address we tried to resolve. * See eventdns.h for arguments; 'arg' holds the address we tried to resolve.
*/ */
static void 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) void *arg)
{ {
char *string_address = arg; char *string_address = arg;
...@@ -1554,7 +1554,7 @@ eventdns_callback(int result, char type, int count, int ttl, void *addresses, ...@@ -1554,7 +1554,7 @@ eventdns_callback(int result, char type, int count, int ttl, void *addresses,
escaped_safe_str(string_address)); escaped_safe_str(string_address));
} }
} else { } else {
if (eventdns_err_is_transient(result)) if (evdns_err_is_transient(result))
status = DNS_RESOLVE_FAILED_TRANSIENT; status = DNS_RESOLVE_FAILED_TRANSIENT;
} }
dns_found_answer(string_address, is_reverse, addr, hostname, status, ttl); 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) ...@@ -1583,13 +1583,13 @@ launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ)
if (r == 0) { if (r == 0) {
log_info(LD_EXIT, "Launching eventdns request for %s", log_info(LD_EXIT, "Launching eventdns request for %s",
escaped_safe_str(exitconn->_base.address)); escaped_safe_str(exitconn->_base.address));
r = eventdns_resolve_ipv4(exitconn->_base.address, options, r = evdns_resolve_ipv4(exitconn->_base.address, options,
eventdns_callback, addr); evdns_callback, addr);
} else if (r == 1) { } else if (r == 1) {
log_info(LD_EXIT, "Launching eventdns reverse request for %s", log_info(LD_EXIT, "Launching eventdns reverse request for %s",
escaped_safe_str(exitconn->_base.address)); escaped_safe_str(exitconn->_base.address));
r = eventdns_resolve_reverse(&in, DNS_QUERY_NO_SEARCH, r = evdns_resolve_reverse(&in, DNS_QUERY_NO_SEARCH,
eventdns_callback, addr); evdns_callback, addr);
} else if (r == -1) { } else if (r == -1) {
log_warn(LD_BUG, "Somehow a malformed in-addr.arpa address reached here."); 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) ...@@ -1598,7 +1598,7 @@ launch_resolve(edge_connection_t *exitconn, or_circuit_t *circ)
log_warn(LD_EXIT, "eventdns rejected address %s: error %d.", log_warn(LD_EXIT, "eventdns rejected address %s: error %d.",
escaped_safe_str(addr), r); escaped_safe_str(addr), r);
if (exitconn->_base.purpose == EXIT_PURPOSE_RESOLVE) { 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); send_resolved_cell(exitconn, circ, RESOLVED_TYPE_ERROR_TRANSIENT);
else { else {
exitconn->address_ttl = DEFAULT_DNS_TTL; exitconn->address_ttl = DEFAULT_DNS_TTL;
...@@ -1658,7 +1658,7 @@ wildcard_increment_answer(const char *id) ...@@ -1658,7 +1658,7 @@ wildcard_increment_answer(const char *id)
/** Callback function when we get an answer (possibly failing) for a request /** Callback function when we get an answer (possibly failing) for a request
* for a (hopefully) nonexistent domain. */ * for a (hopefully) nonexistent domain. */
static void 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) void *addresses, void *arg)
{ {
static int notice_given = 0; static int notice_given = 0;
...@@ -1704,8 +1704,8 @@ launch_wildcard_check(int min_len, int max_len, const char *suffix) ...@@ -1704,8 +1704,8 @@ launch_wildcard_check(int min_len, int max_len, const char *suffix)
strlcat(name, suffix, sizeof(name)); strlcat(name, suffix, sizeof(name));
addr = tor_strdup(name); addr = tor_strdup(name);
r = eventdns_resolve_ipv4(name, DNS_QUERY_NO_SEARCH, r = evdns_resolve_ipv4(name, DNS_QUERY_NO_SEARCH,
eventdns_wildcard_check_callback, addr); evdns_wildcard_check_callback, addr);
if (r) if (r)
tor_free(addr); tor_free(addr);
} }
......
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
* reformat the whitespace, add Tor dependencies, or so on. * reformat the whitespace, add Tor dependencies, or so on.
* *
* TODO: * TODO:
* - Support AAAA records * - Have a way to query for AAAA and A records simultaneously.
* - Have a way to query for AAAA and A records simultaneously. * - Improve request API.
* - Improve request API. * - (Can we suppress cnames? Should we?)
* - (Can we suppress cnames? Should we?) * - Replace all externally visible magic numbers with #defined constants.
* - Replace all externally visible magic numbers with #defined constants. * - Write documentation for APIs of all external functions.
* - Write documentation for APIs of all external functions.
*/ */
/* Async DNS Library /* Async DNS Library
* Adam Langley <agl@imperialviolet.org> * Adam Langley <agl@imperialviolet.org>
* http://www.imperialviolet.org/eventdns.html
* Public Domain code * Public Domain code
* *
* This software is Public Domain. To view a copy of the public domain dedication, * This software is Public Domain. To view a copy of the public domain dedication,
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* *
* I ask and expect, but do not require, that all derivative works contain an * I ask and expect, but do not require, that all derivative works contain an
* attribution similar to: * 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 * You may wish to replace the word "Parts" with something else depending on
* the amount of original code. * the amount of original code.
...@@ -59,16 +59,16 @@ ...@@ -59,16 +59,16 @@
* one of them. In increasing order of preference: * one of them. In increasing order of preference:
* *
* DNS_USE_GETTIMEOFDAY_FOR_ID: * DNS_USE_GETTIMEOFDAY_FOR_ID:
* Using the bottom 16 bits of the usec result from gettimeofday. This * Using the bottom 16 bits of the usec result from gettimeofday. This
* is a pretty poor solution but should work anywhere. * is a pretty poor solution but should work anywhere.
* DNS_USE_CPU_CLOCK_FOR_ID: * DNS_USE_CPU_CLOCK_FOR_ID:
* Using the bottom 16 bits of the nsec result from the CPU's time * Using the bottom 16 bits of the nsec result from the CPU's time
* counter. This is better, but may not work everywhere. Requires * counter. This is better, but may not work everywhere. Requires
* POSIX realtime support and you'll need to link against -lrt on * POSIX realtime support and you'll need to link against -lrt on
* glibc systems at least. * glibc systems at least.
* DNS_USE_OPENSSL_FOR_ID: * DNS_USE_OPENSSL_FOR_ID:
* Uses the OpenSSL RAND_bytes call to generate the data. You must * Uses the OpenSSL RAND_bytes call to generate the data. You must
* have seeded the pool before making any calls to this library. * have seeded the pool before making any calls to this library.
* *
* The library keeps track of the state of nameservers and will avoid * The library keeps track of the state of nameservers and will avoid
* them when they go down. Otherwise it will round robin between them. * them when they go down. Otherwise it will round robin between them.
...@@ -76,9 +76,9 @@ ...@@ -76,9 +76,9 @@
* Quick start guide: * Quick start guide:
* #include "eventdns.h" * #include "eventdns.h"
* void callback(int result, char type, int count, int ttl, * void callback(int result, char type, int count, int ttl,
* void *addresses, void *arg); * void *addresses, void *arg);
* eventdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf"); * evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
* eventdns_resolve("www.hostname.com", 0, callback, NULL); * evdns_resolve("www.hostname.com", 0, callback, NULL);
* *
* When the lookup is complete the callback function is called. The * When the lookup is complete the callback function is called. The
* first argument will be one of the DNS_ERR_* defines in eventdns.h. * first argument will be one of the DNS_ERR_* defines in eventdns.h.
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
* DNS_IPv4_A, count will be the number of IP addresses, ttl is the time * 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 * 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 * to an array of uint32_t's and arg will be whatever you passed to
* eventdns_resolve. * evdns_resolve.
* *
* Searching: * Searching:
* *
...@@ -97,24 +97,24 @@ ...@@ -97,24 +97,24 @@
* *
* Searching appears to be a single lookup from the point of view of the API, * 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 * 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. * of names.
* *
* To disable searching: * To disable searching:
* 1. Never set it up. If you never call eventdns_resolv_conf_parse or * 1. Never set it up. If you never call evdns_resolv_conf_parse or
* eventdns_search_add then no searching will occur. * evdns_search_add then no searching will occur.
* *
* 2. If you do call eventdns_resolv_conf_parse then don't pass * 2. If you do call evdns_resolv_conf_parse then don't pass
* DNS_OPTION_SEARCH (or DNS_OPTIONS_ALL, which implies it). * 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 * 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 * number is greater than the ndots setting then the names is first tried
* globally. Otherwise each search domain is appended in turn. * globally. Otherwise each search domain is appended in turn.
* *
* The ndots setting can either be set from a resolv.conf, or by calling * 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 * For example, with ndots set to 1 (the default) and a search domain list of
* ["myhome.net"]: * ["myhome.net"]:
...@@ -126,20 +126,20 @@ ...@@ -126,20 +126,20 @@
* *
* API reference: * 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 * Add a nameserver. The address should be an IP address in
* network byte order. The type of address is chosen so that * network byte order. The type of address is chosen so that
* it matches in_addr.s_addr. * it matches in_addr.s_addr.
* Returns non-zero on error. * 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 * This wraps the above function by parsing a string as an IP
* address and adds it as a nameserver. * address and adds it as a nameserver.
* Returns non-zero on error * Returns non-zero on error
* *
* int eventdns_resolve(const char *name, int flags, * int evdns_resolve(const char *name, int flags,
* eventdns_callback_type callback, * evdns_callback_type callback,
* void *ptr) * void *ptr)
* Resolve a name. The name parameter should be a DNS name. * Resolve a name. The name parameter should be a DNS name.
* The flags parameter should be 0, or DNS_QUERY_NO_SEARCH * The flags parameter should be 0, or DNS_QUERY_NO_SEARCH
* which disables searching for this query. (see defn of * which disables searching for this query. (see defn of
...@@ -151,37 +151,37 @@ ...@@ -151,37 +151,37 @@
* *
* Returns non-zero on error * Returns non-zero on error
* *
* void eventdns_search_clear() * void evdns_search_clear()
* Clears the list of search domains * 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 * 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 * Set the number of dots which, when found in a name, causes
* the first query to be without any search domain. * 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 * Return the number of configured nameservers (not necessarily the
* number of running nameservers). This is useful for double-checking * number of running nameservers). This is useful for double-checking
* whether our calls to the various nameserver configuration functions * whether our calls to the various nameserver configuration functions
* have been successful. * 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 * Remove all currently configured nameservers, and suspend all pending
* resolves. Resolves will not necessarily be re-attempted until * 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 * 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 * Attempt to configure a set of nameservers based on platform settings on
* a win32 host. Preferentially tries to use GetNetworkParams; if that fails, * a win32 host. Preferentially tries to use GetNetworkParams; if that fails,
* looks in the registry. Returns 0 on success, nonzero on failure. * 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. * Parse a resolv.conf like file from the given filename.
* *
* See the man page for resolv.conf for the format of this file. * See the man page for resolv.conf for the format of this file.
...@@ -283,8 +283,8 @@ ...@@ -283,8 +283,8 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
#define EVENTDNS_LOG_DEBUG 0 #define EVDNS_LOG_DEBUG 0
#define EVENTDNS_LOG_WARN 1 #define EVDNS_LOG_WARN 1
#ifndef HOST_NAME_MAX #ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255 #define HOST_NAME_MAX 255
...@@ -326,11 +326,11 @@ typedef unsigned int uint; ...@@ -326,11 +326,11 @@ typedef unsigned int uint;
struct request { struct request {
u8 *request; // the dns packet data u8 *request; // the dns packet data
unsigned int request_len; unsigned int request_len;
u8 reissue_count; int reissue_count;
u8 tx_count; // the number of times that this packet has been sent int tx_count; // the number of times that this packet has been sent
u8 request_type; // TYPE_PTR or TYPE_A unsigned int request_type; // TYPE_PTR or TYPE_A
void *user_pointer; // the pointer given to us for this request 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 struct nameserver *ns; // the server which we last sent it
// elements used by the searching code // elements used by the searching code
...@@ -350,8 +350,8 @@ struct request { ...@@ -350,8 +350,8 @@ struct request {
}; };
struct reply { struct reply {
u8 type; unsigned int type;
u8 have_answer; unsigned int have_answer;
union { union {
struct { struct {
u32 addrcount; u32 addrcount;
...@@ -395,8 +395,8 @@ static int global_requests_waiting = 0; ...@@ -395,8 +395,8 @@ static int global_requests_waiting = 0;
static int global_max_requests_inflight = 64; static int global_max_requests_inflight = 64;
static struct timeval global_timeout = {3, 0}; // 3 seconds 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 int 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_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 // number of timeouts in a row before we consider this server to be down
static int global_max_nameserver_timeout = 3; static int global_max_nameserver_timeout = 3;
...@@ -405,25 +405,26 @@ 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 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); 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 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 void nameserver_ready_callback(int fd, short events, void *arg);
static int eventdns_transmit(void); static int evdns_transmit(void);
static int eventdns_request_transmit(struct request *req); static int evdns_request_transmit(struct request *req);
static void nameserver_send_probe(struct nameserver *const ns); static void nameserver_send_probe(struct nameserver *const ns);
static void search_request_finished(struct request *const); static void search_request_finished(struct request *const);
static int search_try_next(struct request *const req); 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 int search_request_new(int type, const char *const name, int flags, evdns_callback_type user_callback, void *user_arg);
static void eventdns_requests_pump_waiting_queue(void); static void evdns_requests_pump_waiting_queue(void);
static u16 transaction_id_pick(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); static void request_submit(struct request *req);
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
static int static int
last_error(int sock) { last_error(int sock)
{
int optval, optvallen=sizeof(optval); int optval, optvallen=sizeof(optval);
int err = WSAGetLastError(); int err = WSAGetLastError();
if (err == WSAEWOULDBLOCK && sock >= 0) { if (err == WSAEWOULDBLOCK && sock >= 0) {
...@@ -437,11 +438,13 @@ last_error(int sock) { ...@@ -437,11 +438,13 @@ last_error(int sock) {
} }
static int static int
error_is_eagain(int err) { error_is_eagain(int err)
{
return err == EAGAIN || err == WSAEWOULDBLOCK; return err == EAGAIN || err == WSAEWOULDBLOCK;
} }
static int static int
inet_aton(const char *c, struct in_addr *addr) { inet_aton(const char *c, struct in_addr *addr)
{
uint32_t r; uint32_t r;
if (strcmp(c, "255.255.255.255") == 0) { if (strcmp(c, "255.255.255.255") == 0) {
addr->s_addr = 0xffffffffu; addr->s_addr = 0xffffffffu;
...@@ -465,7 +468,8 @@ inet_aton(const char *c, struct in_addr *addr) { ...@@ -465,7 +468,8 @@ inet_aton(const char *c, struct in_addr *addr) {
#ifndef NDEBUG #ifndef NDEBUG
static const char * static const char *
debug_ntoa(u32 address) { debug_ntoa(u32 address)
{
static char buf[32]; static char buf[32];
u32 a = ntohl(address); u32 a = ntohl(address);
sprintf(buf, "%d.%d.%d.%d", sprintf(buf, "%d.%d.%d.%d",
...@@ -477,25 +481,26 @@ debug_ntoa(u32 address) { ...@@ -477,25 +481,26 @@ debug_ntoa(u32 address) {
} }
#endif #endif
static eventdns_debug_log_fn_type eventdns_log_fn = NULL; static evdns_debug_log_fn_type evdns_log_fn = NULL;
void void
eventdns_set_log_fn(eventdns_debug_log_fn_type fn) { evdns_set_log_fn(evdns_debug_log_fn_type fn)
eventdns_log_fn = fn; {
evdns_log_fn = fn;
} }
#ifdef __GNUC__