troglobit / mdnsd

Jeremie Miller's original mdnsd
BSD 3-Clause "New" or "Revised" License
56 stars 35 forks source link

IP address selection and operation while no address #16

Closed troglobit closed 6 years ago

troglobit commented 6 years ago

As reported by @thom-nic in https://github.com/troglobit/mdnsd/issues/14#issuecomment-413626567, mdnsd picks the first address returned by getaddrinfo() and happily runs even when the (any) interface still hasn't got a valid address.

As @thom-nic points out, announcing mDNS records with address 0.0.0.0 is not ideal since it'll take the TTL before they expire.

  1. When starting up we should handle the "no address yet" case by deferring our transmitting any records (we can enter the main loop and receive packets, but not send)
  2. When we get an address we should not just accept the first non-zero address, but ask for more until we get "the best" address (a future version of mdnsd would need to announce more records I think, at least for both IPv4 and IPv6)
  3. If we lose our address at runtime, and don't have any other valid address, we should revoke our records and goto 1.
thom-nic commented 6 years ago

From #14:

The address selection criteria you propose seem obvious, i.e. prefer a global address over link-local. Possibly there is a way to announce all (IPv4) addresses, but I don't know yet.

I think you can add multiple A-records (same name, one for each address) to a DNS query response. I was thinking they could be weighted but that's only for MX. One would hope the recipient OS will pick the one which it can route to. Seems like it would be easy to test in any case.

troglobit commented 6 years ago

Aha, that's really useful info thanks!

troglobit commented 6 years ago

There's a possible fix on the improve-a-record-support .. slightly misrepresentative branch name, but there are two fixes relevant to your case. Hopefully 06c0df8 does at least the bare minimum of what you need.

I haven't merged it to master yet because I wanted to give you a chance to review it first. Please let me know if it's to your liking.

thom-nic commented 6 years ago

Fantastic, I'll give it a try in the morning and update once I do. Thanks!

thom-nic commented 6 years ago

I've been playing around with this all morning - 06c0df8 looks good! I get a global address when I'm on a DHCP network and I can hotplug the ethernet between link-local and DHCP LAN, meanwhile mdnsd handles the network changes gracefully without restarting or poking the process. Brilliant! 🎉

troglobit commented 6 years ago

Great news, thank you so much for testing this! :heart:

Then I can proceed to merge and prepare the last steps of the v0.8 release :smiley:

troglobit commented 6 years ago

@thom-nic An official v0.8 is released now. Thank you for all your invaluable help and encouraging conversation! :smiley: