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_HTTPSRR
28#include "urldata.h"
29#include "connect.h"
30#include "curl_trc.h"
31#include "vdns/httpsrr.h"
32#include "curlx/strdup.h"
33#include "curlx/inet_ntop.h"
35static CURLcode httpsrr_decode_alpn(const uint8_t *cp, size_t len,
36 unsigned char *alpns)
37{
38 /*
39 * The wire-format value for "alpn" consists of at least one alpn-id
40 * prefixed by its length as a single octet, and these length-value pairs
41 * are concatenated to form the SvcParamValue. These pairs MUST exactly fill
42 * the SvcParamValue; otherwise, the SvcParamValue is malformed.
43 */
44 int idnum = 0;
46 while(len > 0) {
47 size_t tlen = *cp++;
48 enum alpnid id;
49 len--;
50 if(tlen > len)
51 return CURLE_BAD_CONTENT_ENCODING;
53 /* we only store ALPN ids we know about */
54 id = Curl_alpn2alpnid(cp, tlen);
55 if(id != ALPN_none) {
56 if(idnum == MAX_HTTPSRR_ALPNS)
57 break;
58 if(idnum && memchr(alpns, id, idnum))
59 /* this ALPN id is already stored */
60 ;
61 else
62 alpns[idnum++] = (unsigned char)id;
63 }
64 cp += tlen;
65 len -= tlen;
66 }
67 if(idnum < MAX_HTTPSRR_ALPNS)
68 alpns[idnum] = ALPN_none; /* terminate the list */
69 return CURLE_OK;
70}
72#ifdef CURLVERBOSE
74static CURLcode httpsrr_print_addr(struct dynbuf *dyn,
75 int ai_family,
76 const uint8_t *addr,
77 size_t total_len)
78{
79 char buf[MAX_IPADR_LEN];
80 size_t i, alen = (ai_family == AF_INET6) ? 16 : 4;
81 const char *sep = "";
82 CURLcode result = CURLE_OK;
84 for(i = 0; (i < (total_len / alen)) && !result; ++i) {
85 if(curlx_inet_ntop(ai_family, addr + (i * alen), buf, sizeof(buf)))
86 result = curlx_dyn_add(dyn, "<error parsing address>");
87 else
88 result = curlx_dyn_addf(dyn, "%s%s", sep, buf);
89 sep = ",";
90 }
91 return result;
92}
94void Curl_httpsrr_trace(struct Curl_easy *data,
95 struct Curl_https_rrinfo *rr)
96{
97 struct dynbuf tmp;
98 CURLcode result;
100 if(!rr) {
101 CURL_TRC_DNS(data, "[HTTPS] no record available");
102 return;
103 }
104 curlx_dyn_init(&tmp, 1024);
105 result = Curl_httpsrr_print(&tmp, rr);
106 if(!result)
107 CURL_TRC_DNS(data, "[HTTPS] record: %s", curlx_dyn_ptr(&tmp));
108 else
109 CURL_TRC_DNS(data, "[HTTPS] error printing information");
110 curlx_dyn_free(&tmp);
111}
113CURLcode Curl_httpsrr_print(struct dynbuf *tmp,
114 struct Curl_https_rrinfo *rr)
115{
116 CURLcode result;
117 int i;
119 curlx_dyn_reset(tmp);
120 result = curlx_dyn_addf(tmp, "%u %s", rr->priority,
121 rr->target ? rr->target : ".");
122 if(!result && rr->mandatory)
123 result = curlx_dyn_add(tmp, " mandatory-keys(ignored)");
124 if(!result && rr->alpns[0]) {
125 const char *sep = "", *name;
126 result = curlx_dyn_add(tmp, " alpn=");
127 for(i = 0; !result && (i < 4); ++i) {
128 switch(rr->alpns[i]) {
129 case ALPN_h1:
130 name = "http/1.1";
131 break;
132 case ALPN_h2:
133 name = "h2";
134 break;
135 case ALPN_h3:
136 name = "h3";
137 break;
138 default:
139 name = NULL;
140 }
141 if(name) {
142 result = curlx_dyn_addf(tmp, "%s%s", sep, name);
143 sep = ",";
144 }
145 }
146 }
147 if(!result && rr->port_set) {
148 result = curlx_dyn_addf(tmp, " port=%u", rr->port);
149 }
150 if(!result && rr->no_def_alpn)
151 result = curlx_dyn_add(tmp, " no-default-alpn");
152 if(!result && rr->ipv6hints_len) {
153 result = curlx_dyn_add(tmp, " ipv6hint=");
154 if(!result)
155 result = httpsrr_print_addr(
156 tmp, AF_INET6, rr->ipv6hints, rr->ipv6hints_len);
157 }
158 if(!result && rr->ipv4hints_len) {
159 result = curlx_dyn_add(tmp, " ipv4hint=");
160 if(!result)
161 result = httpsrr_print_addr(
162 tmp, AF_INET, rr->ipv4hints, rr->ipv4hints_len);
163 }
164 if(!result && rr->echconfiglist_len)
165 result = curlx_dyn_addf(tmp, " ech=<%zu bytes>", rr->echconfiglist_len);
167 return result;
168}
170#endif /* CURLVERBOSE */
172CURLcode Curl_httpsrr_set(struct Curl_https_rrinfo *rr,
173 uint16_t rrkey, const uint8_t *val, size_t vlen)
174{
175 CURLcode result = CURLE_OK;
176 switch(rrkey) {
177 case HTTPS_RR_CODE_MANDATORY:
178 rr->mandatory = TRUE;
179 break;
180 case HTTPS_RR_CODE_ALPN: /* str_list */
181 result = httpsrr_decode_alpn(val, vlen, rr->alpns);
182 break;
183 case HTTPS_RR_CODE_NO_DEF_ALPN:
184 if(vlen) /* no data */
185 return CURLE_BAD_FUNCTION_ARGUMENT;
186 rr->no_def_alpn = TRUE;
187 break;
188 case HTTPS_RR_CODE_IPV4: /* addr4 list */
189 if(!vlen || (vlen & 3)) /* the size must be 4-byte aligned */
190 return CURLE_BAD_FUNCTION_ARGUMENT;
191 curlx_free(rr->ipv4hints);
192 rr->ipv4hints = curlx_memdup(val, vlen);
193 if(!rr->ipv4hints)
194 return CURLE_OUT_OF_MEMORY;
195 rr->ipv4hints_len = vlen;
196 break;
197 case HTTPS_RR_CODE_ECH:
198 if(!vlen)
199 return CURLE_BAD_FUNCTION_ARGUMENT;
200 curlx_free(rr->echconfiglist);
201 rr->echconfiglist = curlx_memdup(val, vlen);
202 if(!rr->echconfiglist)
203 return CURLE_OUT_OF_MEMORY;
204 rr->echconfiglist_len = vlen;
205 break;
206 case HTTPS_RR_CODE_IPV6: /* addr6 list */
207 if(!vlen || (vlen & 15)) /* the size must be 16-byte aligned */
208 return CURLE_BAD_FUNCTION_ARGUMENT;
209 curlx_free(rr->ipv6hints);
210 rr->ipv6hints = curlx_memdup(val, vlen);
211 if(!rr->ipv6hints)
212 return CURLE_OUT_OF_MEMORY;
213 rr->ipv6hints_len = vlen;
214 break;
215 case HTTPS_RR_CODE_PORT:
216 if(vlen != 2)
217 return CURLE_BAD_FUNCTION_ARGUMENT;
218 rr->port = (uint16_t)((val[0] << 8) | val[1]);
219 rr->port_set = TRUE;
220 break;
221 default:
222 /* unknown code */
223 break;
224 }
225 return result;
226}
228void Curl_httpsrr_destroy(struct Curl_https_rrinfo *rrinfo)
229{
230 if(rrinfo) {
231 curlx_free(rrinfo->target);
232 curlx_free(rrinfo->echconfiglist);
233 curlx_free(rrinfo->ipv4hints);
234 curlx_free(rrinfo->ipv6hints);
235 curlx_free(rrinfo);
236 }
237}
239bool Curl_httpsrr_applicable(struct Curl_easy *data,
240 const struct Curl_https_rrinfo *rr)
241{
242 if(!data->conn)
243 return FALSE;
244 return Curl_httpsrr_is_for_peer(data->conn->origin, rr);
245}
247bool Curl_httpsrr_is_for_peer(struct Curl_peer *peer,
248 const struct Curl_https_rrinfo *rr)
249{
250 if(!peer || !rr)
251 return FALSE;
252 return (!rr->target || !rr->target[0] ||
253 (rr->target[0] == '.' && !rr->target[1])) &&
254 (!rr->port_set || rr->port == peer->port);
255}
257#ifdef USE_ARES
259static CURLcode httpsrr_opt(const ares_dns_rr_t *rr,
260 ares_dns_rr_key_t key, size_t idx,
261 struct Curl_https_rrinfo *hinfo)
262{
263 const unsigned char *val = NULL;
264 unsigned short code;
265 size_t len = 0;
267 code = ares_dns_rr_get_opt(rr, key, idx, &val, &len);
268 return Curl_httpsrr_set(hinfo, code, val, len);
269}
271CURLcode Curl_httpsrr_from_ares(const ares_dns_record_t *dnsrec,
272 struct Curl_https_rrinfo **phinfo)
273{
274 struct Curl_https_rrinfo *hinfo = NULL;
275 CURLcode result = CURLE_OUT_OF_MEMORY;
276 size_t i;
278 hinfo = curlx_calloc(1, sizeof(*hinfo));
279 if(!hinfo)
280 goto out;
282 for(i = 0; i < ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER); i++) {
283 const char *target;
284 size_t opt;
285 const ares_dns_rr_t *rr =
286 ares_dns_record_rr_get_const(dnsrec, ARES_SECTION_ANSWER, i);
287 if(ares_dns_rr_get_type(rr) != ARES_REC_TYPE_HTTPS)
288 continue;
289 /* When SvcPriority is 0, the SVCB record is in AliasMode. Otherwise, it
290 is in ServiceMode */
291 target = ares_dns_rr_get_str(rr, ARES_RR_HTTPS_TARGET);
292 if(target && target[0]) {
293 curlx_free(hinfo->target);
294 hinfo->target = curlx_strdup(target);
295 if(!hinfo->target) {
296 result = CURLE_OUT_OF_MEMORY;
297 goto out;
298 }
299 }
300 hinfo->priority = ares_dns_rr_get_u16(rr, ARES_RR_HTTPS_PRIORITY);
301 for(opt = 0; opt < ares_dns_rr_get_opt_cnt(rr, ARES_RR_HTTPS_PARAMS);
302 opt++) {
303 result = httpsrr_opt(rr, ARES_RR_HTTPS_PARAMS, opt, hinfo);
304 if(result)
305 goto out;
306 }
307 }
308 result = CURLE_OK;
310out:
311 if(result) {
312 *phinfo = NULL;
313 Curl_httpsrr_destroy(hinfo);
314 }
315 else {
316 DEBUGASSERT(hinfo);
317 *phinfo = hinfo;
318 }
319 return result;
320}
322#endif /* USE_ARES */
324#endif /* USE_HTTPSRR */
Diagnostics4 git calls · 69 ms
CallStatusSizeTime069 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 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 · hit19 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=19 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
fetch2003.1 KiB · hit47 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=47 git.response.bytes=3194 git.response.cache=HIT git.response.duration_ms=47 git.fetch.wants=12a829978bfe5d3e0c5662f14cf95b7413c76271 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=3194 git.pkt.payload.max=3173 git.sideband.band1.bytes=3172 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
- a5e9ef2f3a7f0acb
- Request
- 3e7ff4f6…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format