]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Linklocal and sitelocal IPv6 changes
authorDanny Mayer <mayer@ntp.org>
Tue, 3 Aug 2004 22:39:54 +0000 (18:39 -0400)
committerDanny Mayer <mayer@ntp.org>
Tue, 3 Aug 2004 22:39:54 +0000 (18:39 -0400)
bk: 4110143a5aChWTXofaAoosF3PotKqw

include/ntp_rfc2553.h
ntpd/ntp_io.c

index ede8054e959e89bd5eb97f35212b22cda519c4ed..797992e71dbdf4cf706ef53f5eecc74f5b343fcd 100644 (file)
@@ -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 */
index 511dab85234c6c19348e7c29274441ed5d94fab3..8353db0f4869e9c9dd9efe8b725b8a3f5baa5856 100644 (file)
@@ -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);