DISCLAIMER: I have pretty limited knowledge of network management,
avahi/zeroconf/Bonjour/mdns/dns-sd
usage, and even less so about networking code, on Haiku or elsewhere, so… expect mistakes ahead
Hello folks.
Yesterday I tried porting mDNSResponder
(Apple’s “Bonjour”) into Haiku, and after much cursing and sweating (I suck at this)… managed to get parts of it working. And even if the work is by no means complete, I thought that maybe some of you might find it interesting enough.
Also… I better write down what I managed to understand, before I forget it all.
This post is kinda too long… if you’re already familiar with zeroconf/avahi/bonjour… you might want to just jump to the screenshots.
What’s this “Bonjour” thing?
To put it in simple terms… “Bonjour” allows computers in a local network to find each other, without the need to know their IP addresses. Specially useful, if your network uses dynamic IP addresses, and/or to connect to “headless” computers.
For that to work each computer has to be able to (again, I’m simplifying a lot):
- “Advertise” any services it provides (think… sshd, ftp, barrier/synapse, etc).
- Be able to “resolve” hostnames into the actual IP addresses (as DNS do for the rest of the internet).
(If there was no DHCP server on the network… the machines would also need to have working Link-Local addressing… not sure if Haiku supports that, BTW).
The Apple’s Bonjour project provides fairly portable source code (at least on its “posix” form) for the first of the items above, and Linux specific code for the second (as far as I managed to understand it). It also provides Windows and MacOS specific code for both, and more, but we don’t care about all that.
It consists of:
- An mDNSResponder, a.k.a.: multicast-dns daemon/server (
/bin/mdnsd
).
you “register” services to this daemon, and it “advertise” them on the network, so other machines can find them. - A
/bin/dns-sd
CLI util that lets you interact with the above server. You can browse for services, or use it to register services, among other things. - Some “stand-alone” utilities, aimed at use in embedded, or otherwise more constrained, systems.
Useful during testing, too!
For the “other part” (the hostname->IP address resolution), we need something more integrated with the networking stack of the OS.
On Linux it seems that this is accomplished via a “plugin” module system, that lets you alter how that resolution is performed.
The mechanism, seems to be Name Service Switch, which allows you to “hook” different modules/libraries via dlopen()
. Apple’s Bonjour provides libnss_mdns-0.2.so
for Linux.
On Haiku… the host name resolution is handled (AFAICT), by libnetwork.so
, with some code for “netresolv” coming from NetBSD, and as it seems to me that it supports a similar mechanism to load modules (eg: libnss_mdnsd.so.0
in our case)…
I went ahead and stole NetBSD’s nss_mdnsd.c file, and “shoe-horned” it into Apple’s Bonjour makefiles (replacing the Linux code, without looking much into it after it gave its first compile-error).
So… what works?
All builds relatively fine, after some minor patching (had to disable IPv6, and code related to detection of network interfaces changes). Mind you… I barely know what I’m doing, so expect the patch to look… less than ideal
All the utilities seem to work well enough. No crashes or KDLs at least
The “advertise services” part of the equation seems functional enough… I was able to connect to my Haiku machines via ssh from Linux and Win10, using the hostname instead of IPs: ssh OscarL@A760G.local
.
What I didn’t manage to get working was being able to resolve “.local” hostnames from within Haiku.
Not even sure if that libnss_mdns.so
module is being loaded at all, if it fails to talk to the running mdnd
server, or where the problem might actually be.
“Pics, or didn’t happen”
First screenshot shows:
- Connecting a Haiku PC (hostname: A760G), via ssh, to a Linux netbook (hostname: exo-x355), using IP address.
- Attempting to connect back via ssh to the Haiku PC, using hostname. Failed.
- Using
dns-sd
to browse for machines advertising ssh services. Shows the one running Haiku (A760G), and two netbooks running Linux (exo-x355, suma-c10). This is on Linux side, mind you. - Successful ssh connection to Haiku, using
ssh <user>@<hostname>.local
(instead of the IP).
Second screenshot shows Bonjour Browser running on Windows 10, showing the ssh
service from Haiku, with a custom message
This was accomplished by using the /bin/mDNSResponderPosix
, for simplicity, as it makes it easy to test advertising a single service via the command line. I have yet to learn how /bin/mdnsd
config files work
Issues:
When running Haiku on a VM (VBox), only the host OS was able to resolve the “A760G.local” hostname, other machines on the network… saw nothing.
When running the same Haiku install on bare-metal… I did managed to see “A760G.local” from all the machines eventually… but seemingly, only one at a time? LOL! Might be due to the use of /bin/mDNSResponderPosix
, though. We’ll see when I get to properly configure services for /bin/mdnsd
.
Final words.
All in all, not a bad outcome for a day’s work… the difficult part was actually learning about all this, and working around my limited skills. At least I’ll be able to connect to my Haiku’s installs by hostname from now on
I plan to do some patch clean up, and push my changes back to github, later on today/tomorrow. Will update this post/thread with the link to that when its ready.
I’ll start to work on a HaikuPorts .recipe
as well, and maybe even provide an mdnsresponder-0.0.0-1.hpkg
package to play with.
It also might be worth to see if NetBSD’s version of mDNSResponder can be used as “upstream” instead of Apple’s repo?
Regarding the libnetwork.so
/ /etc/nssswitch.conf
/ libnss_mdnsd.so
thing… being able to browse “Bonjour” FROM Haiku… we will a proper developer to look at it (or at least an aspiring one, with better skills than mine… it can’t be too hard to find such person )
Thanks for reading.