Fixing nss-mdns for IPv6 linklocal scoped addresses on FreeBSD 8 / 9
FreeBSD 8.2-RELEASE with
Update: still works on
nss_mdns is a port of nss-mdns for FreeBSD. It adds support for mDNS address resolution system-wide through the use of a name service switch plugin. Here is the simplest configuration:
- install avahi (mDNS implementation) and nss-mdns using ports
# cd /usr/ports/net/avahi # make install # cd /usr/ports/dns/nss_mdns # make install
and make appropriate configuration changes
hosts: files mdns dns
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.
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. (cf. ping6.c:966
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
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
git diffon branch
release-0.10(not needed if you use the port)
- patch-src_AAA-nss-mdns-linklocal.diff 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
deinstallbefore if needed)
- copy this file in
- FreeBSD 8.2
- IPv6 on FreeBSD
- nss_mdns port
- ping6 source code
- Installing avahi on FreeBSD
- Local Patches and Ports