socket.getaddrinfo: flags |= AI_ADDRCONFIG

K

Karl Chen

I've discovered that since glibc 2.3.2, getaddrinfo(3) supports a
useful flag called AI_ADDRCONFIG. It turns off AAAA lookups if
the machine isn't configured for IPv6 (and similarly for IPv4,
theoretically). This is especially important when behind gateways
whose DNS forwarder silently filter AAAA requests. Without
AI_ADDRCONFIG, every DNS request has to wait for 4 AAAA request
timeouts before it even attempts an A request.

Passing hints=NULL to getaddrinfo (the C function) means
hints->flags = AI_V4MAPPED | AI_ADDRCONFIG. I.e., not the same as
hints->hints->flags = 0. (Don't ask me why the default isn't 0, I
don't like this API either. It means if you wish to specify only
some hint parameters you have to carefully get the flags right.)

Python's socketmodule.c, especially socket_getaddrinfo, uses 0 as
the default flags. So AI_ADDRCONFIG is turned off by default.

I propose:
1) mimic glibc default behavior, i.e. if flags is unspecified or
None, treat it as the default value of AI_V4MAPPED |
AI_ADDRCONFIG).

Alternatively:
2) add these flags to callers of socket.getaddrinfo in various
standard libs, e.g. httplib.


(AI_V4MAPPED isn't as important since it only applies if you
explicitly choose AF_INET6, a conscious decision.)

Karl
 
M

Martin v. Löwis

1) mimic glibc default behavior, i.e. if flags is unspecified or
None, treat it as the default value of AI_V4MAPPED |
AI_ADDRCONFIG).

Unfortunately, that contradicts with RFC 3493, which says

# If hints is a null pointer, the behavior
# shall be as if it referred to a structure containing the value zero
# for the ai_flags, ai_socktype and ai_protocol fields, and AF_UNSPEC
# for the ai_family field.

Of course, we might chose to ignore that.
Alternatively:
2) add these flags to callers of socket.getaddrinfo in various
standard libs, e.g. httplib.

There is apparently a problem with this one, also: implementations
might define AI_ADDRCONFIG, but not implement it, but instead return
EAI_BADFLAGS. Not sure whether this is a real problem, though.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top