]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3512] Set SO_REUSEPORT option when opening multicast socket.
authorMarcin Siodelski <marcin@isc.org>
Thu, 21 Aug 2014 14:33:06 +0000 (16:33 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 21 Aug 2014 14:33:06 +0000 (16:33 +0200)
This is required on NetNSD and OpenBSD so as multiple sockets can be bound
to in6addr_any and dhcp server port.

src/lib/dhcp/pkt_filter_inet6.cc

index 44fab37cd1a1e4ed4cff187f5f009d15999c5930..8df83ccfd5824967655894274e3150d5996f9122 100644 (file)
@@ -73,6 +73,19 @@ PktFilterInet6::openSocket(const Iface& iface,
                   " socket.");
     }
 
+#ifdef SO_REUSEPORT
+    // Set SO_REUSEPORT has to be set to open multiple sockets and bind to
+    // in6addr_any (binding to port). Binding to port is required on some
+    // operating systems, e.g. NetBSD and OpenBSD so as the socket can
+    // join the socket to multicast group.
+    if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,
+                   (char *)&flag, sizeof(flag)) < 0) {
+        close(sock);
+        isc_throw(SocketConfigError, "Can't set SO_REUSEPORT option on IPv6"
+                  " socket.");
+    }
+#endif
+
     if (bind(sock, (struct sockaddr *)&addr6, sizeof(addr6)) < 0) {
         // Get the error message immediately after the bind because the
         // invocation to close() below would override the errno.