Commit 0b657695 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 8dd41143
......@@ -1225,7 +1225,7 @@ add_listener(ns_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) {
listener->perm = cfg_obj_asuint32(cfg_tuple_get(control,
......
......@@ -129,6 +129,12 @@ ISC_LANG_BEGINDECLS
*/
#define ISC_SOCKET_REUSEADDRESS 0x01U
/*%
* set socket option IP_FREEBIND prior to calling
* bind() (applies to AF_INET and AF_INET6).
*/
#define ISC_SOCKET_IP_FREEBIND 0x02U
/*%
* Statistics counters. Used as isc_statscounter_t values.
*/
......
......@@ -5594,6 +5594,16 @@ isc__socket_bind(isc_socket_t *sock0, isc_sockaddr_t *sockaddr,
ISC_MSG_FAILED, "failed"));
/* 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) %s", sock->fd,
isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
ISC_MSG_FAILED, "failed"));
}
#endif
#ifdef AF_UNIX
bind_socket:
#endif
......
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