Tor  0.4.7.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-2021, 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;
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 int set_exitconn_info_from_resolve(edge_connection_t *exitconn, const cached_resolve_t *resolve, char **hostname_out)
Definition: dns.c:847
int dns_init(void)
Definition: dns.c:217
int dns_seems_to_be_broken(void)
Definition: dns.c:2052
STATIC void send_resolved_cell(edge_connection_t *conn, uint8_t answer_type, const cached_resolve_t *resolved)
Definition: dns.c:493
void dns_reset_correctness_checks(void)
Definition: dns.c:2066
STATIC void send_resolved_hostname_cell(edge_connection_t *conn, const char *hostname)
Definition: dns.c:560
STATIC void dns_cancel_pending_resolve(const char *address)
Definition: dns.c:1024
size_t number_of_configured_nameservers(void)
Definition: dns.c:1324
void connection_dns_remove(edge_connection_t *conn)
Definition: dns.c:969
int has_dns_init_failed(void)
Definition: dns.c:258
void dump_dns_mem_usage(int severity)
Definition: dns.c:2138
void dns_free_all(void)
Definition: dns.c:376
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:695
STATIC int launch_resolve(cached_resolve_t *resolve)
Definition: dns.c:1719
int dns_seems_to_be_broken_for_ipv6(void)
Definition: dns.c:2059
int dns_resolve(edge_connection_t *exitconn)
Definition: dns.c:610
int dns_reset(void)
Definition: dns.c:230
void dns_launch_correctness_checks(void)
Definition: dns.c:2030
void assert_connection_edge_not_dns_pending(edge_connection_t *conn)
Definition: dns.c:942
Structures used in dns.c. Exposed to dns.c, and to the unit tests that declare DNS_PRIVATE.
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
#define tor_assert_nonfatal_unreached()
Definition: util_bug.h:176