Tor  0.4.4.0-alpha-dev
dns.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2020, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file dns.h
9  * \brief Header file for dns.c.
10  **/
11 
12 #ifndef TOR_DNS_H
13 #define TOR_DNS_H
14 
15 #ifdef HAVE_MODULE_RELAY
16 
17 int dns_init(void);
18 int has_dns_init_failed(void);
19 int dns_reset(void);
22 int dns_resolve(edge_connection_t *exitconn);
23 int dns_seems_to_be_broken(void);
26 size_t dns_cache_total_allocation(void);
27 void dump_dns_mem_usage(int severity);
28 size_t dns_cache_handle_oom(time_t now, size_t min_remove_bytes);
29 
30 /* These functions are only used within the feature/relay module, and don't
31  * need stubs. */
32 void dns_free_all(void);
34 
35 #else /* !defined(HAVE_MODULE_RELAY) */
36 
37 #define dns_init() (0)
38 #define dns_seems_to_be_broken() (0)
39 #define has_dns_init_failed() (0)
40 #define dns_cache_total_allocation() (0)
41 
42 #define dns_reset_correctness_checks() STMT_NIL
43 
44 #define assert_connection_edge_not_dns_pending(conn) \
45  ((void)(conn))
46 #define dump_dns_mem_usage(severity)\
47  ((void)(severity))
48 #define dns_cache_handle_oom(now, bytes) \
49  ((void)(now), (void)(bytes), 0)
50 
51 #define connection_dns_remove(conn) \
52  STMT_BEGIN \
53  (void)(conn); \
54  tor_assert_nonfatal_unreached(); \
55  STMT_END
56 
57 static inline int
58 dns_reset(void)
59 {
60  return 0;
61 }
62 static inline int
64 {
65  (void)exitconn;
66  tor_assert_nonfatal_unreached();
67  return -1;
68 }
69 
70 #endif /* defined(HAVE_MODULE_RELAY) */
71 
72 #ifdef DNS_PRIVATE
74 
76 #ifdef HAVE_EVDNS_BASE_GET_NAMESERVER_ADDR
77 tor_addr_t *configured_nameserver_address(const size_t idx);
78 #endif
79 
80 MOCK_DECL(STATIC void,dns_cancel_pending_resolve,(const char *question));
82 int is_resolve,or_circuit_t *oncirc, char **hostname_out,
83 int *made_connection_pending_out, cached_resolve_t **resolve_out));
84 
86 uint8_t answer_type,const cached_resolve_t *resolved));
87 
89 const char *hostname));
90 
91 cached_resolve_t *dns_get_cache_entry(cached_resolve_t *query);
92 void dns_insert_cache_entry(cached_resolve_t *new_entry);
93 
94 MOCK_DECL(STATIC int,
96  const cached_resolve_t *resolve,
97  char **hostname_out));
98 
99 MOCK_DECL(STATIC int,
100 launch_resolve,(cached_resolve_t *resolve));
101 
102 #endif /* defined(DNS_PRIVATE) */
103 
104 #endif /* !defined(TOR_DNS_H) */
STATIC void dns_cancel_pending_resolve(const char *address)
Definition: dns.c:1032
void assert_connection_edge_not_dns_pending(edge_connection_t *conn)
Definition: dns.c:950
void connection_dns_remove(edge_connection_t *conn)
Definition: dns.c:977
STATIC void send_resolved_cell(edge_connection_t *conn, uint8_t answer_type, const cached_resolve_t *resolved)
Definition: dns.c:501
int dns_init(void)
Definition: dns.c:224
int dns_seems_to_be_broken_for_ipv6(void)
Definition: dns.c:2038
void dns_reset_correctness_checks(void)
Definition: dns.c:2045
#define STATIC
Definition: testsupport.h:32
Structures used in dns.c. Exposed to dns.c, and to the unit tests that declare DNS_PRIVATE.
STATIC int set_exitconn_info_from_resolve(edge_connection_t *exitconn, const cached_resolve_t *resolve, char **hostname_out)
Definition: dns.c:855
void dns_free_all(void)
Definition: dns.c:384
int has_dns_init_failed(void)
Definition: dns.c:266
int dns_reset(void)
Definition: dns.c:238
int dns_resolve(edge_connection_t *exitconn)
Definition: dns.c:618
int dns_seems_to_be_broken(void)
Definition: dns.c:2031
size_t number_of_configured_nameservers(void)
Definition: dns.c:1332
void dump_dns_mem_usage(int severity)
Definition: dns.c:2117
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
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)
Definition: dns.c:703
STATIC int launch_resolve(cached_resolve_t *resolve)
Definition: dns.c:1705
STATIC void send_resolved_hostname_cell(edge_connection_t *conn, const char *hostname)
Definition: dns.c:568
void dns_launch_correctness_checks(void)
Definition: dns.c:2009