ares: use ares_strerror() to retrieve error messages

Add optional detail to `Curl_resolver_error()` to add to failure message
where available. This makes, for c-ares, the reason for a failed
resource available to the user without extra trace config.

When "dns" tracing enabled, print the c-ares server config at the start
of a resolve.

Closes #18251
This commit is contained in:
Stefan Eissing 2025-08-11 15:58:11 +02:00 committed by Daniel Stenberg
parent 8ebea37eb1
commit 6b111f0a8c
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 15 additions and 31 deletions

View file

@ -359,32 +359,10 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data,
/* if we have not found anything, report the proper
* CURLE_COULDNT_RESOLVE_* code */
if(!result && !data->state.async.dns) {
result = Curl_resolver_error(data);
if(ares->ares_status != ARES_SUCCESS) {
const char *msg;
switch(ares->ares_status) {
case ARES_ECONNREFUSED:
msg = "connection to DNS server refused";
break;
case ARES_ETIMEOUT:
msg = "query to DNS server timed out";
break;
case ARES_ENOTFOUND:
msg = "DNS server did not find the address";
break;
case ARES_EREFUSED:
msg = "DNS server refused query";
break;
default:
msg = "resolve failed";
break;
}
CURL_TRC_DNS(data, "asyn-ares: %s (error %d)", msg, ares->ares_status);
#if ARES_VERSION >= 0x011800 /* >= v1.24.0 */
CURL_TRC_DNS(data, "asyn-ares config: %s",
ares_get_servers_csv(ares->channel));
#endif
}
const char *msg = NULL;
if(ares->ares_status != ARES_SUCCESS)
msg = ares_strerror(ares->ares_status);
result = Curl_resolver_error(data, msg);
}
if(result)
@ -768,6 +746,11 @@ struct Curl_addrinfo *Curl_async_getaddrinfo(struct Curl_easy *data,
ares->ares_status = ARES_ENOTFOUND;
ares->result = CURLE_OK;
#if ARES_VERSION >= 0x011800 /* >= v1.24.0 */
CURL_TRC_DNS(data, "asyn-ares: servers=%s",
ares_get_servers_csv(ares->channel));
#endif
#ifdef HAVE_CARES_GETADDRINFO
{
struct ares_addrinfo_hints hints;

View file

@ -683,7 +683,7 @@ CURLcode Curl_async_is_resolved(struct Curl_easy *data,
}
if(!result && !data->state.async.dns)
result = Curl_resolver_error(data);
result = Curl_resolver_error(data, NULL);
if(result)
Curl_resolv_unlink(data, &data->state.async.dns);
*dns = data->state.async.dns;

View file

@ -1552,7 +1552,7 @@ CURLcode Curl_resolv_check(struct Curl_easy *data,
if(data->conn->bits.doh) {
result = Curl_doh_is_resolved(data, dns);
if(result)
Curl_resolver_error(data);
Curl_resolver_error(data, NULL);
}
else
#endif
@ -1618,7 +1618,7 @@ CURLcode Curl_once_resolved(struct Curl_easy *data,
*/
#ifdef USE_CURL_ASYNC
CURLcode Curl_resolver_error(struct Curl_easy *data)
CURLcode Curl_resolver_error(struct Curl_easy *data, const char *detail)
{
struct connectdata *conn = data->conn;
const char *host_or_proxy = "host";
@ -1634,7 +1634,8 @@ CURLcode Curl_resolver_error(struct Curl_easy *data)
}
#endif
failf(data, "Could not resolve %s: %s", host_or_proxy, name);
failf(data, "Could not resolve %s: %s%s%s%s", host_or_proxy, name,
detail ? " (" : "", detail ? detail : "", detail ? ")" : "");
return result;
}
#endif /* USE_CURL_ASYNC */

View file

@ -201,7 +201,7 @@ CURLcode Curl_resolv_check(struct Curl_easy *data,
CURLcode Curl_resolv_pollset(struct Curl_easy *data,
struct easy_pollset *ps);
CURLcode Curl_resolver_error(struct Curl_easy *data);
CURLcode Curl_resolver_error(struct Curl_easy *data, const char *detail);
#ifdef CURLRES_SYNCH
/*