From 28948f72a2689afe0ba8a31fd396a0c7faf7c213 Mon Sep 17 00:00:00 2001 From: Matt Ginzton Date: Tue, 8 Mar 2011 23:55:56 +0100 Subject: core: avahi on Linux uses incorrect address for P-t-P interface Hi, 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.) thanks, Matt --- avahi-core/iface-linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avahi-core/iface-linux.c b/avahi-core/iface-linux.c index 4d12f73..c1843dd 100644 --- a/avahi-core/iface-linux.c +++ b/avahi-core/iface-linux.c @@ -203,7 +203,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat while (RTA_OK(a, l)) { switch(a->rta_type) { - case IFA_ADDRESS: + case IFA_LOCAL: /* Fill in address data */ if ((raddr.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || -- cgit