Ticket #331 (closed defect: fixed)
avahi on Linux uses incorrect address for P-t-P interface
|Reported by:||metamatt||Owned by:||lennart|
I sent a less knowledgeable question about avahi-daemon and point-to-point links a few days ago, http://lists.freedesktop.org/archives/avahi/2011-January/001969.html. When I didn't get a response to this, I decided to build avahi from source and step through it and see how it builds its list of interfaces and their addresses.
This is in iface-linux.c, netlink_callback(). It looks for a RTM_NEWADDR message, then extracts the payload of type IFA_ADDRESS.
Short story: I think it should be using the payload of type IFA_LOCAL, not the payload of type IFA_ADDRESS.
In the VM where I was running these experiments, there are 3 interfaces -- lo, eth0 and tun0. I printed out the IFA_ADDRESS and IFA_LOCAL for all 3 of these; for lo and eth0 these are the same address; for tun0 (IFF_POINTOPOINT), IFA_ADDRESS is the remote end and IFA_LOCAL is the local end.
I'm no expert on Linux rtnetlink or these IFA fields, but quoting /usr/include/linux/if_addr.h:
- Important comment:
- IFA_ADDRESS is prefix address, rather than local interface address.
- It makes no difference for normally configured broadcast interfaces,
- but for point-to-point IFA_ADDRESS is DESTINATION address,
- local address is supplied in IFA_LOCAL attribute. */
See also this stackoverflow question/answer: http://stackoverflow.com/questions/4678637/what-is-difference-between-ifa-local-and-ifa-address-in-rtnetlink-linux
Does anyone know why avahi is looking for IFA_ADDRESS here, and whether there's any reason not to use IFA_LOCAL instead?
Assuming there's not a specific reason to use IFA_ADDRESS here, I propose the patch attached at the end of this message, which works for me. (The bug this fixes is described in the earlier message linked above -- avahi chooses the wrong address to associate with the P-t-P interface, and if you enable avahi's reflector, avahi tries to call sendmsg() using that as the source address and the kernel always, correctly, fails the sendmsg() call with EINVAL.)
(And when/why this changed -- I was able to use avahi over P-t-P interfaces on Linux several years ago; I don't know what avahi version I was using at the time.)