cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Workaround for missing ares_getaddrinfo() with IPv4 and IPv6

From: Tommie Gannert <tommie_at_spotify.com>
Date: Wed, 08 Dec 2010 14:42:30 +0100

Daniel Stenberg wrote:
> On Mon, 6 Dec 2010, Tommie Gannert wrote:
>
>> this is a patch to let hostares.c request both IPv4 and IPv6
>> addresses when IPv6 is enabled.
>
> Can I ask you to instead make a local function in there called
> _ares_getaddrinfo() or something that would have an API that might
> match what an _actual_ ares_getaddrinfo() would use?
>
> That would make a much cleaner step towards having c-ares itself
> provide the function and once it does it'll be easier to adapt our
> code to that.
Sure. I'd like to avoid calling it GAI because that interface would be a
pain to fulfill, but something simplified should be possible.

>> Currently, c-ares returns IPv4 address when there are no IPv6
>> addresses, and in those cases the Curl DNS cache will contain
>> duplicate addresses.
>
> It returns IPv4 even when you specify family PF_INET6? Isn't that a bug?
It's a deliberate fallback mechanism (in
ares_gethostbyname.c:host_callback()):

status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL);
if (status == ARES_ENODATA || status == ARES_EBADRESP) {
/* The query returned something but either there were no AAAA records
(e.g. just CNAME)
or the response was malformed. Try looking up A instead.
We should possibly limit this attempt-next logic to AF_UNSPEC lookups
only. */

and

/* The AAAA query yielded no useful result. Now look up an A instead.
We should possibly limit this attempt-next logic to AF_UNSPEC lookups
only. */
hquery->sent_family = AF_INET;
ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback,
hquery);

I'm for limiting the fallback to AF_UNSPEC, but this is the code now.

>
>> There are no ordering guarantees on which address family comes first
>> in the DNS cache. Is that needed?
>
> The DNS cache stores the adresses as Curl_addrinfo structs which
> should have the addresses in the same order as the name resolver
> returned them and that's how it is supposed to work.
>
> The name resolver is in fact supposed to return the names in preferred
> order, but that's a job for c-ares really.
Agreed. The problem is I'm running both gethostbyname(INET|INET6) in
parallel, so which one
comes first is unspecified, and then the addrinfo structs are simply
appended.

It's definitely a solvable problem, but adds code that may not be all
that useful.

-- 
Tommie

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

Received on 2010-12-08