1 diff -urN djbdns-1.05.orig/dnscache.c djbdns-1.05/dnscache.c
2 --- djbdns-1.05.orig/dnscache.c 2009-03-03 11:32:02.000000000 +0100
3 +++ djbdns-1.05/dnscache.c 2009-03-03 11:32:32.000000000 +0100
8 +#include "maxclient.h"
14 struct interf *interhead = 0;
17 static struct udpclient {
28 diff -urN djbdns-1.05.orig/log.c djbdns-1.05/log.c
29 --- djbdns-1.05.orig/log.c 2009-03-03 11:32:02.000000000 +0100
30 +++ djbdns-1.05/log.c 2009-03-03 11:32:32.000000000 +0100
35 +void log_tx_piggyback(const char *q, const char qtype[2], const char *control)
38 + logtype(qtype); space(); name(q); space(); name(control);
42 void log_cachedanswer(const char *q,const char type[2])
44 string("cached "); logtype(type); space();
45 diff -urN djbdns-1.05.orig/log.h djbdns-1.05/log.h
46 --- djbdns-1.05.orig/log.h 2009-03-03 11:32:02.000000000 +0100
47 +++ djbdns-1.05/log.h 2009-03-03 11:32:32.000000000 +0100
49 extern void log_cachedns(const char *,const char *);
51 extern void log_tx(const char *,const char *,const char *,const char *,unsigned int);
52 +extern void log_tx_piggyback(const char *,const char *,const char *);
54 extern void log_nxdomain(const char *,const char *,unsigned int);
55 extern void log_nodata(const char *,const char *,const char *,unsigned int);
56 diff -urN djbdns-1.05.orig/Makefile djbdns-1.05/Makefile
57 --- djbdns-1.05.orig/Makefile 2009-03-03 11:32:02.000000000 +0100
58 +++ djbdns-1.05/Makefile 2009-03-03 11:32:32.000000000 +0100
63 -load dnscache.o droproot.o okclient.o log.o cache.o query.o \
64 +load dnscache.o droproot.o okclient.o log.o cache.o query.o qmerge.o \
65 response.o dd.o roots.o iopause.o prot.o dns.a env.a alloc.a buffer.a \
66 libtai.a unix.a byte.a socket.lib
67 ./load dnscache droproot.o okclient.o log.o cache.o \
68 - query.o response.o dd.o roots.o iopause.o prot.o dns.a \
69 + query.o qmerge.o response.o dd.o roots.o iopause.o prot.o dns.a \
70 env.a alloc.a buffer.a libtai.a unix.a byte.a `cat \
74 uint16.h uint64.h socket.h uint16.h dns.h stralloc.h gen_alloc.h \
75 iopause.h taia.h tai.h uint64.h taia.h taia.h byte.h roots.h fmt.h \
76 iopause.h query.h dns.h uint32.h alloc.h response.h uint32.h cache.h \
77 -uint32.h uint64.h ndelay.h log.h uint64.h okclient.h droproot.h
78 +uint32.h uint64.h ndelay.h log.h uint64.h okclient.h droproot.h maxclient.h
83 compile qlog.c buffer.h qlog.h uint16.h
87 +compile qmerge.c qmerge.h dns.h stralloc.h gen_alloc.h iopause.h \
88 +taia.h tai.h uint64.h log.h maxclient.h
92 compile query.c error.h roots.h log.h uint64.h case.h cache.h \
93 uint32.h uint64.h byte.h dns.h stralloc.h gen_alloc.h iopause.h \
94 taia.h tai.h uint64.h taia.h uint64.h uint32.h uint16.h dd.h alloc.h \
95 -response.h uint32.h query.h dns.h uint32.h
96 +response.h uint32.h query.h dns.h uint32.h qmerge.h
100 diff -urN djbdns-1.05.orig/maxclient.h djbdns-1.05/maxclient.h
101 --- djbdns-1.05.orig/maxclient.h 1970-01-01 01:00:00.000000000 +0100
102 +++ djbdns-1.05/maxclient.h 2009-03-03 11:32:32.000000000 +0100
110 +#endif /* MAXCLIENT_H */
111 diff -urN djbdns-1.05.orig/qmerge.c djbdns-1.05/qmerge.c
112 --- djbdns-1.05.orig/qmerge.c 1970-01-01 01:00:00.000000000 +0100
113 +++ djbdns-1.05/qmerge.c 2009-03-03 11:32:32.000000000 +0100
118 +#include "maxclient.h"
120 +#define QMERGE_MAX (MAXUDP+MAXTCP)
121 +struct qmerge inprogress[QMERGE_MAX];
124 +int qmerge_key_init(struct qmerge_key *qmk, const char *q, const char qtype[2],
125 + const char *control)
127 + if (!dns_domain_copy(&qmk->q, q)) return 0;
128 + byte_copy(qmk->qtype, 2, qtype);
129 + if (!dns_domain_copy(&qmk->control, control)) return 0;
134 +int qmerge_key_equal(struct qmerge_key *a, struct qmerge_key *b)
137 + byte_equal(a->qtype, 2, b->qtype) &&
138 + dns_domain_equal(a->q, b->q) &&
139 + dns_domain_equal(a->control, b->control);
143 +void qmerge_key_free(struct qmerge_key *qmk)
145 + dns_domain_free(&qmk->q);
146 + dns_domain_free(&qmk->control);
149 +void qmerge_free(struct qmerge **x)
155 + if (!qm || !qm->active) return;
159 + qmerge_key_free(&qm->key);
160 + dns_transmit_free(&qm->dt);
164 +int qmerge_start(struct qmerge **qm, const char servers[64], int flagrecursive,
165 + const char *q, const char qtype[2], const char localip[4],
166 + const char *control)
168 + struct qmerge_key k;
174 + byte_zero(&k, sizeof k);
175 + if (!qmerge_key_init(&k, q, qtype, control)) return -1;
176 + for (i = 0; i < QMERGE_MAX; i++) {
177 + if (!inprogress[i].active) continue;
178 + if (!qmerge_key_equal(&k, &inprogress[i].key)) continue;
179 + log_tx_piggyback(q, qtype, control);
180 + inprogress[i].active++;
181 + *qm = &inprogress[i];
182 + qmerge_key_free(&k);
186 + for (i = 0; i < QMERGE_MAX; i++)
187 + if (!inprogress[i].active)
189 + if (i == QMERGE_MAX) return -1;
191 + log_tx(q, qtype, control, servers, 0);
192 + r = dns_transmit_start(&inprogress[i].dt, servers, flagrecursive, q, qtype, localip);
193 + if (r == -1) { qmerge_key_free(&k); return -1; }
194 + inprogress[i].active++;
195 + inprogress[i].state = 0;
196 + qmerge_key_free(&inprogress[i].key);
197 + byte_copy(&inprogress[i].key, sizeof k, &k);
198 + *qm = &inprogress[i];
202 +void qmerge_io(struct qmerge *qm, iopause_fd *io, struct taia *deadline)
204 + if (qm->state == 0) {
205 + dns_transmit_io(&qm->dt, io, deadline);
214 +int qmerge_get(struct qmerge **x, const iopause_fd *io, const struct taia *when)
220 + if (qm->state == -1) return -1; /* previous error */
221 + if (qm->state == 0) return 0; /* no packet */
222 + if (qm->state == 2) return 1; /* already got packet */
224 + r = dns_transmit_get(&qm->dt, io, when);
225 + if (r == -1) { qm->state = -1; return -1; } /* error */
226 + if (r == 0) { qm->state = 0; return 0; } /* must wait for i/o */
227 + if (r == 1) { qm->state = 2; return 1; } /* got packet */
228 + return -1; /* bug */
230 diff -urN djbdns-1.05.orig/qmerge.h djbdns-1.05/qmerge.h
231 --- djbdns-1.05.orig/qmerge.h 1970-01-01 01:00:00.000000000 +0100
232 +++ djbdns-1.05/qmerge.h 2009-03-03 11:32:32.000000000 +0100
247 + struct qmerge_key key;
248 + struct dns_transmit dt;
249 + int state; /* -1 = error, 0 = need io, 1 = need get, 2 = got packet */
252 +extern int qmerge_start(struct qmerge **,const char *,int,const char *,const char *,const char *,const char *);
253 +extern void qmerge_io(struct qmerge *,iopause_fd *,struct taia *);
254 +extern int qmerge_get(struct qmerge **,const iopause_fd *,const struct taia *);
255 +extern void qmerge_free(struct qmerge **);
257 +#endif /* QMERGE_H */
258 diff -urN djbdns-1.05.orig/query.c djbdns-1.05/query.c
259 --- djbdns-1.05.orig/query.c 2009-03-03 11:32:02.000000000 +0100
260 +++ djbdns-1.05/query.c 2009-03-03 11:39:26.000000000 +0100
265 - dns_transmit_free(&z->dt);
266 + qmerge_free(&z->qm);
267 for (j = 0;j < QUERY_MAXALIAS;++j)
268 dns_domain_free(&z->alias[j]);
269 for (j = 0;j < QUERY_MAXLEVEL;++j) {
271 if (j == 256) goto SERVFAIL;
273 dns_sortip6(z->servers[z->level],256);
275 - log_tx(z->name[z->level],DNS_T_A,z->control[z->level],z->servers[z->level],z->level);
276 - if (dns_transmit_start(&z->dt,z->servers[z->level],flagforwardonly,z->name[z->level],DNS_T_A,z->localip) == -1) goto DIE;
279 - log_tx(z->name[0],z->type,z->control[0],z->servers[0],0);
280 - if (dns_transmit_start(&z->dt,z->servers[0],flagforwardonly,z->name[0],z->type,z->localip) == -1) goto DIE;
282 + dtype = z->level ? DNS_T_A : z->type;
283 + if (qmerge_start(&z->qm,z->servers[z->level],flagforwardonly,z->name[z->level],dtype,z->localip,z->control[z->level]) == -1) goto DIE;
287 @@ -640,10 +634,10 @@
290 if (++z->loop == 100) goto DIE;
291 - buf = z->dt.packet;
292 - len = z->dt.packetlen;
293 + buf = z->qm->dt.packet;
294 + len = z->qm->dt.packetlen;
296 - whichserver = z->dt.servers + 16 * z->dt.curserver;
297 + whichserver = z->qm->dt.servers + 16 * z->qm->dt.curserver;
298 control = z->control[z->level];
299 d = z->name[z->level];
300 dtype = z->level ? DNS_T_A : z->type;
301 @@ -1050,7 +1044,7 @@
303 int query_get(struct query *z,iopause_fd *x,struct taia *stamp)
305 - switch(dns_transmit_get(&z->dt,x,stamp)) {
306 + switch(qmerge_get(&z->qm,x,stamp)) {
310 @@ -1061,5 +1055,5 @@
312 void query_io(struct query *z,iopause_fd *x,struct taia *deadline)
314 - dns_transmit_io(&z->dt,x,deadline);
315 + qmerge_io(z->qm,x,deadline);
317 diff -urN djbdns-1.05.orig/query.h djbdns-1.05/query.h
318 --- djbdns-1.05.orig/query.h 2009-03-03 11:32:02.000000000 +0100
319 +++ djbdns-1.05/query.h 2009-03-03 11:32:32.000000000 +0100
328 #define QUERY_MAXLEVEL 5
333 - struct dns_transmit dt;
337 extern int query_start(struct query *,char *,char *,char *,char *,unsigned int);