From 24c38796754521844eb77f0bacd7dd53a34b10e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 27 Apr 2022 17:41:47 +0200 Subject: [PATCH 1/3] Move socket related functions to netmgr/socket.c Move the netmgr socket related functions from netmgr/netmgr.c and netmgr/uv-compat.c to netmgr/socket.c, so they are all present all in the same place. Adjust the names of couple interal functions accordingly. --- lib/isc/Makefile.am | 1 + lib/isc/netmgr/netmgr-int.h | 18 +- lib/isc/netmgr/netmgr.c | 282 --------------------------- lib/isc/netmgr/socket.c | 378 ++++++++++++++++++++++++++++++++++++ lib/isc/netmgr/tcp.c | 8 +- lib/isc/netmgr/tcpdns.c | 8 +- lib/isc/netmgr/tlsdns.c | 8 +- lib/isc/netmgr/udp.c | 12 +- lib/isc/netmgr/uv-compat.c | 79 -------- lib/isc/netmgr/uv-compat.h | 8 - lib/isc/tests/doh_test.c | 1 + lib/isc/tests/netmgr_test.c | 1 + 12 files changed, 411 insertions(+), 393 deletions(-) create mode 100644 lib/isc/netmgr/socket.c diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index c0bb69fa4a..7ac556adaa 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -103,6 +103,7 @@ libisc_la_SOURCES = \ $(libisc_la_HEADERS) \ netmgr/netmgr-int.h \ netmgr/netmgr.c \ + netmgr/socket.c \ netmgr/tcp.c \ netmgr/tcpdns.c \ netmgr/timer.c \ diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 10c56514af..0594faa5f6 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -1875,12 +1875,6 @@ isc__nm_closesocket(uv_os_sock_t sock); * Platform independent closesocket() version */ -isc_result_t -isc__nm_socket_freebind(uv_os_sock_t fd, sa_family_t sa_family); -/*%< - * Set the IP_FREEBIND (or equivalent) socket option on the uv_handle - */ - isc_result_t isc__nm_socket_reuse(uv_os_sock_t fd); /*%< @@ -2160,3 +2154,15 @@ isc__nmsocket_writetimeout_cb(void *data, isc_result_t eresult); isc_error_fatal(__FILE__, __LINE__, "%s failed: %s", #func, \ uv_strerror(ret)); \ } + +/* + * Bind to the socket, but allow binding to IPv6 tentative addresses reported by + * the route socket by setting IP_FREEBIND (or equivalent). + */ +int +isc__nm_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr, + unsigned int flags); + +int +isc__nm_tcp_freebind(uv_tcp_t *handle, const struct sockaddr *addr, + unsigned int flags); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index f7444630c8..0b250fe1dc 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -2978,213 +2978,6 @@ isc__nm_decstats(isc_nmsocket_t *sock, isc__nm_statid_t id) { } } -isc_result_t -isc__nm_socket(int domain, int type, int protocol, uv_os_sock_t *sockp) { - int sock = socket(domain, type, protocol); - if (sock < 0) { - return (isc_errno_toresult(errno)); - } - - *sockp = (uv_os_sock_t)sock; - return (ISC_R_SUCCESS); -} - -void -isc__nm_closesocket(uv_os_sock_t sock) { - close(sock); -} - -#define setsockopt_on(socket, level, name) \ - setsockopt(socket, level, name, &(int){ 1 }, sizeof(int)) - -#define setsockopt_off(socket, level, name) \ - setsockopt(socket, level, name, &(int){ 0 }, sizeof(int)) - -isc_result_t -isc__nm_socket_freebind(uv_os_sock_t fd, sa_family_t sa_family) { - /* - * Set the IP_FREEBIND (or equivalent option) on the uv_handle. - */ -#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) - if (sa_family == AF_INET) { -#if defined(IP_BINDANY) - 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 (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(fd); - UNUSED(sa_family); - return (ISC_R_NOTIMPLEMENTED); -#endif -} - -isc_result_t -isc__nm_socket_reuse(uv_os_sock_t fd) { - /* - * Generally, the SO_REUSEADDR socket option allows reuse of - * local addresses. - * - * On the BSDs, SO_REUSEPORT implies SO_REUSEADDR but with some - * additional refinements for programs that use multicast. - * - * On Linux, SO_REUSEPORT has different semantics: it _shares_ the port - * rather than steal it from the current listener, so we don't use it - * here, but rather in isc__nm_socket_reuse_lb(). - * - * On Windows, it also allows a socket to forcibly bind to a port in use - * by another socket. - */ - -#if defined(SO_REUSEPORT) && !defined(__linux__) - if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEPORT) == -1) { - return (ISC_R_FAILURE); - } - return (ISC_R_SUCCESS); -#elif defined(SO_REUSEADDR) - if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEADDR) == -1) { - return (ISC_R_FAILURE); - } - return (ISC_R_SUCCESS); -#else - UNUSED(fd); - return (ISC_R_NOTIMPLEMENTED); -#endif -} - -isc_result_t -isc__nm_socket_reuse_lb(uv_os_sock_t fd) { - /* - * On FreeBSD 12+, SO_REUSEPORT_LB socket option allows sockets to be - * bound to an identical socket address. For UDP sockets, the use of - * this option can provide better distribution of incoming datagrams to - * multiple processes (or threads) as compared to the traditional - * technique of having multiple processes compete to receive datagrams - * on the same socket. - * - * On Linux, the same thing is achieved simply with SO_REUSEPORT. - */ -#if defined(SO_REUSEPORT_LB) - if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEPORT_LB) == -1) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#elif defined(SO_REUSEPORT) && defined(__linux__) - if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEPORT) == -1) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#else - UNUSED(fd); - return (ISC_R_NOTIMPLEMENTED); -#endif -} - -isc_result_t -isc__nm_socket_incoming_cpu(uv_os_sock_t fd) { -#ifdef SO_INCOMING_CPU - if (setsockopt_on(fd, SOL_SOCKET, SO_INCOMING_CPU) == -1) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#else - UNUSED(fd); -#endif - return (ISC_R_NOTIMPLEMENTED); -} - -isc_result_t -isc__nm_socket_disable_pmtud(uv_os_sock_t fd, sa_family_t sa_family) { - /* - * Disable the Path MTU Discovery on IP packets - */ - if (sa_family == AF_INET6) { -#if defined(IPV6_DONTFRAG) - if (setsockopt_off(fd, IPPROTO_IPV6, IPV6_DONTFRAG) == -1) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#elif defined(IPV6_MTU_DISCOVER) && defined(IP_PMTUDISC_OMIT) - if (setsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, - &(int){ IP_PMTUDISC_OMIT }, sizeof(int)) == -1) - { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#else - UNUSED(fd); -#endif - } else if (sa_family == AF_INET) { -#if defined(IP_DONTFRAG) - if (setsockopt_off(fd, IPPROTO_IP, IP_DONTFRAG) == -1) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#elif defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_OMIT) - if (setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, - &(int){ IP_PMTUDISC_OMIT }, sizeof(int)) == -1) - { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#else - UNUSED(fd); -#endif - } else { - return (ISC_R_FAMILYNOSUPPORT); - } - - return (ISC_R_NOTIMPLEMENTED); -} - -isc_result_t -isc__nm_socket_v6only(uv_os_sock_t fd, sa_family_t sa_family) { - /* - * Enable the IPv6-only option on IPv6 sockets - */ - if (sa_family == AF_INET6) { -#if defined(IPV6_V6ONLY) - if (setsockopt_on(fd, IPPROTO_IPV6, IPV6_V6ONLY) == -1) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#else - UNUSED(fd); -#endif - } - return (ISC_R_NOTIMPLEMENTED); -} - isc_result_t isc_nm_checkaddr(const isc_sockaddr_t *addr, isc_socktype_t type) { int proto, pf, addrlen, fd, r; @@ -3242,81 +3035,6 @@ isc_nm_checkaddr(const isc_sockaddr_t *addr, isc_socktype_t type) { #define TIMEOUT_OPTNAME TCP_KEEPINIT #endif -isc_result_t -isc__nm_socket_connectiontimeout(uv_os_sock_t fd, int timeout_ms) { -#if defined(TIMEOUT_OPTNAME) - TIMEOUT_TYPE timeout = timeout_ms / TIMEOUT_DIV; - - if (timeout == 0) { - timeout = 1; - } - - if (setsockopt(fd, IPPROTO_TCP, TIMEOUT_OPTNAME, &timeout, - sizeof(timeout)) == -1) - { - return (ISC_R_FAILURE); - } - - return (ISC_R_SUCCESS); -#else - UNUSED(fd); - UNUSED(timeout_ms); - - return (ISC_R_SUCCESS); -#endif -} - -isc_result_t -isc__nm_socket_tcp_nodelay(uv_os_sock_t fd) { -#ifdef TCP_NODELAY - if (setsockopt_on(fd, IPPROTO_TCP, TCP_NODELAY) == -1) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#else - UNUSED(fd); - return (ISC_R_SUCCESS); -#endif -} - -isc_result_t -isc__nm_socket_tcp_maxseg(uv_os_sock_t fd, int size) { -#ifdef TCP_MAXSEG - if (setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, (void *)&size, - sizeof(size))) { - return (ISC_R_FAILURE); - } else { - return (ISC_R_SUCCESS); - } -#else - UNUSED(fd); - UNUSED(size); - return (ISC_R_SUCCESS); -#endif -} - -isc_result_t -isc__nm_socket_min_mtu(uv_os_sock_t fd, sa_family_t sa_family) { - if (sa_family != AF_INET6) { - return (ISC_R_SUCCESS); - } -#ifdef IPV6_USE_MIN_MTU - if (setsockopt_on(fd, IPPROTO_IPV6, IPV6_USE_MIN_MTU) == -1) { - return (ISC_R_FAILURE); - } -#elif defined(IPV6_MTU) - if (setsockopt(fd, IPPROTO_IPV6, IPV6_MTU, &(int){ 1280 }, - sizeof(int)) == -1) { - return (ISC_R_FAILURE); - } -#else - UNUSED(fd); -#endif - - return (ISC_R_SUCCESS); -} - void isc__nm_set_network_buffers(isc_nm_t *nm, uv_handle_t *handle) { int32_t recv_buffer_size = 0; diff --git a/lib/isc/netmgr/socket.c b/lib/isc/netmgr/socket.c new file mode 100644 index 0000000000..291ac99fa2 --- /dev/null +++ b/lib/isc/netmgr/socket.c @@ -0,0 +1,378 @@ +/* + * 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 + +#include "netmgr-int.h" +#include "uv-compat.h" + +#define setsockopt_on(socket, level, name) \ + setsockopt(socket, level, name, &(int){ 1 }, sizeof(int)) + +#define setsockopt_off(socket, level, name) \ + setsockopt(socket, level, name, &(int){ 0 }, sizeof(int)) + +static isc_result_t +socket_freebind(uv_os_sock_t fd, sa_family_t sa_family) { + /* + * Set the IP_FREEBIND (or equivalent option) on the uv_handle. + */ +#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) + if (sa_family == AF_INET) { +#if defined(IP_BINDANY) + 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 (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(fd); + UNUSED(sa_family); + return (ISC_R_NOTIMPLEMENTED); +#endif +} + +int +isc__nm_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 && + 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 +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__nm_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 = tcp_bind_now(handle, addr, flags); + if (r == UV_EADDRNOTAVAIL && + 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 = tcp_bind_now(handle, addr, flags); + } + + return (r); +} + +isc_result_t +isc__nm_socket(int domain, int type, int protocol, uv_os_sock_t *sockp) { + int sock = socket(domain, type, protocol); + if (sock < 0) { + return (isc_errno_toresult(errno)); + } + + *sockp = (uv_os_sock_t)sock; + return (ISC_R_SUCCESS); +} + +void +isc__nm_closesocket(uv_os_sock_t sock) { + close(sock); +} + +isc_result_t +isc__nm_socket_reuse(uv_os_sock_t fd) { + /* + * Generally, the SO_REUSEADDR socket option allows reuse of + * local addresses. + * + * On the BSDs, SO_REUSEPORT implies SO_REUSEADDR but with some + * additional refinements for programs that use multicast. + * + * On Linux, SO_REUSEPORT has different semantics: it _shares_ the port + * rather than steal it from the current listener, so we don't use it + * here, but rather in isc__nm_socket_reuse_lb(). + * + * On Windows, it also allows a socket to forcibly bind to a port in use + * by another socket. + */ + +#if defined(SO_REUSEPORT) && !defined(__linux__) + if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEPORT) == -1) { + return (ISC_R_FAILURE); + } + return (ISC_R_SUCCESS); +#elif defined(SO_REUSEADDR) + if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEADDR) == -1) { + return (ISC_R_FAILURE); + } + return (ISC_R_SUCCESS); +#else + UNUSED(fd); + return (ISC_R_NOTIMPLEMENTED); +#endif +} + +isc_result_t +isc__nm_socket_reuse_lb(uv_os_sock_t fd) { + /* + * On FreeBSD 12+, SO_REUSEPORT_LB socket option allows sockets to be + * bound to an identical socket address. For UDP sockets, the use of + * this option can provide better distribution of incoming datagrams to + * multiple processes (or threads) as compared to the traditional + * technique of having multiple processes compete to receive datagrams + * on the same socket. + * + * On Linux, the same thing is achieved simply with SO_REUSEPORT. + */ +#if defined(SO_REUSEPORT_LB) + if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEPORT_LB) == -1) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#elif defined(SO_REUSEPORT) && defined(__linux__) + if (setsockopt_on(fd, SOL_SOCKET, SO_REUSEPORT) == -1) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#else + UNUSED(fd); + return (ISC_R_NOTIMPLEMENTED); +#endif +} + +isc_result_t +isc__nm_socket_incoming_cpu(uv_os_sock_t fd) { +#ifdef SO_INCOMING_CPU + if (setsockopt_on(fd, SOL_SOCKET, SO_INCOMING_CPU) == -1) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#else + UNUSED(fd); +#endif + return (ISC_R_NOTIMPLEMENTED); +} + +isc_result_t +isc__nm_socket_disable_pmtud(uv_os_sock_t fd, sa_family_t sa_family) { + /* + * Disable the Path MTU Discovery on IP packets + */ + if (sa_family == AF_INET6) { +#if defined(IPV6_DONTFRAG) + if (setsockopt_off(fd, IPPROTO_IPV6, IPV6_DONTFRAG) == -1) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#elif defined(IPV6_MTU_DISCOVER) && defined(IP_PMTUDISC_OMIT) + if (setsockopt(fd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, + &(int){ IP_PMTUDISC_OMIT }, sizeof(int)) == -1) + { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#else + UNUSED(fd); +#endif + } else if (sa_family == AF_INET) { +#if defined(IP_DONTFRAG) + if (setsockopt_off(fd, IPPROTO_IP, IP_DONTFRAG) == -1) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#elif defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_OMIT) + if (setsockopt(fd, IPPROTO_IP, IP_MTU_DISCOVER, + &(int){ IP_PMTUDISC_OMIT }, sizeof(int)) == -1) + { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#else + UNUSED(fd); +#endif + } else { + return (ISC_R_FAMILYNOSUPPORT); + } + + return (ISC_R_NOTIMPLEMENTED); +} + +isc_result_t +isc__nm_socket_v6only(uv_os_sock_t fd, sa_family_t sa_family) { + /* + * Enable the IPv6-only option on IPv6 sockets + */ + if (sa_family == AF_INET6) { +#if defined(IPV6_V6ONLY) + if (setsockopt_on(fd, IPPROTO_IPV6, IPV6_V6ONLY) == -1) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#else + UNUSED(fd); +#endif + } + return (ISC_R_NOTIMPLEMENTED); +} + +isc_result_t +isc__nm_socket_connectiontimeout(uv_os_sock_t fd, int timeout_ms) { +#if defined(TIMEOUT_OPTNAME) + TIMEOUT_TYPE timeout = timeout_ms / TIMEOUT_DIV; + + if (timeout == 0) { + timeout = 1; + } + + if (setsockopt(fd, IPPROTO_TCP, TIMEOUT_OPTNAME, &timeout, + sizeof(timeout)) == -1) + { + return (ISC_R_FAILURE); + } + + return (ISC_R_SUCCESS); +#else + UNUSED(fd); + UNUSED(timeout_ms); + + return (ISC_R_SUCCESS); +#endif +} + +isc_result_t +isc__nm_socket_tcp_nodelay(uv_os_sock_t fd) { +#ifdef TCP_NODELAY + if (setsockopt_on(fd, IPPROTO_TCP, TCP_NODELAY) == -1) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#else + UNUSED(fd); + return (ISC_R_SUCCESS); +#endif +} + +isc_result_t +isc__nm_socket_tcp_maxseg(uv_os_sock_t fd, int size) { +#ifdef TCP_MAXSEG + if (setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, (void *)&size, + sizeof(size))) { + return (ISC_R_FAILURE); + } else { + return (ISC_R_SUCCESS); + } +#else + UNUSED(fd); + UNUSED(size); + return (ISC_R_SUCCESS); +#endif +} + +isc_result_t +isc__nm_socket_min_mtu(uv_os_sock_t fd, sa_family_t sa_family) { + if (sa_family != AF_INET6) { + return (ISC_R_SUCCESS); + } +#ifdef IPV6_USE_MIN_MTU + if (setsockopt_on(fd, IPPROTO_IPV6, IPV6_USE_MIN_MTU) == -1) { + return (ISC_R_FAILURE); + } +#elif defined(IPV6_MTU) + if (setsockopt(fd, IPPROTO_IPV6, IPV6_MTU, &(int){ 1280 }, + sizeof(int)) == -1) { + return (ISC_R_FAILURE); + } +#else + UNUSED(fd); +#endif + + return (ISC_R_SUCCESS); +} diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index e7eb77feb5..1ef80d4e2e 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -550,16 +550,16 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ev0) { } if (mgr->load_balance_sockets) { - r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, - &sock->iface.type.sa, flags); + r = isc__nm_tcp_freebind(&sock->uv_handle.tcp, + &sock->iface.type.sa, flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; } } else { if (sock->parent->fd == -1) { - r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, - &sock->iface.type.sa, flags); + r = isc__nm_tcp_freebind(&sock->uv_handle.tcp, + &sock->iface.type.sa, flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; diff --git a/lib/isc/netmgr/tcpdns.c b/lib/isc/netmgr/tcpdns.c index 73753742ea..0d928069ab 100644 --- a/lib/isc/netmgr/tcpdns.c +++ b/lib/isc/netmgr/tcpdns.c @@ -516,16 +516,16 @@ isc__nm_async_tcpdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) { } if (mgr->load_balance_sockets) { - r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, - &sock->iface.type.sa, flags); + r = isc__nm_tcp_freebind(&sock->uv_handle.tcp, + &sock->iface.type.sa, flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; } } else { if (sock->parent->fd == -1) { - r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, - &sock->iface.type.sa, flags); + r = isc__nm_tcp_freebind(&sock->uv_handle.tcp, + &sock->iface.type.sa, flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; diff --git a/lib/isc/netmgr/tlsdns.c b/lib/isc/netmgr/tlsdns.c index 68fbca67fe..3529c35616 100644 --- a/lib/isc/netmgr/tlsdns.c +++ b/lib/isc/netmgr/tlsdns.c @@ -603,16 +603,16 @@ isc__nm_async_tlsdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) { } if (mgr->load_balance_sockets) { - r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, - &sock->iface.type.sa, flags); + r = isc__nm_tcp_freebind(&sock->uv_handle.tcp, + &sock->iface.type.sa, flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; } } else { if (sock->parent->fd == -1) { - r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, - &sock->iface.type.sa, flags); + r = isc__nm_tcp_freebind(&sock->uv_handle.tcp, + &sock->iface.type.sa, flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index 29a603a0dd..df4312fba2 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -463,9 +463,9 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) { } if (mgr->load_balance_sockets) { - r = isc_uv_udp_freebind(&sock->uv_handle.udp, - &sock->parent->iface.type.sa, - uv_bind_flags); + r = isc__nm_udp_freebind(&sock->uv_handle.udp, + &sock->parent->iface.type.sa, + uv_bind_flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; @@ -473,9 +473,9 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) { } else { if (sock->parent->fd == -1) { /* This thread is first, bind the socket */ - r = isc_uv_udp_freebind(&sock->uv_handle.udp, - &sock->parent->iface.type.sa, - uv_bind_flags); + r = isc__nm_udp_freebind(&sock->uv_handle.udp, + &sock->parent->iface.type.sa, + uv_bind_flags); if (r < 0) { isc__nm_incstats(sock, STATID_BINDFAIL); goto done; diff --git a/lib/isc/netmgr/uv-compat.c b/lib/isc/netmgr/uv-compat.c index b7c0f7b0e2..39ec0cfed2 100644 --- a/lib/isc/netmgr/uv-compat.c +++ b/lib/isc/netmgr/uv-compat.c @@ -59,82 +59,3 @@ uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb) { return (0); } #endif /* UV_VERSION_HEX < UV_VERSION(1, 32, 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); -} diff --git a/lib/isc/netmgr/uv-compat.h b/lib/isc/netmgr/uv-compat.h index 3a103874e4..91e5d2c107 100644 --- a/lib/isc/netmgr/uv-compat.h +++ b/lib/isc/netmgr/uv-compat.h @@ -116,11 +116,3 @@ uv_os_getenv(const char *name, char *buffer, size_t *size) { #define uv_os_setenv(name, value) setenv(name, value, 0) #endif /* UV_VERSION_HEX < UV_VERSION(1, 12, 0) */ - -int -isc_uv_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr, - unsigned int flags); - -int -isc_uv_tcp_freebind(uv_tcp_t *handle, const struct sockaddr *addr, - unsigned int flags); diff --git a/lib/isc/tests/doh_test.c b/lib/isc/tests/doh_test.c index 2d7907d500..a2625a0a97 100644 --- a/lib/isc/tests/doh_test.c +++ b/lib/isc/tests/doh_test.c @@ -43,6 +43,7 @@ #include "../netmgr/http.c" #include "../netmgr/netmgr-int.h" +#include "../netmgr/socket.c" #include "../netmgr/uv-compat.c" #include "../netmgr/uv-compat.h" #include "../netmgr_p.h" diff --git a/lib/isc/tests/netmgr_test.c b/lib/isc/tests/netmgr_test.c index 62353dd0b7..c9c6a7504d 100644 --- a/lib/isc/tests/netmgr_test.c +++ b/lib/isc/tests/netmgr_test.c @@ -35,6 +35,7 @@ #define KEEP_BEFORE #include "../netmgr/netmgr-int.h" +#include "../netmgr/socket.c" #include "../netmgr/udp.c" #include "../netmgr/uv-compat.c" #include "../netmgr/uv-compat.h" From b43812692de476ccd6bba79c02b42abbbb37315e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 27 Apr 2022 17:41:47 +0200 Subject: [PATCH 2/3] Move netmgr/uv-compat.h to As we are going to use libuv outside of the netmgr, we need the shims to be readily available for the rest of the codebase. Move the "netmgr/uv-compat.h" to and netmgr/uv-compat.c to uv.c, and as a rule of thumb, the users of libuv should include instead of directly. Additionally, merge netmgr/uverr2result.c into uv.c and rename the single function from isc__nm_uverr2result() to isc_uverr2result(). --- bin/named/dlz_dlopen_driver.c | 2 +- bin/named/main.c | 2 +- lib/dns/dyndb.c | 2 +- lib/dns/tests/dispatch_test.c | 4 +- lib/isc/Makefile.am | 9 ++- lib/isc/include/isc/barrier.h | 2 +- .../{netmgr/uv-compat.h => include/isc/uv.h} | 60 +++++++++++------- lib/isc/netmgr/netmgr-int.h | 22 +------ lib/isc/netmgr/netmgr.c | 5 +- lib/isc/netmgr/socket.c | 6 +- lib/isc/netmgr/tcp.c | 28 ++++----- lib/isc/netmgr/tcpdns.c | 32 +++++----- lib/isc/netmgr/timer.c | 3 +- lib/isc/netmgr/tlsdns.c | 29 +++++---- lib/isc/netmgr/tlsstream.c | 3 +- lib/isc/netmgr/udp.c | 20 +++--- lib/isc/netmgr/uv-compat.c | 61 ------------------ lib/isc/task.c | 3 +- lib/isc/tests/Makefile.am | 3 +- lib/isc/tests/doh_test.c | 4 +- lib/isc/tests/netmgr_test.c | 6 +- lib/isc/tests/uv_wrap.h | 3 +- lib/isc/{netmgr/uverr2result.c => uv.c} | 63 ++++++++++++++++--- lib/ns/hooks.c | 2 +- 24 files changed, 168 insertions(+), 206 deletions(-) rename lib/isc/{netmgr/uv-compat.h => include/isc/uv.h} (69%) delete mode 100644 lib/isc/netmgr/uv-compat.c rename lib/isc/{netmgr/uverr2result.c => uv.c} (60%) diff --git a/bin/named/dlz_dlopen_driver.c b/bin/named/dlz_dlopen_driver.c index 45cfbfa976..bd96882b64 100644 --- a/bin/named/dlz_dlopen_driver.c +++ b/bin/named/dlz_dlopen_driver.c @@ -16,12 +16,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include diff --git a/bin/named/main.c b/bin/named/main.c index 33421faeaa..2977dcbd7b 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -19,7 +19,6 @@ #include #include #include -#include #ifdef HAVE_DNSTAP #include @@ -44,6 +43,7 @@ #include #include #include +#include #include #include diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c index 682e0b2eb3..253d58f9fe 100644 --- a/lib/dns/dyndb.c +++ b/lib/dns/dyndb.c @@ -12,7 +12,6 @@ */ #include -#include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/lib/dns/tests/dispatch_test.c b/lib/dns/tests/dispatch_test.c index f51c05332e..76d498041d 100644 --- a/lib/dns/tests/dispatch_test.c +++ b/lib/dns/tests/dispatch_test.c @@ -22,7 +22,6 @@ #include #include #include -#include #define UNIT_TESTING #include @@ -32,6 +31,7 @@ #include #include #include +#include #include #include @@ -68,7 +68,7 @@ const struct in6_addr in6addr_blackhole = { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, static int setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) { socklen_t addrlen = sizeof(*addr); - uv_os_sock_t fd; + uv_os_sock_t fd = -1; int r; isc_sockaddr_fromin6(addr, &in6addr_loopback, 0); diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 7ac556adaa..16bb818f46 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -97,7 +97,8 @@ libisc_la_HEADERS = \ include/isc/types.h \ include/isc/url.h \ include/isc/utf8.h \ - include/isc/util.h + include/isc/util.h \ + include/isc/uv.h libisc_la_SOURCES = \ $(libisc_la_HEADERS) \ @@ -109,9 +110,6 @@ libisc_la_SOURCES = \ netmgr/timer.c \ netmgr/tlsdns.c \ netmgr/udp.c \ - netmgr/uv-compat.c \ - netmgr/uv-compat.h \ - netmgr/uverr2result.c \ aes.c \ app.c \ assertions.c \ @@ -199,7 +197,8 @@ libisc_la_SOURCES = \ trampoline.c \ trampoline_p.h \ url.c \ - utf8.c + utf8.c \ + uv.c libisc_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ diff --git a/lib/isc/include/isc/barrier.h b/lib/isc/include/isc/barrier.h index 2ff380e158..74e6327681 100644 --- a/lib/isc/include/isc/barrier.h +++ b/lib/isc/include/isc/barrier.h @@ -28,7 +28,7 @@ #else -#include +#include #define isc_barrier_t uv_barrier_t diff --git a/lib/isc/netmgr/uv-compat.h b/lib/isc/include/isc/uv.h similarity index 69% rename from lib/isc/netmgr/uv-compat.h rename to lib/isc/include/isc/uv.h index 91e5d2c107..c0f0d54154 100644 --- a/lib/isc/netmgr/uv-compat.h +++ b/lib/isc/include/isc/uv.h @@ -12,13 +12,15 @@ */ #pragma once + +#include #include +#include + /* * These functions were introduced in newer libuv, but we still * want BIND9 compile on older ones so we emulate them. - * They're inline to avoid conflicts when running with a newer - * library version. */ #define UV_VERSION(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) @@ -44,6 +46,13 @@ #define UV__ERR(x) (-(x)) #endif +#if UV_VERSION_HEX < UV_VERSION(1, 12, 0) +int +uv_os_getenv(const char *name, char *buffer, size_t *size); + +#define uv_os_setenv(name, value) setenv(name, value, 0) +#endif /* UV_VERSION_HEX < UV_VERSION(1, 12, 0) */ + #if UV_VERSION_HEX < UV_VERSION(1, 19, 0) static inline void * uv_handle_get_data(const uv_handle_t *handle) { @@ -89,30 +98,33 @@ isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr); #define isc_uv_udp_connect uv_udp_connect #endif /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */ -#if UV_VERSION_HEX < UV_VERSION(1, 12, 0) -#include -#include +/* + * These are used with all versions of libuv: + */ -static inline int -uv_os_getenv(const char *name, char *buffer, size_t *size) { - size_t len; - char *buf = getenv(name); - - if (buf == NULL) { - return (UV_ENOENT); +#define UV_RUNTIME_CHECK(func, ret) \ + if (ret != 0) { \ + isc_error_fatal(__FILE__, __LINE__, "%s failed: %s\n", #func, \ + uv_strerror(ret)); \ } - len = strlen(buf) + 1; - if (len > *size) { - *size = len; - return (UV_ENOBUFS); - } +#define isc_uverr2result(x) \ + isc__uverr2result(x, true, __FILE__, __LINE__, __func__) +isc_result_t +isc__uverr2result(int uverr, bool dolog, const char *file, unsigned int line, + const char *func); +/*%< + * Convert a libuv error value into an isc_result_t. The + * list of supported error values is not complete; new users + * of this function should add any expected errors that are + * not already there. + */ - *size = len; - memmove(buffer, buf, len); +/** + * Type-casting helpers + */ - return (0); -} - -#define uv_os_setenv(name, value) setenv(name, value, 0) -#endif /* UV_VERSION_HEX < UV_VERSION(1, 12, 0) */ +#define uv_handle_set_data(handle, data) \ + uv_handle_set_data((uv_handle_t *)(handle), (data)) +#define uv_handle_get_data(handle) uv_handle_get_data((uv_handle_t *)(handle)) +#define uv_close(handle, close_cb) uv_close((uv_handle_t *)handle, close_cb) diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 0594faa5f6..bf6c3039ff 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -14,7 +14,6 @@ #pragma once #include -#include #include #include @@ -37,8 +36,7 @@ #include #include #include - -#include "uv-compat.h" +#include #define ISC_NETMGR_TID_UNKNOWN -1 @@ -1821,18 +1819,6 @@ isc__nm_http_set_tlsctx(isc_nmsocket_t *sock, isc_tlsctx_t *tlsctx); void isc__nm_async_settlsctx(isc__networker_t *worker, isc__netievent_t *ev0); -#define isc__nm_uverr2result(x) \ - isc___nm_uverr2result(x, true, __FILE__, __LINE__, __func__) -isc_result_t -isc___nm_uverr2result(int uverr, bool dolog, const char *file, - unsigned int line, const char *func); -/*%< - * Convert a libuv error value into an isc_result_t. The - * list of supported error values is not complete; new users - * of this function should add any expected errors that are - * not already there. - */ - bool isc__nm_acquire_interlocked(isc_nm_t *mgr); /*%< @@ -2149,12 +2135,6 @@ isc__nmsocket_readtimeout_cb(uv_timer_t *timer); void isc__nmsocket_writetimeout_cb(void *data, isc_result_t eresult); -#define UV_RUNTIME_CHECK(func, ret) \ - if (ret != 0) { \ - isc_error_fatal(__FILE__, __LINE__, "%s failed: %s", #func, \ - uv_strerror(ret)); \ - } - /* * Bind to the socket, but allow binding to IPv6 tentative addresses reported by * the route socket by setting IP_FREEBIND (or equivalent). diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 0b250fe1dc..880d57ed98 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -39,12 +38,12 @@ #include #include #include +#include #include "netmgr-int.h" #include "netmgr_p.h" #include "openssl_shim.h" #include "trampoline_p.h" -#include "uv-compat.h" /*% * How many isc_nmhandles and isc_nm_uvreqs will we be @@ -3097,7 +3096,7 @@ isc__nm_after_work_cb(uv_work_t *req, int status) { isc_nm_t *netmgr = work->netmgr; if (status != 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); } work->after_cb(work->data, result); diff --git a/lib/isc/netmgr/socket.c b/lib/isc/netmgr/socket.c index 291ac99fa2..7a706c44cb 100644 --- a/lib/isc/netmgr/socket.c +++ b/lib/isc/netmgr/socket.c @@ -12,9 +12,9 @@ */ #include +#include #include "netmgr-int.h" -#include "uv-compat.h" #define setsockopt_on(socket, level, name) \ setsockopt(socket, level, name, &(int){ 1 }, sizeof(int)) @@ -67,7 +67,7 @@ int isc__nm_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr, unsigned int flags) { int r; - uv_os_sock_t fd; + uv_os_sock_t fd = -1; r = uv_fileno((const uv_handle_t *)handle, (uv_os_fd_t *)&fd); if (r < 0) { @@ -119,7 +119,7 @@ int isc__nm_tcp_freebind(uv_tcp_t *handle, const struct sockaddr *addr, unsigned int flags) { int r; - uv_os_sock_t fd; + uv_os_sock_t fd = -1; r = uv_fileno((const uv_handle_t *)handle, (uv_os_fd_t *)&fd); if (r < 0) { diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index 1ef80d4e2e..c094c365a8 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -33,9 +32,9 @@ #include #include #include +#include #include "netmgr-int.h" -#include "uv-compat.h" static atomic_uint_fast32_t last_tcpquota_log = 0; @@ -175,7 +174,7 @@ tcp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { atomic_store(&sock->connected, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); LOCK(&sock->lock); sock->result = result; SIGNAL(&sock->cond); @@ -262,7 +261,7 @@ tcp_connect_cb(uv_connect_t *uvreq, int status) { result = ISC_R_TIMEDOUT; goto error; } else if (status != 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); goto error; } @@ -270,7 +269,7 @@ tcp_connect_cb(uv_connect_t *uvreq, int status) { r = uv_tcp_getpeername(&sock->uv_handle.tcp, (struct sockaddr *)&ss, &(int){ sizeof(ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto error; } @@ -586,7 +585,7 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ev0) { isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, ISC_LOG_ERROR, "uv_listen failed: %s", - isc_result_totext(isc__nm_uverr2result(r))); + isc_result_totext(isc_uverr2result(r))); isc__nm_incstats(sock, STATID_BINDFAIL); goto done; } @@ -594,7 +593,7 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ev0) { atomic_store(&sock->listening, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); if (result != ISC_R_SUCCESS) { sock->pquota = NULL; } @@ -616,7 +615,7 @@ tcp_connection_cb(uv_stream_t *server, int status) { isc_quota_t *quota = NULL; if (status != 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); goto done; } @@ -853,7 +852,7 @@ isc__nm_tcp_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { isc__nm_incstats(sock, STATID_RECVFAIL); } - isc__nm_tcp_failed_read_cb(sock, isc__nm_uverr2result(nread)); + isc__nm_tcp_failed_read_cb(sock, isc_uverr2result(nread)); goto free; } @@ -970,14 +969,14 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { r = uv_accept(&ssock->uv_handle.stream, &csock->uv_handle.stream); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } r = uv_tcp_getpeername(&csock->uv_handle.tcp, (struct sockaddr *)&ss, &(int){ sizeof(ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } @@ -990,7 +989,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { r = uv_tcp_getsockname(&csock->uv_handle.tcp, (struct sockaddr *)&ss, &(int){ sizeof(ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } @@ -1090,8 +1089,7 @@ tcp_send_cb(uv_write_t *req, int status) { if (status < 0) { isc__nm_incstats(sock, STATID_SENDFAIL); - isc__nm_failed_send_cb(sock, uvreq, - isc__nm_uverr2result(status)); + isc__nm_failed_send_cb(sock, uvreq, isc_uverr2result(status)); return; } @@ -1135,7 +1133,7 @@ tcp_send_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { r = uv_write(&req->uv_req.write, &sock->uv_handle.stream, &req->uvbuf, 1, tcp_send_cb); if (r < 0) { - return (isc__nm_uverr2result(r)); + return (isc_uverr2result(r)); } isc_nm_timer_create(req->handle, isc__nmsocket_writetimeout_cb, req, diff --git a/lib/isc/netmgr/tcpdns.c b/lib/isc/netmgr/tcpdns.c index 0d928069ab..e840cf40b3 100644 --- a/lib/isc/netmgr/tcpdns.c +++ b/lib/isc/netmgr/tcpdns.c @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -33,9 +32,9 @@ #include #include #include +#include #include "netmgr-int.h" -#include "uv-compat.h" static atomic_uint_fast32_t last_tcpdnsquota_log = 0; @@ -145,7 +144,7 @@ tcpdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { atomic_store(&sock->connected, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); error: LOCK(&sock->lock); sock->result = result; @@ -225,7 +224,7 @@ tcpdns_connect_cb(uv_connect_t *uvreq, int status) { result = ISC_R_TIMEDOUT; goto error; } else if (status != 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); goto error; } @@ -233,7 +232,7 @@ tcpdns_connect_cb(uv_connect_t *uvreq, int status) { r = uv_tcp_getpeername(&sock->uv_handle.tcp, (struct sockaddr *)&ss, &(int){ sizeof(ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto error; } @@ -325,7 +324,7 @@ isc_nm_tcpdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, static uv_os_sock_t isc__nm_tcpdns_lb_socket(isc_nm_t *mgr, sa_family_t sa_family) { isc_result_t result; - uv_os_sock_t sock; + uv_os_sock_t sock = -1; result = isc__nm_socket(sa_family, SOCK_STREAM, 0, &sock); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -552,7 +551,7 @@ isc__nm_async_tcpdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) { isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, ISC_LOG_ERROR, "uv_listen failed: %s", - isc_result_totext(isc__nm_uverr2result(r))); + isc_result_totext(isc_uverr2result(r))); isc__nm_incstats(sock, STATID_BINDFAIL); goto done; } @@ -560,7 +559,7 @@ isc__nm_async_tcpdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) { atomic_store(&sock->listening, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); if (result != ISC_R_SUCCESS) { sock->pquota = NULL; } @@ -582,7 +581,7 @@ tcpdns_connection_cb(uv_stream_t *server, int status) { isc_quota_t *quota = NULL; if (status != 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); goto done; } @@ -853,7 +852,7 @@ isc__nm_tcpdns_read_cb(uv_stream_t *stream, ssize_t nread, isc__nm_incstats(sock, STATID_RECVFAIL); } - isc__nm_failed_read_cb(sock, isc__nm_uverr2result(nread), true); + isc__nm_failed_read_cb(sock, isc_uverr2result(nread), true); goto free; } @@ -972,7 +971,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { r = uv_accept(&ssock->uv_handle.stream, &csock->uv_handle.stream); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } @@ -980,7 +979,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { (struct sockaddr *)&peer_ss, &(int){ sizeof(peer_ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } @@ -994,7 +993,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { (struct sockaddr *)&local_ss, &(int){ sizeof(local_ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } @@ -1115,8 +1114,7 @@ tcpdns_send_cb(uv_write_t *req, int status) { if (status < 0) { isc__nm_incstats(sock, STATID_SENDFAIL); - isc__nm_failed_send_cb(sock, uvreq, - isc__nm_uverr2result(status)); + isc__nm_failed_send_cb(sock, uvreq, isc_uverr2result(status)); return; } @@ -1175,14 +1173,14 @@ isc__nm_async_tcpdnssend(isc__networker_t *worker, isc__netievent_t *ev0) { /* uv_try_write not supported, send asynchronously */ } else { /* error sending data */ - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto fail; } r = uv_write(&uvreq->uv_req.write, &sock->uv_handle.stream, bufs, nbufs, tcpdns_send_cb); if (r < 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto fail; } diff --git a/lib/isc/netmgr/timer.c b/lib/isc/netmgr/timer.c index 83287750ab..7cfa433f05 100644 --- a/lib/isc/netmgr/timer.c +++ b/lib/isc/netmgr/timer.c @@ -11,10 +11,9 @@ * information regarding copyright ownership. */ -#include - #include #include +#include #include "netmgr-int.h" diff --git a/lib/isc/netmgr/tlsdns.c b/lib/isc/netmgr/tlsdns.c index 3529c35616..15b4bcdb3e 100644 --- a/lib/isc/netmgr/tlsdns.c +++ b/lib/isc/netmgr/tlsdns.c @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -33,10 +32,10 @@ #include #include #include +#include #include "netmgr-int.h" #include "openssl_shim.h" -#include "uv-compat.h" static atomic_uint_fast32_t last_tlsdnsquota_log = 0; @@ -175,7 +174,7 @@ tlsdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { atomic_store(&sock->connected, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); error: LOCK(&sock->lock); sock->result = result; @@ -254,7 +253,7 @@ tlsdns_connect_cb(uv_connect_t *uvreq, int status) { result = ISC_R_TIMEDOUT; goto error; } else if (status != 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); goto error; } @@ -262,7 +261,7 @@ tlsdns_connect_cb(uv_connect_t *uvreq, int status) { r = uv_tcp_getpeername(&sock->uv_handle.tcp, (struct sockaddr *)&ss, &(int){ sizeof(ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto error; } @@ -640,7 +639,7 @@ isc__nm_async_tlsdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) { isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, ISC_LOG_ERROR, "uv_listen failed: %s", - isc_result_totext(isc__nm_uverr2result(r))); + isc_result_totext(isc_uverr2result(r))); isc__nm_incstats(sock, STATID_BINDFAIL); goto done; } @@ -648,7 +647,7 @@ isc__nm_async_tlsdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) { atomic_store(&sock->listening, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); if (result != ISC_R_SUCCESS) { sock->pquota = NULL; } @@ -670,7 +669,7 @@ tlsdns_connection_cb(uv_stream_t *server, int status) { isc_quota_t *quota = NULL; if (status != 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); goto done; } @@ -1195,7 +1194,7 @@ free_senddata(isc_nmsocket_t *sock, const isc_result_t result) { static void tls_write_cb(uv_write_t *req, int status) { - isc_result_t result = status != 0 ? isc__nm_uverr2result(status) + isc_result_t result = status != 0 ? isc_uverr2result(status) : ISC_R_SUCCESS; isc__nm_uvreq_t *uvreq = (isc__nm_uvreq_t *)req->data; isc_nmsocket_t *sock = uvreq->sock; @@ -1271,7 +1270,7 @@ tls_cycle_output(isc_nmsocket_t *sock) { /* uv_try_write is not supported, send * asynchronously */ } else { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); isc__nm_uvreq_put(&req, sock); free_senddata(sock, result); break; @@ -1280,7 +1279,7 @@ tls_cycle_output(isc_nmsocket_t *sock) { r = uv_write(&req->uv_req.write, &sock->uv_handle.stream, &req->uvbuf, 1, tls_write_cb); if (r < 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); isc__nm_uvreq_put(&req, sock); free_senddata(sock, result); break; @@ -1408,7 +1407,7 @@ isc__nm_tlsdns_read_cb(uv_stream_t *stream, ssize_t nread, isc__nm_incstats(sock, STATID_RECVFAIL); } - isc__nm_failed_read_cb(sock, isc__nm_uverr2result(nread), true); + isc__nm_failed_read_cb(sock, isc_uverr2result(nread), true); goto free; } @@ -1528,7 +1527,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { r = uv_accept(&ssock->uv_handle.stream, &csock->uv_handle.stream); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } @@ -1536,7 +1535,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { (struct sockaddr *)&peer_ss, &(int){ sizeof(peer_ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } @@ -1550,7 +1549,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { (struct sockaddr *)&local_ss, &(int){ sizeof(local_ss) }); if (r != 0) { - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); goto failure; } diff --git a/lib/isc/netmgr/tlsstream.c b/lib/isc/netmgr/tlsstream.c index c7d7fafd33..2734bae7ae 100644 --- a/lib/isc/netmgr/tlsstream.c +++ b/lib/isc/netmgr/tlsstream.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -36,10 +35,10 @@ #include #include #include +#include #include "../openssl_shim.h" #include "netmgr-int.h" -#include "uv-compat.h" #define TLS_BUF_SIZE (UINT16_MAX) diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index df4312fba2..505cd0442b 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -12,7 +12,6 @@ */ #include -#include #include #include @@ -29,9 +28,9 @@ #include #include #include +#include #include "netmgr-int.h" -#include "uv-compat.h" #ifdef HAVE_NET_ROUTE_H #include @@ -87,7 +86,7 @@ stop_udp_child(isc_nmsocket_t *sock); static uv_os_sock_t isc__nm_udp_lb_socket(isc_nm_t *mgr, sa_family_t sa_family) { isc_result_t result; - uv_os_sock_t sock; + uv_os_sock_t sock = -1; result = isc__nm_socket(sa_family, SOCK_DGRAM, 0, &sock); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -223,7 +222,7 @@ isc_nm_listenudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, static isc_result_t route_socket(uv_os_sock_t *fdp) { isc_result_t result; - uv_os_sock_t fd; + uv_os_sock_t fd = -1; #ifdef USE_NETLINK struct sockaddr_nl sa; int r; @@ -286,7 +285,7 @@ route_connect_direct(isc_nmsocket_t *sock) { atomic_store(&sock->connected, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); error: LOCK(&sock->lock); @@ -502,7 +501,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) { atomic_store(&sock->listening, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); atomic_fetch_add(&sock->parent->rchildren, 1); if (sock->parent->result == ISC_R_UNSET) { sock->parent->result = result; @@ -603,8 +602,7 @@ udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf, * - If there was a networking error. */ if (nrecv < 0) { - isc__nm_failed_read_cb(sock, isc__nm_uverr2result(nrecv), - false); + isc__nm_failed_read_cb(sock, isc_uverr2result(nrecv), false); goto free; } @@ -796,7 +794,7 @@ udp_send_cb(uv_udp_send_t *req, int status) { REQUIRE(sock->tid == isc_nm_tid()); if (status < 0) { - result = isc__nm_uverr2result(status); + result = isc_uverr2result(status); isc__nm_incstats(sock, STATID_SENDFAIL); } @@ -837,7 +835,7 @@ udp_send_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req, r = uv_udp_send(&req->uv_req.udp_send, &sock->uv_handle.udp, &req->uvbuf, 1, sa, udp_send_cb); if (r < 0) { - return (isc__nm_uverr2result(r)); + return (isc_uverr2result(r)); } return (ISC_R_SUCCESS); @@ -914,7 +912,7 @@ udp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { atomic_store(&sock->connected, true); done: - result = isc__nm_uverr2result(r); + result = isc_uverr2result(r); error: LOCK(&sock->lock); diff --git a/lib/isc/netmgr/uv-compat.c b/lib/isc/netmgr/uv-compat.c deleted file mode 100644 index 39ec0cfed2..0000000000 --- a/lib/isc/netmgr/uv-compat.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 - -#include - -#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) */ - -#if UV_VERSION_HEX < UV_VERSION(1, 32, 0) -int -uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb) { - if (setsockopt(handle->io_watcher.fd, SOL_SOCKET, SO_LINGER, - &(struct linger){ 1, 0 }, sizeof(struct linger)) == -1) - { -#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) */ - } - - uv_close((uv_handle_t *)handle, close_cb); - return (0); -} -#endif /* UV_VERSION_HEX < UV_VERSION(1, 32, 0) */ diff --git a/lib/isc/task.c b/lib/isc/task.c index f61b46fd5d..5df035e7c7 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -20,7 +20,6 @@ #include #include -#include #include #include @@ -39,6 +38,7 @@ #include #include #include +#include #ifdef HAVE_LIBXML2 #include @@ -49,7 +49,6 @@ #include #endif /* HAVE_JSON_C */ -#include "netmgr/uv-compat.h" #include "task_p.h" /* diff --git a/lib/isc/tests/Makefile.am b/lib/isc/tests/Makefile.am index 4e93cfa3b5..07ce59c9a8 100644 --- a/lib/isc/tests/Makefile.am +++ b/lib/isc/tests/Makefile.am @@ -1,7 +1,8 @@ include $(top_srcdir)/Makefile.top AM_CPPFLAGS += \ - $(LIBISC_CFLAGS) + $(LIBISC_CFLAGS) \ + -I.. LDADD += \ libisctest.la \ diff --git a/lib/isc/tests/doh_test.c b/lib/isc/tests/doh_test.c index a2625a0a97..0d3c43448f 100644 --- a/lib/isc/tests/doh_test.c +++ b/lib/isc/tests/doh_test.c @@ -21,7 +21,6 @@ #include #include #include -#include #define UNIT_TESTING #include @@ -37,6 +36,7 @@ #include #include #include +#include #include "uv_wrap.h" #define KEEP_BEFORE @@ -44,8 +44,6 @@ #include "../netmgr/http.c" #include "../netmgr/netmgr-int.h" #include "../netmgr/socket.c" -#include "../netmgr/uv-compat.c" -#include "../netmgr/uv-compat.h" #include "../netmgr_p.h" #include "isctest.h" diff --git a/lib/isc/tests/netmgr_test.c b/lib/isc/tests/netmgr_test.c index c9c6a7504d..6c8e3ed53e 100644 --- a/lib/isc/tests/netmgr_test.c +++ b/lib/isc/tests/netmgr_test.c @@ -18,7 +18,6 @@ #include #include #include -#include #define UNIT_TESTING #include @@ -30,6 +29,7 @@ #include #include #include +#include #include "uv_wrap.h" #define KEEP_BEFORE @@ -37,8 +37,6 @@ #include "../netmgr/netmgr-int.h" #include "../netmgr/socket.c" #include "../netmgr/udp.c" -#include "../netmgr/uv-compat.c" -#include "../netmgr/uv-compat.h" #include "../netmgr_p.h" #include "isctest.h" @@ -244,7 +242,7 @@ _teardown(void **state __attribute__((unused))) { static int setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) { socklen_t addrlen = sizeof(*addr); - uv_os_sock_t fd; + uv_os_sock_t fd = -1; int r; isc_sockaddr_fromin6(addr, &in6addr_loopback, 0); diff --git a/lib/isc/tests/uv_wrap.h b/lib/isc/tests/uv_wrap.h index 5c557b8988..f81c0c01b5 100644 --- a/lib/isc/tests/uv_wrap.h +++ b/lib/isc/tests/uv_wrap.h @@ -23,14 +23,13 @@ #include #include #include -#include #include #define UNIT_TESTING #include -#include "../netmgr/uv-compat.h" +#include /* uv_udp_t */ diff --git a/lib/isc/netmgr/uverr2result.c b/lib/isc/uv.c similarity index 60% rename from lib/isc/netmgr/uverr2result.c rename to lib/isc/uv.c index 5ce953d729..af23012fca 100644 --- a/lib/isc/netmgr/uverr2result.c +++ b/lib/isc/uv.c @@ -11,15 +11,62 @@ * information regarding copyright ownership. */ -#include -#include +#include -#include -#include -#include #include +#include -#include "netmgr-int.h" +#if UV_VERSION_HEX < UV_VERSION(1, 12, 0) +#include +#include + +#endif + +#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) */ + +#if UV_VERSION_HEX < UV_VERSION(1, 32, 0) +int +uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb) { + if (setsockopt(handle->io_watcher.fd, SOL_SOCKET, SO_LINGER, + &(struct linger){ 1, 0 }, sizeof(struct linger)) == -1) + { +#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) */ + } + + INSIST(!uv_is_closing((uv_handle_t *)handle)); + uv_close((uv_handle_t *)handle, close_cb); + return (0); +} +#endif /* UV_VERSION_HEX < UV_VERSION(1, 32, 0) */ + +#define setsockopt_on(socket, level, name) \ + setsockopt(socket, level, name, &(int){ 1 }, sizeof(int)) /*% * Convert a libuv error value into an isc_result_t. The @@ -28,8 +75,8 @@ * not already there. */ isc_result_t -isc___nm_uverr2result(int uverr, bool dolog, const char *file, - unsigned int line, const char *func) { +isc__uverr2result(int uverr, bool dolog, const char *file, unsigned int line, + const char *func) { switch (uverr) { case 0: return (ISC_R_SUCCESS); diff --git a/lib/ns/hooks.c b/lib/ns/hooks.c index 27c14ed098..702d020840 100644 --- a/lib/ns/hooks.c +++ b/lib/ns/hooks.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #include From 88b109514c0be9d335129dadc05b61f2b847c4a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 3 May 2022 10:04:23 +0200 Subject: [PATCH 3/3] Add CHANGES note for [GL !6199] --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index bd6f729be3..b0e770e88c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +5883. [cleanup] Move netmgr/uv-compat.{c,h} to , so + the compatibility libuv shims could be used outside + the network manager. [GL !6199] + 5882. [contrib] Avoid name space collision in dlz modules by prefixing functions with 'dlz_'. [GL !5778]