summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/bind/lib/isc/Makefile.in4
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/Makefile.in6
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/interfaceiter.h132
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/os.h37
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/resource.h96
-rw-r--r--usr.sbin/bind/lib/isc/include/isc/types.h16
-rw-r--r--usr.sbin/bind/lib/isc/unix/Makefile.in13
-rw-r--r--usr.sbin/bind/lib/isc/unix/ifiter_getifaddrs.c233
-rw-r--r--usr.sbin/bind/lib/isc/unix/ifiter_ioctl.c882
-rw-r--r--usr.sbin/bind/lib/isc/unix/ifiter_sysctl.c289
-rw-r--r--usr.sbin/bind/lib/isc/unix/include/isc/Makefile.in4
-rw-r--r--usr.sbin/bind/lib/isc/unix/include/isc/keyboard.h51
-rw-r--r--usr.sbin/bind/lib/isc/unix/interfaceiter.c302
-rw-r--r--usr.sbin/bind/lib/isc/unix/keyboard.c125
-rw-r--r--usr.sbin/bind/lib/isc/unix/os.c93
-rw-r--r--usr.sbin/bind/lib/isc/unix/privsep_fdpass.c123
-rw-r--r--usr.sbin/bind/lib/isc/unix/resource.c230
-rw-r--r--usr.sbin/bind/lib/isc/unix/socket.c654
-rw-r--r--usr.sbin/bind/lib/isccfg/namedconf.c2
19 files changed, 14 insertions, 3278 deletions
diff --git a/usr.sbin/bind/lib/isc/Makefile.in b/usr.sbin/bind/lib/isc/Makefile.in
index 39c6b213645..890d26b100f 100644
--- a/usr.sbin/bind/lib/isc/Makefile.in
+++ b/usr.sbin/bind/lib/isc/Makefile.in
@@ -33,8 +33,8 @@ CWARNINGS =
UNIXOBJS = @ISC_ISCIPV6_O@ @ISC_ISCPK11_API_O@ \
unix/app.@O@ unix/dir.@O@ unix/errno.@O@ \
unix/errno2result.@O@ unix/file.@O@ unix/fsaccess.@O@ \
- unix/interfaceiter.@O@ unix/keyboard.@O@ unix/net.@O@ \
- unix/os.@O@ unix/resource.@O@ unix/socket.@O@ unix/stdio.@O@ \
+ unix/net.@O@ \
+ unix/socket.@O@ unix/stdio.@O@ \
unix/stdtime.@O@ unix/strerror.@O@ unix/syslog.@O@ unix/time.@O@
NLSOBJS = nls/msgcat.@O@
diff --git a/usr.sbin/bind/lib/isc/include/isc/Makefile.in b/usr.sbin/bind/lib/isc/include/isc/Makefile.in
index 2a71b2affb4..8c68da3d283 100644
--- a/usr.sbin/bind/lib/isc/include/isc/Makefile.in
+++ b/usr.sbin/bind/lib/isc/include/isc/Makefile.in
@@ -28,13 +28,13 @@ HEADERS = aes.h app.h assertions.h base32.h base64.h \
commandline.h counter.h crc64.h errno.h error.h \
event.h eventclass.h file.h formatcheck.h fsaccess.h \
hash.h heap.h hex.h hmacmd5.h hmacsha.h httpd.h \
- interfaceiter.h @ISC_IPV6_H@ iterated_hash.h json.h \
+ @ISC_IPV6_H@ iterated_hash.h json.h \
lang.h lex.h lfsr.h lib.h likely.h list.h log.h \
magic.h md5.h mem.h msgcat.h msgs.h mutexblock.h \
- netaddr.h netscope.h ondestroy.h os.h parseint.h \
+ netaddr.h netscope.h ondestroy.h parseint.h \
pool.h portset.h print.h queue.h quota.h \
radix.h ratelimiter.h refcount.h regex.h \
- region.h resource.h result.h resultclass.h rwlock.h \
+ region.h result.h resultclass.h rwlock.h \
safe.h serial.h sha1.h sha2.h sockaddr.h socket.h \
stdio.h stdlib.h string.h symtab.h task.h \
taskpool.h timer.h tm.h types.h util.h version.h \
diff --git a/usr.sbin/bind/lib/isc/include/isc/interfaceiter.h b/usr.sbin/bind/lib/isc/include/isc/interfaceiter.h
deleted file mode 100644
index 159f28d1579..00000000000
--- a/usr.sbin/bind/lib/isc/include/isc/interfaceiter.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: interfaceiter.h,v 1.4 2020/01/09 18:17:19 florian Exp $ */
-
-#ifndef INTERFACEITER_H
-#define INTERFACEITER_H 1
-
-/*****
- ***** Module Info
- *****/
-
-/*! \file isc/interfaceiter.h
- * \brief Iterates over the list of network interfaces.
- *
- * Interfaces whose address family is not supported are ignored and never
- * returned by the iterator. Interfaces whose netmask, interface flags,
- * or similar cannot be obtained are also ignored, and the failure is logged.
- *
- * Standards:
- * The API for scanning varies greatly among operating systems.
- * This module attempts to hide the differences.
- */
-
-/***
- *** Imports
- ***/
-
-#include <isc/lang.h>
-#include <isc/netaddr.h>
-#include <isc/types.h>
-
-/*!
- * \brief Public structure describing a network interface.
- */
-
-struct interface {
- char name[32]; /*%< Interface name, null-terminated. */
- unsigned int af; /*%< Address family. */
- isc_netaddr_t address; /*%< Local address. */
- isc_netaddr_t netmask; /*%< Network mask. */
- isc_netaddr_t dstaddress; /*%< Destination address (point-to-point only). */
- uint32_t flags; /*%< Flags; see INTERFACE flags. */
-};
-
-/*@{*/
-/*! Interface flags. */
-
-#define INTERFACE_F_UP 0x00000001U
-#define INTERFACE_F_POINTTOPOINT 0x00000002U
-#define INTERFACE_F_LOOPBACK 0x00000004U
-/*@}*/
-
-/***
- *** Functions
- ***/
-
-ISC_LANG_BEGINDECLS
-
-isc_result_t
-interfaceiter_create(isc_mem_t *mctx, interfaceiter_t **iterp);
-/*!<
- * \brief Create an iterator for traversing the operating system's list
- * of network interfaces.
- *
- * Returns:
- *\li #ISC_R_SUCCESS
- * \li #ISC_R_NOMEMORY
- *\li Various network-related errors
- */
-
-isc_result_t
-interfaceiter_first(interfaceiter_t *iter);
-/*!<
- * \brief Position the iterator on the first interface.
- *
- * Returns:
- *\li #ISC_R_SUCCESS Success.
- *\li #ISC_R_NOMORE There are no interfaces.
- */
-
-isc_result_t
-interfaceiter_current(interfaceiter_t *iter,
- interface_t *ifdata);
-/*!<
- * \brief Get information about the interface the iterator is currently
- * positioned at and store it at *ifdata.
- *
- * Requires:
- *\li The iterator has been successfully positioned using
- * interface_iter_first() / interface_iter_next().
- *
- * Returns:
- *\li #ISC_R_SUCCESS Success.
- */
-
-isc_result_t
-interfaceiter_next(interfaceiter_t *iter);
-/*!<
- * \brief Position the iterator on the next interface.
- *
- * Requires:
- * \li The iterator has been successfully positioned using
- * interface_iter_first() / interface_iter_next().
- *
- * Returns:
- *\li #ISC_R_SUCCESS Success.
- *\li #ISC_R_NOMORE There are no more interfaces.
- */
-
-void
-interfaceiter_destroy(interfaceiter_t **iterp);
-/*!<
- * \brief Destroy the iterator.
- */
-
-ISC_LANG_ENDDECLS
-
-#endif /* INTERFACEITER_H */
diff --git a/usr.sbin/bind/lib/isc/include/isc/os.h b/usr.sbin/bind/lib/isc/include/isc/os.h
deleted file mode 100644
index 2de61cba7aa..00000000000
--- a/usr.sbin/bind/lib/isc/include/isc/os.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: os.h,v 1.3 2019/12/17 01:46:35 sthen Exp $ */
-
-#ifndef ISC_OS_H
-#define ISC_OS_H 1
-
-/*! \file isc/os.h */
-
-#include <isc/lang.h>
-
-ISC_LANG_BEGINDECLS
-
-unsigned int
-isc_os_ncpus(void);
-/*%<
- * Return the number of CPUs available on the system, or 1 if this cannot
- * be determined.
- */
-
-ISC_LANG_ENDDECLS
-
-#endif /* ISC_OS_H */
diff --git a/usr.sbin/bind/lib/isc/include/isc/resource.h b/usr.sbin/bind/lib/isc/include/isc/resource.h
deleted file mode 100644
index 0c4afebd27c..00000000000
--- a/usr.sbin/bind/lib/isc/include/isc/resource.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: resource.h,v 1.5 2020/01/09 18:17:19 florian Exp $ */
-
-#ifndef ISC_RESOURCE_H
-#define ISC_RESOURCE_H 1
-
-/*! \file isc/resource.h */
-#include <stdint.h>
-#include <isc/lang.h>
-#include <isc/types.h>
-
-#define ISC_RESOURCE_UNLIMITED ((isc_resourcevalue_t)UINT64_MAX)
-
-ISC_LANG_BEGINDECLS
-
-isc_result_t
-isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value);
-/*%<
- * Set the maximum limit for a system resource.
- *
- * Notes:
- *\li If 'value' exceeds the maximum possible on the operating system,
- * it is silently limited to that maximum -- or to "infinity", if
- * the operating system has that concept. #ISC_RESOURCE_UNLIMITED
- * can be used to explicitly ask for the maximum.
- *
- * Requires:
- *\li 'resource' is a valid member of the isc_resource_t enumeration.
- *
- * Returns:
- *\li #ISC_R_SUCCESS Success.
- *\li #ISC_R_NOTIMPLEMENTED 'resource' is not a type known by the OS.
- *\li #ISC_R_NOPERM The calling process did not have adequate permission
- * to change the resource limit.
- */
-
-isc_result_t
-isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value);
-/*%<
- * Get the maximum limit for a system resource.
- *
- * Notes:
- *\li 'value' is set to the maximum limit.
- *
- *\li #ISC_RESOURCE_UNLIMITED is the maximum value of isc_resourcevalue_t.
- *
- *\li On many (all?) Unix systems, RLIM_INFINITY is a valid value that is
- * significantly less than #ISC_RESOURCE_UNLIMITED, but which in practice
- * behaves the same.
- *
- *\li The current ISC libdns configuration file parser assigns a value
- * of UINT32_MAX for a size_spec of "unlimited" and ISC_UNIT32_MAX - 1
- * for "default", the latter of which is supposed to represent "the
- * limit that was in force when the server started". Since these are
- * valid values in the middle of the range of isc_resourcevalue_t,
- * there is the possibility for confusion over what exactly those
- * particular values are supposed to represent in a particular context --
- * discrete integral values or generalized concepts.
- *
- * Requires:
- *\li 'resource' is a valid member of the isc_resource_t enumeration.
- *
- * Returns:
- *\li #ISC_R_SUCCESS Success.
- *\li #ISC_R_NOTIMPLEMENTED 'resource' is not a type known by the OS.
- */
-
-isc_result_t
-isc_resource_getcurlimit(isc_resource_t resource, isc_resourcevalue_t *value);
-/*%<
- * Same as isc_resource_getlimit(), but returns the current (soft) limit.
- *
- * Returns:
- *\li #ISC_R_SUCCESS Success.
- *\li #ISC_R_NOTIMPLEMENTED 'resource' is not a type known by the OS.
- */
-
-ISC_LANG_ENDDECLS
-
-#endif /* ISC_RESOURCE_H */
-
diff --git a/usr.sbin/bind/lib/isc/include/isc/types.h b/usr.sbin/bind/lib/isc/include/isc/types.h
index b0a33684cef..a5ee0fb9ca6 100644
--- a/usr.sbin/bind/lib/isc/include/isc/types.h
+++ b/usr.sbin/bind/lib/isc/include/isc/types.h
@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: types.h,v 1.9 2020/01/09 18:17:19 florian Exp $ */
+/* $Id: types.h,v 1.10 2020/01/09 19:50:35 florian Exp $ */
#ifndef ISC_TYPES_H
#define ISC_TYPES_H 1
@@ -76,7 +76,6 @@ typedef struct isc_quota isc_quota_t; /*%< Quota */
typedef struct isc_random isc_random_t; /*%< Random */
typedef struct isc_ratelimiter isc_ratelimiter_t; /*%< Rate Limiter */
typedef struct isc_region isc_region_t; /*%< Region */
-typedef uint64_t isc_resourcevalue_t; /*%< Resource Value */
typedef unsigned int isc_result_t; /*%< Result */
typedef struct isc_rwlock isc_rwlock_t; /*%< Read Write Lock */
typedef struct isc_sockaddr isc_sockaddr_t; /*%< Socket Address */
@@ -112,19 +111,6 @@ typedef isc_result_t (isc_httpdaction_t)(const char *url,
void **freecb_args);
typedef isc_boolean_t (isc_httpdclientok_t)(const isc_sockaddr_t *, void *);
-/*% Resource */
-typedef enum {
- isc_resource_coresize = 1,
- isc_resource_cputime,
- isc_resource_datasize,
- isc_resource_filesize,
- isc_resource_lockedmemory,
- isc_resource_openfiles,
- isc_resource_processes,
- isc_resource_residentsize,
- isc_resource_stacksize
-} isc_resource_t;
-
/*% Statistics formats (text file or XML) */
typedef enum {
isc_statsformat_file,
diff --git a/usr.sbin/bind/lib/isc/unix/Makefile.in b/usr.sbin/bind/lib/isc/unix/Makefile.in
index 3384f95ea79..9cb000d8478 100644
--- a/usr.sbin/bind/lib/isc/unix/Makefile.in
+++ b/usr.sbin/bind/lib/isc/unix/Makefile.in
@@ -28,22 +28,19 @@ CWARNINGS =
# Alphabetically
OBJS = @ISC_IPV6_O@ @ISC_PK11_API_O@ \
app.@O@ dir.@O@ errno.@O@ errno2result.@O@ \
- file.@O@ fsaccess.@O@ interfaceiter.@O@ \
- keyboard.@O@ net.@O@ \
- os.@O@ resource.@O@ socket.@O@ stdio.@O@ stdtime.@O@ \
+ file.@O@ fsaccess.@O@ \
+ net.@O@ \
+ socket.@O@ stdio.@O@ stdtime.@O@ \
strerror.@O@ syslog.@O@ time.@O@
# Alphabetically
SRCS = @ISC_IPV6_C@ @ISC_PK11_API_C@ \
app.c dir.c errno.c errno2result.c file.c \
- fsaccess.c interfaceiter.c keyboard.c net.c \
- os.c resource.c socket.c stdio.c stdtime.c \
+ fsaccess.c net.c \
+ socket.c stdio.c stdtime.c \
strerror.c syslog.c time.c
SUBDIRS = include
TARGETS = ${OBJS}
@BIND9_MAKE_RULES@
-
-interfaceiter.@O@: interfaceiter.c ifiter_ioctl.c ifiter_sysctl.c ifiter_getifaddrs.c
-
diff --git a/usr.sbin/bind/lib/isc/unix/ifiter_getifaddrs.c b/usr.sbin/bind/lib/isc/unix/ifiter_getifaddrs.c
deleted file mode 100644
index f0f583348af..00000000000
--- a/usr.sbin/bind/lib/isc/unix/ifiter_getifaddrs.c
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: ifiter_getifaddrs.c,v 1.4 2020/01/09 18:17:19 florian Exp $ */
-
-/*! \file
- * \brief
- * Obtain the list of network interfaces using the getifaddrs(3) library.
- */
-
-#include <ifaddrs.h>
-
-/*% Iterator Magic */
-#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'G')
-/*% Valid Iterator */
-#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
-
-#ifdef __linux
-static isc_boolean_t seenv6 = ISC_FALSE;
-#endif
-
-/*% Iterator structure */
-struct interfaceiter {
- unsigned int magic; /*%< Magic number. */
- isc_mem_t *mctx;
- void *buf; /*%< (unused) */
- unsigned int bufsize; /*%< (always 0) */
- struct ifaddrs *ifaddrs; /*%< List of ifaddrs */
- struct ifaddrs *pos; /*%< Ptr to current ifaddr */
- interface_t current; /*%< Current interface data. */
- isc_result_t result; /*%< Last result code. */
-#ifdef __linux
- FILE * proc;
- char entry[ISC_IF_INET6_SZ];
- isc_result_t valid;
-#endif
-};
-
-isc_result_t
-interfaceiter_create(isc_mem_t *mctx, interfaceiter_t **iterp) {
- interfaceiter_t *iter;
- isc_result_t result;
- char strbuf[ISC_STRERRORSIZE];
-
- REQUIRE(mctx != NULL);
- REQUIRE(iterp != NULL);
- REQUIRE(*iterp == NULL);
-
- iter = isc_mem_get(mctx, sizeof(*iter));
- if (iter == NULL)
- return (ISC_R_NOMEMORY);
-
- iter->mctx = mctx;
- iter->buf = NULL;
- iter->bufsize = 0;
- iter->ifaddrs = NULL;
-#ifdef __linux
- /*
- * Only open "/proc/net/if_inet6" if we have never seen a IPv6
- * address returned by getifaddrs().
- */
- if (!seenv6)
- iter->proc = fopen("/proc/net/if_inet6", "r");
- else
- iter->proc = NULL;
- iter->valid = ISC_R_FAILURE;
-#endif
-
- if (getifaddrs(&iter->ifaddrs) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERGETIFADDRS,
- ISC_MSG_GETIFADDRS,
- "getting interface "
- "addresses: getifaddrs: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto failure;
- }
-
- /*
- * A newly created iterator has an undefined position
- * until interfaceiter_first() is called.
- */
- iter->pos = NULL;
- iter->result = ISC_R_FAILURE;
-
- iter->magic = IFITER_MAGIC;
- *iterp = iter;
- return (ISC_R_SUCCESS);
-
- failure:
-#ifdef __linux
- if (iter->proc != NULL)
- fclose(iter->proc);
-#endif
- if (iter->ifaddrs != NULL) /* just in case */
- freeifaddrs(iter->ifaddrs);
- isc_mem_put(mctx, iter, sizeof(*iter));
- return (result);
-}
-
-/*
- * Get information about the current interface to iter->current.
- * If successful, return ISC_R_SUCCESS.
- * If the interface has an unsupported address family,
- * return ISC_R_IGNORE.
- */
-
-static isc_result_t
-internal_current(interfaceiter_t *iter) {
- struct ifaddrs *ifa;
- int family;
- unsigned int namelen;
-
- REQUIRE(VALID_IFITER(iter));
-
- ifa = iter->pos;
-
-#ifdef __linux
- if (iter->pos == NULL)
- return (linux_if_inet6_current(iter));
-#endif
-
- INSIST(ifa != NULL);
- INSIST(ifa->ifa_name != NULL);
-
- if (ifa->ifa_addr == NULL)
- return (ISC_R_IGNORE);
-
- family = ifa->ifa_addr->sa_family;
- if (family != AF_INET && family != AF_INET6)
- return (ISC_R_IGNORE);
-
-#ifdef __linux
- if (family == AF_INET6)
- seenv6 = ISC_TRUE;
-#endif
-
- memset(&iter->current, 0, sizeof(iter->current));
-
- namelen = strlen(ifa->ifa_name);
- if (namelen > sizeof(iter->current.name) - 1)
- namelen = sizeof(iter->current.name) - 1;
-
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memmove(iter->current.name, ifa->ifa_name, namelen);
-
- iter->current.flags = 0;
-
- if ((ifa->ifa_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
- if ((ifa->ifa_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-
- if ((ifa->ifa_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
- iter->current.af = family;
-
- get_addr(family, &iter->current.address, ifa->ifa_addr, ifa->ifa_name);
-
- if (ifa->ifa_netmask != NULL)
- get_addr(family, &iter->current.netmask, ifa->ifa_netmask,
- ifa->ifa_name);
-
- if (ifa->ifa_dstaddr != NULL &&
- (iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0)
- get_addr(family, &iter->current.dstaddress, ifa->ifa_dstaddr,
- ifa->ifa_name);
-
- return (ISC_R_SUCCESS);
-}
-
-/*
- * Step the iterator to the next interface. Unlike
- * interfaceiter_next(), this may leave the iterator
- * positioned on an interface that will ultimately
- * be ignored. Return ISC_R_NOMORE if there are no more
- * interfaces, otherwise ISC_R_SUCCESS.
- */
-static isc_result_t
-internal_next(interfaceiter_t *iter) {
-
- if (iter->pos != NULL)
- iter->pos = iter->pos->ifa_next;
- if (iter->pos == NULL) {
-#ifdef __linux
- if (!seenv6)
- return (linux_if_inet6_next(iter));
-#endif
- return (ISC_R_NOMORE);
- }
-
- return (ISC_R_SUCCESS);
-}
-
-static void
-internal_destroy(interfaceiter_t *iter) {
-
-#ifdef __linux
- if (iter->proc != NULL)
- fclose(iter->proc);
- iter->proc = NULL;
-#endif
- if (iter->ifaddrs)
- freeifaddrs(iter->ifaddrs);
- iter->ifaddrs = NULL;
-}
-
-static
-void internal_first(interfaceiter_t *iter) {
-
-#ifdef __linux
- linux_if_inet6_first(iter);
-#endif
- iter->pos = iter->ifaddrs;
-}
diff --git a/usr.sbin/bind/lib/isc/unix/ifiter_ioctl.c b/usr.sbin/bind/lib/isc/unix/ifiter_ioctl.c
deleted file mode 100644
index 6fd8c4d26cb..00000000000
--- a/usr.sbin/bind/lib/isc/unix/ifiter_ioctl.c
+++ /dev/null
@@ -1,882 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: ifiter_ioctl.c,v 1.13 2020/01/09 18:17:19 florian Exp $ */
-
-
-
-/*! \file
- * \brief
- * Obtain the list of network interfaces using the SIOCGLIFCONF ioctl.
- * See netintro(4).
- */
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-#define ISC_HAVE_LIFC_FAMILY 1
-#define ISC_HAVE_LIFC_FLAGS 1
-#define LIFCONF lifconf
-
-#define LIFREQ lifreq
-#endif
-
-#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'T')
-#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
-
-struct interfaceiter {
- unsigned int magic; /* Magic number. */
- isc_mem_t *mctx;
- int mode;
- int socket;
- struct ifconf ifc;
- void *buf; /* Buffer for sysctl data. */
- unsigned int bufsize; /* Bytes allocated. */
- unsigned int pos; /* Current offset in
- SIOCGIFCONF data */
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- int socket6;
- struct LIFCONF lifc;
- void *buf6; /* Buffer for sysctl data. */
- unsigned int bufsize6; /* Bytes allocated. */
- unsigned int pos6; /* Current offset in
- SIOCGLIFCONF data */
- isc_result_t result6; /* Last result code. */
- isc_boolean_t first6;
-#endif
-#ifdef HAVE_TRUCLUSTER
- int clua_context; /* Cluster alias context */
- isc_boolean_t clua_done;
- struct sockaddr clua_sa;
-#endif
-#ifdef __linux
- FILE * proc;
- char entry[ISC_IF_INET6_SZ];
- isc_result_t valid;
-#endif
- interface_t current; /* Current interface data. */
- isc_result_t result; /* Last result code. */
-};
-
-#ifdef HAVE_TRUCLUSTER
-#include <clua/clua.h>
-#include <sys/socket.h>
-#endif
-
-
-/*%
- * Size of buffer for SIOCGLIFCONF, in bytes. We assume no sane system
- * will have more than a megabyte of interface configuration data.
- */
-#define IFCONF_BUFSIZE_INITIAL 4096
-#define IFCONF_BUFSIZE_MAX 1048576
-
-#ifdef __linux
-#ifndef IF_NAMESIZE
-# ifdef IFNAMSIZ
-# define IF_NAMESIZE IFNAMSIZ
-# else
-# define IF_NAMESIZE 16
-# endif
-#endif
-#endif
-
-static isc_result_t
-getbuf4(interfaceiter_t *iter) {
- char strbuf[ISC_STRERRORSIZE];
-
- iter->bufsize = IFCONF_BUFSIZE_INITIAL;
-
- for (;;) {
- iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
- if (iter->buf == NULL)
- return (ISC_R_NOMEMORY);
-
- memset(&iter->ifc.ifc_len, 0, sizeof(iter->ifc.ifc_len));
- iter->ifc.ifc_len = iter->bufsize;
- iter->ifc.ifc_buf = iter->buf;
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion". It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFCONF, (char *)&iter->ifc)
- == -1) {
- if (errno != EINVAL) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "get interface "
- "configuration: %s"),
- strbuf);
- goto unexpected;
- }
- /*
- * EINVAL. Retry with a bigger buffer.
- */
- } else {
- /*
- * The ioctl succeeded.
- * Some OS's just return what will fit rather
- * than set EINVAL if the buffer is too small
- * to fit all the interfaces in. If
- * ifc.lifc_len is too near to the end of the
- * buffer we will grow it just in case and
- * retry.
- */
- if (iter->ifc.ifc_len + 2 * sizeof(struct ifreq)
- < iter->bufsize)
- break;
- }
- if (iter->bufsize >= IFCONF_BUFSIZE_MAX) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_BUFFERMAX,
- "get interface "
- "configuration: "
- "maximum buffer "
- "size exceeded"));
- goto unexpected;
- }
- isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
-
- iter->bufsize *= 2;
- }
- return (ISC_R_SUCCESS);
-
- unexpected:
- isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
- iter->buf = NULL;
- return (ISC_R_UNEXPECTED);
-}
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-static isc_result_t
-getbuf6(interfaceiter_t *iter) {
- char strbuf[ISC_STRERRORSIZE];
- isc_result_t result;
-
- iter->bufsize6 = IFCONF_BUFSIZE_INITIAL;
-
- for (;;) {
- iter->buf6 = isc_mem_get(iter->mctx, iter->bufsize6);
- if (iter->buf6 == NULL)
- return (ISC_R_NOMEMORY);
-
- memset(&iter->lifc, 0, sizeof(iter->lifc));
-#ifdef ISC_HAVE_LIFC_FAMILY
- iter->lifc.lifc_family = AF_INET6;
-#endif
-#ifdef ISC_HAVE_LIFC_FLAGS
- iter->lifc.lifc_flags = 0;
-#endif
- iter->lifc.lifc_len = iter->bufsize6;
- iter->lifc.lifc_buf = iter->buf6;
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion". It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket6, SIOCGLIFCONF, (char *)&iter->lifc)
- == -1) {
-#ifdef __hpux
- /*
- * IPv6 interface scanning is not available on all
- * kernels w/ IPv6 sockets.
- */
- if (errno == ENOENT) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_INTERFACE,
- ISC_LOG_DEBUG(1),
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "get interface "
- "configuration: %s"),
- strbuf);
- result = ISC_R_FAILURE;
- goto cleanup;
- }
-#endif
- if (errno != EINVAL) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "get interface "
- "configuration: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto cleanup;
- }
- /*
- * EINVAL. Retry with a bigger buffer.
- */
- } else {
- /*
- * The ioctl succeeded.
- * Some OS's just return what will fit rather
- * than set EINVAL if the buffer is too small
- * to fit all the interfaces in. If
- * ifc.ifc_len is too near to the end of the
- * buffer we will grow it just in case and
- * retry.
- */
- if (iter->lifc.lifc_len + 2 * sizeof(struct LIFREQ)
- < iter->bufsize6)
- break;
- }
- if (iter->bufsize6 >= IFCONF_BUFSIZE_MAX) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_BUFFERMAX,
- "get interface "
- "configuration: "
- "maximum buffer "
- "size exceeded"));
- result = ISC_R_UNEXPECTED;
- goto cleanup;
- }
- isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
-
- iter->bufsize6 *= 2;
- }
-
- if (iter->lifc.lifc_len != 0)
- iter->mode = 6;
- return (ISC_R_SUCCESS);
-
- cleanup:
- isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
- iter->buf6 = NULL;
- return (result);
-}
-#endif
-
-isc_result_t
-interfaceiter_create(isc_mem_t *mctx, interfaceiter_t **iterp) {
- interfaceiter_t *iter;
- isc_result_t result;
- char strbuf[ISC_STRERRORSIZE];
-
- REQUIRE(mctx != NULL);
- REQUIRE(iterp != NULL);
- REQUIRE(*iterp == NULL);
-
- iter = isc_mem_get(mctx, sizeof(*iter));
- if (iter == NULL)
- return (ISC_R_NOMEMORY);
-
- iter->mctx = mctx;
- iter->mode = 4;
- iter->buf = NULL;
- iter->pos = (unsigned int) -1;
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- iter->buf6 = NULL;
- iter->pos6 = (unsigned int) -1;
- iter->result6 = ISC_R_NOMORE;
- iter->socket6 = -1;
- iter->first6 = ISC_FALSE;
-#endif
-
- /*
- * Get the interface configuration, allocating more memory if
- * necessary.
- */
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- result = isc_net_probeipv6();
- if (result == ISC_R_SUCCESS) {
- /*
- * Create an unbound datagram socket to do the SIOCGLIFCONF
- * ioctl on. HP/UX requires an AF_INET6 socket for
- * SIOCGLIFCONF to get IPv6 addresses.
- */
- if ((iter->socket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_MAKESCANSOCKET,
- "making interface "
- "scan socket: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto socket6_failure;
- }
- result = iter->result6 = getbuf6(iter);
- if (result != ISC_R_NOTIMPLEMENTED && result != ISC_R_SUCCESS)
- goto ioctl6_failure;
- }
-#endif
- if ((iter->socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_MAKESCANSOCKET,
- "making interface "
- "scan socket: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto socket_failure;
- }
- result = getbuf4(iter);
- if (result != ISC_R_SUCCESS)
- goto ioctl_failure;
-
- /*
- * A newly created iterator has an undefined position
- * until interfaceiter_first() is called.
- */
-#ifdef HAVE_TRUCLUSTER
- iter->clua_context = -1;
- iter->clua_done = ISC_TRUE;
-#endif
-#ifdef __linux
- iter->proc = fopen("/proc/net/if_inet6", "r");
- iter->valid = ISC_R_FAILURE;
-#endif
- iter->result = ISC_R_FAILURE;
-
- iter->magic = IFITER_MAGIC;
- *iterp = iter;
- return (ISC_R_SUCCESS);
-
- ioctl_failure:
- if (iter->buf != NULL)
- isc_mem_put(mctx, iter->buf, iter->bufsize);
- (void) close(iter->socket);
-
- socket_failure:
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->buf6 != NULL)
- isc_mem_put(mctx, iter->buf6, iter->bufsize6);
- ioctl6_failure:
- if (iter->socket6 != -1)
- (void) close(iter->socket6);
- socket6_failure:
-#endif
-
- isc_mem_put(mctx, iter, sizeof(*iter));
- return (result);
-}
-
-#ifdef HAVE_TRUCLUSTER
-static void
-get_inaddr(isc_netaddr_t *dst, struct in_addr *src) {
- dst->family = AF_INET;
- memmove(&dst->type.in, src, sizeof(struct in_addr));
-}
-
-static isc_result_t
-internal_current_clusteralias(interfaceiter_t *iter) {
- struct clua_info ci;
- if (clua_getaliasinfo(&iter->clua_sa, &ci) != CLUA_SUCCESS)
- return (ISC_R_IGNORE);
- memset(&iter->current, 0, sizeof(iter->current));
- iter->current.af = iter->clua_sa.sa_family;
- memset(iter->current.name, 0, sizeof(iter->current.name));
- snprintf(iter->current.name, sizeof(iter->current.name),
- "clua%d", ci.aliasid);
- iter->current.flags = INTERFACE_F_UP;
- get_inaddr(&iter->current.address, &ci.addr);
- get_inaddr(&iter->current.netmask, &ci.netmask);
- return (ISC_R_SUCCESS);
-}
-#endif
-
-/*
- * Get information about the current interface to iter->current.
- * If successful, return ISC_R_SUCCESS.
- * If the interface has an unsupported address family, or if
- * some operation on it fails, return ISC_R_IGNORE to make
- * the higher-level iterator code ignore it.
- */
-
-static isc_result_t
-internal_current4(interfaceiter_t *iter) {
- struct ifreq *ifrp;
- struct ifreq ifreq;
- int family;
- char strbuf[ISC_STRERRORSIZE];
- char sabuf[256];
- int i, bits, prefixlen;
-
- REQUIRE(VALID_IFITER(iter));
-
- if (iter->ifc.ifc_len == 0 ||
- iter->pos == (unsigned int)iter->ifc.ifc_len) {
-#ifdef __linux
- return (linux_if_inet6_current(iter));
-#else
- return (ISC_R_NOMORE);
-#endif
- }
-
- INSIST( iter->pos < (unsigned int) iter->ifc.ifc_len);
-
- ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
-
- memset(&ifreq, 0, sizeof(ifreq));
- memmove(&ifreq, ifrp, sizeof(ifreq));
-
- family = ifreq.ifr_addr.sa_family;
- if (family != AF_INET && family != AF_INET6)
- return (ISC_R_IGNORE);
-
- memset(&iter->current, 0, sizeof(iter->current));
- iter->current.af = family;
-
- INSIST(sizeof(ifreq.ifr_name) <= sizeof(iter->current.name));
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memmove(iter->current.name, ifreq.ifr_name, sizeof(ifreq.ifr_name));
-
- get_addr(family, &iter->current.address,
- (struct sockaddr *)&ifrp->ifr_addr, ifreq.ifr_name);
-
- /*
- * If the interface does not have a address ignore it.
- */
- switch (family) {
- case AF_INET:
- if (iter->current.address.type.in.s_addr == htonl(INADDR_ANY))
- return (ISC_R_IGNORE);
- break;
- case AF_INET6:
- if (memcmp(&iter->current.address.type.in6, &in6addr_any,
- sizeof(in6addr_any)) == 0)
- return (ISC_R_IGNORE);
- break;
- }
-
- /*
- * Get interface flags.
- */
-
- iter->current.flags = 0;
-
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "%s: getting interface flags: %s",
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
-
- if ((ifreq.ifr_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
-#ifdef IFF_POINTOPOINT
- if ((ifreq.ifr_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-#endif
-
- if ((ifreq.ifr_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
- if (family == AF_INET)
- goto inet;
-
- isc_netaddr_format(&iter->current.address, sabuf, sizeof(sabuf));
- isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_INTERFACE,
- ISC_LOG_INFO,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "prefix length for %s is unknown "
- "(assume 128)"), sabuf);
- prefixlen = 128;
-
- /*
- * Netmask already zeroed.
- */
- iter->current.netmask.family = family;
- for (i = 0; i < 16; i++) {
- if (prefixlen > 8) {
- bits = 0;
- prefixlen -= 8;
- } else {
- bits = 8 - prefixlen;
- prefixlen = 0;
- }
- iter->current.netmask.type.in6.s6_addr[i] =
- (~0U << bits) & 0xff;
- }
- return (ISC_R_SUCCESS);
-
- inet:
- if (family != AF_INET)
- return (ISC_R_IGNORE);
-#ifdef IFF_POINTOPOINT
- /*
- * If the interface is point-to-point, get the destination address.
- */
- if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFDSTADDR, (char *)&ifreq)
- < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETDESTADDR,
- "%s: getting "
- "destination address: %s"),
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.dstaddress,
- (struct sockaddr *)&ifreq.ifr_dstaddr, ifreq.ifr_name);
- }
-#endif
-
- /*
- * Get the network mask.
- */
- memset(&ifreq, 0, sizeof(ifreq));
- memmove(&ifreq, ifrp, sizeof(ifreq));
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFNETMASK, (char *)&ifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETNETMASK,
- "%s: getting netmask: %s"),
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.netmask,
- (struct sockaddr *)&ifreq.ifr_addr, ifreq.ifr_name);
- return (ISC_R_SUCCESS);
-}
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-static isc_result_t
-internal_current6(interfaceiter_t *iter) {
- struct LIFREQ *ifrp;
- struct LIFREQ lifreq;
- int family;
- char strbuf[ISC_STRERRORSIZE];
- int fd;
-
- REQUIRE(VALID_IFITER(iter));
- if (iter->result6 != ISC_R_SUCCESS)
- return (iter->result6);
- REQUIRE(iter->pos6 < (unsigned int) iter->lifc.lifc_len);
-
- ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos6);
-
- memset(&lifreq, 0, sizeof(lifreq));
- memmove(&lifreq, ifrp, sizeof(lifreq));
-
- family = lifreq.lifr_addr.ss_family;
- if (family != AF_INET && family != AF_INET6)
- return (ISC_R_IGNORE);
-
- memset(&iter->current, 0, sizeof(iter->current));
- iter->current.af = family;
-
- INSIST(sizeof(lifreq.lifr_name) <= sizeof(iter->current.name));
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memmove(iter->current.name, lifreq.lifr_name, sizeof(lifreq.lifr_name));
-
- get_addr(family, &iter->current.address,
- (struct sockaddr *)&lifreq.lifr_addr, lifreq.lifr_name);
-
- /*
- * If the interface does not have a address ignore it.
- */
- switch (family) {
- case AF_INET:
- if (iter->current.address.type.in.s_addr == htonl(INADDR_ANY))
- return (ISC_R_IGNORE);
- break;
- case AF_INET6:
- if (memcmp(&iter->current.address.type.in6, &in6addr_any,
- sizeof(in6addr_any)) == 0)
- return (ISC_R_IGNORE);
- break;
- }
-
- /*
- * Get interface flags.
- */
-
- iter->current.flags = 0;
-
- if (family == AF_INET6)
- fd = iter->socket6;
- else
- fd = iter->socket;
-
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(fd, SIOCGLIFFLAGS, (char *) &lifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "%s: getting interface flags: %s",
- lifreq.lifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
-
- if ((lifreq.lifr_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
-#ifdef IFF_POINTOPOINT
- if ((lifreq.lifr_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-#endif
-
- if ((lifreq.lifr_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
-#ifdef IFF_POINTOPOINT
- /*
- * If the interface is point-to-point, get the destination address.
- */
- if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(fd, SIOCGLIFDSTADDR, (char *)&lifreq)
- < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETDESTADDR,
- "%s: getting "
- "destination address: %s"),
- lifreq.lifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.dstaddress,
- (struct sockaddr *)&lifreq.lifr_dstaddr,
- lifreq.lifr_name);
- }
-#endif
-
- /*
- * Get the network mask. Netmask already zeroed.
- */
- memset(&lifreq, 0, sizeof(lifreq));
- memmove(&lifreq, ifrp, sizeof(lifreq));
-
-#ifdef lifr_addrlen
- /*
- * Special case: if the system provides lifr_addrlen member, the
- * netmask of an IPv6 address can be derived from the length, since
- * an IPv6 address always has a contiguous mask.
- */
- if (family == AF_INET6) {
- int i, bits;
-
- iter->current.netmask.family = family;
- for (i = 0; i < lifreq.lifr_addrlen; i += 8) {
- bits = lifreq.lifr_addrlen - i;
- bits = (bits < 8) ? (8 - bits) : 0;
- iter->current.netmask.type.in6.s6_addr[i / 8] =
- (~0U << bits) & 0xff;
- }
-
- return (ISC_R_SUCCESS);
- }
-#endif
-
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(fd, SIOCGLIFNETMASK, (char *)&lifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETNETMASK,
- "%s: getting netmask: %s"),
- lifreq.lifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.netmask,
- (struct sockaddr *)&lifreq.lifr_addr, lifreq.lifr_name);
-
- return (ISC_R_SUCCESS);
-}
-#endif
-
-static isc_result_t
-internal_current(interfaceiter_t *iter) {
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->mode == 6) {
- iter->result6 = internal_current6(iter);
- if (iter->result6 != ISC_R_NOMORE)
- return (iter->result6);
- }
-#endif
-#ifdef HAVE_TRUCLUSTER
- if (!iter->clua_done)
- return(internal_current_clusteralias(iter));
-#endif
- return (internal_current4(iter));
-}
-
-/*
- * Step the iterator to the next interface. Unlike
- * interfaceiter_next(), this may leave the iterator
- * positioned on an interface that will ultimately
- * be ignored. Return ISC_R_NOMORE if there are no more
- * interfaces, otherwise ISC_R_SUCCESS.
- */
-static isc_result_t
-internal_next4(interfaceiter_t *iter) {
- struct ifreq *ifrp;
-
- if (iter->pos < (unsigned int) iter->ifc.ifc_len) {
- ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
-
- if (ifrp->ifr_addr.sa_len > sizeof(struct sockaddr))
- iter->pos += sizeof(ifrp->ifr_name) +
- ifrp->ifr_addr.sa_len;
- else
- iter->pos += sizeof(struct ifreq);
-
- } else {
- INSIST(iter->pos == (unsigned int) iter->ifc.ifc_len);
-#ifdef __linux
- return (linux_if_inet6_next(iter));
-#else
- return (ISC_R_NOMORE);
-#endif
- }
- return (ISC_R_SUCCESS);
-}
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-static isc_result_t
-internal_next6(interfaceiter_t *iter) {
- struct LIFREQ *ifrp;
-
- if (iter->result6 != ISC_R_SUCCESS && iter->result6 != ISC_R_IGNORE)
- return (iter->result6);
-
- REQUIRE(iter->pos6 < (unsigned int) iter->lifc.lifc_len);
-
- ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos6);
-
- if (ifrp->lifr_addr.sa_len > sizeof(struct sockaddr))
- iter->pos6 += sizeof(ifrp->lifr_name) + ifrp->lifr_addr.sa_len;
- else
- iter->pos6 += sizeof(struct LIFREQ);
-
- if (iter->pos6 >= (unsigned int) iter->lifc.lifc_len)
- return (ISC_R_NOMORE);
-
- return (ISC_R_SUCCESS);
-}
-#endif
-
-static isc_result_t
-internal_next(interfaceiter_t *iter) {
-#ifdef HAVE_TRUCLUSTER
- int clua_result;
-#endif
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->mode == 6) {
- iter->result6 = internal_next6(iter);
- if (iter->result6 != ISC_R_NOMORE)
- return (iter->result6);
- if (iter->first6) {
- iter->first6 = ISC_FALSE;
- return (ISC_R_SUCCESS);
- }
- }
-#endif
-#ifdef HAVE_TRUCLUSTER
- if (!iter->clua_done) {
- clua_result = clua_getaliasaddress(&iter->clua_sa,
- &iter->clua_context);
- if (clua_result != CLUA_SUCCESS)
- iter->clua_done = ISC_TRUE;
- return (ISC_R_SUCCESS);
- }
-#endif
- return (internal_next4(iter));
-}
-
-static void
-internal_destroy(interfaceiter_t *iter) {
- (void) close(iter->socket);
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->socket6 != -1)
- (void) close(iter->socket6);
- if (iter->buf6 != NULL) {
- isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
- }
-#endif
-#ifdef __linux
- if (iter->proc != NULL)
- fclose(iter->proc);
-#endif
-}
-
-static
-void internal_first(interfaceiter_t *iter) {
-#ifdef HAVE_TRUCLUSTER
- int clua_result;
-#endif
- iter->pos = 0;
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- iter->pos6 = 0;
- if (iter->result6 == ISC_R_NOMORE)
- iter->result6 = ISC_R_SUCCESS;
- iter->first6 = ISC_TRUE;
-#endif
-#ifdef HAVE_TRUCLUSTER
- iter->clua_context = 0;
- clua_result = clua_getaliasaddress(&iter->clua_sa,
- &iter->clua_context);
- iter->clua_done = ISC_TF(clua_result != CLUA_SUCCESS);
-#endif
-#ifdef __linux
- linux_if_inet6_first(iter);
-#endif
-}
diff --git a/usr.sbin/bind/lib/isc/unix/ifiter_sysctl.c b/usr.sbin/bind/lib/isc/unix/ifiter_sysctl.c
deleted file mode 100644
index 100574e1625..00000000000
--- a/usr.sbin/bind/lib/isc/unix/ifiter_sysctl.c
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: ifiter_sysctl.c,v 1.6 2020/01/09 18:17:19 florian Exp $ */
-
-/*! \file
- * \brief
- * Obtain the list of network interfaces using sysctl.
- * See TCP/IP Illustrated Volume 2, sections 19.8, 19.14,
- * and 19.16.
- */
-
-#include <sys/param.h>
-#include <sys/sysctl.h>
-
-#include <net/route.h>
-#include <net/if_dl.h>
-
-
-
-/* XXX what about Alpha? */
-#ifdef sgi
-#define ROUNDUP(a) ((a) > 0 ? \
- (1 + (((a) - 1) | (sizeof(__uint64_t) - 1))) : \
- sizeof(__uint64_t))
-#else
-#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) \
- : sizeof(long))
-#endif
-
-#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'S')
-#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
-
-struct interfaceiter {
- unsigned int magic; /* Magic number. */
- isc_mem_t *mctx;
- void *buf; /* Buffer for sysctl data. */
- unsigned int bufsize; /* Bytes allocated. */
- unsigned int bufused; /* Bytes used. */
- unsigned int pos; /* Current offset in
- sysctl data. */
- interface_t current; /* Current interface data. */
- isc_result_t result; /* Last result code. */
-};
-
-static int mib[6] = {
- CTL_NET,
- PF_ROUTE,
- 0,
- 0, /* Any address family. */
- NET_RT_IFLIST,
- 0 /* Flags. */
-};
-
-isc_result_t
-interfaceiter_create(isc_mem_t *mctx, interfaceiter_t **iterp) {
- interfaceiter_t *iter;
- isc_result_t result;
- size_t bufsize;
- size_t bufused;
- char strbuf[ISC_STRERRORSIZE];
-
- REQUIRE(mctx != NULL);
- REQUIRE(iterp != NULL);
- REQUIRE(*iterp == NULL);
-
- iter = isc_mem_get(mctx, sizeof(*iter));
- if (iter == NULL)
- return (ISC_R_NOMEMORY);
-
- iter->mctx = mctx;
- iter->buf = 0;
-
- /*
- * Determine the amount of memory needed.
- */
- bufsize = 0;
- if (sysctl(mib, 6, NULL, &bufsize, NULL, (size_t) 0) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERSYSCTL,
- ISC_MSG_GETIFLISTSIZE,
- "getting interface "
- "list size: sysctl: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto failure;
- }
- iter->bufsize = bufsize;
-
- iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
- if (iter->buf == NULL) {
- result = ISC_R_NOMEMORY;
- goto failure;
- }
-
- bufused = bufsize;
- if (sysctl(mib, 6, iter->buf, &bufused, NULL, (size_t) 0) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERSYSCTL,
- ISC_MSG_GETIFLIST,
- "getting interface list: "
- "sysctl: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto failure;
- }
- iter->bufused = bufused;
- INSIST(iter->bufused <= iter->bufsize);
-
- /*
- * A newly created iterator has an undefined position
- * until interfaceiter_first() is called.
- */
- iter->pos = (unsigned int) -1;
- iter->result = ISC_R_FAILURE;
-
- iter->magic = IFITER_MAGIC;
- *iterp = iter;
- return (ISC_R_SUCCESS);
-
- failure:
- if (iter->buf != NULL)
- isc_mem_put(mctx, iter->buf, iter->bufsize);
- isc_mem_put(mctx, iter, sizeof(*iter));
- return (result);
-}
-
-/*
- * Get information about the current interface to iter->current.
- * If successful, return ISC_R_SUCCESS.
- * If the interface has an unsupported address family,
- * return ISC_R_IGNORE. In case of other failure,
- * return ISC_R_UNEXPECTED.
- */
-
-static isc_result_t
-internal_current(interfaceiter_t *iter) {
- struct ifa_msghdr *ifam, *ifam_end;
-
- REQUIRE(VALID_IFITER(iter));
- REQUIRE (iter->pos < (unsigned int) iter->bufused);
-
- ifam = (struct ifa_msghdr *) ((char *) iter->buf + iter->pos);
- ifam_end = (struct ifa_msghdr *) ((char *) iter->buf + iter->bufused);
-
- if (ifam->ifam_type == RTM_IFINFO) {
- struct if_msghdr *ifm = (struct if_msghdr *) ifam;
- struct sockaddr_dl *sdl = (struct sockaddr_dl *) (ifm + 1);
- unsigned int namelen;
-
- memset(&iter->current, 0, sizeof(iter->current));
-
- namelen = sdl->sdl_nlen;
- if (namelen > sizeof(iter->current.name) - 1)
- namelen = sizeof(iter->current.name) - 1;
-
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memmove(iter->current.name, sdl->sdl_data, namelen);
-
- iter->current.flags = 0;
-
- if ((ifam->ifam_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
- if ((ifam->ifam_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-
- if ((ifam->ifam_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
- /*
- * This is not an interface address.
- * Force another iteration.
- */
- return (ISC_R_IGNORE);
- } else if (ifam->ifam_type == RTM_NEWADDR) {
- int i;
- int family;
- struct sockaddr *mask_sa = NULL;
- struct sockaddr *addr_sa = NULL;
- struct sockaddr *dst_sa = NULL;
-
- struct sockaddr *sa = (struct sockaddr *)(ifam + 1);
- family = sa->sa_family;
-
- for (i = 0; i < RTAX_MAX; i++)
- {
- if ((ifam->ifam_addrs & (1 << i)) == 0)
- continue;
-
- INSIST(sa < (struct sockaddr *) ifam_end);
-
- switch (i) {
- case RTAX_NETMASK: /* Netmask */
- mask_sa = sa;
- break;
- case RTAX_IFA: /* Interface address */
- addr_sa = sa;
- break;
- case RTAX_BRD: /* Broadcast or destination address */
- dst_sa = sa;
- break;
- }
- sa = (struct sockaddr *)((char*)(sa)
- + ROUNDUP(sa->sa_len));
- }
-
- if (addr_sa == NULL)
- return (ISC_R_IGNORE);
-
- family = addr_sa->sa_family;
- if (family != AF_INET && family != AF_INET6)
- return (ISC_R_IGNORE);
-
- iter->current.af = family;
-
- get_addr(family, &iter->current.address, addr_sa,
- iter->current.name);
-
- if (mask_sa != NULL)
- get_addr(family, &iter->current.netmask, mask_sa,
- iter->current.name);
-
- if (dst_sa != NULL &&
- (iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0)
- get_addr(family, &iter->current.dstaddress, dst_sa,
- iter->current.name);
-
- return (ISC_R_SUCCESS);
- } else {
- printf(isc_msgcat_get(isc_msgcat, ISC_MSGSET_IFITERSYSCTL,
- ISC_MSG_UNEXPECTEDTYPE,
- "warning: unexpected interface list "
- "message type\n"));
- return (ISC_R_IGNORE);
- }
-}
-
-/*
- * Step the iterator to the next interface. Unlike
- * interfaceiter_next(), this may leave the iterator
- * positioned on an interface that will ultimately
- * be ignored. Return ISC_R_NOMORE if there are no more
- * interfaces, otherwise ISC_R_SUCCESS.
- */
-static isc_result_t
-internal_next(interfaceiter_t *iter) {
- struct ifa_msghdr *ifam;
- REQUIRE (iter->pos < (unsigned int) iter->bufused);
-
- ifam = (struct ifa_msghdr *) ((char *) iter->buf + iter->pos);
-
- iter->pos += ifam->ifam_msglen;
-
- if (iter->pos >= iter->bufused)
- return (ISC_R_NOMORE);
-
- return (ISC_R_SUCCESS);
-}
-
-static void
-internal_destroy(interfaceiter_t *iter) {
- UNUSED(iter); /* Unused. */
- /*
- * Do nothing.
- */
-}
-
-static
-void internal_first(interfaceiter_t *iter) {
- iter->pos = 0;
-}
diff --git a/usr.sbin/bind/lib/isc/unix/include/isc/Makefile.in b/usr.sbin/bind/lib/isc/unix/include/isc/Makefile.in
index b91923afd26..f73fb305c5c 100644
--- a/usr.sbin/bind/lib/isc/unix/include/isc/Makefile.in
+++ b/usr.sbin/bind/lib/isc/unix/include/isc/Makefile.in
@@ -12,7 +12,7 @@
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
-# $Id: Makefile.in,v 1.4 2020/01/09 18:17:20 florian Exp $
+# $Id: Makefile.in,v 1.5 2020/01/09 19:50:35 florian Exp $
srcdir = @srcdir@
VPATH = @srcdir@
@@ -20,7 +20,7 @@ top_srcdir = @top_srcdir@
VERSION=@BIND9_VERSION@
-HEADERS = dir.h keyboard.h net.h netdb.h offset.h stat.h \
+HEADERS = dir.h net.h netdb.h offset.h stat.h \
stdtime.h strerror.h syslog.h time.h
SUBDIRS =
diff --git a/usr.sbin/bind/lib/isc/unix/include/isc/keyboard.h b/usr.sbin/bind/lib/isc/unix/include/isc/keyboard.h
deleted file mode 100644
index 1101bdb1e32..00000000000
--- a/usr.sbin/bind/lib/isc/unix/include/isc/keyboard.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: keyboard.h,v 1.3 2019/12/17 01:46:37 sthen Exp $ */
-
-#ifndef ISC_KEYBOARD_H
-#define ISC_KEYBOARD_H 1
-
-/*! \file */
-
-#include <termios.h>
-
-#include <isc/lang.h>
-#include <isc/result.h>
-
-ISC_LANG_BEGINDECLS
-
-typedef struct {
- int fd;
- struct termios saved_mode;
- isc_result_t result;
-} isc_keyboard_t;
-
-isc_result_t
-isc_keyboard_open(isc_keyboard_t *keyboard);
-
-isc_result_t
-isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleepseconds);
-
-isc_result_t
-isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp);
-
-isc_boolean_t
-isc_keyboard_canceled(isc_keyboard_t *keyboard);
-
-ISC_LANG_ENDDECLS
-
-#endif /* ISC_KEYBOARD_H */
diff --git a/usr.sbin/bind/lib/isc/unix/interfaceiter.c b/usr.sbin/bind/lib/isc/unix/interfaceiter.c
deleted file mode 100644
index 456226b183b..00000000000
--- a/usr.sbin/bind/lib/isc/unix/interfaceiter.c
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: interfaceiter.c,v 1.6 2020/01/09 18:17:19 florian Exp $ */
-
-/*! \file */
-
-#include <config.h>
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_SYS_SOCKIO_H
-#include <sys/sockio.h> /* Required for ifiter_ioctl.c. */
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <isc/interfaceiter.h>
-#include <isc/log.h>
-#include <isc/magic.h>
-#include <isc/mem.h>
-#include <isc/msgs.h>
-#include <isc/net.h>
-
-#include <isc/result.h>
-#include <isc/strerror.h>
-#include <isc/string.h>
-#include <isc/types.h>
-#include <isc/util.h>
-
-/* Must follow <isc/net.h>. */
-#ifdef HAVE_NET_IF6_H
-#include <net/if6.h>
-#endif
-#include <net/if.h>
-
-/* Common utility functions */
-
-/*%
- * Extract the network address part from a "struct sockaddr".
- * \brief
- * The address family is given explicitly
- * instead of using src->sa_family, because the latter does not work
- * for copying a network mask obtained by SIOCGIFNETMASK (it does
- * not have a valid address family).
- */
-
-static void
-get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src,
- char *ifname)
-{
- struct sockaddr_in6 *sa6;
-
- /* clear any remaining value for safety */
- memset(dst, 0, sizeof(*dst));
-
- dst->family = family;
- switch (family) {
- case AF_INET:
- memmove(&dst->type.in,
- &((struct sockaddr_in *) src)->sin_addr,
- sizeof(struct in_addr));
- break;
- case AF_INET6:
- sa6 = (struct sockaddr_in6 *)src;
- memmove(&dst->type.in6, &sa6->sin6_addr,
- sizeof(struct in6_addr));
- if (sa6->sin6_scope_id != 0)
- isc_netaddr_setzone(dst, sa6->sin6_scope_id);
- else {
- /*
- * BSD variants embed scope zone IDs in the 128bit
- * address as a kernel internal form. Unfortunately,
- * the embedded IDs are not hidden from applications
- * when getting access to them by sysctl or ioctl.
- * We convert the internal format to the pure address
- * part and the zone ID part.
- * Since multicast addresses should not appear here
- * and they cannot be distinguished from netmasks,
- * we only consider unicast link-local addresses.
- */
- if (IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr)) {
- uint16_t zone16;
-
- memmove(&zone16, &sa6->sin6_addr.s6_addr[2],
- sizeof(zone16));
- zone16 = ntohs(zone16);
- if (zone16 != 0) {
- /* the zone ID is embedded */
- isc_netaddr_setzone(dst,
- (uint32_t)zone16);
- dst->type.in6.s6_addr[2] = 0;
- dst->type.in6.s6_addr[3] = 0;
- } else if (ifname != NULL) {
- unsigned int zone;
-
- /*
- * sin6_scope_id is still not provided,
- * but the corresponding interface name
- * is know. Use the interface ID as
- * the link ID.
- */
- zone = if_nametoindex(ifname);
- if (zone != 0) {
- isc_netaddr_setzone(dst,
- (uint32_t)zone);
- }
- }
- }
- }
- break;
- default:
- INSIST(0);
- break;
- }
-}
-
-/*
- * Include system-dependent code.
- */
-
-#ifdef __linux
-#define ISC_IF_INET6_SZ \
- sizeof("00000000000000000000000000000001 01 80 10 80 XXXXXXloXXXXXXXX\n")
-static isc_result_t linux_if_inet6_next(interfaceiter_t *);
-static isc_result_t linux_if_inet6_current(interfaceiter_t *);
-static void linux_if_inet6_first(interfaceiter_t *iter);
-#endif
-
-#if HAVE_GETIFADDRS
-#include "ifiter_getifaddrs.c"
-#elif HAVE_IFLIST_SYSCTL
-#include "ifiter_sysctl.c"
-#else
-#include "ifiter_ioctl.c"
-#endif
-
-#ifdef __linux
-static void
-linux_if_inet6_first(interfaceiter_t *iter) {
- if (iter->proc != NULL) {
- rewind(iter->proc);
- (void)linux_if_inet6_next(iter);
- } else
- iter->valid = ISC_R_NOMORE;
-}
-
-static isc_result_t
-linux_if_inet6_next(interfaceiter_t *iter) {
- if (iter->proc != NULL &&
- fgets(iter->entry, sizeof(iter->entry), iter->proc) != NULL)
- iter->valid = ISC_R_SUCCESS;
- else
- iter->valid = ISC_R_NOMORE;
- return (iter->valid);
-}
-
-static isc_result_t
-linux_if_inet6_current(interfaceiter_t *iter) {
- char address[33];
- char name[IF_NAMESIZE+1];
- struct in6_addr addr6;
- unsigned int ifindex, prefix, flag3, flag4;
- int res;
- unsigned int i;
-
- if (iter->valid != ISC_R_SUCCESS)
- return (iter->valid);
- if (iter->proc == NULL) {
- isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR,
- "/proc/net/if_inet6:iter->proc == NULL");
- return (ISC_R_FAILURE);
- }
-
- res = sscanf(iter->entry, "%32[a-f0-9] %x %x %x %x %16s\n",
- address, &ifindex, &prefix, &flag3, &flag4, name);
- if (res != 6) {
- isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR,
- "/proc/net/if_inet6:sscanf() -> %d (expected 6)",
- res);
- return (ISC_R_FAILURE);
- }
- if (strlen(address) != 32) {
- isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR,
- "/proc/net/if_inet6:strlen(%s) != 32", address);
- return (ISC_R_FAILURE);
- }
- for (i = 0; i < 16; i++) {
- unsigned char byte;
- static const char hex[] = "0123456789abcdef";
- byte = ((strchr(hex, address[i * 2]) - hex) << 4) |
- (strchr(hex, address[i * 2 + 1]) - hex);
- addr6.s6_addr[i] = byte;
- }
- iter->current.af = AF_INET6;
- iter->current.flags = INTERFACE_F_UP;
- isc_netaddr_fromin6(&iter->current.address, &addr6);
- if (isc_netaddr_islinklocal(&iter->current.address)) {
- isc_netaddr_setzone(&iter->current.address,
- (uint32_t)ifindex);
- }
- for (i = 0; i < 16; i++) {
- if (prefix > 8) {
- addr6.s6_addr[i] = 0xff;
- prefix -= 8;
- } else {
- addr6.s6_addr[i] = (0xff << (8 - prefix)) & 0xff;
- prefix = 0;
- }
- }
- isc_netaddr_fromin6(&iter->current.netmask, &addr6);
- strlcpy(iter->current.name, name, sizeof(iter->current.name));
- return (ISC_R_SUCCESS);
-}
-#endif
-
-/*
- * The remaining code is common to the sysctl and ioctl case.
- */
-
-isc_result_t
-interfaceiter_current(interfaceiter_t *iter,
- interface_t *ifdata)
-{
- REQUIRE(iter->result == ISC_R_SUCCESS);
- memmove(ifdata, &iter->current, sizeof(*ifdata));
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-interfaceiter_first(interfaceiter_t *iter) {
- isc_result_t result;
-
- REQUIRE(VALID_IFITER(iter));
-
- internal_first(iter);
- for (;;) {
- result = internal_current(iter);
- if (result != ISC_R_IGNORE)
- break;
- result = internal_next(iter);
- if (result != ISC_R_SUCCESS)
- break;
- }
- iter->result = result;
- return (result);
-}
-
-isc_result_t
-interfaceiter_next(interfaceiter_t *iter) {
- isc_result_t result;
-
- REQUIRE(VALID_IFITER(iter));
- REQUIRE(iter->result == ISC_R_SUCCESS);
-
- for (;;) {
- result = internal_next(iter);
- if (result != ISC_R_SUCCESS)
- break;
- result = internal_current(iter);
- if (result != ISC_R_IGNORE)
- break;
- }
- iter->result = result;
- return (result);
-}
-
-void
-interfaceiter_destroy(interfaceiter_t **iterp)
-{
- interfaceiter_t *iter;
- REQUIRE(iterp != NULL);
- iter = *iterp;
- REQUIRE(VALID_IFITER(iter));
-
- internal_destroy(iter);
- if (iter->buf != NULL)
- isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
-
- iter->magic = 0;
- isc_mem_put(iter->mctx, iter, sizeof(*iter));
- *iterp = NULL;
-}
diff --git a/usr.sbin/bind/lib/isc/unix/keyboard.c b/usr.sbin/bind/lib/isc/unix/keyboard.c
deleted file mode 100644
index c241d1840da..00000000000
--- a/usr.sbin/bind/lib/isc/unix/keyboard.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: keyboard.c,v 1.3 2019/12/17 01:46:37 sthen Exp $ */
-
-#include <config.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/uio.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <isc/keyboard.h>
-#include <isc/util.h>
-
-isc_result_t
-isc_keyboard_open(isc_keyboard_t *keyboard) {
- int fd;
- isc_result_t ret;
- struct termios current_mode;
-
- REQUIRE(keyboard != NULL);
-
- fd = open("/dev/tty", O_RDONLY, 0);
- if (fd < 0)
- return (ISC_R_IOERROR);
-
- keyboard->fd = fd;
-
- if (tcgetattr(fd, &keyboard->saved_mode) < 0) {
- ret = ISC_R_IOERROR;
- goto errout;
- }
-
- current_mode = keyboard->saved_mode;
-
- current_mode.c_iflag &=
- ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
- current_mode.c_oflag &= ~OPOST;
- current_mode.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
- current_mode.c_cflag &= ~(CSIZE|PARENB);
- current_mode.c_cflag |= CS8;
-
- current_mode.c_cc[VMIN] = 1;
- current_mode.c_cc[VTIME] = 0;
- if (tcsetattr(fd, TCSAFLUSH, &current_mode) < 0) {
- ret = ISC_R_IOERROR;
- goto errout;
- }
-
- keyboard->result = ISC_R_SUCCESS;
-
- return (ISC_R_SUCCESS);
-
- errout:
- close (fd);
-
- return (ret);
-}
-
-isc_result_t
-isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleeptime) {
- REQUIRE(keyboard != NULL);
-
- if (sleeptime > 0 && keyboard->result != ISC_R_CANCELED)
- (void)sleep(sleeptime);
-
- (void)tcsetattr(keyboard->fd, TCSAFLUSH, &keyboard->saved_mode);
- (void)close(keyboard->fd);
-
- keyboard->fd = -1;
-
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp) {
- ssize_t cc;
- unsigned char c;
- cc_t *controlchars;
-
- REQUIRE(keyboard != NULL);
- REQUIRE(cp != NULL);
-
- cc = read(keyboard->fd, &c, 1);
- if (cc < 0) {
- keyboard->result = ISC_R_IOERROR;
- return (keyboard->result);
- }
-
- controlchars = keyboard->saved_mode.c_cc;
- if (c == controlchars[VINTR] || c == controlchars[VQUIT]) {
- keyboard->result = ISC_R_CANCELED;
- return (keyboard->result);
- }
-
- *cp = c;
-
- return (ISC_R_SUCCESS);
-}
-
-isc_boolean_t
-isc_keyboard_canceled(isc_keyboard_t *keyboard) {
- return (ISC_TF(keyboard->result == ISC_R_CANCELED));
-}
diff --git a/usr.sbin/bind/lib/isc/unix/os.c b/usr.sbin/bind/lib/isc/unix/os.c
deleted file mode 100644
index 658b86b844f..00000000000
--- a/usr.sbin/bind/lib/isc/unix/os.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: os.c,v 1.3 2019/12/17 01:46:37 sthen Exp $ */
-
-#include <config.h>
-
-#include <isc/os.h>
-
-
-#ifdef HAVE_SYSCONF
-
-#include <unistd.h>
-
-#ifndef __hpux
-static inline long
-sysconf_ncpus(void) {
-#if defined(_SC_NPROCESSORS_ONLN)
- return sysconf((_SC_NPROCESSORS_ONLN));
-#elif defined(_SC_NPROC_ONLN)
- return sysconf((_SC_NPROC_ONLN));
-#else
- return (0);
-#endif
-}
-#endif
-#endif /* HAVE_SYSCONF */
-
-
-#ifdef __hpux
-
-#include <sys/pstat.h>
-
-static inline int
-hpux_ncpus(void) {
- struct pst_dynamic psd;
- if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) != -1)
- return (psd.psd_proc_cnt);
- else
- return (0);
-}
-
-#endif /* __hpux */
-
-#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
-#include <sys/types.h> /* for FreeBSD */
-#include <sys/param.h> /* for NetBSD */
-#include <sys/sysctl.h>
-
-static int
-sysctl_ncpus(void) {
- int ncpu, result;
- size_t len;
-
- len = sizeof(ncpu);
- result = sysctlbyname("hw.ncpu", &ncpu, &len , 0, 0);
- if (result != -1)
- return (ncpu);
- return (0);
-}
-#endif
-
-unsigned int
-isc_os_ncpus(void) {
- long ncpus = 0;
-
-#ifdef __hpux
- ncpus = hpux_ncpus();
-#elif defined(HAVE_SYSCONF)
- ncpus = sysconf_ncpus();
-#endif
-#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
- if (ncpus <= 0)
- ncpus = sysctl_ncpus();
-#endif
- if (ncpus <= 0)
- ncpus = 1;
-
- return ((unsigned int)ncpus);
-}
diff --git a/usr.sbin/bind/lib/isc/unix/privsep_fdpass.c b/usr.sbin/bind/lib/isc/unix/privsep_fdpass.c
deleted file mode 100644
index 5a59e0bda73..00000000000
--- a/usr.sbin/bind/lib/isc/unix/privsep_fdpass.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/* $OpenBSD: privsep_fdpass.c,v 1.7 2008/03/24 16:11:02 deraadt Exp $ */
-
-/*
- * Copyright 2001 Niels Provos <provos@citi.umich.edu>
- * All rights reserved.
- *
- * Copyright (c) 2002 Matthieu Herrb
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <isc/privsep.h>
-
-void
-send_fd(int sock, int fd)
-{
- struct msghdr msg;
- union {
- struct cmsghdr hdr;
- char buf[CMSG_SPACE(sizeof(int))];
- } cmsgbuf;
- struct cmsghdr *cmsg;
- struct iovec vec;
- int result = 0;
- ssize_t n;
-
- memset(&msg, 0, sizeof(msg));
-
- if (fd >= 0) {
- msg.msg_control = (caddr_t)&cmsgbuf.buf;
- msg.msg_controllen = sizeof(cmsgbuf.buf);
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_len = CMSG_LEN(sizeof(int));
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- *(int *)CMSG_DATA(cmsg) = fd;
- } else
- result = errno;
-
- vec.iov_base = &result;
- vec.iov_len = sizeof(int);
- msg.msg_iov = &vec;
- msg.msg_iovlen = 1;
-
- if ((n = sendmsg(sock, &msg, 0)) == -1)
- warn("%s: sendmsg(%d)", __func__, sock);
- if (n != sizeof(int))
- warnx("%s: sendmsg: expected sent 1 got %ld",
- __func__, (long)n);
-}
-
-int
-receive_fd(int sock)
-{
- struct msghdr msg;
- union {
- struct cmsghdr hdr;
- char buf[CMSG_SPACE(sizeof(int))];
- } cmsgbuf;
- struct cmsghdr *cmsg;
- struct iovec vec;
- ssize_t n;
- int result;
- int fd;
-
- memset(&msg, 0, sizeof(msg));
- vec.iov_base = &result;
- vec.iov_len = sizeof(int);
- msg.msg_iov = &vec;
- msg.msg_iovlen = 1;
- msg.msg_control = &cmsgbuf.buf;
- msg.msg_controllen = sizeof(cmsgbuf.buf);
-
- if ((n = recvmsg(sock, &msg, 0)) == -1)
- warn("%s: recvmsg", __func__);
- if (n != sizeof(int))
- warnx("%s: recvmsg: expected received 1 got %ld",
- __func__, (long)n);
- if (result == 0) {
- cmsg = CMSG_FIRSTHDR(&msg);
- if (cmsg->cmsg_type != SCM_RIGHTS)
- warnx("%s: expected type %d got %d", __func__,
- SCM_RIGHTS, cmsg->cmsg_type);
- fd = (*(int *)CMSG_DATA(cmsg));
- return (fd);
- } else {
- errno = result;
- return (-1);
- }
-}
diff --git a/usr.sbin/bind/lib/isc/unix/resource.c b/usr.sbin/bind/lib/isc/unix/resource.c
deleted file mode 100644
index 57605894dcf..00000000000
--- a/usr.sbin/bind/lib/isc/unix/resource.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-/* $Id: resource.c,v 1.5 2020/01/09 14:18:30 florian Exp $ */
-
-#include <config.h>
-
-#include <sys/types.h>
-#include <sys/time.h> /* Required on some systems for <sys/resource.h>. */
-#include <sys/resource.h>
-
-#include <isc/platform.h>
-#include <isc/resource.h>
-#include <isc/result.h>
-#include <isc/util.h>
-
-#ifdef __linux__
-#include <linux/fs.h> /* To get the large NR_OPEN. */
-#endif
-
-#if defined(__hpux) && defined(HAVE_SYS_DYNTUNE_H)
-#include <sys/dyntune.h>
-#endif
-
-#include "errno2result.h"
-
-static isc_result_t
-resource2rlim(isc_resource_t resource, int *rlim_resource) {
- isc_result_t result = ISC_R_SUCCESS;
-
- switch (resource) {
- case isc_resource_coresize:
- *rlim_resource = RLIMIT_CORE;
- break;
- case isc_resource_cputime:
- *rlim_resource = RLIMIT_CPU;
- break;
- case isc_resource_datasize:
- *rlim_resource = RLIMIT_DATA;
- break;
- case isc_resource_filesize:
- *rlim_resource = RLIMIT_FSIZE;
- break;
- case isc_resource_lockedmemory:
-#ifdef RLIMIT_MEMLOCK
- *rlim_resource = RLIMIT_MEMLOCK;
-#else
- result = ISC_R_NOTIMPLEMENTED;
-#endif
- break;
- case isc_resource_openfiles:
-#ifdef RLIMIT_NOFILE
- *rlim_resource = RLIMIT_NOFILE;
-#else
- result = ISC_R_NOTIMPLEMENTED;
-#endif
- break;
- case isc_resource_processes:
-#ifdef RLIMIT_NPROC
- *rlim_resource = RLIMIT_NPROC;
-#else
- result = ISC_R_NOTIMPLEMENTED;
-#endif
- break;
- case isc_resource_residentsize:
-#ifdef RLIMIT_RSS
- *rlim_resource = RLIMIT_RSS;
-#else
- result = ISC_R_NOTIMPLEMENTED;
-#endif
- break;
- case isc_resource_stacksize:
- *rlim_resource = RLIMIT_STACK;
- break;
- default:
- /*
- * This test is not very robust if isc_resource_t
- * changes, but generates a clear assertion message.
- */
- REQUIRE(resource >= isc_resource_coresize &&
- resource <= isc_resource_stacksize);
-
- result = ISC_R_RANGE;
- break;
- }
-
- return (result);
-}
-
-isc_result_t
-isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) {
- struct rlimit rl;
- rlim_t rlim_value;
- int unixresult;
- int unixresource;
- isc_result_t result;
-
- result = resource2rlim(resource, &unixresource);
- if (result != ISC_R_SUCCESS)
- return (result);
-
- if (value == ISC_RESOURCE_UNLIMITED)
- rlim_value = RLIM_INFINITY;
-
- else {
- /*
- * isc_resourcevalue_t was chosen as an unsigned 64 bit
- * integer so that it could contain the maximum range of
- * reasonable values. Unfortunately, this exceeds the typical
- * range on Unix systems. Ensure the range of
- * rlim_t is not overflowed.
- */
- isc_resourcevalue_t rlim_max;
- isc_boolean_t rlim_t_is_signed =
- ISC_TF(((double)(rlim_t)-1) < 0);
-
- if (rlim_t_is_signed)
- rlim_max = ~((rlim_t)1 <<
- (sizeof(rlim_t) * 8 - 1));
- else
- rlim_max = (rlim_t)-1;
-
- if (value > rlim_max)
- value = rlim_max;
-
- rlim_value = value;
- }
-
- rl.rlim_cur = rl.rlim_max = rlim_value;
- unixresult = setrlimit(unixresource, &rl);
-
- if (unixresult == 0)
- return (ISC_R_SUCCESS);
-
-#if defined(OPEN_MAX) && defined(__APPLE__)
- /*
- * The Darwin kernel doesn't accept RLIM_INFINITY for rlim_cur; the
- * maximum possible value is OPEN_MAX. BIND8 used to use
- * sysconf(_SC_OPEN_MAX) for such a case, but this value is much
- * smaller than OPEN_MAX and is not really effective.
- */
- if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
- rl.rlim_cur = OPEN_MAX;
- unixresult = setrlimit(unixresource, &rl);
- if (unixresult == 0)
- return (ISC_R_SUCCESS);
- }
-#elif defined(__linux__)
-#ifndef NR_OPEN
-#define NR_OPEN (1024*1024)
-#endif
-
- /*
- * Some Linux kernels don't accept RLIM_INFINIT; the maximum
- * possible value is the NR_OPEN defined in linux/fs.h.
- */
- if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
- rl.rlim_cur = rl.rlim_max = NR_OPEN;
- unixresult = setrlimit(unixresource, &rl);
- if (unixresult == 0)
- return (ISC_R_SUCCESS);
- }
-#elif defined(__hpux) && defined(HAVE_SYS_DYNTUNE_H)
- if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
- uint64_t maxfiles;
- if (gettune("maxfiles_lim", &maxfiles) == 0) {
- rl.rlim_cur = rl.rlim_max = maxfiles;
- unixresult = setrlimit(unixresource, &rl);
- if (unixresult == 0)
- return (ISC_R_SUCCESS);
- }
- }
-#endif
- if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
- if (getrlimit(unixresource, &rl) == 0) {
- rl.rlim_cur = rl.rlim_max;
- unixresult = setrlimit(unixresource, &rl);
- if (unixresult == 0)
- return (ISC_R_SUCCESS);
- }
- }
- return (isc__errno2result(errno));
-}
-
-isc_result_t
-isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
- int unixresult;
- int unixresource;
- struct rlimit rl;
- isc_result_t result;
-
- result = resource2rlim(resource, &unixresource);
- if (result == ISC_R_SUCCESS) {
- unixresult = getrlimit(unixresource, &rl);
- INSIST(unixresult == 0);
- *value = rl.rlim_max;
- }
-
- return (result);
-}
-
-isc_result_t
-isc_resource_getcurlimit(isc_resource_t resource, isc_resourcevalue_t *value) {
- int unixresult;
- int unixresource;
- struct rlimit rl;
- isc_result_t result;
-
- result = resource2rlim(resource, &unixresource);
- if (result == ISC_R_SUCCESS) {
- unixresult = getrlimit(unixresource, &rl);
- INSIST(unixresult == 0);
- *value = rl.rlim_cur;
- }
-
- return (result);
-}
diff --git a/usr.sbin/bind/lib/isc/unix/socket.c b/usr.sbin/bind/lib/isc/unix/socket.c
index b05321f4ba5..df38446f9c2 100644
--- a/usr.sbin/bind/lib/isc/unix/socket.c
+++ b/usr.sbin/bind/lib/isc/unix/socket.c
@@ -55,7 +55,6 @@
#include <isc/platform.h>
#include <isc/region.h>
-#include <isc/resource.h>
#include <isc/socket.h>
#include <isc/strerror.h>
@@ -75,10 +74,8 @@
/* See task.c about the following definition: */
#define USE_SHARED_MANAGER
-#ifndef USE_WATCHER_THREAD
#include "socket_p.h"
#include "../task_p.h"
-#endif /* USE_WATCHER_THREAD */
#if defined(SO_BSDCOMPAT) && defined(__linux__)
#include <sys/utsname.h>
@@ -89,7 +86,6 @@
*/
#define USE_KQUEUE
-#ifndef USE_WATCHER_THREAD
#if defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL)
struct isc_socketwait {
int nevents;
@@ -102,7 +98,6 @@ struct isc_socketwait {
int maxfd;
};
#endif /* USE_KQUEUE */
-#endif /* !USE_WATCHER_THREAD */
/*
* Set by the -T dscp option on the command line. If set to a value
@@ -371,13 +366,6 @@ struct isc__socketmgr {
int nevents;
struct epoll_event *events;
#endif /* USE_EPOLL */
-#ifdef USE_DEVPOLL
- int devpoll_fd;
- isc_resourcevalue_t open_max;
- unsigned int calls;
- int nevents;
- struct pollfd *events;
-#endif /* USE_DEVPOLL */
#ifdef USE_SELECT
int fd_bufsize;
#endif /* USE_SELECT */
@@ -389,9 +377,6 @@ struct isc__socketmgr {
#if defined(USE_EPOLL)
uint32_t *epoll_events;
#endif
-#ifdef USE_DEVPOLL
- pollinfo_t *fdpollinfo;
-#endif
/* Locked by manager lock. */
ISC_LIST(isc__socket_t) socklist;
@@ -403,12 +388,7 @@ struct isc__socketmgr {
int maxfd;
#endif /* USE_SELECT */
int reserved; /* unlocked */
-#ifdef USE_WATCHER_THREAD
- isc_thread_t watcher;
- isc_condition_t shutdown_ok;
-#else /* USE_WATCHER_THREAD */
unsigned int refs;
-#endif /* USE_WATCHER_THREAD */
int maxudp;
};
@@ -451,9 +431,6 @@ static void build_msghdr_send(isc__socket_t *, char *, isc_socketevent_t *,
struct msghdr *, struct iovec *, size_t *);
static void build_msghdr_recv(isc__socket_t *, char *, isc_socketevent_t *,
struct msghdr *, struct iovec *, size_t *);
-#ifdef USE_WATCHER_THREAD
-static isc_boolean_t process_ctlfd(isc__socketmgr_t *manager);
-#endif
static void setdscp(isc__socket_t *sock, isc_dscp_t dscp);
/*%
@@ -756,29 +733,6 @@ watch_fd(isc__socketmgr_t *manager, int fd, int msg) {
}
return (result);
-#elif defined(USE_DEVPOLL)
- struct pollfd pfd;
- int lockid = FDLOCK_ID(fd);
-
- memset(&pfd, 0, sizeof(pfd));
- if (msg == SELECT_POKE_READ)
- pfd.events = POLLIN;
- else
- pfd.events = POLLOUT;
- pfd.fd = fd;
- pfd.revents = 0;
- LOCK(&manager->fdlock[lockid]);
- if (write(manager->devpoll_fd, &pfd, sizeof(pfd)) == -1)
- result = isc__errno2result(errno);
- else {
- if (msg == SELECT_POKE_READ)
- manager->fdpollinfo[fd].want_read = 1;
- else
- manager->fdpollinfo[fd].want_write = 1;
- }
- UNLOCK(&manager->fdlock[lockid]);
-
- return (result);
#elif defined(USE_SELECT)
LOCK(&manager->lock);
if (msg == SELECT_POKE_READ)
@@ -833,45 +787,6 @@ unwatch_fd(isc__socketmgr_t *manager, int fd, int msg) {
result = ISC_R_UNEXPECTED;
}
return (result);
-#elif defined(USE_DEVPOLL)
- struct pollfd pfds[2];
- size_t writelen = sizeof(pfds[0]);
- int lockid = FDLOCK_ID(fd);
-
- memset(pfds, 0, sizeof(pfds));
- pfds[0].events = POLLREMOVE;
- pfds[0].fd = fd;
-
- /*
- * Canceling read or write polling via /dev/poll is tricky. Since it
- * only provides a way of canceling per FD, we may need to re-poll the
- * socket for the other operation.
- */
- LOCK(&manager->fdlock[lockid]);
- if (msg == SELECT_POKE_READ &&
- manager->fdpollinfo[fd].want_write == 1) {
- pfds[1].events = POLLOUT;
- pfds[1].fd = fd;
- writelen += sizeof(pfds[1]);
- }
- if (msg == SELECT_POKE_WRITE &&
- manager->fdpollinfo[fd].want_read == 1) {
- pfds[1].events = POLLIN;
- pfds[1].fd = fd;
- writelen += sizeof(pfds[1]);
- }
-
- if (write(manager->devpoll_fd, pfds, writelen) == -1)
- result = isc__errno2result(errno);
- else {
- if (msg == SELECT_POKE_READ)
- manager->fdpollinfo[fd].want_read = 0;
- else
- manager->fdpollinfo[fd].want_write = 0;
- }
- UNLOCK(&manager->fdlock[lockid]);
-
- return (result);
#elif defined(USE_SELECT)
LOCK(&manager->lock);
if (msg == SELECT_POKE_READ)
@@ -946,78 +861,6 @@ wakeup_socket(isc__socketmgr_t *manager, int fd, int msg) {
}
}
-#ifdef USE_WATCHER_THREAD
-/*
- * Poke the select loop when there is something for us to do.
- * The write is required (by POSIX) to complete. That is, we
- * will not get partial writes.
- */
-static void
-select_poke(isc__socketmgr_t *mgr, int fd, int msg) {
- int cc;
- int buf[2];
- char strbuf[ISC_STRERRORSIZE];
-
- buf[0] = fd;
- buf[1] = msg;
-
- do {
- cc = write(mgr->pipe_fds[1], buf, sizeof(buf));
-#ifdef ENOSR
- /*
- * Treat ENOSR as EAGAIN but loop slowly as it is
- * unlikely to clear fast.
- */
- if (cc < 0 && errno == ENOSR) {
- sleep(1);
- errno = EAGAIN;
- }
-#endif
- } while (cc < 0 && SOFT_ERROR(errno));
-
- if (cc < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- FATAL_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKET,
- ISC_MSG_WRITEFAILED,
- "write() failed "
- "during watcher poke: %s"),
- strbuf);
- }
-
- INSIST(cc == sizeof(buf));
-}
-
-/*
- * Read a message on the internal fd.
- */
-static void
-select_readmsg(isc__socketmgr_t *mgr, int *fd, int *msg) {
- int buf[2];
- int cc;
- char strbuf[ISC_STRERRORSIZE];
-
- cc = read(mgr->pipe_fds[0], buf, sizeof(buf));
- if (cc < 0) {
- *msg = SELECT_POKE_NOTHING;
- *fd = -1; /* Silence compiler. */
- if (SOFT_ERROR(errno))
- return;
-
- isc__strerror(errno, strbuf, sizeof(strbuf));
- FATAL_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKET,
- ISC_MSG_READFAILED,
- "read() failed "
- "during watcher poke: %s"),
- strbuf);
- }
- INSIST(cc == sizeof(buf));
-
- *fd = buf[0];
- *msg = buf[1];
-}
-#else /* USE_WATCHER_THREAD */
/*
* Update the state of the socketmgr when something changes.
*/
@@ -1029,7 +872,6 @@ select_poke(isc__socketmgr_t *manager, int fd, int msg) {
wakeup_socket(manager, fd, msg);
return;
}
-#endif /* USE_WATCHER_THREAD */
/*
* Make a fd non-blocking.
@@ -2008,11 +1850,6 @@ destroy(isc__socket_t **sockp) {
ISC_LIST_UNLINK(manager->socklist, sock, link);
-#ifdef USE_WATCHER_THREAD
- if (ISC_LIST_EMPTY(manager->socklist))
- SIGNAL(&manager->shutdown_ok);
-#endif /* USE_WATCHER_THREAD */
-
/* can't unlock manager as its memory context is still used */
free_socket(sockp);
@@ -2640,10 +2477,6 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type,
#if defined(USE_EPOLL)
manager->epoll_events[sock->fd] = 0;
#endif
-#ifdef USE_DEVPOLL
- INSIST(sock->manager->fdpollinfo[sock->fd].want_read == 0 &&
- sock->manager->fdpollinfo[sock->fd].want_write == 0);
-#endif
UNLOCK(&manager->fdlock[lockid]);
LOCK(&manager->lock);
@@ -2719,10 +2552,6 @@ isc__socket_open(isc_socket_t *sock0) {
#if defined(USE_EPOLL)
sock->manager->epoll_events[sock->fd] = 0;
#endif
-#ifdef USE_DEVPOLL
- INSIST(sock->manager->fdpollinfo[sock->fd].want_read == 0 &&
- sock->manager->fdpollinfo[sock->fd].want_write == 0);
-#endif
UNLOCK(&sock->manager->fdlock[lockid]);
#ifdef USE_SELECT
@@ -3654,9 +3483,6 @@ process_fds(isc__socketmgr_t *manager, struct kevent *events, int nevents) {
int i;
isc_boolean_t readable, writable;
isc_boolean_t done = ISC_FALSE;
-#ifdef USE_WATCHER_THREAD
- isc_boolean_t have_ctlevent = ISC_FALSE;
-#endif
if (nevents == manager->nevents) {
/*
@@ -3672,22 +3498,11 @@ process_fds(isc__socketmgr_t *manager, struct kevent *events, int nevents) {
for (i = 0; i < nevents; i++) {
REQUIRE(events[i].ident < manager->maxsocks);
-#ifdef USE_WATCHER_THREAD
- if (events[i].ident == (uintptr_t)manager->pipe_fds[0]) {
- have_ctlevent = ISC_TRUE;
- continue;
- }
-#endif
readable = ISC_TF(events[i].filter == EVFILT_READ);
writable = ISC_TF(events[i].filter == EVFILT_WRITE);
process_fd(manager, events[i].ident, readable, writable);
}
-#ifdef USE_WATCHER_THREAD
- if (have_ctlevent)
- done = process_ctlfd(manager);
-#endif
-
return (done);
}
#elif defined(USE_EPOLL)
@@ -3696,9 +3511,6 @@ process_fds(isc__socketmgr_t *manager, struct epoll_event *events, int nevents)
{
int i;
isc_boolean_t done = ISC_FALSE;
-#ifdef USE_WATCHER_THREAD
- isc_boolean_t have_ctlevent = ISC_FALSE;
-#endif
if (nevents == manager->nevents) {
manager_log(manager, ISC_LOGCATEGORY_GENERAL,
@@ -3709,12 +3521,6 @@ process_fds(isc__socketmgr_t *manager, struct epoll_event *events, int nevents)
for (i = 0; i < nevents; i++) {
REQUIRE(events[i].data.fd < (int)manager->maxsocks);
-#ifdef USE_WATCHER_THREAD
- if (events[i].data.fd == manager->pipe_fds[0]) {
- have_ctlevent = ISC_TRUE;
- continue;
- }
-#endif
if ((events[i].events & EPOLLERR) != 0 ||
(events[i].events & EPOLLHUP) != 0) {
/*
@@ -3732,47 +3538,6 @@ process_fds(isc__socketmgr_t *manager, struct epoll_event *events, int nevents)
(events[i].events & EPOLLOUT) != 0);
}
-#ifdef USE_WATCHER_THREAD
- if (have_ctlevent)
- done = process_ctlfd(manager);
-#endif
-
- return (done);
-}
-#elif defined(USE_DEVPOLL)
-static isc_boolean_t
-process_fds(isc__socketmgr_t *manager, struct pollfd *events, int nevents) {
- int i;
- isc_boolean_t done = ISC_FALSE;
-#ifdef USE_WATCHER_THREAD
- isc_boolean_t have_ctlevent = ISC_FALSE;
-#endif
-
- if (nevents == manager->nevents) {
- manager_log(manager, ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_SOCKET, ISC_LOG_INFO,
- "maximum number of FD events (%d) received",
- nevents);
- }
-
- for (i = 0; i < nevents; i++) {
- REQUIRE(events[i].fd < (int)manager->maxsocks);
-#ifdef USE_WATCHER_THREAD
- if (events[i].fd == manager->pipe_fds[0]) {
- have_ctlevent = ISC_TRUE;
- continue;
- }
-#endif
- process_fd(manager, events[i].fd,
- (events[i].events & POLLIN) != 0,
- (events[i].events & POLLOUT) != 0);
- }
-
-#ifdef USE_WATCHER_THREAD
- if (have_ctlevent)
- done = process_ctlfd(manager);
-#endif
-
return (done);
}
#elif defined(USE_SELECT)
@@ -3785,215 +3550,12 @@ process_fds(isc__socketmgr_t *manager, int maxfd, fd_set *readfds,
REQUIRE(maxfd <= (int)manager->maxsocks);
for (i = 0; i < maxfd; i++) {
-#ifdef USE_WATCHER_THREAD
- if (i == manager->pipe_fds[0] || i == manager->pipe_fds[1])
- continue;
-#endif /* USE_WATCHER_THREAD */
process_fd(manager, i, FD_ISSET(i, readfds),
FD_ISSET(i, writefds));
}
}
#endif
-#ifdef USE_WATCHER_THREAD
-static isc_boolean_t
-process_ctlfd(isc__socketmgr_t *manager) {
- int msg, fd;
-
- for (;;) {
- select_readmsg(manager, &fd, &msg);
-
- manager_log(manager, IOEVENT,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKET,
- ISC_MSG_WATCHERMSG,
- "watcher got message %d "
- "for socket %d"), msg, fd);
-
- /*
- * Nothing to read?
- */
- if (msg == SELECT_POKE_NOTHING)
- break;
-
- /*
- * Handle shutdown message. We really should
- * jump out of this loop right away, but
- * it doesn't matter if we have to do a little
- * more work first.
- */
- if (msg == SELECT_POKE_SHUTDOWN)
- return (ISC_TRUE);
-
- /*
- * This is a wakeup on a socket. Look
- * at the event queue for both read and write,
- * and decide if we need to watch on it now
- * or not.
- */
- wakeup_socket(manager, fd, msg);
- }
-
- return (ISC_FALSE);
-}
-
-/*
- * This is the thread that will loop forever, always in a select or poll
- * call.
- *
- * When select returns something to do, track down what thread gets to do
- * this I/O and post the event to it.
- */
-static isc_threadresult_t
-watcher(void *uap) {
- isc__socketmgr_t *manager = uap;
- isc_boolean_t done;
- int cc;
-#ifdef USE_KQUEUE
- const char *fnname = "kevent()";
-#elif defined (USE_EPOLL)
- const char *fnname = "epoll_wait()";
-#elif defined(USE_DEVPOLL)
- isc_result_t result;
- const char *fnname = "ioctl(DP_POLL)";
- struct dvpoll dvp;
- int pass;
-#if defined(ISC_SOCKET_USE_POLLWATCH)
- pollstate_t pollstate = poll_idle;
-#endif
-#elif defined (USE_SELECT)
- const char *fnname = "select()";
- int maxfd;
- int ctlfd;
-#endif
- char strbuf[ISC_STRERRORSIZE];
-
-#if defined (USE_SELECT)
- /*
- * Get the control fd here. This will never change.
- */
- ctlfd = manager->pipe_fds[0];
-#endif
- done = ISC_FALSE;
- while (!done) {
- do {
-#ifdef USE_KQUEUE
- cc = kevent(manager->kqueue_fd, NULL, 0,
- manager->events, manager->nevents, NULL);
-#elif defined(USE_EPOLL)
- cc = epoll_wait(manager->epoll_fd, manager->events,
- manager->nevents, -1);
-#elif defined(USE_DEVPOLL)
- /*
- * Re-probe every thousand calls.
- */
- if (manager->calls++ > 1000U) {
- result = isc_resource_getcurlimit(
- isc_resource_openfiles,
- &manager->open_max);
- if (result != ISC_R_SUCCESS)
- manager->open_max = 64;
- manager->calls = 0;
- }
- for (pass = 0; pass < 2; pass++) {
- dvp.dp_fds = manager->events;
- dvp.dp_nfds = manager->nevents;
- if (dvp.dp_nfds >= manager->open_max)
- dvp.dp_nfds = manager->open_max - 1;
-#ifndef ISC_SOCKET_USE_POLLWATCH
- dvp.dp_timeout = -1;
-#else
- if (pollstate == poll_idle)
- dvp.dp_timeout = -1;
- else
- dvp.dp_timeout =
- ISC_SOCKET_POLLWATCH_TIMEOUT;
-#endif /* ISC_SOCKET_USE_POLLWATCH */
- cc = ioctl(manager->devpoll_fd, DP_POLL, &dvp);
- if (cc == -1 && errno == EINVAL) {
- /*
- * {OPEN_MAX} may have dropped. Look
- * up the current value and try again.
- */
- result = isc_resource_getcurlimit(
- isc_resource_openfiles,
- &manager->open_max);
- if (result != ISC_R_SUCCESS)
- manager->open_max = 64;
- } else
- break;
- }
-#elif defined(USE_SELECT)
- LOCK(&manager->lock);
- memmove(manager->read_fds_copy, manager->read_fds,
- manager->fd_bufsize);
- memmove(manager->write_fds_copy, manager->write_fds,
- manager->fd_bufsize);
- maxfd = manager->maxfd + 1;
- UNLOCK(&manager->lock);
-
- cc = select(maxfd, manager->read_fds_copy,
- manager->write_fds_copy, NULL, NULL);
-#endif /* USE_KQUEUE */
-
- if (cc < 0 && !SOFT_ERROR(errno)) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- FATAL_ERROR(__FILE__, __LINE__,
- "%s %s: %s", fnname,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED,
- "failed"), strbuf);
- }
-
-#if defined(USE_DEVPOLL) && defined(ISC_SOCKET_USE_POLLWATCH)
- if (cc == 0) {
- if (pollstate == poll_active)
- pollstate = poll_checking;
- else if (pollstate == poll_checking)
- pollstate = poll_idle;
- } else if (cc > 0) {
- if (pollstate == poll_checking) {
- /*
- * XXX: We'd like to use a more
- * verbose log level as it's actually an
- * unexpected event, but the kernel bug
- * reportedly happens pretty frequently
- * (and it can also be a false positive)
- * so it would be just too noisy.
- */
- manager_log(manager,
- ISC_LOGCATEGORY_GENERAL,
- ISC_LOGMODULE_SOCKET,
- ISC_LOG_DEBUG(1),
- "unexpected POLL timeout");
- }
- pollstate = poll_active;
- }
-#endif
- } while (cc < 0);
-
-#if defined(USE_KQUEUE) || defined (USE_EPOLL) || defined (USE_DEVPOLL)
- done = process_fds(manager, manager->events, cc);
-#elif defined(USE_SELECT)
- process_fds(manager, maxfd, manager->read_fds_copy,
- manager->write_fds_copy);
-
- /*
- * Process reads on internal, control fd.
- */
- if (FD_ISSET(ctlfd, manager->read_fds_copy))
- done = process_ctlfd(manager);
-#endif
- }
-
- manager_log(manager, TRACE, "%s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_EXITING, "watcher exiting"));
-
- return ((isc_threadresult_t)0);
-}
-#endif /* USE_WATCHER_THREAD */
-
void
isc__socketmgr_setreserved(isc_socketmgr_t *manager0, uint32_t reserved) {
isc__socketmgr_t *manager = (isc__socketmgr_t *)manager0;
@@ -4043,15 +3605,6 @@ setup_watcher(isc_mem_t *mctx, isc__socketmgr_t *manager) {
return (result);
}
-#ifdef USE_WATCHER_THREAD
- result = watch_fd(manager, manager->pipe_fds[0], SELECT_POKE_READ);
- if (result != ISC_R_SUCCESS) {
- close(manager->kqueue_fd);
- isc_mem_put(mctx, manager->events,
- sizeof(struct kevent) * manager->nevents);
- return (result);
- }
-#endif /* USE_WATCHER_THREAD */
#elif defined(USE_EPOLL)
manager->nevents = ISC_SOCKET_MAXEVENTS;
manager->events = isc_mem_get(mctx, sizeof(struct epoll_event) *
@@ -4071,64 +3624,6 @@ setup_watcher(isc_mem_t *mctx, isc__socketmgr_t *manager) {
sizeof(struct epoll_event) * manager->nevents);
return (result);
}
-#ifdef USE_WATCHER_THREAD
- result = watch_fd(manager, manager->pipe_fds[0], SELECT_POKE_READ);
- if (result != ISC_R_SUCCESS) {
- close(manager->epoll_fd);
- isc_mem_put(mctx, manager->events,
- sizeof(struct epoll_event) * manager->nevents);
- return (result);
- }
-#endif /* USE_WATCHER_THREAD */
-#elif defined(USE_DEVPOLL)
- manager->nevents = ISC_SOCKET_MAXEVENTS;
- result = isc_resource_getcurlimit(isc_resource_openfiles,
- &manager->open_max);
- if (result != ISC_R_SUCCESS)
- manager->open_max = 64;
- manager->calls = 0;
- manager->events = isc_mem_get(mctx, sizeof(struct pollfd) *
- manager->nevents);
- if (manager->events == NULL)
- return (ISC_R_NOMEMORY);
- /*
- * Note: fdpollinfo should be able to support all possible FDs, so
- * it must have maxsocks entries (not nevents).
- */
- manager->fdpollinfo = isc_mem_get(mctx, sizeof(pollinfo_t) *
- manager->maxsocks);
- if (manager->fdpollinfo == NULL) {
- isc_mem_put(mctx, manager->events,
- sizeof(struct pollfd) * manager->nevents);
- return (ISC_R_NOMEMORY);
- }
- memset(manager->fdpollinfo, 0, sizeof(pollinfo_t) * manager->maxsocks);
- manager->devpoll_fd = open("/dev/poll", O_RDWR);
- if (manager->devpoll_fd == -1) {
- result = isc__errno2result(errno);
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "open(/dev/poll) %s: %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"),
- strbuf);
- isc_mem_put(mctx, manager->events,
- sizeof(struct pollfd) * manager->nevents);
- isc_mem_put(mctx, manager->fdpollinfo,
- sizeof(pollinfo_t) * manager->maxsocks);
- return (result);
- }
-#ifdef USE_WATCHER_THREAD
- result = watch_fd(manager, manager->pipe_fds[0], SELECT_POKE_READ);
- if (result != ISC_R_SUCCESS) {
- close(manager->devpoll_fd);
- isc_mem_put(mctx, manager->events,
- sizeof(struct pollfd) * manager->nevents);
- isc_mem_put(mctx, manager->fdpollinfo,
- sizeof(pollinfo_t) * manager->maxsocks);
- return (result);
- }
-#endif /* USE_WATCHER_THREAD */
#elif defined(USE_SELECT)
UNUSED(result);
@@ -4176,12 +3671,7 @@ setup_watcher(isc_mem_t *mctx, isc__socketmgr_t *manager) {
memset(manager->read_fds, 0, manager->fd_bufsize);
memset(manager->write_fds, 0, manager->fd_bufsize);
-#ifdef USE_WATCHER_THREAD
- (void)watch_fd(manager, manager->pipe_fds[0], SELECT_POKE_READ);
- manager->maxfd = manager->pipe_fds[0];
-#else /* USE_WATCHER_THREAD */
manager->maxfd = 0;
-#endif /* USE_WATCHER_THREAD */
#endif /* USE_KQUEUE */
return (ISC_R_SUCCESS);
@@ -4189,17 +3679,6 @@ setup_watcher(isc_mem_t *mctx, isc__socketmgr_t *manager) {
static void
cleanup_watcher(isc_mem_t *mctx, isc__socketmgr_t *manager) {
-#ifdef USE_WATCHER_THREAD
- isc_result_t result;
-
- result = unwatch_fd(manager, manager->pipe_fds[0], SELECT_POKE_READ);
- if (result != ISC_R_SUCCESS) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "epoll_ctl(DEL) %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
- }
-#endif /* USE_WATCHER_THREAD */
#ifdef USE_KQUEUE
close(manager->kqueue_fd);
@@ -4209,12 +3688,6 @@ cleanup_watcher(isc_mem_t *mctx, isc__socketmgr_t *manager) {
close(manager->epoll_fd);
isc_mem_put(mctx, manager->events,
sizeof(struct epoll_event) * manager->nevents);
-#elif defined(USE_DEVPOLL)
- close(manager->devpoll_fd);
- isc_mem_put(mctx, manager->events,
- sizeof(struct pollfd) * manager->nevents);
- isc_mem_put(mctx, manager->fdpollinfo,
- sizeof(pollinfo_t) * manager->maxsocks);
#elif defined(USE_SELECT)
if (manager->read_fds != NULL)
isc_mem_put(mctx, manager->read_fds, manager->fd_bufsize);
@@ -4238,9 +3711,6 @@ isc__socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
{
int i;
isc__socketmgr_t *manager;
-#ifdef USE_WATCHER_THREAD
- char strbuf[ISC_STRERRORSIZE];
-#endif
isc_result_t result;
REQUIRE(managerp != NULL && *managerp == NULL);
@@ -4316,37 +3786,6 @@ isc__socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
}
}
-#ifdef USE_WATCHER_THREAD
- if (isc_condition_init(&manager->shutdown_ok) != ISC_R_SUCCESS) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_condition_init() %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
- result = ISC_R_UNEXPECTED;
- goto cleanup_lock;
- }
-
- /*
- * Create the special fds that will be used to wake up the
- * select/poll loop when something internal needs to be done.
- */
- if (pipe(manager->pipe_fds) != 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "pipe() %s: %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto cleanup_condition;
- }
-
- RUNTIME_CHECK(make_nonblock(manager->pipe_fds[0]) == ISC_R_SUCCESS);
-#if 0
- RUNTIME_CHECK(make_nonblock(manager->pipe_fds[1]) == ISC_R_SUCCESS);
-#endif
-#endif /* USE_WATCHER_THREAD */
-
#ifdef USE_SHARED_MANAGER
manager->refs = 1;
#endif /* USE_SHARED_MANAGER */
@@ -4360,22 +3799,6 @@ isc__socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
memset(manager->fdstate, 0, manager->maxsocks * sizeof(int));
-#ifdef USE_WATCHER_THREAD
- /*
- * Start up the select/poll thread.
- */
- if (isc_thread_create(watcher, manager, &manager->watcher) !=
- ISC_R_SUCCESS) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_thread_create() %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
- cleanup_watcher(mctx, manager);
- result = ISC_R_UNEXPECTED;
- goto cleanup;
- }
- isc_thread_setname(manager->watcher, "isc-socket");
-#endif /* USE_WATCHER_THREAD */
isc_mem_attach(mctx, &manager->mctx);
#ifdef USE_SHARED_MANAGER
@@ -4386,15 +3809,6 @@ isc__socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp,
return (ISC_R_SUCCESS);
cleanup:
-#ifdef USE_WATCHER_THREAD
- (void)close(manager->pipe_fds[0]);
- (void)close(manager->pipe_fds[1]);
-#endif /* USE_WATCHER_THREAD */
-
-#ifdef USE_WATCHER_THREAD
-cleanup_condition:
- (void)isc_condition_destroy(&manager->shutdown_ok);
-#endif /* USE_WATCHER_THREAD */
cleanup_lock:
@@ -4468,17 +3882,9 @@ isc__socketmgr_destroy(isc_socketmgr_t **managerp) {
* Wait for all sockets to be destroyed.
*/
while (!ISC_LIST_EMPTY(manager->socklist)) {
-#ifdef USE_WATCHER_THREAD
- manager_log(manager, CREATION, "%s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKET,
- ISC_MSG_SOCKETSREMAIN,
- "sockets exist"));
- WAIT(&manager->shutdown_ok, &manager->lock);
-#else /* USE_WATCHER_THREAD */
UNLOCK(&manager->lock);
isc__taskmgr_dispatch(NULL);
LOCK(&manager->lock);
-#endif /* USE_WATCHER_THREAD */
}
UNLOCK(&manager->lock);
@@ -4490,28 +3896,11 @@ isc__socketmgr_destroy(isc_socketmgr_t **managerp) {
*/
select_poke(manager, 0, SELECT_POKE_SHUTDOWN);
-#ifdef USE_WATCHER_THREAD
- /*
- * Wait for thread to exit.
- */
- if (isc_thread_join(manager->watcher, NULL) != ISC_R_SUCCESS)
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "isc_thread_join() %s",
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
-#endif /* USE_WATCHER_THREAD */
-
/*
* Clean up.
*/
cleanup_watcher(manager->mctx, manager);
-#ifdef USE_WATCHER_THREAD
- (void)close(manager->pipe_fds[0]);
- (void)close(manager->pipe_fds[1]);
- (void)isc_condition_destroy(&manager->shutdown_ok);
-#endif /* USE_WATCHER_THREAD */
-
for (i = 0; i < (int)manager->maxsocks; i++)
if (manager->fdstate[i] == CLOSE_PENDING) /* no need to lock */
(void)close(i);
@@ -5896,7 +5285,6 @@ isc_socket_socketevent(isc_mem_t *mctx, void *sender,
return (allocate_socketevent(mctx, sender, eventtype, action, arg));
}
-#ifndef USE_WATCHER_THREAD
/*
* In our assumed scenario, we can simply use a single static object.
* XXX: this is not true if the application uses multiple threads with
@@ -5916,11 +5304,6 @@ isc__socketmgr_waitevents(isc_socketmgr_t *manager0, struct timeval *tvp,
#ifdef USE_EPOLL
int timeout;
#endif
-#ifdef USE_DEVPOLL
- isc_result_t result;
- int pass;
- struct dvpoll dvp;
-#endif
REQUIRE(swaitp != NULL && *swaitp == NULL);
@@ -5951,42 +5334,6 @@ isc__socketmgr_waitevents(isc_socketmgr_t *manager0, struct timeval *tvp,
manager->events,
manager->nevents, timeout);
n = swait_private.nevents;
-#elif defined(USE_DEVPOLL)
- /*
- * Re-probe every thousand calls.
- */
- if (manager->calls++ > 1000U) {
- result = isc_resource_getcurlimit(isc_resource_openfiles,
- &manager->open_max);
- if (result != ISC_R_SUCCESS)
- manager->open_max = 64;
- manager->calls = 0;
- }
- for (pass = 0; pass < 2; pass++) {
- dvp.dp_fds = manager->events;
- dvp.dp_nfds = manager->nevents;
- if (dvp.dp_nfds >= manager->open_max)
- dvp.dp_nfds = manager->open_max - 1;
- if (tvp != NULL) {
- dvp.dp_timeout = tvp->tv_sec * 1000 +
- (tvp->tv_usec + 999) / 1000;
- } else
- dvp.dp_timeout = -1;
- n = ioctl(manager->devpoll_fd, DP_POLL, &dvp);
- if (n == -1 && errno == EINVAL) {
- /*
- * {OPEN_MAX} may have dropped. Look
- * up the current value and try again.
- */
- result = isc_resource_getcurlimit(
- isc_resource_openfiles,
- &manager->open_max);
- if (result != ISC_R_SUCCESS)
- manager->open_max = 64;
- } else
- break;
- }
- swait_private.nevents = n;
#elif defined(USE_SELECT)
memmove(manager->read_fds_copy, manager->read_fds, manager->fd_bufsize);
memmove(manager->write_fds_copy, manager->write_fds,
@@ -6025,7 +5372,6 @@ isc__socketmgr_dispatch(isc_socketmgr_t *manager0, isc_socketwait_t *swait) {
return (ISC_R_SUCCESS);
#endif
}
-#endif /* USE_WATCHER_THREAD */
void
isc__socket_setname(isc_socket_t *socket0, const char *name, void *tag) {
diff --git a/usr.sbin/bind/lib/isccfg/namedconf.c b/usr.sbin/bind/lib/isccfg/namedconf.c
index 5a7fa6c804a..6c59c0136dd 100644
--- a/usr.sbin/bind/lib/isccfg/namedconf.c
+++ b/usr.sbin/bind/lib/isccfg/namedconf.c
@@ -1993,7 +1993,7 @@ cfg_type_t cfg_type_newzones = {
};
static isc_result_t
-parse_unitstring(char *str, isc_resourcevalue_t *valuep) {
+parse_unitstring(char *str, uint64_t *valuep) {
char *endp;
unsigned int len;
uint64_t value;