mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Refactor isc__nm_socket_freebind() to take fd and sa_family as args
The isc__nm_socket_freebind() has been refactored to match other isc__nm_socket_...() helper functions and take uv_os_fd_t and sa_family_t as function arguments.
This commit is contained in:
@@ -1584,50 +1584,44 @@ isc__nm_decstats(isc_nm_t *mgr, isc_statscounter_t counterid) {
|
||||
setsockopt(socket, level, name, &(int){ 1 }, sizeof(int))
|
||||
|
||||
isc_result_t
|
||||
isc__nm_socket_freebind(const uv_handle_t *handle) {
|
||||
isc__nm_socket_freebind(uv_os_fd_t fd, sa_family_t sa_family) {
|
||||
/*
|
||||
* Set the IP_FREEBIND (or equivalent option) on the uv_handle.
|
||||
*/
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
uv_os_fd_t fd;
|
||||
if (uv_fileno(handle, &fd) != 0) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
#ifdef IP_FREEBIND
|
||||
UNUSED(sa_family);
|
||||
if (setsockopt_on(fd, IPPROTO_IP, IP_FREEBIND) == -1) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
#elif defined(IP_BINDANY) || defined(IPV6_BINDANY)
|
||||
struct sockaddr_in sockfd;
|
||||
|
||||
if (getsockname(fd, (struct sockaddr *)&sockfd,
|
||||
&(socklen_t){ sizeof(sockfd) }) == -1)
|
||||
{
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
if (sa_family == AF_INET) {
|
||||
#if defined(IP_BINDANY)
|
||||
if (sockfd.sin_family == AF_INET) {
|
||||
if (setsockopt_on(fd, IPPROTO_IP, IP_BINDANY) == -1) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
#endif
|
||||
} else if (sa_family == AF_INET6) {
|
||||
#if defined(IPV6_BINDANY)
|
||||
if (sockfd.sin_family == AF_INET6) {
|
||||
if (setsockopt_on(fd, IPPROTO_IPV6, IPV6_BINDANY) == -1) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
#elif defined(SO_BINDANY)
|
||||
UNUSED(sa_family);
|
||||
if (setsockopt_on(fd, SOL_SOCKET, SO_BINDANY) == -1) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
return (ISC_R_SUCCESS);
|
||||
#else
|
||||
UNUSED(handle);
|
||||
result = ISC_R_NOTIMPLEMENTED;
|
||||
UNUSED(fd);
|
||||
UNUSED(sa_family);
|
||||
return (ISC_R_NOTIMPLEMENTED);
|
||||
#endif
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
|
Reference in New Issue
Block a user