Fixing nss-mdns for IPv6 linklocal scoped addresses
Running FreeBSD 8.2-RELEASE with GENERIC kernel.
# cd /usr/ports/net/avahi # make install # cd /usr/ports/dns/nss_mdns # make install
and make appropriate configuration changes
- in /etc/rc.conf
- in /etc/nsswitch.conf
hosts: files dns mdns
IPv6 is configured on all interfaces and no global prefix is defined. We only have linklocal addresses. mDNS resolution works fine, but ping6 fails miserably, even when specifying the outgoing interface.
bsd1# RES_OPTIONS=inet6 getent hosts bsd2.local fe80::a00:27ff:fef4:c55d bsd2.local bsd1# ping6 bsd2.local ping6: UDP connect: Device not configured bsd1# ping6 -I em0 bsd2.local ping6: UDP connect: Device not configured
This is not a routing problem, we would have Network is unreachable in this case, but an interface / scope id problem.
Even option -I in ping6 would not change anything. And when tracing down the scope id used, it turned out to be 673273636! Obviously, there is no such device configured.
The problem is in bsdnss.c where the address is copied in sin6_addr with a way to long length, ai->ai_addrlen, where it should be sizeof(struct in6_addr).
The quick fix and dirty enhancement
With this fixed, no more device not configured, but still a network unreachable. Although, using ping6 -I works nicely now. But it would be great to have the scope id filled in the data structure, which is possible at low cost, since Avahi returns this information, the second field in the reply below.
bsd1# nc -U /var/run/avahi-daemon/socket RESOLVE-HOSTNAME-IPV6 bsd2.local + 2 1 bsd2.local fe80::a00:27ff:fef4:c55d
A simple and dirty patch in query.h to add the scope_id to the data structure (we can do that safely, even if it is very ugly, because the buffer mallocated at nss.c:307 is huge), avahi.c to fill this info, and bsdnss.c to fill the struct sockaddr_in6 when we have a linklocal address, and that's it. Things work nicely now:
# ping6 bsd2.local PING6(56=40+8+8 bytes) fe80::a00:27ff:fe9d:5a8f%em1 --> fe80::a00:27ff:fef4:c55d%em1 16 bytes from fe80::a00:27ff:fef4:c55d%em1, icmp_seq=0 hlim=64 time=0.329 ms 16 bytes from fe80::a00:27ff:fef4:c55d%em1, icmp_seq=1 hlim=64 time=0.657 ms ^C --- bsd2.local ping6 statistics --- 2 packets transmitted, 2 packets received, 0.0% packet loss round-trip min/avg/max/std-dev = 0.329/0.493/0.657/0.164 ms
This fix and enhancement were made only for the FreeBSD port, based on release-0.10.
- [ git diff patch file] on branch release-0.10 (not needed if you use the port)
- patch-src_AAA-nss-mdns-linklocal.c patch file for the FreeBSD port: this patch was made so that it can be applied before the port patches without problems (hence the stupid name)
- copy this file in /usr/ports/dns/nss_mdns/files
- make install (deinstall before if needed)