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);
} }
......
This diff is collapsed.
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#define DNS_ERR_TIMEOUT 67 #define DNS_ERR_TIMEOUT 67
#define DNS_IPv4_A 1 #define DNS_IPv4_A 1
#define DNS_PTR 2 /* XXXX ???? */ #define DNS_PTR 2
#define DNS_QUERY_NO_SEARCH 1 #define DNS_QUERY_NO_SEARCH 1
...@@ -47,26 +47,27 @@ ...@@ -47,26 +47,27 @@
#define DNS_OPTION_MISC 4 #define DNS_OPTION_MISC 4
#define DNS_OPTIONS_ALL 7 #define DNS_OPTIONS_ALL 7
typedef void (*eventdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg); typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
int eventdns_nameserver_add(unsigned long int address); int evdns_init(void);
int eventdns_count_nameservers(void); int evdns_nameserver_add(unsigned long int address);
int eventdns_clear_nameservers_and_suspend(void); int evdns_count_nameservers(void);
int eventdns_resume(void); int evdns_clear_nameservers_and_suspend(void);
int eventdns_nameserver_ip_add(const char *ip_as_string); int evdns_resume(void);
int eventdns_resolve_ipv4(const char *name, int flags, eventdns_callback_type callback, void *ptr); int evdns_nameserver_ip_add(const char *ip_as_string);
int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr);
struct in_addr; struct in_addr;
int eventdns_resolve_reverse(struct in_addr *addr, int flags, eventdns_callback_type callback, void *ptr); int evdns_resolve_reverse(struct in_addr *addr, int flags, evdns_callback_type callback, void *ptr);
int eventdns_resolv_conf_parse(int flags, const char *); int evdns_resolv_conf_parse(int flags, const char *);
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
int eventdns_config_windows_nameservers(void); int evdns_config_windows_nameservers(void);
#endif #endif
void eventdns_search_clear(void); void evdns_search_clear(void);
void eventdns_search_add(const char *domain); void evdns_search_add(const char *domain);
void eventdns_search_ndots_set(const int ndots); void evdns_search_ndots_set(const int ndots);
typedef void (*eventdns_debug_log_fn_type)(int warn, const char *msg); typedef void (*evdns_debug_log_fn_type)(int warn, const char *msg);
void eventdns_set_log_fn(eventdns_debug_log_fn_type fn); void evdns_set_log_fn(evdns_debug_log_fn_type fn);
#define DNS_NO_SEARCH 1 #define DNS_NO_SEARCH 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment