summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2013-06-01 09:21:11 +0000
committerEric Faurot <eric@cvs.openbsd.org>2013-06-01 09:21:11 +0000
commit92cc823d561a30c1dfbbdf587145cb205f1c65f4 (patch)
tree3b0bb5659cf382458d3629a903aeaeb1c0d5b60c
parent347b54d81b72d3ce4f61e77eaf8cd064b735cac0 (diff)
iterating over the ns list only matters for res_send_async.c, so move
things around.
-rw-r--r--lib/libc/asr/asr.c33
-rw-r--r--lib/libc/asr/asr_private.h8
-rw-r--r--lib/libc/asr/res_send_async.c35
3 files changed, 37 insertions, 39 deletions
diff --git a/lib/libc/asr/asr.c b/lib/libc/asr/asr.c
index a2025ec4af0..32bb413899c 100644
--- a/lib/libc/asr/asr.c
+++ b/lib/libc/asr/asr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asr.c,v 1.26 2013/05/27 17:31:01 eric Exp $ */
+/* $OpenBSD: asr.c,v 1.27 2013/06/01 09:21:09 eric Exp $ */
/*
* Copyright (c) 2010-2012 Eric Faurot <eric@openbsd.org>
*
@@ -914,42 +914,11 @@ asr_iter_db(struct async *as)
}
as->as_db_idx += 1;
- as->as_ns_idx = 0;
DPRINT("asr_iter_db: %i\n", as->as_db_idx);
return (0);
}
-/*
- * Set the async context nameserver index to the next nameserver of the
- * currently used DB (assuming it is DNS), cycling over the list until the
- * maximum retry counter is reached. Return 0 on success, or -1 if all
- * nameservers were used.
- */
-int
-asr_iter_ns(struct async *as)
-{
- for (;;) {
- if (as->as_ns_cycles >= as->as_ctx->ac_nsretries)
- return (-1);
-
- as->as_ns_idx += 1;
- if (as->as_ns_idx <= as->as_ctx->ac_nscount)
- break;
- as->as_ns_idx = 0;
- as->as_ns_cycles++;
- DPRINT("asr: asr_iter_ns(): cycle %i\n", as->as_ns_cycles);
- }
-
- as->as_timeout = 1000 * (as->as_ctx->ac_nstimeout << as->as_ns_cycles);
- if (as->as_ns_cycles > 0)
- as->as_timeout /= as->as_ctx->ac_nscount;
- if (as->as_timeout < 1000)
- as->as_timeout = 1000;
-
- return (0);
-}
-
enum {
DOM_INIT,
DOM_DOMAIN,
diff --git a/lib/libc/asr/asr_private.h b/lib/libc/asr/asr_private.h
index 3564e302c6a..57849ff51bc 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.18 2013/05/27 17:31:01 eric Exp $ */
+/* $OpenBSD: asr_private.h,v 1.19 2013/06/01 09:21:10 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -181,8 +181,6 @@ struct async {
int as_dom_flags;
int as_family_idx;
int as_db_idx;
- int as_ns_idx;
- int as_ns_cycles;
int as_count;
@@ -196,6 +194,9 @@ struct async {
int rcode; /* response code */
int ancount; /* answer count */
+ int nsidx;
+ int nsloop;
+
/* io buffers for query/response */
unsigned char *obuf;
size_t obuflen;
@@ -319,7 +320,6 @@ size_t asr_make_fqdn(const char *, const char *, char *, size_t);
size_t asr_domcat(const char *, const char *, char *, size_t);
char *asr_strdname(const char *, char *, size_t);
int asr_iter_db(struct async *);
-int asr_iter_ns(struct async *);
int asr_iter_domain(struct async *, const char *, char *, size_t);
int asr_parse_namedb_line(FILE *, char **, int);
diff --git a/lib/libc/asr/res_send_async.c b/lib/libc/asr/res_send_async.c
index 2a661a12e95..4a3e1665df7 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.17 2013/04/30 12:02:39 eric Exp $ */
+/* $OpenBSD: res_send_async.c,v 1.18 2013/06/01 09:21:10 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -43,9 +43,9 @@ 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);
+int asr_iter_ns(struct async *);
-
-#define AS_NS_SA(p) ((p)->as_ctx->ac_ns[(p)->as_ns_idx - 1])
+#define AS_NS_SA(p) ((p)->as_ctx->ac_ns[(p)->as.dns.nsidx - 1])
struct async *
@@ -734,3 +734,32 @@ validate_packet(struct async *as)
errno = EINVAL;
return (-1);
}
+
+/*
+ * Set the async context nameserver index to the next nameserver, cycling
+ * over the list until the maximum retry counter is reached. Return 0 on
+ * success, or -1 if all nameservers were used.
+ */
+int
+asr_iter_ns(struct async *as)
+{
+ for (;;) {
+ if (as->as.dns.nsloop >= as->as_ctx->ac_nsretries)
+ return (-1);
+
+ as->as.dns.nsidx += 1;
+ if (as->as.dns.nsidx <= as->as_ctx->ac_nscount)
+ break;
+ as->as.dns.nsidx = 0;
+ as->as.dns.nsloop++;
+ DPRINT("asr: asr_iter_ns(): cycle %i\n", as->as.dns.nsloop);
+ }
+
+ as->as_timeout = 1000 * (as->as_ctx->ac_nstimeout << as->as.dns.nsloop);
+ if (as->as.dns.nsloop > 0)
+ as->as_timeout /= as->as_ctx->ac_nscount;
+ if (as->as_timeout < 1000)
+ as->as_timeout = 1000;
+
+ return (0);
+}