1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

resolv: Mirror the entire resolver configuration in struct resolv_conf

This commit adds the remaining unchanging members (which are loaded
from /etc/resolv.conf) to struct resolv_conf.

The extended name server list is currently not used by the stub
resolver.  The switch depends on a cleanup: The _u._ext.nssocks
array stores just a single socket, and needs to be replaced with
a single socket value.

(The compatibility gethostname implementation does not use the
extended addres sort list, either.  Updating the compat code is
not worthwhile.)
This commit is contained in:
Florian Weimer
2017-06-30 20:19:10 +02:00
parent 3f853f22c8
commit a1c4eb8794
7 changed files with 572 additions and 116 deletions

View File

@@ -112,6 +112,67 @@ __resolv_context_search_list (const struct resolv_context *ctx, size_t index)
return NULL;
}
/* Return the number of name servers. */
static __attribute__ ((nonnull (1), unused)) size_t
__resolv_context_nameserver_count (const struct resolv_context *ctx)
{
if (ctx->conf != NULL)
return ctx->conf->nameserver_list_size;
else
return ctx->resp->nscount;
}
/* Return a pointer to the socket address of the name server INDEX, or
NULL if the index is out of bounds. */
static __attribute__ ((nonnull (1), unused)) const struct sockaddr *
__resolv_context_nameserver (const struct resolv_context *ctx, size_t index)
{
if (ctx->conf != NULL)
{
if (index < ctx->conf->nameserver_list_size)
return ctx->conf->nameserver_list[index];
}
else
if (index < ctx->resp->nscount)
{
if (ctx->resp->nsaddr_list[index].sin_family != 0)
return (const struct sockaddr *) &ctx->resp->nsaddr_list[index];
else
return (const struct sockaddr *) &ctx->resp->_u._ext.nsaddrs[index];
}
return NULL;
}
/* Return the number of sort list entries. */
static __attribute__ ((nonnull (1), unused)) size_t
__resolv_context_sort_count (const struct resolv_context *ctx)
{
if (ctx->conf != NULL)
return ctx->conf->sort_list_size;
else
return ctx->resp->nsort;
}
/* Return the sort list entry at INDEX. */
static __attribute__ ((nonnull (1), unused)) struct resolv_sortlist_entry
__resolv_context_sort_entry (const struct resolv_context *ctx, size_t index)
{
if (ctx->conf != NULL)
{
if (index < ctx->conf->sort_list_size)
return ctx->conf->sort_list[index];
/* Fall through. */
}
else if (index < ctx->resp->nsort)
return (struct resolv_sortlist_entry)
{
.addr = ctx->resp->sort_list[index].addr,
.mask = ctx->resp->sort_list[index].mask,
};
return (struct resolv_sortlist_entry) { .mask = 0, };
}
/* Called during thread shutdown to free the associated resolver
context (mostly in response to cancellation, otherwise the
__resolv_context_get/__resolv_context_put pairing will already have