aboutsummaryrefslogtreecommitdiff
path: root/resolv/resolv_context.h
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-06-30 20:19:10 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-07-03 21:03:21 +0200
commita1c4eb8794e789b5055d7ceb13b2b3231abf5e26 (patch)
tree33fddb61bf0cb074a486dbe6155d0e36dd08ecaf /resolv/resolv_context.h
parent3f853f22c87f0b671c0366eb290919719fa56c0e (diff)
downloadglibc-a1c4eb8794e789b5055d7ceb13b2b3231abf5e26.tar
glibc-a1c4eb8794e789b5055d7ceb13b2b3231abf5e26.tar.gz
glibc-a1c4eb8794e789b5055d7ceb13b2b3231abf5e26.tar.bz2
glibc-a1c4eb8794e789b5055d7ceb13b2b3231abf5e26.zip
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.)
Diffstat (limited to 'resolv/resolv_context.h')
-rw-r--r--resolv/resolv_context.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/resolv/resolv_context.h b/resolv/resolv_context.h
index 0f4d47d26d..e2f7ad6645 100644
--- a/resolv/resolv_context.h
+++ b/resolv/resolv_context.h
@@ -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