From: Marcin Siodelski Date: Thu, 21 Aug 2014 14:33:06 +0000 (+0200) Subject: [3512] Set SO_REUSEPORT option when opening multicast socket. X-Git-Tag: trac3482_base~11^2~2^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dddc0834e06671c75ed4cc3ed6d4fb64741dde6f;p=thirdparty%2Fkea.git [3512] Set SO_REUSEPORT option when opening multicast socket. This is required on NetNSD and OpenBSD so as multiple sockets can be bound to in6addr_any and dhcp server port. --- diff --git a/src/lib/dhcp/pkt_filter_inet6.cc b/src/lib/dhcp/pkt_filter_inet6.cc index 44fab37cd1..8df83ccfd5 100644 --- a/src/lib/dhcp/pkt_filter_inet6.cc +++ b/src/lib/dhcp/pkt_filter_inet6.cc @@ -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.