diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2014-03-25 19:48:12 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2014-03-25 19:48:12 +0000 |
commit | 1a090236bf712741c66bb951190b19b8606e20de (patch) | |
tree | 6355a65f2168b0e5be6fe216d4dc4cfed415633c /lib/libc | |
parent | 2d06d16ca6569b9936404a79bf3821691d0fb951 (diff) |
Cleanup and simplify the API to be exposed. Use better names for
structures, functions and defines.
discussed with and ok deraadt@ guenther@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/asr/asr.c | 38 | ||||
-rw-r--r-- | lib/libc/asr/asr.h | 104 | ||||
-rw-r--r-- | lib/libc/asr/asr_debug.c | 3 | ||||
-rw-r--r-- | lib/libc/asr/asr_private.h | 36 | ||||
-rw-r--r-- | lib/libc/asr/getaddrinfo.c | 8 | ||||
-rw-r--r-- | lib/libc/asr/getaddrinfo_async.c | 43 | ||||
-rw-r--r-- | lib/libc/asr/gethostnamadr.c | 18 | ||||
-rw-r--r-- | lib/libc/asr/gethostnamadr_async.c | 32 | ||||
-rw-r--r-- | lib/libc/asr/getnameinfo.c | 10 | ||||
-rw-r--r-- | lib/libc/asr/getnameinfo_async.c | 24 | ||||
-rw-r--r-- | lib/libc/asr/getnetnamadr.c | 14 | ||||
-rw-r--r-- | lib/libc/asr/getnetnamadr_async.c | 24 | ||||
-rw-r--r-- | lib/libc/asr/getrrsetbyname.c | 10 | ||||
-rw-r--r-- | lib/libc/asr/getrrsetbyname_async.c | 22 | ||||
-rw-r--r-- | lib/libc/asr/res_query.c | 14 | ||||
-rw-r--r-- | lib/libc/asr/res_search_async.c | 26 | ||||
-rw-r--r-- | lib/libc/asr/res_send.c | 10 | ||||
-rw-r--r-- | lib/libc/asr/res_send_async.c | 69 |
18 files changed, 251 insertions, 254 deletions
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c index f87fc513647..8edbf10a6d2 100644 --- a/lib/libc/asr/asr.c +++ b/lib/libc/asr/asr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr.c,v 1.31 2013/07/12 14:36:21 eric Exp $ */ +/* $OpenBSD: asr.c,v 1.32 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org> * @@ -86,7 +86,7 @@ static void *__THREAD_NAME(_asr); static struct asr *_asr = NULL; /* Allocate and configure an async "resolver". */ -struct asr * +void * asr_resolver(const char *conf) { static int init = 0; @@ -156,8 +156,9 @@ asr_resolver(const char *conf) * Drop the reference to the current context. */ void -asr_resolver_done(struct asr *asr) +asr_resolver_done(void *arg) { + struct asr *asr = arg; struct asr **priv; if (asr == NULL) { @@ -177,26 +178,26 @@ asr_resolver_done(struct asr *asr) * Cancel an async query. */ void -asr_async_abort(struct async *as) +asr_abort(struct asr_query *as) { asr_async_free(as); } /* * Resume the "as" async query resolution. Return one of ASYNC_COND, - * ASYNC_YIELD or ASYNC_DONE and put query-specific return values in - * the user-allocated memory at "ar". + * or ASYNC_DONE and put query-specific return values in the user-allocated + * memory at "ar". */ int -asr_async_run(struct async *as, struct async_res *ar) +asr_run(struct asr_query *as, struct asr_result *ar) { int r, saved_errno = errno; - DPRINT("asr: async_run(%p, %p) %s ctx=[%p]\n", as, ar, + DPRINT("asr: asr_run(%p, %p) %s ctx=[%p]\n", as, ar, asr_querystr(as->as_type), as->as_ctx); r = as->as_run(as, ar); - DPRINT("asr: async_run(%p, %p) -> %s", as, ar, asr_transitionstr(r)); + DPRINT("asr: asr_run(%p, %p) -> %s", as, ar, asr_transitionstr(r)); #ifdef DEBUG if (r == ASYNC_COND) #endif @@ -214,20 +215,20 @@ asr_async_run(struct async *as, struct async_res *ar) * Same as above, but run in a loop that handles the fd conditions result. */ int -asr_async_run_sync(struct async *as, struct async_res *ar) +asr_run_sync(struct asr_query *as, struct asr_result *ar) { struct pollfd fds[1]; int r, saved_errno = errno; - while ((r = asr_async_run(as, ar)) == ASYNC_COND) { + while ((r = asr_run(as, ar)) == ASYNC_COND) { fds[0].fd = ar->ar_fd; - fds[0].events = (ar->ar_cond == ASYNC_READ) ? POLLIN : POLLOUT; + fds[0].events = (ar->ar_cond == ASR_WANT_READ) ? POLLIN:POLLOUT; again: r = poll(fds, 1, ar->ar_timeout); if (r == -1 && errno == EINTR) goto again; /* - * Otherwise, just ignore the error and let asr_async_run() + * Otherwise, just ignore the error and let asr_run() * catch the failure. */ } @@ -242,10 +243,10 @@ asr_async_run_sync(struct async *as, struct async_res *ar) * Take a reference on it so it does not gets deleted while the async query * is running. */ -struct async * +struct asr_query * asr_async_new(struct asr_ctx *ac, int type) { - struct async *as; + struct asr_query *as; DPRINT("asr: asr_async_new(ctx=%p) type=%i refcount=%i\n", ac, type, ac ? ac->ac_refcount : 0); @@ -265,7 +266,7 @@ asr_async_new(struct asr_ctx *ac, int type) * Free an async query and unref the associated context. */ void -asr_async_free(struct async *as) +asr_async_free(struct asr_query *as) { DPRINT("asr: asr_async_free(%p)\n", as); switch (as->as_type) { @@ -339,8 +340,9 @@ asr_async_free(struct async *as) * using this context. */ struct asr_ctx * -asr_use_resolver(struct asr *asr) +asr_use_resolver(void *arg) { + struct asr *asr = arg; struct asr **priv; if (asr == NULL) { @@ -886,7 +888,7 @@ asr_parse_namedb_line(FILE *file, char **tokens, int ntoken) * Return 0 on success, or -1 if no more DBs is available. */ int -asr_iter_db(struct async *as) +asr_iter_db(struct asr_query *as) { if (as->as_db_idx >= as->as_ctx->ac_dbcount) { DPRINT("asr_iter_db: done\n"); diff --git a/lib/libc/asr/asr.h b/lib/libc/asr/asr.h index a8b3caf904f..9a1d792220a 100644 --- a/lib/libc/asr/asr.h +++ b/lib/libc/asr/asr.h @@ -1,6 +1,6 @@ -/* $OpenBSD: asr.h,v 1.7 2013/07/12 14:36:21 eric Exp $ */ +/* $OpenBSD: asr.h,v 1.8 2014/03/25 19:48:11 eric Exp $ */ /* - * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> + * Copyright (c) 2012-2014 Eric Faurot <eric@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,83 +18,75 @@ #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> -#include <netinet/in.h> /* - * This part is the generic API for the async mechanism. It could be useful - * beyond the resolver. + * Expected fd conditions */ - -/* Return values for async_run() */ -#define ASYNC_COND 0 /* wait for fd condition */ -#define ASYNC_YIELD 1 /* partial result */ -#define ASYNC_DONE 2 /* done */ - -/* Expected fd conditions */ -#define ASYNC_READ 1 -#define ASYNC_WRITE 2 - -/* This opaque structure holds an async query state. */ -struct async; +#define ASR_WANT_READ 1 +#define ASR_WANT_WRITE 2 /* - * This is the structure through which async_run() returns async - * results to the caller. + * Structure through which asynchronous query results are returned when + * calling asr_run(). */ -struct async_res { - int ar_cond; - int ar_fd; - int ar_timeout; +struct asr_result { + /* Fields set if the query is not done yet (asr_run returns 0) */ + int ar_cond; /* ASR_WANT_READ or ASR_WANT_WRITE */ + int ar_fd; /* the fd waiting for io condition */ + int ar_timeout; /* time to wait for in milliseconds */ + /* Error fields. Depends on the query type. */ int ar_errno; int ar_h_errno; int ar_gai_errno; int ar_rrset_errno; - int ar_count; - - int ar_rcode; - void *ar_data; - int ar_datalen; - union { - struct sockaddr sa; - struct sockaddr_in sain; - struct sockaddr_in6 sain6; - } ar_sa; + /* Result for res_*_async() calls */ + int ar_count; /* number of answers in the dns reply */ + int ar_rcode; /* response code in the dns reply */ + void *ar_data; /* raw reply packet (must be freed) */ + int ar_datalen; /* reply packet length */ + struct sockaddr_storage ar_ns; /* nameserver that responded */ + /* Result for other calls. Must be freed properly. */ struct addrinfo *ar_addrinfo; struct rrsetinfo *ar_rrsetinfo; struct hostent *ar_hostent; struct netent *ar_netent; }; -int asr_async_run(struct async *, struct async_res *); -int asr_async_run_sync(struct async *, struct async_res *); -void asr_async_abort(struct async *); - -/* This opaque structure holds an async resolver context. */ -struct asr; +/* + * Asynchronous query management. + */ -struct asr *asr_resolver(const char *); -void asr_resolver_done(struct asr *); +/* Forward declaration. The API uses opaque pointers as query handles. */ +struct asr_query; -/* Async version of the resolver API */ +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 *); -struct async *res_send_async(const unsigned char *, int, struct asr *); -struct async *res_query_async(const char *, int, int, struct asr *); -struct async *res_search_async(const char *, int, int, struct asr *); +/* + * Asynchronous version of the resolver functions. Similar prototypes, with + * an extra context parameter at the end which must currently be set to NULL. + * All functions return a handle suitable for use with the management functions + * above. + */ +struct asr_query *res_send_async(const unsigned char *, int, void *); +struct asr_query *res_query_async(const char *, int, int, void *); +struct asr_query *res_search_async(const char *, int, int, void *); -struct async *getrrsetbyname_async(const char *, unsigned int, unsigned int, - unsigned int, struct asr *); +struct asr_query *getrrsetbyname_async(const char *, unsigned int, unsigned int, + unsigned int, void *); -struct async *gethostbyname_async(const char *, struct asr *); -struct async *gethostbyname2_async(const char *, int, struct asr *); -struct async *gethostbyaddr_async(const void *, socklen_t, int, struct asr *); +struct asr_query *gethostbyname_async(const char *, void *); +struct asr_query *gethostbyname2_async(const char *, int, void *); +struct asr_query *gethostbyaddr_async(const void *, socklen_t, int, void *); -struct async *getnetbyname_async(const char *, struct asr *); -struct async *getnetbyaddr_async(in_addr_t, int, struct asr *); +struct asr_query *getnetbyname_async(const char *, void *); +struct asr_query *getnetbyaddr_async(in_addr_t, int, void *); -struct async *getaddrinfo_async(const char *, const char *, - const struct addrinfo *, struct asr *); -struct async *getnameinfo_async(const struct sockaddr *, socklen_t, char *, - size_t, char *, size_t, int, struct asr *); +struct asr_query *getaddrinfo_async(const char *, const char *, + const struct addrinfo *, void *); +struct asr_query *getnameinfo_async(const struct sockaddr *, socklen_t, char *, + size_t, char *, size_t, int, void *); diff --git a/lib/libc/asr/asr_debug.c b/lib/libc/asr/asr_debug.c index fff192edcea..cfab567704e 100644 --- a/lib/libc/asr/asr_debug.c +++ b/lib/libc/asr/asr_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_debug.c,v 1.15 2014/03/14 11:07:33 eric Exp $ */ +/* $OpenBSD: asr_debug.c,v 1.16 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -354,7 +354,6 @@ asr_transitionstr(int type) { switch (type) { CASE(ASYNC_COND); - CASE(ASYNC_YIELD); CASE(ASYNC_DONE); default: return "?"; diff --git a/lib/libc/asr/asr_private.h b/lib/libc/asr/asr_private.h index c8cd3456f0c..d03e686310a 100644 --- a/lib/libc/asr/asr_private.h +++ b/lib/libc/asr/asr_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asr_private.h,v 1.24 2014/03/14 11:07:33 eric Exp $ */ +/* $OpenBSD: asr_private.h,v 1.25 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -152,6 +152,8 @@ struct asr { struct asr_ctx *a_ctx; }; +#define ASYNC_COND 0 +#define ASYNC_DONE 1 #define ASYNC_DOM_FQDN 0x00000001 #define ASYNC_DOM_NDOTS 0x00000002 @@ -164,8 +166,8 @@ struct asr { #define ASYNC_EXTOBUF 0x00002000 -struct async { - int (*as_run)(struct async *, struct async_res *); +struct asr_query { + int (*as_run)(struct asr_query *, struct asr_result *); struct asr_ctx *as_ctx; int as_type; int as_state; @@ -212,7 +214,7 @@ struct async { int class; int type; char *name; - struct async *subq; + struct asr_query *subq; int saved_h_errno; } search; @@ -221,13 +223,13 @@ struct async { int class; int type; char *name; - struct async *subq; + struct asr_query *subq; } rrset; struct { char *name; int family; - struct async *subq; + struct asr_query *subq; char addr[16]; int addrlen; int subq_h_errno; @@ -236,7 +238,7 @@ struct async { struct { char *name; int family; - struct async *subq; + struct asr_query *subq; in_addr_t addr; } netnamadr; @@ -255,7 +257,7 @@ struct async { char *fqdn; struct addrinfo *aifirst; struct addrinfo *ailast; - struct async *subq; + struct asr_query *subq; int flags; } ai; @@ -270,7 +272,7 @@ struct async { struct sockaddr_in6 sain6; } sa; int flags; - struct async *subq; + struct asr_query *subq; } ni; #define MAXTOKEN 10 } as; @@ -311,20 +313,22 @@ ssize_t asr_dname_from_fqdn(const char *, char *, size_t); ssize_t asr_addr_as_fqdn(const char *, int, char *, size_t); /* asr.c */ -struct asr_ctx *asr_use_resolver(struct asr *); +void *asr_resolver(const char *); +void asr_resolver_done(void *); +struct asr_ctx *asr_use_resolver(void *); void asr_ctx_unref(struct asr_ctx *); -struct async *asr_async_new(struct asr_ctx *, int); -void asr_async_free(struct async *); +struct asr_query *asr_async_new(struct asr_ctx *, int); +void asr_async_free(struct asr_query *); size_t asr_make_fqdn(const char *, const char *, char *, size_t); char *asr_strdname(const char *, char *, size_t); -int asr_iter_db(struct async *); +int asr_iter_db(struct asr_query *); int asr_parse_namedb_line(FILE *, char **, int); char *asr_hostalias(struct asr_ctx *, const char *, char *, size_t); /* *_async.c */ -struct async *res_query_async_ctx(const char *, int, int, struct asr_ctx *); -struct async *res_search_async_ctx(const char *, int, int, struct asr_ctx *); -struct async *gethostbyaddr_async_ctx(const void *, socklen_t, int, +struct asr_query *res_query_async_ctx(const char *, int, int, struct asr_ctx *); +struct asr_query *res_search_async_ctx(const char *, int, int, struct asr_ctx *); +struct asr_query *gethostbyaddr_async_ctx(const void *, socklen_t, int, struct asr_ctx *); #ifdef DEBUG diff --git a/lib/libc/asr/getaddrinfo.c b/lib/libc/asr/getaddrinfo.c index 0c6e2f45c75..074a824c1be 100644 --- a/lib/libc/asr/getaddrinfo.c +++ b/lib/libc/asr/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.3 2013/07/12 14:36:21 eric Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.4 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -27,8 +27,8 @@ int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res) { - struct async *as; - struct async_res ar; + struct asr_query *as; + struct asr_result ar; int saved_errno = errno; res_init(); @@ -42,7 +42,7 @@ getaddrinfo(const char *hostname, const char *servname, return (EAI_SYSTEM); } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); *res = ar.ar_addrinfo; if (ar.ar_gai_errno == EAI_SYSTEM) diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c index b730d8c87d5..bf7328803a5 100644 --- a/lib/libc/asr/getaddrinfo_async.c +++ b/lib/libc/asr/getaddrinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.24 2014/03/14 11:07:33 eric Exp $ */ +/* $OpenBSD: getaddrinfo_async.c,v 1.25 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -43,15 +43,15 @@ struct match { int protocol; }; -static int getaddrinfo_async_run(struct async *, struct async_res *); +static int getaddrinfo_async_run(struct asr_query *, struct asr_result *); static int get_port(const char *, const char *, int); -static int iter_family(struct async *, int); -static int iter_domain(struct async *, const char *, char *, size_t); -static int addrinfo_add(struct async *, const struct sockaddr *, const char *); -static int addrinfo_from_file(struct async *, int, FILE *); -static int addrinfo_from_pkt(struct async *, char *, size_t); +static int iter_family(struct asr_query *, int); +static int iter_domain(struct asr_query *, const char *, char *, size_t); +static int addrinfo_add(struct asr_query *, const struct sockaddr *, const char *); +static int addrinfo_from_file(struct asr_query *, int, FILE *); +static int addrinfo_from_pkt(struct asr_query *, char *, size_t); #ifdef YP -static int addrinfo_from_yp(struct async *, int, char *); +static int addrinfo_from_yp(struct asr_query *, int, char *); #endif static const struct match matches[] = { @@ -76,13 +76,13 @@ enum { DOM_DONE }; -struct async * +struct asr_query * getaddrinfo_async(const char *hostname, const char *servname, - const struct addrinfo *hints, struct asr *asr) + const struct addrinfo *hints, void *asr) { - struct asr_ctx *ac; - struct async *as; - char alias[MAXDNAME]; + struct asr_ctx *ac; + struct asr_query *as; + char alias[MAXDNAME]; ac = asr_use_resolver(asr); if ((as = asr_async_new(ac, ASR_GETADDRINFO)) == NULL) @@ -114,7 +114,7 @@ getaddrinfo_async(const char *hostname, const char *servname, } static int -getaddrinfo_async_run(struct async *as, struct async_res *ar) +getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar) { #ifdef YP static char *domain = NULL; @@ -422,8 +422,9 @@ getaddrinfo_async_run(struct async *as, struct async_res *ar) break; case ASR_STATE_SUBQUERY: - if ((r = asr_async_run(as->as.ai.subq, ar)) == ASYNC_COND) + if ((r = asr_run(as->as.ai.subq, ar)) == ASYNC_COND) return (ASYNC_COND); + as->as.ai.subq = NULL; if (ar->ar_datalen == -1) { @@ -512,7 +513,7 @@ get_port(const char *servname, const char *proto, int numonly) * list on the async context, unless a specific family was given in hints. */ static int -iter_family(struct async *as, int first) +iter_family(struct asr_query *as, int first) { if (first) { as->as_family_idx = 0; @@ -561,7 +562,7 @@ domcat(const char *name, const char *domain, char *buf, size_t buflen) * error generating the next name, or the resulting name length. */ static int -iter_domain(struct async *as, const char *name, char * buf, size_t len) +iter_domain(struct asr_query *as, const char *name, char * buf, size_t len) { const char *c; int dots; @@ -644,7 +645,7 @@ iter_domain(struct async *as, const char *name, char * buf, size_t len) * entry per protocol/socktype match. */ static int -addrinfo_add(struct async *as, const struct sockaddr *sa, const char *cname) +addrinfo_add(struct asr_query *as, const struct sockaddr *sa, const char *cname) { struct addrinfo *ai; int i, port, proto; @@ -706,7 +707,7 @@ addrinfo_add(struct async *as, const struct sockaddr *sa, const char *cname) } static int -addrinfo_from_file(struct async *as, int family, FILE *f) +addrinfo_from_file(struct asr_query *as, int family, FILE *f) { char *tokens[MAXTOKEN], *c; int n, i; @@ -743,7 +744,7 @@ addrinfo_from_file(struct async *as, int family, FILE *f) } static int -addrinfo_from_pkt(struct async *as, char *pkt, size_t pktlen) +addrinfo_from_pkt(struct asr_query *as, char *pkt, size_t pktlen) { struct asr_unpack p; struct asr_dns_header h; @@ -815,7 +816,7 @@ strsplit(char *line, char **tokens, int ntokens) } static int -addrinfo_from_yp(struct async *as, int family, char *line) +addrinfo_from_yp(struct asr_query *as, int family, char *line) { char *next, *tokens[MAXTOKEN], *c; int ntok; diff --git a/lib/libc/asr/gethostnamadr.c b/lib/libc/asr/gethostnamadr.c index 31ead29cf31..a7561f132e3 100644 --- a/lib/libc/asr/gethostnamadr.c +++ b/lib/libc/asr/gethostnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostnamadr.c,v 1.9 2013/07/12 14:36:21 eric Exp $ */ +/* $OpenBSD: gethostnamadr.c,v 1.10 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012,2013 Eric Faurot <eric@openbsd.org> * @@ -102,9 +102,9 @@ static int _gethostbyname(const char *name, int af, struct hostent *ret, char *buf, size_t buflen, int *h_errnop) { - struct async *as; - struct async_res ar; - int r; + struct asr_query *as; + struct asr_result ar; + int r; if (af == -1) as = gethostbyname_async(name, NULL); @@ -114,7 +114,7 @@ _gethostbyname(const char *name, int af, struct hostent *ret, char *buf, if (as == NULL) return (errno); - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); errno = ar.ar_errno; *h_errnop = ar.ar_h_errno; @@ -164,9 +164,9 @@ gethostbyname2(const char *name, int af) struct hostent * gethostbyaddr(const void *addr, socklen_t len, int af) { - struct async *as; - struct async_res ar; - int r; + struct asr_query *as; + struct asr_result ar; + int r; res_init(); @@ -176,7 +176,7 @@ gethostbyaddr(const void *addr, socklen_t len, int af) return (NULL); } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); errno = ar.ar_errno; h_errno = ar.ar_h_errno; diff --git a/lib/libc/asr/gethostnamadr_async.c b/lib/libc/asr/gethostnamadr_async.c index dd41ccb73e8..7d27be9eedb 100644 --- a/lib/libc/asr/gethostnamadr_async.c +++ b/lib/libc/asr/gethostnamadr_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gethostnamadr_async.c,v 1.26 2014/03/14 11:07:33 eric Exp $ */ +/* $OpenBSD: gethostnamadr_async.c,v 1.27 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -49,7 +49,7 @@ struct hostent_ext { char *pos; }; -static int gethostnamadr_async_run(struct async *, struct async_res *); +static int gethostnamadr_async_run(struct asr_query *, struct asr_result *); static struct hostent_ext *hostent_alloc(int); static int hostent_set_cname(struct hostent_ext *, const char *, int); static int hostent_add_alias(struct hostent_ext *, const char *, int); @@ -63,17 +63,17 @@ static struct hostent_ext *_yp_gethostnamadr(int, const void *); static struct hostent_ext *hostent_from_yp(int, char *); #endif -struct async * -gethostbyname_async(const char *name, struct asr *asr) +struct asr_query * +gethostbyname_async(const char *name, void *asr) { return gethostbyname2_async(name, AF_INET, asr); } -struct async * -gethostbyname2_async(const char *name, int af, struct asr *asr) +struct asr_query * +gethostbyname2_async(const char *name, int af, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; /* the original segfaults */ if (name == NULL) { @@ -105,11 +105,11 @@ gethostbyname2_async(const char *name, int af, struct asr *asr) return (NULL); } -struct async * -gethostbyaddr_async(const void *addr, socklen_t len, int af, struct asr *asr) +struct asr_query * +gethostbyaddr_async(const void *addr, socklen_t len, int af, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; ac = asr_use_resolver(asr); as = gethostbyaddr_async_ctx(addr, len, af, ac); @@ -118,11 +118,11 @@ gethostbyaddr_async(const void *addr, socklen_t len, int af, struct asr *asr) return (as); } -struct async * +struct asr_query * gethostbyaddr_async_ctx(const void *addr, socklen_t len, int af, struct asr_ctx *ac) { - struct async *as; + struct asr_query *as; if ((as = asr_async_new(ac, ASR_GETHOSTBYADDR)) == NULL) goto abort; /* errno set */ @@ -142,7 +142,7 @@ gethostbyaddr_async_ctx(const void *addr, socklen_t len, int af, } static int -gethostnamadr_async_run(struct async *as, struct async_res *ar) +gethostnamadr_async_run(struct asr_query *as, struct asr_result *ar) { struct hostent_ext *h; int r, type, saved_errno; @@ -306,7 +306,7 @@ gethostnamadr_async_run(struct async *as, struct async_res *ar) /* Run the DNS subquery. */ - if ((r = asr_async_run(as->as.hostnamadr.subq, ar)) == ASYNC_COND) + if ((r = asr_run(as->as.hostnamadr.subq, ar)) == ASYNC_COND) return (ASYNC_COND); /* Done. */ diff --git a/lib/libc/asr/getnameinfo.c b/lib/libc/asr/getnameinfo.c index 5f5c6535da5..4ca82dae098 100644 --- a/lib/libc/asr/getnameinfo.c +++ b/lib/libc/asr/getnameinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo.c,v 1.3 2013/07/12 14:36:21 eric Exp $ */ +/* $OpenBSD: getnameinfo.c,v 1.4 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -27,9 +27,9 @@ int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { - struct async *as; - struct async_res ar; - int saved_errno = errno; + struct asr_query *as; + struct asr_result ar; + int saved_errno = errno; res_init(); @@ -43,7 +43,7 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, return (EAI_SYSTEM); } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); if (ar.ar_gai_errno == EAI_SYSTEM) errno = ar.ar_errno; diff --git a/lib/libc/asr/getnameinfo_async.c b/lib/libc/asr/getnameinfo_async.c index 55f0e68b1b3..6f8965c0b7c 100644 --- a/lib/libc/asr/getnameinfo_async.c +++ b/lib/libc/asr/getnameinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnameinfo_async.c,v 1.7 2013/07/12 14:36:22 eric Exp $ */ +/* $OpenBSD: getnameinfo_async.c,v 1.8 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -31,16 +31,16 @@ #include "asr.h" #include "asr_private.h" -static int getnameinfo_async_run(struct async *, struct async_res *); -static int _servname(struct async *); -static int _numerichost(struct async *); +static int getnameinfo_async_run(struct asr_query *, struct asr_result *); +static int _servname(struct asr_query *); +static int _numerichost(struct asr_query *); -struct async * +struct asr_query * getnameinfo_async(const struct sockaddr *sa, socklen_t slen, char *host, - size_t hostlen, char *serv, size_t servlen, int flags, struct asr *asr) + size_t hostlen, char *serv, size_t servlen, int flags, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; ac = asr_use_resolver(asr); if ((as = asr_async_new(ac, ASR_GETNAMEINFO)) == NULL) @@ -70,7 +70,7 @@ getnameinfo_async(const struct sockaddr *sa, socklen_t slen, char *host, } static int -getnameinfo_async_run(struct async *as, struct async_res *ar) +getnameinfo_async_run(struct asr_query *as, struct asr_result *ar) { void *addr; socklen_t addrlen; @@ -153,7 +153,7 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) case ASR_STATE_SUBQUERY: - if ((r = asr_async_run(as->as.ni.subq, ar)) == ASYNC_COND) + if ((r = asr_run(as->as.ni.subq, ar)) == ASYNC_COND) return (ASYNC_COND); /* @@ -206,7 +206,7 @@ getnameinfo_async_run(struct async *as, struct async_res *ar) * return (-1) if the buffer is too small. */ static int -_servname(struct async *as) +_servname(struct asr_query *as) { struct servent s; struct servent_data sd; @@ -244,7 +244,7 @@ _servname(struct async *as) * Write the numeric address */ static int -_numerichost(struct async *as) +_numerichost(struct asr_query *as) { unsigned int ifidx; char scope[IF_NAMESIZE + 1], *ifname; diff --git a/lib/libc/asr/getnetnamadr.c b/lib/libc/asr/getnetnamadr.c index eeae092c9a1..07ed822d02d 100644 --- a/lib/libc/asr/getnetnamadr.c +++ b/lib/libc/asr/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr.c,v 1.6 2013/07/12 14:36:22 eric Exp $ */ +/* $OpenBSD: getnetnamadr.c,v 1.7 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -80,8 +80,8 @@ _fillnetent(const struct netent *e, struct netent *r, char *buf, size_t len) struct netent * getnetbyname(const char *name) { - struct async *as; - struct async_res ar; + struct asr_query *as; + struct asr_result ar; res_init(); @@ -91,7 +91,7 @@ getnetbyname(const char *name) return (NULL); } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); errno = ar.ar_errno; h_errno = ar.ar_h_errno; @@ -107,8 +107,8 @@ getnetbyname(const char *name) struct netent * getnetbyaddr(in_addr_t net, int type) { - struct async *as; - struct async_res ar; + struct asr_query *as; + struct asr_result ar; res_init(); @@ -118,7 +118,7 @@ getnetbyaddr(in_addr_t net, int type) return (NULL); } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); errno = ar.ar_errno; h_errno = ar.ar_h_errno; diff --git a/lib/libc/asr/getnetnamadr_async.c b/lib/libc/asr/getnetnamadr_async.c index af46c5ba89e..6a948a52cb5 100644 --- a/lib/libc/asr/getnetnamadr_async.c +++ b/lib/libc/asr/getnetnamadr_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr_async.c,v 1.12 2014/03/14 11:07:33 eric Exp $ */ +/* $OpenBSD: getnetnamadr_async.c,v 1.13 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -40,18 +40,18 @@ struct netent_ext { char *pos; }; -static int getnetnamadr_async_run(struct async *, struct async_res *); +static int getnetnamadr_async_run(struct asr_query *, struct asr_result *); static struct netent_ext *netent_alloc(int); static int netent_set_cname(struct netent_ext *, const char *, int); static int netent_add_alias(struct netent_ext *, const char *, int); static struct netent_ext *netent_file_match(FILE *, int, const char *); static struct netent_ext *netent_from_packet(int, char *, size_t); -struct async * -getnetbyname_async(const char *name, struct asr *asr) +struct asr_query * +getnetbyname_async(const char *name, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; /* The current resolver segfaults. */ if (name == NULL) { @@ -79,11 +79,11 @@ getnetbyname_async(const char *name, struct asr *asr) return (NULL); } -struct async * -getnetbyaddr_async(in_addr_t net, int family, struct asr *asr) +struct asr_query * +getnetbyaddr_async(in_addr_t net, int family, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; ac = asr_use_resolver(asr); if ((as = asr_async_new(ac, ASR_GETNETBYADDR)) == NULL) @@ -104,7 +104,7 @@ getnetbyaddr_async(in_addr_t net, int family, struct asr *asr) } static int -getnetnamadr_async_run(struct async *as, struct async_res *ar) +getnetnamadr_async_run(struct asr_query *as, struct asr_result *ar) { struct netent_ext *n; int r, type, saved_errno; @@ -201,7 +201,7 @@ getnetnamadr_async_run(struct async *as, struct async_res *ar) case ASR_STATE_SUBQUERY: - if ((r = asr_async_run(as->as.netnamadr.subq, ar)) == ASYNC_COND) + if ((r = asr_run(as->as.netnamadr.subq, ar)) == ASYNC_COND) return (ASYNC_COND); as->as.netnamadr.subq = NULL; diff --git a/lib/libc/asr/getrrsetbyname.c b/lib/libc/asr/getrrsetbyname.c index 8736ae06a72..359f1dd416b 100644 --- a/lib/libc/asr/getrrsetbyname.c +++ b/lib/libc/asr/getrrsetbyname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getrrsetbyname.c,v 1.3 2013/07/12 14:36:22 eric Exp $ */ +/* $OpenBSD: getrrsetbyname.c,v 1.4 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -28,9 +28,9 @@ int getrrsetbyname(const char *name, unsigned int class, unsigned int type, unsigned int flags, struct rrsetinfo **res) { - struct async *as; - struct async_res ar; - int r, saved_errno = errno; + struct asr_query *as; + struct asr_result ar; + int r, saved_errno = errno; res_init(); @@ -41,7 +41,7 @@ getrrsetbyname(const char *name, unsigned int class, unsigned int type, return (r); } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); *res = ar.ar_rrsetinfo; diff --git a/lib/libc/asr/getrrsetbyname_async.c b/lib/libc/asr/getrrsetbyname_async.c index 338fc8d563a..3f23d7bf3cd 100644 --- a/lib/libc/asr/getrrsetbyname_async.c +++ b/lib/libc/asr/getrrsetbyname_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getrrsetbyname_async.c,v 1.5 2013/07/12 14:36:22 eric Exp $ */ +/* $OpenBSD: getrrsetbyname_async.c,v 1.6 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -31,15 +31,15 @@ #include "asr.h" #include "asr_private.h" -static int getrrsetbyname_async_run(struct async *, struct async_res *); -static void get_response(struct async_res *, const char *, int); +static int getrrsetbyname_async_run(struct asr_query *, struct asr_result *); +static void get_response(struct asr_result *, const char *, int); -struct async * +struct asr_query * getrrsetbyname_async(const char *hostname, unsigned int rdclass, - unsigned int rdtype, unsigned int flags, struct asr *asr) + unsigned int rdtype, unsigned int flags, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; ac = asr_use_resolver(asr); if ((as = asr_async_new(ac, ASR_GETRRSETBYNAME)) == NULL) @@ -64,7 +64,7 @@ getrrsetbyname_async(const char *hostname, unsigned int rdclass, } static int -getrrsetbyname_async_run(struct async *as, struct async_res *ar) +getrrsetbyname_async_run(struct asr_query *as, struct asr_result *ar) { next: switch (as->as_state) { @@ -109,7 +109,7 @@ getrrsetbyname_async_run(struct async *as, struct async_res *ar) case ASR_STATE_SUBQUERY: - if ((asr_async_run(as->as.rrset.subq, ar)) == ASYNC_COND) + if ((asr_run(as->as.rrset.subq, ar)) == ASYNC_COND) return (ASYNC_COND); as->as.rrset.subq = NULL; @@ -169,7 +169,7 @@ getrrsetbyname_async_run(struct async *as, struct async_res *ar) /* The rest of this file is taken from the orignal implementation. */ -/* $OpenBSD: getrrsetbyname_async.c,v 1.5 2013/07/12 14:36:22 eric Exp $ */ +/* $OpenBSD: getrrsetbyname_async.c,v 1.6 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2001 Jakob Schlyter. All rights reserved. @@ -254,7 +254,7 @@ static void free_dns_response(struct dns_response *); static int count_dns_rr(struct dns_rr *, u_int16_t, u_int16_t); static void -get_response(struct async_res *ar, const char *pkt, int pktlen) +get_response(struct asr_result *ar, const char *pkt, int pktlen) { struct rrsetinfo *rrset = NULL; struct dns_response *response = NULL; diff --git a/lib/libc/asr/res_query.c b/lib/libc/asr/res_query.c index 72401af31b5..2c6b198e464 100644 --- a/lib/libc/asr/res_query.c +++ b/lib/libc/asr/res_query.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_query.c,v 1.6 2013/11/12 06:09:50 deraadt Exp $ */ +/* $OpenBSD: res_query.c,v 1.7 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -28,8 +28,8 @@ int res_query(const char *name, int class, int type, u_char *ans, int anslen) { - struct async *as; - struct async_res ar; + struct asr_query *as; + struct asr_result ar; size_t len; res_init(); @@ -49,7 +49,7 @@ res_query(const char *name, int class, int type, u_char *ans, int anslen) return (-1); /* errno set */ } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); if (ar.ar_errno) errno = ar.ar_errno; @@ -70,8 +70,8 @@ res_query(const char *name, int class, int type, u_char *ans, int anslen) int res_search(const char *name, int class, int type, u_char *ans, int anslen) { - struct async *as; - struct async_res ar; + struct asr_query *as; + struct asr_result ar; size_t len; res_init(); @@ -91,7 +91,7 @@ res_search(const char *name, int class, int type, u_char *ans, int anslen) return (-1); /* errno set */ } - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); if (ar.ar_errno) errno = ar.ar_errno; diff --git a/lib/libc/asr/res_search_async.c b/lib/libc/asr/res_search_async.c index c053d0ae9b4..f08557db527 100644 --- a/lib/libc/asr/res_search_async.c +++ b/lib/libc/asr/res_search_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_search_async.c,v 1.11 2014/02/24 20:23:27 eric Exp $ */ +/* $OpenBSD: res_search_async.c,v 1.12 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -28,19 +28,19 @@ #include "asr.h" #include "asr_private.h" -static int res_search_async_run(struct async *, struct async_res *); +static int res_search_async_run(struct asr_query *, struct asr_result *); static size_t domcat(const char *, const char *, char *, size_t); -static int iter_domain(struct async *, const char *, char *, size_t); +static int iter_domain(struct asr_query *, const char *, char *, size_t); /* * Unlike res_query_async(), this function returns a valid packet only if * h_errno is NETDB_SUCCESS. */ -struct async * -res_search_async(const char *name, int class, int type, struct asr *asr) +struct asr_query * +res_search_async(const char *name, int class, int type, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; DPRINT("asr: res_search_async(\"%s\", %i, %i)\n", name, class, type); @@ -51,11 +51,11 @@ res_search_async(const char *name, int class, int type, struct asr *asr) return (as); } -struct async * +struct asr_query * res_search_async_ctx(const char *name, int class, int type, struct asr_ctx *ac) { - struct async *as; - char alias[MAXDNAME]; + struct asr_query *as; + char alias[MAXDNAME]; DPRINT("asr: res_search_async_ctx(\"%s\", %i, %i)\n", name, class, type); @@ -82,7 +82,7 @@ res_search_async_ctx(const char *name, int class, int type, struct asr_ctx *ac) #define HERRNO_UNSET -2 static int -res_search_async_run(struct async *as, struct async_res *ar) +res_search_async_run(struct asr_query *as, struct asr_result *ar) { int r; char fqdn[MAXDNAME]; @@ -134,7 +134,7 @@ res_search_async_run(struct async *as, struct async_res *ar) case ASR_STATE_SUBQUERY: - if ((r = asr_async_run(as->as.search.subq, ar)) == ASYNC_COND) + if ((r = asr_run(as->as.search.subq, ar)) == ASYNC_COND) return (ASYNC_COND); as->as.search.subq = NULL; @@ -239,7 +239,7 @@ enum { * error generating the next name, or the resulting name length. */ int -iter_domain(struct async *as, const char *name, char * buf, size_t len) +iter_domain(struct asr_query *as, const char *name, char * buf, size_t len) { const char *c; int dots; diff --git a/lib/libc/asr/res_send.c b/lib/libc/asr/res_send.c index 7c6152e258c..b00510c4943 100644 --- a/lib/libc/asr/res_send.c +++ b/lib/libc/asr/res_send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_send.c,v 1.6 2013/11/12 06:09:50 deraadt Exp $ */ +/* $OpenBSD: res_send.c,v 1.7 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -28,9 +28,9 @@ int res_send(const u_char *buf, int buflen, u_char *ans, int anslen) { - struct async *as; - struct async_res ar; - size_t len; + struct asr_query *as; + struct asr_result ar; + size_t len; res_init(); @@ -43,7 +43,7 @@ res_send(const u_char *buf, int buflen, u_char *ans, int anslen) if (as == NULL) return (-1); /* errno set */ - asr_async_run_sync(as, &ar); + asr_run_sync(as, &ar); if (ar.ar_errno) { errno = ar.ar_errno; diff --git a/lib/libc/asr/res_send_async.c b/lib/libc/asr/res_send_async.c index ddbae94bc03..a9d4f696b11 100644 --- a/lib/libc/asr/res_send_async.c +++ b/lib/libc/asr/res_send_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_send_async.c,v 1.20 2014/03/14 11:07:33 eric Exp $ */ +/* $OpenBSD: res_send_async.c,v 1.21 2014/03/25 19:48:11 eric Exp $ */ /* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * @@ -34,25 +34,25 @@ #define OP_QUERY (0) -static int res_send_async_run(struct async *, struct async_res *); +static int res_send_async_run(struct asr_query *, struct asr_result *); static int sockaddr_connect(const struct sockaddr *, int); -static int udp_send(struct async *); -static int udp_recv(struct async *); -static int tcp_write(struct async *); -static int tcp_read(struct async *); -static int validate_packet(struct async *); -static int setup_query(struct async *, const char *, const char *, int, int); -static int ensure_ibuf(struct async *, size_t); -static int iter_ns(struct async *); +static int udp_send(struct asr_query *); +static int udp_recv(struct asr_query *); +static int tcp_write(struct asr_query *); +static int tcp_read(struct asr_query *); +static int validate_packet(struct asr_query *); +static int setup_query(struct asr_query *, const char *, const char *, int, int); +static int ensure_ibuf(struct asr_query *, size_t); +static int iter_ns(struct asr_query *); #define AS_NS_SA(p) ((p)->as_ctx->ac_ns[(p)->as.dns.nsidx - 1]) -struct async * -res_send_async(const unsigned char *buf, int buflen, struct asr *asr) +struct asr_query * +res_send_async(const unsigned char *buf, int buflen, void *asr) { struct asr_ctx *ac; - struct async *as; + struct asr_query *as; struct asr_unpack p; struct asr_dns_header h; struct asr_dns_query q; @@ -97,14 +97,13 @@ res_send_async(const unsigned char *buf, int buflen, struct asr *asr) /* * Unlike res_query(), this version will actually return the packet * if it has received a valid one (errno == 0) even if h_errno is - * not NETDB_SUCCESS. So the packet *must* be freed if necessary - * (ans == NULL). + * not NETDB_SUCCESS. So the packet *must* be freed if necessary. */ -struct async * -res_query_async(const char *name, int class, int type, struct asr *asr) +struct asr_query * +res_query_async(const char *name, int class, int type, void *asr) { - struct asr_ctx *ac; - struct async *as; + struct asr_ctx *ac; + struct asr_query *as; DPRINT("asr: res_query_async(\"%s\", %i, %i)\n", name, class, type); @@ -115,10 +114,10 @@ res_query_async(const char *name, int class, int type, struct asr *asr) return (as); } -struct async * +struct asr_query * res_query_async_ctx(const char *name, int class, int type, struct asr_ctx *a_ctx) { - struct async *as; + struct asr_query *as; DPRINT("asr: res_query_async_ctx(\"%s\", %i, %i)\n", name, class, type); @@ -142,7 +141,7 @@ res_query_async_ctx(const char *name, int class, int type, struct asr_ctx *a_ctx } static int -res_send_async_run(struct async *as, struct async_res *ar) +res_send_async_run(struct asr_query *as, struct asr_result *ar) { next: switch (as->as_state) { @@ -180,7 +179,7 @@ res_send_async_run(struct async *as, struct async_res *ar) break; } async_set_state(as, ASR_STATE_UDP_RECV); - ar->ar_cond = ASYNC_READ; + ar->ar_cond = ASR_WANT_READ; ar->ar_fd = as->as_fd; ar->ar_timeout = as->as_timeout; return (ASYNC_COND); @@ -215,12 +214,12 @@ res_send_async_run(struct async *as, struct async_res *ar) break; case 0: async_set_state(as, ASR_STATE_TCP_READ); - ar->ar_cond = ASYNC_READ; + ar->ar_cond = ASR_WANT_READ; ar->ar_fd = as->as_fd; ar->ar_timeout = as->as_timeout; return (ASYNC_COND); case 1: - ar->ar_cond = ASYNC_WRITE; + ar->ar_cond = ASR_WANT_WRITE; ar->ar_fd = as->as_fd; ar->ar_timeout = as->as_timeout; return (ASYNC_COND); @@ -241,7 +240,7 @@ res_send_async_run(struct async *as, struct async_res *ar) async_set_state(as, ASR_STATE_PACKET); break; case 1: - ar->ar_cond = ASYNC_READ; + ar->ar_cond = ASR_WANT_READ; ar->ar_fd = as->as_fd; ar->ar_timeout = as->as_timeout; return (ASYNC_COND); @@ -250,7 +249,7 @@ res_send_async_run(struct async *as, struct async_res *ar) case ASR_STATE_PACKET: - memmove(&ar->ar_sa.sa, AS_NS_SA(as), AS_NS_SA(as)->sa_len); + memmove(&ar->ar_ns, AS_NS_SA(as), AS_NS_SA(as)->sa_len); ar->ar_datalen = as->as.dns.ibuflen; ar->ar_data = as->as.dns.ibuf; as->as.dns.ibuf = NULL; @@ -343,7 +342,7 @@ sockaddr_connect(const struct sockaddr *sa, int socktype) * Return 0 on success, set errno and return -1 on error. */ static int -setup_query(struct async *as, const char *name, const char *dom, +setup_query(struct asr_query *as, const char *name, const char *dom, int class, int type) { struct asr_pack p; @@ -416,7 +415,7 @@ setup_query(struct async *as, const char *name, const char *dom, * Return 0 on success, or -1 on error (errno set). */ static int -udp_send(struct async *as) +udp_send(struct asr_query *as) { ssize_t n; int save_errno; @@ -449,7 +448,7 @@ udp_send(struct async *as) * Return 0 if a full packet could be read, or -1 on error (errno set). */ static int -udp_recv(struct async *as) +udp_recv(struct asr_query *as) { ssize_t n; int save_errno; @@ -487,7 +486,7 @@ udp_recv(struct async *as) * socket or it is not connected yet, or -1 on error (errno set). */ static int -tcp_write(struct async *as) +tcp_write(struct asr_query *as) { struct msghdr msg; struct iovec iov[2]; @@ -562,7 +561,7 @@ close: * socket must be read again, or -1 on error (errno set). */ static int -tcp_read(struct async *as) +tcp_read(struct asr_query *as) { ssize_t n; size_t offset, len; @@ -641,7 +640,7 @@ close: * extend it if necessary. Return 0 on success, or set errno and return -1. */ static int -ensure_ibuf(struct async *as, size_t n) +ensure_ibuf(struct asr_query *as, size_t n) { char *t; @@ -670,7 +669,7 @@ ensure_ibuf(struct async *as, size_t n) * Return 0 on success, or set errno and return -1. */ static int -validate_packet(struct async *as) +validate_packet(struct asr_query *as) { struct asr_unpack p; struct asr_dns_header h; @@ -741,7 +740,7 @@ validate_packet(struct async *as) * success, or -1 if all nameservers were used. */ static int -iter_ns(struct async *as) +iter_ns(struct asr_query *as) { for (;;) { if (as->as.dns.nsloop >= as->as_ctx->ac_nsretries) |