mirage / ocaml-dns

OCaml implementation of the DNS protocol
BSD 2-Clause "Simplified" License
105 stars 43 forks source link

Client does not special-case `localhost`, `ip6-localhost`, `ip6-loopback` #220

Closed cfcs closed 4 years ago

cfcs commented 4 years ago

On Debian the default /etc/hosts file ships with:

127.0.0.1   localhost
::1     localhost ip6-localhost ip6-loopback
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

It appears users are confused by dns-client trying to resolve at least localhost upstream. We should consider if we want to support at least localhost, and perhaps the others. Which then begs the question of whether we should have a /etc/hosts-equivalent in the library that users are able to override, e.g. this could be part of the S.create API.

Where to put it: Intuitively I'd say the cache would seem like a good place?

For anecdotal real-world evidence of this being confusing to users: https://github.com/roburio/openvpn/issues/28

cfcs commented 4 years ago

On fedora it's

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 
hannesm commented 4 years ago

I'd not go with "debian's /etc/hosts", but instead use good old RFCs. In https://github.com/mirage/ocaml-dns/blob/v4.4.0/resolver/dns_resolver_root.ml#L37 we already have a list with references to RFCs of top-level domain names and networks that are not supposed to (a) leave the local host (b) leave the link-local scope (c) leave the private network. I'd suggest we revise this list to separate it into these cases more clearly, and then reuse this in the dns-client.

cfcs commented 4 years ago

Wikipedia has a bunch of references to RFCs: https://en.wikipedia.org/wiki/Localhost

hannesm commented 4 years ago

@cfcs hmm, I think they're mostly out of date / link to obsolete RFCs. From the code comments:

Maybe relevant: