3 @@ -315,11 +315,11 @@ stralloc.h iopause.h taia.h tai.h uint64
7 -load dnscache.o droproot.o okclient.o log.o cache.o query.o \
8 +load dnscache.o droproot.o okclient.o log.o cache.o query.o qmerge.o \
9 response.o dd.o roots.o iopause.o prot.o dns.a env.a alloc.a buffer.a \
10 libtai.a unix.a byte.a socket.lib
11 ./load dnscache droproot.o okclient.o log.o cache.o \
12 - query.o response.o dd.o roots.o iopause.o prot.o dns.a \
13 + query.o qmerge.o response.o dd.o roots.o iopause.o prot.o dns.a \
14 env.a alloc.a buffer.a libtai.a unix.a byte.a `cat \
17 @@ -340,7 +340,7 @@ compile dnscache.c env.h exit.h scan.h s
18 uint16.h uint64.h socket.h uint16.h dns.h stralloc.h gen_alloc.h \
19 iopause.h taia.h tai.h uint64.h taia.h taia.h byte.h roots.h fmt.h \
20 iopause.h query.h dns.h uint32.h alloc.h response.h uint32.h cache.h \
21 -uint32.h uint64.h ndelay.h log.h uint64.h okclient.h droproot.h
22 +uint32.h uint64.h ndelay.h log.h uint64.h okclient.h droproot.h maxclient.h
26 @@ -685,11 +685,16 @@ qlog.o: \
27 compile qlog.c buffer.h qlog.h uint16.h
31 +compile qmerge.c qmerge.h dns.h stralloc.h gen_alloc.h iopause.h \
32 +taia.h tai.h uint64.h log.h maxclient.h
36 compile query.c error.h roots.h log.h uint64.h case.h cache.h \
37 uint32.h uint64.h byte.h dns.h stralloc.h gen_alloc.h iopause.h \
38 taia.h tai.h uint64.h taia.h uint64.h uint32.h uint16.h dd.h alloc.h \
39 -response.h uint32.h query.h dns.h uint32.h
40 +response.h uint32.h query.h dns.h uint32.h qmerge.h
50 +#include "maxclient.h"
54 @@ -57,7 +58,6 @@ uint64 numqueries = 0;
59 static struct udpclient {
62 @@ -134,7 +134,6 @@ void u_new(void)
72 @@ -151,6 +151,13 @@ void log_tx(const char *q,const char qty
76 +void log_tx_piggyback(const char *q, const char qtype[2], const char *control)
79 + logtype(qtype); space(); name(q); space(); name(control);
83 void log_cachedanswer(const char *q,const char type[2])
85 string("cached "); logtype(type); space();
88 @@ -20,6 +20,7 @@ extern void log_cachednxdomain(const cha
89 extern void log_cachedns(const char *,const char *);
91 extern void log_tx(const char *,const char *,const char *,const char *,unsigned int);
92 +extern void log_tx_piggyback(const char *,const char *,const char *);
94 extern void log_nxdomain(const char *,const char *,unsigned int);
95 extern void log_nodata(const char *,const char *,const char *,unsigned int);
105 +#endif /* MAXCLIENT_H */
112 +#include "maxclient.h"
114 +#define QMERGE_MAX (MAXUDP+MAXTCP)
115 +struct qmerge inprogress[QMERGE_MAX];
118 +int qmerge_key_init(struct qmerge_key *qmk, const char *q, const char qtype[2],
119 + const char *control)
121 + if (!dns_domain_copy(&qmk->q, q)) return 0;
122 + byte_copy(qmk->qtype, 2, qtype);
123 + if (!dns_domain_copy(&qmk->control, control)) return 0;
128 +int qmerge_key_equal(struct qmerge_key *a, struct qmerge_key *b)
131 + byte_equal(a->qtype, 2, b->qtype) &&
132 + dns_domain_equal(a->q, b->q) &&
133 + dns_domain_equal(a->control, b->control);
137 +void qmerge_key_free(struct qmerge_key *qmk)
139 + dns_domain_free(&qmk->q);
140 + dns_domain_free(&qmk->control);
143 +void qmerge_free(struct qmerge **x)
149 + if (!qm || !qm->active) return;
153 + qmerge_key_free(&qm->key);
154 + dns_transmit_free(&qm->dt);
158 +int qmerge_start(struct qmerge **qm, const char servers[64], int flagrecursive,
159 + const char *q, const char qtype[2], const char localip[4],
160 + const char *control)
162 + struct qmerge_key k;
168 + byte_zero(&k, sizeof k);
169 + if (!qmerge_key_init(&k, q, qtype, control)) return -1;
170 + for (i = 0; i < QMERGE_MAX; i++) {
171 + if (!inprogress[i].active) continue;
172 + if (!qmerge_key_equal(&k, &inprogress[i].key)) continue;
173 + log_tx_piggyback(q, qtype, control);
174 + inprogress[i].active++;
175 + *qm = &inprogress[i];
176 + qmerge_key_free(&k);
180 + for (i = 0; i < QMERGE_MAX; i++)
181 + if (!inprogress[i].active)
183 + if (i == QMERGE_MAX) return -1;
185 + log_tx(q, qtype, control, servers, 0);
186 + r = dns_transmit_start(&inprogress[i].dt, servers, flagrecursive, q, qtype, localip);
187 + if (r == -1) { qmerge_key_free(&k); return -1; }
188 + inprogress[i].active++;
189 + inprogress[i].state = 0;
190 + qmerge_key_free(&inprogress[i].key);
191 + byte_copy(&inprogress[i].key, sizeof k, &k);
192 + *qm = &inprogress[i];
196 +void qmerge_io(struct qmerge *qm, iopause_fd *io, struct taia *deadline)
198 + if (qm->state == 0) {
199 + dns_transmit_io(&qm->dt, io, deadline);
208 +int qmerge_get(struct qmerge **x, const iopause_fd *io, const struct taia *when)
214 + if (qm->state == -1) return -1; /* previous error */
215 + if (qm->state == 0) return 0; /* no packet */
216 + if (qm->state == 2) return 1; /* already got packet */
218 + r = dns_transmit_get(&qm->dt, io, when);
219 + if (r == -1) { qm->state = -1; return -1; } /* error */
220 + if (r == 0) { qm->state = 0; return 0; } /* must wait for i/o */
221 + if (r == 1) { qm->state = 2; return 1; } /* got packet */
222 + return -1; /* bug */
240 + struct qmerge_key key;
241 + struct dns_transmit dt;
242 + int state; /* -1 = error, 0 = need io, 1 = need get, 2 = got packet */
245 +extern int qmerge_start(struct qmerge **,const char *,int,const char *,const char *,const char *,const char *);
246 +extern void qmerge_io(struct qmerge *,iopause_fd *,struct taia *);
247 +extern int qmerge_get(struct qmerge **,const iopause_fd *,const struct taia *);
248 +extern void qmerge_free(struct qmerge **);
250 +#endif /* QMERGE_H */
253 @@ -83,7 +83,7 @@ static void cleanup(struct query *z)
257 - dns_transmit_free(&z->dt);
258 + qmerge_free(&z->qm);
259 for (j = 0;j < QUERY_MAXALIAS;++j)
260 dns_domain_free(&z->alias[j]);
261 for (j = 0;j < QUERY_MAXLEVEL;++j) {
262 @@ -452,14 +452,8 @@ static int doit(struct query *z,int stat
263 if (j == 64) goto SERVFAIL;
265 dns_sortip(z->servers[z->level],64);
267 - log_tx(z->name[z->level],DNS_T_A,z->control[z->level],z->servers[z->level],z->level);
268 - if (dns_transmit_start(&z->dt,z->servers[z->level],flagforwardonly,z->name[z->level],DNS_T_A,z->localip) == -1) goto DIE;
271 - log_tx(z->name[0],z->type,z->control[0],z->servers[0],0);
272 - if (dns_transmit_start(&z->dt,z->servers[0],flagforwardonly,z->name[0],z->type,z->localip) == -1) goto DIE;
274 + dtype = z->level ? DNS_T_A : z->type;
275 + if (qmerge_start(&z->qm,z->servers[z->level],flagforwardonly,z->name[z->level],dtype,z->localip,z->control[z->level]) == -1) goto DIE;
279 @@ -473,10 +467,10 @@ static int doit(struct query *z,int stat
282 if (++z->loop == 100) goto DIE;
283 - buf = z->dt.packet;
284 - len = z->dt.packetlen;
285 + buf = z->qm->dt.packet;
286 + len = z->qm->dt.packetlen;
288 - whichserver = z->dt.servers + 4 * z->dt.curserver;
289 + whichserver = z->qm->dt.servers + 4 * z->qm->dt.curserver;
290 control = z->control[z->level];
291 d = z->name[z->level];
292 dtype = z->level ? DNS_T_A : z->type;
293 @@ -902,7 +896,7 @@ int query_start(struct query *z,char *dn
295 int query_get(struct query *z,iopause_fd *x,struct taia *stamp)
297 - switch(dns_transmit_get(&z->dt,x,stamp)) {
298 + switch(qmerge_get(&z->qm,x,stamp)) {
302 @@ -913,5 +907,5 @@ int query_get(struct query *z,iopause_fd
304 void query_io(struct query *z,iopause_fd *x,struct taia *deadline)
306 - dns_transmit_io(&z->dt,x,deadline);
307 + qmerge_io(z->qm,x,deadline);
319 #define QUERY_MAXLEVEL 5
320 @@ -20,7 +20,7 @@ struct query {
324 - struct dns_transmit dt;
328 extern int query_start(struct query *,char *,char *,char *,char *);