From: Dave Hart Date: Tue, 12 Oct 2010 14:27:43 +0000 (+0000) Subject: [Bug 1080] ntpd on ipv6 routers very chatty. X-Git-Tag: NTP_4_2_6P3_RC3~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c828abe2f7afa5ab548134139bd89ebf050fda39;p=thirdparty%2Fntp.git [Bug 1080] ntpd on ipv6 routers very chatty. bk: 4cb4705f0-7oLzY15vMPxO_B-xXLbw --- diff --git a/ChangeLog b/ChangeLog index bf01e325e..8d3310817 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ --- * [Bug 750] Non-existing device causes coredump with RIPE-NCC driver. +* [Bug 1080] ntpd on ipv6 routers very chatty. * [Bug 1567] Support Arbiter 1093C Satellite Clock on Windows. * [Bug 1643] Range-check the decoding of the RIPE-NCC status codes. * [Bug 1644] cvo.sh should use lsb_release to identify linux distros. diff --git a/configure.ac b/configure.ac index 5f57818f9..e1d14c2c6 100644 --- a/configure.ac +++ b/configure.ac @@ -462,29 +462,51 @@ case "$host" in AC_CHECK_FUNCS(getpassphrase) esac -AC_CHECK_HEADERS(arpa/nameser.h) -AC_CHECK_HEADERS(sys/socket.h) -AC_CHECK_HEADERS(net/if.h, [], [], -[#if HAVE_SYS_SOCKET_H +AC_CHECK_HEADERS([arpa/nameser.h]) +AC_CHECK_HEADERS([sys/socket.h]) +AC_CHECK_HEADERS([net/if.h], [], [], +[#ifdef HAVE_SYS_SOCKET_H #include #endif ]) -AC_CHECK_HEADERS(net/if6.h) -AC_CHECK_HEADERS(net/route.h, [], [], [ +AC_CHECK_HEADERS([net/if6.h]) +AC_CHECK_HEADERS([net/route.h], [], [], [ #include #include #include ]) -AC_CHECK_HEADERS(netinet/in_system.h netinet/in_systm.h) -AC_CHECK_HEADERS(netinet/in.h) -AC_CHECK_HEADERS(netinet/ip.h, [], [], +AC_CHECK_HEADERS([netinet/in_system.h netinet/in_systm.h netinet/in.h]) +AC_CHECK_HEADERS([net/if_var.h], [], [], [#if HAVE_SYS_TYPES_H #include #endif -#if HAVE_NETINET_IN_H +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_NET_IF_H +#include +#endif +]) +AC_CHECK_HEADERS([netinet/ip.h netinet/in_var.h], [], [], +[#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NET_IF_H +#include +#endif +#ifdef HAVE_NETINET_IN_H #include #endif -#if HAVE_NETINET_IN_SYSTM_H +#ifdef HAVE_NET_IF_VAR_H +#include +#endif +#ifdef HAVE_NETINET_IN_SYSTM_H #include #endif ]) diff --git a/include/ntp_net.h b/include/ntp_net.h index da2a22ab5..97e7805ea 100644 --- a/include/ntp_net.h +++ b/include/ntp_net.h @@ -9,9 +9,18 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_NET_IF_H +#include +#endif #ifdef HAVE_NETINET_IN_H #include #endif +#ifdef HAVE_NET_IF_VAR_H +#include +#endif +#ifdef HAVE_NETINET_IN_VAR_H +#include +#endif #include "ntp_rfc2553.h" diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index 7eaa9c0b6..366927a0f 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -193,6 +193,9 @@ static int is_wildcard_netaddr (const isc_netaddr_t *); * Multicast functions */ static isc_boolean_t addr_ismulticast (sockaddr_u *); +static isc_boolean_t is_anycast (sockaddr_u *, + const char *); + /* * Not all platforms support multicast */ @@ -1470,6 +1473,39 @@ set_wildcard_reuse( } #endif /* OS_NEEDS_REUSEADDR_FOR_IFADDRBIND */ + +static isc_boolean_t +is_anycast( + sockaddr_u *psau, + const char *name + ) +{ +#if defined(INCLUDE_IPV6_SUPPORT) && defined(SIOCGIFAFLAG_IN6) && \ + defined(IN6_IFF_ANYCAST) + struct in6_ifreq ifr6; + int fd; + u_int32_t flags6; + + if (psau->sa.sa_family != AF_INET6) + return ISC_FALSE; + if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + return ISC_FALSE; + memset(&ifr6, 0, sizeof(ifr6)); + memcpy(&ifr6.ifr_addr, &psau->sa6, sizeof(ifr6.ifr_addr)); + strncpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name)); + if (ioctl(fd, SIOCGIFAFLAG_IN6, &ifr6) < 0) { + close(fd); + return ISC_FALSE; + } + close(fd); + flags6 = ifr6.ifr_ifru.ifru_flags6; + if ((flags6 & IN6_IFF_ANYCAST) != 0) + return ISC_TRUE; +#endif /* INCLUDE_IPV6_SUPPORT && SIOCGIFAFLAG_IN6 && IN6_IFF_ANYCAST */ + return ISC_FALSE; +} + + /* * update_interface strategy * @@ -1592,6 +1628,9 @@ update_interfaces( if (is_wildcard_addr(&interface.sin)) continue; + if (is_anycast(&interface.sin, isc_if.name)) + continue; + /* * map to local *address* in order to map all duplicate * interfaces to an interface structure with the