lib: provide a getaddrinfo wrapper

This uses c-ares under the hood and supports the CURL_DNS_SERVER
environment variable - for debug builds only. The getaddrinfo()
replacement function is only used if CURL_DNS_SERVER is set to make a
debug build work more like a release version without the variable set.

'override-dns' is a new feature for the test suite when curl can be told
to use a dedicated DNS server, and test 2102 is the first to require
this.

Requires c-ares 1.26.0 or later.

Closes #17134
This commit is contained in:
Daniel Stenberg 2025-04-22 14:51:49 +02:00
parent da33c1e349
commit e0ebc3ff13
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 335 additions and 11 deletions

View file

@ -476,6 +476,7 @@ Features testable here are:
- `NTLM`
- `NTLM_WB`
- `OpenSSL`
- `override-dns` - this build can use a "fake" DNS server
- `parsedate`
- `proxy`
- `PSL`

View file

@ -118,10 +118,42 @@ SPDX-License-Identifier: curl
The HTTP server supports listening on a Unix domain socket, the default
location is 'http.sock'.
For HTTP/2 and HTTP/3 testing an installed `nghttpx` is used. HTTP/3
tests check if nghttpx supports the protocol. To override the nghttpx
used, set the environment variable `NGHTTPX`. The default can also be
changed by specifying `--with-test-nghttpx=<path>` as argument to `configure`.
For HTTP/2 and HTTP/3 testing an installed `nghttpx` is used. HTTP/3 tests
check if nghttpx supports the protocol. To override the nghttpx used, set
the environment variable `NGHTTPX`. The default can also be changed by
specifying `--with-test-nghttpx=<path>` as argument to `configure`.
### DNS server
There is a test DNS server to allow tests to resolve hostnames to verify
those code paths. This server is started like all the other servers within
the `<servers>` section.
To make a curl build actually use the test DNS server requires a debug
build. When such a test runs, the environment variable `CURL_DNS_SERVER` is
set to identify the IP address and port number of the DNS server to use.
- curl built to use c-ares for resolving automatically asks that server for
host information
- curl built to use `getaddrinfo()` for resolving *and* is built with c-ares
1.26.0 or later, gets a special work-around. In such builds, when the
environment variable is set, curl instead invokes a getaddrinfo wrapper
that emulates the function and acknowledges the DNS server environment
variable. This way, the getaddrinfo-using code paths in curl are verified,
and yet the custom responses from the test DNS server are used.
curl that is built to support a custom DNS server in a test gets the
`override-dns` feature set.
When curl ask for HTTPS-RR, c-ares is always used and in debug builds such
asks respects the dns server environment variable as well.
The test DNS server only has a few limited responses. When asked for
- type `A` response, it returns the address `127.0.0.1` three times
- type `AAAA` response, it returns the address `::1` three times
- other types, it returns a blank response without answers
### Shell startup scripts

View file

@ -33,8 +33,7 @@ http
dns
</server>
<features>
Debug
c-ares
override-dns
</features>
<name>
HTTP GET with host name