about summary refs log tree commit diff
path: root/resolv
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-10-04 11:52:10 +0200
committerFlorian Weimer <fweimer@redhat.com>2016-12-31 18:55:14 +0100
commitb76e065991ec01299225d9da90a627ebe6c1ac97 (patch)
treeac94cc82b134096975419ced320f6ed329130756 /resolv
parent5840c75c2d6a9b980d6789f2ca7d47a9fa067263 (diff)
downloadglibc-b76e065991ec01299225d9da90a627ebe6c1ac97.tar.gz
glibc-b76e065991ec01299225d9da90a627ebe6c1ac97.tar.xz
glibc-b76e065991ec01299225d9da90a627ebe6c1ac97.zip
resolv: Deprecate the "inet6" option and RES_USE_INET6 [BZ #19582]
Diffstat (limited to 'resolv')
-rw-r--r--resolv/Makefile3
-rw-r--r--resolv/README6
-rw-r--r--resolv/compat-gethnamaddr.c14
-rw-r--r--resolv/nss_dns/dns-host.c18
-rw-r--r--resolv/res_debug.c4
-rw-r--r--resolv/res_init.c4
-rw-r--r--resolv/resolv-internal.h35
-rw-r--r--resolv/resolv.h3
8 files changed, 56 insertions, 31 deletions
diff --git a/resolv/Makefile b/resolv/Makefile
index 5eb10e38af..1e9f56285c 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -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
diff --git a/resolv/README b/resolv/README
index 17aa631c92..c50025168c 100644
--- a/resolv/README
+++ b/resolv/README
@@ -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.
diff --git a/resolv/compat-gethnamaddr.c b/resolv/compat-gethnamaddr.c
index 6d2292b4cd..813c7d4e85 100644
--- a/resolv/compat-gethnamaddr.c
+++ b/resolv/compat-gethnamaddr.c
@@ -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>
@@ -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);
@@ -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);
@@ -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);
@@ -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;
@@ -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;
@@ -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);
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index c1333b816b..901e037451 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -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>
 
@@ -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,
@@ -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)
@@ -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;
 }
diff --git a/resolv/res_debug.c b/resolv/res_debug.c
index a0383d47cb..33891878d8 100644
--- a/resolv/res_debug.c
+++ b/resolv/res_debug.c
@@ -101,7 +101,7 @@
 #include <errno.h>
 #include <math.h>
 #include <netdb.h>
-#include <resolv.h>
+#include <resolv/resolv-internal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -556,7 +556,7 @@ p_option(u_long option) {
 	case RES_INSECURE1:	return "insecure1";
 	case RES_INSECURE2:	return "insecure2";
 	case RES_NOALIASES:	return "noaliases";
-	case RES_USE_INET6:	return "inet6";
+	case DEPRECATED_RES_USE_INET6:	return "inet6";
 	case RES_ROTATE:	return "rotate";
 	case RES_BLAST:		return "blast";
 	case RES_USE_EDNS0:	return "edns0";
diff --git a/resolv/res_init.c b/resolv/res_init.c
index b29c0d4ee5..923724f86d 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -66,7 +66,7 @@
 
 #include <ctype.h>
 #include <netdb.h>
-#include <resolv.h>
+#include <resolv/resolv-internal.h>
 #include <stdio.h>
 #include <stdio_ext.h>
 #include <stdlib.h>
@@ -437,7 +437,7 @@ res_setoptions(res_state statp, const char *options, const char *source) {
 		    unsigned long int flag;
 		  } options[] = {
 #define STRnLEN(str) str, sizeof (str) - 1
-		    { STRnLEN ("inet6"), 0, RES_USE_INET6 },
+		    { STRnLEN ("inet6"), 0, DEPRECATED_RES_USE_INET6 },
 		    { STRnLEN ("rotate"), 0, RES_ROTATE },
 		    { STRnLEN ("edns0"), 0, RES_USE_EDNS0 },
 		    { STRnLEN ("single-request-reopen"), 0, RES_SNGLKUPREOP },
diff --git a/resolv/resolv-internal.h b/resolv/resolv-internal.h
new file mode 100644
index 0000000000..269758c416
--- /dev/null
+++ b/resolv/resolv-internal.h
@@ -0,0 +1,35 @@
+/* libresolv interfaces for internal use across glibc.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _RESOLV_INTERNAL_H
+#define _RESOLV_INTERNAL_H 1
+
+#include <resolv.h>
+#include <stdbool.h>
+
+/* Internal version of RES_USE_INET6 which does not trigger a
+   deprecation warning.  */
+#define DEPRECATED_RES_USE_INET6 0x00002000
+
+static inline bool
+res_use_inet6 (void)
+{
+  return _res.options & DEPRECATED_RES_USE_INET6;
+}
+
+#endif  /* _RESOLV_INTERNAL_H */
diff --git a/resolv/resolv.h b/resolv/resolv.h
index 1062903699..ddc022091c 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -190,7 +190,8 @@ struct res_sym {
 #define	RES_INSECURE1	0x00000400	/* type 1 security disabled */
 #define	RES_INSECURE2	0x00000800	/* type 2 security disabled */
 #define	RES_NOALIASES	0x00001000	/* shuts off HOSTALIASES feature */
-#define	RES_USE_INET6	0x00002000	/* use/map IPv6 in gethostbyname() */
+#define	RES_USE_INET6	\
+  __glibc_macro_warning ("RES_USE_INET6 is deprecated") 0x00002000
 #define RES_ROTATE	0x00004000	/* rotate ns list after each query */
 #define	RES_NOCHECKNAME \
   __glibc_macro_warning ("RES_NOCHECKNAME is deprecated") 0x00008000