Line | Count | Source |
1 | | #ifndef HEADER_CURL_HOSTIP_H |
2 | | #define HEADER_CURL_HOSTIP_H |
3 | | /*************************************************************************** |
4 | | * _ _ ____ _ |
5 | | * Project ___| | | | _ \| | |
6 | | * / __| | | | |_) | | |
7 | | * | (__| |_| | _ <| |___ |
8 | | * \___|\___/|_| \_\_____| |
9 | | * |
10 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
11 | | * |
12 | | * This software is licensed as described in the file COPYING, which |
13 | | * you should have received as part of this distribution. The terms |
14 | | * are also available at https://curl.se/docs/copyright.html. |
15 | | * |
16 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
17 | | * copies of the Software, and permit persons to whom the Software is |
18 | | * furnished to do so, under the terms of the COPYING file. |
19 | | * |
20 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
21 | | * KIND, either express or implied. |
22 | | * |
23 | | * SPDX-License-Identifier: curl |
24 | | * |
25 | | ***************************************************************************/ |
26 | | #include "curl_setup.h" |
27 | | |
28 | | #include "hash.h" |
29 | | #include "curlx/timeval.h" /* for curltime, timediff_t */ |
30 | | |
31 | | /* Allocate enough memory to hold the full name information structs and |
32 | | * everything. OSF1 is known to require at least 8872 bytes. The buffer |
33 | | * required for storing all possible aliases and IP numbers is according to |
34 | | * Stevens' Unix Network Programming 2nd edition, p. 304: 8192 bytes! |
35 | | */ |
36 | | #define CURL_HOSTENT_SIZE 9000 |
37 | | |
38 | 0 | #define CURL_TIMEOUT_RESOLVE_MS (300 * 1000) |
39 | | |
40 | | struct addrinfo; |
41 | | struct hostent; |
42 | | struct Curl_easy; |
43 | | struct connectdata; |
44 | | struct easy_pollset; |
45 | | struct Curl_https_rrinfo; |
46 | | struct Curl_multi; |
47 | | struct Curl_dns_entry; |
48 | | struct Curl_peer; |
49 | | |
50 | | /* DNS query types */ |
51 | 0 | #define CURL_DNSQ_A (1U << 0) |
52 | 0 | #define CURL_DNSQ_AAAA (1U << 1) |
53 | 0 | #define CURL_DNSQ_HTTPS (1U << 2) |
54 | | |
55 | 0 | #define CURL_DNSQ_ALL (CURL_DNSQ_A | CURL_DNSQ_AAAA | CURL_DNSQ_HTTPS) |
56 | 0 | #define CURL_DNSQ_IP(x) (uint8_t)((x)&(CURL_DNSQ_A | CURL_DNSQ_AAAA)) |
57 | | |
58 | | #ifdef CURLVERBOSE |
59 | | const char *Curl_resolv_query_str(uint8_t dns_queries); |
60 | | #endif |
61 | | |
62 | | /* Return CURL_DNSQ_* bits for the transfer and ip_version. */ |
63 | | uint8_t Curl_resolv_dns_queries(struct Curl_easy *data, uint8_t ip_version); |
64 | | |
65 | | enum alpnid { |
66 | | ALPN_none = 0, |
67 | | ALPN_h1 = CURLALTSVC_H1, |
68 | | ALPN_h2 = CURLALTSVC_H2, |
69 | | ALPN_h3 = CURLALTSVC_H3 |
70 | | }; |
71 | | |
72 | | bool Curl_host_is_ipnum(const char *hostname); |
73 | | |
74 | | #ifdef USE_IPV6 |
75 | | /* probe if it seems to work */ |
76 | | CURLcode Curl_probeipv6(struct Curl_multi *multi); |
77 | | #else |
78 | | #define Curl_probeipv6(x) CURLE_OK |
79 | | #endif |
80 | | |
81 | | /* IPv4 thread-safe resolve function used for synch and asynch builds */ |
82 | | struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, uint16_t port); |
83 | | |
84 | | /* |
85 | | * Curl_printable_address() returns a printable version of the 1st address |
86 | | * given in the 'ai' argument. The result will be stored in the buf that is |
87 | | * bufsize bytes big. |
88 | | */ |
89 | | void Curl_printable_address(const struct Curl_addrinfo *ai, |
90 | | char *buf, size_t bufsize); |
91 | | |
92 | | /* Start DNS resolving for the given parameters. Returns |
93 | | * - CURLE_OK: `*pdns` is the resolved DNS entry (needs to be unlinked). |
94 | | * `*presolv_id` is 0. |
95 | | * - CURLE_AGAIN: resolve is asynchronous and not finished yet. |
96 | | * `presolv_id` is the identifier for querying results later. |
97 | | * - other: the operation failed, `*pdns` is NULL, `*presolv_id` is 0. |
98 | | */ |
99 | | CURLcode Curl_resolv(struct Curl_easy *data, |
100 | | struct Curl_peer *peer, |
101 | | uint8_t dns_queries, |
102 | | uint8_t transport, |
103 | | bool for_proxy, |
104 | | timediff_t timeout_ms, |
105 | | uint32_t *presolv_id, |
106 | | struct Curl_dns_entry **pdns); |
107 | | |
108 | | CURLcode Curl_resolv_blocking(struct Curl_easy *data, |
109 | | uint8_t dns_queries, |
110 | | const char *hostname, |
111 | | uint16_t port, |
112 | | uint8_t transport, |
113 | | struct Curl_dns_entry **pdns); |
114 | | |
115 | | /* Announce start of a resolve operation to application callback, |
116 | | * passing the resolver implementation (maybe NULL). */ |
117 | | CURLcode Curl_resolv_announce_start(struct Curl_easy *data, |
118 | | void *resolver); |
119 | | |
120 | | #ifdef USE_CURL_ASYNC |
121 | | |
122 | | CURLcode Curl_resolv_pollset(struct Curl_easy *data, |
123 | | struct easy_pollset *ps); |
124 | | |
125 | | /* Get the `async` struct for the given `resolv_id`, if it exists. */ |
126 | | struct Curl_resolv_async *Curl_async_get(struct Curl_easy *data, |
127 | | uint32_t resolv_id); |
128 | | |
129 | | /* Shut down all resolves of the given easy handle. */ |
130 | | void Curl_resolv_shutdown_all(struct Curl_easy *data); |
131 | | |
132 | | /* Destroy all resolve resources of the given easy handle. */ |
133 | | void Curl_resolv_destroy_all(struct Curl_easy *data); |
134 | | |
135 | | CURLcode Curl_resolv_take_result(struct Curl_easy *data, uint32_t resolv_id, |
136 | | struct Curl_dns_entry **pdns); |
137 | | |
138 | | void Curl_resolv_destroy(struct Curl_easy *data, uint32_t resolv_id); |
139 | | |
140 | | /* How much time has gone by since start of resolve. |
141 | | * Returns CURL_TIMEOUT_RESOLVE_MS if `resolv_id` is no longer valid. */ |
142 | | timediff_t Curl_resolv_elapsed_ms(struct Curl_easy *data, |
143 | | uint32_t resolv_id); |
144 | | |
145 | | /* Return TRUE if `resolv_id` has answers (positive or negative) to |
146 | | * all queries in `dns_queries`. |
147 | | * Queries not requested are considered answered. */ |
148 | | bool Curl_resolv_has_answers(struct Curl_easy *data, |
149 | | uint32_t resolv_id, uint8_t dns_queries); |
150 | | |
151 | | const struct Curl_addrinfo *Curl_resolv_get_ai(struct Curl_easy *data, |
152 | | uint32_t resolv_id, |
153 | | int ai_family, |
154 | | unsigned int index); |
155 | | #ifdef USE_HTTPSRR |
156 | | const struct Curl_https_rrinfo *Curl_resolv_get_https(struct Curl_easy *data, |
157 | | uint32_t resolv_id); |
158 | | bool Curl_resolv_knows_https(struct Curl_easy *data, uint32_t resolv_id); |
159 | | #endif /* USE_HTTPSRR */ |
160 | | |
161 | | #else /* !USE_CURL_ASYNC */ |
162 | | #define Curl_resolv_shutdown_all(x) Curl_nop_stmt |
163 | | #define Curl_resolv_destroy_all(x) Curl_nop_stmt |
164 | | #define Curl_resolv_take_result(x, y, z) CURLE_NOT_BUILT_IN |
165 | | #define Curl_resolv_elapsed_ms(x, y) CURL_TIMEOUT_RESOLVE_MS |
166 | | #define Curl_resolv_has_answers(x, y, z) TRUE |
167 | | #define Curl_resolv_get_ai(x, y, z, a) NULL |
168 | | #define Curl_resolv_get_https(x, y) NULL |
169 | | #define Curl_resolv_knows_https(x, y) TRUE |
170 | | #define Curl_resolv_pollset(x, y) CURLE_OK |
171 | | #define Curl_resolv_destroy(x, y) Curl_nop_stmt |
172 | | #endif /* USE_CURL_ASYNC */ |
173 | | |
174 | | #ifdef CURLRES_SYNCH |
175 | | /* |
176 | | * Curl_sync_getaddrinfo() is the non-async low-level name resolve API. |
177 | | * There are several versions of this function - depending on IPV6 |
178 | | * support and platform. |
179 | | */ |
180 | | struct Curl_addrinfo *Curl_sync_getaddrinfo(struct Curl_easy *data, |
181 | | uint8_t dns_queries, |
182 | | const char *hostname, |
183 | | uint16_t port, |
184 | | uint8_t transport); |
185 | | #endif |
186 | | |
187 | | #endif /* HEADER_CURL_HOSTIP_H */ |