diff options
author | Florian Weimer <fweimer@redhat.com> | 2017-06-30 21:10:23 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2017-07-03 20:52:59 +0200 |
commit | 352f4ff9a268b81ef5d4b2413f582565806e4790 (patch) | |
tree | fb27056dfdeafe43c021f6127c9544c016e78019 /nscd | |
parent | 4e45d83c92dbb5b8dc20654f32395108d18cf739 (diff) | |
download | glibc-352f4ff9a268b81ef5d4b2413f582565806e4790.tar.gz glibc-352f4ff9a268b81ef5d4b2413f582565806e4790.tar.xz 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 'nscd')
-rw-r--r-- | nscd/aicache.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/nscd/aicache.c b/nscd/aicache.c index f1f9284f6d..a3de792cc4 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -26,6 +26,8 @@ #include <unistd.h> #include <sys/mman.h> #include <resolv/resolv-internal.h> +#include <resolv/resolv_context.h> +#include <resolv/res_use_inet6.h> #include "dbg_log.h" #include "nscd.h" @@ -100,17 +102,15 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, no_more = 0; nip = hosts_database; - /* Initialize configurations. */ - if (__res_maybe_init (&_res, 0) == -1) + /* Initialize configurations. 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. Therefore, use the + _no_inet6 variant. */ + struct resolv_context *ctx = __resolv_context_get (); + bool enable_inet6 = __resolv_context_disable_inet6 (ctx); + if (ctx == NULL) 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. */ - int old_res_options = _res.options; - _res.options &= ~DEPRECATED_RES_USE_INET6; - size_t tmpbuf6len = 1024; char *tmpbuf6 = alloca (tmpbuf6len); size_t tmpbuf4len = 0; @@ -534,7 +534,8 @@ next_nip: } out: - _res.options |= old_res_options & DEPRECATED_RES_USE_INET6; + __resolv_context_enable_inet6 (ctx, enable_inet6); + __resolv_context_put (ctx); if (dataset != NULL && !alloca_used) { |