72 #include "core/or/or_circuit_st.h"
76 #ifdef HAVE_SYS_STAT_H
80 #include <event2/event.h>
81 #include <event2/dns.h>
85 #define RESOLVE_MAX_TIMEOUT 300
105 const char *hostname,
114 #ifdef DEBUG_DNS_CACHE
115 static void assert_cache_ok_(
void);
116 #define assert_cache_ok() assert_cache_ok_()
118 #define assert_cache_ok() STMT_NIL
126 static uint64_t n_ipv6_requests_made = 0;
128 static uint64_t n_ipv6_timeouts = 0;
130 static int dns_is_broken_for_ipv6 = 0;
143 static inline unsigned int
146 return (
unsigned) siphash24g((
const uint8_t*)a->
address, strlen(a->
address));
158 HT_INIT(cache_map, &cache_root);
166 static int all_down = 0;
170 log_info(LD_EXIT,
"eventdns: Resolve requested.");
175 if (!
strcmpstart(msg,
"Nameserver ") && (cp=strstr(msg,
" has failed: "))) {
176 char *ns = tor_strndup(msg+11, cp-(msg+11));
177 const char *colon = strchr(cp,
':');
179 const char *err = colon+2;
185 "NAMESERVER_STATUS NS=%s STATUS=DOWN ERR=%s",
189 (cp=strstr(msg,
" is back up"))) {
190 char *ns = tor_strndup(msg+11, cp-(msg+11));
194 "NAMESERVER_STATUS NS=%s STATUS=UP", ns);
196 }
else if (!strcmp(msg,
"All nameservers have failed")) {
199 }
else if (!
strcmpstart(msg,
"Address mismatch on received DNS")) {
200 static ratelim_t mismatch_limit = RATELIM_INIT(3600);
201 const char *src = strstr(msg,
" Apparent source");
206 "eventdns: Received a DNS packet from "
207 "an IP address to which we did not send a request. This "
208 "could be a DNS spoofing attempt, or some kind of "
209 "misconfiguration.%s", src);
212 tor_log(severity, LD_EXIT,
"eventdns: %s", msg);
237 log_err(
LD_BUG,
"Couldn't create an evdns_base");
276 r->
magic = 0xFF00FF00;
287 if (a->
expire < b->expire)
289 else if (a->
expire == b->expire)
304 const char *answer_hostname,
307 if (query_type == DNS_PTR) {
311 if (dns_result == DNS_ERR_NONE && answer_hostname) {
312 resolve->result_ptr.hostname = tor_strdup(answer_hostname);
319 }
else if (query_type == DNS_IPv4_A) {
323 if (dns_result == DNS_ERR_NONE && answer_addr &&
332 }
else if (query_type == DNS_IPv6_AAAA) {
336 if (dns_result == DNS_ERR_NONE && answer_addr &&
367 resolve->
expire = expires;
387 for (ptr = HT_START(cache_map, &cache_root); ptr != NULL; ptr = next) {
389 next = HT_NEXT_RMV(cache_map, &cache_root, ptr);
392 HT_CLEAR(cache_map, &cache_root);
413 if (resolve->
expire > now)
421 "Expiring a dns resolve %s that's still pending. Forgot to "
422 "cull it? DNS resolve didn't tell us about the timeout?",
426 "Forgetting old cached resolve (address %s, expires %lu)",
428 (
unsigned long)resolve->
expire);
437 "Closing pending connections on timed-out DNS resolve!");
443 pendconn = pend->conn;
457 removed = HT_REMOVE(cache_map, &cache_root, resolve);
458 if (removed != resolve) {
459 log_err(
LD_BUG,
"The expired resolve we purged didn't match any in"
460 " the cache. Tried to purge %s (%p); instead got %s (%p).",
461 resolve->
address, (
void*)resolve,
462 removed ? removed->
address :
"NULL", (
void*)removed);
471 tor_free(resolve->result_ptr.hostname);
472 resolve->
magic = 0xF0BBF0BB;
481 #define RESOLVED_TYPE_AUTO 0xff
499 buf[0] = answer_type;
504 case RESOLVED_TYPE_AUTO:
506 cp[0] = RESOLVED_TYPE_IPV4;
514 cp[0] = RESOLVED_TYPE_IPV6;
516 memcpy(cp+2, bytes, 16);
524 answer_type = RESOLVED_TYPE_ERROR;
528 case RESOLVED_TYPE_ERROR_TRANSIENT:
529 case RESOLVED_TYPE_ERROR:
531 const char *errmsg =
"Error resolving hostname";
532 size_t msglen = strlen(errmsg);
534 buf[0] = answer_type;
536 strlcpy(buf+2, errmsg,
sizeof(buf)-2);
560 const char *hostname))
569 size_t namelen = strlen(hostname);
574 buf[0] = RESOLVED_TYPE_HOSTNAME;
575 buf[1] = (uint8_t)namelen;
576 memcpy(buf+2, hostname, namelen);
578 buflen = 2+namelen+4;
614 int made_connection_pending = 0;
615 char *hostname = NULL;
620 &made_connection_pending, &resolve);
653 (r == -1) ? RESOLVED_TYPE_ERROR : RESOLVED_TYPE_ERROR_TRANSIENT,
694 int *made_connection_pending_out,
702 time_t now = time(NULL);
708 *made_connection_pending_out = 0;
729 tor_log(LOG_PROTOCOL_WARN, LD_EXIT,
730 "Rejecting invalid destination address %s",
747 AF_UNSPEC, 0)) != 0) {
750 if (tor_addr_is_internal(&addr, 0))
754 if (!is_reverse || !is_resolve) {
756 log_info(LD_EXIT,
"Bad .in-addr.arpa address \"%s\"; sending error.",
758 else if (!is_resolve)
760 "Attempt to connect to a .in-addr.arpa address \"%s\"; "
773 resolve = HT_FIND(cache_map, &cache_root, &search);
774 if (resolve && resolve->
expire > now) {
775 switch (resolve->
state) {
778 pending_connection = tor_malloc_zero(
780 pending_connection->conn = exitconn;
783 *made_connection_pending_out = 1;
784 log_debug(LD_EXIT,
"Connection (fd "TOR_SOCKET_T_FORMAT
") waiting "
785 "for pending DNS resolve of %s", exitconn->base_.
s,
789 log_debug(LD_EXIT,
"Connection (fd "TOR_SOCKET_T_FORMAT
") found "
790 "cached answer for %s",
794 *resolve_out = resolve;
798 log_err(
LD_BUG,
"Found a 'DONE' dns resolve still in the cache.");
813 pending_connection->conn = exitconn;
815 *made_connection_pending_out = 1;
818 HT_INSERT(cache_map, &cache_root, resolve);
821 log_debug(LD_EXIT,
"Launching %s.",
847 char **hostname_out))
849 int ipv4_ok, ipv6_ok, answer_with_ipv4, r;
850 uint32_t begincell_flags;
858 *hostname_out = tor_strdup(resolve->result_ptr.hostname);
870 begincell_flags = exitconn->begincell_flags;
880 if (ipv4_ok && ipv6_ok && is_resolve) {
881 answer_with_ipv4 = 1;
882 }
else if (ipv4_ok && ipv6_ok) {
884 const uint16_t port = exitconn->base_.
port;
885 int ipv4_allowed, ipv6_allowed;
891 if (ipv4_allowed && !ipv6_allowed) {
892 answer_with_ipv4 = 1;
893 }
else if (ipv6_allowed && !ipv4_allowed) {
894 answer_with_ipv4 = 0;
898 answer_with_ipv4 = !(begincell_flags &
904 answer_with_ipv4 = 1;
905 }
else if (ipv6_ok) {
906 answer_with_ipv4 = 0;
909 answer_with_ipv4 = !(begincell_flags &
916 if (answer_with_ipv4) {
950 resolve = HT_FIND(cache_map, &cache_root, &search);
958 HT_FOREACH(resolve, cache_map, &cache_root) {
959 for (pend = (*resolve)->pending_connections; pend; pend = pend->next) {
980 resolve = HT_FIND(cache_map, &cache_root, &search);
982 log_notice(
LD_BUG,
"Address %s is not pending. Dropping.",
992 if (pend->conn == conn) {
995 log_debug(LD_EXIT,
"First connection (fd "TOR_SOCKET_T_FORMAT
") no "
996 "longer waiting for resolve of %s",
1001 for ( ; pend->next; pend = pend->next) {
1002 if (pend->next->conn == conn) {
1003 victim = pend->next;
1004 pend->next = victim->next;
1007 "Connection (fd "TOR_SOCKET_T_FORMAT
") no longer waiting "
1008 "for resolve of %s",
1013 log_warn(
LD_BUG,
"Connection (fd "TOR_SOCKET_T_FORMAT
") was not waiting "
1014 "for a resolve of %s, but we tried to remove it.",
1034 resolve = HT_FIND(cache_map, &cache_root, &search);
1044 "Address %s is not pending but has pending connections!",
1053 "Address %s is pending but has no pending connections!",
1062 "Failing all connections waiting on DNS resolve of %s",
1067 pendconn = pend->conn;
1082 tmp = HT_REMOVE(cache_map, &cache_root, resolve);
1083 if (tmp != resolve) {
1084 log_err(
LD_BUG,
"The cancelled resolve we purged didn't match any in"
1085 " the cache. Tried to purge %s (%p); instead got %s (%p).",
1086 resolve->
address, (
void*)resolve,
1087 tmp ? tmp->
address :
"NULL", (
void*)tmp);
1117 const char *hostname, uint32_t ttl)
1126 resolve = HT_FIND(cache_map, &cache_root, &search);
1130 log_info(LD_EXIT,
"Resolved unasked address %s; ignoring.",
1142 "Resolved %s which was already resolved; ignoring",
1148 cached_resolve_add_answer(resolve, query_type, dns_answer,
1149 addr, hostname, ttl);
1174 char *hostname = NULL;
1176 pendconn = pend->conn;
1201 RESOLVED_TYPE_ERROR : RESOLVED_TYPE_ERROR_TRANSIENT,
1256 removed = HT_REMOVE(cache_map, &cache_root, resolve);
1257 if (removed != resolve) {
1258 log_err(
LD_BUG,
"The pending resolve we found wasn't removable from"
1259 " the cache. Tried to purge %s (%p); instead got %s (%p).",
1260 resolve->
address, (
void*)resolve,
1261 removed ? removed->
address :
"NULL", (
void*)removed);
1272 uint32_t ttl = UINT32_MAX;
1275 new_resolve->result_ptr.hostname =
1276 tor_strdup(resolve->result_ptr.hostname);
1281 HT_INSERT(cache_map, &cache_root, new_resolve);
1311 case DNS_ERR_SERVERFAILED:
1312 case DNS_ERR_TRUNCATED:
1313 case DNS_ERR_TIMEOUT:
1329 #ifdef HAVE_EVDNS_BASE_GET_NAMESERVER_ADDR
1335 configured_nameserver_address(
const size_t idx)
1337 struct sockaddr_storage sa;
1338 ev_socklen_t sa_len =
sizeof(sa);
1341 (
struct sockaddr *)&sa,
1345 (
const struct sockaddr *)&sa,
1366 const char *conf_fname;
1373 conf_fname =
"/etc/resolv.conf";
1375 flags = DNS_OPTIONS_ALL;
1379 log_err(
LD_BUG,
"Couldn't create an evdns_base");
1386 log_debug(
LD_FS,
"stat()ing %s", conf_fname);
1387 int missing_resolv_conf = 0;
1391 log_warn(LD_EXIT,
"Unable to stat resolver configuration in '%s': %s",
1392 conf_fname, strerror(errno));
1393 missing_resolv_conf = 1;
1397 log_info(LD_EXIT,
"No change to '%s'", conf_fname);
1401 if (stat_res == 0 && st.st_size == 0)
1402 missing_resolv_conf = 1;
1408 #if defined(DNS_OPTION_HOSTSFILE) && defined(USE_LIBSECCOMP)
1409 if (flags & DNS_OPTION_HOSTSFILE) {
1410 flags ^= DNS_OPTION_HOSTSFILE;
1411 log_debug(
LD_FS,
"Loading /etc/hosts");
1417 if (!missing_resolv_conf) {
1418 log_info(LD_EXIT,
"Parsing resolver configuration in '%s'", conf_fname);
1421 log_warn(LD_EXIT,
"Unable to parse '%s', or no nameservers "
1422 "in '%s' (%d)", conf_fname, conf_fname, r);
1429 log_warn(LD_EXIT,
"Unable to find any nameservers in '%s'.",
1437 log_warn(LD_EXIT,
"Could not read your DNS config from '%s' - "
1438 "please investigate your DNS configuration. "
1439 "This is possibly a problem. Meanwhile, falling"
1440 " back to local DNS at 127.0.0.1.", conf_fname);
1454 log_warn(LD_EXIT,
"Could not config nameservers.");
1458 log_warn(LD_EXIT,
"Unable to find any platform nameservers in "
1459 "your Windows configuration.");
1469 #define SET(k,v) evdns_base_set_option(the_evdns_base, (k), (v))
1479 SET(
"max-timeouts:",
"1000000");
1481 SET(
"max-timeouts:",
"10");
1490 SET(
"max-inflight:",
"8192");
1496 SET(
"timeout:",
"5");
1497 SET(
"attempts:",
"3");
1500 SET(
"randomize-case:",
"1");
1502 SET(
"randomize-case:",
"0");
1534 uint8_t orig_query_type = arg_[0];
1535 char *string_address = arg_ + 1;
1537 const char *hostname = NULL;
1538 int was_wildcarded = 0;
1543 if (result == DNS_ERR_TIMEOUT) {
1553 if (type == DNS_IPv6_AAAA) {
1554 if (result == DNS_ERR_TIMEOUT) {
1558 if (n_ipv6_timeouts > 10 &&
1559 n_ipv6_timeouts > n_ipv6_requests_made / 2) {
1560 if (! dns_is_broken_for_ipv6) {
1561 log_notice(LD_EXIT,
"More than half of our IPv6 requests seem to "
1562 "have timed out. I'm going to assume I can't get AAAA "
1564 dns_is_broken_for_ipv6 = 1;
1569 if (result == DNS_ERR_NONE) {
1570 if (type == DNS_IPv4_A && count) {
1572 char *escaped_address;
1573 uint32_t *addrs = addresses;
1580 log_debug(LD_EXIT,
"eventdns said that %s resolves to ISP-hijacked "
1581 "address %s; treating as a failure.",
1582 safe_str(escaped_address),
1586 result = DNS_ERR_NOTEXIST;
1588 log_debug(LD_EXIT,
"eventdns said that %s resolves to %s",
1589 safe_str(escaped_address),
1593 }
else if (type == DNS_IPv6_AAAA && count) {
1595 char *escaped_address;
1597 struct in6_addr *addrs = addresses;
1600 sizeof(answer_buf));
1603 if (BUG(ip_str == NULL)) {
1604 log_warn(LD_EXIT,
"tor_inet_ntop() failed!");
1605 result = DNS_ERR_NOTEXIST;
1607 log_debug(LD_EXIT,
"eventdns said that %s resolves to ISP-hijacked "
1608 "address %s; treating as a failure.",
1609 safe_str(escaped_address),
1613 result = DNS_ERR_NOTEXIST;
1615 log_debug(LD_EXIT,
"eventdns said that %s resolves to %s",
1616 safe_str(escaped_address),
1620 }
else if (type == DNS_PTR && count) {
1621 char *escaped_address;
1622 hostname = ((
char**)addresses)[0];
1624 log_debug(LD_EXIT,
"eventdns said that %s resolves to %s",
1625 safe_str(escaped_address),
1629 log_info(LD_EXIT,
"eventdns returned only unrecognized answer types "
1633 log_info(LD_EXIT,
"eventdns returned no addresses or error for %s.",
1637 if (was_wildcarded) {
1645 if (orig_query_type && type && orig_query_type != type) {
1646 log_warn(
LD_BUG,
"Weird; orig_query_type == %d but type == %d",
1647 (
int)orig_query_type, (
int)type);
1649 if (result != DNS_ERR_SHUTDOWN)
1651 result, &addr, hostname, ttl);
1668 : DNS_QUERY_NO_SEARCH;
1669 const size_t addr_len = strlen(address);
1670 struct evdns_request *req = 0;
1671 char *addr = tor_malloc(addr_len + 2);
1672 addr[0] = (char) query_type;
1673 memcpy(addr+1, address, addr_len + 1);
1678 switch (query_type) {
1686 ++n_ipv6_requests_made;
1692 DNS_QUERY_NO_SEARCH,
1697 DNS_QUERY_NO_SEARCH,
1700 log_warn(
LD_BUG,
"Called with PTR query and unexpected address family");
1703 log_warn(
LD_BUG,
"Called with unexpected query type %d", (
int)query_type);
1729 log_warn(LD_EXIT,
"(Harmless.) Nameservers not configured, but resolve "
1730 "launched. Configuring.");
1737 &a, resolve->
address, AF_UNSPEC, 0);
1741 log_info(LD_EXIT,
"Launching eventdns request for %s",
1748 resolve->res_status_ipv4 = 0;
1755 resolve->res_status_ipv6 = 0;
1759 }
else if (r == 1) {
1761 log_info(LD_EXIT,
"Launching eventdns reverse request for %s",
1765 resolve->res_status_hostname = 0;
1768 }
else if (r == -1) {
1769 log_warn(
LD_BUG,
"Somehow a malformed in-addr.arpa address reached here.");
1773 log_fn(LOG_PROTOCOL_WARN, LD_EXIT,
"eventdns rejected address %s.",
1818 ip = tor_malloc_zero(
sizeof(
int));
1827 "Your DNS provider has given \"%s\" as an answer for %d different "
1828 "invalid addresses. Apparently they are hijacking DNS failures. "
1829 "I'll try to correct for this by treating future occurrences of "
1830 "\"%s\" as 'not found'.",
id, *ip,
id);
1844 int n, n_test_addrs;
1853 smartlist_len(
get_options()->ServerDNSTestAddresses) : 0;
1857 if (n > n_test_addrs/2) {
1859 LD_EXIT,
"Your DNS provider tried to redirect \"%s\" to a junk "
1860 "address. It has done this with %d test addresses so far. I'm "
1861 "going to stop being an exit node for now, since our DNS seems so "
1862 "broken.", address, n);
1877 void *addresses,
void *arg)
1882 if (result == DNS_ERR_NONE && count) {
1883 char *string_address = arg;
1885 if (type == DNS_IPv4_A) {
1886 const uint32_t *addrs = addresses;
1887 for (i = 0; i < count; ++i) {
1891 in.s_addr = addrs[i];
1892 ntoa_res =
tor_inet_ntoa(&in, answer_buf,
sizeof(answer_buf));
1893 tor_assert_nonfatal(ntoa_res >= 0);
1897 }
else if (type == DNS_IPv6_AAAA) {
1898 const struct in6_addr *addrs = addresses;
1899 for (i = 0; i < count; ++i) {
1902 sizeof(answer_buf));
1903 tor_assert_nonfatal(ip_str);
1910 "Your DNS provider gave an answer for \"%s\", which "
1911 "is not supposed to exist. Apparently they are hijacking "
1912 "DNS failures. Trying to correct for this. We've noticed %d "
1913 "possibly bad address%s so far.",
1929 struct evdns_request *req;
1932 log_info(LD_EXIT,
"Testing whether our DNS server is hijacking nonexistent "
1933 "domains with request for bogus hostname \"%s\"", addr);
1937 req = evdns_base_resolve_ipv6(
1944 req = evdns_base_resolve_ipv4(
1969 log_info(LD_EXIT,
"Launching checks to see whether our nameservers like to "
1970 "hijack *everything*.");
1978 const char *, address) {
1980 log_info(LD_EXIT,
"eventdns rejected test address %s",
1985 log_info(LD_EXIT,
"eventdns rejected test address %s",
1988 } SMARTLIST_FOREACH_END(address);
1992 #define N_WILDCARD_CHECKS 2
2002 log_info(LD_EXIT,
"Launching checks to see whether our nameservers like "
2003 "to hijack DNS failures.");
2004 for (ipv6 = 0; ipv6 <= 1; ++ipv6) {
2005 for (i = 0; i < N_WILDCARD_CHECKS; ++i) {
2032 static struct event *launch_event = NULL;
2045 if (evtimer_add(launch_event, &
timeout) < 0) {
2046 log_warn(
LD_BUG,
"Couldn't add timer for checking for dns hijacking");
2061 return dns_is_broken_for_ipv6;
2073 n_ipv6_requests_made = n_ipv6_timeouts = 0;
2086 dns_is_broken_for_ipv6 = 0;
2112 if (resolve->is_reverse)
2125 return HT_SIZE(&cache_root);
2130 dns_cache_total_allocation(
void)
2133 HT_MEM_USAGE(&cache_root);
2142 size_t hash_mem = dns_cache_total_allocation();
2147 tor_log(severity,
LD_MM,
"Our DNS cache has %d entries.", hash_count);
2148 tor_log(severity,
LD_MM,
"Our DNS cache size is approximately %u bytes.",
2149 (
unsigned)hash_mem);
2156 dns_cache_handle_oom(time_t now,
size_t min_remove_bytes)
2158 time_t time_inc = 0;
2159 size_t total_bytes_removed = 0;
2160 size_t current_size = dns_cache_total_allocation();
2168 time_t cutoff = now + time_inc;
2172 size_t bytes_removed = current_size - dns_cache_total_allocation();
2173 current_size -= bytes_removed;
2174 total_bytes_removed += bytes_removed;
2178 }
while (total_bytes_removed < min_remove_bytes);
2180 return total_bytes_removed;
2183 #ifdef DEBUG_DNS_CACHE
2186 assert_cache_ok_(
void)
2189 int bad_rep = HT_REP_IS_BAD_(cache_map, &cache_root);
2191 log_err(
LD_BUG,
"Bad rep type %d on dns cache hash table", bad_rep);
2195 HT_FOREACH(resolve, cache_map, &cache_root) {
2209 cached_resolve_t *found = HT_FIND(cache_map, &cache_root, res);
2210 tor_assert(!found || found != res);
2212 cached_resolve_t *found = HT_FIND(cache_map, &cache_root, res);
2223 return HT_FIND(cache_map, &cache_root, query);
2229 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)
const char * tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len, int decorate)
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)
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 or_options_t * get_options(void)
const char * escaped_safe_str(const char *address)
Header file for config.c.
void assert_connection_ok(connection_t *conn, time_t now)
void connection_free_(connection_t *conn)
Header file for connection.c.
void connection_exit_connect(edge_connection_t *edge_conn)
uint32_t clip_dns_ttl(uint32_t ttl)
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 int dns_wildcard_one_notice_given
static int nameservers_configured
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)
void connection_dns_remove(edge_connection_t *conn)
static smartlist_t * dns_wildcarded_test_address_list
int has_dns_init_failed(void)
static int dns_is_completely_invalid
void dump_dns_mem_usage(int severity)
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 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 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 HT_HEAD(cache_map, cached_resolve_t)
void assert_connection_edge_not_dns_pending(edge_connection_t *conn)
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.
const char * escaped(const char *s)
char * esc_for_log(const char *s)
HT_PROTOTYPE(hs_circuitmap_ht, circuit_t, hs_circuitmap_node, hs_circuit_hash_token, hs_circuits_have_same_token)
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_free_(void *mem)
void * tor_reallocarray_(void *ptr, size_t sz1, size_t sz2)
int net_is_disabled(void)
Master header file for Tor-specific functionality.
#define RELAY_PAYLOAD_SIZE
Header file for policies.c.
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)
void rep_hist_note_overload(overload_type_t overload)
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.
int server_mode(const or_options_t *options)
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_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_pqueue_pop(smartlist_t *sl, int(*compare)(const void *a, const void *b), ptrdiff_t idx_field_offset)
smartlist_t * smartlist_new(void)
void smartlist_add_strdup(struct smartlist_t *sl, const char *string)
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::@18 result_ipv4
char address[MAX_ADDRESSLEN]
pending_connection_t * pending_connections
union cached_resolve_t::@19 result_ipv6
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
int ServerDNSRandomizeCase
#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)