Commit 668b6626 authored by Tomas Korbar's avatar Tomas Korbar
Browse files

Add support for IP_FREEBIND socket option

isc_socket_bind function is now able to set
IP_FREEBIND option before binding a socket.

Control channel uses this feature to mitigate
issue with trying to bind interface which is
not yet up.
parent c913ac48
......@@ -1233,7 +1233,7 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
if (result == ISC_R_SUCCESS) {
result = isc_socket_bind(listener->sock, &listener->address,
ISC_SOCKET_REUSEADDRESS);
ISC_SOCKET_REUSEADDRESS | ISC_SOCKET_IP_FREEBIND);
}
if (result == ISC_R_SUCCESS && type == isc_sockettype_unix) {
......
......@@ -79,9 +79,12 @@ ISC_LANG_BEGINDECLS
* _REUSEADDRESS: Set SO_REUSEADDR prior to calling bind(),
* if a non-zero port is specified (applies to
* AF_INET and AF_INET6).
* _IP_FREEBIND: set socket option IP_FREEBIND prior to calling
* bind() (applies to AF_INET and AF_INET6).
*/
typedef enum {
ISC_SOCKET_REUSEADDRESS = 0x01U,
ISC_SOCKET_IP_FREEBIND = 0x02U,
} isc_socket_options_t;
/*@}*/
......
......@@ -4442,6 +4442,14 @@ isc_socket_bind(isc_socket_t *sock0, const isc_sockaddr_t *sockaddr,
#endif /* if defined(__FreeBSD_kernel__) && defined(SO_REUSEPORT_LB) */
/* Press on... */
}
#ifdef IP_FREEBIND
if ((options & ISC_SOCKET_IP_FREEBIND) != 0 &&
setsockopt(sock->fd, SOL_SOCKET, IP_FREEBIND, (void *)&on,
sizeof(on)) < 0) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"setsockopt(%d) failed", sock->fd);
}
#endif
#ifdef AF_UNIX
bind_socket:
#endif /* ifdef AF_UNIX */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment