aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-06-30 21:10:23 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-07-03 20:52:59 +0200
commit352f4ff9a268b81ef5d4b2413f582565806e4790 (patch)
treefb27056dfdeafe43c021f6127c9544c016e78019 /sysdeps
parent4e45d83c92dbb5b8dc20654f32395108d18cf739 (diff)
downloadglibc-352f4ff9a268b81ef5d4b2413f582565806e4790.tar
glibc-352f4ff9a268b81ef5d4b2413f582565806e4790.tar.gz
glibc-352f4ff9a268b81ef5d4b2413f582565806e4790.tar.bz2
glibc-352f4ff9a268b81ef5d4b2413f582565806e4790.zip
resolv: Introduce struct resolv_context [BZ #21668]
struct resolv_context objects provide a temporary resolver context which does not change during a name lookup operation. Only when the outmost context is created, the stub resolver configuration is verified to be current (at present, only against previous res_init calls). Subsequent attempts to obtain the context will reuse the result of the initial verification operation. struct resolv_context can also be extended in the future to store data which needs to be deallocated during thread cancellation.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/posix/getaddrinfo.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 4fb1eaef79..efa7118498 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -60,6 +60,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <netdb.h>
#include <nss.h>
#include <resolv/resolv-internal.h>
+#include <resolv/resolv_context.h>
+#include <resolv/res_use_inet6.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio_ext.h>
@@ -266,7 +268,8 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
if (herrno == NETDB_INTERNAL) \
{ \
__set_h_errno (herrno); \
- _res.options |= old_res_options & DEPRECATED_RES_USE_INET6; \
+ __resolv_context_enable_inet6 (res_ctx, res_enable_inet6); \
+ __resolv_context_put (res_ctx); \
result = -EAI_SYSTEM; \
goto free_and_return; \
} \
@@ -279,7 +282,8 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
{ \
if (!convert_hostent_to_gaih_addrtuple (req, _family,h, &addrmem)) \
{ \
- _res.options |= old_res_options & DEPRECATED_RES_USE_INET6; \
+ __resolv_context_enable_inet6 (res_ctx, res_enable_inet6); \
+ __resolv_context_put (res_ctx); \
result = -EAI_SYSTEM; \
goto free_and_return; \
} \
@@ -582,7 +586,8 @@ gaih_inet (const char *name, const struct gaih_service *service,
enum nss_status inet6_status = NSS_STATUS_UNAVAIL;
enum nss_status status = NSS_STATUS_UNAVAIL;
int no_more;
- int old_res_options;
+ struct resolv_context *res_ctx = NULL;
+ bool res_enable_inet6 = false;
/* If we do not have to look for IPv6 addresses or the canonical
name, use the simple, old functions, which do not support
@@ -765,16 +770,14 @@ gaih_inet (const char *name, const struct gaih_service *service,
no_more = 0;
nip = __nss_hosts_database;
- /* Initialize configurations. */
- if (__res_maybe_init (&_res, 0) == -1)
- no_more = 1;
-
/* If we are looking for both IPv4 and IPv6 address we don't
want the lookup functions to automatically promote IPv4
- addresses to IPv6 addresses. Currently this is decided
- by setting the RES_USE_INET6 bit in _res.options. */
- old_res_options = _res.options;
- _res.options &= ~DEPRECATED_RES_USE_INET6;
+ addresses to IPv6 addresses, so we use the no_inet6
+ function variant. */
+ res_ctx = __resolv_context_get ();
+ res_enable_inet6 = __resolv_context_disable_inet6 (res_ctx);
+ if (res_ctx == NULL)
+ no_more = 1;
while (!no_more)
{
@@ -811,8 +814,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
if (!scratch_buffer_grow (tmpbuf))
{
- _res.options
- |= old_res_options & DEPRECATED_RES_USE_INET6;
+ __resolv_context_enable_inet6
+ (res_ctx, res_enable_inet6);
+ __resolv_context_put (res_ctx);
result = -EAI_MEMORY;
goto free_and_return;
}
@@ -911,9 +915,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
canonbuf = getcanonname (nip, at, name);
if (canonbuf == NULL)
{
- _res.options
- |= old_res_options
- & DEPRECATED_RES_USE_INET6;
+ __resolv_context_enable_inet6
+ (res_ctx, res_enable_inet6);
+ __resolv_context_put (res_ctx);
result = -EAI_MEMORY;
goto free_and_return;
}
@@ -953,7 +957,8 @@ gaih_inet (const char *name, const struct gaih_service *service,
nip = nip->next;
}
- _res.options |= old_res_options & DEPRECATED_RES_USE_INET6;
+ __resolv_context_enable_inet6 (res_ctx, res_enable_inet6);
+ __resolv_context_put (res_ctx);
if (h_errno == NETDB_INTERNAL)
{