cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Re: [libcurl 7.24.0] AAAA DNS query with --disable-ipv6

From: Jongman Heo <jongman.heo_at_samsung.com>
Date: Mon, 03 Dec 2012 05:15:35 +0000 (GMT)

------- Original Message -------
Sender : Daniel Stenberg<daniel_at_haxx.se>
Date : 2012-12-02 23:49 (GMT+09:00)
Title : Re: [libcurl 7.24.0] AAAA DNS query with --disable-ipv6

On Fri, 30 Nov 2012, Jongman Heo wrote:

> I had used libcurl 7.18.2, with following flags;

...

> I upgrade the libcurl package to 7.24.0, with following flags;

> So, c-ares has been replaced with threaded-resolver. For both, disable-ipv6
> is specified.

That is probably a significant change...

> With 7.18.2, I couldn't see IPv6 DNS query (AAAA). But with 7.24.0, there
> exist AAAA DNS query. Is this expected behavior with 7.24.0 and
> threaded-resolver though --disable-ipv6 is specified?

No. I wouldn't say it is expected but it rather surprises me.

I looked into the code just now and for this case, Curl_ipv4_resolve_r() gets
called internally in the resolver thread and it uses Curl_getaddrinfo_ex() if
configure found getaddrinfo() to exist and be thread-safe. But it then only
asks for PF_INET addresses which implies that IPv6 addresses are not
interesting.

If you can debug this and verify that this is the case then we'd have to
figure out next why the libc function does what it does...

> Should I use CURL_IPRESOLVE_V4 option explicitly ?

Sure you can do that, but in this particular case I'm not sure it makes any
difference as the code already assumes IPv4-only... Did you try and see any
difference?

-- 
  / daniel.haxx.se
===============================================================================
Hi, Daniel,
I tried, but CURL_IPRESOLVE_V4 doesn't help.
As I already stated, I have a --disable-ipv6 --enable-threaded-resolver flag.
I put some debug messages and now know where the problem comes.
In lib/asyn-thread.c,
Curl_resolver_getaddrinfo(...)
{
 ...
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = pf;                                // Here, ai_family is AF_INET (2), as I expected...
  hints.ai_socktype = conn->socktype;
...
  /* fire up a new resolver thread! */
  if(init_resolve_thread(conn, hostname, port, &hints)) {
    *waitp = 1; /* expect asynchronous response */
    return NULL;
  }
...
}
init_resolve_thread() above calls init_thread_sync_data() internally but init_thread_sync_data() does not sync tsd->hints if CURLRES_IPV6 is not defined (which is my case). So, tsd->hints remains NULL. So, it seems that default AF_UNSPEC is used.
I didn't expect AF_UNSPEC might be used though I specified --disable-ipv6. 
In my environment, I should not issue IPv6 AAAA DNS query due to some environmental problem. 
Could you give me a hint how to disable IPv6 thing entirely if --disable-ipv6 is not enough?
Following change solves issue for me, but I'm not sure it is appropriate and don't know its side effect.
 static
 int init_thread_sync_data()
 {
   memset(tsd, 0, sizeof(*tsd));
   tsd->port = port;
 #ifdef CURLRES_IPV6
   DEBUGASSERT(hints);
   tsd->hints = *hints;
 #else
   (void) hints;
+  tsd->hints = *hints; // Adding this line makes getaddrinfo() use AF_INET...
 #endif
Best regards,
Jongman Heo.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2012-12-03