Skip to content

[th/curl-resolve-list] connectivity: fix constructing hosts list for CURLOPT_RESOLVE

Thomas Haller requested to merge th/curl-resolve-list into main

Curl's CURLOPT_RESOLVE expects one list entry per host. That documentation ([1]) also makes that clear that the form is "[+]HOST:PORT:ADDRESS[,ADDRESS]".

The way we constructed the list, only the last entry was honored:

  <trace> [1647551393.5362] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:18.159.254.57' to curl resolve list
  <trace> [1647551393.5363] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:152.19.134.142' to curl resolve list
  <trace> [1647551393.5363] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:18.192.40.85' to curl resolve list
  ...
  <trace> [1647551393.5366] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:85.236.55.6' to curl resolve list
  <trace> [1647551393.5366] connectivity: (eth0,IPv4,25) adding 'fedoraproject.org:80:38.145.60.20' to curl resolve list
  ...
  <trace> [1647551393.5415] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:18.159.254.57 to DNS cache\012
  <trace> [1647551393.5416] connectivity: (eth0,IPv4,25) libcurl: == Info: RESOLVE fedoraproject.org:80 is - old addresses discarded!\012
  <trace> [1647551393.5416] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:152.19.134.142 to DNS cache\012
  <trace> [1647551393.5417] connectivity: (eth0,IPv4,25) libcurl: == Info: RESOLVE fedoraproject.org:80 is - old addresses discarded!\012
  ...
  <trace> [1647551393.5422] connectivity: (eth0,IPv4,25) libcurl: == Info: RESOLVE fedoraproject.org:80 is - old addresses discarded!\012
  <trace> [1647551393.5423] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:38.145.60.20 to DNS cache\012
  <trace> [1647551393.5424] connectivity: (eth0,IPv4,25) libcurl: == Info: Hostname fedoraproject.org was found in DNS cache\012
  <trace> [1647551393.5424] connectivity: (eth0,IPv4,25) libcurl: == Info:   Trying 38.145.60.20:80...\012

There are two possible fixes. Either join all addresses in one entry, or use the '+' modifier. Do the former.

Now we get:

<trace> [1647551967.0378] connectivity: (eth0,IPv4,25) set curl resolve list to 'fedoraproject.org:80:38.145.60.21,152.19.134.142,152.19.1...
...
<trace> [1647551967.0559] connectivity: (eth0,IPv4,25) libcurl: == Info: Added fedoraproject.org:80:38.145.60.21,152.19.134.142,152.19.134.198,18.192.40.85,185.141.165.254,18.159.254.57,1>
<trace> [1647551967.0560] connectivity: (eth0,IPv4,25) libcurl: == Info: Hostname fedoraproject.org was found in DNS cache\012
<trace> [1647551967.0561] connectivity: (eth0,IPv4,25) libcurl: == Info:   Trying 38.145.60.21:80...\012

[1] https://curl.se/libcurl/c/CURLOPT_RESOLVE.html

Reported-by: @hadess

Fixes: 2cec94ba ('connectivity: use systemd-resolved for resolving the check endpoint')


See-also: #648 (comment 1301596)

Only merge after !1151 (merged)

Merge request reports