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#include "fake_addrinfo.h"
28#ifdef USE_FAKE_GETADDRINFO
30#include <ares.h>
32void r_freeaddrinfo(struct addrinfo *cahead)
33{
34 struct addrinfo *canext;
35 struct addrinfo *ca;
37 for(ca = cahead; ca; ca = canext) {
38 canext = ca->ai_next;
39 curlx_free(ca);
40 }
41}
43struct context {
44 struct ares_addrinfo *addr;
45 int status;
46};
48static void async_addrinfo_cb(void *userp, int status, int timeouts,
49 struct ares_addrinfo *addr)
50{
51 struct context *ctx = (struct context *)userp;
52 (void)timeouts;
53 ctx->status = status;
54 if(ARES_SUCCESS == status) {
55 ctx->addr = addr;
56 }
57}
59/* convert the c-ares version into the "native" version */
60static struct addrinfo *mk_getaddrinfo(const struct ares_addrinfo *aihead)
61{
62 const struct ares_addrinfo_node *ai;
63 struct addrinfo *ca;
64 struct addrinfo *cafirst = NULL;
65 struct addrinfo *calast = NULL;
66 const char *name = aihead->name;
68 /* traverse the addrinfo list */
69 for(ai = aihead->nodes; ai; ai = ai->ai_next) {
70 size_t ss_size;
71 size_t namelen = name ? strlen(name) + 1 : 0;
72 /* ignore elements with unsupported address family,
73 settle family-specific sockaddr structure size. */
74 if(ai->ai_family == AF_INET)
75 ss_size = sizeof(struct sockaddr_in);
76 else if(ai->ai_family == AF_INET6)
77 ss_size = sizeof(struct sockaddr_in6);
78 else
79 continue;
81 /* ignore elements without required address info */
82 if(!ai->ai_addr || !(ai->ai_addrlen > 0))
83 continue;
85 /* ignore elements with bogus address size */
86 if((size_t)ai->ai_addrlen < ss_size)
87 continue;
89 ca = curlx_malloc(sizeof(struct addrinfo) + ss_size + namelen);
90 if(!ca) {
91 r_freeaddrinfo(cafirst);
92 return NULL;
93 }
95 /* copy each structure member individually, member ordering,
96 size, or padding might be different for each platform. */
98 ca->ai_flags = ai->ai_flags;
99 ca->ai_family = ai->ai_family;
100 ca->ai_socktype = ai->ai_socktype;
101 ca->ai_protocol = ai->ai_protocol;
102 ca->ai_addrlen = (curl_socklen_t)ss_size;
103 ca->ai_addr = NULL;
104 ca->ai_canonname = NULL;
105 ca->ai_next = NULL;
107 ca->ai_addr = (void *)((char *)ca + sizeof(struct addrinfo));
108 memcpy(ca->ai_addr, ai->ai_addr, ss_size);
110 if(namelen) {
111 ca->ai_canonname = (void *)((char *)ca->ai_addr + ss_size);
112 memcpy(ca->ai_canonname, name, namelen);
114 /* the name is only pointed to by the first entry in the "real"
115 addrinfo chain, so stop now */
116 name = NULL;
117 }
119 /* if the return list is empty, this becomes the first element */
120 if(!cafirst)
121 cafirst = ca;
123 /* add this element last in the return list */
124 if(calast)
125 calast->ai_next = ca;
126 calast = ca;
127 }
129 return cafirst;
130}
132/* RETURN VALUE
133 getaddrinfo() returns 0 if it succeeds, or one of the following nonzero
134 error codes:
135 ... */
136int r_getaddrinfo(const char *node,
137 const char *service,
138 const struct addrinfo *hints,
139 struct addrinfo **res)
140{
141 int status;
142 struct context ctx;
143 struct ares_options options;
144 int optmask = 0;
145 struct ares_addrinfo_hints ahints;
146 ares_channel channel;
147 int rc = 0;
149 memset(&options, 0, sizeof(options));
150 optmask |= ARES_OPT_EVENT_THREAD;
151 options.evsys = ARES_EVSYS_DEFAULT;
153 memset(&ahints, 0, sizeof(ahints));
154 memset(&ctx, 0, sizeof(ctx));
156 if(hints) {
157 ahints.ai_flags = hints->ai_flags;
158 ahints.ai_family = hints->ai_family;
159 ahints.ai_socktype = hints->ai_socktype;
160 ahints.ai_protocol = hints->ai_protocol;
161 }
163 status = ares_init_options(&channel, &options, optmask);
164 if(status)
165 return EAI_MEMORY; /* major problem */
167 else {
168 const char *env = getenv("CURL_DNS_SERVER");
169 if(env) {
170 rc = ares_set_servers_ports_csv(channel, env);
171 if(rc) {
172 curl_mfprintf(stderr, "ares_set_servers_ports_csv failed: %d", rc);
173 /* Cleanup */
174 ares_destroy(channel);
175 return EAI_MEMORY; /* we cannot run */
176 }
177 }
178 }
180 ares_getaddrinfo(channel, node, service, &ahints, async_addrinfo_cb, &ctx);
182 /* Wait until no more requests are left to be processed */
183 ares_queue_wait_empty(channel, -1);
185 if(ctx.addr) {
186 /* convert the c-ares version */
187 *res = mk_getaddrinfo(ctx.addr);
188 /* free the old */
189 ares_freeaddrinfo(ctx.addr);
190 }
191 else if((ctx.status == ARES_ENOTFOUND) || (ctx.status == ARES_ENODATA))
192 rc = EAI_NONAME; /* no such name */
193 else
194 rc = EAI_AGAIN; /* failed without an authoritative answer */
196 /* Cleanup */
197 ares_destroy(channel);
199 return rc;
200}
202#endif /* USE_FAKE_GETADDRINFO */
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 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 · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=23 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=1 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
fetch2002.3 KiB · hit23 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2327 git.response.cache=HIT git.response.duration_ms=23 git.fetch.wants=6857d6348518bc40ce36032b502d2954f95e8b90 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=2327 git.pkt.payload.max=2306 git.sideband.band1.bytes=2305 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
- a5e309df6dd8ee28
- Request
- a7cd42e2…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format