Tor 0.4.9.0-alpha-dev
Macros | Functions | Variables
dns.c File Reference

Implements a local cache for DNS results for Tor servers. This is implemented as a wrapper around Adam Langley's eventdns.c code. (We can't just use gethostbyname() and friends because we really need to be nonblocking.) More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
#include "core/or/circuitlist.h"
#include "core/or/circuituse.h"
#include "core/or/connection_edge.h"
#include "core/or/policies.h"
#include "core/or/relay.h"
#include "feature/control/control_events.h"
#include "feature/relay/dns.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "feature/stats/rephist.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/evloop/compat_libevent.h"
#include "lib/sandbox/sandbox.h"
#include "core/or/edge_connection_st.h"
#include "core/or/or_circuit_st.h"
#include "core/or/conflux_util.h"
#include "ht.h"
#include <event2/event.h>
#include <event2/dns.h>

Go to the source code of this file.

Macros

#define DNS_PRIVATE
 
#define RESOLVE_MAX_TIMEOUT   300
 
#define assert_cache_ok()   STMT_NIL
 
#define RESOLVED_TYPE_AUTO   0xff
 
#define EXIT_DNS_TIMEOUT_DEFAULT   (1000)
 
#define EXIT_DNS_TIMEOUT_MIN   (1)
 
#define EXIT_DNS_TIMEOUT_MAX   (120000)
 
#define EXIT_DNS_NUM_ATTEMPTS_DEFAULT   (2)
 
#define EXIT_DNS_NUM_ATTEMPTS_MIN   (0)
 
#define EXIT_DNS_NUM_ATTEMPTS_MAX   (255)
 
#define SET(k, v)   evdns_base_set_option(the_evdns_base, (k), (v))
 
#define N_WILDCARD_CHECKS   2
 

Functions

static void purge_expired_resolves (time_t now)
 
static void dns_found_answer (const char *address, uint8_t query_type, int dns_answer, const tor_addr_t *addr, const char *hostname, uint32_t ttl)
 
static void add_wildcarded_test_address (const char *address)
 
static int configure_nameservers (int force)
 
static int answer_is_wildcarded (const char *ip)
 
static int evdns_err_is_transient (int err)
 
static void inform_pending_connections (cached_resolve_t *resolve)
 
static void make_pending_resolve_cached (cached_resolve_t *cached)
 
static void configure_libevent_options (void)
 
static void assert_resolve_ok (cached_resolve_t *resolve)
 
static HT_HEAD (cache_map, cached_resolve_t)
 
static unsigned int cached_resolve_hash (cached_resolve_t *a)
 
 HT_PROTOTYPE (cache_map, cached_resolve_t, node, cached_resolve_hash, cached_resolves_eq)
 
 HT_GENERATE2 (cache_map, cached_resolve_t, node, cached_resolve_hash, cached_resolves_eq, 0.6, tor_reallocarray_, tor_free_)
 
static void init_cache_map (void)
 
static void evdns_log_cb (int warn, const char *msg)
 
void dns_new_consensus_params (const networkstatus_t *ns)
 
int dns_init (void)
 
int dns_reset (void)
 
int has_dns_init_failed (void)
 
static void free_cached_resolve_ (cached_resolve_t *r)
 
static int compare_cached_resolves_by_expiry_ (const void *_a, const void *_b)
 
static void cached_resolve_add_answer (cached_resolve_t *resolve, int query_type, int dns_result, const tor_addr_t *answer_addr, const char *answer_hostname, uint32_t ttl)
 
static int cached_resolve_have_all_answers (const cached_resolve_t *resolve)
 
static void set_expiry (cached_resolve_t *resolve, time_t expires)
 
void dns_free_all (void)
 
STATIC void send_resolved_cell (edge_connection_t *conn, uint8_t answer_type, const cached_resolve_t *resolved)
 
void dns_send_resolved_error_cell (edge_connection_t *conn, uint8_t answer_type)
 
STATIC void send_resolved_hostname_cell (edge_connection_t *conn, const char *hostname)
 
int dns_resolve (edge_connection_t *exitconn)
 
STATIC int dns_resolve_impl (edge_connection_t *exitconn, int is_resolve, or_circuit_t *oncirc, char **hostname_out, int *made_connection_pending_out, cached_resolve_t **resolve_out)
 
