]>
Commit | Line | Data |
---|---|---|
70db6d00 GS |
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 | |
4 | @@ -24,6 +24,7 @@ | |
5 | #include "log.h" | |
6 | #include "okclient.h" | |
7 | #include "droproot.h" | |
8 | +#include "maxclient.h" | |
9 | ||
10 | long interface; | |
11 | ||
12 | @@ -68,7 +69,6 @@ | |
13 | ||
14 | struct interf *interhead = 0; | |
15 | ||
16 | -#define MAXUDP 200 | |
17 | static struct udpclient { | |
18 | struct query q; | |
19 | struct taia start; | |
20 | @@ -145,7 +145,6 @@ | |
21 | } | |
22 | } | |
23 | ||
24 | -#define MAXTCP 20 | |
25 | struct tcpclient { | |
26 | struct query q; | |
27 | struct taia start; | |
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 | |
31 | @@ -149,6 +149,13 @@ | |
32 | line(); | |
33 | } | |
34 | ||
35 | +void log_tx_piggyback(const char *q, const char qtype[2], const char *control) | |
36 | +{ | |
37 | + string("txpb "); | |
38 | + logtype(qtype); space(); name(q); space(); name(control); | |
39 | + line(); | |
40 | +} | |
41 | + | |
42 | void log_cachedanswer(const char *q,const char type[2]) | |
43 | { | |
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 | |
48 | @@ -19,6 +19,7 @@ | |
49 | extern void log_cachedns(const char *,const char *); | |
50 | ||
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 *); | |
53 | ||
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 | |
59 | @@ -342,11 +342,11 @@ | |
60 | ./compile dns_txt.c | |
61 | ||
62 | dnscache: \ | |
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 \ | |
71 | socket.lib` | |
72 | ||
73 | @@ -367,7 +367,7 @@ | |
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 | |
79 | ./compile dnscache.c | |
80 | ||
81 | dnsfilter: \ | |
82 | @@ -745,11 +745,16 @@ | |
83 | compile qlog.c buffer.h qlog.h uint16.h | |
84 | ./compile qlog.c | |
85 | ||
86 | +qmerge.o: \ | |
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 | |
89 | + ./compile qmerge.c | |
90 | + | |
91 | query.o: \ | |
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 | |
97 | ./compile query.c | |
98 | ||
99 | random-ip: \ | |
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 | |
103 | @@ -0,0 +1,7 @@ | |
104 | +#ifndef MAXCLIENT_H | |
105 | +#define MAXCLIENT_H | |
106 | + | |
107 | +#define MAXUDP 200 | |
108 | +#define MAXTCP 20 | |
109 | + | |
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 | |
114 | @@ -0,0 +1,115 @@ | |
115 | +#include "qmerge.h" | |
116 | +#include "byte.h" | |
117 | +#include "log.h" | |
118 | +#include "maxclient.h" | |
119 | + | |
120 | +#define QMERGE_MAX (MAXUDP+MAXTCP) | |
121 | +struct qmerge inprogress[QMERGE_MAX]; | |
122 | + | |
123 | +static | |
124 | +int qmerge_key_init(struct qmerge_key *qmk, const char *q, const char qtype[2], | |
125 | + const char *control) | |
126 | +{ | |
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; | |
130 | + return 1; | |
131 | +} | |
132 | + | |
133 | +static | |
134 | +int qmerge_key_equal(struct qmerge_key *a, struct qmerge_key *b) | |
135 | +{ | |
136 | + return | |
137 | + byte_equal(a->qtype, 2, b->qtype) && | |
138 | + dns_domain_equal(a->q, b->q) && | |
139 | + dns_domain_equal(a->control, b->control); | |
140 | +} | |
141 | + | |
142 | +static | |
143 | +void qmerge_key_free(struct qmerge_key *qmk) | |
144 | +{ | |
145 | + dns_domain_free(&qmk->q); | |
146 | + dns_domain_free(&qmk->control); | |
147 | +} | |
148 | + | |
149 | +void qmerge_free(struct qmerge **x) | |
150 | +{ | |
151 | + struct qmerge *qm; | |
152 | + | |
153 | + qm = *x; | |
154 | + *x = 0; | |
155 | + if (!qm || !qm->active) return; | |
156 | + | |
157 | + qm->active--; | |
158 | + if (!qm->active) { | |
159 | + qmerge_key_free(&qm->key); | |
160 | + dns_transmit_free(&qm->dt); | |
161 | + } | |
162 | +} | |
163 | + | |
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) | |
167 | +{ | |
168 | + struct qmerge_key k; | |
169 | + int i; | |
170 | + int r; | |
171 | + | |
172 | + qmerge_free(qm); | |
173 | + | |
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); | |
183 | + return 0; | |
184 | + } | |
185 | + | |
186 | + for (i = 0; i < QMERGE_MAX; i++) | |
187 | + if (!inprogress[i].active) | |
188 | + break; | |
189 | + if (i == QMERGE_MAX) return -1; | |
190 | + | |
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]; | |
199 | + return 0; | |
200 | +} | |
201 | + | |
202 | +void qmerge_io(struct qmerge *qm, iopause_fd *io, struct taia *deadline) | |
203 | +{ | |
204 | + if (qm->state == 0) { | |
205 | + dns_transmit_io(&qm->dt, io, deadline); | |
206 | + qm->state = 1; | |
207 | + } | |
208 | + else { | |
209 | + io->fd = -1; | |
210 | + io->events = 0; | |
211 | + } | |
212 | +} | |
213 | + | |
214 | +int qmerge_get(struct qmerge **x, const iopause_fd *io, const struct taia *when) | |
215 | +{ | |
216 | + int r; | |
217 | + struct qmerge *qm; | |
218 | + | |
219 | + qm = *x; | |
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 */ | |
223 | + | |
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 */ | |
229 | +} | |
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 | |
233 | @@ -0,0 +1,24 @@ | |
234 | +#ifndef QMERGE_H | |
235 | +#define QMERGE_H | |
236 | + | |
237 | +#include "dns.h" | |
238 | + | |
239 | +struct qmerge_key { | |
240 | + char *q; | |
241 | + char qtype[2]; | |
242 | + char *control; | |
243 | +}; | |
244 | + | |
245 | +struct qmerge { | |
246 | + int active; | |
247 | + struct qmerge_key key; | |
248 | + struct dns_transmit dt; | |
249 | + int state; /* -1 = error, 0 = need io, 1 = need get, 2 = got packet */ | |
250 | +}; | |
251 | + | |
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 **); | |
256 | + | |
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 | |
261 | @@ -84,7 +84,7 @@ | |
262 | int j; | |
263 | int k; | |
264 | ||
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) { | |
270 | @@ -619,14 +619,8 @@ | |
271 | if (j == 256) goto SERVFAIL; | |
272 | ||
273 | dns_sortip6(z->servers[z->level],256); | |
274 | - if (z->level) { | |
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; | |
277 | - } | |
278 | - else { | |
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; | |
281 | - } | |
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; | |
284 | return 0; | |
285 | ||
286 | ||
287 | @@ -640,10 +634,10 @@ | |
288 | ||
289 | HAVEPACKET: | |
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; | |
295 | ||
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 @@ | |
302 | ||
303 | int query_get(struct query *z,iopause_fd *x,struct taia *stamp) | |
304 | { | |
305 | - switch(dns_transmit_get(&z->dt,x,stamp)) { | |
306 | + switch(qmerge_get(&z->qm,x,stamp)) { | |
307 | case 1: | |
308 | return doit(z,1); | |
309 | case -1: | |
310 | @@ -1061,5 +1055,5 @@ | |
311 | ||
312 | void query_io(struct query *z,iopause_fd *x,struct taia *deadline) | |
313 | { | |
314 | - dns_transmit_io(&z->dt,x,deadline); | |
315 | + qmerge_io(z->qm,x,deadline); | |
316 | } | |
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 | |
320 | @@ -1,7 +1,7 @@ | |
321 | #ifndef QUERY_H | |
322 | #define QUERY_H | |
323 | ||
324 | -#include "dns.h" | |
325 | +#include "qmerge.h" | |
326 | #include "uint32.h" | |
327 | ||
328 | #define QUERY_MAXLEVEL 5 | |
329 | @@ -21,7 +21,7 @@ | |
330 | uint32 scope_id; | |
331 | char type[2]; | |
332 | char class[2]; | |
333 | - struct dns_transmit dt; | |
334 | + struct qmerge *qm; | |
335 | } ; | |
336 | ||
337 | extern int query_start(struct query *,char *,char *,char *,char *,unsigned int); |