mirror of
https://github.com/curl/curl.git
synced 2026-04-14 18:11:40 +03:00
hostip: resolve user supplied ip addresses
When a user supplied an ip address in a URL as hostname, use that even when address family restrictions like -4 or -6 are set. Add test_10_15/16 to verify with a local proxy server. Fixes #21146 Reported-by: Terrance Wong How: - cf-dns: on see the hostname is an ip(v6) address, add the respective A/AAAA to the dns query bits - cf-dns/hostip: only hand out addrinfos for a family if that family is part of the DNS queries. That prevents for example ipv6 addresses to show up from dns cache entries - change cf-ip-happy to no longer check for "ip_version" and instead use all addresses that cf-dns hands out Closes #21295
This commit is contained in:
parent
ec445fc595
commit
40d57c9f58
6 changed files with 65 additions and 22 deletions
20
lib/cf-dns.c
20
lib/cf-dns.c
|
|
@ -167,7 +167,13 @@ static CURLcode cf_dns_start(struct Curl_cfilter *cf,
|
|||
#endif
|
||||
|
||||
/* Resolve target host right on */
|
||||
CURL_TRC_CF(data, cf, "resolve host %s:%u", ctx->hostname, ctx->port);
|
||||
CURL_TRC_CF(data, cf, "cf_dns_start host %s:%u", ctx->hostname, ctx->port);
|
||||
if(Curl_is_ipv4addr(ctx->hostname))
|
||||
ctx->dns_queries |= CURL_DNSQ_A;
|
||||
#ifdef USE_IPV6
|
||||
else if(Curl_is_ipaddr(ctx->hostname)) /* not ipv4, must be ipv6 then */
|
||||
ctx->dns_queries |= CURL_DNSQ_AAAA;
|
||||
#endif
|
||||
result = Curl_resolv(data, ctx->dns_queries,
|
||||
ctx->hostname, ctx->port, ctx->transport,
|
||||
timeout_ms, &ctx->resolv_id, pdns);
|
||||
|
|
@ -495,10 +501,18 @@ CURLcode Curl_conn_dns_result(struct connectdata *conn, int sockindex)
|
|||
}
|
||||
|
||||
static const struct Curl_addrinfo *
|
||||
cf_dns_get_nth_ai(const struct Curl_addrinfo *ai,
|
||||
cf_dns_get_nth_ai(struct Curl_cfilter *cf, const struct Curl_addrinfo *ai,
|
||||
int ai_family, unsigned int index)
|
||||
{
|
||||
struct cf_dns_ctx *ctx = cf->ctx;
|
||||
unsigned int i = 0;
|
||||
|
||||
if((ai_family == AF_INET) && !(ctx->dns_queries & CURL_DNSQ_A))
|
||||
return NULL;
|
||||
#ifdef USE_IPV6
|
||||
if((ai_family == AF_INET6) && !(ctx->dns_queries & CURL_DNSQ_AAAA))
|
||||
return NULL;
|
||||
#endif
|
||||
for(i = 0; ai; ai = ai->ai_next) {
|
||||
if(ai->ai_family == ai_family) {
|
||||
if(i == index)
|
||||
|
|
@ -550,7 +564,7 @@ Curl_cf_dns_get_ai(struct Curl_cfilter *cf,
|
|||
if(ctx->resolv_result)
|
||||
return NULL;
|
||||
else if(ctx->dns)
|
||||
return cf_dns_get_nth_ai(ctx->dns->addr, ai_family, index);
|
||||
return cf_dns_get_nth_ai(cf, ctx->dns->addr, ai_family, index);
|
||||
else
|
||||
return Curl_resolv_get_ai(data, ctx->resolv_id, ai_family, index);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ static void cf_ip_ballers_clear(struct Curl_cfilter *cf,
|
|||
bs->winner = NULL;
|
||||
}
|
||||
|
||||
static CURLcode cf_ip_ballers_init(struct cf_ip_ballers *bs, int ip_version,
|
||||
static CURLcode cf_ip_ballers_init(struct cf_ip_ballers *bs,
|
||||
struct Curl_cfilter *cf,
|
||||
cf_ip_connect_create *cf_create,
|
||||
uint8_t transport,
|
||||
|
|
@ -320,19 +320,9 @@ static CURLcode cf_ip_ballers_init(struct cf_ip_ballers *bs, int ip_version,
|
|||
}
|
||||
else { /* TCP/UDP/QUIC */
|
||||
#ifdef USE_IPV6
|
||||
if(ip_version == CURL_IPRESOLVE_V6)
|
||||
cf_ai_iter_init(&bs->addr_iter, NULL, AF_INET);
|
||||
else
|
||||
cf_ai_iter_init(&bs->addr_iter, cf, AF_INET);
|
||||
|
||||
if(ip_version == CURL_IPRESOLVE_V4)
|
||||
cf_ai_iter_init(&bs->ipv6_iter, NULL, AF_INET6);
|
||||
else
|
||||
cf_ai_iter_init(&bs->ipv6_iter, cf, AF_INET6);
|
||||
#else
|
||||
(void)ip_version;
|
||||
cf_ai_iter_init(&bs->addr_iter, cf, AF_INET);
|
||||
cf_ai_iter_init(&bs->ipv6_iter, cf, AF_INET6);
|
||||
#endif
|
||||
cf_ai_iter_init(&bs->addr_iter, cf, AF_INET);
|
||||
}
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
|
@ -748,7 +738,7 @@ static CURLcode cf_ip_happy_init(struct Curl_cfilter *cf,
|
|||
|
||||
CURL_TRC_CF(data, cf, "init ip ballers for transport %u", ctx->transport);
|
||||
ctx->started = *Curl_pgrs_now(data);
|
||||
return cf_ip_ballers_init(&ctx->ballers, cf->conn->ip_version, cf,
|
||||
return cf_ip_ballers_init(&ctx->ballers, cf,
|
||||
ctx->cf_create, ctx->transport,
|
||||
data->set.happy_eyeballs_timeout,
|
||||
IP_HE_MAX_CONCURRENT_ATTEMPTS);
|
||||
|
|
|
|||
|
|
@ -448,8 +448,15 @@ Curl_resolv_get_ai(struct Curl_easy *data, uint32_t resolv_id,
|
|||
{
|
||||
#ifdef CURLRES_ASYNCH
|
||||
struct Curl_resolv_async *async = Curl_async_get(data, resolv_id);
|
||||
if(async)
|
||||
if(async) {
|
||||
if((ai_family == AF_INET) && !(async->dns_queries & CURL_DNSQ_A))
|
||||
return NULL;
|
||||
#ifdef USE_IPV6
|
||||
if((ai_family == AF_INET6) && !(async->dns_queries & CURL_DNSQ_AAAA))
|
||||
return NULL;
|
||||
#endif
|
||||
return Curl_async_get_ai(data, async, ai_family, index);
|
||||
}
|
||||
#else
|
||||
(void)data;
|
||||
(void)resolv_id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue