dnscache: own source file, improvements

- Rename `Curl_resolv_unlink()` to `Curl_dns_entry_unlink()`.
- Change `Curl_dnscache_get()` to return CURLcode result. Returns
  now `CURLE_COULDNT_RESOLVE_HOST` for "negative" cache entries.
- Add `Curl_dnscache_add_negative()` to put a "negative" entry
  into the cache.

Closes #20864
This commit is contained in:
Stefan Eissing 2026-03-06 09:22:26 +01:00 committed by Daniel Stenberg
parent b0f6e9a3d7
commit 96d5b5c688
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
35 changed files with 1648 additions and 1413 deletions

View file

@ -245,8 +245,8 @@ CURLcode Curl_close(struct Curl_easy **datap)
/* release any resolve information this transfer kept */
Curl_async_destroy(data);
Curl_resolv_unlink(data, &data->state.dns[0]); /* done with this */
Curl_resolv_unlink(data, &data->state.dns[1]);
Curl_dns_entry_unlink(data, &data->state.dns[0]); /* done with this */
Curl_dns_entry_unlink(data, &data->state.dns[1]);
data->set.verbose = FALSE; /* no more calls to DEBUGFUNCTION */
data->magic = 0; /* force a clear AFTER the possibly enforced removal from
@ -2821,7 +2821,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data,
if(port >= 0) {
conn->conn_to_port = (uint16_t)port;
conn->bits.conn_to_port = TRUE;
infof(data, "Connecting to port: %d", port);
infof(data, "Connecting to port: %u", conn->conn_to_port);
}
else {
/* no "connect to port" */
@ -2991,7 +2991,6 @@ static CURLcode resolve_unix(struct Curl_easy *data,
*************************************************************/
static CURLcode resolve_server(struct Curl_easy *data,
struct connectdata *conn,
bool *async,
struct Curl_dns_entry **pdns)
{
struct hostname *ehost;
@ -3035,30 +3034,32 @@ static CURLcode resolve_server(struct Curl_easy *data,
ehost = conn->bits.conn_to_host ? &conn->conn_to_host : &conn->host;
/* If not connecting via a proxy, extract the port from the URL, if it is
* there, thus overriding any defaults that might have been set above. */
eport = conn->bits.conn_to_port ? conn->conn_to_port : conn->remote_port;
eport = conn->bits.conn_to_port ?
conn->conn_to_port : (uint16_t)conn->remote_port;
}
result = Curl_resolv_timeout(data, ehost->name,
eport, conn->ip_version,
pdns, timeout_ms);
result = Curl_resolv(data, ehost->name, eport,
conn->ip_version, timeout_ms, pdns);
DEBUGASSERT(!result || !*pdns);
if(result == CURLE_AGAIN) {
*async = TRUE;
if(!result) { /* resolved right away, either sync or from dnscache */
DEBUGASSERT(*pdns);
return CURLE_OK;
}
else if(result == CURLE_OPERATION_TIMEDOUT) {
else if(result == CURLE_AGAIN) { /* async resolv in progress */
return CURLE_AGAIN;
}
else if(result == CURLE_OPERATION_TIMEDOUT) { /* took too long */
failf(data, "Failed to resolve %s '%s' with timeout after %"
FMT_TIMEDIFF_T " ms", peertype, ehost->dispname,
curlx_ptimediff_ms(Curl_pgrs_now(data),
&data->progress.t_startsingle));
return CURLE_OPERATION_TIMEDOUT;
}
else if(result) {
else {
DEBUGASSERT(result);
failf(data, "Could not resolve %s: %s", peertype, ehost->dispname);
return result;
}
DEBUGASSERT(*pdns);
return CURLE_OK;
}
static void url_move_hostname(struct hostname *dest, struct hostname *src)
@ -3594,14 +3595,17 @@ CURLcode Curl_connect(struct Curl_easy *data,
* Resolve the address of the server or proxy
*************************************************************/
struct Curl_dns_entry *dns;
result = resolve_server(data, conn, asyncp, &dns);
result = resolve_server(data, conn, &dns);
if(!result) {
*asyncp = !dns;
if(dns)
/* DNS resolution is done: that is either because this is a reused
connection, in which case DNS was unnecessary, or because DNS
really did finish already (synch resolver/fast async resolve) */
result = Curl_setup_conn(data, dns, protocol_done);
DEBUGASSERT(dns);
/* DNS resolution is done: that is either because this is a reused
connection, in which case DNS was unnecessary, or because DNS
really did finish already (synch resolver/fast async resolve) */
result = Curl_setup_conn(data, dns, protocol_done);
}
else if(result == CURLE_AGAIN) {
*asyncp = TRUE;
result = CURLE_OK;
}
}
}