]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Enable IPv6 multicast interface
authorDanny Mayer <mayer@ntp.org>
Mon, 1 Aug 2005 16:34:24 +0000 (12:34 -0400)
committerDanny Mayer <mayer@ntp.org>
Mon, 1 Aug 2005 16:34:24 +0000 (12:34 -0400)
bk: 42ee4f10q3KNQSiFluK9v-_fw-6BwA

include/ntpd.h
ntpd/ntp_io.c
ntpd/ntp_peer.c

index 4daa90d2852bcd3e1fa469149880bb0af1ac55c4..4aaee370685306ce113950bd0246d0923eb21706 100644 (file)
@@ -74,6 +74,7 @@ extern        void    ntp_intres      P((void));
 extern struct interface *findinterface P((struct sockaddr_storage *));
 extern  struct interface *findbcastinter P((struct sockaddr_storage *));
 extern  void   enable_broadcast P((struct interface *, struct sockaddr_storage *));
+extern  void   enable_multicast_if P((struct interface *, struct sockaddr_storage *));
 extern void    interface_dump   P((struct interface *));
 
 extern void    init_io         P((void));
index 5b4cc9716cc77ba2c54be9ad039a73f3b6bc2b6d..9abac786c2b992af1561abdb73c379ff9cf4db60 100644 (file)
@@ -161,6 +161,9 @@ static      char *  fdbits          P((int, fd_set *));
 static void    set_reuseaddr   P((int));
 static isc_boolean_t   socket_broadcast_enable  P((struct interface *, SOCKET, struct sockaddr_storage *));
 static isc_boolean_t   socket_broadcast_disable P((struct interface *, int, struct sockaddr_storage *));
+/*
+ * Multicast functions
+ */
 static isc_boolean_t   addr_ismulticast         P((struct sockaddr_storage *));
 /*
  * Not all platforms support multicast
@@ -876,6 +879,59 @@ addr_ismulticast(struct sockaddr_storage *maddr)
                return (ISC_FALSE);
        }
 }
+/*
+ * Multicast servers need to set the appropriate Multicast interface
+ * socket option in order for it to know which interface to use for
+ * send the multicast packet.
+ */
+void
+enable_multicast_if(struct interface *iface, struct sockaddr_storage *maddr)
+{
+       switch (maddr->ss_family)
+       {
+       case AF_INET:
+               if (setsockopt(iface->fd, IPPROTO_IP, IP_MULTICAST_IF,
+                  (char *)&(((struct sockaddr_in*)&iface->sin)->sin_addr.s_addr),
+                   sizeof(struct sockaddr_in*)) == -1) {
+                       netsyslog(LOG_ERR,
+                       "setsockopt IP_MULTICAST_IF failure: %m on socket %d, addr %s for multicast address %s",
+                       iface->fd, stoa(&iface->sin), stoa(maddr));
+                       return;
+               }
+#ifdef DEBUG
+               if (debug > 0) {
+                       printf(
+                       "Added IPv4 multicast interface on socket %d, addr %s for multicast address %s\n",
+                       iface->fd, stoa(&iface->sin),
+                       stoa(maddr));
+               }
+#endif
+               break;
+       case AF_INET6:
+#ifdef INCLUDE_IPV6_MULTICAST_SUPPORT
+               if (setsockopt(iface->fd, IPPROTO_IPV6, IPV6_MULTICAST_IF,
+                   &iface->scopeid, sizeof(iface->scopeid)) == -1) {
+                       netsyslog(LOG_ERR,
+                       "setsockopt IPV6_MULTICAST_IF failure: %m on socket %d, addr %s, scope %d for multicast address %s",
+                       iface->fd, stoa(&iface->sin), iface->scopeid,
+                       stoa(maddr));
+                       return;
+               }
+#ifdef DEBUG
+               if (debug > 0) {
+                       printf(
+                       "Added IPv6 multicast interface on socket %d, addr %s, scope %d for multicast address %s\n",
+                       iface->fd,  stoa(&iface->sin), iface->scopeid,
+                       stoa(maddr));
+               }
+#endif
+               break;
+#else
+               return;
+#endif /* INCLUDE_IPV6_MULTICAST_SUPPORT */
+       }
+       return;
+}
 /*
  * NOTE: Not all platforms support multicast
  */
@@ -2231,8 +2287,10 @@ input_handler(
        {
                if (select_count == 0) /* We really had nothing to do */
                {
+#ifdef DEBUG
                        if (debug)
                            netsyslog(LOG_DEBUG, "input_handler: select() returned 0");
+#endif
                        --handler_count;
                        return;
                }
@@ -2244,9 +2302,10 @@ input_handler(
                 * it.
                 */
                L_SUB(&ts_e, &ts);
+#ifdef DEBUG
                if (debug > 3)
                    netsyslog(LOG_INFO, "input_handler: Processed a gob of fd's in %s msec", lfptoms(&ts_e, 6));
-
+#endif
                /* just bail. */
                --handler_count;
                return;
@@ -2515,7 +2574,7 @@ findbcastinter(
                if (inter_list[i].sin.ss_family == AF_INET6 &&
                   (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6*)&inter_list[i].sin)->sin6_addr)))
                {
-                       continue;
+/*                     continue; */
                }
 #endif
                /*
index a6b79905f29666375cfa51832b88d715c7e1a2f3..42e5af72dd97b31dffb4d006ef31a42777ac7655 100644 (file)
@@ -576,9 +576,14 @@ newpeer(
        else if (cast_flags & (MDF_BCLNT | MDF_ACAST | MDF_MCAST | MDF_BCAST)) {
                peer->dstadr = findbcastinter(srcadr);
 #ifdef DEBUG
-               if (debug > 1)
-                       printf("Found broadcast interface address %s, for address %s\n",
-                               stoa(&(peer->dstadr)->sin), stoa(srcadr));
+               if (debug > 1) {
+                       if (peer->dstadr != NULL)
+                               printf("Found broadcast interface address %s, for address %s\n",
+                                       stoa(&(peer->dstadr)->sin), stoa(srcadr));
+                       else
+                               printf("No broadcast local address found for address %s\n",
+                                       stoa(srcadr));
+               }
 #endif
                /*
                 * If it was a multicast packet, findbcastinter() may not
@@ -605,6 +610,12 @@ newpeer(
        if (cast_flags & MDF_BCAST) {
                enable_broadcast(peer->dstadr, srcadr);
        }
+       /*
+        * Multicast needs the socket interface enabled for multicast
+        */
+       if (cast_flags & MDF_MCAST) {
+               enable_multicast_if(peer->dstadr, srcadr);
+       }
 #ifdef DEBUG
        if (debug>2)
                printf("newpeer: using fd %d and our addr %s\n",