[getdns-api] comments/suggestions on DNS vs non-DNS (0.268)

Dan Winship dan.winship at gmail.com
Mon Feb 4 08:12:23 MST 2013


> One still-problematic part of the design is that not everything that
> seems like a query to the DNS is actually a DNS query.

Yeah. So one way to deal with this would be to split up the API:

  getdns_address() - replaces getaddrinfo(), uses both DNS and
    non-DNS sources

  getdns_hostname() - replaces getnameinfo(), uses both DNS and
    non-DNS sources

  getdns_service() - does DNS SRV lookups

  getdns() - does generic DNS lookups

Since getdns's response format is so generic, they could still all
take the same callback type.



getdns_address()

Takes an ASCII or UTF-8 hostname, or a stringified IP address, and
returns a list of IP addresses.

You want to allow UTF-8 because not all protocols use punycode. (Eg,
mDNS uses UTF-8 directly). From RFC 6055, section 4:

   Instead, conversion to A-label form, or any other special encoding
   required by a particular name-lookup protocol, should be done only by
   an entity that knows which protocol will be used (e.g., the DNS
   resolver, or getaddrinfo() upon deciding to pass the name to DNS),
   rather than by general applications that call protocol-independent
   name resolution APIs.

And you don't need to allow the escaped RFC 4343 form in
getdns_address(), because the sorts of names that would need to be
escaped like that wouldn't be valid A/AAAA records, right?


If the input is an IP address, it should just translate it and return
the binary form (as getaddrinfo() does); this is useful because it
means that if you have a string containing a "hostname" from the user,
or a URI, etc, you can just pass it to getaddrinfo() without needing
to check whether it's a name or an IP address, and it does the right thing.


Another thing that getaddrinfo() handles that getdns() doesn't is IPv6
scope ids (which is one of the reasons it works with sockaddrs rather
than in_addr/in6_addrs). If you pass "fe80::223:15ff:fe28:aaec%eth0"
to getaddrinfo(), it will translate "eth0" and return a sockaddr_in6
with the correct sin6_scope_id. And if you pass "foo.local", and it
resolves it to an IPv6 address via mDNS, it will return a sockaddr
that has the scope id corresponding to the interface that the mDNS
reply came back on. (In theory, anyway.) getdns_address() could
support this by returning sockaddrs like getaddinfo() does, or it
could do something else like including the scope_id of each address as
an extra field in the response. (Which would mean it could include the
scope/interface id for link-local IPv4 responses too, which might be
helpful.)

(getaddrinfo() also handles looking up service names in /etc/services
for you, but that's not actually very useful, because some platforms
have out-of-date /etc/services files, so it only works reliably for
really old protocols.)


Most people calling getdns_address() are going to just want the
address, not the full gory details of replies_tree/replies_full, so it
would be nice to save all that extra malloc'ing/freeing and just
return the equivalent of the "just_address_answers" part. There could
be an extension you could pass if you wanted to get the full response.
(I guess you might need more than just addresses if you're doing
DNSSEC too. So not exactly the current just_address_answers part, but
something like it.)



getdns_hostname()

I think when doing a PTR lookup, it's more common to start out with a
sockaddr/in_addr/in6_addr rather than a string, so getdns_hostname()
should take a binary address, like getnameinfo() does.

Paralleling the UTF-8/punycode discussion above, I guess this should
return names in whatever form is canonical for the protocol they came
from... punycode for DNS, UTF-8 for mDNS, etc. Or maybe return both a
canonical and a display name for each result (where the two would be
the same for mDNS, but for DNS, "canonical" would be punycode and
"display" would be UTF-8)?

As with getdns_address(), most callers only want the names, not the
full parsing details, so that should be the default.



getdns_service()

Another simplified form; does DNS SRV lookups and returns the
equivalent of the srv_addresses special case in the existing spec.
Maybe it should guarantee that it always includes the corresponding
IP addresses too? (That is, if the server response doesn't include
the A/AAAA records as additional responses, getdns_service() will
automatically do a second lookup and merge the results together.)



getdns()

Works basically as described in the existing spec, except probably
without the special just_address_answers and srv_addresses cases that
are now handled by getdns_address() / getdns_service().


More information about the getdns-api mailing list