From: Danny Mayer Date: Tue, 3 Aug 2004 22:39:54 +0000 (-0400) Subject: Linklocal and sitelocal IPv6 changes X-Git-Tag: NTP_4_2_3~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3f99fdec990eb38f9d8d2d70f99d50c674cded42;p=thirdparty%2Fntp.git Linklocal and sitelocal IPv6 changes bk: 4110143a5aChWTXofaAoosF3PotKqw --- diff --git a/include/ntp_rfc2553.h b/include/ntp_rfc2553.h index ede8054e95..797992e71d 100644 --- a/include/ntp_rfc2553.h +++ b/include/ntp_rfc2553.h @@ -208,6 +208,20 @@ struct sockaddr_in6 { #ifndef IN6_IS_ADDR_MULTICAST #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) #endif +/* + * Unicast link / site local. + */ +#ifndef IN6_IS_ADDR_LINKLOCAL +#define IN6_IS_ADDR_LINKLOCAL(a) (\ +(*((u_long *)((a)->s6_addr) ) == 0xfe) && \ +((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0x80)) +#endif + +#ifndef IN6_IS_ADDR_SITELOCAL +#define IN6_IS_ADDR_SITELOCAL(a) (\ +(*((u_long *)((a)->s6_addr) ) == 0xfe) && \ +((*((u_long *)((a)->s6_addr) + 1) & 0xc0) == 0xc0)) +#endif struct addrinfo { int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 511dab8523..8353db0f48 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -2018,6 +2018,11 @@ findinterface( */ for (i= nwilds; i < ninterfaces; i++) { + /* + * Skip the loopback. It can't act as an outgoing interface + */ + if (inter_list[i].flags & INT_LOOPBACK) + continue; /* * For IPv4 we can check the network mask to see if * we have a match on the outgoing interface @@ -2031,6 +2036,19 @@ findinterface( if (amask == imask) return (&inter_list[i]); } + + /* + * See if the IPv6 address is Link-Local or Site Local + */ + if (addr->ss_family == AF_INET6) { + if (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6*)addr)->sin6_addr) && + IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6*)&inter_list[i].sin)->sin6_addr)) + return (&inter_list[i]); + + if (IN6_IS_ADDR_SITELOCAL(&((struct sockaddr_in6*)addr)->sin6_addr) && + IN6_IS_ADDR_SITELOCAL(&((struct sockaddr_in6*)&inter_list[i].sin)->sin6_addr)) + return (&inter_list[i]); + } } saddrlen = SOCKLEN(addr);