Browse Source

[3437] Bind to any address when joining multicast group.

Marcin Siodelski 11 years ago
parent
commit
30b6420a0e
2 changed files with 9 additions and 4 deletions
  1. 2 3
      src/lib/dhcp/iface_mgr_bsd.cc
  2. 7 1
      src/lib/dhcp/pkt_filter_inet6.cc

+ 2 - 3
src/lib/dhcp/iface_mgr_bsd.cc

@@ -156,10 +156,9 @@ IfaceMgr::openMulticastSocket(Iface& iface,
                               const uint16_t port,
                               const uint16_t port,
                               IfaceMgrErrorMsgCallback error_handler) {
                               IfaceMgrErrorMsgCallback error_handler) {
     try {
     try {
-        // This should open a socket, bound it to link-local address
+        // This should open a socket, bind it to link-local address
         // and join multicast group.
         // and join multicast group.
-        openSocket(iface.getName(), addr, port,
-                   iface.flag_multicast_);
+        openSocket(iface.getName(), addr, port, iface.flag_multicast_);
 
 
     } catch (const Exception& ex) {
     } catch (const Exception& ex) {
         IFACEMGR_ERROR(SocketConfigError, error_handler,
         IFACEMGR_ERROR(SocketConfigError, error_handler,

+ 7 - 1
src/lib/dhcp/pkt_filter_inet6.cc

@@ -42,7 +42,13 @@ PktFilterInet6::openSocket(const Iface& iface,
         addr6.sin6_scope_id = if_nametoindex(iface.getName().c_str());
         addr6.sin6_scope_id = if_nametoindex(iface.getName().c_str());
     }
     }
 
 
-    memcpy(&addr6.sin6_addr, &addr.toBytes()[0], sizeof(addr6.sin6_addr));
+    // In order to listen to the multicast traffic we need to bind socket
+    // to in6addr_any.
+    if (join_multicast && iface.flag_multicast_) {
+        memcpy(&addr6.sin6_addr, &in6addr_any, sizeof(addr6.sin6_addr));
+    } else {
+        memcpy(&addr6.sin6_addr, &addr.toBytes()[0], sizeof(addr6.sin6_addr));
+    }
 #ifdef HAVE_SA_LEN
 #ifdef HAVE_SA_LEN
     addr6.sin6_len = sizeof(addr6);
     addr6.sin6_len = sizeof(addr6);
 #endif
 #endif