summaryrefslogtreecommitdiff
path: root/lib/asyn-ares.c
diff options
context:
space:
mode:
authorDmitry Karpov <dkarpov@roku.com>2021-06-03 23:56:37 +0200
committerDaniel Stenberg <daniel@haxx.se>2021-06-05 23:41:21 +0200
commit4bd20889fc3803b42647eaa4902e5257c508b363 (patch)
tree30cfcc0824396f635a6901d130d1150f26e06fdd /lib/asyn-ares.c
parent0a513555561d8ee4c1de930996ecc0cf73154378 (diff)
downloadcurl-4bd20889fc3803b42647eaa4902e5257c508b363.tar.gz
ares: always store IPv6 addresses first
Trying dual-stack on some embedded platform, I noticed that quite frequently (20%) libCurl starts from IPv4 regardless the Happy Eyeballs timeout value. After debugging this issue, I noticed that this happens if c-ares resolver response for IPv6 family comes before IPv4 (which was randomly happening in my tests). In such cases, because libCurl puts the last resolver response on top of the address list, when IPv4 resolver response comes after IPv6 one - the IPv4 family starts the connection phase instead of IPv6 family. The solution for this issue is to always put IPv6 addresses on top of the address list, regardless the order of resolver responses. Bug: https://curl.se/mail/lib-2021-06/0003.html Closes #7188
Diffstat (limited to 'lib/asyn-ares.c')
-rw-r--r--lib/asyn-ares.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c
index 782784735..9ee307beb 100644
--- a/lib/asyn-ares.c
+++ b/lib/asyn-ares.c
@@ -493,17 +493,31 @@ CURLcode Curl_resolver_wait_resolv(struct Curl_easy *data,
static void compound_results(struct thread_data *res,
struct Curl_addrinfo *ai)
{
- struct Curl_addrinfo *ai_tail;
if(!ai)
return;
- ai_tail = ai;
- while(ai_tail->ai_next)
- ai_tail = ai_tail->ai_next;
+#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
+ if(res->temp_ai && res->temp_ai->ai_family == PF_INET6) {
+ /* We have results already, put the new IPv6 entries at the head of the
+ list. */
+ struct Curl_addrinfo *temp_ai_tail = res->temp_ai;
- /* Add the new results to the list of old results. */
- ai_tail->ai_next = res->temp_ai;
- res->temp_ai = ai;
+ while(temp_ai_tail->ai_next)
+ temp_ai_tail = temp_ai_tail->ai_next;
+
+ temp_ai_tail->ai_next = ai;
+ }
+ else
+#endif /* CURLRES_IPV6 */
+ {
+ /* Add the new results to the list of old results. */
+ struct Curl_addrinfo *ai_tail = ai;
+ while(ai_tail->ai_next)
+ ai_tail = ai_tail->ai_next;
+
+ ai_tail->ai_next = res->temp_ai;
+ res->temp_ai = ai;
+ }
}
/*