]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ares: use `ares_strerror()` to retrieve error messages
authorStefan Eissing <stefan@eissing.org>
Mon, 11 Aug 2025 13:58:11 +0000 (15:58 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 22 Aug 2025 08:01:58 +0000 (10:01 +0200)
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

lib/asyn-ares.c
lib/asyn-thrdd.c
lib/hostip.c
lib/hostip.h

index 3eb769d93471db42291ba2459fe79e8f1ba6bf1c..e955990878ac1ac722679322d9ead243d1afe816 100644 (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;
index 1ff2d949d27c90a6a78b48e0faca2d0f1fe7bde3..a6eb250ed2c2c679b5c4c2bafb372213c04f05a9 100644 (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;
index e36184b4e3cbda08cf997638984fb2dd5b29f1cf..dfff9d61da86cd35166c87bbd565147dd6ab53af 100644 (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 */
index 65fa78fa5001789584c4c64e59fe8458530b71e2..2f78be82c2e72886a59608c7377db4771ba21e3f 100644 (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
 /*