73#include "core/or/or_circuit_st.h"
82#include <event2/event.h>
83#include <event2/dns.h>
87#define RESOLVE_MAX_TIMEOUT 300
94#define RESOLVED_CLIPPED_TTL (60)
114 const char *hostname,
124#ifdef DEBUG_DNS_CACHE
125static void assert_cache_ok_(
void);
126#define assert_cache_ok() assert_cache_ok_()
128#define assert_cache_ok() STMT_NIL
136static uint64_t n_ipv6_requests_made = 0;
138static uint64_t n_ipv6_timeouts = 0;
140static int dns_is_broken_for_ipv6 = 0;
153static inline unsigned int
156 return (
unsigned) siphash24g((
const uint8_t*)a->
address, strlen(a->
address));
168 HT_INIT(cache_map, &cache_root);
176 static int all_down = 0;
180 log_info(LD_EXIT,
"eventdns: Resolve requested.");
185 if (!
strcmpstart(msg,
"Nameserver ") && (cp=strstr(msg,
" has failed: "))) {
186 char *ns = tor_strndup(msg+11, cp-(msg+11));
187 const char *colon = strchr(cp,
':');
189 const char *err = colon+2;
195 "NAMESERVER_STATUS NS=%s STATUS=DOWN ERR=%s",
199 (cp=strstr(msg,
" is back up"))) {
200 char *ns = tor_strndup(msg+11, cp-(msg+11));
204 "NAMESERVER_STATUS NS=%s STATUS=UP", ns);
206 }
else if (!strcmp(msg,
"All nameservers have failed")) {
209 }
else if (!
strcmpstart(msg,
"Address mismatch on received DNS")) {
210 static ratelim_t mismatch_limit = RATELIM_INIT(3600);
211 const char *src = strstr(msg,
" Apparent source");
216 "eventdns: Received a DNS packet from "
217 "an IP address to which we did not send a request. This "
218 "could be a DNS spoofing attempt, or some kind of "
219 "misconfiguration.%s", src);
222 tor_log(severity, LD_EXIT,
"eventdns: %s", msg);
256 if (! server_mode(options)) {
260 log_err(
LD_BUG,
"Couldn't create an evdns_base");
299 r->
magic = 0xFF00FF00;
310 if (a->
expire < b->expire)
312 else if (a->
expire == b->expire)
327 const char *answer_hostname,
330 if (query_type == DNS_PTR) {
334 if (dns_result == DNS_ERR_NONE && answer_hostname) {
335 resolve->result_ptr.hostname = tor_strdup(answer_hostname);
342 }
else if (query_type == DNS_IPv4_A) {
346 if (dns_result == DNS_ERR_NONE && answer_addr &&
355 }
else if (query_type == DNS_IPv6_AAAA) {
359 if (dns_result == DNS_ERR_NONE && answer_addr &&
390 resolve->
expire = expires;
410 for (ptr = HT_START(cache_map, &cache_root); ptr != NULL; ptr = next) {
412 next = HT_NEXT_RMV(cache_map, &cache_root, ptr);
415 HT_CLEAR(cache_map, &cache_root);
436 if (resolve->
expire > now)
444 "Expiring a dns resolve %s that's still pending. Forgot to "
445 "cull it? DNS resolve didn't tell us about the timeout?",
449 "Forgetting old cached resolve (address %s, expires %lu)",
451 (
unsigned long)resolve->
expire);
460 "Closing pending connections on timed-out DNS resolve!");
466 pendconn = pend->conn;
480 removed = HT_REMOVE(cache_map, &cache_root, resolve);
481 if (removed != resolve) {
482 log_err(
LD_BUG,
"The expired resolve we purged didn't match any in"
483 " the cache. Tried to purge %s (%p); instead got %s (%p).",
484 resolve->
address, (
void*)resolve,
485 removed ? removed->
address :
"NULL", (
void*)removed);
494 tor_free(resolve->result_ptr.hostname);
495 resolve->
magic = 0xF0BBF0BB;
504#define RESOLVED_TYPE_AUTO 0xff
524 buf[0] = answer_type;
528 case RESOLVED_TYPE_AUTO:
530 cp[0] = RESOLVED_TYPE_IPV4;
538 cp[0] = RESOLVED_TYPE_IPV6;
540 memcpy(cp+2, bytes, 16);
548 answer_type = RESOLVED_TYPE_ERROR;
552 case RESOLVED_TYPE_ERROR_TRANSIENT:
553 case RESOLVED_TYPE_ERROR:
555 const char *errmsg =
"Error resolving hostname";
556 size_t msglen = strlen(errmsg);
558 buf[0] = answer_type;
560 strlcpy(buf+2, errmsg,
sizeof(buf)-2);
590 const char *hostname))
599 size_t namelen = strlen(hostname);
601 if (BUG(namelen >= 256)) {
605 buf[0] = RESOLVED_TYPE_HOSTNAME;
606 buf[1] = (uint8_t)namelen;
607 memcpy(buf+2, hostname, namelen);
609 buflen = 2+namelen+4;
645 int made_connection_pending = 0;
646 char *hostname = NULL;
651 &made_connection_pending, &resolve);
686 (r == -1) ? RESOLVED_TYPE_ERROR : RESOLVED_TYPE_ERROR_TRANSIENT,
727 int *made_connection_pending_out,
735 time_t now = time(NULL);
741 *made_connection_pending_out = 0;
762 tor_log(LOG_PROTOCOL_WARN, LD_EXIT,
763 "Rejecting invalid destination address %s",
780 AF_UNSPEC, 0)) != 0) {
783 if (tor_addr_is_internal(&addr, 0))
787 if (!is_reverse || !is_resolve) {
789 log_info(LD_EXIT,
"Bad .in-addr.arpa address %s; sending error.",
791 else if (!is_resolve)
793 "Attempt to connect to a .in-addr.arpa address %s; "
806 resolve = HT_FIND(cache_map, &cache_root, &search);
807 if (resolve && resolve->
expire > now) {
808 switch (resolve->
state) {
811 pending_connection = tor_malloc_zero(
813 pending_connection->conn = exitconn;
816 *made_connection_pending_out = 1;
817 log_debug(LD_EXIT,
"Connection (fd "TOR_SOCKET_T_FORMAT
") waiting "
818 "for pending DNS resolve of %s", exitconn->base_.
s,
822 log_debug(LD_EXIT,
"Connection (fd "TOR_SOCKET_T_FORMAT
") found "
823 "cached answer for %s",
827 *resolve_out = resolve;
831 log_err(
LD_BUG,
"Found a 'DONE' dns resolve still in the cache.");
846 pending_connection->conn = exitconn;
848 *made_connection_pending_out = 1;
851 HT_INSERT(cache_map, &cache_root, resolve);
854 log_debug(LD_EXIT,
"Launching %s.",
880 char **hostname_out))
882 int ipv4_ok, ipv6_ok, answer_with_ipv4, r;
883 uint32_t begincell_flags;
891 *hostname_out = tor_strdup(resolve->result_ptr.hostname);
903 begincell_flags = exitconn->begincell_flags;
913 if (ipv4_ok && ipv6_ok && is_resolve) {
914 answer_with_ipv4 = 1;
915 }
else if (ipv4_ok && ipv6_ok) {
917 const uint16_t port = exitconn->base_.
port;
918 int ipv4_allowed, ipv6_allowed;
924 if (ipv4_allowed && !ipv6_allowed) {
925 answer_with_ipv4 = 1;
926 }
else if (ipv6_allowed && !ipv4_allowed) {
927 answer_with_ipv4 = 0;
931 answer_with_ipv4 = !(begincell_flags &
937 answer_with_ipv4 = 1;
938 }
else if (ipv6_ok) {
939 answer_with_ipv4 = 0;
942 answer_with_ipv4 = !(begincell_flags &
949 if (answer_with_ipv4) {
983 resolve = HT_FIND(cache_map, &cache_root, &search);
991 HT_FOREACH(resolve, cache_map, &cache_root) {
992 for (pend = (*resolve)->pending_connections; pend; pend = pend->next) {
1013 resolve = HT_FIND(cache_map, &cache_root, &search);
1015 log_notice(
LD_BUG,
"Address %s is not pending. Dropping.",
1025 if (pend->conn == conn) {
1028 log_debug(LD_EXIT,
"First connection (fd "TOR_SOCKET_T_FORMAT
") no "
1029 "longer waiting for resolve of %s",
1034 for ( ; pend->next; pend = pend->next) {
1035 if (pend->next->conn == conn) {
1036 victim = pend->next;
1037 pend->next = victim->next;
1040 "Connection (fd "TOR_SOCKET_T_FORMAT
") no longer waiting "
1041 "for resolve of %s",
1046 log_warn(
LD_BUG,
"Connection (fd "TOR_SOCKET_T_FORMAT
") was not waiting "
1047 "for a resolve of %s, but we tried to remove it.",
1067 resolve = HT_FIND(cache_map, &cache_root, &search);
1077 "Address %s is not pending but has pending connections!",
1086 "Address %s is pending but has no pending connections!",
1095 "Failing all connections waiting on DNS resolve of %s",
1100 pendconn = pend->conn;
1115 tmp = HT_REMOVE(cache_map, &cache_root, resolve);
1116 if (tmp != resolve) {
1117 log_err(
LD_BUG,
"The cancelled resolve we purged didn't match any in"
1118 " the cache. Tried to purge %s (%p); instead got %s (%p).",
1119 resolve->
address, (
void*)resolve,
1120 tmp ? tmp->
address :
"NULL", (
void*)tmp);
1150 const char *hostname, uint32_t ttl)
1159 resolve = HT_FIND(cache_map, &cache_root, &search);
1163 log_info(LD_EXIT,
"Resolved unasked address %s; ignoring.",
1175 "Resolved %s which was already resolved; ignoring",
1181 cached_resolve_add_answer(resolve, query_type, dns_answer,
1182 addr, hostname, ttl);
1207 char *hostname = NULL;
1209 pendconn = pend->conn;
1234 RESOLVED_TYPE_ERROR : RESOLVED_TYPE_ERROR_TRANSIENT,
1290 removed = HT_REMOVE(cache_map, &cache_root, resolve);
1291 if (removed != resolve) {
1292 log_err(
LD_BUG,
"The pending resolve we found wasn't removable from"
1293 " the cache. Tried to purge %s (%p); instead got %s (%p).",
1294 resolve->
address, (
void*)resolve,
1295 removed ? removed->
address :
"NULL", (
void*)removed);
1306 uint32_t ttl = UINT32_MAX;
1309 new_resolve->result_ptr.hostname =
1310 tor_strdup(resolve->result_ptr.hostname);
1315 HT_INSERT(cache_map, &cache_root, new_resolve);
1345 case DNS_ERR_SERVERFAILED:
1346 case DNS_ERR_TRUNCATED:
1347 case DNS_ERR_TIMEOUT:
1363#ifdef HAVE_EVDNS_BASE_GET_NAMESERVER_ADDR
1369configured_nameserver_address(
const size_t idx)
1371 struct sockaddr_storage sa;
1372 ev_socklen_t sa_len =
sizeof(sa);
1375 (
struct sockaddr *)&sa,
1379 (
const struct sockaddr *)&sa,
1399#define EXIT_DNS_TIMEOUT_DEFAULT (1000)
1400#define EXIT_DNS_TIMEOUT_MIN (1)
1401#define EXIT_DNS_TIMEOUT_MAX (120000)
1403 EXIT_DNS_TIMEOUT_DEFAULT,
1404 EXIT_DNS_TIMEOUT_MIN,
1405 EXIT_DNS_TIMEOUT_MAX);
1413 val = MAX(1, val / 1000);
1427#define EXIT_DNS_NUM_ATTEMPTS_DEFAULT (2)
1428#define EXIT_DNS_NUM_ATTEMPTS_MIN (0)
1429#define EXIT_DNS_NUM_ATTEMPTS_MAX (255)
1431 EXIT_DNS_NUM_ATTEMPTS_DEFAULT,
1432 EXIT_DNS_NUM_ATTEMPTS_MIN,
1433 EXIT_DNS_NUM_ATTEMPTS_MAX);
1450#define SET(k,v) evdns_base_set_option(the_evdns_base, (k), (v))
1460 SET(
"max-timeouts:",
"1000000");
1462 SET(
"max-timeouts:",
"10");
1471 SET(
"max-inflight:",
"8192");
1488 SET(
"randomize-case:",
"1");
1490 SET(
"randomize-case:",
"0");
1505 const char *conf_fname;
1512 conf_fname =
"/etc/resolv.conf";
1514 flags = DNS_OPTIONS_ALL;
1518 log_err(
LD_BUG,
"Couldn't create an evdns_base");
1525 log_debug(
LD_FS,
"stat()ing %s", conf_fname);
1526 int missing_resolv_conf = 0;
1530 log_warn(LD_EXIT,
"Unable to stat resolver configuration in '%s': %s",
1531 conf_fname, strerror(errno));
1532 missing_resolv_conf = 1;
1536 log_info(LD_EXIT,
"No change to '%s'", conf_fname);
1540 if (stat_res == 0 && st.st_size == 0)
1541 missing_resolv_conf = 1;
1547#if defined(DNS_OPTION_HOSTSFILE) && defined(USE_LIBSECCOMP)
1548 if (flags & DNS_OPTION_HOSTSFILE) {
1549 flags ^= DNS_OPTION_HOSTSFILE;
1550 log_debug(
LD_FS,
"Loading /etc/hosts");
1556 if (!missing_resolv_conf) {
1557 log_info(LD_EXIT,
"Parsing resolver configuration in '%s'", conf_fname);
1560 log_warn(LD_EXIT,
"Unable to parse '%s', or no nameservers "
1561 "in '%s' (%d)", conf_fname, conf_fname, r);
1568 log_warn(LD_EXIT,
"Unable to find any nameservers in '%s'.",
1576 log_warn(LD_EXIT,
"Could not read your DNS config from '%s' - "
1577 "please investigate your DNS configuration. "
1578 "This is possibly a problem. Meanwhile, falling"
1579 " back to local DNS at 127.0.0.1.", conf_fname);
1593 log_warn(LD_EXIT,
"Could not config nameservers.");
1597 log_warn(LD_EXIT,
"Unable to find any platform nameservers in "
1598 "your Windows configuration.");
1640 uint8_t orig_query_type = arg_[0];
1641 char *string_address = arg_ + 1;
1643 const char *hostname = NULL;
1644 int was_wildcarded = 0;
1649 if (type == DNS_IPv6_AAAA) {
1650 if (result == DNS_ERR_TIMEOUT) {
1654 if (n_ipv6_timeouts > 10 &&
1655 n_ipv6_timeouts > n_ipv6_requests_made / 2) {
1656 if (! dns_is_broken_for_ipv6) {
1657 log_notice(LD_EXIT,
"More than half of our IPv6 requests seem to "
1658 "have timed out. I'm going to assume I can't get AAAA "
1660 dns_is_broken_for_ipv6 = 1;
1665 if (result == DNS_ERR_NONE) {
1666 if (type == DNS_IPv4_A && count) {
1668 char *escaped_address;
1669 uint32_t *addrs = addresses;
1676 log_debug(LD_EXIT,
"eventdns said that %s resolves to ISP-hijacked "
1677 "address %s; treating as a failure.",
1678 safe_str(escaped_address),
1682 result = DNS_ERR_NOTEXIST;
1684 log_debug(LD_EXIT,
"eventdns said that %s resolves to %s",
1685 safe_str(escaped_address),
1689 }
else if (type == DNS_IPv6_AAAA && count) {
1691 char *escaped_address;
1693 struct in6_addr *addrs = addresses;
1696 sizeof(answer_buf));
1699 if (BUG(ip_str == NULL)) {
1700 log_warn(LD_EXIT,
"tor_inet_ntop() failed!");
1701 result = DNS_ERR_NOTEXIST;
1703 log_debug(LD_EXIT,
"eventdns said that %s resolves to ISP-hijacked "
1704 "address %s; treating as a failure.",
1705 safe_str(escaped_address),
1709 result = DNS_ERR_NOTEXIST;
1711 log_debug(LD_EXIT,
"eventdns said that %s resolves to %s",
1712 safe_str(escaped_address),
1716 }
else if (type == DNS_PTR && count) {
1717 char *escaped_address;
1718 hostname = ((
char**)addresses)[0];
1720 log_debug(LD_EXIT,
"eventdns said that %s resolves to %s",
1721 safe_str(escaped_address),
1725 log_info(LD_EXIT,
"eventdns returned only unrecognized answer types "
1729 log_info(LD_EXIT,
"eventdns returned no addresses or error for %s.",
1733 if (was_wildcarded) {
1741 if (orig_query_type && type && orig_query_type != type) {
1742 log_warn(
LD_BUG,
"Weird; orig_query_type == %d but type == %d",
1743 (
int)orig_query_type, (
int)type);
1745 if (result != DNS_ERR_SHUTDOWN)
1764 : DNS_QUERY_NO_SEARCH;
1765 const size_t addr_len = strlen(address);
1766 struct evdns_request *req = 0;
1767 char *addr = tor_malloc(addr_len + 2);
1768 addr[0] = (char) query_type;
1769 memcpy(addr+1, address, addr_len + 1);
1774 switch (query_type) {
1782 ++n_ipv6_requests_made;
1788 DNS_QUERY_NO_SEARCH,
1793 DNS_QUERY_NO_SEARCH,
1796 log_warn(
LD_BUG,
"Called with PTR query and unexpected address family");
1799 log_warn(
LD_BUG,
"Called with unexpected query type %d", (
int)query_type);
1825 log_warn(LD_EXIT,
"(Harmless.) Nameservers not configured, but resolve "
1826 "launched. Configuring.");
1833 &a, resolve->
address, AF_UNSPEC, 0);
1837 log_info(LD_EXIT,
"Launching eventdns request for %s",
1844 resolve->res_status_ipv4 = 0;
1851 resolve->res_status_ipv6 = 0;
1855 }
else if (r == 1) {
1857 log_info(LD_EXIT,
"Launching eventdns reverse request for %s",
1861 resolve->res_status_hostname = 0;
1864 }
else if (r == -1) {
1865 log_warn(
LD_BUG,
"Somehow a malformed in-addr.arpa address reached here.");
1869 log_fn(LOG_PROTOCOL_WARN, LD_EXIT,
"eventdns rejected address %s.",
1914 ip = tor_malloc_zero(
sizeof(
int));
1923 "Your DNS provider has given \"%s\" as an answer for %d different "
1924 "invalid addresses. Apparently they are hijacking DNS failures. "
1925 "I'll try to correct for this by treating future occurrences of "
1926 "\"%s\" as 'not found'.",
id, *ip,
id);
1940 int n, n_test_addrs;
1949 smartlist_len(
get_options()->ServerDNSTestAddresses) : 0;
1953 if (n > n_test_addrs/2) {
1955 LD_EXIT,
"Your DNS provider tried to redirect \"%s\" to a junk "
1956 "address. It has done this with %d test addresses so far. I'm "
1957 "going to stop being an exit node for now, since our DNS seems so "
1958 "broken.", address, n);
1973 void *addresses,
void *arg)
1978 if (result == DNS_ERR_NONE && count) {
1979 char *string_address = arg;
1981 if (type == DNS_IPv4_A) {
1982 const uint32_t *addrs = addresses;
1983 for (i = 0; i < count; ++i) {
1987 in.s_addr = addrs[i];
1988 ntoa_res =
tor_inet_ntoa(&in, answer_buf,
sizeof(answer_buf));
1989 tor_assert_nonfatal(ntoa_res >= 0);
1993 }
else if (type == DNS_IPv6_AAAA) {
1994 const struct in6_addr *addrs = addresses;
1995 for (i = 0; i < count; ++i) {
1998 sizeof(answer_buf));
1999 tor_assert_nonfatal(ip_str);
2006 "Your DNS provider gave an answer for \"%s\", which "
2007 "is not supposed to exist. Apparently they are hijacking "
2008 "DNS failures. Trying to correct for this. We've noticed %d "
2009 "possibly bad address%s so far.",
2025 struct evdns_request *req;
2028 log_info(LD_EXIT,
"Testing whether our DNS server is hijacking nonexistent "
2029 "domains with request for bogus hostname \"%s\"", addr);
2033 req = evdns_base_resolve_ipv6(
2040 req = evdns_base_resolve_ipv4(
2065 log_info(LD_EXIT,
"Launching checks to see whether our nameservers like to "
2066 "hijack *everything*.");
2074 const char *, address) {
2076 log_info(LD_EXIT,
"eventdns rejected test address %s",
2081 log_info(LD_EXIT,
"eventdns rejected test address %s",
2084 } SMARTLIST_FOREACH_END(address);
2088#define N_WILDCARD_CHECKS 2
2098 log_info(LD_EXIT,
"Launching checks to see whether our nameservers like "
2099 "to hijack DNS failures.");
2100 for (ipv6 = 0; ipv6 <= 1; ++ipv6) {
2101 for (i = 0; i < N_WILDCARD_CHECKS; ++i) {
2128 static struct event *launch_event = NULL;
2141 if (evtimer_add(launch_event, &
timeout) < 0) {
2142 log_warn(
LD_BUG,
"Couldn't add timer for checking for dns hijacking");
2157 return dns_is_broken_for_ipv6;
2169 n_ipv6_requests_made = n_ipv6_timeouts = 0;
2182 dns_is_broken_for_ipv6 = 0;
2208 if (resolve->is_reverse)
2221 return HT_SIZE(&cache_root);
2226dns_cache_total_allocation(
void)
2229 HT_MEM_USAGE(&cache_root);
2234dump_dns_mem_usage(
int severity)
2238 size_t hash_mem = dns_cache_total_allocation();
2243 tor_log(severity,
LD_MM,
"Our DNS cache has %d entries.", hash_count);
2244 tor_log(severity,
LD_MM,
"Our DNS cache size is approximately %u bytes.",
2245 (
unsigned)hash_mem);
2252dns_cache_handle_oom(time_t now,
size_t min_remove_bytes)
2254 time_t time_inc = 0;
2255 size_t total_bytes_removed = 0;
2256 size_t current_size = dns_cache_total_allocation();
2264 time_t cutoff = now + time_inc;
2268 size_t bytes_removed = current_size - dns_cache_total_allocation();
2269 current_size -= bytes_removed;
2270 total_bytes_removed += bytes_removed;
2274 }
while (total_bytes_removed < min_remove_bytes);
2276 return total_bytes_removed;
2279#ifdef DEBUG_DNS_CACHE
2282assert_cache_ok_(
void)
2285 int bad_rep = HT_REP_IS_BAD_(cache_map, &cache_root);
2287 log_err(
LD_BUG,
"Bad rep type %d on dns cache hash table", bad_rep);
2291 HT_FOREACH(resolve, cache_map, &cache_root) {
2319 return HT_FIND(cache_map, &cache_root, query);
2325 HT_INSERT(cache_map, &cache_root, new_entry);
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
void tor_addr_from_ipv4n(tor_addr_t *dest, uint32_t v4addr)
void tor_addr_make_unspec(tor_addr_t *a)
int tor_addr_parse(tor_addr_t *addr, const char *src)
int tor_addr_parse_PTR_name(tor_addr_t *result, const char *address, int family, int accept_regular)
void tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6)
const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len, int decorate)
int tor_addr_from_sockaddr(tor_addr_t *a, const struct sockaddr *sa, uint16_t *port_out)
static const struct in_addr * tor_addr_to_in(const tor_addr_t *a)
static sa_family_t tor_addr_family(const tor_addr_t *a)
static uint32_t tor_addr_to_ipv4h(const tor_addr_t *a)
static const struct in6_addr * tor_addr_to_in6(const tor_addr_t *a)
#define tor_addr_from_ipv4h(dest, v4addr)
static void set_uint32(void *cp, uint32_t v)
circuit_t * circuit_get_by_edge_conn(edge_connection_t *conn)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
Header file for circuitlist.c.
#define CIRCUIT_IS_ORIGIN(c)
void circuit_detach_stream(circuit_t *circ, edge_connection_t *conn)
Header file for circuituse.c.
struct event_base * tor_libevent_get_base(void)
Header for compat_libevent.c.
const char * escaped_safe_str(const char *address)
const or_options_t * get_options(void)
Header file for config.c.
void conflux_update_resolving_streams(or_circuit_t *circ, edge_connection_t *stream)
void conflux_update_n_streams(or_circuit_t *circ, edge_connection_t *stream)
Header file for conflux_util.c.
void assert_connection_ok(connection_t *conn, time_t now)
void connection_free_(connection_t *conn)
Header file for connection.c.
uint32_t clip_dns_fuzzy_ttl(uint32_t ttl)
void connection_exit_connect(edge_connection_t *edge_conn)
int connection_edge_end(edge_connection_t *conn, uint8_t reason)
Header file for connection_edge.c.
#define EXIT_CONN_STATE_CONNECTING
int address_is_invalid_destination(const char *address, int client)
#define BEGIN_FLAG_IPV6_PREFERRED
#define EXIT_CONN_STATE_RESOLVEFAILED
#define EXIT_PURPOSE_CONNECT
#define BEGIN_FLAG_IPV4_NOT_OK
#define EXIT_CONN_STATE_RESOLVING
#define BEGIN_FLAG_IPV6_OK
#define EXIT_PURPOSE_RESOLVE
int control_event_server_status(int severity, const char *format,...)
Header file for control_events.c.
char * crypto_random_hostname(int min_rand_len, int max_rand_len, const char *prefix, const char *suffix)
Common functions for using (pseudo-)random number generators.
static int dns_wildcard_notice_given
STATIC int set_exitconn_info_from_resolve(edge_connection_t *exitconn, const cached_resolve_t *resolve, char **hostname_out)
static const char * get_consensus_param_exit_dns_attempts(void)
static int dns_wildcard_one_notice_given
static int nameservers_configured
#define RESOLVED_CLIPPED_TTL
static unsigned int cached_resolve_hash(cached_resolve_t *a)
static void add_wildcarded_test_address(const char *address)
static int nameserver_config_failed
static void dns_launch_wildcard_checks(void)
static void assert_resolve_ok(cached_resolve_t *resolve)
static char * resolv_conf_fname
static int dns_cache_entry_count(void)
int dns_seems_to_be_broken(void)
STATIC void send_resolved_cell(edge_connection_t *conn, uint8_t answer_type, const cached_resolve_t *resolved)
void dns_reset_correctness_checks(void)
STATIC void send_resolved_hostname_cell(edge_connection_t *conn, const char *hostname)
static int n_wildcard_requests
static void init_cache_map(void)
static struct evdns_base * the_evdns_base
static void evdns_callback(int result, char type, int count, int ttl, void *addresses, void *arg)
static int configure_nameservers(int force)
static void inform_pending_connections(cached_resolve_t *resolve)
static smartlist_t * dns_wildcard_list
static void evdns_wildcard_check_callback(int result, char type, int count, int ttl, void *addresses, void *arg)
#define RESOLVE_MAX_TIMEOUT
static void purge_expired_resolves(time_t now)
STATIC void dns_cancel_pending_resolve(const char *address)
static int evdns_err_is_transient(int err)
size_t number_of_configured_nameservers(void)
static smartlist_t * dns_wildcarded_test_address_list
int has_dns_init_failed(void)
static int dns_is_completely_invalid
static void free_cached_resolve_(cached_resolve_t *r)
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 void launch_test_addresses(evutil_socket_t fd, short event, void *args)
static int dns_wildcarded_test_address_notice_given
static int launch_one_resolve(const char *address, uint8_t query_type, const tor_addr_t *ptr_address)
static void evdns_log_cb(int warn, const char *msg)
static int answer_is_wildcarded(const char *ip)
STATIC int launch_resolve(cached_resolve_t *resolve)
int dns_seems_to_be_broken_for_ipv6(void)
int dns_resolve(edge_connection_t *exitconn)
static strmap_t * dns_wildcard_response_count
static const char * get_consensus_param_exit_dns_timeout(void)
static time_t resolv_conf_mtime
static void launch_wildcard_check(int min_len, int max_len, int is_ipv6, const char *suffix)
static int is_test_address(const char *address)
static void configure_libevent_options(void)
static int compare_cached_resolves_by_expiry_(const void *_a, const void *_b)
static void make_pending_resolve_cached(cached_resolve_t *cached)
void dns_launch_correctness_checks(void)
static smartlist_t * cached_resolve_pqueue
static int cached_resolve_have_all_answers(const cached_resolve_t *resolve)
static void set_expiry(cached_resolve_t *resolve, time_t expires)
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 wildcard_increment_answer(const char *id)
#define CACHE_STATE_PENDING
#define RES_STATUS_DONE_OK
#define CACHED_RESOLVE_MAGIC
#define CACHE_STATE_CACHED
#define RES_STATUS_DONE_ERR
#define RES_STATUS_INFLIGHT
Edge-connection structure.
char * esc_for_log(const char *s)
const char * escaped(const char *s)
int tor_inet_ntoa(const struct in_addr *in, char *buf, size_t buf_len)
const char * tor_inet_ntop(int af, const void *src, char *dst, size_t len)
#define INET_NTOA_BUF_LEN
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
#define log_fn(severity, domain, args,...)
#define log_fn_ratelim(ratelim, severity, domain, args,...)
void dns_servers_relaunch_checks(void)
Header file for mainloop.c.
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
void tor_free_(void *mem)
int net_is_disabled(void)
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
Header file for networkstatus.c.
Master header file for Tor-specific functionality.
#define RELAY_PAYLOAD_SIZE_MIN
#define RELAY_PAYLOAD_SIZE_MAX
Header file for policies.c.
int tor_snprintf(char *str, size_t size, const char *format,...)
int connection_edge_send_command(edge_connection_t *fromconn, uint8_t relay_command, const char *payload, size_t payload_len)
void rep_hist_note_dns_error(int type, uint8_t error)
void rep_hist_note_dns_request(int type)
Header file for rephist.c.
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port)
void mark_my_descriptor_dirty(const char *reason)
int router_my_exit_policy_is_reject_star(void)
Header file for router.c.
Header file for routermode.c.
Header file for sandbox.c.
#define sandbox_intern_string(s)
void smartlist_pqueue_assert_ok(smartlist_t *sl, int(*compare)(const void *a, const void *b), ptrdiff_t idx_field_offset)
int smartlist_contains_string_case(const smartlist_t *sl, const char *element)
void * smartlist_pqueue_pop(smartlist_t *sl, int(*compare)(const void *a, const void *b), ptrdiff_t idx_field_offset)
void smartlist_pqueue_add(smartlist_t *sl, int(*compare)(const void *a, const void *b), ptrdiff_t idx_field_offset, void *item)
int smartlist_contains_string(const smartlist_t *sl, const char *element)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
smartlist_t * smartlist_new(void)
void smartlist_clear(smartlist_t *sl)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
struct in6_addr addr_ipv6
union cached_resolve_t::@26 result_ipv6
union cached_resolve_t::@25 result_ipv4
char address[MAX_ADDRESSLEN]
pending_connection_t * pending_connections
uint16_t marked_for_close
unsigned int is_reverse_dns_lookup
struct edge_connection_t * next_stream
struct circuit_t * on_circuit
edge_connection_t * resolving_streams
edge_connection_t * n_streams
char * ServerDNSResolvConfFile
struct smartlist_t * ServerDNSTestAddresses
int ServerDNSSearchDomains
#define MOCK_IMPL(rv, funcname, arglist)
#define tor_fragile_assert()
void tor_strlower(char *s)
int strcmpstart(const char *s1, const char *s2)
int tor_strisnonupper(const char *s)