Skip to content

Commit

Permalink
resolv: Deprecate the "inet6" option and RES_USE_INET6 [BZ #19582]
Browse files Browse the repository at this point in the history
  • Loading branch information
fweimer-rh committed Dec 31, 2016
1 parent 5840c75 commit b76e065
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 62 deletions.
38 changes: 38 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
2016-12-27 Florian Weimer <fweimer@redhat.com>

[BZ #19582]
Deprecate RES_USE_INET6.
* nis/nss_nis/nis-hosts.c (_nss_nis_gethostent_r)
(_nss_nis_gethostbyname2_r, _nss_nis_gethostbyname_r)
(_nss_nis_gethostbyaddr_r): Use res_use_inet6 instead of
RES_USE_INET6.
* nis/nss_nisplus/nisplus-hosts.c (internal_nisplus_gethostent_r)
(_nss_nisplus_gethostbyname2_r, _nss_nisplus_gethostbyname_r)
(_nss_nisplus_gethostbyaddr_r): Likewise.
* nscd/aicache.c (addhstaiX): Use DEPRECATED_RES_USE_INET6 instead
of res_use_inet6.
* nscd/nscd_gethst_r.c (__nscd_gethostbyname_r): Use res_use_inet6
instead of RES_USE_INET6.
* nss/digits_dots.c (__nss_hostname_digits_dots): Likewise.
* nss/nss_files/files-hosts.c (EXTRA_ARGS_VALUE)
(_nss_files_gethostbyname3_r, _nss_files_gethostbyname_r):
Likewise.
* resolv/compat-gethnamaddr.c (getanswer, res_gethostbyname)
(res_gethostbyname2, res_gethostbyaddr, _gethtent, _gethtbyname):
Likewise.
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname3_r)
(_nss_dns_gethostbyname_r): Likewise.
(_nss_dns_gethostbyaddr2_r): Remove commented-out code for
alternate RES_USE_INET6 handling.
* resolv/res_debug.c (p_option): Use DEPRECATED_RES_USE_INET6
instead of RES_USE_INET6.
* resolv/res_init.c (res_setoptions): Likewise.
* resolv/resolv.h (RES_USE_INET6): Mark as deprecated.
* resolv/resolv-internal.h: New file.
* resolv/Makefile (CFLAGS-tst-res_use_inet6.c): Use -Wno-error to
make the deprecation warning non-fatal.
* resolv/README (Using the resolver in multi-threaded code): Drop
reference to RES_USE_INET6.
* sysdeps/posix/getaddrinfo.c (gethosts, gaih_inet): Use
DEPRECATED_RES_USE_INET6 instead of res_use_inet6.

2016-12-31 Florian Weimer <fweimer@redhat.com>

* resolv/Makefile (tests): Add tst-bug18665, tst-bug18665-tcp,
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ Version 2.25
in the <resolv.h> header file have been deprecated. They were already
unimplemented.

* The "inet6" option in /etc/resolv.conf and the RES_USE_INET6 flag for
_res.flags are deprecated. The flag was standardized in RFC 2133, but
removed again from the IETF name lookup interface specification in RFC
2553. Applications should use getaddrinfo instead.

* DNSSEC-related declarations and definitions have been removed from the
<arpa/nameser.h> header file, and libresolv will no longer attempt to
decode the data part of DNSSEC record types. Previous versions of glibc
Expand Down
13 changes: 6 additions & 7 deletions nis/nss_nis/nis-hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <libc-lock.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
Expand Down Expand Up @@ -231,8 +231,8 @@ _nss_nis_gethostent_r (struct hostent *host, char *buffer, size_t buflen,
__libc_lock_lock (lock);

status = internal_nis_gethostent_r (host, buffer, buflen, errnop, h_errnop,
((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET),
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0 ));
(res_use_inet6 () ? AF_INET6 : AF_INET),
(res_use_inet6 () ? AI_V4MAPPED : 0 ));

__libc_lock_unlock (lock);

Expand Down Expand Up @@ -351,15 +351,15 @@ _nss_nis_gethostbyname2_r (const char *name, int af, struct hostent *host,

return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
h_errnop,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
(res_use_inet6 () ? AI_V4MAPPED : 0));
}


