#include "or.h"
#include "ht.h"
#include <event.h>
#include "eventdns.h"
Data Structures | |
struct | pending_connection_t |
struct | cached_resolve_t |
Defines | |
#define | evdns_base_new(x, y) tor_malloc(1) |
#define | evdns_base_clear_nameservers_and_suspend(base) evdns_clear_nameservers_and_suspend() |
#define | evdns_base_search_clear(base) evdns_search_clear() |
#define | evdns_base_set_default_outgoing_bind_address(base, a, len) evdns_set_default_outgoing_bind_address((a),(len)) |
#define | evdns_base_resolv_conf_parse(base, options, fname) evdns_resolv_conf_parse((options), (fname)) |
#define | evdns_base_count_nameservers(base) evdns_count_nameservers() |
#define | evdns_base_resume(base) evdns_resume() |
#define | evdns_base_config_windows_nameservers(base) evdns_config_windows_nameservers() |
#define | evdns_base_set_option_(base, opt, val) evdns_set_option((opt),(val),DNS_OPTIONS_ALL) |
#define | evdns_base_resolve_ipv4(base, addr, options, cb, ptr) ((evdns_resolve_ipv4(addr, options, cb, ptr)<0) ? NULL : ((void*)1)) |
#define | evdns_base_resolve_reverse(base, addr, options, cb, ptr) ((evdns_resolve_reverse(addr, options, cb, ptr)<0) ? NULL : ((void*)1)) |
#define | evdns_base_resolve_reverse_ipv6(base, addr, options, cb, ptr) ((evdns_resolve_reverse_ipv6(addr, options, cb, ptr)<0) ? NULL : ((void*)1)) |
#define | MAX_ADDRESSLEN 256 |
#define | RESOLVE_MAX_TIMEOUT 300 |
#define | DNS_RESOLVE_FAILED_TRANSIENT 1 |
#define | DNS_RESOLVE_FAILED_PERMANENT 2 |
#define | DNS_RESOLVE_SUCCEEDED 3 |
#define | CACHED_RESOLVE_MAGIC 0x1234F00D |
#define | CACHE_STATE_PENDING 0 |
#define | CACHE_STATE_DONE 1 |
#define | CACHE_STATE_CACHED_VALID 2 |
#define | CACHE_STATE_CACHED_FAILED 3 |
#define | assert_cache_ok() STMT_NIL |
#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 is_reverse, uint32_t addr, const char *hostname, char outcome, uint32_t ttl) |
static void | send_resolved_cell (edge_connection_t *conn, uint8_t answer_type) |
static int | launch_resolve (edge_connection_t *exitconn) |
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 | dns_resolve_impl (edge_connection_t *exitconn, int is_resolve, or_circuit_t *oncirc, char **resolved_to_hostname) |
static void | assert_resolve_ok (cached_resolve_t *resolve) |
static | HT_HEAD (cache_map, cached_resolve_t) |
static INLINE unsigned int | cached_resolve_hash (cached_resolve_t *a) |
HT_PROTOTYPE (HT_GENERATE(cache_map, HT_GENERATE(cached_resolve_t, HT_GENERATE(node, HT_GENERATE(cached_resolve_hash, HT_GENERATE(cached_resolves_eq) | |
static void | evdns_log_cb (int warn, const char *msg) |
static void | _dns_randfn (char *b, size_t n) |
int | dns_init (void) |
int | dns_reset (void) |
int | has_dns_init_failed (void) |
uint32_t | dns_clip_ttl (uint32_t ttl) |
static uint32_t | dns_get_expiry_ttl (uint32_t ttl) |
static void | _free_cached_resolve (cached_resolve_t *r) |
static int | _compare_cached_resolves_by_expiry (const void *_a, const void *_b) |
static void | set_expiry (cached_resolve_t *resolve, time_t expires) |
void | dns_free_all (void) |
static void | send_resolved_hostname_cell (edge_connection_t *conn, const char *hostname) |
int | dns_resolve (edge_connection_t *exitconn) |
void | assert_connection_edge_not_dns_pending (edge_connection_t *conn) |
void | assert_all_pending_dns_resolves_ok (void) |
void | connection_dns_remove (edge_connection_t *conn) |
void | dns_cancel_pending_resolve (const char *address) |
static void | add_answer_to_cache (const char *address, uint8_t is_reverse, uint32_t addr, const char *hostname, char outcome, uint32_t ttl) |
static INLINE int | is_test_address (const char *address) |
static int | evdns_err_is_transient (int err) |
static void | evdns_callback (int result, char type, int count, int ttl, void *addresses, void *arg) |
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, const char *suffix) |
static void | launch_test_addresses (int 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) |
void | dns_reset_correctness_checks (void) |
static int | dns_cache_entry_count (void) |
void | dump_dns_mem_usage (int severity) |
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_t * | cached_resolve_pqueue = NULL |
static int | n_wildcard_requests = 0 |
static strmap_t * | dns_wildcard_response_count = NULL |
static smartlist_t * | dns_wildcard_list = NULL |
static int | dns_wildcard_one_notice_given = 0 |
static int | dns_wildcard_notice_given = 0 |
static smartlist_t * | dns_wildcarded_test_address_list = NULL |
static int | dns_wildcarded_test_address_notice_given = 0 |
static int | dns_is_completely_invalid = 0 |
#define CACHE_STATE_CACHED_FAILED 3 |
We are caching a failure for this address. This should have no pending connections, and should appear in the hash table
Referenced by add_answer_to_cache(), dns_resolve_impl(), and purge_expired_resolves().
#define CACHE_STATE_CACHED_VALID 2 |
We are caching an answer for this address. This should have no pending connections, and should appear in the hash table.
Referenced by add_answer_to_cache(), dns_resolve_impl(), and purge_expired_resolves().
#define CACHE_STATE_DONE 1 |
This used to be a pending cached_resolve_t, and we got an answer for it. Now we're waiting for this cached_resolve_t to expire. This should have no pending connections, and should not appear in the hash table.
Referenced by assert_resolve_ok(), dns_cancel_pending_resolve(), dns_found_answer(), dns_free_all(), dns_resolve_impl(), and purge_expired_resolves().
#define CACHE_STATE_PENDING 0 |
We are waiting for the resolver system to tell us an answer here. When we get one, or when we time out, the state of this cached_resolve_t will become "DONE" and we'll possibly add a CACHED_VALID or a CACHED_FAILED entry. This cached_resolve_t will be in the hash table so that we will know not to launch more requests for this addr, but rather to add more connections to the pending list for the addr.
Referenced by assert_resolve_ok(), dns_cancel_pending_resolve(), dns_found_answer(), dns_resolve_impl(), and purge_expired_resolves().
#define CACHED_RESOLVE_MAGIC 0x1234F00D |
Value of 'magic' field for cached_resolve_t. Used to try to catch bad pointers and memory stomping.
Referenced by add_answer_to_cache(), assert_resolve_ok(), and dns_resolve_impl().
#define DNS_RESOLVE_FAILED_TRANSIENT 1 |
Possible outcomes from hostname lookup: permanent failure, transient (retryable) failure, and success.
Referenced by add_answer_to_cache(), and evdns_callback().
#define MAX_ADDRESSLEN 256 |
Longest hostname we're willing to resolve.
Referenced by assert_resolve_ok(), and HT_HEAD().
#define RESOLVE_MAX_TIMEOUT 300 |
How long will we wait for an answer from the resolver before we decide that the resolver is wedged?
Referenced by dns_resolve_impl().
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.
References cached_resolve_t::expire.
Referenced by purge_expired_resolves(), and set_expiry().
static void _dns_randfn | ( | char * | b, | |
size_t | n | |||
) | [static] |
Helper: passed to eventdns.c as a callback so it can generate random numbers for transaction IDs and 0x20-hack coding.
References crypto_rand().
Referenced by dns_init().
static void _free_cached_resolve | ( | cached_resolve_t * | r | ) | [static] |
Helper: free storage held by an entry in the DNS cache.
References cached_resolve_t::is_reverse, pending_connection_t::next, cached_resolve_t::pending_connections, cached_resolve_t::result, and tor_free.
Referenced by dns_free_all().
static void add_answer_to_cache | ( | const char * | address, | |
uint8_t | is_reverse, | |||
uint32_t | addr, | |||
const char * | hostname, | |||
char | outcome, | |||
uint32_t | ttl | |||
) | [static] |
Helper: adds an entry to the DNS cache mapping address to the ipv4 address addr (if is_reverse is 0) or the hostname hostname (if is_reverse is 1). ttl is a cache ttl; outcome is one of DNS_RESOLVE_{FAILED_TRANSIENT|FAILED_PERMANENT|SUCCEEDED}.
References assert_resolve_ok(), CACHE_STATE_CACHED_FAILED, CACHE_STATE_CACHED_VALID, CACHED_RESOLVE_MAGIC, dns_get_expiry_ttl(), DNS_RESOLVE_FAILED_TRANSIENT, cached_resolve_t::is_reverse, cached_resolve_t::result, set_expiry(), cached_resolve_t::state, tor_assert, and cached_resolve_t::ttl.
Referenced by dns_found_answer().
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.
References control_event_server_status(), dns_is_completely_invalid, dns_wildcarded_test_address_notice_given, get_options(), mark_my_descriptor_dirty(), or_options_t::ServerDNSTestAddresses, smartlist_add(), smartlist_create(), and smartlist_string_isin_case().
Referenced by evdns_callback().
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.
References smartlist_string_isin().
Referenced by evdns_callback().
void assert_all_pending_dns_resolves_ok | ( | void | ) |
Log an error and abort if any connection waiting for a DNS resolve is corrupted.
References edge_connection_t::_base, assert_connection_ok(), pending_connection_t::conn, connection_in_array(), pending_connection_t::next, connection_t::s, TO_CONN, and tor_assert.
void assert_connection_edge_not_dns_pending | ( | edge_connection_t * | conn | ) |
Log an error and abort if conn is waiting for a DNS resolve.
References edge_connection_t::_base, connection_t::address, pending_connection_t::conn, pending_connection_t::next, cached_resolve_t::pending_connections, and tor_assert.
Referenced by connection_unlink().
static void assert_resolve_ok | ( | cached_resolve_t * | resolve | ) | [static] |
Exit with an assertion if resolve is corrupt.
References CACHE_STATE_DONE, CACHE_STATE_PENDING, CACHED_RESOLVE_MAGIC, cached_resolve_t::is_reverse, MAX_ADDRESSLEN, cached_resolve_t::pending_connections, cached_resolve_t::result, cached_resolve_t::state, tor_assert, tor_strisnonupper(), and cached_resolve_t::ttl.
Referenced by add_answer_to_cache(), dns_found_answer(), and HT_HEAD().
static INLINE unsigned int cached_resolve_hash | ( | cached_resolve_t * | a | ) | [static] |
Hash function for cached_resolve objects
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.
References dns_servers_relaunch_checks(), evdns_log_cb(), get_options(), LD_BUG, LD_CONFIG, mark_my_descriptor_dirty(), nameserver_config_failed, nameservers_configured, or_options_t::OutboundBindAddress, resolv_conf_fname, resolv_conf_mtime, or_options_t::ServerDNSRandomizeCase, or_options_t::ServerDNSResolvConfFile, the_evdns_base, tor_addr_from_str(), tor_addr_to_sockaddr(), tor_free, and tor_libevent_get_base().
Referenced by dns_init(), dns_reset(), and launch_resolve().
void connection_dns_remove | ( | edge_connection_t * | conn | ) |
Remove conn from the list of connections waiting for conn->address.
References edge_connection_t::_base, connection_t::address, assert_connection_ok(), pending_connection_t::conn, CONN_TYPE_EXIT, escaped_safe_str(), EXIT_CONN_STATE_RESOLVING, LD_BUG, pending_connection_t::next, cached_resolve_t::pending_connections, connection_t::s, connection_t::state, TO_CONN, tor_assert, tor_free, and connection_t::type.
Referenced by connection_about_to_close_connection().
static int dns_cache_entry_count | ( | void | ) | [static] |
Return the number of DNS cache entries as an int
Referenced by dump_dns_mem_usage().
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.
References edge_connection_t::_base, assert_connection_ok(), CACHE_STATE_DONE, CACHE_STATE_PENDING, circuit_detach_stream(), circuit_get_by_edge_conn(), pending_connection_t::conn, connection_edge_end(), connection_free(), escaped_safe_str(), EXIT_CONN_STATE_RESOLVEFAILED, LD_BUG, connection_t::marked_for_close, pending_connection_t::next, cached_resolve_t::pending_connections, connection_t::s, connection_t::state, cached_resolve_t::state, TO_CONN, tor_assert, tor_fragile_assert, and tor_free.
Referenced by dns_resolve().
uint32_t dns_clip_ttl | ( | uint32_t | ttl | ) |
Helper: Given a TTL from a DNS response, determine what TTL to give the OP that asked us to resolve it.
References MAX_DNS_TTL, and MIN_DNS_TTL.
Referenced by client_dns_set_addressmap_impl(), connection_edge_end(), connection_edge_finished_connecting(), connection_exit_connect(), send_resolved_cell(), and send_resolved_hostname_cell().
static void dns_found_answer | ( | const char * | address, | |
uint8_t | is_reverse, | |||
uint32_t | addr, | |||
const char * | hostname, | |||
char | outcome, | |||
uint32_t | ttl | |||
) | [static] |
Called on the OR side when a DNS worker or the eventdns library tells us the outcome of a DNS resolve: tell all pending connections about the result of the lookup, and cache the value. (address is a NUL-terminated string containing the address to look up; addr is an IPv4 address in host order; outcome is one of DNS_RESOLVE_{FAILED_TRANSIENT|FAILED_PERMANENT|SUCCEEDED}.
References edge_connection_t::_base, add_answer_to_cache(), connection_t::addr, edge_connection_t::address_ttl, assert_connection_ok(), assert_resolve_ok(), CACHE_STATE_DONE, CACHE_STATE_PENDING, circuit_detach_stream(), circuit_get_by_edge_conn(), CIRCUIT_IS_ORIGIN, pending_connection_t::conn, connection_edge_end(), connection_exit_connect(), connection_free(), escaped_safe_str(), EXIT_CONN_STATE_CONNECTING, EXIT_CONN_STATE_RESOLVEFAILED, EXIT_PURPOSE_CONNECT, is_test_address(), LD_BUG, or_circuit_t::n_streams, pending_connection_t::next, edge_connection_t::next_stream, edge_connection_t::on_circuit, cached_resolve_t::pending_connections, connection_t::purpose, send_resolved_cell(), send_resolved_hostname_cell(), connection_t::state, cached_resolve_t::state, TO_CONN, TO_OR_CIRCUIT(), tor_addr_from_ipv4h, tor_assert, and tor_free.
Referenced by evdns_callback().
void dns_free_all | ( | void | ) |
Free all storage held in the DNS cache and related structures.
References _free_cached_resolve(), CACHE_STATE_DONE, resolv_conf_fname, smartlist_free(), and tor_free.
Referenced by tor_free_all().
static uint32_t dns_get_expiry_ttl | ( | uint32_t | ttl | ) | [static] |
Helper: Given a TTL from a DNS response, determine how long to hold it in our cache.
References MAX_DNS_ENTRY_AGE, and MIN_DNS_TTL.
Referenced by add_answer_to_cache().
int dns_init | ( | void | ) |
Initialize the DNS subsystem; called by the OR process.
References _dns_randfn(), configure_nameservers(), get_options(), and server_mode().
Referenced by do_main_loop(), and run_scheduled_events().
void dns_launch_correctness_checks | ( | void | ) |
If appropriate, start testing whether our DNS servers tend to lie to us.
References dns_launch_wildcard_checks(), get_options(), launch_test_addresses(), LD_BUG, tor_evtimer_new(), and tor_libevent_get_base().
Referenced by run_scheduled_events().
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.
References launch_wildcard_check().
Referenced by dns_launch_correctness_checks().
int dns_reset | ( | void | ) |
Called when DNS-related options change (or may have changed). Returns -1 on failure, 0 on success.
References configure_nameservers(), get_options(), LD_BUG, nameservers_configured, resolv_conf_fname, resolv_conf_mtime, server_mode(), the_evdns_base, tor_free, and tor_libevent_get_base().
Referenced by do_hup(), and options_act().
void dns_reset_correctness_checks | ( | void | ) |
Forget what we've previously learned about our DNS servers' correctness.
References _tor_free(), dns_is_completely_invalid, dns_wildcard_notice_given, dns_wildcard_one_notice_given, dns_wildcard_response_count, dns_wildcarded_test_address_notice_given, n_wildcard_requests, smartlist_clear(), strmap_free(), and tor_free.
Referenced by dns_servers_relaunch_checks().
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.
References edge_connection_t::_base, connection_t::address, connection_free(), dns_cancel_pending_resolve(), dns_resolve_impl(), EXIT_CONN_STATE_RESOLVING, EXIT_PURPOSE_RESOLVE, connection_t::marked_for_close, or_circuit_t::n_streams, edge_connection_t::next_stream, edge_connection_t::on_circuit, connection_t::purpose, or_circuit_t::resolving_streams, send_resolved_cell(), send_resolved_hostname_cell(), connection_t::state, TO_CONN, TO_OR_CIRCUIT(), tor_assert, and tor_free.
Referenced by connection_exit_begin_conn(), and connection_exit_begin_resolve().
static int dns_resolve_impl | ( | edge_connection_t * | exitconn, | |
int | is_resolve, | |||
or_circuit_t * | oncirc, | |||
char ** | hostname_out | |||
) | [static] |
Helper function for dns_resolve: same functionality, but does not handle:
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.
References edge_connection_t::_base, connection_t::addr, connection_t::address, address_is_invalid_destination(), edge_connection_t::address_ttl, assert_connection_ok(), CACHE_STATE_CACHED_FAILED, CACHE_STATE_CACHED_VALID, CACHE_STATE_DONE, CACHE_STATE_PENDING, CACHED_RESOLVE_MAGIC, pending_connection_t::conn, DEFAULT_DNS_TTL, escaped_safe_str(), routerinfo_t::exit_policy, cached_resolve_t::expire, cached_resolve_t::is_reverse, launch_resolve(), LD_BUG, cached_resolve_t::minheap_idx, pending_connection_t::next, cached_resolve_t::pending_connections, policy_is_reject_star(), purge_expired_resolves(), RESOLVE_MAX_TIMEOUT, cached_resolve_t::result, router_get_my_routerinfo(), connection_t::s, set_expiry(), cached_resolve_t::state, TO_CONN, tor_addr_copy(), tor_addr_family(), tor_addr_from_ipv4h, tor_addr_from_str(), tor_addr_is_internal(), tor_addr_parse_reverse_lookup_name(), tor_assert, tor_fragile_assert, tor_strlower(), and cached_resolve_t::ttl.
Referenced by dns_resolve().
int dns_seems_to_be_broken | ( | void | ) |
Return true iff our DNS servers lie to us too much to be trusted.
References dns_is_completely_invalid.
Referenced by router_dump_router_to_string().
void dump_dns_mem_usage | ( | int | severity | ) |
Log memory information about our internal DNS cache at level 'severity'.
References dns_cache_entry_count(), and LD_MM.
Referenced by dumpmemusage().
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.
References add_wildcarded_test_address(), answer_is_wildcarded(), dns_found_answer(), DNS_RESOLVE_FAILED_TRANSIENT, esc_for_log(), escaped_safe_str(), evdns_err_is_transient(), INET_NTOA_BUF_LEN, is_test_address(), LD_BUG, safe_str(), tor_free, and tor_inet_ntoa().
Referenced by launch_resolve(), and launch_test_addresses().
static int evdns_err_is_transient | ( | int | err | ) | [static] |
Eventdns helper: return true iff the eventdns result err is a transient failure.
Referenced by evdns_callback().
static void evdns_log_cb | ( | int | warn, | |
const char * | msg | |||
) | [static] |
Helper: called by eventdns when eventdns wants to log something.
References control_event_server_status(), escaped(), get_options(), strcmpstart(), tor_assert, and tor_free.
Referenced by configure_nameservers().
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.
References dns_wildcard_one_notice_given, dns_wildcard_response_count, INET_NTOA_BUF_LEN, n_wildcard_requests, strmap_size(), tor_free, tor_inet_ntoa(), and wildcard_increment_answer().
Referenced by launch_wildcard_check().
int has_dns_init_failed | ( | void | ) |
Return true iff the most recent attempt to initialize the DNS subsystem failed.
References nameserver_config_failed.
Referenced by router_dump_router_to_string(), and run_scheduled_events().
static HT_HEAD | ( | cache_map | , | |
cached_resolve_t | ||||
) | [static] |
Hash table of cached_resolve objects.
References assert_resolve_ok(), and MAX_ADDRESSLEN.
HT_PROTOTYPE | ( | HT_GENERATE( | cache_map, | |
HT_GENERATE( | cached_resolve_t, | |||
HT_GENERATE( | node, | |||
HT_GENERATE( | cached_resolve_hash, | |||
HT_GENERATE( | cached_resolves_eq | |||
) |
Initialize the DNS cache.
static INLINE int is_test_address | ( | const char * | address | ) | [static] |
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.
References get_options(), or_options_t::ServerDNSTestAddresses, and smartlist_string_isin_case().
Referenced by dns_found_answer(), and evdns_callback().
static int launch_resolve | ( | edge_connection_t * | exitconn | ) | [static] |
For eventdns: start resolving as necessary to find the target for exitconn. Returns -1 on error, -2 on transient error, 0 on "resolve launched."
References edge_connection_t::_base, connection_t::address, configure_nameservers(), escaped_safe_str(), evdns_callback(), get_options(), LD_BUG, nameservers_configured, or_options_t::ServerDNSSearchDomains, the_evdns_base, tor_addr_family(), tor_addr_parse_reverse_lookup_name(), tor_addr_to_in(), tor_addr_to_in6(), tor_assert, and tor_free.
Referenced by dns_resolve_impl().
static void launch_test_addresses | ( | int | fd, | |
short | event, | |||
void * | args | |||
) | [static] |
Launch attempts to resolve a bunch of known-good addresses (configured in ServerDNSTestAddresses). [Callback for a libevent timer]
References escaped_safe_str(), evdns_callback(), get_options(), or_options_t::ServerDNSTestAddresses, the_evdns_base, tor_assert, and tor_free.
Referenced by dns_launch_correctness_checks().
static void launch_wildcard_check | ( | int | min_len, | |
int | max_len, | |||
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
References crypto_random_hostname(), evdns_wildcard_check_callback(), the_evdns_base, tor_assert, and tor_free.
Referenced by dns_launch_wildcard_checks().
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.
References edge_connection_t::_base, _compare_cached_resolves_by_expiry(), CACHE_STATE_CACHED_FAILED, CACHE_STATE_CACHED_VALID, CACHE_STATE_DONE, CACHE_STATE_PENDING, circuit_detach_stream(), circuit_get_by_edge_conn(), pending_connection_t::conn, connection_edge_end(), connection_free(), escaped_safe_str(), cached_resolve_t::expire, cached_resolve_t::is_reverse, LD_BUG, pending_connection_t::next, cached_resolve_t::pending_connections, cached_resolve_t::result, connection_t::s, smartlist_pqueue_pop(), cached_resolve_t::state, STRUCT_OFFSET, TO_CONN, tor_assert, tor_fragile_assert, and tor_free.
Referenced by dns_resolve_impl().
static void send_resolved_cell | ( | edge_connection_t * | conn, | |
uint8_t | answer_type | |||
) | [static] |
Send a response to the RESOLVE request of a connection. answer_type must be one of RESOLVED_TYPE_(IPV4|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.
References edge_connection_t::_base, connection_t::addr, edge_connection_t::address_ttl, connection_edge_send_command(), dns_clip_ttl(), RELAY_PAYLOAD_SIZE, set_uint32(), tor_addr_to_ipv4n(), and tor_assert.
Referenced by dns_found_answer(), and dns_resolve().
static void send_resolved_hostname_cell | ( | edge_connection_t * | conn, | |
const char * | hostname | |||
) | [static] |
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.
References edge_connection_t::address_ttl, connection_edge_send_command(), dns_clip_ttl(), RELAY_PAYLOAD_SIZE, set_uint32(), and tor_assert.
Referenced by dns_found_answer(), and dns_resolve().
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
References _compare_cached_resolves_by_expiry(), cached_resolve_t::expire, smartlist_create(), smartlist_pqueue_add(), STRUCT_OFFSET, and tor_assert.
Referenced by add_answer_to_cache(), and dns_resolve_impl().
static void wildcard_increment_answer | ( | const char * | id | ) | [static] |
Called when we see id (a dotted quad) in response to a request for a hopefully bogus address.
References control_event_server_status(), dns_wildcard_notice_given, dns_wildcard_response_count, n_wildcard_requests, smartlist_add(), smartlist_create(), smartlist_string_isin(), strmap_get(), and strmap_set().
Referenced by evdns_wildcard_check_callback().
smartlist_t* cached_resolve_pqueue = NULL [static] |
Priority queue of cached_resolve_t objects to let us know when they will expire.
int dns_is_completely_invalid = 0 [static] |
True iff all addresses seem to be getting wildcarded.
Referenced by add_wildcarded_test_address(), dns_reset_correctness_checks(), and dns_seems_to_be_broken().
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.
int dns_wildcard_notice_given = 0 [static] |
True iff we've warned that our DNS server is wildcarding too many failures.
Referenced by dns_reset_correctness_checks(), and wildcard_increment_answer().
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.
Referenced by dns_reset_correctness_checks(), and evdns_wildcard_check_callback().
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().
Referenced by dns_reset_correctness_checks(), evdns_wildcard_check_callback(), and wildcard_increment_answer().
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.
int dns_wildcarded_test_address_notice_given = 0 [static] |
True iff we've warned about a test address getting wildcarded
Referenced by add_wildcarded_test_address(), and dns_reset_correctness_checks().
int n_wildcard_requests = 0 [static] |
How many requests for bogus addresses have we launched so far?
Referenced by dns_reset_correctness_checks(), evdns_wildcard_check_callback(), and wildcard_increment_answer().
int nameserver_config_failed = 0 [static] |
Did our most recent attempt to configure nameservers with eventdns fail?
Referenced by configure_nameservers(), and has_dns_init_failed().
int nameservers_configured = 0 [static] |
Have we currently configured nameservers with eventdns?
Referenced by configure_nameservers(), dns_reset(), and launch_resolve().
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.
Referenced by configure_nameservers(), dns_free_all(), and dns_reset().
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.
Referenced by configure_nameservers(), and dns_reset().
struct evdns_base* the_evdns_base = NULL [static] |
Our evdns_base; this structure handles all our name lookups.
Referenced by configure_nameservers(), dns_reset(), launch_resolve(), launch_test_addresses(), and launch_wildcard_check().