From 3afb9c2528a8d3ecb43181eac8fb67400ef9deb6 Mon Sep 17 00:00:00 2001 From: Florian Obser Date: Tue, 15 Sep 2020 08:19:30 +0000 Subject: we no longer need isc_netaddr_t OK beck, deraadt (who also OK'ed the previous two diffs) --- usr.bin/dig/dighost.c | 26 ++++-- usr.bin/dig/lib/isc/Makefile.inc | 4 +- usr.bin/dig/lib/isc/include/isc/netaddr.h | 77 --------------- usr.bin/dig/lib/isc/include/isc/types.h | 3 +- usr.bin/dig/lib/isc/netaddr.c | 119 ------------------------ usr.bin/dig/lib/isc/sockaddr.c | 26 +++--- usr.bin/dig/lib/isccfg/include/isccfg/grammar.h | 3 +- 7 files changed, 32 insertions(+), 226 deletions(-) delete mode 100644 usr.bin/dig/lib/isc/include/isc/netaddr.h delete mode 100644 usr.bin/dig/lib/isc/netaddr.c (limited to 'usr.bin') diff --git a/usr.bin/dig/dighost.c b/usr.bin/dig/dighost.c index 92a9710cf9d..1930361eded 100644 --- a/usr.bin/dig/dighost.c +++ b/usr.bin/dig/dighost.c @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dighost.c,v 1.31 2020/09/15 08:15:17 florian Exp $ */ +/* $Id: dighost.c,v 1.32 2020/09/15 08:19:29 florian Exp $ */ /*! \file * \note @@ -55,7 +55,6 @@ #include #include #include -#include #include #include #include @@ -558,10 +557,9 @@ isc_result_t set_nameserver(char *opt) { isc_result_t result; isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES]; - isc_netaddr_t netaddr; int count, i; dig_server_t *srv; - char tmp[ISC_NETADDR_FORMATSIZE]; + char tmp[NI_MAXHOST]; if (opt == NULL) return ISC_R_NOTFOUND; @@ -574,8 +572,12 @@ set_nameserver(char *opt) { flush_server_list(); for (i = 0; i < count; i++) { - isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]); - isc_netaddr_format(&netaddr, tmp, sizeof(tmp)); + int error; + error = getnameinfo(&sockaddrs[i].type.sa, + sockaddrs[i].type.sa.sa_len, tmp, sizeof(tmp), NULL, 0, + NI_NUMERICHOST | NI_NUMERICSERV); + if (error) + fatal("%s", gai_strerror(error)); srv = make_server(tmp, opt); if (srv == NULL) fatal("memory allocation failure"); @@ -3733,10 +3735,9 @@ int getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp) { isc_result_t result; isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES]; - isc_netaddr_t netaddr; int count, i; dig_server_t *srv; - char tmp[ISC_NETADDR_FORMATSIZE]; + char tmp[NI_MAXHOST]; result = get_addresses(host, 0, sockaddrs, DIG_MAX_ADDRESSES, &count); @@ -3750,8 +3751,13 @@ getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp) { } for (i = 0; i < count; i++) { - isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]); - isc_netaddr_format(&netaddr, tmp, sizeof(tmp)); + int error; + error = getnameinfo(&sockaddrs[i].type.sa, + sockaddrs[i].type.sa.sa_len, tmp, sizeof(tmp), NULL, 0, + NI_NUMERICHOST | NI_NUMERICSERV); + if (error) + fatal("%s", gai_strerror(error)); + srv = make_server(tmp, host); ISC_LIST_APPEND(lookup->my_server_list, srv, link); } diff --git a/usr.bin/dig/lib/isc/Makefile.inc b/usr.bin/dig/lib/isc/Makefile.inc index 568a648f9ab..864ce2abbe6 100644 --- a/usr.bin/dig/lib/isc/Makefile.inc +++ b/usr.bin/dig/lib/isc/Makefile.inc @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile.inc,v 1.7 2020/09/13 09:33:39 florian Exp $ +# $OpenBSD: Makefile.inc,v 1.8 2020/09/15 08:19:29 florian Exp $ .PATH: ${.CURDIR}/lib/isc -SRCS+= assertions.c base32.c base64.c netaddr.c buffer.c bufferlist.c +SRCS+= assertions.c base32.c base64.c buffer.c bufferlist.c SRCS+= error.c event.c hash.c heap.c hex.c hmacsha.c SRCS+= lex.c log.c regex.c sockaddr.c SRCS+= task.c result.c refcount.c timer.c diff --git a/usr.bin/dig/lib/isc/include/isc/netaddr.h b/usr.bin/dig/lib/isc/include/isc/netaddr.h deleted file mode 100644 index 4084269ea9e..00000000000 --- a/usr.bin/dig/lib/isc/include/isc/netaddr.h +++ /dev/null @@ -1,77 +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: netaddr.h,v 1.7 2020/09/15 08:13:35 florian Exp $ */ - -#ifndef ISC_NETADDR_H -#define ISC_NETADDR_H 1 - -/*! \file isc/netaddr.h */ - -#include - -#include -#include -#include -#include -#include - -struct isc_netaddr { - unsigned int family; - union { - struct in_addr in; - struct in6_addr in6; - char un[sizeof(((struct sockaddr_un *)0)->sun_path)]; - } type; - uint32_t zone; -}; - -/*%< - * Compare the 'prefixlen' most significant bits of the network - * addresses 'a' and 'b'. If 'b''s scope is zero then 'a''s scope is - * ignored. Return #1 if they are equal, #0 if not. - */ - -isc_result_t -isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target); -/*%< - * Append a text representation of 'sockaddr' to the buffer 'target'. - * The text is NOT null terminated. Handles IPv4 and IPv6 addresses. - * - * Returns: - *\li #ISC_R_SUCCESS - *\li #ISC_R_NOSPACE The text or the null termination did not fit. - *\li #ISC_R_FAILURE Unspecified failure - */ - -void -isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size); -/*%< - * Format a human-readable representation of the network address '*na' - * into the character array 'array', which is of size 'size'. - * The resulting string is guaranteed to be null-terminated. - */ - -#define ISC_NETADDR_FORMATSIZE \ - sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX%SSSSSSSSSS") -/*%< - * Minimum size of array to pass to isc_netaddr_format(). - */ - -void -isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source); - -#endif /* ISC_NETADDR_H */ diff --git a/usr.bin/dig/lib/isc/include/isc/types.h b/usr.bin/dig/lib/isc/include/isc/types.h index 0352aee05fa..6822ae6c41b 100644 --- a/usr.bin/dig/lib/isc/include/isc/types.h +++ b/usr.bin/dig/lib/isc/include/isc/types.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: types.h,v 1.5 2020/09/14 08:40:44 florian Exp $ */ +/* $Id: types.h,v 1.6 2020/09/15 08:19:29 florian Exp $ */ #ifndef ISC_TYPES_H #define ISC_TYPES_H 1 @@ -42,7 +42,6 @@ typedef struct isc_log isc_log_t; /*%< Log */ typedef struct isc_logcategory isc_logcategory_t; /*%< Log Category */ typedef struct isc_logconfig isc_logconfig_t; /*%< Log Configuration */ typedef struct isc_logmodule isc_logmodule_t; /*%< Log Module */ -typedef struct isc_netaddr isc_netaddr_t; /*%< Net Address */ typedef struct isc_region isc_region_t; /*%< Region */ typedef unsigned int isc_result_t; /*%< Result */ typedef struct isc_sockaddr isc_sockaddr_t; /*%< Socket Address */ diff --git a/usr.bin/dig/lib/isc/netaddr.c b/usr.bin/dig/lib/isc/netaddr.c deleted file mode 100644 index f22203d22dd..00000000000 --- a/usr.bin/dig/lib/isc/netaddr.c +++ /dev/null @@ -1,119 +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: netaddr.c,v 1.10 2020/09/15 08:13:35 florian Exp $ */ - -/*! \file */ - -#include - -#include -#include - -#include -#include -#include - -isc_result_t -isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target) { - char abuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")]; - char zbuf[sizeof("%4294967295")]; - unsigned int alen; - int zlen; - const char *r; - const void *type; - - REQUIRE(netaddr != NULL); - - switch (netaddr->family) { - case AF_INET: - type = &netaddr->type.in; - break; - case AF_INET6: - type = &netaddr->type.in6; - break; - default: - return (ISC_R_FAILURE); - } - r = inet_ntop(netaddr->family, type, abuf, sizeof(abuf)); - if (r == NULL) - return (ISC_R_FAILURE); - - alen = strlen(abuf); - INSIST(alen < sizeof(abuf)); - - zlen = 0; - if (netaddr->family == AF_INET6 && netaddr->zone != 0) { - zlen = snprintf(zbuf, sizeof(zbuf), "%%%u", netaddr->zone); - if (zlen < 0) - return (ISC_R_FAILURE); - INSIST((unsigned int)zlen < sizeof(zbuf)); - } - - if (alen + zlen > isc_buffer_availablelength(target)) - return (ISC_R_NOSPACE); - - isc_buffer_putmem(target, (unsigned char *)abuf, alen); - isc_buffer_putmem(target, (unsigned char *)zbuf, zlen); - - return (ISC_R_SUCCESS); -} - -void -isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size) { - isc_result_t result; - isc_buffer_t buf; - - isc_buffer_init(&buf, array, size); - result = isc_netaddr_totext(na, &buf); - - if (size == 0) - return; - - /* - * Null terminate. - */ - if (result == ISC_R_SUCCESS) { - if (isc_buffer_availablelength(&buf) >= 1) - isc_buffer_putuint8(&buf, 0); - else - result = ISC_R_NOSPACE; - } - - if (result != ISC_R_SUCCESS) { - snprintf(array, size, "", - na->family); - array[size - 1] = '\0'; - } -} - -void -isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s) { - int family = s->type.sa.sa_family; - t->family = family; - switch (family) { - case AF_INET: - t->type.in = s->type.sin.sin_addr; - t->zone = 0; - break; - case AF_INET6: - memmove(&t->type.in6, &s->type.sin6.sin6_addr, 16); - t->zone = s->type.sin6.sin6_scope_id; - break; - default: - INSIST(0); - } -} diff --git a/usr.bin/dig/lib/isc/sockaddr.c b/usr.bin/dig/lib/isc/sockaddr.c index 90beb4a58ec..911653ec6a0 100644 --- a/usr.bin/dig/lib/isc/sockaddr.c +++ b/usr.bin/dig/lib/isc/sockaddr.c @@ -14,14 +14,15 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: sockaddr.c,v 1.10 2020/09/15 08:13:35 florian Exp $ */ +/* $Id: sockaddr.c,v 1.11 2020/09/15 08:19:29 florian Exp $ */ /*! \file */ - +#include +#include +#include #include #include -#include #include #include @@ -95,18 +96,17 @@ isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b, isc_result_t isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { - isc_result_t result; - isc_netaddr_t netaddr; char pbuf[sizeof("65000")]; unsigned int plen; isc_region_t avail; + int error; + char tmp[NI_MAXHOST]; REQUIRE(sockaddr != NULL); /* * Do the port first, giving us the opportunity to check for - * unsupported address families before calling - * isc_netaddr_fromsockaddr(). + * unsupported address families. */ switch (sockaddr->type.sa.sa_family) { case AF_INET: @@ -122,10 +122,11 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) { plen = strlen(pbuf); INSIST(plen < sizeof(pbuf)); - isc_netaddr_fromsockaddr(&netaddr, sockaddr); - result = isc_netaddr_totext(&netaddr, target); - if (result != ISC_R_SUCCESS) - return (result); + error = getnameinfo(&sockaddr->type.sa, sockaddr->type.sa.sa_len, tmp, + sizeof(tmp), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV); + if (strlen(tmp) > isc_buffer_availablelength(target)) + return (ISC_R_NOSPACE); + isc_buffer_putmem(target, tmp, strlen(tmp)); if (1 + plen + 1 > isc_buffer_availablelength(target)) return (ISC_R_NOSPACE); @@ -154,9 +155,6 @@ isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size) { isc_buffer_init(&buf, array, size); result = isc_sockaddr_totext(sa, &buf); if (result != ISC_R_SUCCESS) { - /* - * The message is the same as in netaddr.c. - */ snprintf(array, size, "", sa->type.sa.sa_family); array[size - 1] = '\0'; diff --git a/usr.bin/dig/lib/isccfg/include/isccfg/grammar.h b/usr.bin/dig/lib/isccfg/include/isccfg/grammar.h index d37b57bf4e2..f85b53ffb95 100644 --- a/usr.bin/dig/lib/isccfg/include/isccfg/grammar.h +++ b/usr.bin/dig/lib/isccfg/include/isccfg/grammar.h @@ -14,7 +14,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: grammar.h,v 1.5 2020/09/14 08:40:44 florian Exp $ */ +/* $Id: grammar.h,v 1.6 2020/09/15 08:19:29 florian Exp $ */ #ifndef ISCCFG_GRAMMAR_H #define ISCCFG_GRAMMAR_H 1 @@ -22,7 +22,6 @@ /*! \file isccfg/grammar.h */ #include -#include #include #include #include -- cgit v1.2.3