enum nss_status
_nss_nis_gethostbyname_r (const char *name, struct hostent *host, char *buffer,
size_t buflen, int *errnop, int *h_errnop)
{
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
{
enum nss_status status;

Expand Down Expand Up @@ -433,8 +433,7 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
free (result);

int parse_res = parse_line (p, host, data, buflen, errnop, af,
((_res.options & RES_USE_INET6)
? AI_V4MAPPED : 0));
(res_use_inet6 () ? AI_V4MAPPED : 0));
if (__glibc_unlikely (parse_res < 1))
{
if (parse_res == -1)
Expand Down
9 changes: 5 additions & 4 deletions nis/nss_nisplus/nisplus-hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static u_long tablename_len;
(NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)

/* Get implementation for some internal functions. */
#include <resolv/resolv-internal.h>
#include <resolv/mapv4v6addr.h>


Expand Down Expand Up @@ -321,7 +322,7 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer,
}
}

if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
parse_res = _nss_nisplus_parse_hostent (result, AF_INET6, host, buffer,
buflen, errnop, AI_V4MAPPED);
else
Expand Down Expand Up @@ -488,7 +489,7 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host,

return internal_gethostbyname2_r (name, af, host, buffer, buflen, errnop,
herrnop,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
(res_use_inet6 () ? AI_V4MAPPED : 0));
}


