socket.getaddrinfo: flags |= AI_ADDRCONFIG

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karl Chen

    socket.getaddrinfo: flags |= AI_ADDRCONFIG


    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_getaddri nfo, 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.getaddri nfo 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
  • =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

    #2
    Re: socket.getaddri nfo: flags |= AI_ADDRCONFIG

    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.getaddri nfo 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

    Comment

    Working...