master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26#ifdef USE_RESOLV_ARES
28/***********************************************************************
29 * Only for ares-enabled builds and only for functions that fulfill
30 * the asynch resolver backend API as defined in asyn.h,
31 * nothing else belongs in this file!
32 **********************************************************************/
34#ifdef HAVE_NETINET_IN_H
35#include <netinet/in.h>
36#endif
37#ifdef HAVE_NETDB_H
38#include <netdb.h>
39#endif
40#ifdef HAVE_ARPA_INET_H
41#include <arpa/inet.h>
42#endif
43#ifdef __VMS
44#include <in.h>
45#include <inet.h>
46#endif
48#include "urldata.h"
49#include "cfilters.h"
50#include "curl_addrinfo.h"
51#include "curl_trc.h"
52#include "url.h"
53#include "multiif.h"
54#include "curlx/inet_pton.h"
55#include "connect.h"
56#include "select.h"
57#include "progress.h"
58#include "curlx/timediff.h"
59#include "vdns/hostip.h"
60#include "vdns/httpsrr.h"
61#include <ares.h>
63#if ARES_VERSION < 0x011000
64#error "c-ares 1.16.0 or greater required"
65#endif
67#ifdef USE_HTTPSRR
68#if ARES_VERSION < 0x011c00
69#error "c-ares 1.28.0 or greater required for HTTPSRR"
70#endif
71#define HTTPSRR_WORKS
72#endif
74#define CARES_TIMEOUT_PER_ATTEMPT 2000
76static int ares_ver = 0;
78static CURLcode async_ares_set_dns_servers(struct Curl_easy *data,
79 struct Curl_resolv_async *async);
80static CURLcode async_ares_set_dns_interface(struct Curl_easy *data,
81 struct Curl_resolv_async *async);
82static CURLcode async_ares_set_dns_local_ip4(struct Curl_easy *data,
83 struct Curl_resolv_async *async);
84static CURLcode async_ares_set_dns_local_ip6(struct Curl_easy *data,
85 struct Curl_resolv_async *async);
87/*
88 * Curl_async_global_init() - the generic low-level asynchronous name
89 * resolve API. Called from curl_global_init() to initialize global resolver
90 * environment. Initializes ares library.
91 */
92int Curl_async_global_init(void)
93{
94#ifdef CARES_HAVE_ARES_LIBRARY_INIT
95 if(ares_library_init(ARES_LIB_INIT_ALL)) {
96 return CURLE_FAILED_INIT;
97 }
98#endif
99 ares_version(&ares_ver);
100 return CURLE_OK;
101}
103/*
104 * Curl_async_global_cleanup()
105 *
106 * Called from curl_global_cleanup() to destroy global resolver environment.
107 * Deinitializes ares library.
108 */
109void Curl_async_global_cleanup(void)
110{
111#ifdef CARES_HAVE_ARES_LIBRARY_CLEANUP
112 ares_library_cleanup();
113#endif
114}
116static void sock_state_cb(void *data, ares_socket_t socket_fd,
117 int readable, int writable)
118{
119 struct Curl_easy *easy = data;
120 if(!readable && !writable) {
121 DEBUGASSERT(easy);
122 Curl_multi_will_close(easy, socket_fd);
123 }
124}
126static CURLcode async_ares_init(struct Curl_easy *data,
127 struct Curl_resolv_async *async)
128{
129 struct async_ares_ctx *ares = &async->ares;
130 int status;
131 struct ares_options options;
132 int optmask = ARES_OPT_SOCK_STATE_CB;
133 CURLcode result = CURLE_OK;
135 /* initial status - failed */
136 ares->ares_status = ARES_ENOTFOUND;
137 async->queries_ongoing = 0;
139 options.sock_state_cb = sock_state_cb;
140 options.sock_state_cb_data = data;
142 DEBUGASSERT(!ares->channel);
143 /*
144 if c ares < 1.20.0: curl set timeout to CARES_TIMEOUT_PER_ATTEMPT (2s)
146 if c-ares >= 1.20.0 it already has the timeout to 2s, curl does not need
147 to set the timeout value;
149 if c-ares >= 1.24.0, user can set the timeout via /etc/resolv.conf to
150 overwrite c-ares' timeout.
151 */
152 DEBUGASSERT(ares_ver);
153 if(ares_ver < 0x011400) {
154 options.timeout = CARES_TIMEOUT_PER_ATTEMPT;
155 optmask |= ARES_OPT_TIMEOUTMS;
156 }
158 status = ares_init_options(&ares->channel, &options, optmask);
159 if(status != ARES_SUCCESS) {
160 ares->channel = NULL;
161 result = (status == ARES_ENOMEM) ? CURLE_OUT_OF_MEMORY : CURLE_FAILED_INIT;
162 goto out;
163 }
165 result = async_ares_set_dns_servers(data, async);
166 if(result && result != CURLE_NOT_BUILT_IN)
167 goto out;
169 result = async_ares_set_dns_interface(data, async);
170 if(result && result != CURLE_NOT_BUILT_IN)
171 goto out;
173 result = async_ares_set_dns_local_ip4(data, async);
174 if(result && result != CURLE_NOT_BUILT_IN)
175 goto out;
177 result = async_ares_set_dns_local_ip6(data, async);
178 if(result && result != CURLE_NOT_BUILT_IN)
179 goto out;
181 result = CURLE_OK;
183out:
184 if(result && ares->channel) {
185 ares_destroy(ares->channel);
186 ares->channel = NULL;
187 }
188 return result;
189}
191void Curl_async_ares_shutdown(struct Curl_easy *data,
192 struct Curl_resolv_async *async)
193{
194 /* c-ares has a method to "cancel" operations on a channel, but
195 * as reported in #18216, this does not totally reset the channel
196 * and ares may get stuck.
197 * We need to destroy the channel and on demand create a new
198 * one to avoid that. */
199 Curl_async_ares_destroy(data, async);
200}
202void Curl_async_ares_destroy(struct Curl_easy *data,
203 struct Curl_resolv_async *async)
204{
205 struct async_ares_ctx *ares = &async->ares;
206 (void)data;
207 if(ares->channel) {
208 ares_destroy(ares->channel);
209 ares->channel = NULL;
210 }
211}
213CURLcode Curl_async_pollset(struct Curl_easy *data,
214 struct Curl_resolv_async *async,
215 struct easy_pollset *ps)
216{
217 struct async_ares_ctx *ares = &async->ares;
218 CURLcode result = CURLE_OK;
220 if(ares->channel) {
221 result = Curl_ares_pollset(data, ares->channel, ps);
222 if(!result) {
223 timediff_t ms = Curl_ares_timeout_ms(data, async, ares->channel);
224 Curl_expire(data, ms, EXPIRE_ASYNC_NAME);
225 }
226 }
227 return result;
228}
230/*
231 * Curl_async_take_result() is called repeatedly to check if a previous
232 * name resolve request has completed. It should also make sure to time-out if
233 * the operation seems to take too long.
234 *
235 * Returns normal CURLcode errors.
236 */
237CURLcode Curl_async_take_result(struct Curl_easy *data,
238 struct Curl_resolv_async *async,
239 struct Curl_dns_entry **pdns)
240{
241 struct async_ares_ctx *ares = &async->ares;
242 struct Curl_dns_entry *dns = NULL;
243 CURLcode result = CURLE_OK;
245 DEBUGASSERT(pdns);
246 *pdns = NULL;
247 if(!ares)
248 return CURLE_FAILED_INIT;
250 if(Curl_ares_perform(ares->channel, 0) < 0) {
251 result = CURLE_UNRECOVERABLE_POLL;
252 goto out;
253 }
255 if(async->queries_ongoing) {
256 result = CURLE_AGAIN;
257 goto out;
258 }
260 /* all c-ares operations done, what is the result to report? */
261 result = ares->result;
262 if(ares->ares_status == ARES_SUCCESS && !result) {
264 if(CURL_DNSQ_IS_ADDR(async->dns_queries)) {
265 dns = Curl_dnsc_mk_addr2(data, async->dns_queries,
266 &async->ai_AAAA, &async->ai_A,
267 async->peer);
268 if(!dns) {
269 result = CURLE_OUT_OF_MEMORY;
270 goto out;
271 }
272 }
274#ifdef HTTPSRR_WORKS
275 if(!dns && (async->dns_queries & CURL_DNSQ_HTTPS)) {
276 dns = Curl_dnsc_mk_https(data, &async->httpsrr, async->peer);
277 if(!dns) {
278 result = CURLE_OUT_OF_MEMORY;
279 goto out;
280 }
281 }
282#endif
283 }
284 /* if we have not found anything, report the proper
285 * CURLE_COULDNT_RESOLVE_* code */
286 if(!result && !dns) {
287 const char *msg = NULL;
288 /* only an authoritative "does not exist" answer from every query
289 may be cached as a negative entry, not transient failures like
290 timeouts or server troubles */
291 async->negative_answer = !ares->transient_err &&
292 ((ares->ares_status == ARES_ENOTFOUND) ||
293 (ares->ares_status == ARES_ENODATA));
294 if(ares->ares_status != ARES_SUCCESS)
295 msg = ares_strerror(ares->ares_status);
296 result = Curl_async_failed(data, async, msg);
297 }
299 CURL_TRC_DNS(data, "[%s] ares_take_result, result=%d, ares_result=%d, "
300 "ares_status=%d, dns=%sfound",
301 Curl_resolv_query_str(async->dns_queries),
302 (int)result, (int)ares->result, ares->ares_status,
303 dns ? "" : "not ");
305out:
306 if(result != CURLE_AGAIN)
307 ares->result = result;
308 *pdns = result ? NULL : dns;
309 return result;
310}
312static timediff_t async_ares_poll_timeout(struct async_ares_ctx *ares,
313 timediff_t timeout_ms)
314{
315 struct timeval *ares_calced, time_buf, max_timeout;
316 int itimeout_ms;
318#if TIMEDIFF_T_MAX > INT_MAX
319 itimeout_ms = (timeout_ms > INT_MAX) ? INT_MAX :
320 ((timeout_ms < 0) ? -1 : (int)timeout_ms);
321#else
322 itimeout_ms = (int)timeout_ms;
323#endif
324 max_timeout.tv_sec = itimeout_ms / 1000;
325 max_timeout.tv_usec = (itimeout_ms % 1000) * 1000;
327 /* c-ares tells us the shortest timeout of any operation on channel */
328 ares_calced = ares_timeout(ares->channel, &max_timeout, &time_buf);
329 /* use the timeout period ares returned to us above if less than one
330 second is left, otherwise use 1000ms to make sure the progress callback
331 gets called frequent enough */
332 if(!ares_calced->tv_sec)
333 return (timediff_t)(ares_calced->tv_usec / 1000);
334 else
335 return 1000;
336}
338/*
339 * Curl_async_await()
340 *
341 * Waits for a resolve to finish. This function should be avoided since using
342 * this risk getting the multi interface to "hang".
343 *
344 * 'pdns' MUST be non-NULL.
345 *
346 * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
347 * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
348 */
349CURLcode Curl_async_await(struct Curl_easy *data, uint32_t resolv_id,
350 struct Curl_dns_entry **pdns)
351{
352 struct Curl_resolv_async *async = Curl_async_get(data, resolv_id);
353 struct async_ares_ctx *ares = async ? &async->ares : NULL;
354 struct curltime start = *Curl_pgrs_now(data);
355 CURLcode result = CURLE_OK;
357 DEBUGASSERT(pdns);
358 *pdns = NULL; /* clear on entry */
360 if(!ares)
361 return CURLE_FAILED_INIT;
363 /* Wait for the name resolve query to complete or time out. */
364 while(!result) {
365 timediff_t timeout_ms;
367 timeout_ms = Curl_timeleft_ms(data);
368 if(!timeout_ms) { /* no applicable timeout from `data`*/
369 timediff_t elapsed_ms = curlx_ptimediff_ms(Curl_pgrs_now(data), &start);
370 if(elapsed_ms < CURL_TIMEOUT_RESOLVE_MS)
371 timeout_ms = CURL_TIMEOUT_RESOLVE_MS - elapsed_ms;
372 else
373 timeout_ms = -1;
374 }
376 if(timeout_ms < 0) {
377 result = CURLE_OPERATION_TIMEDOUT;
378 break;
379 }
381 if(Curl_ares_perform(ares->channel,
382 async_ares_poll_timeout(ares, timeout_ms)) < 0) {
383 result = CURLE_UNRECOVERABLE_POLL;
384 break;
385 }
387 result = Curl_async_take_result(data, async, pdns);
388 if(result == CURLE_AGAIN)
389 result = CURLE_OK;
390 else if(result || *pdns)
391 break;
393 if(Curl_pgrsUpdate(data)) {
394 result = CURLE_ABORTED_BY_CALLBACK;
395 break;
396 }
397 }
399 if(result)
400 ares_cancel(ares->channel);
401 return result;
402}
404#define CARES_MAX_ADDRS 256
406static bool async_ares_addr_seen(const struct Curl_addrinfo *cafirst,
407 int family, size_t ss_size,
408 const void *addr)
409{
410 const struct Curl_addrinfo *ca;
411 for(ca = cafirst; ca; ca = ca->ai_next) {
412 if((ca->ai_family == family) &&
413 ((size_t)ca->ai_addrlen == ss_size) &&
414 !memcmp(ca->ai_addr, addr, ss_size))
415 return TRUE;
416 }
417 return FALSE;
418}
420/*
421 * async_ares_node2addr() converts an address list provided by c-ares
422 * to an internal libcurl compatible list.
423 */
424static struct Curl_addrinfo *async_ares_node2addr(
425 struct ares_addrinfo_node *node)
426{
427 /* traverse the ares_addrinfo_node list */
428 struct ares_addrinfo_node *ai;
429 struct Curl_addrinfo *cafirst = NULL;
430 struct Curl_addrinfo *calast = NULL;
431 int error = 0;
432 unsigned int naddrs = 0;
434 for(ai = node; ai && (naddrs < CARES_MAX_ADDRS); ai = ai->ai_next) {
435 size_t ss_size;
436 struct Curl_addrinfo *ca;
437 /* ignore elements with unsupported address family,
438 settle family-specific sockaddr structure size. */
439 if(ai->ai_family == AF_INET)
440 ss_size = sizeof(struct sockaddr_in);
441#ifdef USE_IPV6
442 else if(ai->ai_family == AF_INET6)
443 ss_size = sizeof(struct sockaddr_in6);
444#endif
445 else
446 continue;
448 /* ignore elements without required address info */
449 if(!ai->ai_addr || !(ai->ai_addrlen > 0))
450 continue;
452 /* ignore elements with bogus address size */
453 if((size_t)ai->ai_addrlen < ss_size)
454 continue;
456 /* ignore duplicate addresses already collected */
457 if(async_ares_addr_seen(cafirst, ai->ai_family, ss_size, ai->ai_addr))
458 continue;
460 ca = curlx_malloc(sizeof(struct Curl_addrinfo) + ss_size);
461 if(!ca) {
462 error = EAI_MEMORY;
463 break;
464 }
466 /* copy each structure member individually, member ordering,
467 size, or padding might be different for each platform. */
469 ca->ai_flags = ai->ai_flags;
470 ca->ai_family = ai->ai_family;
471 ca->ai_socktype = ai->ai_socktype;
472 ca->ai_protocol = ai->ai_protocol;
473 ca->ai_addrlen = (curl_socklen_t)ss_size;
474 ca->ai_addr = NULL;
475 ca->ai_canonname = NULL;
476 ca->ai_next = NULL;
478 ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo));
479 memcpy(ca->ai_addr, ai->ai_addr, ss_size);
481 /* if the return list is empty, this becomes the first element */
482 if(!cafirst)
483 cafirst = ca;
485 /* add this element last in the return list */
486 if(calast)
487 calast->ai_next = ca;
488 calast = ca;
489 ++naddrs;
490 }
492 /* if we failed, destroy the Curl_addrinfo list */
493 if(error) {
494 Curl_freeaddrinfo(cafirst);
495 cafirst = NULL;
496 }
498 return cafirst;
499}
501static void async_ares_A_cb(void *user_data, int status, int timeouts,
502 struct ares_addrinfo *ares_ai)
503{
504 struct Curl_resolv_async *async = user_data;
505 struct async_ares_ctx *ares = async ? &async->ares : NULL;
507 (void)timeouts;
508 if(!async)
509 return;
511 async->dns_responses |= CURL_DNSQ_A;
512 async->queries_ongoing--;
513 async->done = !async->queries_ongoing;
514 if(status == ARES_SUCCESS) {
515 ares->ares_status = ARES_SUCCESS;
516 async->ai_A = async_ares_node2addr(ares_ai->nodes);
517 ares_freeaddrinfo(ares_ai);
518 }
519 else {
520 if((status != ARES_ENOTFOUND) && (status != ARES_ENODATA))
521 ares->transient_err = TRUE;
522 if(ares->ares_status != ARES_SUCCESS) /* do not overwrite success */
523 ares->ares_status = status;
524 }
525}
527#ifdef CURLRES_IPV6
528static void async_ares_AAAA_cb(void *user_data, int status, int timeouts,
529 struct ares_addrinfo *ares_ai)
530{
531 struct Curl_resolv_async *async = user_data;
532 struct async_ares_ctx *ares = async ? &async->ares : NULL;
534 (void)timeouts;
535 if(!async)
536 return;
538 async->dns_responses |= CURL_DNSQ_AAAA;
539 async->queries_ongoing--;
540 async->done = !async->queries_ongoing;
541 if(status == ARES_SUCCESS) {
542 ares->ares_status = ARES_SUCCESS;
543 async->ai_AAAA = async_ares_node2addr(ares_ai->nodes);
544 ares_freeaddrinfo(ares_ai);
545 }
546 else {
547 if((status != ARES_ENOTFOUND) && (status != ARES_ENODATA))
548 ares->transient_err = TRUE;
549 if(ares->ares_status != ARES_SUCCESS) /* do not overwrite success */
550 ares->ares_status = status;
551 }
552}
553#endif /* CURLRES_IPV6 */
555#ifdef USE_HTTPSRR
556static void async_ares_rr_done(void *user_data, ares_status_t status,
557 size_t timeouts,
558 const ares_dns_record_t *dnsrec)
559{
560 struct Curl_resolv_async *async = user_data;
561 struct async_ares_ctx *ares = async ? &async->ares : NULL;
563 if(!async)
564 return;
566 (void)timeouts;
567 async->dns_responses |= CURL_DNSQ_HTTPS;
568 async->queries_ongoing--;
569 async->done = !async->queries_ongoing;
570 ares->ares_status = status;
571 if((status != ARES_ENOTFOUND) && (status != ARES_ENODATA))
572 ares->transient_err = TRUE;
573 if((ARES_SUCCESS != status) || !dnsrec)
574 return;
575 ares->result = Curl_httpsrr_from_ares(dnsrec, &async->httpsrr);
576}
577#endif /* USE_HTTPSRR */
579/*
580 * Curl_async_getaddrinfo() - when using ares
581 *
582 * Starts a name resolve for the given hostname and port number.
583 */
584CURLcode Curl_async_getaddrinfo(struct Curl_easy *data,
585 struct Curl_resolv_async *async)
586{
587 struct async_ares_ctx *ares = &async->ares;
588 char service[12];
589 int socktype;
590 CURLcode result = CURLE_OK;
592 if(ares->channel) {
593 DEBUGASSERT(0);
594 result = CURLE_FAILED_INIT;
595 goto out;
596 }
598 result = async_ares_init(data, async);
599 if(result)
600 goto out;
602 result = Curl_resolv_announce_start(data, ares->channel);
603 if(result)
604 goto out;
606#if defined(CURLVERBOSE) && ARES_VERSION >= 0x011800 /* >= v1.24.0 */
607 if(CURL_TRC_DNS_is_verbose(data)) {
608 char *csv = ares_get_servers_csv(ares->channel);
609 CURL_TRC_DNS(data, "ares: servers=%s", csv);
610 ares_free_string(csv);
611 }
612#endif
614 curl_msnprintf(service, sizeof(service), "%d", async->peer->port);
615 socktype =
616 (Curl_conn_get_transport(data, data->conn) == TRNSPRT_TCP) ?
617 SOCK_STREAM : SOCK_DGRAM;
619#ifdef CURLRES_IPV6
620 if(async->dns_queries & CURL_DNSQ_AAAA) {
621 struct ares_addrinfo_hints hints;
623 memset(&hints, 0, sizeof(hints));
624 CURL_TRC_DNS(data, "[AAAA] ares: query records for %s",
625 async->peer->hostname);
626 hints.ai_family = PF_INET6;
627 hints.ai_socktype = socktype;
628 hints.ai_flags = ARES_AI_NUMERICSERV;
629 async->queries_ongoing++;
630 ares_getaddrinfo(ares->channel, async->peer->hostname,
631 service, &hints, async_ares_AAAA_cb, async);
632 }
633#endif /* CURLRES_IPV6 */
635 if(async->dns_queries & CURL_DNSQ_A) {
636 struct ares_addrinfo_hints hints;
638 memset(&hints, 0, sizeof(hints));
639 CURL_TRC_DNS(data, "[A] ares: query records for %s",
640 async->peer->hostname);
641 hints.ai_family = PF_INET;
642 hints.ai_socktype = socktype;
643 hints.ai_flags = ARES_AI_NUMERICSERV;
644 async->queries_ongoing++;
645 ares_getaddrinfo(ares->channel, async->peer->hostname,
646 service, &hints, async_ares_A_cb, async);
647 }
649#ifdef USE_HTTPSRR
650 if(async->dns_queries & CURL_DNSQ_HTTPS) {
651 char *https_name = NULL;
652 if(async->peer->port != 443) {
653 https_name = curl_maprintf("_%u._https.%s",
654 async->peer->port, async->peer->hostname);
655 if(!https_name)
656 return CURLE_OUT_OF_MEMORY;
657 }
658 CURL_TRC_DNS(data, "[HTTPS] ares: query records for %s",
659 https_name ? https_name : async->peer->hostname);
660 async->queries_ongoing++;
661 ares_query_dnsrec(ares->channel,
662 https_name ? https_name : async->peer->hostname,
663 ARES_CLASS_IN, ARES_REC_TYPE_HTTPS,
664 async_ares_rr_done, async, NULL);
665 curlx_free(https_name);
666 }
667#endif /* USE_HTTPSRR */
669out:
670 ares->result = result;
671 return result ? result : (async->queries_ongoing ? CURLE_AGAIN : CURLE_OK);
672}
674/* Set what DNS server are is to use. This is called in 2 situations:
675 * 1. when the application does 'CURLOPT_DNS_SERVERS' and passing NULL
676 * means any previous set value should be unset. Which means
677 * we need to destroy and create the are channel anew, if there is one.
678 * 2. When we lazy init the ares channel and NULL means that there
679 * are no preferences and we do not reset any existing channel. */
680static CURLcode async_ares_set_dns_servers(struct Curl_easy *data,
681 struct Curl_resolv_async *async)
682{
683 struct async_ares_ctx *ares = async ? &async->ares : NULL;
684 CURLcode result = CURLE_NOT_BUILT_IN;
685 const char *servers = CURL_EASY_STR(data, STRING_DNS_SERVERS);
686 int ares_result = ARES_SUCCESS;
688#ifdef DEBUGBUILD
689 if(getenv("CURL_DNS_SERVER"))
690 servers = getenv("CURL_DNS_SERVER");
691#endif
693 if(!servers)
694 return CURLE_OK;
696 /* if channel is not there, this is a parameter check */
697 if(ares && ares->channel)
698 ares_result = ares_set_servers_ports_csv(ares->channel, servers);
699 switch(ares_result) {
700 case ARES_SUCCESS:
701 result = CURLE_OK;
702 break;
703 case ARES_ENOMEM:
704 result = CURLE_OUT_OF_MEMORY;
705 break;
706 case ARES_ENOTINITIALIZED:
707 case ARES_ENODATA:
708 case ARES_EBADSTR:
709 default:
710 DEBUGF(infof(data, "bad servers set"));
711 result = CURLE_BAD_FUNCTION_ARGUMENT;
712 break;
713 }
714 return result;
715}
717static CURLcode async_ares_set_dns_interface(struct Curl_easy *data,
718 struct Curl_resolv_async *async)
719{
720 struct async_ares_ctx *ares = async ? &async->ares : NULL;
721 const char *interf = CURL_EASY_STR(data, STRING_DNS_INTERFACE);
723 if(!interf)
724 interf = "";
726 /* if channel is not there, this is a parameter check */
727 if(ares && ares->channel)
728 ares_set_local_dev(ares->channel, interf);
730 return CURLE_OK;
731}
733static CURLcode async_ares_set_dns_local_ip4(struct Curl_easy *data,
734 struct Curl_resolv_async *async)
735{
736 struct async_ares_ctx *ares = async ? &async->ares : NULL;
737 struct in_addr a4;
738 const char *local_ip4 = CURL_EASY_STR(data, STRING_DNS_LOCAL_IP4);
740 if(!local_ip4 || (local_ip4[0] == 0)) {
741 a4.s_addr = 0; /* disabled: do not bind to a specific address */
742 }
743 else {
744 if(curlx_inet_pton(AF_INET, local_ip4, &a4) != 1) {
745 DEBUGF(infof(data, "bad DNS IPv4 address"));
746 return CURLE_BAD_FUNCTION_ARGUMENT;
747 }
748 }
750 /* if channel is not there yet, this is a parameter check */
751 if(ares && ares->channel)
752 ares_set_local_ip4(ares->channel, ntohl(a4.s_addr));
754 return CURLE_OK;
755}
757static CURLcode async_ares_set_dns_local_ip6(struct Curl_easy *data,
758 struct Curl_resolv_async *async)
759{
760#ifdef USE_IPV6
761 struct async_ares_ctx *ares = async ? &async->ares : NULL;
762 unsigned char a6[INET6_ADDRSTRLEN];
763 const char *local_ip6 = CURL_EASY_STR(data, STRING_DNS_LOCAL_IP6);
765 if(!local_ip6 || (local_ip6[0] == 0)) {
766 /* disabled: do not bind to a specific address */
767 memset(a6, 0, sizeof(a6));
768 }
769 else {
770 if(curlx_inet_pton(AF_INET6, local_ip6, a6) != 1) {
771 DEBUGF(infof(data, "bad DNS IPv6 address"));
772 return CURLE_BAD_FUNCTION_ARGUMENT;
773 }
774 }
776 /* if channel is not there, this is a parameter check */
777 if(ares && ares->channel)
778 ares_set_local_ip6(ares->channel, a6);
780 return CURLE_OK;
781#else /* no IPv6 support */
782 (void)data;
783 (void)async;
784 return CURLE_NOT_BUILT_IN;
785#endif
786}
788#endif /* USE_RESOLV_ARES */
Diagnostics4 git calls · 345 ms
CallStatusSizeTime0345 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=5 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=5 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2006.9 KiB337 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=337 git.response.bytes=7084 git.response.cache=MISS git.response.duration_ms=337 git.fetch.wants=e74e3523c7fbde46b10435cd99ad167a5828d75a git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=7084 git.pkt.payload.max=7063 git.sideband.band1.bytes=7062 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e9effe9e9c0acb
- Request
- c5378ecc…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format