Expand All @@ -497,7 +498,7 @@ _nss_nisplus_gethostbyname_r (const char *name, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
int *h_errnop)
{
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
{
enum nss_status status;

Expand Down Expand Up @@ -558,7 +559,7 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,

parse_res = _nss_nisplus_parse_hostent (result, af, host,
buffer, buflen, errnop,
((_res.options & RES_USE_INET6)
(res_use_inet6 ()
? AI_V4MAPPED : 0));
nis_freeresult (result);

Expand Down
5 changes: 3 additions & 2 deletions nscd/aicache.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <time.h>
#include <unistd.h>
#include <sys/mman.h>
#include <resolv/resolv-internal.h>
#include <resolv/res_hconf.h>

#include "dbg_log.h"
Expand Down Expand Up @@ -110,7 +111,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
IPv6 addresses. Currently this is decided by setting the
RES_USE_INET6 bit in _res.options. */
int old_res_options = _res.options;
_res.options &= ~RES_USE_INET6;
_res.options &= ~DEPRECATED_RES_USE_INET6;

size_t tmpbuf6len = 1024;
char *tmpbuf6 = alloca (tmpbuf6len);
Expand Down Expand Up @@ -535,7 +536,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
}

out:
_res.options |= old_res_options & RES_USE_INET6;
_res.options |= old_res_options & DEPRECATED_RES_USE_INET6;

if (dataset != NULL && !alloca_used)
{
Expand Down
4 changes: 2 additions & 2 deletions nscd/nscd_gethst_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<http://www.gnu.org/licenses/>. */

#include <errno.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
Expand All @@ -42,7 +42,7 @@ __nscd_gethostbyname_r (const char *name, struct hostent *resultbuf,
{
request_type reqtype;

reqtype = (_res.options & RES_USE_INET6) ? GETHOSTBYNAMEv6 : GETHOSTBYNAME;
reqtype = res_use_inet6 () ? GETHOSTBYNAMEv6 : GETHOSTBYNAME;

return nscd_gethst_r (name, strlen (name) + 1, reqtype, resultbuf,
buffer, buflen, result, h_errnop);
Expand Down
8 changes: 4 additions & 4 deletions nss/digits_dots.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <wctype.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>
#include <netdb.h>
#include <arpa/inet.h>
#include "nsswitch.h"
Expand Down Expand Up @@ -80,7 +80,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
break;

default:
af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET;
af = res_use_inet6 () ? AF_INET6 : AF_INET;
addr_size = af == AF_INET6 ? IN6ADDRSZ : INADDRSZ;
break;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
(*h_addr_ptrs)[0] = (char *) host_addr;
(*h_addr_ptrs)[1] = NULL;
resbuf->h_addr_list = *h_addr_ptrs;
if (af == AF_INET && (_res.options & RES_USE_INET6))
if (af == AF_INET && res_use_inet6 ())
{
/* We need to change the IP v4 address into the
IP v6 address. */
Expand Down Expand Up @@ -211,7 +211,7 @@ __nss_hostname_digits_dots (const char *name, struct hostent *resbuf,
switch (af)
{
default:
af = (_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET;
af = res_use_inet6 () ? AF_INET6 : AF_INET;
if (af == AF_INET6)
{
addr_size = IN6ADDRSZ;
Expand Down
10 changes: 5 additions & 5 deletions nss/nss_files/files-hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
#include <resolv/resolv-internal.h>


/* Get implementation for some internal functions. */
Expand Down Expand Up @@ -98,8 +98,8 @@ LINE_PARSER
})

#define EXTRA_ARGS_VALUE \
, ((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET), \
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0)
, (res_use_inet6 () ? AF_INET6 : AF_INET), \
(res_use_inet6 () ? AI_V4MAPPED : 0)
#include "files-XXX.c"
#undef EXTRA_ARGS_VALUE

Expand Down Expand Up @@ -132,7 +132,7 @@ _nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
{
/* XXX Is using _res to determine whether we want to convert IPv4
addresses to IPv6 addresses really the right thing to do? */
int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0);
int flags = (res_use_inet6 () ? AI_V4MAPPED : 0);

while ((status = internal_getent (stream, result, buffer, buflen, errnop,
herrnop, af, flags))
Expand Down Expand Up @@ -351,7 +351,7 @@ _nss_files_gethostbyname_r (const char *name, struct hostent *result,
char *buffer, size_t buflen, int *errnop,
int *herrnop)
{
int af = ((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET);
int af = (res_use_inet6 () ? AF_INET6 : AF_INET);

return _nss_files_gethostbyname3_r (name, af, result, buffer, buflen,
errnop, herrnop, NULL, NULL);
Expand Down
3 changes: 3 additions & 0 deletions resolv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,6 @@ $(objpfx)tst-res_use_inet6: $(objpfx)libresolv.so $(shared-thread-library)
$(objpfx)tst-resolv-basic: $(objpfx)libresolv.so $(shared-thread-library)
$(objpfx)tst-resolv-network: $(objpfx)libresolv.so $(shared-thread-library)
$(objpfx)tst-resolv-search: $(objpfx)libresolv.so $(shared-thread-library)

# This test case uses the deprecated RES_USE_INET6 resolver option.
CFLAGS-tst-res_use_inet6.c += -Wno-error
6 changes: 1 addition & 5 deletions resolv/README
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ code:

* In Multi-threaded that manipulate the _res structure, calls to
functions like `gethostbyname' in threads other than the "main"
thread won't be influenced by the those changes anymore. So if you
set RES_USE_INET6, a call to `gethostbyname' won't return any IPv6
hosts anymore. If you recompile such programs, manipulating the
_res structure will affect the thread in which you do so instead of
the "main" thread.
thread won't be influenced by the those changes anymore.

We recommend to use the new thread-safe interfaces in new code, since
the traditional interfaces have been deprecated by the BIND folks.
Expand Down
14 changes: 7 additions & 7 deletions resolv/compat-gethnamaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

# include <stdio.h>
# include <netdb.h>
# include <resolv.h>
# include <resolv/resolv-internal.h>
# include <ctype.h>
# include <errno.h>
# include <stdlib.h>
Expand Down Expand Up @@ -412,7 +412,7 @@ getanswer (const querybuf *answer, int anslen, const char *qname, int qtype)
bp += n;
buflen -= n;
}
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
map_v4v6_hostent(&host, &bp, &buflen);
__set_h_errno (NETDB_SUCCESS);
return (&host);
Expand All @@ -434,7 +434,7 @@ res_gethostbyname (const char *name)
__set_h_errno (NETDB_INTERNAL);
return (NULL);
}
if (_res.options & RES_USE_INET6) {
if (res_use_inet6 ()) {
hp = res_gethostbyname2(name, AF_INET6);
if (hp)
return (hp);
Expand Down Expand Up @@ -516,7 +516,7 @@ res_gethostbyname2 (const char *name, int af)
h_addr_ptrs[0] = (char *)host_addr;
h_addr_ptrs[1] = NULL;
host.h_addr_list = h_addr_ptrs;
if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
map_v4v6_hostent(&host, &bp, &len);
__set_h_errno (NETDB_SUCCESS);
return (&host);
Expand Down Expand Up @@ -665,7 +665,7 @@ res_gethostbyaddr (const void *addr, socklen_t len, int af)
memmove(host_addr, addr, len);
h_addr_ptrs[0] = (char *)host_addr;
h_addr_ptrs[1] = NULL;
if (af == AF_INET && (_res.options & RES_USE_INET6)) {
if (af == AF_INET && res_use_inet6 ()) {
map_v4v6_address((char*)host_addr, (char*)host_addr);
hp->h_addrtype = AF_INET6;
hp->h_length = IN6ADDRSZ;
Expand Down Expand Up @@ -724,7 +724,7 @@ _gethtent (void)
af = AF_INET6;
len = IN6ADDRSZ;
} else if (inet_pton(AF_INET, p, host_addr) > 0) {
if (_res.options & RES_USE_INET6) {
if (res_use_inet6 ()) {
map_v4v6_address((char*)host_addr, (char*)host_addr);
af = AF_INET6;
len = IN6ADDRSZ;
Expand Down Expand Up @@ -768,7 +768,7 @@ _gethtbyname (const char *name)
{
struct hostent *hp;

if (_res.options & RES_USE_INET6) {
if (res_use_inet6 ()) {
hp = _gethtbyname2(name, AF_INET6);
if (hp)
return (hp);
Expand Down
18 changes: 4 additions & 14 deletions resolv/nss_dns/dns-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@

#include "nsswitch.h"

/* Get implementation for some internal functions. */
/* Get implementeation for some internal functions. */
#include <resolv/resolv-internal.h>
#include <resolv/mapv4v6addr.h>
#include <resolv/mapv4v6hostent.h>

Expand Down Expand Up @@ -232,7 +233,7 @@ _nss_dns_gethostbyname3_r (const char *name, int af, struct hostent *result,
/* If we are looking for an IPv6 address and mapping is enabled
by having the RES_USE_INET6 bit in _res.options set, we try
another lookup. */
if (af == AF_INET6 && (_res.options & RES_USE_INET6))
if (af == AF_INET6 && res_use_inet6 ())
n = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer.buf->buf,
host_buffer.buf != orig_host_buffer
? MAXPACKET : 1024, &host_buffer.ptr,
Expand Down Expand Up @@ -277,7 +278,7 @@ _nss_dns_gethostbyname_r (const char *name, struct hostent *result,
{
enum nss_status status = NSS_STATUS_NOTFOUND;

if (_res.options & RES_USE_INET6)
if (res_use_inet6 ())
status = _nss_dns_gethostbyname3_r (name, AF_INET6, result, buffer,
buflen, errnop, h_errnop, NULL, NULL);
if (status == NSS_STATUS_NOTFOUND)
Expand Down Expand Up @@ -503,17 +504,6 @@ _nss_dns_gethostbyaddr2_r (const void *addr, socklen_t len, int af,
memcpy (host_data->host_addr, addr, len);
host_data->h_addr_ptrs[0] = (char *) host_data->host_addr;
host_data->h_addr_ptrs[1] = NULL;
#if 0
/* XXX I think this is wrong. Why should an IPv4 address be
converted to IPv6 if the user explicitly asked for IPv4? */
if (af == AF_INET && (_res.options & RES_USE_INET6))
{
map_v4v6_address ((char *) host_data->host_addr,
(char *) host_data->host_addr);
result->h_addrtype = AF_INET6;
result->h_length = IN6ADDRSZ;
}
#endif
*h_errnop = NETDB_SUCCESS;
return NSS_STATUS_SUCCESS;
}
Expand Down
Loading

0 comments on commit b76e065

Please sign in to comment.