djbdnscurve6 51
djbdnscurve6
Loading...
Searching...
No Matches
query.c
Go to the documentation of this file.
1#include "error.h"
2#include "roots.h"
3#include "log.h"
4#include "case.h"
5#include "sipcache.h"
6#include "byte.h"
7#include "dns.h"
8#include "uint_t.h"
9#include "dd.h"
10#include "alloc.h"
11#include "response.h"
12#include "query.h"
13#include "ip.h"
14#include "curvedns.h"
15
16#define LABLEN 255
17
18extern int flagusetxtformat;
19
20static char secretkey[32];
21static char publickey[32];
22
23void query_init(void)
24{
25 int k;
26
27 /* called after droproot(), can't use crypto_box_keypair (depends on /dev/urandom) */
28 for (k = 0; k < 32; ++k)
29 secretkey[k] = dns_random(256);
30 crypto_scalarmult_base((unsigned char *) publickey,(unsigned char *) secretkey);
31
32}
33
34static int flagforwardonly = 0;
35
37{
38 flagforwardonly = 1;
39}
40
41static void cachegeneric(const char type[2],const char *d,const char *data,unsigned int datalen,uint32 ttl)
42{
43 unsigned int len;
44 char key[257];
45
47 if (len > LABLEN) return;
48
49 byte_copy(key,2,type);
50 byte_copy(key + 2,len,d);
51 case_lowerb(key + 2,len);
52
53 cache_set(key,len + 2,data,datalen,ttl);
54}
55
56static char save_buf[8192];
57static unsigned int save_len;
58static unsigned int save_ok;
59
60static void save_start(void)
61{
62 save_len = 0;
63 save_ok = 1;
64}
65
66static void save_data(const char *buf,unsigned int len)
67{
68 if (!save_ok) return;
69 if (len > (sizeof(save_buf)) - save_len) { save_ok = 0; return; }
70 byte_copy(save_buf + save_len,len,buf);
71 save_len += len;
72}
73
74static void save_finish(const char type[2],const char *d,uint32 ttl)
75{
76 if (!save_ok) return;
77 cachegeneric(type,d,save_buf,save_len,ttl);
78}
79
80static int typematch(const char rtype[2],const char qtype[2])
81{
82 return byte_equal(qtype,2,rtype) || byte_equal(qtype,2,DNS_T_ANY);
83}
84
85static uint32 ttlget(char buf[4])
86{
87 uint32 ttl;
88
89 uint32_unpack_big(buf,&ttl);
90 if (ttl > 1000000000) return 0;
91 if (ttl > 604800) return 604800;
92 return ttl;
93}
94
95static void cleanup(struct query *z)
96{
97 int j;
98 int k;
99
100 dns_transmit_free(&z->dt);
101 for (j = 0; j < QUERY_MAXALIAS; ++j)
102 dns_domain_free(&z->alias[j]);
103 for (j = 0; j < QUERY_MAXLEVEL; ++j) {
104 dns_domain_free(&z->name[j]);
105 for (k = 0; k < QUERY_MAXNS; ++k)
106 dns_domain_free(&z->ns[j][k]);
107 }
108}
109
110static int rqa(struct query *z)
111{
112 int i;
113
114 for (i = QUERY_MAXALIAS - 1; i >= 0; --i)
115 if (z->alias[i]) {
116 if (!response_query(z->alias[i],z->type,z->class)) return 0;
117 while (i > 0) {
118 if (!response_cname(z->alias[i],z->alias[i - 1],z->aliasttl[i])) return 0;
119 --i;
120 }
121 if (!response_cname(z->alias[0],z->name[0],z->aliasttl[0])) return 0;
122 return 1;
123 }
124
125 if (!response_query(z->name[0],z->type,z->class)) return 0;
126 return 1;
127}
128
129static int globalip(char *d,char ip[16])
130{
131 if (dns_domain_equal(d,"\014ip6-loopback\0")) {
132 byte_copy(ip,16,IP6_LOOPBACK_OCTAL);
133 return 1;
134 }
135 if (dns_domain_equal(d,"\014ip4-loopback\0")) {
136 byte_copy(ip,12,V4mappedprefix);
137 byte_copy(ip + 12,4,IP4_LOOPBACK_OCTAL);
138 return 1;
139 }
140
141 /* Domain names may look like IPv4 addresses: 1.2.3.com; not like IPv6 */
142
143 if (dd4(d,"",ip) == 4) return 1;
144 return 0;
145}
146
147static char *t1 = 0;
148static char *t2 = 0;
149static char *t3 = 0;
150static char *cname = 0;
151static char *referral = 0;
152static unsigned int *records = 0;
153
154static int smaller(char *buf,unsigned int len,unsigned int pos1,unsigned int pos2)
155{
156 char header1[12];
157 char header2[12];
158 int r;
159 unsigned int len1;
160 unsigned int len2;
161
162 pos1 = dns_packet_getname(buf,len,pos1,&t1);
163 dns_packet_copy(buf,len,pos1,header1,10);
164 pos2 = dns_packet_getname(buf,len,pos2,&t2);
165 dns_packet_copy(buf,len,pos2,header2,10);
166
167 r = byte_diff(header1,4,header2);
168 if (r < 0) return 1;
169 if (r > 0) return 0;
170
171 len1 = dns_domain_length(t1);
172 len2 = dns_domain_length(t2);
173 if (len1 < len2) return 1;
174 if (len1 > len2) return 0;
175
176 r = case_diffb(t1,len1,t2);
177 if (r < 0) return 1;
178 if (r > 0) return 0;
179
180 if (pos1 < pos2) return 1;
181 return 0;
182}
183
184static int doit(struct query *z,int state)
185{
186 char key[257];
187 char *cached;
188 unsigned int cachedlen;
189 char *buf;
190 unsigned int len;
191 const char *whichserver;
192 char *whichkey;
193 char header[24];
194 char addr[16];
195 char misc[20];
196 char pubkey[32];
197 int flaghaskey;
198 int flagns;
199 unsigned int rcode;
200 unsigned int posanswers;
201 uint16 numanswers;
202 unsigned int posauthority;
203 uint16 numauthority;
204 uint16 numglue;
205 unsigned int pos;
206 unsigned int pos2;
207 uint16 datalen;
208 char *control;
209 char *d;
210 char *suffix;
211 const char *dtype;
212 unsigned int dlen;
213 int flagout;
214 int flagcname;
215 int flagreferral;
216 int flagsoa;
217 const char *cnskey;
218 uint32 ttl;
219 uint32 soattl;
220 uint32 cachettl;
221 uint32 cnamettl;
222 int i;
223 int j;
224 int k;
225 int p;
226 int q;
227
228 errno = EIO;
229 if (state == 1) goto HAVEPACKET;
230 if (state == -1) {
231 log_servfail(z->name[z->level]);
232 goto SERVFAIL;
233 }
234
235
236 NEWNAME:
237 if (++z->loop == QUERY_MAXLOOP) goto DIE;
238 d = z->name[z->level];
239 dtype = z->level ? (z->ipv6[z->level] ? DNS_T_AAAA : DNS_T_A) : z->type;
241
242 if (globalip(d,misc)) {
243 if (z->level) {
244 flagns = cns_addns(z,misc,0,0); /* new; ok */
245 if (flagns) log_servflag(addr,flagns);
246 goto LOWERLEVEL;
247 }
248 if (!rqa(z)) goto DIE;
249 if (typematch(DNS_T_A,dtype)) {
250 if (!response_rstart(d,DNS_T_A,MAX_TTL)) goto DIE;
251 if (!response_addbytes(misc,4)) goto DIE;
253 }
254 if (typematch(DNS_T_AAAA,dtype)) {
255 if (!response_rstart(d,DNS_T_AAAA,MAX_TTL)) goto DIE;
256 if (!response_addbytes(misc,16)) goto DIE;
258 }
259 cleanup(z);
260 return 1;
261 }
262
263 /* common localhost and loopback handling (query.h) */
264
265 if (dns_domain_equal(d,"\011localhost\0") ||
266 dns_domain_equal(d,"\010loopback\0")) {
267 if (z->level) goto LOWERLEVEL;
268 if (!rqa(z)) goto DIE;
269 if (typematch(DNS_T_A,dtype)) {
270 if (!response_rstart(d,DNS_T_A,MAX_TTL)) goto DIE;
271 if (!response_addbytes(IP4_LOOPBACK_OCTAL,4)) goto DIE;
273 }
274 if (typematch(DNS_T_AAAA,dtype)) {
275 if (!response_rstart(d,DNS_T_AAAA,MAX_TTL)) goto DIE;
276 if (!response_addbytes(IP6_LOOPBACK_OCTAL,16)) goto DIE;
278 }
279 cleanup(z);
280 return 1;
281 }
282
283 /* IPv6 well-known names (query.h) RFC 4291 */
284
287 if (z->level) goto LOWERLEVEL;
288 if (!rqa(z)) goto DIE;
289 if (typematch(DNS_T_PTR,dtype)) {
290 if (!response_rstart(d,DNS_T_PTR,MAX_TTL)) goto DIE;
291 if (!response_addname("\014ip6-loopback\0")) goto DIE;
293 }
294 cleanup(z);
295 return 1;
296 }
297
298 if (dns_domain_equal(d,IP6_LOCALNET_ARPA)) { /* unspecified IPv6 */
299 if (z->level) goto LOWERLEVEL;
300 if (!rqa(z)) goto DIE;
301 if (typematch(DNS_T_PTR,dtype)) {
302 if (!response_rstart(d,DNS_T_PTR,MAX_TTL)) goto DIE;
303 if (!response_addname("\014ip6-localnet\0")) goto DIE;
305 }
306 cleanup(z);
307 return 1;
308 }
309
311 if (z->level) goto LOWERLEVEL;
312 if (!rqa(z)) goto DIE;
313 if (typematch(DNS_T_PTR,dtype)) {
314 if (!response_rstart(d,DNS_T_PTR,MAX_TTL)) goto DIE;
315 if (!response_addname("\017ip6-mcastprefix\0")) goto DIE;
317 }
318 cleanup(z);
319 return 1;
320 }
321
323 if (z->level) goto LOWERLEVEL;
324 if (!rqa(z)) goto DIE;
325 if (typematch(DNS_T_PTR,dtype)) {
326 if (!response_rstart(d,DNS_T_PTR,MAX_TTL)) goto DIE;
327 if (!response_addname("\016ip6-allnodes\0")) goto DIE;
329 }
330 cleanup(z);
331 return 1;
332 }
333
335 if (z->level) goto LOWERLEVEL;
336 if (!rqa(z)) goto DIE;
337 if (typematch(DNS_T_PTR,dtype)) {
338 if (!response_rstart(d,DNS_T_PTR,MAX_TTL)) goto DIE;
339 if (!response_addname("\016ip6-allrouters\0")) goto DIE;
341 }
342 cleanup(z);
343 return 1;
344 }
345
346 if (dns_domain_equal(d,"\015ip6-localhost\0") ||
347 dns_domain_equal(d,"\014ip6-loopback\0")) {
348 if (z->level) goto LOWERLEVEL;
349 if (!rqa(z)) goto DIE;
350 if (typematch(DNS_T_AAAA,dtype)) {
351 if (!response_rstart(d,DNS_T_AAAA,MAX_TTL)) goto DIE;
352 if (!response_addbytes(IP6_LOOPBACK_OCTAL,16)) goto DIE;
354 }
355 cleanup(z);
356 return 1;
357 }
358
359 if (dns_domain_equal(d,"\014ip6-localnet\0")) {
360 if (z->level) goto LOWERLEVEL;
361 if (!rqa(z)) goto DIE;
362 if (typematch(DNS_T_AAAA,dtype)) {
363 if (!response_rstart(d,DNS_T_AAAA,MAX_TTL)) goto DIE;
364 if (!response_addbytes(IP6_LOCALNET,16)) goto DIE;
366 }
367 cleanup(z);
368 return 1;
369 }
370
371 if (dns_domain_equal(d,"\017ip6-mcastprefix\0")) {
372 if (z->level) goto LOWERLEVEL;
373 if (!rqa(z)) goto DIE;
374 if (typematch(DNS_T_AAAA,dtype)) {
375 if (!response_rstart(d,DNS_T_AAAA,MAX_TTL)) goto DIE;
376 if (!response_addbytes(IP6_MULTICASTPFX_OCTAL,16)) goto DIE;
378 }
379 cleanup(z);
380 return 1;
381 }
382
383 if (dns_domain_equal(d,"\14ip6-allnodes\0")) {
384 if (z->level) goto LOWERLEVEL;
385 if (!rqa(z)) goto DIE;
386 if (typematch(DNS_T_AAAA,dtype)) {
387 if (!response_rstart(d,DNS_T_AAAA,MAX_TTL)) goto DIE;
388 if (!response_addbytes(IP6_ALLNODES_OCTAL,16)) goto DIE;
390 }
391 cleanup(z);
392 return 1;
393 }
394
395 if (dns_domain_equal(d,"\16ip6-allrouters\0")) {
396 if (z->level) goto LOWERLEVEL;
397 if (!rqa(z)) goto DIE;
398 if (typematch(DNS_T_AAAA,dtype)) {
399 if (!response_rstart(d,DNS_T_AAAA,MAX_TTL)) goto DIE;
400 if (!response_addbytes(IP6_ALLROUTERS_OCTAL,16)) goto DIE;
402 }
403 cleanup(z);
404 return 1;
405 }
406
407 /* IPv4 well-known names (query.h) */
408
410 if (z->level) goto LOWERLEVEL;
411 if (!rqa(z)) goto DIE;
412 if (typematch(DNS_T_PTR,dtype)) {
413 if (!response_rstart(d,DNS_T_PTR,MAX_TTL)) goto DIE;
414 if (!response_addname("\014ip4-loopback\0")) goto DIE;
416 }
417 cleanup(z);
418 return 1;
419 }
420
422 if (z->level) goto LOWERLEVEL;
423 if (!rqa(z)) goto DIE;
424 if (typematch(DNS_T_PTR,dtype)) {
425 if (!response_rstart(d,DNS_T_PTR,MAX_TTL)) goto DIE;
426 if (!response_addname("\015ip4-localhost\0")) goto DIE;
428 }
429 cleanup(z);
430 log_stats();
431 return 1;
432 }
433
434 if (dns_domain_equal(d,"\014ip4-localnet\0")) {
435 if (z->level) goto LOWERLEVEL;
436 if (!rqa(z)) goto DIE;
437 if (typematch(DNS_T_A,dtype)) {
438 if (!response_rstart(d,DNS_T_A,MAX_TTL)) goto DIE;
439 if (!response_addbytes(IP4_LOCALNET,4)) goto DIE;
441 }
442 cleanup(z);
443 return 1;
444 }
445
446 if (dns_domain_equal(d,"\015ip4-localhost\0") ||
447 dns_domain_equal(d,"\014ip4-loopback\0")) {
448 if (z->level) goto LOWERLEVEL;
449 if (!rqa(z)) goto DIE;
450 if (typematch(DNS_T_A,dtype)) {
451 if (!response_rstart(d,DNS_T_A,MAX_TTL)) goto DIE;
452 if (!response_addbytes(IP4_LOOPBACK_OCTAL,4)) goto DIE;
454 }
455 cleanup(z);
456 return 1;
457 }
458
459 /* .onion TLD RFC 7686 */
460
461 if (dns_domain_suffix(d,"\05onion\0"))
462 goto NXDOMAIN;
463
464 /* Reverse lookup for locally assigned IPv6 addresses (FD00::/8) RFC 4193 */
465
466 if (typematch(DNS_T_PTR,dtype) &&
467 dns_domain_suffix(d,"\01d\01f\03ip6\04arpa\0") &&
468 roots_same(d,"\0") &&
469 !flagforwardonly) // the cache we'll ask might know a proper NS
470 goto NXDOMAIN;
471
472 /* special names done */
473
474 if (dlen <= LABLEN) {
475 byte_copy(key,2,DNS_T_ANY);
476 byte_copy(key + 2,dlen,d);
477 case_lowerb(key + 2,dlen);
478 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
479 if (cached) {
481 goto NXDOMAIN;
482 }
483
484 byte_copy(key,2,DNS_T_CNAME);
485 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
486
487 if (cached && cachedlen) {
488 if (typematch(DNS_T_CNAME,dtype)) {
490 if (!rqa(z)) goto DIE;
491 if (!response_cname(z->name[0],cached,ttl)) goto DIE;
492 cleanup(z);
493 return 1;
494 }
495 log_cachedcname(d,cached);
496
497 if (!dns_domain_copy(&cname,cached)) goto DIE;
498 goto CNAME;
499 }
500
501 if (typematch(DNS_T_NS,dtype)) {
502 byte_copy(key,2,DNS_T_NS);
503 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
504 if (cached && (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
505 if (z->level) {
506 flaghaskey = cns_pubkey(d,pubkey);
507 flagns = cns_addns(z,cached,flaghaskey,pubkey); /* ok */
508 if (flagns) log_servflag(addr,flagns);
510 }
511 if (!rqa(z)) goto DIE;
512 pos = 0;
513 while ((pos = dns_packet_getname(cached,cachedlen,pos,&t2))) {
514 if (!response_rstart(d,DNS_T_NS,ttl)) goto DIE;
515 if (!response_addname(t2)) goto DIE;
517 }
518 cleanup(z);
519 return 1;
520 }
521 }
522
523 if (typematch(DNS_T_PTR,dtype)) {
524 byte_copy(key,2,DNS_T_PTR);
525 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
526 if (cached && (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
528 if (!rqa(z)) goto DIE;
529 pos = 0;
530 while ((pos = dns_packet_getname(cached,cachedlen,pos,&t2))) {
531 if (!response_rstart(d,DNS_T_PTR,ttl)) goto DIE;
532 if (!response_addname(t2)) goto DIE;
534 }
535 cleanup(z);
536 return 1;
537 }
538 }
539
540 if (typematch(DNS_T_MX,dtype)) {
541 byte_copy(key,2,DNS_T_MX);
542 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
543 if (cached && (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
545 if (!rqa(z)) goto DIE;
546 pos = 0;
547 while ((pos = dns_packet_copy(cached,cachedlen,pos,misc,2))) {
548 pos = dns_packet_getname(cached,cachedlen,pos,&t2);
549 if (!pos) break;
550 if (!response_rstart(d,DNS_T_MX,ttl)) goto DIE;
551 if (!response_addbytes(misc,2)) goto DIE;
552 if (!response_addname(t2)) goto DIE;
554 }
555 cleanup(z);
556 return 1;
557 }
558 }
559
560 if (typematch(DNS_T_A,dtype)) {
561 byte_copy(key,2,DNS_T_A);
562 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
563 /* if we were looking the A record up to find an NS, try IPv6 too */
564 if (cached && !cachedlen && z->level) {
565 z->ipv6[z->level] = 1;
566 goto NEWNAME;
567 }
568 if (cached && (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
569 if (z->level) {
570 flaghaskey = cns_pubkey(d,pubkey);
572 while (cachedlen >= 4) {
573 for (k = 0; k < QUERY_MAXIPLEN; k += 16)
574 if (byte_equal(z->servers[z->level - 1] + k,16,V6localnet)) {
575 byte_copy(z->servers[z->level - 1] + k,12,V4mappedprefix);
576 byte_copy(z->servers[z->level - 1] + k + 12,4,cached);
577 break;
578 }
579 byte_copy(addr,12,V4mappedprefix);
580 byte_copy(addr+12,4,cached);
581 flagns = cns_addns(z,addr,flaghaskey,pubkey);
582 if (flagns) log_servflag(addr,flagns);
583 cached += 4;
584 cachedlen -= 4;
585 }
586 goto LOWERLEVEL;
587 }
588
590 if (!rqa(z)) goto DIE;
591 while (cachedlen >= 4) {
592 if (!response_rstart(d,DNS_T_A,ttl)) goto DIE;
593 if (!response_addbytes(cached,4)) goto DIE;
595 cached += 4;
596 cachedlen -= 4;
597 }
598 cleanup(z);
599 return 1;
600 }
601 }
602
603 if (typematch(DNS_T_AAAA,dtype)) {
604 byte_copy(key,2,DNS_T_AAAA);
605 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
606 if (cached && (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
607 if (z->level) {
608 flaghaskey = cns_pubkey(d,pubkey);
610 while (cachedlen >= 16) {
611 flagns = cns_addns(z,cached,flaghaskey,pubkey);
612 if (flagns) log_servflag(addr,flagns);
613 cached += 16;
614 cachedlen -= 16;
615 }
616 goto LOWERLEVEL;
617 }
618
620 if (!rqa(z)) goto DIE;
621 while (cachedlen >= 16) {
622 if (!response_rstart(d,DNS_T_AAAA,ttl)) goto DIE;
623 if (!response_addbytes(cached,16)) goto DIE;
625 cached += 16;
626 cachedlen -= 16;
627 }
628 cleanup(z);
629 return 1;
630 }
631 }
632
633 if (!typematch(DNS_T_ANY,dtype) && !typematch(DNS_T_AXFR,dtype) &&
634 !typematch(DNS_T_NS,dtype) && !typematch(DNS_T_PTR,dtype) &&
635 !typematch(DNS_T_A,dtype) && !typematch(DNS_T_AAAA,dtype) &&
636 !typematch(DNS_T_MX,dtype)) {
637 byte_copy(key,2,dtype);
638 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
639 if (cached && (cachedlen || byte_diff(dtype,2,DNS_T_ANY))) {
640 log_cachedanswer(d,dtype);
641 if (!rqa(z)) goto DIE;
642 while (cachedlen >= 2) {
643 uint16_unpack_big(cached,&datalen);
644 cached += 2;
645 cachedlen -= 2;
646 if (datalen > cachedlen) goto DIE;
647 if (!response_rstart(d,dtype,ttl)) goto DIE;
648 if (!response_addbytes(cached,datalen)) goto DIE;
650 cached += datalen;
651 cachedlen -= datalen;
652 }
653 cleanup(z);
654 return 1;
655 }
656 }
657 } /* end of dlen if */
658
659 for (;;) {
660 /* XXX: allow roots() to provide keys */
661 if (roots(z->servers[z->level],d)) {
662 z->flagnskeys[z->level] = 0;
663 for (j = 0; j < QUERY_MAXNS; ++j)
664 dns_domain_free(&z->ns[z->level][j]);
665 z->control[z->level] = d;
666 break;
667 }
668
669 if (!flagforwardonly && (z->level < 2))
670 if (dlen < LABLEN) {
671 byte_copy(key,2,DNS_T_NS);
672 byte_copy(key + 2,dlen,d);
673 case_lowerb(key + 2,dlen);
674 cached = cache_get(key,dlen + 2,&cachedlen,&ttl);
675 if (cached && cachedlen) {
676 z->control[z->level] = d;
677 byte_zero(z->servers[z->level],QUERY_MAXIPLEN);
678 z->flagnskeys[z->level] = 0; /* XXX */
679 for (j = 0; j < QUERY_MAXNS; ++j)
680 dns_domain_free(&z->ns[z->level][j]);
681 pos = 0;
682 j = 0;
683 while ((pos = dns_packet_getname(cached,cachedlen,pos,&t1))) {
684 log_cachedns(d,t1);
685 if (j < QUERY_MAXNS)
686 if (!dns_domain_copy(&z->ns[z->level][j++],t1)) goto DIE;
687 }
688 break;
689 }
690 }
691
692 if (!*d) goto DIE;
693 j = 1 + (unsigned int) (unsigned char) *d;
694 dlen -= j;
695 d += j;
696 }
697
698
699 HAVENS:
700 for (j = 0; j < QUERY_MAXNS; ++j)
701 if (z->ns[z->level][j]) {
702 if (z->level + 1 < QUERY_MAXLEVEL) {
703 if (!dns_domain_copy(&z->name[z->level + 1],z->ns[z->level][j])) goto DIE;
704 dns_domain_free(&z->ns[z->level][j]);
705 ++z->level;
706 z->ipv6[z->level] = 0;
707 goto NEWNAME;
708 }
709 dns_domain_free(&z->ns[z->level][j]);
710 }
711
712 for (j = 0; j < QUERY_MAXIPLEN; j += 16)
713 if (byte_diff(z->servers[z->level] + j,16,V6localnet)) break;
714 if (j == QUERY_MAXIPLEN) goto SERVFAIL;
715
716 if (z->flagnskeys[z->level]) {
717 byte_copy(key,2,DNS_T_AXFR);
718 for (j = 0; j < QUERY_MAXIPLEN; j += 16)
719 if (byte_diff(z->servers[z->level] + j,16,V6localnet)) {
720 whichkey = z->keys[z->level] + 2 * j;
721 byte_copy(key + 2,32,whichkey);
722 cached = cache_get(key,34,&cachedlen,&ttl);
723 if (cached && (cachedlen == 32)) {
724 byte_copy(whichkey,32,cached);
725 continue;
726 }
727 crypto_box_beforenm((unsigned char *) whichkey,(const unsigned char *) whichkey,(const unsigned char *) secretkey);
728 cache_set(key,34,whichkey,32,MAX_TTL);
729 }
730 }
731
732 cns_sortns(z->servers[z->level],z->keys[z->level],QUERY_MAXNS);
733 dtype = z->level ? DNS_T_A : z->type;
734 control = flagusetxtformat ? z->control[z->level] : 0;
735 cnskey = z->flagnskeys[z->level] ? z->keys[z->level] : 0;
736 log_tx(z->name[z->level],dtype,z->control[z->level],z->servers[z->level],z->flagnskeys[z->level],z->level);
737
738 if (cns_transmit_start(&z->dt,z->servers[z->level],flagforwardonly,z->name[z->level],\
739 dtype,z->localip,cnskey,publickey,control) < 0) goto DIE;
740
741 return 0;
742
743
744 LOWERLEVEL:
745 dns_domain_free(&z->name[z->level]);
746 for (j = 0; j < QUERY_MAXNS; ++j)
747 dns_domain_free(&z->ns[z->level][j]);
748 --z->level;
749 goto HAVENS;
750
751
752 HAVEPACKET:
753 if (++z->loop == QUERY_MAXLOOP) goto DIE;
754 buf = z->dt.packet;
755 len = z->dt.packetlen;
756
757 whichserver = z->dt.servers + 16 * z->dt.curserver;
758 control = z->control[z->level];
759 d = z->name[z->level];
760 /* dtype = z->level ? DNS_T_A : z->type; */
761 dtype = z->level ? (z->ipv6[z->level] ? DNS_T_AAAA : DNS_T_A) : z->type;
762
763 pos = dns_packet_copy(buf,len,0,header,12); if (!pos) goto DIE;
764 pos = dns_packet_skipname(buf,len,pos); if (!pos) goto DIE;
765 pos += 4;
766 posanswers = pos;
767
768 uint16_unpack_big(header + 6,&numanswers);
769 uint16_unpack_big(header + 8,&numauthority);
770 uint16_unpack_big(header + 10,&numglue);
771
772 rcode = header[3] & 15;
773 if (rcode && (rcode != 3)) goto DIE; /* impossible; see irrelevant() */
774
775 flagout = 0;
776 flagcname = 0;
777 flagreferral = 0;
778 flagsoa = 0;
779 soattl = 0;
780 cachettl = 0;
781 cnamettl = 0;
782
783 for (j = 0; j < numanswers; ++j) {
784 pos = dns_packet_getname(buf,len,pos,&t1); if (!pos) goto DIE;
785 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
786
787 if (dns_domain_equal(t1,d))
788 if (byte_equal(header + 2,2,DNS_C_IN)) { /* should always be true */
789 if (typematch(header,dtype))
790 flagout = 1;
791 else if (typematch(header,DNS_T_CNAME)) {
792 if (!dns_packet_getname(buf,len,pos,&cname)) goto DIE;
793 flagcname = 1;
794 cnamettl = ttlget(header + 4);
795 }
796 }
797
798 uint16_unpack_big(header + 8,&datalen);
799 pos += datalen;
800 }
801 posauthority = pos;
802
803 for (j = 0; j < numauthority; ++j) {
804 pos = dns_packet_getname(buf,len,pos,&t1); if (!pos) goto DIE;
805 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
806
807 if (typematch(header,DNS_T_SOA)) {
808 flagsoa = 1;
809 soattl = ttlget(header + 4);
810 if (soattl > 3600) soattl = 3600;
811 }
812 else if (typematch(header,DNS_T_NS)) {
813 flagreferral = 1;
814 if (!dns_domain_copy(&referral,t1)) goto DIE;
815 }
816
817 uint16_unpack_big(header + 8,&datalen);
818 pos += datalen;
819 }
820
821 /* JBP Negative cache patch and record in log */
822
823 if (flagsoa && (pos <= len)) {
824 cachettl = ttlget(buf + pos - 4);
825 if (soattl < cachettl) cachettl = soattl;
826 }
827
828 if (!flagcname && !rcode && !flagout && flagreferral && !flagsoa)
829 if (dns_domain_equal(referral,control) || !dns_domain_suffix(referral,control)) {
830 log_lame(whichserver,control,referral);
831 byte_zero((char *)whichserver,4);
832 goto HAVENS;
833 }
834
835 if (records) { alloc_free(records); records = 0; }
836
837 k = numanswers + numauthority + numglue;
838 records = (unsigned int *) alloc(k * sizeof(unsigned int));
839 if (!records) goto DIE;
840
841 pos = posanswers;
842 for (j = 0; j < k; ++j) {
843 records[j] = pos;
844 pos = dns_packet_getname(buf,len,pos,&t1); if (!pos) goto DIE;
845 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
846 uint16_unpack_big(header + 8,&datalen);
847 pos += datalen;
848 }
849
850 i = j = k;
851 while (j > 1) {
852 if (i > 1) { --i; pos = records[i - 1]; }
853 else { pos = records[j - 1]; records[j - 1] = records[i - 1]; --j; }
854
855 q = i;
856 while ((p = q * 2) < j) {
857 if (!smaller(buf,len,records[p],records[p - 1])) ++p;
858 records[q - 1] = records[p - 1]; q = p;
859 }
860 if (p == j) {
861 records[q - 1] = records[p - 1]; q = p;
862 }
863 while ((q > i) && smaller(buf,len,records[(p = q/2) - 1],pos)) {
864 records[q - 1] = records[p - 1]; q = p;
865 }
866 records[q - 1] = pos;
867 }
868
869 i = 0;
870 while (i < k) {
871 char type[2];
872
873 pos = dns_packet_getname(buf,len,records[i],&t1); if (!pos) goto DIE;
874 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
875 ttl = ttlget(header + 4);
876
877 byte_copy(type,2,header);
878 if (byte_diff(header + 2,2,DNS_C_IN)) { ++i; continue; }
879
880 for (j = i + 1; j < k; ++j) {
881 pos = dns_packet_getname(buf,len,records[j],&t2); if (!pos) goto DIE;
882 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
883 if (!dns_domain_equal(t1,t2)) break;
884 if (byte_diff(header,2,type)) break;
885 if (byte_diff(header + 2,2,DNS_C_IN)) break;
886 }
887
888 if (!dns_domain_suffix(t1,control)) { i = j; continue; }
889 if (!roots_same(t1,control)) { i = j; continue; }
890
891 if (byte_equal(type,2,DNS_T_ANY))
892 ;
893 else if (byte_equal(type,2,DNS_T_AXFR))
894 ;
895 else if (byte_equal(type,2,DNS_T_SOA)) {
896 while (i < j) {
897 pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
898 pos = dns_packet_getname(buf,len,pos + 10,&t2); if (!pos) goto DIE;
899 pos = dns_packet_getname(buf,len,pos,&t3); if (!pos) goto DIE;
900 pos = dns_packet_copy(buf,len,pos,misc,20); if (!pos) goto DIE;
901 if (records[i] < posauthority)
902 log_rrsoa(whichserver,t1,t2,t3,misc,ttl);
903 ++i;
904 }
905 }
906 else if (byte_equal(type,2,DNS_T_CNAME)) {
907 pos = dns_packet_skipname(buf,len,records[j - 1]); if (!pos) goto DIE;
908 pos = dns_packet_getname(buf,len,pos + 10,&t2); if (!pos) goto DIE;
909 log_rrcname(whichserver,t1,t2,ttl);
910 cachegeneric(DNS_T_CNAME,t1,t2,dns_domain_length(t2),ttl);
911 }
912 else if (byte_equal(type,2,DNS_T_PTR)) {
913 save_start();
914 while (i < j) {
915 pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
916 pos = dns_packet_getname(buf,len,pos + 10,&t2); if (!pos) goto DIE;
917 log_rrptr(whichserver,t1,t2,ttl);
918 save_data(t2,dns_domain_length(t2));
919 ++i;
920 }
921 save_finish(DNS_T_PTR,t1,ttl);
922 }
923 else if (byte_equal(type,2,DNS_T_NS)) {
924 save_start();
925 while (i < j) {
926 pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
927 pos = dns_packet_getname(buf,len,pos + 10,&t2); if (!pos) goto DIE;
928 log_rrns(whichserver,t1,t2,ttl);
929 save_data(t2,dns_domain_length(t2));
930 ++i;
931 }
932 save_finish(DNS_T_NS,t1,ttl);
933 }
934 else if (byte_equal(type,2,DNS_T_MX)) {
935 save_start();
936 while (i < j) {
937 pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
938 pos = dns_packet_copy(buf,len,pos + 10,misc,2); if (!pos) goto DIE;
939 pos = dns_packet_getname(buf,len,pos,&t2); if (!pos) goto DIE;
940 log_rrmx(whichserver,t1,t2,misc,ttl);
941 save_data(misc,2);
942 save_data(t2,dns_domain_length(t2));
943 ++i;
944 }
945 save_finish(DNS_T_MX,t1,ttl);
946 }
947 else if (byte_equal(type,2,DNS_T_A)) {
948 save_start();
949 while (i < j) {
950 pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
951 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
952 if (byte_equal(header + 8,2,"\0\4")) {
953 pos = dns_packet_copy(buf,len,pos,header,4); if (!pos) goto DIE;
954 save_data(header,4);
955 log_rr(whichserver,t1,DNS_T_A,header,4,ttl);
956 }
957 ++i;
958 }
959 save_finish(DNS_T_A,t1,ttl);
960 }
961 else if (byte_equal(type,2,DNS_T_AAAA)) {
962 save_start();
963 while (i < j) {
964 pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
965 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
966 if (byte_equal(header + 8,2,"\0\20")) {
967 pos = dns_packet_copy(buf,len,pos,header,16); if (!pos) goto DIE;
968 save_data(header,16);
969 log_rr(whichserver,t1,DNS_T_AAAA,header,16,ttl);
970 }
971 ++i;
972 }
973 save_finish(DNS_T_AAAA,t1,ttl);
974 }
975 else {
976 save_start();
977 while (i < j) {
978 pos = dns_packet_skipname(buf,len,records[i]); if (!pos) goto DIE;
979 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
980 uint16_unpack_big(header + 8,&datalen);
981 if (datalen > len - pos) goto DIE;
982 save_data(header + 8,2);
983 save_data(buf + pos,datalen);
984 log_rr(whichserver,t1,type,buf + pos,datalen,ttl);
985 ++i;
986 }
987 save_finish(type,t1,ttl);
988 }
989
990 i = j;
991 }
992
993 alloc_free(records); records = 0;
994
995 /* Original DJB's CNAME handling instead of JBP;
996 ** the latter does not work well under all given circumstances */
997
998 if (flagcname) {
999 ttl = cnamettl;
1000 CNAME:
1001 if (!z->level) {
1002 if (z->alias[QUERY_MAXALIAS - 1]) goto DIE;
1003 for (j = QUERY_MAXALIAS - 1; j > 0; --j)
1004 z->alias[j] = z->alias[j - 1];
1005
1006 for (j = QUERY_MAXALIAS - 1; j > 0; --j)
1007 z->aliasttl[j] = z->aliasttl[j - 1];
1008
1009 z->alias[0] = z->name[0];
1010 z->aliasttl[0] = ttl;
1011 z->name[0] = 0;
1012 }
1013 if (!dns_domain_copy(&z->name[z->level],cname)) goto DIE;
1014 goto NEWNAME;
1015 }
1016
1017 if (rcode == 3) {
1018 log_nxdomain(whichserver,d,cachettl);
1019 cachegeneric(DNS_T_ANY,d,"",0,cachettl);
1020
1021 NXDOMAIN:
1022 if (z->level) goto LOWERLEVEL;
1023 if (!rqa(z)) goto DIE;
1025 cleanup(z);
1026 return 1;
1027 }
1028
1029 /* Don't save empty RRSets for those types that we use as special markers */
1030
1031 if (!flagout && flagsoa)
1032 if (byte_diff(DNS_T_ANY,2,dtype))
1033 if (byte_diff(DNS_T_AXFR,2,dtype)) {
1034 save_start();
1035 save_finish(dtype,d,soattl);
1036 log_nodata(whichserver,d,dtype,soattl);
1037 if (z->level && !byte_diff(DNS_T_A,2,dtype)) {
1038 d = z->name[z->level];
1039 z->ipv6[z->level] = 1;
1040 goto NEWNAME; /* retry, will ask for AAAA next */
1041 }
1042 }
1043
1044 log_stats();
1045
1046 if (flagout || flagsoa || !flagreferral) {
1047 if (z->level) {
1048 flaghaskey = cns_pubkey(d,pubkey);
1049 pos = posanswers;
1050 for (j = 0; j < numanswers; ++j) {
1051 pos = dns_packet_getname(buf,len,pos,&t1); if (!pos) goto DIE;
1052 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
1053 uint16_unpack_big(header + 8,&datalen);
1054 if (dns_domain_equal(t1,d)) {
1055 if (typematch(header,DNS_T_A))
1056 if (byte_equal(header + 2,2,DNS_C_IN)) /* should always be true */
1057 if (datalen == 4) {
1058 if (!dns_packet_copy(buf,len,pos,misc,4)) goto DIE;
1059 byte_copy(addr,12,V4mappedprefix);
1060 byte_copy(addr+12,4,misc);
1061 flagns = cns_addns(z,addr,flaghaskey,pubkey);
1062 if (flagns) log_servflag(addr,flagns);
1063 }
1064 if (typematch(header,DNS_T_AAAA))
1065 if (byte_equal(header + 2,2,DNS_C_IN)) /* should always be true */
1066 if (datalen == 16) {
1067 if (!dns_packet_copy(buf,len,pos,misc,16)) goto DIE;
1068 flagns = cns_addns(z,misc,flaghaskey,pubkey);
1069 if (flagns) log_servflag(addr,flagns);
1070 }
1071 }
1072 pos += datalen;
1073 }
1074 goto LOWERLEVEL;
1075 }
1076
1077 if (!rqa(z)) goto DIE;
1078
1079 pos = posanswers;
1080 for (j = 0; j < numanswers; ++j) {
1081 pos = dns_packet_getname(buf,len,pos,&t1); if (!pos) goto DIE;
1082 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
1083 ttl = ttlget(header + 4);
1084 uint16_unpack_big(header + 8,&datalen);
1085 if (dns_domain_equal(t1,d))
1086 if (byte_equal(header + 2,2,DNS_C_IN)) /* should always be true */
1087 if (typematch(header,dtype)) {
1088 if (!response_rstart(t1,header,ttl)) goto DIE;
1089
1090 if (typematch(header,DNS_T_NS) || typematch(header,DNS_T_CNAME) || typematch(header,DNS_T_PTR)) {
1091 if (!dns_packet_getname(buf,len,pos,&t2)) goto DIE;
1092 if (!response_addname(t2)) goto DIE;
1093 }
1094 else if (typematch(header,DNS_T_MX)) {
1095 pos2 = dns_packet_copy(buf,len,pos,misc,2); if (!pos2) goto DIE;
1096 if (!response_addbytes(misc,2)) goto DIE;
1097 if (!dns_packet_getname(buf,len,pos2,&t2)) goto DIE;
1098 if (!response_addname(t2)) goto DIE;
1099 }
1100 else if (typematch(header,DNS_T_SOA)) {
1101 pos2 = dns_packet_getname(buf,len,pos,&t2); if (!pos2) goto DIE;
1102 if (!response_addname(t2)) goto DIE;
1103 pos2 = dns_packet_getname(buf,len,pos2,&t3); if (!pos2) goto DIE;
1104 if (!response_addname(t3)) goto DIE;
1105 pos2 = dns_packet_copy(buf,len,pos2,misc,20); if (!pos2) goto DIE;
1106 if (!response_addbytes(misc,20)) goto DIE;
1107 }
1108 else {
1109 if (pos + datalen > len) goto DIE;
1110 if (!response_addbytes(buf + pos,datalen)) goto DIE;
1111 }
1112
1114 }
1115 pos += datalen;
1116 }
1117
1118 cleanup(z);
1119 return 1;
1120 }
1121
1122
1123 if (!dns_domain_suffix(d,referral)) goto DIE;
1124
1125 /* In strict "forwardonly" mode, we don't, as the manual states,
1126 ** contact a chain of servers according to "NS" resource records.
1127 ** We don't obey any referral responses, therefore. Instead, we
1128 ** eliminate the server from the list and try the next one. */
1129
1130 if (flagforwardonly) {
1131 log_ignore_referral(whichserver,control,referral);
1132 byte_zero((char *)whichserver,16);
1133 goto HAVENS;
1134 }
1135
1136 control = d + dns_domain_suffixpos(d,referral);
1137 z->control[z->level] = control;
1138 z->byzg = numauthority*100 + numglue;
1139 z->flagnskeys[z->level] = 0; /* XXX */
1140 byte_zero(z->servers[z->level],QUERY_MAXIPLEN);
1141 for (j = 0; j < QUERY_MAXNS; ++j)
1142 dns_domain_free(&z->ns[z->level][j]);
1143 k = 0;
1144
1145 pos = posauthority;
1146 for (j = 0; j < numauthority; ++j) {
1147 pos = dns_packet_getname(buf,len,pos,&t1); if (!pos) goto DIE;
1148 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) goto DIE;
1149 uint16_unpack_big(header + 8,&datalen);
1150 if (dns_domain_equal(referral,t1)) /* should always be true */
1151 if (typematch(header,DNS_T_NS)) /* should always be true */
1152 if (byte_equal(header + 2,2,DNS_C_IN)) /* should always be true */
1153 if (k < QUERY_MAXNS)
1154 if (!dns_packet_getname(buf,len,pos,&z->ns[z->level][k++])) goto DIE;
1155 pos += datalen;
1156 }
1157
1158 goto HAVENS;
1159
1160
1161 SERVFAIL:
1162 if (z->level) goto LOWERLEVEL;
1163 if (!rqa(z)) goto DIE;
1165 cleanup(z);
1166 return 1;
1167
1168
1169 DIE:
1170 cleanup(z);
1171 if (records) { alloc_free(records); records = 0; }
1172 return DNS_ERR;
1173}
1174
1175int query_start(struct query *z,char *dn,char type[2],char class[2],char localip[16],uint32 scope_id)
1176{
1177 if (byte_equal(type,2,DNS_T_AXFR)) { errno = EPERM; return DNS_ERR; }
1178
1179 cleanup(z);
1180 z->level = 0;
1181 z->loop = 0;
1182
1183 if (!dns_domain_copy(&z->name[0],dn)) return DNS_ERR;
1184 byte_copy(z->type,2,type);
1185 byte_copy(z->class,2,class);
1186 byte_copy(z->localip,16,localip);
1187 z->scope_id = scope_id;
1188 z->ipv6[0] = 0;
1189
1190 return doit(z,0);
1191}
1192
1193int query_get(struct query *z,iopause_fd *x,struct taia *stamp)
1194{
1195 switch (dns_transmit_get(&z->dt,x,stamp)) {
1196 case 1:
1197 return doit(z,1);
1198 case -1: case -2: case -3:
1199 return doit(z,-1);
1200 }
1201 return 0;
1202}
1203
1204void query_io(struct query *z,iopause_fd *x,struct taia *deadline)
1205{
1206 dns_transmit_io(&z->dt,x,deadline);
1207}
unsigned int doit(char *buf, unsigned int len, unsigned int pos)
Definition: axfr-get.c:131
char data[32767]
Definition: axfrdns.c:130
char ip[16]
Definition: axfrdns.c:125
uint16 len
Definition: axfrdns.c:319
char buf[MSGSIZE]
Definition: axfrdns.c:318
uint32 dlen
Definition: axfrdns.c:131
#define crypto_box_beforenm
Definition: curve.h:12
#define crypto_scalarmult_base
Definition: curve.h:10
int cns_transmit_start(struct dns_transmit *d, const char servers[QUERY_MAXIPLEN], int flagrecursive, const char *q, const char qtype[2], const char localip[16], const char keys[1024], const char pubkey[32], const char *suffix)
Definition: curvedns.c:261
void cns_sortns(char *s, char *t, unsigned int n)
Definition: curvedns.c:207
int cns_pubkey(const char *dn, char *key)
Definition: curvedns.c:193
int cns_addns(struct query *z, const char *addr, int flagnskey, const char *key)
Definition: curvedns.c:227
int dd4(const char *q, const char *base, char ip[4])
Definition: dd.c:7
#define DNS_ERR
Definition: dns.h:34
#define DNS_T_A
Definition: dns.h:56
#define QUERY_MAXIPLEN
Definition: dns.h:47
#define DNS_T_AXFR
Definition: dns.h:86
#define DNS_C_IN
Definition: dns.h:53
#define DNS_T_ANY
Definition: dns.h:87
#define MAX_TTL
Definition: dns.h:44
#define DNS_T_PTR
Definition: dns.h:60
#define DNS_T_SOA
Definition: dns.h:59
#define DNS_T_NS
Definition: dns.h:57
#define QUERY_MAXNS
Definition: dns.h:46
#define DNS_T_CNAME
Definition: dns.h:58
#define DNS_T_AAAA
Definition: dns.h:67
#define DNS_T_MX
Definition: dns.h:62
int dns_domain_equal(const char *dn1, const char *dn2)
Definition: dns_domain.c:39
unsigned int dns_domain_length(const char *dn)
Definition: dns_domain.c:6
int dns_domain_copy(char **out, const char *in)
Definition: dns_domain.c:25
int dns_domain_suffix(const char *big, const char *little)
Definition: dns_domain.c:50
void dns_domain_free(char **out)
Definition: dns_domain.c:17
unsigned int dns_domain_suffixpos(const char *big, const char *little)
Definition: dns_domain.c:62
unsigned int dns_packet_getname(const char *buf, unsigned int len, unsigned int pos, char **d)
Definition: dns_packet.c:35
unsigned int dns_packet_copy(const char *buf, unsigned int len, unsigned int pos, char *out, unsigned int outlen)
Definition: dns_packet.c:8
unsigned int dns_packet_skipname(const char *buf, unsigned int len, unsigned int pos)
Definition: dns_packet.c:18
unsigned int dns_random(unsigned int n)
Definition: dns_random.c:56
void dns_transmit_io(struct dns_transmit *d, iopause_fd *x, struct taia *deadline)
Definition: dns_transmit.c:279
void dns_transmit_free(struct dns_transmit *d)
Definition: dns_transmit.c:95
int dns_transmit_get(struct dns_transmit *d, const iopause_fd *x, const struct taia *when)
Definition: dns_transmit.c:296
char * p
Definition: dnscache.c:37
struct line * x
char type[2]
Definition: dnsq.c:56
void d(const char *home, const char *subdir, int uid, int gid, int mode)
void z(char *home, char *subdir, char *file, int len, int uid, int gid, int mode)
Definition: install.c:88
void log_rrptr(const char[16], const char *, const char *, unsigned int)
Definition: log.c:278
void log_rr(const char[16], const char *, const char[2], const char *, unsigned int, unsigned int)
Definition: log.c:246
void log_lame(const char[16], const char *, const char *)
Definition: log.c:220
void log_tx(const char *, const char[2], const char *, const char[QUERY_MAXIPLEN], int, unsigned int)
Definition: log.c:159
void log_rrmx(const char[16], const char *, const char *, const char[2], unsigned int)
Definition: log.c:286
void log_ignore_referral(const char[16], const char *, const char *)
Definition: log.c:136
void log_servfail(const char *)
Definition: log.c:237
void log_servflag(const char[16], int)
Definition: log.c:227
void log_nxdomain(const char[16], const char *, unsigned int)
Definition: log.c:206
void log_nodata(const char[16], const char *, const char[2], unsigned int)
Definition: log.c:213
void log_stats(void)
Definition: log.c:312
void log_rrns(const char[16], const char *, const char *, unsigned int)
Definition: log.c:263
void log_cachedcname(const char *, const char *)
Definition: log.c:188
void log_cachedanswer(const char *, const char[2])
Definition: log.c:181
void log_rrsoa(const char[16], const char *, const char *, const char *, const char[20], unsigned int)
Definition: log.c:297
void log_cachednxdomain(const char *)
Definition: log.c:200
void log_cachedns(const char *, const char *)
Definition: log.c:194
void log_rrcname(const char[16], const char *, const char *, unsigned int)
Definition: log.c:270
#define LABLEN
Definition: query.c:16
void query_init(void)
Definition: query.c:23
void query_io(struct query *z, iopause_fd *x, struct taia *deadline)
Definition: query.c:1204
int query_get(struct query *z, iopause_fd *x, struct taia *stamp)
Definition: query.c:1193
int flagusetxtformat
Definition: dnscache.c:34
void query_forwardonly(void)
Definition: query.c:36
int query_start(struct query *z, char *dn, char type[2], char class[2], char localip[16], uint32 scope_id)
Definition: query.c:1175
#define QUERY_MAXALIAS
Definition: query.h:10
#define IP6_LOOPBACK_OCTAL
Definition: query.h:29
#define IP6_ALLROUTERS_OCTAL
Definition: query.h:37
#define IP6_MULTICASTPFX_OCTAL
Definition: query.h:33
#define IP6_MULTICAST_ARPA
Definition: query.h:22
#define QUERY_MAXLEVEL
Definition: query.h:9
#define IP6_ALLNODESMULTICAST_ARPA
Definition: query.h:24
#define QUERY_MAXLOOP
Definition: query.h:11
#define IP4_LOOPBACK_ARPA
Definition: query.h:45
#define IP4_LOCALHOST_ARPA
Definition: query.h:43
#define IP6_LOCALHOST_ARPA
Definition: query.h:57
#define IP6_LOOPBACK_ARPA
Definition: query.h:18
#define IP6_LOCALNET
Definition: query.h:55
#define IP4_LOOPBACK_OCTAL
Definition: query.h:48
#define IP6_ALLROUTERSMULTICAST_ARPA
Definition: query.h:26
#define IP6_LOCALNET_ARPA
Definition: query.h:20
#define IP4_LOCALNET
Definition: query.h:54
#define IP6_ALLNODES_OCTAL
Definition: query.h:35
int response_rstart(const char *, const char[2], uint32)
Definition: response.c:75
int response_addname(const char *)
Definition: response.c:25
void response_rfinish(int)
Definition: response.c:89
int response_addbytes(const char *, unsigned int)
Definition: response.c:17
int response_cname(const char *, const char *, uint32)
Definition: response.c:95
int response_query(const char *, const char[2], const char[2])
Definition: response.c:54
#define RESPONSE_ANSWER
Definition: response.h:23
void response_nxdomain(void)
Definition: response.c:103
void response_servfail(void)
Definition: response.c:109
int roots(char[QUERY_MAXIPLEN], char *)
Definition: roots.c:48
int roots_same(char *, char *)
Definition: roots.c:57
char * cache_get(const char *, unsigned int, unsigned int *, uint32 *)
Definition: sipcache.c:73
void cache_set(const char *, unsigned int, const char *, unsigned int, uint32)
Definition: sipcache.c:119
Definition: query.h:59