STATIC int set_exitconn_info_from_resolve (edge_connection_t *exitconn, const cached_resolve_t *resolve, char **hostname_out)
 
void assert_connection_edge_not_dns_pending (edge_connection_t *conn)
 
void connection_dns_remove (edge_connection_t *conn)
 
STATIC void dns_cancel_pending_resolve (const char *address)
 
static int is_test_address (const char *address)
 
size_t number_of_configured_nameservers (void)
 
static const char * get_consensus_param_exit_dns_timeout (void)
 
static const char * get_consensus_param_exit_dns_attempts (void)
 
static void evdns_callback (int result, char type, int count, int ttl, void *addresses, void *arg)
 
static int launch_one_resolve (const char *address, uint8_t query_type, const tor_addr_t *ptr_address)
 
STATIC int launch_resolve (cached_resolve_t *resolve)
 
static void wildcard_increment_answer (const char *id)
 
static void evdns_wildcard_check_callback (int result, char type, int count, int ttl, void *addresses, void *arg)
 
static void launch_wildcard_check (int min_len, int max_len, int is_ipv6, const char *suffix)
 
static void launch_test_addresses (evutil_socket_t fd, short event, void *args)
 
static void dns_launch_wildcard_checks (void)
 
void dns_launch_correctness_checks (void)
 
int dns_seems_to_be_broken (void)
 
int dns_seems_to_be_broken_for_ipv6 (void)
 
void dns_reset_correctness_checks (void)
 
static int dns_cache_entry_count (void)
 
size_t dns_cache_total_allocation (void)
 
void dump_dns_mem_usage (int severity)
 
size_t dns_cache_handle_oom (time_t now, size_t min_remove_bytes)
 
cached_resolve_tdns_get_cache_entry (cached_resolve_t *query)
 
void dns_insert_cache_entry (cached_resolve_t *new_entry)
 

Variables

static struct evdns_base * the_evdns_base = NULL
 
static int nameservers_configured = 0
 
static int nameserver_config_failed = 0
 
static char * resolv_conf_fname = NULL
 
static time_t resolv_conf_mtime = 0
 
static smartlist_tcached_resolve_pqueue = NULL
 
static int n_wildcard_requests = 0
 
static strmap_t * dns_wildcard_response_count = NULL
 
static smartlist_tdns_wildcard_list = NULL
 
static int dns_wildcard_one_notice_given = 0
 
static int dns_wildcard_notice_given = 0
 
static smartlist_tdns_wildcarded_test_address_list = NULL
 
static int dns_wildcarded_test_address_notice_given = 0
 
static int dns_is_completely_invalid = 0
 

Detailed Description

Implements a local cache for DNS results for Tor servers. This is implemented as a wrapper around Adam Langley's eventdns.c code. (We can't just use gethostbyname() and friends because we really need to be nonblocking.)

There are three main cases when a Tor relay uses dns.c to launch a DNS request:

  1. To check whether the DNS server is working more or less correctly. This happens via dns_launch_correctness_checks(). The answer is reported in the return value from later calls to dns_seems_to_be_broken().
  2. When a client has asked the relay, in a RELAY_BEGIN cell, to connect to a given server by hostname. This happens via dns_resolve().
  3. When a client has asked the relay, in a RELAY_RESOLVE cell, to look up a given server's IP address(es) by hostname. This also happens via dns_resolve().

Each of these gets handled a little differently.

To check for correctness, we look up some hostname we expect to exist and have real entries, some hostnames which we expect to definitely not exist, and some hostnames that we expect to probably not exist. If too many of the hostnames that shouldn't exist do exist, that's a DNS hijacking attempt. If too many of the hostnames that should exist have the same addresses as the ones that shouldn't exist, that's a very bad DNS hijacking attempt, or a very naughty captive portal. And if the hostnames that should exist simply don't exist, we probably have a broken nameserver.

To handle client requests, we first check our cache for answers. If there isn't something up-to-date, we've got to launch A or AAAA requests as appropriate. How we handle responses to those in particular is a bit complex; see dns_lookup() and set_exitconn_info_from_resolve().

