Artifactspublic-v0

curl

master
ply4 git calls307 ms299 KiB2 cachedprotocol v2
1291 lines38 KiBRaw
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#ifndef CURL_DISABLE_DOH
28#include "urldata.h"
29#include "curl_addrinfo.h"
30#include "curl_trc.h"
31#include "multiif.h"
32#include "url.h"
33#include "connect.h"
34#include "vdns/doh.h"
35#include "vdns/httpsrr.h"
36#include "curlx/strdup.h"
37#include "curlx/dynbuf.h"
38#include "escape.h" /* for Curl_hexencode() */
39#include "urlapi-int.h"
41#define DNS_CLASS_IN 0x01
43static void doh_close(struct Curl_easy *data,
44 struct Curl_resolv_async *async);
46#ifdef CURLVERBOSE
47static const char * const doh_code_str[] = {
48 "",
49 "Bad label",
50 "Out of range",
51 "Label loop",
52 "Too small",
53 "Out of memory",
54 "RDATA length",
55 "Malformat",
56 "Bad RCODE",
57 "Unexpected TYPE",
58 "Unexpected CLASS",
59 "No content",
60 "Bad ID",
61 "Name too long",
62 "No such name",
63 "Transport failed",
64 "Out Of Memory"
65};
67static const char *doh_strerror(DOHcode code)
69 if((size_t)code < CURL_ARRAYSIZE(doh_code_str))
70 return doh_code_str[code];
71 return "bad error code";
74static const char *doh_type2name(DNStype dnstype)
76 switch(dnstype) {
77 case CURL_DNS_TYPE_A:
78 return "A";
79 case CURL_DNS_TYPE_AAAA:
80 return "AAAA";
81#ifdef USE_HTTPSRR
82 case CURL_DNS_TYPE_HTTPS:
83 return "HTTPS";
84#endif
85 default:
86 return "unknown";
87 }
90#endif /* CURLVERBOSE */
92/* @unittest 1655
93 */
94UNITTEST DOHcode doh_req_encode(const char *host,
95 DNStype dnstype,
96 unsigned char *dnsp, /* buffer */
97 size_t len, /* buffer size */
98 size_t *olen); /* output length */
99UNITTEST DOHcode doh_req_encode(const char *host,
100 DNStype dnstype,
101 unsigned char *dnsp, /* buffer */
102 size_t len, /* buffer size */
103 size_t *olen) /* output length */
105 const size_t hostlen = strlen(host);
106 unsigned char *orig = dnsp;
107 const char *hostp = host;
109 /* The expected output length is 16 bytes more than the length of
110 * the QNAME-encoding of the hostname.
111 *
112 * A valid DNS name may not contain a zero-length label, except at
113 * the end. For this reason, a name beginning with a dot, or
114 * containing a sequence of two or more consecutive dots, is invalid
115 * and cannot be encoded as a QNAME.
116 *
117 * If the hostname ends with a trailing dot, the corresponding
118 * QNAME-encoding is one byte longer than the hostname. If (as is
119 * also valid) the hostname is shortened by the omission of the
120 * trailing dot, then its QNAME-encoding will be two bytes longer
121 * than the hostname.
122 *
123 * Each [ label, dot ] pair is encoded as [ length, label ],
124 * preserving overall length. A final [ label ] without a dot is
125 * also encoded as [ length, label ], increasing overall length
126 * by one. The encoding is completed by appending a NUL byte,
127 * representing the zero-length root label, again increasing
128 * the overall length by one.
129 */
131 size_t expected_len;
132 DEBUGASSERT(hostlen);
133 expected_len = 12 + 1 + hostlen + 4;
134 if(host[hostlen - 1] != '.')
135 expected_len++;
137 if(expected_len > DOH_MAX_DNSREQ_SIZE)
138 return DOH_DNS_NAME_TOO_LONG;
140 if(len < expected_len)
141 return DOH_TOO_SMALL_BUFFER;
143 *dnsp++ = 0; /* 16-bit id */
144 *dnsp++ = 0;
145 *dnsp++ = 0x01; /* |QR| Opcode |AA|TC|RD| Set the RD bit */
146 *dnsp++ = '\0'; /* |RA| Z | RCODE | */
147 *dnsp++ = '\0';
148 *dnsp++ = 1; /* QDCOUNT (number of entries in the question section) */
149 *dnsp++ = '\0';
150 *dnsp++ = '\0'; /* ANCOUNT */
151 *dnsp++ = '\0';
152 *dnsp++ = '\0'; /* NSCOUNT */
153 *dnsp++ = '\0';
154 *dnsp++ = '\0'; /* ARCOUNT */
156 /* encode each label and store it in the QNAME */
157 while(*hostp) {
158 size_t labellen;
159 const char *dot = strchr(hostp, '.');
160 if(dot)
161 labellen = dot - hostp;
162 else
163 labellen = strlen(hostp);
164 if((labellen > 63) || (!labellen)) {
165 /* label is too long or too short, error out */
166 *olen = 0;
167 return DOH_DNS_BAD_LABEL;
168 }
169 /* label is non-empty, process it */
170 *dnsp++ = (unsigned char)labellen;
171 memcpy(dnsp, hostp, labellen);
172 dnsp += labellen;
173 hostp += labellen;
174 /* advance past dot, but only if there is one */
175 if(dot)
176 hostp++;
177 } /* next label */
179 *dnsp++ = 0; /* append zero-length label for root */
181 /* There are assigned TYPE codes beyond 255: use range [1..65535] */
182 *dnsp++ = (unsigned char)(255 & (dnstype >> 8)); /* upper 8-bit TYPE */
183 *dnsp++ = (unsigned char)(255 & dnstype); /* lower 8-bit TYPE */
185 *dnsp++ = '\0'; /* upper 8-bit CLASS */
186 *dnsp++ = DNS_CLASS_IN; /* IN - "the Internet" */
188 *olen = dnsp - orig;
190 /* verify that our estimation of length is valid, since
191 * this has led to buffer overflows in this function */
192 DEBUGASSERT(*olen == expected_len);
193 return DOH_OK;
196static size_t doh_probe_write_cb(char *contents, size_t size, size_t nmemb,
197 void *userp)
199 size_t realsize = size * nmemb;
200 struct Curl_easy *data = userp;
201 struct doh_request *doh_req = Curl_meta_get(data, CURL_EZM_DOH_PROBE);
202 if(!doh_req)
203 return CURL_WRITEFUNC_ERROR;
205 if(curlx_dyn_addn(&doh_req->resp_body, contents, realsize))
206 return 0;
208 return realsize;
211static void doh_probe_done(struct Curl_easy *doh,
212 struct Curl_easy *master, CURLcode result);
213static void doh_probe_dtor(const void *key, size_t klen, void *e)
215 (void)key;
216 (void)klen;
217 if(e) {
218 struct doh_request *doh_req = e;
219 curl_slist_free_all(doh_req->req_hds);
220 curlx_dyn_free(&doh_req->resp_body);
221 curlx_free(e);
222 }
225#define ERROR_CHECK_SETOPT(x, y) \
226 do { \
227 result = curl_easy_setopt((CURL *)doh, x, y); \
228 if(result && \
229 result != CURLE_NOT_BUILT_IN && \
230 result != CURLE_UNKNOWN_OPTION) \
231 goto error; \
232 } while(0)
234static CURLcode doh_probe_run(struct Curl_easy *data,
235 DNStype dnstype,
236 const char *host,
237 const char *url, CURLM *multi,
238 uint32_t resolv_id,
239 uint32_t *pmid)
241 struct Curl_easy *doh = NULL;
242 CURLcode result = CURLE_OK;
243 timediff_t timeout_ms;
244 struct doh_request *doh_req;
245 DOHcode d;
246 bool maybe_https = !curl_strnequal(url, STRCONST("http:"));
248 *pmid = UINT32_MAX;
250 doh_req = curlx_calloc(1, sizeof(*doh_req));
251 if(!doh_req)
252 return CURLE_OUT_OF_MEMORY;
253 doh_req->resolv_id = resolv_id;
254 doh_req->dnstype = dnstype;
255 curlx_dyn_init(&doh_req->resp_body, DYN_DOH_RESPONSE);
257 d = doh_req_encode(host, dnstype, doh_req->req_body,
258 sizeof(doh_req->req_body),
259 &doh_req->req_body_len);
260 if(d) {
261 failf(data, "Failed to encode DoH packet [%d]", (int)d);
262 result = CURLE_OUT_OF_MEMORY;
263 goto error;
264 }
266 timeout_ms = Curl_timeleft_ms(data);
267 if(timeout_ms < 0) {
268 result = CURLE_OPERATION_TIMEDOUT;
269 goto error;
270 }
272 doh_req->req_hds =
273 curl_slist_append(NULL, "Content-Type: application/dns-message");
274 if(!doh_req->req_hds) {
275 result = CURLE_OUT_OF_MEMORY;
276 goto error;
277 }
279 /* Curl_open() is the internal version of curl_easy_init() */
280 result = Curl_open(&doh);
281 if(result)
282 goto error;
284 /* pass in the struct pointer via a local variable to please coverity and
285 the gcc typecheck helpers */
286 VERBOSE(doh->state.feat = &Curl_trc_feat_doh);
287 ERROR_CHECK_SETOPT(CURLOPT_URL, url);
288 ERROR_CHECK_SETOPT(CURLOPT_DEFAULT_PROTOCOL, "https");
289 ERROR_CHECK_SETOPT(CURLOPT_WRITEFUNCTION, doh_probe_write_cb);
290 ERROR_CHECK_SETOPT(CURLOPT_WRITEDATA, doh);
291 ERROR_CHECK_SETOPT(CURLOPT_POSTFIELDS, doh_req->req_body);
292 ERROR_CHECK_SETOPT(CURLOPT_POSTFIELDSIZE, (long)doh_req->req_body_len);
293 ERROR_CHECK_SETOPT(CURLOPT_HTTPHEADER, doh_req->req_hds);
294#ifdef USE_HTTP2
295 if(maybe_https) {
296 ERROR_CHECK_SETOPT(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
297 ERROR_CHECK_SETOPT(CURLOPT_PIPEWAIT, 1L);
298 }
299#endif
300#ifndef DEBUGBUILD
301 /* enforce HTTPS if not debug */
302 ERROR_CHECK_SETOPT(CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
303#else
304 /* in debug mode, also allow http */
305 ERROR_CHECK_SETOPT(CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
306#endif
307 ERROR_CHECK_SETOPT(CURLOPT_TIMEOUT_MS, (long)timeout_ms);
308 ERROR_CHECK_SETOPT(CURLOPT_SHARE, (CURLSH *)data->share);
309 if(data->set.err && data->set.err != stderr)
310 ERROR_CHECK_SETOPT(CURLOPT_STDERR, data->set.err);
311 if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_doh))
312 ERROR_CHECK_SETOPT(CURLOPT_VERBOSE, 1L);
313 if(data->set.no_signal)
314 ERROR_CHECK_SETOPT(CURLOPT_NOSIGNAL, 1L);
315 if(data->set.fdebug)
316 ERROR_CHECK_SETOPT(CURLOPT_DEBUGFUNCTION, data->set.fdebug);
317 if(data->set.debugdata)
318 ERROR_CHECK_SETOPT(CURLOPT_DEBUGDATA, data->set.debugdata);
320#ifdef USE_RESOLV_ARES
321 if(CURL_EASY_STR(data, STRING_DNS_SERVERS)) {
322 ERROR_CHECK_SETOPT(CURLOPT_DNS_SERVERS,
323 CURL_EASY_STR(data, STRING_DNS_SERVERS));
324 }
325 if(CURL_EASY_STR(data, STRING_DNS_INTERFACE)) {
326 ERROR_CHECK_SETOPT(CURLOPT_DNS_INTERFACE,
327 CURL_EASY_STR(data, STRING_DNS_INTERFACE));
328 }
329 if(CURL_EASY_STR(data, STRING_DNS_LOCAL_IP4)) {
330 ERROR_CHECK_SETOPT(CURLOPT_DNS_LOCAL_IP4,
331 CURL_EASY_STR(data, STRING_DNS_LOCAL_IP4));
332 }
333 if(CURL_EASY_STR(data, STRING_DNS_LOCAL_IP6)) {
334 ERROR_CHECK_SETOPT(CURLOPT_DNS_LOCAL_IP6,
335 CURL_EASY_STR(data, STRING_DNS_LOCAL_IP6));
336 }
337#endif
338 if(maybe_https) {
339 ERROR_CHECK_SETOPT(CURLOPT_SSL_VERIFYHOST,
340 data->set.doh_verifyhost ? 2L : 0L);
341 ERROR_CHECK_SETOPT(CURLOPT_SSL_VERIFYPEER,
342 data->set.doh_verifypeer ? 1L : 0L);
343 ERROR_CHECK_SETOPT(CURLOPT_SSL_VERIFYSTATUS,
344 data->set.doh_verifystatus ? 1L : 0L);
346 /* Inherit *some* SSL options from the user's transfer. This is a
347 best-guess as to which options are needed for compatibility. #3661
349 Note DoH does not inherit the user's proxy server so proxy SSL settings
350 have no effect and are not inherited. If that changes then two new
351 options should be added to check doh proxy insecure separately,
352 CURLOPT_DOH_PROXY_SSL_VERIFYHOST and CURLOPT_DOH_PROXY_SSL_VERIFYPEER.
353 */
354 doh->set.ssl.custom_cafile = data->set.ssl.custom_cafile;
355 doh->set.ssl.custom_capath = data->set.ssl.custom_capath;
356 doh->set.ssl.custom_cablob = data->set.ssl.custom_cablob;
357 if(CURL_EASY_STR(data, STRING_SSL_CAFILE)) {
358 ERROR_CHECK_SETOPT(CURLOPT_CAINFO,
359 CURL_EASY_STR(data, STRING_SSL_CAFILE));
360 }
361 if(data->set.blobs[BLOB_CAINFO]) {
362 ERROR_CHECK_SETOPT(CURLOPT_CAINFO_BLOB, data->set.blobs[BLOB_CAINFO]);
363 }
364 if(CURL_EASY_STR(data, STRING_SSL_CAPATH)) {
365 ERROR_CHECK_SETOPT(CURLOPT_CAPATH,
366 CURL_EASY_STR(data, STRING_SSL_CAPATH));
367 }
368 if(CURL_EASY_STR(data, STRING_SSL_CRLFILE)) {
369 ERROR_CHECK_SETOPT(CURLOPT_CRLFILE,
370 CURL_EASY_STR(data, STRING_SSL_CRLFILE));
371 }
372 if(data->set.ssl.certinfo)
373 ERROR_CHECK_SETOPT(CURLOPT_CERTINFO, 1L);
374 if(data->set.ssl_fsslctx)
375 ERROR_CHECK_SETOPT(CURLOPT_SSL_CTX_FUNCTION, data->set.ssl_fsslctx);
376 if(data->set.ssl_fsslctxp)
377 ERROR_CHECK_SETOPT(CURLOPT_SSL_CTX_DATA, data->set.ssl_fsslctxp);
378 if(CURL_EASY_STR(data, STRING_SSL_EC_CURVES)) {
379 ERROR_CHECK_SETOPT(CURLOPT_SSL_EC_CURVES,
380 CURL_EASY_STR(data, STRING_SSL_EC_CURVES));
381 }
382 (void)curl_easy_setopt(doh, CURLOPT_SSL_OPTIONS,
383 ((long)data->set.ssl.ssl_options &
384 ~CURLSSLOPT_AUTO_CLIENT_CERT));
385 }
387 doh->state.internal = TRUE;
388 doh->master_mid = data->mid; /* master transfer of this one */
389 doh->sub_xfer_done = doh_probe_done;
391 result = Curl_meta_set(doh, CURL_EZM_DOH_PROBE, doh_req, doh_probe_dtor);
392 doh_req = NULL; /* call took ownership */
393 if(result)
394 goto error;
396 /* DoH handles must not inherit private_data. The handles may be passed to
397 the user via callbacks and the user will be able to identify them as
398 internal handles because private data is not set. The user can then set
399 private_data via CURLOPT_PRIVATE if they so choose. */
400 DEBUGASSERT(!doh->set.private_data);
402 if(Curl_multi_add_handle(multi, doh))
403 goto error;
405 *pmid = doh->mid;
406 return CURLE_OK;
408error:
409 Curl_close(&doh);
410 if(doh_req)
411 doh_probe_dtor(NULL, 0, doh_req);
412 return result;
415/*
416 * Curl_doh() starts a name resolve using DoH. It resolves a name and returns
417 * a 'Curl_addrinfo *' with the address information.
418 */
420CURLcode Curl_doh(struct Curl_easy *data,
421 struct Curl_resolv_async *async)
423 CURLcode result = CURLE_OK;
424 struct doh_probes *dohp = NULL;
425 size_t i;
427 DEBUGASSERT(!async->doh);
428 DEBUGASSERT(async->peer->hostname[0]);
429 if(async->doh) {
430 DEBUGASSERT(0); /* should not happen */
431 Curl_doh_cleanup(data, async);
432 }
434 if(!async->dns_queries)
435 return CURLE_BAD_FUNCTION_ARGUMENT;
436#ifdef USE_HTTPSRR
437 if(CURL_DNSQ_IS_ADDR(async->dns_queries) &&
438 (async->dns_queries & CURL_DNSQ_HTTPS)) {
439 /* Can't mix those in the same async resolve */
440 DEBUGASSERT(0);
441 return CURLE_BAD_FUNCTION_ARGUMENT;
442 }
443#else
444 if(async->dns_queries & CURL_DNSQ_HTTPS) {
445 DEBUGASSERT(0);
446 return CURLE_NOT_BUILT_IN;
447 }
448#endif
450 /* start clean, consider allocating this struct on demand */
451 async->doh = dohp = curlx_calloc(1, sizeof(struct doh_probes));
452 if(!dohp)
453 return CURLE_OUT_OF_MEMORY;
455 for(i = 0; i < DOH_SLOT_COUNT; ++i) {
456 dohp->probe_rc[i] = DOH_OK;
457 dohp->probe_mid[i] = UINT32_MAX;
458 }
460#ifdef USE_IPV6
461 /* AAAA results have preference in happy eyeballing, trigger first */
462 if(async->dns_queries & CURL_DNSQ_AAAA) {
463 /* create IPv6 DoH request */
464 result = doh_probe_run(data, CURL_DNS_TYPE_AAAA,
465 async->peer->hostname,
466 CURL_EASY_STR(data, STRING_DOH),
467 data->multi, async->id,
468 &dohp->probe_mid[DOH_SLOT_IPV6]);
469 if(result)
470 goto error;
471 async->queries_ongoing++;
472 }
473#endif
475 /* create IPv4 DoH request */
476 if(async->dns_queries & CURL_DNSQ_A) {
477 result = doh_probe_run(data, CURL_DNS_TYPE_A,
478 async->peer->hostname,
479 CURL_EASY_STR(data, STRING_DOH),
480 data->multi, async->id,
481 &dohp->probe_mid[DOH_SLOT_IPV4]);
482 if(result)
483 goto error;
484 async->queries_ongoing++;
485 }
487#ifdef USE_HTTPSRR
488 if(async->dns_queries & CURL_DNSQ_HTTPS) {
489 char *qname = NULL;
490 if(async->peer->port != PORT_HTTPS) {
491 qname = curl_maprintf("_%u._https.%s",
492 async->peer->port, async->peer->hostname);
493 if(!qname)
494 goto error;
495 }
496 result = doh_probe_run(data, CURL_DNS_TYPE_HTTPS,
497 qname ? qname : async->peer->hostname,
498 CURL_EASY_STR(data, STRING_DOH), data->multi,
499 async->id,
500 &dohp->probe_mid[DOH_SLOT_HTTPS_RR]);
501 curlx_free(qname);
502 if(result)
503 goto error;
504 async->queries_ongoing++;
505 }
506#endif
507 return CURLE_OK;
509error:
510 Curl_doh_cleanup(data, async);
511 return result;
514static DOHcode doh_skipqname(const unsigned char *doh, size_t dohlen,
515 unsigned int *indexp)
517 unsigned char length;
518 do {
519 if(dohlen < (*indexp + 1))
520 return DOH_DNS_OUT_OF_RANGE;
521 length = doh[*indexp];
522 if((length & 0xc0) == 0xc0) {
523 /* name pointer, advance over it and be done */
524 if(dohlen < (*indexp + 2))
525 return DOH_DNS_OUT_OF_RANGE;
526 *indexp += 2;
527 break;
528 }
529 if(length & 0xc0)
530 return DOH_DNS_BAD_LABEL;
531 if(dohlen < (*indexp + 1 + length))
532 return DOH_DNS_OUT_OF_RANGE;
533 *indexp += (unsigned int)(1 + length);
534 } while(length);
535 return DOH_OK;
538static unsigned short doh_get16bit(const unsigned char *doh,
539 unsigned int index)
541 return (unsigned short)((doh[index] << 8) | doh[index + 1]);
544static unsigned int doh_get32bit(const unsigned char *doh, unsigned int index)
546 /* make clang and gcc optimize this to bswap by incrementing
547 the pointer first. */
548 doh += index;
550 /* avoid undefined behavior by casting to unsigned before shifting
551 24 bits, possibly into the sign bit. codegen is same, but
552 ub sanitizer will not be upset */
553 return ((unsigned)doh[0] << 24) | ((unsigned)doh[1] << 16) |
554 ((unsigned)doh[2] << 8) | doh[3];
557static void doh_store_a(const unsigned char *doh, int index,
558 struct dohentry *d)
560 /* silently ignore addresses over the limit */
561 if(d->numaddr < DOH_MAX_ADDR) {
562 struct dohaddr *a = &d->addr[d->numaddr];
563 a->type = CURL_DNS_TYPE_A;
564 memcpy(&a->ip.v4, &doh[index], 4);
565 d->numaddr++;
566 }
569static void doh_store_aaaa(const unsigned char *doh, int index,
570 struct dohentry *d)
572 /* silently ignore addresses over the limit */
573 if(d->numaddr < DOH_MAX_ADDR) {
574 struct dohaddr *a = &d->addr[d->numaddr];
575 a->type = CURL_DNS_TYPE_AAAA;
576 memcpy(&a->ip.v6, &doh[index], 16);
577 d->numaddr++;
578 }
581#ifdef USE_HTTPSRR
582static DOHcode doh_store_https(const unsigned char *doh, int index,
583 struct dohentry *d, uint16_t len)
585 /* silently ignore RRs over the limit */
586 if(d->numhttps_rrs < DOH_MAX_HTTPS) {
587 struct dohhttps_rr *h = &d->https_rrs[d->numhttps_rrs];
588 h->val = curlx_memdup(&doh[index], len);
589 if(!h->val)
590 return DOH_OUT_OF_MEM;
591 h->len = len;
592 d->numhttps_rrs++;
593 }
594 return DOH_OK;
596#endif
598static DOHcode doh_rdata(const unsigned char *doh,
599 unsigned short rdlength,
600 unsigned short type,
601 int index,
602 struct dohentry *d)
604 /* RDATA
605 - A (TYPE 1): 4 bytes
606 - AAAA (TYPE 28): 16 bytes
607 - HTTPS (TYPE 65): N bytes */
608 switch(type) {
609 case CURL_DNS_TYPE_A:
610 if(rdlength != 4)
611 return DOH_DNS_RDATA_LEN;
612 doh_store_a(doh, index, d);
613 break;
614 case CURL_DNS_TYPE_AAAA:
615 if(rdlength != 16)
616 return DOH_DNS_RDATA_LEN;
617 doh_store_aaaa(doh, index, d);
618 break;
619#ifdef USE_HTTPSRR
620 case CURL_DNS_TYPE_HTTPS:
621 if(rdlength < 3)
622 return DOH_DNS_RDATA_LEN;
623 return doh_store_https(doh, index, d, rdlength);
624#endif
625 default:
626 /* unsupported type, or type we do not store, skip it */
627 break;
628 }
629 return DOH_OK;
632/* @unittest 1655 */
633UNITTEST void de_init(struct dohentry *de);
634UNITTEST void de_init(struct dohentry *de)
636 memset(de, 0, sizeof(*de));
637 de->ttl = INT_MAX;
640/* TTL value cap */
641#define MAX_DNS_TTL 86400U /* 24 hours */
642/* @unittest 1650 */
643UNITTEST DOHcode doh_resp_decode(const unsigned char *doh,
644 size_t dohlen,
645 DNStype dnstype,
646 struct dohentry *d);
647UNITTEST DOHcode doh_resp_decode(const unsigned char *doh,
648 size_t dohlen,
649 DNStype dnstype,
650 struct dohentry *d)
652 unsigned char rcode;
653 unsigned short qdcount;
654 unsigned short ancount;
655 unsigned short type = 0;
656 unsigned short rdlength;
657 unsigned short nscount;
658 unsigned short arcount;
659 unsigned int index = 12;
660 DOHcode rc;
662 if(dohlen < 12)
663 return DOH_TOO_SMALL_BUFFER; /* too small */
664 if(!doh || doh[0] || doh[1])
665 return DOH_DNS_BAD_ID; /* bad ID */
666 rcode = doh[3] & 0x0f;
667 if(rcode == 3)
668 return DOH_DNS_NXDOMAIN; /* name does not exist */
669 if(rcode)
670 return DOH_DNS_BAD_RCODE; /* bad rcode */
672 qdcount = doh_get16bit(doh, 4);
673 while(qdcount) {
674 rc = doh_skipqname(doh, dohlen, &index);
675 if(rc)
676 return rc; /* bad qname */
677 if(dohlen < (index + 4))
678 return DOH_DNS_OUT_OF_RANGE;
679 index += 4; /* skip question's type and class */
680 qdcount--;
681 }
683 ancount = doh_get16bit(doh, 6);
684 while(ancount) {
685 unsigned short dnsclass;
686 unsigned int ttl;
688 rc = doh_skipqname(doh, dohlen, &index);
689 if(rc)
690 return rc; /* bad qname */
692 if(dohlen < (index + 2))
693 return DOH_DNS_OUT_OF_RANGE;
695 type = doh_get16bit(doh, index);
696 if((type != CURL_DNS_TYPE_CNAME) && /* may be synthesized from DNAME */
697 (type != CURL_DNS_TYPE_DNAME) && /* if present, accept and ignore */
698 (type != dnstype))
699 /* Not the same type as was asked for, nor CNAME nor DNAME */
700 return DOH_DNS_UNEXPECTED_TYPE;
701 index += 2;
703 if(dohlen < (index + 2))
704 return DOH_DNS_OUT_OF_RANGE;
705 dnsclass = doh_get16bit(doh, index);
706 if(DNS_CLASS_IN != dnsclass)
707 return DOH_DNS_UNEXPECTED_CLASS; /* unsupported */
708 index += 2;
710 if(dohlen < (index + 4))
711 return DOH_DNS_OUT_OF_RANGE;
713 ttl = doh_get32bit(doh, index);
714 if(ttl > MAX_DNS_TTL)
715 ttl = MAX_DNS_TTL;
716 if(ttl < d->ttl)
717 d->ttl = ttl;
718 index += 4;
720 if(dohlen < (index + 2))
721 return DOH_DNS_OUT_OF_RANGE;
723 rdlength = doh_get16bit(doh, index);
724 index += 2;
725 if(dohlen < (index + rdlength))
726 return DOH_DNS_OUT_OF_RANGE;
728 rc = doh_rdata(doh, rdlength, type, (int)index, d);
729 if(rc)
730 return rc;
731 index += rdlength;
732 ancount--;
733 }
735 nscount = doh_get16bit(doh, 8);
736 while(nscount) {
737 rc = doh_skipqname(doh, dohlen, &index);
738 if(rc)
739 return rc; /* bad qname */
741 if(dohlen < (index + 8))
742 return DOH_DNS_OUT_OF_RANGE;
744 index += 2 + 2 + 4; /* type, dnsclass and ttl */
746 if(dohlen < (index + 2))
747 return DOH_DNS_OUT_OF_RANGE;
749 rdlength = doh_get16bit(doh, index);
750 index += 2;
751 if(dohlen < (index + rdlength))
752 return DOH_DNS_OUT_OF_RANGE;
753 index += rdlength;
754 nscount--;
755 }
757 arcount = doh_get16bit(doh, 10);
758 while(arcount) {
759 rc = doh_skipqname(doh, dohlen, &index);
760 if(rc)
761 return rc; /* bad qname */
763 if(dohlen < (index + 8))
764 return DOH_DNS_OUT_OF_RANGE;
766 index += 2 + 2 + 4; /* type, dnsclass and ttl */
768 if(dohlen < (index + 2))
769 return DOH_DNS_OUT_OF_RANGE;
771 rdlength = doh_get16bit(doh, index);
772 index += 2;
773 if(dohlen < (index + rdlength))
774 return DOH_DNS_OUT_OF_RANGE;
775 index += rdlength;
776 arcount--;
777 }
779 if(index != dohlen)
780 return DOH_DNS_MALFORMAT; /* something is wrong */
782 return DOH_OK; /* ok */
785/*
786 * This function returns a pointer to the first element of a newly allocated
787 * Curl_addrinfo struct linked list filled with the data from a set of DoH
788 * lookups. Curl_addrinfo is meant to work like the addrinfo struct does for
789 * an IPv6 stack, but usable also for IPv4, all hosts and environments.
790 *
791 * The memory allocated by this function *MUST* be free'd later on calling
792 * Curl_freeaddrinfo(). For each successful call to this function there
793 * must be an associated call later to Curl_freeaddrinfo().
794 */
795static CURLcode doh2ai(const struct dohentry *de, const char *hostname,
796 int port, struct Curl_addrinfo **aip)
798 struct Curl_addrinfo *ai;
799 struct Curl_addrinfo *prevai = NULL;
800 struct Curl_addrinfo *firstai = NULL;
801 struct sockaddr_in *addr;
802#ifdef USE_IPV6
803 struct sockaddr_in6 *addr6;
804#endif
805 size_t hostlen = strlen(hostname) + 1; /* include null-terminator */
806 CURLcode result = CURLE_OK;
807 int i;
809 for(i = 0; i < de->numaddr; i++) {
810 size_t ss_size;
811 CURL_SA_FAMILY_T addrtype;
812 if(de->addr[i].type == CURL_DNS_TYPE_AAAA) {
813#ifndef USE_IPV6
814 /* we cannot handle IPv6 addresses */
815 continue;
816#else
817 ss_size = sizeof(struct sockaddr_in6);
818 addrtype = AF_INET6;
819#endif
820 }
821 else {
822 ss_size = sizeof(struct sockaddr_in);
823 addrtype = AF_INET;
824 }
826 ai = curlx_calloc(1, sizeof(struct Curl_addrinfo) + ss_size + hostlen);
827 if(!ai) {
828 result = CURLE_OUT_OF_MEMORY;
829 break;
830 }
831 ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo));
832 ai->ai_canonname = (void *)((char *)ai->ai_addr + ss_size);
833 memcpy(ai->ai_canonname, hostname, hostlen);
835 if(!firstai)
836 /* store the pointer we want to return from this function */
837 firstai = ai;
839 if(prevai)
840 /* make the previous entry point to this */
841 prevai->ai_next = ai;
843 ai->ai_family = addrtype;
845 /* we return all names as STREAM, so when using this address for TFTP
846 the type must be ignored and conn->socktype be used instead! */
847 ai->ai_socktype = SOCK_STREAM;
849 ai->ai_addrlen = (curl_socklen_t)ss_size;
851 /* leave the rest of the struct filled with zero */
853 switch(ai->ai_family) {
854 case AF_INET:
855 addr = (void *)ai->ai_addr; /* storage area for this info */
856 DEBUGASSERT(sizeof(struct in_addr) == sizeof(de->addr[i].ip.v4));
857 memcpy(&addr->sin_addr, &de->addr[i].ip.v4, sizeof(struct in_addr));
858 addr->sin_family = addrtype;
859 addr->sin_port = htons((unsigned short)port);
860 break;
862#ifdef USE_IPV6
863 case AF_INET6:
864 addr6 = (void *)ai->ai_addr; /* storage area for this info */
865 DEBUGASSERT(sizeof(struct in6_addr) == sizeof(de->addr[i].ip.v6));
866 memcpy(&addr6->sin6_addr, &de->addr[i].ip.v6, sizeof(struct in6_addr));
867 addr6->sin6_family = addrtype;
868 addr6->sin6_port = htons((unsigned short)port);
869 break;
870#endif
871 }
873 prevai = ai;
874 }
876 if(result) {
877 Curl_freeaddrinfo(firstai);
878 firstai = NULL;
879 }
880 *aip = firstai;
882 return result;
885/* @unittest 1655 */
886UNITTEST void de_cleanup(struct dohentry *d);
887UNITTEST void de_cleanup(struct dohentry *d)
889#ifdef USE_HTTPSRR
890 int i = 0;
891 for(i = 0; i < d->numhttps_rrs; i++)
892 curlx_safefree(d->https_rrs[i].val);
893#else
894 (void)d;
895#endif
898#ifdef USE_HTTPSRR
900/*
901 * @brief decode the DNS name in a binary RRData
902 * @param buf points to the buffer (in/out)
903 * @param remaining points to the remaining buffer length (in/out)
904 * @param dnsname returns the string form name on success
905 * @return is 1 for success, error otherwise
906 *
907 * The encoding here is defined in
908 * https://datatracker.ietf.org/doc/html/rfc1035#section-3.1
909 *
910 * The input buffer pointer will be modified so it points to after the end of
911 * the DNS name encoding on output. (that is why it is an "unsigned char
912 * **" :-)
913 */
914static CURLcode doh_decode_rdata_name(const unsigned char **buf,
915 size_t *remaining, char **dnsname)
917 const unsigned char *cp = NULL;
918 size_t rem = 0;
919 unsigned char clen = 0; /* chunk len */
920 struct dynbuf thename;
922 DEBUGASSERT(buf && remaining && dnsname);
923 if(!buf || !remaining || !dnsname || !*remaining)
924 return CURLE_OUT_OF_MEMORY;
925 curlx_dyn_init(&thename, CURL_MAXLEN_HOST_NAME);
926 rem = *remaining;
927 cp = *buf;
928 clen = *cp++;
929 /* RFC 9460 says it must be uncompressed */
930 if(clen > 63)
931 return CURLE_WEIRD_SERVER_REPLY;
933 if(clen == 0) {
934 /* special case - return "." as name */
935 if(curlx_dyn_addn(&thename, ".", 1))
936 return CURLE_OUT_OF_MEMORY;
937 }
938 while(clen) {
939 if(clen >= rem) {
940 curlx_dyn_free(&thename);
941 return CURLE_OUT_OF_MEMORY;
942 }
943 if(curlx_dyn_addn(&thename, cp, clen) ||
944 curlx_dyn_addn(&thename, ".", 1))
945 return CURLE_TOO_LARGE;
947 cp += clen;
948 rem -= (clen + 1);
949 if(rem <= 0) {
950 curlx_dyn_free(&thename);
951 return CURLE_OUT_OF_MEMORY;
952 }
953 clen = *cp++;
954 if(clen > 63) {
955 /* invalid format */
956 curlx_dyn_free(&thename);
957 return CURLE_WEIRD_SERVER_REPLY;
958 }
959 }
960 *buf = cp;
961 *remaining = rem - 1;
962 *dnsname = curlx_dyn_ptr(&thename);
963 return CURLE_OK;
966/* scan for byte values <= 32 or 127 */
967static CURLcode junkscan(const char *url)
969 const unsigned char *p = (const unsigned char *)url;
970 while(*p) {
971 if(*p <= 0x20 || *p == 127)
972 return CURLE_WEIRD_SERVER_REPLY;
973 p++;
974 }
975 return CURLE_OK;
978/* @unittest 1658 */
979UNITTEST CURLcode doh_resp_decode_httpsrr(struct Curl_easy *data,
980 const unsigned char *cp, size_t len,
981 struct Curl_https_rrinfo **hrr);
982UNITTEST CURLcode doh_resp_decode_httpsrr(struct Curl_easy *data,
983 const unsigned char *cp, size_t len,
984 struct Curl_https_rrinfo **hrr)
986 uint16_t pcode = 0, plen = 0;
987 uint32_t expected_min_pcode = 0;
988 struct Curl_https_rrinfo *lhrr = NULL;
989 char *dnsname = NULL;
990 CURLcode result = CURLE_OUT_OF_MEMORY;
992 (void)data;
993 *hrr = NULL;
994 if(len <= 2)
995 return CURLE_BAD_FUNCTION_ARGUMENT;
996 lhrr = curlx_calloc(1, sizeof(struct Curl_https_rrinfo));
997 if(!lhrr)
998 return CURLE_OUT_OF_MEMORY;
999 lhrr->priority = doh_get16bit(cp, 0);
1000 cp += 2;
1001 len -= 2;
1002 if(doh_decode_rdata_name(&cp, &len, &dnsname) != CURLE_OK)
1003 goto err;
1004 lhrr->target = dnsname;
1005 result = junkscan(dnsname);
1006 if(result) {
1007 /* unacceptable hostname content */
1008 goto err;
1010 while(len >= 4) {
1011 pcode = doh_get16bit(cp, 0);
1012 plen = doh_get16bit(cp, 2);
1013 cp += 4;
1014 len -= 4;
1015 if(pcode < expected_min_pcode || plen > len) {
1016 result = CURLE_WEIRD_SERVER_REPLY;
1017 goto err;
1019 result = Curl_httpsrr_set(lhrr, pcode, cp, plen);
1020 if(result)
1021 goto err;
1022 Curl_httpsrr_trace(data, lhrr);
1023 cp += plen;
1024 len -= plen;
1025 expected_min_pcode = pcode + 1;
1027 *hrr = lhrr;
1028 return CURLE_OK;
1029err:
1030 Curl_httpsrr_destroy(lhrr);
1031 return result;
1034#endif /* USE_HTTPSRR */
1036/* called from multi when a sub transfer, e.g. doh probe, is done.
1037 * Parse the response and set the results in the `async` context
1038 * of master, using the id from the probe's CURL_EZM_DOH_PROBE
1039 * meta data. */
1040static void doh_probe_done(struct Curl_easy *doh,
1041 struct Curl_easy *master, CURLcode result)
1043 struct Curl_resolv_async *async = NULL;
1044 struct doh_probes *dohp = NULL;
1045 struct doh_request *doh_req = NULL;
1046 struct Curl_addrinfo **pdest_ai;
1047 struct dohentry de;
1048 int slot, httpcode;
1050 de_init(&de);
1051 doh_req = Curl_meta_get(doh, CURL_EZM_DOH_PROBE);
1052 if(!doh_req) {
1053 /* transfer `doh` is not a DoH probe. */
1054 DEBUGASSERT(0);
1055 goto out;
1058 async = Curl_async_get(master, doh_req->resolv_id);
1059 if(!async) {
1060 CURL_TRC_DNS(master, "[%u] ignoring outdated DoH response",
1061 doh_req->resolv_id);
1062 goto out;
1064 dohp = async->doh;
1066 for(slot = 0; slot < DOH_SLOT_COUNT; ++slot) {
1067 if(dohp->probe_mid[slot] == doh->mid)
1068 break;
1070 /* We really should have found the slot where to store the response */
1071 if(slot >= DOH_SLOT_COUNT) {
1072 failf(master, "DoH: unknown sub request done");
1073 DEBUGASSERT(0);
1074 goto out;
1077 async->queries_ongoing--;
1078 dohp = async->doh;
1079 httpcode = doh->info.httpcode;
1080 switch(slot) {
1081 case DOH_SLOT_IPV4:
1082 async->dns_responses |= CURL_DNSQ_A;
1083 break;
1084#ifdef USE_IPV6
1085 case DOH_SLOT_IPV6:
1086 async->dns_responses |= CURL_DNSQ_AAAA;
1087 break;
1088#endif
1089#ifdef USE_HTTPSRR
1090 case DOH_SLOT_HTTPS_RR:
1091 async->dns_responses |= CURL_DNSQ_HTTPS;
1092 break;
1093#endif
1094 default:
1095 DEBUGASSERT(0);
1096 break;
1099 if(result) {
1100 dohp->probe_rc[slot] = DOH_HTTP_FAILED;
1101 infof(doh, "[DoH] [%s] error: %s",
1102 doh_type2name(doh_req->dnstype), curl_easy_strerror(result));
1103 goto out;
1105 else if((httpcode < 200) || (httpcode >= 300)) {
1106 dohp->probe_rc[slot] = DOH_HTTP_FAILED;
1107 infof(doh, "[DoH] [%s] error: HTTP status %d",
1108 doh_type2name(doh_req->dnstype), httpcode);
1109 goto out;
1112 dohp->probe_rc[slot] = doh_resp_decode(curlx_dyn_uptr(&doh_req->resp_body),
1113 curlx_dyn_len(&doh_req->resp_body),
1114 doh_req->dnstype, &de);
1115 if(dohp->probe_rc[slot]) {
1116#ifdef USE_HTTPSRR
1117 if((dohp->probe_rc[slot] == DOH_NO_CONTENT) &&
1118 (doh_req->dnstype == CURL_DNS_TYPE_HTTPS)) {
1119 dohp->probe_rc[slot] = DOH_DNS_NXDOMAIN;
1121#endif
1122 infof(doh, "[DoH] [%s] error decoding response: %s",
1123 doh_type2name(doh_req->dnstype),
1124 doh_strerror(dohp->probe_rc[slot]));
1125 goto out;
1128 if(doh_req->dnstype == CURL_DNS_TYPE_A)
1129 pdest_ai = &async->ai_A;
1130 else if(doh_req->dnstype == CURL_DNS_TYPE_AAAA)
1131 pdest_ai = &async->ai_AAAA;
1132 else
1133 pdest_ai = NULL;
1135 if(pdest_ai && de.numaddr) {
1136 if(*pdest_ai) {
1137 Curl_freeaddrinfo(*pdest_ai);
1138 *pdest_ai = NULL;
1140 result = doh2ai(&de, async->peer->hostname, async->peer->port, pdest_ai);
1141 if(result) { /* hard failure on our side, fail completely */
1142 infof(doh, "[DoH] [%s] error creating addrinfo: %s",
1143 doh_type2name(doh_req->dnstype), curl_easy_strerror(result));
1144 dohp->probe_rc[slot] = DOH_OOM;
1145 async->result = result;
1148#ifdef USE_HTTPSRR
1149 else if((doh_req->dnstype == CURL_DNS_TYPE_HTTPS) && de.numhttps_rrs) {
1150 CURL_TRC_DNS(doh, "[HTTPS] got %d records", de.numhttps_rrs);
1151 result = doh_resp_decode_httpsrr(doh, de.https_rrs->val,
1152 de.https_rrs->len, &async->httpsrr);
1153 if(result) {
1154 dohp->probe_rc[slot] = DOH_HTTP_FAILED;
1155 infof(doh, "[DoH] error decoding HTTPS RR: %s",
1156 curl_easy_strerror(result));
1157 goto out;
1160#endif /* USE_HTTPSRR */
1162 /* DoH request complete, run master to act on results */
1163 infof(doh, "DoH request complete, %u to go", async->queries_ongoing);
1165out:
1166 Curl_multi_mark_dirty(master);
1167 de_cleanup(&de);
1168 Curl_meta_remove(doh, CURL_EZM_DOH_PROBE);
1171CURLcode Curl_doh_take_result(struct Curl_easy *data,
1172 struct Curl_resolv_async *async,
1173 struct Curl_dns_entry **pdns)
1175 struct doh_probes *dohp = async->doh;
1176 CURLcode result = CURLE_OK;
1178 *pdns = NULL; /* defaults to no response */
1179 if(!dohp)
1180 return CURLE_OUT_OF_MEMORY;
1182 async->negative_answer = FALSE;
1183 if(async->result) {
1184 result = async->result;
1185 goto out;
1188 if(CURL_DNSQ_IS_ADDR(async->dns_queries) &&
1189 dohp->probe_mid[DOH_SLOT_IPV4] == UINT32_MAX &&
1190 dohp->probe_mid[DOH_SLOT_IPV6] == UINT32_MAX) {
1191 failf(data, "Could not DoH-resolve: %s", async->peer->hostname);
1192 return async->for_proxy ?
1193 CURLE_COULDNT_RESOLVE_PROXY : CURLE_COULDNT_RESOLVE_HOST;
1195 else if(!async->queries_ongoing) {
1196 struct Curl_dns_entry *dns = NULL;
1197 bool negative = TRUE;
1198 int slot;
1200 /* remove DoH handles from multi handle and close them */
1201 doh_close(data, async);
1202 /* parse the responses, create the struct and return it! */
1203 for(slot = 0; slot < DOH_SLOT_COUNT; slot++) {
1204 /* Failing without an NXDOMAIN answer - a SERVFAIL-class rcode or
1205 an undecodable response - says nothing about the name. Such a
1206 failure must not be cached as a negative entry. */
1207 if(dohp->probe_rc[slot] && (dohp->probe_rc[slot] != DOH_DNS_NXDOMAIN))
1208 negative = FALSE;
1209 } /* next slot */
1211 if(async->ai_A || async->ai_AAAA) {
1212 dns = Curl_dnsc_mk_addr2(
1213 data, async->dns_queries, &async->ai_A, &async->ai_AAAA, async->peer);
1214 if(!dns) {
1215 result = CURLE_OUT_OF_MEMORY;
1216 goto out;
1219#ifdef USE_HTTPSRR
1220 else if((async->dns_queries & CURL_DNSQ_HTTPS) &&
1221 !dohp->probe_rc[DOH_SLOT_HTTPS_RR]) {
1222 Curl_httpsrr_trace(data, async->httpsrr);
1223 dns = Curl_dnsc_mk_https(data, &async->httpsrr, async->peer);
1224 if(!dns) {
1225 result = CURLE_OUT_OF_MEMORY;
1226 goto out;
1229#endif /* USE_HTTPSRR */
1230 else {
1231 /* every query failed. Only NXDOMAIN answers for all of them
1232 make this a negative answer, eligible for caching. */
1233 async->negative_answer = negative;
1234 result = async->for_proxy ?
1235 CURLE_COULDNT_RESOLVE_PROXY : CURLE_COULDNT_RESOLVE_HOST;
1238 /* and add the entry to the cache */
1239 if(dns)
1240 result = Curl_dnscache_add(data, dns);
1241 *pdns = dns;
1242 } /* !async->queries_ongoing */
1243 else
1244 /* wait for pending DoH transactions to complete */
1245 return CURLE_AGAIN;
1247out:
1248 Curl_doh_cleanup(data, async);
1249 return result;
1252static void doh_close(struct Curl_easy *data,
1253 struct Curl_resolv_async *async)
1255 struct doh_probes *doh = async ? async->doh : NULL;
1256 if(doh && data->multi) {
1257 struct Curl_easy *probe_data;
1258 uint32_t mid;
1259 size_t slot;
1260 for(slot = 0; slot < DOH_SLOT_COUNT; slot++) {
1261 mid = doh->probe_mid[slot];
1262 if(mid == UINT32_MAX)
1263 continue;
1264 doh->probe_mid[slot] = UINT32_MAX;
1265 /* should have been called before data is removed from multi handle */
1266 DEBUGASSERT(data->multi);
1267 probe_data = data->multi ? Curl_multi_get_easy(data->multi, mid) : NULL;
1268 if(!probe_data) {
1269 DEBUGF(infof(data, "Curl_doh_close: xfer for mid=%u not found!", mid));
1270 continue;
1272 probe_data->sub_xfer_done = NULL; /* No longer interested in result */
1273 /* data->multi might already be reset at this time */
1274 Curl_multi_remove_handle(data->multi, probe_data);
1275 Curl_close(&probe_data);
1277 CURL_TRC_DNS(data, "[DoH] probe done");
1281void Curl_doh_cleanup(struct Curl_easy *data,
1282 struct Curl_resolv_async *async)
1284 struct doh_probes *dohp = async->doh;
1285 if(dohp) {
1286 doh_close(data, async);
1287 curlx_safefree(async->doh);
1291#endif /* CURL_DISABLE_DOH */
Diagnostics4 git calls · 307 ms
CallStatusSizeTime0307 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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
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 · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=4
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=86
Open pack map
fetch20012 KiB301 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=300
git.response.bytes=12029
git.response.cache=MISS
git.response.duration_ms=301
git.fetch.wants=e30ae359e56a0e48a6553d323a2dd66acdb80ac6
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=12029
git.pkt.payload.max=12008
git.sideband.band1.bytes=12007
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
a5e9ef5dd8df0acb
Request
8c814ced…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format