]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Fixed IPv6 multicast to use correct scope for interface
authorDanny Mayer <mayer@ntp.org>
Thu, 19 Aug 2004 22:33:09 +0000 (18:33 -0400)
committerDanny Mayer <mayer@ntp.org>
Thu, 19 Aug 2004 22:33:09 +0000 (18:33 -0400)
bk: 41252aa5d4DDggs1LTYCJeIr4FXCvg

ntpd/ntp_io.c

index 7c926b4c5addd8fdf430258877eea31514c30812..d210f3e1acbcd856e9a6b7af54ba93326af60b22 100644 (file)
@@ -738,15 +738,15 @@ socket_multicast_enable(struct interface *iface, int ind, struct sockaddr_storag
 
                /*
                 * Enable reception of multicast packets
-                * If the address is link-local we can get the interface index
+                * If the local address is link-local we can get the interface index
                 * from the scope id. Don't do this for other types of multicast
                 * addresses. For now let the kernel figure it out.
                 */
                iaddr6 = ((struct sockaddr_in6*)maddr)->sin6_addr;
                mreq6.ipv6mr_multiaddr = iaddr6;
 #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
-               if (IN6_IS_ADDR_LINKLOCAL(&iaddr6))
-                       mreq6.ipv6mr_interface = ((struct sockaddr_in6*)maddr)->sin6_scope_id;
+               if (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6*)&iface->sin)->sin6_addr))
+                       mreq6.ipv6mr_interface = iface->scopeid;
                else
 #endif
                        mreq6.ipv6mr_interface = 0;
@@ -978,8 +978,16 @@ io_multicast_add(
        jstatus = socket_multicast_enable(&inter_list[ind], ind, &addr);
 
 #ifdef DEBUG
-       if (debug)
-               printf("io_multicast_add %s\n", stoa(&addr));
+       if (debug) {
+               if (jstatus == ISC_TRUE) {
+                       printf("io_multicast_add: Opened multicast client on interface %d, socket: %d\n",
+                       ind, inter_list[ind].fd);
+                       printf("io_multicast_add %s\n", stoa(&addr));
+               }
+               else
+                       printf("io_multicast_add: Unable to Open multicast client for address %s on interface %d\n",
+                       stoa(&addr), ind);
+       }
 #endif
 #else /* MCAST */
        netsyslog(LOG_ERR,
@@ -2287,25 +2295,29 @@ find_interface_index(
                 * See if the IPv6 address is Link-Local or Site Local
                 */
                if (addr->ss_family == AF_INET6 && inter_list[i].family == AF_INET6) {
-                       if (is_linklocal == ISC_TRUE &&
-                           IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6*)&inter_list[i].sin)->sin6_addr))
+                       if (is_sitelocal == ISC_TRUE &&
+                           IN6_IS_ADDR_SITELOCAL(&((struct sockaddr_in6*)&inter_list[i].sin)->sin6_addr))
                        {
 #ifdef DEBUG
                                if (debug > 2)
-                                   printf("Found Link-Local *cast interface %d for address: %s\n", i, stoa(addr));
+                                   printf("Found Site-Local *cast interface %d for address: %s\n", i, stoa(addr));
 #endif
                                return (i);
                        }
-
-                       if (is_sitelocal == ISC_TRUE &&
-                           IN6_IS_ADDR_SITELOCAL(&((struct sockaddr_in6*)&inter_list[i].sin)->sin6_addr))
+                       /*
+                        * We did the sitelocal test first to see if it exists
+                        * otherwise a sitelocal address can use the linklocal interface
+                        */
+                       if ((is_linklocal == ISC_TRUE  || is_sitelocal == ISC_TRUE) &&
+                           IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6*)&inter_list[i].sin)->sin6_addr))
                        {
 #ifdef DEBUG
                                if (debug > 2)
-                                   printf("Found Site-Local *cast interface %d for address: %s\n", i, stoa(addr));
+                                   printf("Found Link-Local *cast interface %d for address: %s\n", i, stoa(addr));
 #endif
                                return (i);
                        }
+
                }
        }