Tor  0.4.8.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);
30 
31 /* These functions are only used within the feature/relay module, and don't
32  * need stubs. */
33 void dns_free_all(void);
35 
36 #else /* !defined(HAVE_MODULE_RELAY) */
37 
38 #define dns_init() (0)
39 #define dns_seems_to_be_broken() (0)
40 #define has_dns_init_failed() (0)
41 #define dns_cache_total_allocation() (0)
42 
43 #define dns_reset_correctness_checks() STMT_NIL
44 
45 #define assert_connection_edge_not_dns_pending(conn) \
46  ((void)(conn))
47 #define dump_dns_mem_usage(severity)\
48  ((void)(severity))
49 #define dns_cache_handle_oom(now, bytes) \
50  ((void)(now), (void)(bytes), 0)
51 #define dns_new_consensus_params(ns) \
52  ((void) ns)
53 
54 #define connection_dns_remove(conn) \
55  STMT_BEGIN \
56  (void)(conn); \
57  tor_assert_nonfatal_unreached(); \
58  STMT_END
59 
60 static inline int
61 dns_reset(void)
62 {
63  return 0;
64 }
65 static inline int
67 {
68  (void)exitconn;
70  return -1;
71 }
72 
73 #endif /* defined(HAVE_MODULE_RELAY) */
74 
75 #ifdef DNS_PRIVATE
77 
79 #ifdef HAVE_EVDNS_BASE_GET_NAMESERVER_ADDR
80 tor_addr_t *configured_nameserver_address(const size_t idx);
81 #endif
82 
83 MOCK_DECL(STATIC void,dns_cancel_pending_resolve,(const char *question));
85 int is_resolve,or_circuit_t *oncirc, char **hostname_out,
86 int *made_connection_pending_out, cached_resolve_t **resolve_out));
87 
89 uint8_t answer_type,const cached_resolve_t *resolved));
90 
92 const char *hostname));
93 
94 cached_resolve_t *dns_get_cache_entry(cached_resolve_t *query);
95 void dns_insert_cache_entry(cached_resolve_t *new_entry);
96 
97 MOCK_DECL(STATIC int,
99  const cached_resolve_t *resolve,
100  char **hostname_out));
101 
102 MOCK_DECL(STATIC int,
103 launch_resolve,(cached_resolve_t *resolve));
104 
105 #endif /* defined(DNS_PRIVATE) */
106 
107 #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:862
int dns_init(void)
Definition: dns.c:232
void dns_new_consensus_params(const networkstatus_t *ns)
Definition: dns.c:219
int dns_seems_to_be_broken(void)
Definition: dns.c:2129
STATIC void send_resolved_cell(edge_connection_t *conn, uint8_t answer_type, const cached_resolve_t *resolved)
Definition: dns.c:508
void dns_reset_correctness_checks(void)
Definition: dns.c:2143
STATIC void send_resolved_hostname_cell(edge_connection_t *conn, const char *hostname)
Definition: dns.c:575
STATIC void dns_cancel_pending_resolve(const char *address)
Definition: dns.c:1039
size_t number_of_configured_nameservers(void)
Definition: dns.c:1339
void connection_dns_remove(edge_connection_t *conn)
Definition: dns.c:984
int has_dns_init_failed(void)
Definition: dns.c:273
void dump_dns_mem_usage(int severity)
Definition: dns.c:2215
void dns_free_all(void)
Definition: dns.c:391
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:710
STATIC int launch_resolve(cached_resolve_t *resolve)
Definition: dns.c:1796
int dns_seems_to_be_broken_for_ipv6(void)
Definition: dns.c:2136
int dns_resolve(edge_connection_t *exitconn)
Definition: dns.c:625
int dns_reset(void)
Definition: dns.c:245
void dns_launch_correctness_checks(void)
Definition: dns.c:2107
void assert_connection_edge_not_dns_pending(edge_connection_t *conn)
Definition: dns.c:957
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