Macros | Functions
dns.h File Reference

Go to the source code of this file.


#define MIN_DNS_TTL_AT_EXIT   (5*60)
#define MAX_DNS_TTL_AT_EXIT   (60*60)
#define MAX_DNS_ENTRY_AGE   (3*60*60)
#define DEFAULT_DNS_TTL   (30*60)


int dns_init (void)
int has_dns_init_failed (void)
void dns_free_all (void)
uint32_t dns_clip_ttl (uint32_t ttl)
int dns_reset (void)
void connection_dns_remove (edge_connection_t *conn)
void assert_connection_edge_not_dns_pending (edge_connection_t *conn)
void assert_all_pending_dns_resolves_ok (void)
 MOCK_DECL (void, dns_cancel_pending_resolve,(const char *question))
int dns_resolve (edge_connection_t *exitconn)
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)
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)

Detailed Description

Header file for dns.c.

Definition in file dns.h.

Macro Definition Documentation


#define DEFAULT_DNS_TTL   (30*60)

How long do we cache/tell clients to cache DNS records when no TTL is known?

Definition at line 25 of file dns.h.


#define MAX_DNS_ENTRY_AGE   (3*60*60)

How long do we keep DNS cache entries before purging them (regardless of their TTL)?

Definition at line 22 of file dns.h.


#define MAX_DNS_TTL_AT_EXIT   (60*60)

Highest value for DNS ttl that a server will give.

Definition at line 18 of file dns.h.

Referenced by dns_clip_ttl().


#define MIN_DNS_TTL_AT_EXIT   (5*60)

Lowest value for DNS ttl that a server will give.

Definition at line 16 of file dns.h.

Referenced by dns_clip_ttl().

Function Documentation

◆ assert_all_pending_dns_resolves_ok()

void assert_all_pending_dns_resolves_ok ( void  )

Log an error and abort if any connection waiting for a DNS resolve is corrupted.

Definition at line 993 of file dns.c.

References assert_connection_ok(), connection_in_array(), connection_t::s, SOCKET_OK, TO_CONN, and tor_assert().

◆ 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().

◆ 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 1012 of file dns.c.

References CONN_TYPE_EXIT, EXIT_CONN_STATE_RESOLVING, connection_t::state, tor_assert(), and connection_t::type.

Referenced by connection_exit_about_to_close().

◆ dns_clip_ttl()

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, and how long to cache that record ourselves.

Definition at line 275 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 400 of file dns.c.

◆ dns_init()

int dns_init ( void  )

Initialize the DNS subsystem; called by the OR process.

Definition at line 224 of file dns.c.

References configure_nameservers(), and dns_randfn_().

Referenced by retry_dns_callback().

◆ 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 2044 of file dns.c.

References dns_launch_wildcard_checks().

◆ 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 238 of file dns.c.

References the_evdns_base.

◆ dns_reset_correctness_checks()

void dns_reset_correctness_checks ( void  )

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

Definition at line 2080 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 634 of file dns.c.

References EXIT_PURPOSE_RESOLVE, edge_connection_t::on_circuit, connection_t::purpose, and TO_OR_CIRCUIT().

◆ 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 2066 of file dns.c.

References dns_is_completely_invalid.

◆ 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 2073 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 2152 of file dns.c.

References dns_cache_entry_count().

Referenced by dumpmemusage().

◆ 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 266 of file dns.c.

References nameserver_config_failed.

Referenced by retry_dns_callback().