summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2019-10-24 05:57:43 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2019-10-24 05:57:43 +0000
commite233ed4fcccbe139da7f649db83d158945ed334a (patch)
treedb1e90449309c67dab7f160e8c777cfd3e4c6cf8
parent360a1bda1f3162b4447b047b41bdfa07ff8a930f (diff)
Allow the caller of asr functions to create and use a specific context.
Diff from eric@ and florian@, commiting on their behalf since they are absent and we want to ride the minor shlib bump.
-rw-r--r--include/asr.h4
-rw-r--r--lib/libc/Symbols.list2
-rw-r--r--lib/libc/asr/asr.c43
-rw-r--r--lib/libc/asr/asr_run.327
-rw-r--r--lib/libc/hidden/asr.h4
5 files changed, 69 insertions, 11 deletions
diff --git a/include/asr.h b/include/asr.h
index 0ceb0f5a604..0e38d550706 100644
--- a/include/asr.h
+++ b/include/asr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr.h,v 1.1 2014/03/26 18:13:15 eric Exp $ */
+/* $OpenBSD: asr.h,v 1.2 2019/10/24 05:57:41 otto Exp $ */
/*
* Copyright (c) 2012-2014 Eric Faurot <eric@openbsd.org>
*
@@ -58,6 +58,8 @@ struct asr_result {
/* Forward declaration. The API uses opaque pointers as query handles. */
struct asr_query;
+void *asr_resolver_from_string(const char *);
+void asr_resolver_free(void *);
int asr_run(struct asr_query *, struct asr_result *);
int asr_run_sync(struct asr_query *, struct asr_result *);
void asr_abort(struct asr_query *);
diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list
index 7d632a96e3c..f9aa62ab6e8 100644
--- a/lib/libc/Symbols.list
+++ b/lib/libc/Symbols.list
@@ -1038,6 +1038,8 @@ wcwidth
/* asr */
asr_abort
+asr_resolver_from_string
+asr_resolver_free
asr_run
asr_run_sync
freerrset
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c
index 4891470b138..cd056c85719 100644
--- a/lib/libc/asr/asr.c
+++ b/lib/libc/asr/asr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr.c,v 1.61 2018/10/22 17:31:24 krw Exp $ */
+/* $OpenBSD: asr.c,v 1.62 2019/10/24 05:57:41 otto Exp $ */
/*
* Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org>
*
@@ -109,10 +109,14 @@ _asr_resolver(void)
void
_asr_resolver_done(void *arg)
{
- struct asr *asr = arg;
+ struct asr_ctx *ac = arg;
+ struct asr *asr;
struct asr **priv;
- if (asr == NULL) {
+ if (ac) {
+ _asr_ctx_unref(ac);
+ return;
+ } else {
priv = _THREAD_PRIVATE(_asr, _asr, &_asr);
if (*priv == NULL)
return;
@@ -124,6 +128,30 @@ _asr_resolver_done(void *arg)
free(asr);
}
+void *
+asr_resolver_from_string(const char *str)
+{
+ struct asr_ctx *ac;
+
+ if ((ac = asr_ctx_create()) == NULL)
+ return NULL;
+
+ if (asr_ctx_from_string(ac, str) == -1) {
+ asr_ctx_free(ac);
+ return NULL;
+ }
+
+ return ac;
+}
+DEF_WEAK(asr_resolver_from_string);
+
+void
+asr_resolver_free(void *arg)
+{
+ _asr_ctx_unref(arg);
+}
+DEF_WEAK(asr_resolver_free);
+
/*
* Cancel an async query.
*/
@@ -309,10 +337,15 @@ _asr_async_free(struct asr_query *as)
struct asr_ctx *
_asr_use_resolver(void *arg)
{
- struct asr *asr = arg;
+ struct asr_ctx *ac = arg;
+ struct asr *asr;
struct asr **priv;
- if (asr == NULL) {
+ if (ac) {
+ asr_ctx_ref(ac);
+ return ac;
+ }
+ else {
DPRINT("using thread-local resolver\n");
priv = _THREAD_PRIVATE(_asr, _asr, &_asr);
if (*priv == NULL) {
diff --git a/lib/libc/asr/asr_run.3 b/lib/libc/asr/asr_run.3
index 61c1b02c1ab..f9dba304cc1 100644
--- a/lib/libc/asr/asr_run.3
+++ b/lib/libc/asr/asr_run.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: asr_run.3,v 1.3 2017/02/18 19:23:05 jca Exp $
+.\" $OpenBSD: asr_run.3,v 1.4 2019/10/24 05:57:41 otto Exp $
.\"
.\" Copyright (c) 2012-2014, Eric Faurot <eric@openbsd.org>
.\"
@@ -14,13 +14,15 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: February 18 2017 $
+.Dd $Mdocdate: October 24 2019 $
.Dt ASR_RUN 3
.Os
.Sh NAME
.Nm asr_run ,
.Nm asr_run_sync ,
.Nm asr_abort ,
+.Nm asr_resolver_from_string ,
+.Nm asr_resolver_free ,
.Nm res_send_async ,
.Nm res_query_async ,
.Nm res_search_async ,
@@ -44,6 +46,10 @@
.Fn asr_run_sync "struct asr_query *aq" "struct asr_result *ar"
.Ft void
.Fn asr_abort "struct asr_query *aq"
+.Ft void *
+.Fn asr_resolver_from_string "const char *str"
+.Ft void
+.Fn asr_resolver_free "void *asr"
.Ft struct asr_query *
.Fn res_send_async "const unsigned char *pkt" "int pktlen" "void *asr"
.Ft struct asr_query *
@@ -187,6 +193,15 @@ returns, so
.Fn asr_abort
must not be called in this case.
.Pp
+The
+.Fn asr_resolver_from_string
+function constructs an asr context from a string that conforms to the
+.Xr resolv.conf 5
+file format.
+.Fn asr_resolver_free
+frees an asr context obtained from
+.Fn asr_resolver_from_string .
+.Pp
The remaining functions are used to initiate different kinds of query
on the
.Fa asr
@@ -200,8 +215,12 @@ They usually have the same interface as an existing resolver function, with
an additional
.Ar asr
argument, which specifies the context to use for this request.
-For now, the argument must always be NULL, which will use the default
-context for the current thread.
+An
+.Ar asr
+argument of NULL will use the default context for the current thread.
+This is constructed from
+.Pa /etc/resolv.conf
+and takes care of reloading the file when it changes.
.Pp
The
.Fn res_send_async ,
diff --git a/lib/libc/hidden/asr.h b/lib/libc/hidden/asr.h
index ccb35fddc4d..f94e2b6d823 100644
--- a/lib/libc/hidden/asr.h
+++ b/lib/libc/hidden/asr.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr.h,v 1.3 2015/10/23 00:52:49 deraadt Exp $ */
+/* $OpenBSD: asr.h,v 1.4 2019/10/24 05:57:42 otto Exp $ */
/*
* Copyright (c) 2015 Philip Guenther <guenther@openbsd.org>
*
@@ -21,6 +21,8 @@
#include_next <asr.h>
PROTO_DEPRECATED(asr_abort);
+PROTO_NORMAL(asr_resolver_from_string);
+PROTO_NORMAL(asr_resolver_free);
PROTO_NORMAL(asr_run);
PROTO_NORMAL(asr_run_sync);
PROTO_NORMAL(getaddrinfo_async);