mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-28 17:46:40 -04:00
This commit converts the license handling to adhere to the REUSE specification. It specifically: 1. Adds used licnses to LICENSES/ directory 2. Add "isc" template for adding the copyright boilerplate 3. Changes all source files to include copyright and SPDX license header, this includes all the C sources, documentation, zone files, configuration files. There are notes in the doc/dev/copyrights file on how to add correct headers to the new files. 4. Handle the rest that can't be modified via .reuse/dep5 file. The binary (or otherwise unmodifiable) files could have license places next to them in <foo>.license file, but this would lead to cluttered repository and most of the files handled in the .reuse/dep5 file are system test files.
122 lines
3 KiB
C
122 lines
3 KiB
C
/*
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
*
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
* information regarding copyright ownership.
|
|
*/
|
|
|
|
#include "uv-compat.h"
|
|
#include <unistd.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
#include "netmgr-int.h"
|
|
|
|
#if UV_VERSION_HEX < UV_VERSION(1, 27, 0)
|
|
int
|
|
isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr) {
|
|
int err = 0;
|
|
|
|
do {
|
|
int addrlen = (addr->sa_family == AF_INET)
|
|
? sizeof(struct sockaddr_in)
|
|
: sizeof(struct sockaddr_in6);
|
|
err = connect(handle->io_watcher.fd, addr, addrlen);
|
|
} while (err == -1 && errno == EINTR);
|
|
|
|
if (err) {
|
|
#if UV_VERSION_HEX >= UV_VERSION(1, 10, 0)
|
|
return (uv_translate_sys_error(errno));
|
|
#else
|
|
return (-errno);
|
|
#endif /* UV_VERSION_HEX >= UV_VERSION(1, 10, 0) */
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
#endif /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */
|
|
|
|
int
|
|
isc_uv_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr,
|
|
unsigned int flags) {
|
|
int r;
|
|
uv_os_sock_t fd;
|
|
|
|
r = uv_fileno((const uv_handle_t *)handle, (uv_os_fd_t *)&fd);
|
|
if (r < 0) {
|
|
return (r);
|
|
}
|
|
|
|
r = uv_udp_bind(handle, addr, flags);
|
|
if (r == UV_EADDRNOTAVAIL &&
|
|
isc__nm_socket_freebind(fd, addr->sa_family) == ISC_R_SUCCESS)
|
|
{
|
|
/*
|
|
* Retry binding with IP_FREEBIND (or equivalent option) if the
|
|
* address is not available. This helps with IPv6 tentative
|
|
* addresses which are reported by the route socket, although
|
|
* named is not yet able to properly bind to them.
|
|
*/
|
|
r = uv_udp_bind(handle, addr, flags);
|
|
}
|
|
|
|
return (r);
|
|
}
|
|
|
|
static int
|
|
isc__uv_tcp_bind_now(uv_tcp_t *handle, const struct sockaddr *addr,
|
|
unsigned int flags) {
|
|
int r;
|
|
struct sockaddr_storage sname;
|
|
int snamelen = sizeof(sname);
|
|
|
|
r = uv_tcp_bind(handle, addr, flags);
|
|
if (r < 0) {
|
|
return (r);
|
|
}
|
|
|
|
/*
|
|
* uv_tcp_bind() uses a delayed error, initially returning
|
|
* success even if bind() fails. By calling uv_tcp_getsockname()
|
|
* here we can find out whether the bind() call was successful.
|
|
*/
|
|
r = uv_tcp_getsockname(handle, (struct sockaddr *)&sname, &snamelen);
|
|
if (r < 0) {
|
|
return (r);
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
isc_uv_tcp_freebind(uv_tcp_t *handle, const struct sockaddr *addr,
|
|
unsigned int flags) {
|
|
int r;
|
|
uv_os_sock_t fd;
|
|
|
|
r = uv_fileno((const uv_handle_t *)handle, (uv_os_fd_t *)&fd);
|
|
if (r < 0) {
|
|
return (r);
|
|
}
|
|
|
|
r = isc__uv_tcp_bind_now(handle, addr, flags);
|
|
if (r == UV_EADDRNOTAVAIL &&
|
|
isc__nm_socket_freebind(fd, addr->sa_family) == ISC_R_SUCCESS)
|
|
{
|
|
/*
|
|
* Retry binding with IP_FREEBIND (or equivalent option) if the
|
|
* address is not available. This helps with IPv6 tentative
|
|
* addresses which are reported by the route socket, although
|
|
* named is not yet able to properly bind to them.
|
|
*/
|
|
r = isc__uv_tcp_bind_now(handle, addr, flags);
|
|
}
|
|
|
|
return (r);
|
|
}
|