mirage / ocaml-dns

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

dns-client: if /etc/resolv.conf modifies, update the internal list of resolvers #291

Closed hannesm closed 2 years ago

hannesm commented 2 years ago

Only affects lwt and unix. Previously, when you started an application, /etc/resolv.conf was read once at startup. When you switch to a different network, and /etc/resolv.conf is updated by DHCP, this is not reflected in the dns-client.

Now, the digest of /etc/resolv.conf is stored internally, and if it changes, it is parsed again. The lwt implementation needed to be modified slightly since connect_to_ns_via_tcp carried a nameserver list, and a different task may have been woken up. Now, there are two functions and it should play out nicely.

//cc @reynir addresses #243

haesbaert commented 2 years ago

Wouldn't it make more sense to just look at mtime on /etc/resolv.conf instead of constantly calculating digests ? Or did I miss something ?

reynir commented 2 years ago

Wouldn't it make more sense to just look at mtime on /etc/resolv.conf instead of constantly calculating digests ? Or did I miss something ?

@haesbaert we discussed this on IRC and most of it is summarized in #296. Note that the lwt implementation will reuse the connection if possible and "only" re-read resolv.conf when reconnecting.

haesbaert commented 2 years ago

Wouldn't it make more sense to just look at mtime on /etc/resolv.conf instead of constantly calculating digests ? Or did I miss something ?

@haesbaert we discussed this on IRC and most of it is summarized in #296. Note that the lwt implementation will reuse the connection if possible and "only" re-read resolv.conf when reconnecting.

Ack, sorry for the noise :D

reynir commented 2 years ago

I made a pull request to this pull request https://github.com/hannesm/ocaml-dns/pull/1 where I implement the behavior I mentioned earlier.