When a lookup is finally complete, the inform_pending_connections() function will tell all of the streams that have been waiting for the resolve, by calling connection_exit_connect() if the client sent a RELAY_BEGIN cell, and by calling send_resolved_cell() or send_hostname_cell() if the client sent a RELAY_RESOLVE cell.

Definition in file dns.c.

Macro Definition Documentation

◆ assert_cache_ok

#define assert_cache_ok ( )    STMT_NIL

Definition at line 121 of file dns.c.

◆ DNS_PRIVATE

#define DNS_PRIVATE

Definition at line 50 of file dns.c.

◆ N_WILDCARD_CHECKS

#define N_WILDCARD_CHECKS   2

Definition at line 2079 of file dns.c.

◆ RESOLVE_MAX_TIMEOUT

#define RESOLVE_MAX_TIMEOUT   300

How long will we wait for an answer from the resolver before we decide that the resolver is wedged?

Definition at line 87 of file dns.c.

◆ RESOLVED_TYPE_AUTO

#define RESOLVED_TYPE_AUTO   0xff

Definition at line 497 of file dns.c.

Function Documentation

◆ add_wildcarded_test_address()

static void add_wildcarded_test_address ( const char *  address)
static

Note that a single test address (one believed to be good) seems to be getting redirected to the same IP as failures are.

Definition at line 1929 of file dns.c.

◆ answer_is_wildcarded()

static int answer_is_wildcarded ( const char *  ip)
static

Return true iff we have noticed that the dotted-quad ip has been returned in response to requests for nonexistent hostnames.

Definition at line 2179 of file dns.c.

◆ assert_connection_edge_not_dns_pending()

void assert_connection_edge_not_dns_pending ( edge_connection_t conn)

Log an error and abort if conn is waiting for a DNS resolve.

Definition at line 966 of file dns.c.

Referenced by connection_unlink().

◆ assert_resolve_ok()

static void assert_resolve_ok ( cached_resolve_t resolve)
static

Exit with an assertion if resolve is corrupt.

Definition at line 2186 of file dns.c.

Referenced by HT_HEAD().

◆ cached_resolve_add_answer()

static void cached_resolve_add_answer ( cached_resolve_t resolve,
int  query_type,
int  dns_result,
const tor_addr_t answer_addr,
const char *  answer_hostname,
uint32_t  ttl 
)
static

Definition at line 316 of file dns.c.

◆ cached_resolve_hash()

static unsigned int cached_resolve_hash ( cached_resolve_t a)
inlinestatic

Hash function for cached_resolve objects

Definition at line 147 of file dns.c.

◆ cached_resolve_have_all_answers()

static int cached_resolve_have_all_answers ( const cached_resolve_t resolve)
static

Return true iff there are no in-flight requests for resolve.

Definition at line 368 of file dns.c.

◆ compare_cached_resolves_by_expiry_()

static int compare_cached_resolves_by_expiry_ ( const void *  _a,
const void *  _b 
)
static

Compare two cached_resolve_t pointers by expiry time, and return less-than-zero, zero, or greater-than-zero as appropriate. Used for the priority queue implementation.

Definition at line 300 of file dns.c.

Referenced by set_expiry().

◆ configure_libevent_options()

static void configure_libevent_options ( void  )
static

Configure the libevent options. This can safely be called after initialization or even if the evdns base is not set.

Definition at line 1432 of file dns.c.

Referenced by dns_new_consensus_params().

◆ configure_nameservers()

static int configure_nameservers ( int  force)
static

Configure eventdns nameservers if force is true, or if the configuration has changed since the last time we called this function, or if we failed on our last attempt. On Unix, this reads from /etc/resolv.conf or options->ServerDNSResolvConfFile; on Windows, this reads from options->ServerDNSResolvConfFile or the registry. Return 0 on success or -1 on failure.

Definition at line 1493 of file dns.c.

Referenced by dns_init().

◆ connection_dns_remove()

void connection_dns_remove ( edge_connection_t conn)

Remove conn from the list of connections waiting for conn->address.

Definition at line 993 of file dns.c.

Referenced by connection_exit_about_to_close().

◆ dns_cache_entry_count()

static int dns_cache_entry_count ( void  )
static

Return the number of DNS cache entries as an int

Definition at line 2210 of file dns.c.

Referenced by dump_dns_mem_usage().

◆ dns_cache_handle_oom()

size_t dns_cache_handle_oom ( time_t  now,
size_t  min_remove_bytes 
)

Definition at line 2243 of file dns.c.

◆ dns_cache_total_allocation()

size_t dns_cache_total_allocation ( void  )

Definition at line 2217 of file dns.c.

◆ dns_cancel_pending_resolve()

STATIC void dns_cancel_pending_resolve ( const char *  address)

Mark all connections waiting for address for close. Then cancel the resolve for address itself, and remove any cached results for address from the cache.

Definition at line 1048 of file dns.c.

◆ dns_found_answer()

static void dns_found_answer ( const char *  address,
uint8_t  query_type,
int  dns_answer,
const tor_addr_t addr,
const char *  hostname,
uint32_t  ttl 
)
static

Called on the OR side when the eventdns library tells us the outcome of a single DNS resolve: remember the answer, and tell all pending connections about the result of the lookup if the lookup is now done. (address is a NUL-terminated string containing the address to look up; query_type is one of DNS_{IPv4_A,IPv6_AAAA,PTR}; dns_answer is DNS_OK or one of DNS_ERR_*, addr is an IPv4 or IPv6 address if we got one; hostname is a hostname fora PTR request if we got one, and ttl is the time-to-live of this answer, in seconds.)

Definition at line 1138 of file dns.c.

◆ dns_free_all()

void dns_free_all ( void  )

Free all storage held in the DNS cache and related structures.

Definition at line 392 of file dns.c.

◆ dns_get_cache_entry()

cached_resolve_t * dns_get_cache_entry ( cached_resolve_t query)

Definition at line 2308 of file dns.c.

◆ dns_init()

int dns_init ( void  )

Initialize the DNS subsystem; called by the OR process.

Definition at line 233 of file dns.c.

Referenced by retry_dns_callback().

◆ dns_insert_cache_entry()

void dns_insert_cache_entry ( cached_resolve_t new_entry)

Definition at line 2314 of file dns.c.

◆ dns_launch_correctness_checks()

void dns_launch_correctness_checks ( void  )

If appropriate, start testing whether our DNS servers tend to lie to us.

Definition at line 2117 of file dns.c.

◆ dns_launch_wildcard_checks()

static void dns_launch_wildcard_checks ( void  )
static

Launch DNS requests for a few nonexistent hostnames and a few well-known hostnames, and see if we can catch our nameserver trying to hijack them and map them to a stupid "I couldn't find ggoogle.com but maybe you'd like to buy these lovely encyclopedias" page.

Definition at line 2086 of file dns.c.

Referenced by dns_launch_correctness_checks().

◆ dns_new_consensus_params()

void dns_new_consensus_params ( const networkstatus_t ns)

New consensus just appeared, take appropriate actions if need be.

Definition at line 220 of file dns.c.

◆ dns_reset()

int dns_reset ( void  )

Called when DNS-related options change (or may have changed). Returns -1 on failure, 0 on success.

Definition at line 246 of file dns.c.

◆ dns_reset_correctness_checks()

void dns_reset_correctness_checks ( void  )

Forget what we've previously learned about our DNS servers' correctness.

Definition at line 2153 of file dns.c.

Referenced by dns_servers_relaunch_checks().

◆ dns_resolve()

int dns_resolve ( edge_connection_t exitconn)

See if we have a cache entry for exitconn->address. If so, if resolve valid, put it into exitconn->addr and return 1. If resolve failed, free exitconn and return -1.

(For EXIT_PURPOSE_RESOLVE connections, send back a RESOLVED error cell on returning -1. For EXIT_PURPOSE_CONNECT connections, there's no need to send back an END cell, since connection_exit_begin_conn will do that for us.)

If we have a cached answer, send the answer back along exitconn's circuit.

Else, if seen before and pending, add conn to the pending list, and return 0.

Else, if not seen before, add conn to pending list, hand to dns farm, and return 0.

Exitconn's on_circuit field must be set, but exitconn should not yet be linked onto the n_streams/resolving_streams list of that circuit. On success, link the connection to n_streams if it's an exit connection. On "pending", link the connection to resolving streams. Otherwise, clear its on_circuit field.

Definition at line 632 of file dns.c.

◆ dns_resolve_impl()

STATIC int dns_resolve_impl ( edge_connection_t exitconn,
int  is_resolve,
or_circuit_t oncirc,
char **  hostname_out,
int *  made_connection_pending_out,
cached_resolve_t **  resolve_out 
)

Helper function for dns_resolve: same functionality, but does not handle:

  • marking connections on error and clearing their on_circuit
  • linking connections to n_streams/resolving_streams,
  • sending resolved cells if we have an answer/error right away,

Return -2 on a transient error. If it's a reverse resolve and it's successful, sets *hostname_out to a newly allocated string holding the cached reverse DNS value.

Set *made_connection_pending_out to true if we have placed exitconn on the list of pending connections for some resolve; set it to false otherwise.

Set *resolve_out to a cached resolve, if we found one.

Definition at line 719 of file dns.c.

Referenced by dns_resolve().

◆ dns_seems_to_be_broken()

int dns_seems_to_be_broken ( void  )

Return true iff our DNS servers lie to us too much to be trusted.

Definition at line 2139 of file dns.c.

◆ dns_seems_to_be_broken_for_ipv6()

int dns_seems_to_be_broken_for_ipv6 ( void  )

Return true iff we think that IPv6 hostname lookup is broken

Definition at line 2146 of file dns.c.

◆ dns_send_resolved_error_cell()

void dns_send_resolved_error_cell ( edge_connection_t conn,
uint8_t  answer_type 
)

Definition at line 567 of file dns.c.

◆ dump_dns_mem_usage()

void dump_dns_mem_usage ( int  severity)

Log memory information about our internal DNS cache at level 'severity'.

Definition at line 2225 of file dns.c.

Referenced by dumpmemusage().

◆ evdns_callback()

static void evdns_callback ( int  result,
char  type,
int  count,
int  ttl,
void *  addresses,
void *  arg 
)
static

For eventdns: Called when we get an answer for a request we launched. See eventdns.h for arguments; 'arg' holds the address we tried to resolve.

Definition at line 1627 of file dns.c.

◆ evdns_err_is_transient()

static int evdns_err_is_transient ( int  err)
static

Eventdns helper: return true iff the eventdns result err is a transient failure.

Definition at line 1332 of file dns.c.

◆ evdns_log_cb()

static void evdns_log_cb ( int  warn,
const char *  msg 
)
static

Helper: called by eventdns when eventdns wants to log something.

Definition at line 166 of file dns.c.

◆ evdns_wildcard_check_callback()

static void evdns_wildcard_check_callback ( int  result,
char  type,
int  count,
int  ttl,
void *  addresses,
void *  arg 
)
static

Callback function when we get an answer (possibly failing) for a request for a (hopefully) nonexistent domain.

Definition at line 1963 of file dns.c.

◆ free_cached_resolve_()

static void free_cached_resolve_ ( cached_resolve_t r)
static

Helper: free storage held by an entry in the DNS cache.

Definition at line 281 of file dns.c.

◆ get_consensus_param_exit_dns_attempts()

static const char * get_consensus_param_exit_dns_attempts ( void  )
static

Return a pointer to a stack allocated buffer containing the string representation of the exit_dns_num_attempts consensus parameter.

Definition at line 1413 of file dns.c.

◆ get_consensus_param_exit_dns_timeout()

static const char * get_consensus_param_exit_dns_timeout ( void  )
static

Return a pointer to a stack allocated buffer containing the string representation of the exit_dns_timeout consensus parameter.

Definition at line 1384 of file dns.c.

◆ has_dns_init_failed()

int has_dns_init_failed ( void  )

Return true iff the most recent attempt to initialize the DNS subsystem failed.

Definition at line 274 of file dns.c.

Referenced by retry_dns_callback().

◆ HT_HEAD()

static HT_HEAD ( cache_map  ,
cached_resolve_t   
)
static

Hash table of cached_resolve objects.

Definition at line 126 of file dns.c.

◆ inform_pending_connections()

static void inform_pending_connections ( cached_resolve_t resolve)
static

Given a pending cached_resolve_t that we just finished resolving, inform every connection that was waiting for the outcome of that resolution.

Do this by sending a RELAY_RESOLVED cell (if the pending stream had sent us a RELAY_RESOLVE cell), or by launching an exit connection (if the pending stream had sent us a RELAY_BEGIN cell).

Definition at line 1191 of file dns.c.

◆ init_cache_map()

static void init_cache_map ( void  )
static

Initialize the DNS cache.

Definition at line 159 of file dns.c.

Referenced by dns_init().

◆ is_test_address()

static int is_test_address ( const char *  address)
inlinestatic

Return true iff address is one of the addresses we use to verify that well-known sites aren't being hijacked by our DNS servers.

Definition at line 1121 of file dns.c.

◆ launch_one_resolve()

static int launch_one_resolve ( const char *  address,
uint8_t  query_type,
const tor_addr_t ptr_address 
)
static

Start a single DNS resolve for address (if query_type is DNS_IPv4_A or DNS_IPv6_AAAA) ptr_address (if query_type is DNS_PTR). Return 0 if we launched the request, -1 otherwise.

Definition at line 1751 of file dns.c.

◆ launch_resolve()

STATIC int launch_resolve ( cached_resolve_t resolve)

For eventdns: start resolving as necessary to find the target for exitconn. Returns -1 on error, -2 on transient error, 0 on "resolve launched."

Definition at line 1806 of file dns.c.

◆ launch_test_addresses()

static void launch_test_addresses ( evutil_socket_t  fd,
short  event,
void *  args 
)
static

Launch attempts to resolve a bunch of known-good addresses (configured in ServerDNSTestAddresses). [Callback for a libevent timer]

Definition at line 2046 of file dns.c.

◆ launch_wildcard_check()

static void launch_wildcard_check ( int  min_len,
int  max_len,
int  is_ipv6,
const char *  suffix 
)
static

Launch a single request for a nonexistent hostname consisting of between min_len and max_len random (plausible) characters followed by suffix

Definition at line 2012 of file dns.c.

◆ make_pending_resolve_cached()

static void make_pending_resolve_cached ( cached_resolve_t resolve)
static

Remove a pending cached_resolve_t from the hashtable, and add a corresponding cached cached_resolve_t.

This function is only necessary because of the perversity of our cache timeout code; see inline comment for ideas on eliminating it.

Definition at line 1276 of file dns.c.

◆ number_of_configured_nameservers()

size_t number_of_configured_nameservers ( void  )

Return number of configured nameservers in the_evdns_base.

Definition at line 1349 of file dns.c.

◆ purge_expired_resolves()

static void purge_expired_resolves ( time_t  now)
static

Remove every cached_resolve whose expire time is before or equal to now from the cache.

Definition at line 417 of file dns.c.

◆ send_resolved_cell()

STATIC void send_resolved_cell ( edge_connection_t conn,
uint8_t  answer_type,
const cached_resolve_t resolved 
)

Send a response to the RESOLVE request of a connection. answer_type must be one of RESOLVED_TYPE_(AUTO|ERROR|ERROR_TRANSIENT|).

If circ is provided, and we have a cached answer, send the answer back along circ; otherwise, send the answer back along conn's attached circuit.

Definition at line 509 of file dns.c.

Referenced by dns_resolve().

◆ send_resolved_hostname_cell()

STATIC void send_resolved_hostname_cell ( edge_connection_t conn,
const char *  hostname 
)

Send a response to the RESOLVE request of a connection for an in-addr.arpa address on connection conn which yielded the result hostname. The answer type will be RESOLVED_HOSTNAME.

If circ is provided, and we have a cached answer, send the answer back along circ; otherwise, send the answer back along conn's attached circuit.

Definition at line 582 of file dns.c.

Referenced by dns_resolve().

◆ set_exitconn_info_from_resolve()

STATIC int set_exitconn_info_from_resolve ( edge_connection_t exitconn,
const cached_resolve_t resolve,
char **  hostname_out 
)

Given an exit connection exitconn, and a cached_resolve_t resolve whose DNS lookups have all either succeeded or failed, update the appropriate fields (address_ttl and addr) of exitconn.

The logic can be complicated here, since we might have launched both an A lookup and an AAAA lookup, and since either of those might have succeeded or failed, and since we want to answer a RESOLVE cell with a full answer but answer a BEGIN cell with whatever answer the client would accept and we could still connect to.

If this is a reverse lookup, set *hostname_out to a newly allocated copy of the name resulting hostname.

Return -2 on a transient error, -1 on a permenent error, and 1 on a successful lookup.

Definition at line 871 of file dns.c.

Referenced by inform_pending_connections().

◆ set_expiry()

static void set_expiry ( cached_resolve_t resolve,
time_t  expires 
)
static

Set an expiry time for a cached_resolve_t, and add it to the expiry priority queue

Definition at line 378 of file dns.c.

◆ wildcard_increment_answer()

static void wildcard_increment_answer ( const char *  id)
static

Called when we see id (a dotted quad or IPv6 address) in response to a request for a hopefully bogus address.

Definition at line 1897 of file dns.c.

Variable Documentation

◆ cached_resolve_pqueue

smartlist_t* cached_resolve_pqueue = NULL
static

Priority queue of cached_resolve_t objects to let us know when they will expire.

Definition at line 313 of file dns.c.

Referenced by set_expiry().

◆ dns_is_completely_invalid

int dns_is_completely_invalid = 0
static

True iff all addresses seem to be getting wildcarded.

Definition at line 1892 of file dns.c.

Referenced by dns_seems_to_be_broken().

◆ dns_wildcard_list

smartlist_t* dns_wildcard_list = NULL
static

If present, a list of dotted-quad IP addresses that we are pretty sure our nameserver wants to return in response to requests for nonexistent domains.

Definition at line 1878 of file dns.c.

Referenced by answer_is_wildcarded().

◆ dns_wildcard_notice_given

int dns_wildcard_notice_given = 0
static

True iff we've warned that our DNS server is wildcarding too many failures.

Definition at line 1884 of file dns.c.

◆ dns_wildcard_one_notice_given

int dns_wildcard_one_notice_given = 0
static

True iff we've logged about a single address getting wildcarded. Subsequent warnings will be less severe.

Definition at line 1881 of file dns.c.

◆ dns_wildcard_response_count

strmap_t* dns_wildcard_response_count = NULL
static

Map from dotted-quad IP address in response to an int holding how many times we've seen it for a randomly generated (hopefully bogus) address. It would be easier to use definitely-invalid addresses (as specified by RFC2606), but see comment in dns_launch_wildcard_checks().

Definition at line 1873 of file dns.c.

Referenced by wildcard_increment_answer().

◆ dns_wildcarded_test_address_list

smartlist_t* dns_wildcarded_test_address_list = NULL
static

List of supposedly good addresses that are getting wildcarded to the same addresses as nonexistent addresses.

Definition at line 1888 of file dns.c.

Referenced by add_wildcarded_test_address().

◆ dns_wildcarded_test_address_notice_given

int dns_wildcarded_test_address_notice_given = 0
static

True iff we've warned about a test address getting wildcarded

Definition at line 1890 of file dns.c.

◆ n_wildcard_requests

int n_wildcard_requests = 0
static

How many requests for bogus addresses have we launched so far?

Definition at line 1867 of file dns.c.

◆ nameserver_config_failed

int nameserver_config_failed = 0
static

Did our most recent attempt to configure nameservers with eventdns fail?

Definition at line 95 of file dns.c.

Referenced by has_dns_init_failed().

◆ nameservers_configured

int nameservers_configured = 0
static

Have we currently configured nameservers with eventdns?

Definition at line 93 of file dns.c.

Referenced by launch_resolve().

◆ resolv_conf_fname

char* resolv_conf_fname = NULL
static

What was the resolv_conf fname we last used when configuring the nameservers? Used to check whether we need to reconfigure.

Definition at line 98 of file dns.c.

◆ resolv_conf_mtime

time_t resolv_conf_mtime = 0
static

What was the mtime on the resolv.conf file we last used when configuring the nameservers? Used to check whether we need to reconfigure.

Definition at line 101 of file dns.c.

◆ the_evdns_base

struct evdns_base* the_evdns_base = NULL
static

Our evdns_base; this structure handles all our name lookups.

Definition at line 90 of file dns.c.

Referenced by configure_libevent_options(), configure_nameservers(), dns_reset(), and number_of_configured_nameservers().