30 |
|
#include "ircd.h" |
31 |
|
#include "numeric.h" |
32 |
|
#include "restart.h" |
33 |
+ |
#include "rng_mt.h" |
34 |
|
#include "fdlist.h" |
35 |
|
#include "fileio.h" /* for fbopen / fbclose / fbputs */ |
36 |
|
#include "s_bsd.h" |
70 |
|
#ifdef IPV6 |
71 |
|
REQ_AAAA, /* Looking up an AAAA */ |
72 |
|
#endif |
73 |
< |
REQ_CNAME, /* We got a CNAME in response, we better get a real answer next */ |
73 |
< |
REQ_INT /* ip6.arpa failed, falling back to ip6.int */ |
73 |
> |
REQ_CNAME /* We got a CNAME in response, we better get a real answer next */ |
74 |
|
} request_state; |
75 |
|
|
76 |
|
struct reslist |
92 |
|
}; |
93 |
|
|
94 |
|
static fde_t ResolverFileDescriptor; |
95 |
< |
static dlink_list request_list = { NULL, NULL, 0 }; |
95 |
> |
static dlink_list request_list = { NULL, NULL, 0 }; |
96 |
|
|
97 |
|
static void rem_request(struct reslist *request); |
98 |
|
static struct reslist *make_request(struct DNSQuery *query); |
136 |
|
struct sockaddr_in *v4in = (struct sockaddr_in *)inp; |
137 |
|
int ns; |
138 |
|
|
139 |
< |
for (ns = 0; ns < irc_nscount; ns++) |
139 |
> |
for (ns = 0; ns < irc_nscount; ns++) |
140 |
|
{ |
141 |
|
const struct irc_ssaddr *srv = &irc_nsaddr_list[ns]; |
142 |
|
#ifdef IPV6 |
256 |
|
void |
257 |
|
init_resolver(void) |
258 |
|
{ |
259 |
– |
#ifdef HAVE_SRAND48 |
260 |
– |
srand48(CurrentTime); |
261 |
– |
#endif |
259 |
|
memset(&ResolverFileDescriptor, 0, sizeof(fde_t)); |
260 |
|
start_resolver(); |
261 |
|
} |
443 |
|
{ |
444 |
|
char host_name[HOSTLEN + 1]; |
445 |
|
|
446 |
< |
strlcpy(host_name, name, HOSTLEN); |
447 |
< |
add_local_domain(host_name, HOSTLEN); |
446 |
> |
strlcpy(host_name, name, HOSTLEN + 1); |
447 |
> |
add_local_domain(host_name, HOSTLEN + 1); |
448 |
|
|
449 |
|
if (request == NULL) |
450 |
|
{ |
451 |
|
request = make_request(query); |
452 |
< |
request->name = (char *)MyMalloc(strlen(host_name) + 1); |
452 |
> |
request->name = MyMalloc(strlen(host_name) + 1); |
453 |
|
request->type = type; |
454 |
|
strcpy(request->name, host_name); |
455 |
|
#ifdef IPV6 |
456 |
< |
if (type == T_A) |
460 |
< |
request->state = REQ_A; |
461 |
< |
else |
456 |
> |
if (type != T_A) |
457 |
|
request->state = REQ_AAAA; |
458 |
< |
#else |
464 |
< |
request->state = REQ_A; |
458 |
> |
else |
459 |
|
#endif |
460 |
+ |
request->state = REQ_A; |
461 |
|
} |
462 |
|
|
463 |
|
request->type = type; |
473 |
|
{ |
474 |
|
char ipbuf[128]; |
475 |
|
const unsigned char *cp; |
476 |
< |
#ifdef IPV6 |
482 |
< |
const char *intarpa; |
483 |
< |
#endif |
476 |
> |
|
477 |
|
if (addr->ss.ss_family == AF_INET) |
478 |
|
{ |
479 |
|
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
489 |
|
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
490 |
|
cp = (const unsigned char *)&v6->sin6_addr.s6_addr; |
491 |
|
|
492 |
< |
if (request != NULL && request->state == REQ_INT) |
493 |
< |
intarpa = "int"; |
501 |
< |
else |
502 |
< |
intarpa = "arpa"; |
503 |
< |
|
504 |
< |
(void)sprintf(ipbuf, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." |
505 |
< |
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.%s.", |
492 |
> |
sprintf(ipbuf, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." |
493 |
> |
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa.", |
494 |
|
(unsigned int)(cp[15]&0xf), (unsigned int)(cp[15]>>4), |
495 |
|
(unsigned int)(cp[14]&0xf), (unsigned int)(cp[14]>>4), |
496 |
|
(unsigned int)(cp[13]&0xf), (unsigned int)(cp[13]>>4), |
506 |
|
(unsigned int)(cp[3]&0xf), (unsigned int)(cp[3]>>4), |
507 |
|
(unsigned int)(cp[2]&0xf), (unsigned int)(cp[2]>>4), |
508 |
|
(unsigned int)(cp[1]&0xf), (unsigned int)(cp[1]>>4), |
509 |
< |
(unsigned int)(cp[0]&0xf), (unsigned int)(cp[0]>>4), intarpa); |
509 |
> |
(unsigned int)(cp[0]&0xf), (unsigned int)(cp[0]>>4)); |
510 |
|
} |
511 |
|
#endif |
512 |
|
if (request == NULL) |
514 |
|
request = make_request(query); |
515 |
|
request->type = T_PTR; |
516 |
|
memcpy(&request->addr, addr, sizeof(struct irc_ssaddr)); |
517 |
< |
request->name = (char *)MyMalloc(HOSTLEN + 1); |
517 |
> |
request->name = MyMalloc(HOSTLEN + 1); |
518 |
|
} |
519 |
|
|
520 |
|
query_name(ipbuf, C_IN, T_PTR, request); |
536 |
|
(unsigned char *)buf, sizeof(buf))) > 0) |
537 |
|
{ |
538 |
|
HEADER *header = (HEADER *)buf; |
539 |
< |
#ifndef HAVE_LRAND48 |
552 |
< |
int k = 0; |
553 |
< |
struct timeval tv; |
554 |
< |
#endif |
539 |
> |
|
540 |
|
/* |
541 |
|
* generate an unique id |
542 |
|
* NOTE: we don't have to worry about converting this to and from |
543 |
|
* network byte order, the nameserver does not interpret this value |
544 |
|
* and returns it unchanged |
545 |
|
*/ |
561 |
– |
#ifdef HAVE_LRAND48 |
562 |
– |
do |
563 |
– |
{ |
564 |
– |
header->id = (header->id + lrand48()) & 0xffff; |
565 |
– |
} while (find_id(header->id)); |
566 |
– |
#else |
567 |
– |
gettimeofday(&tv, NULL); |
546 |
|
do |
547 |
< |
{ |
548 |
< |
header->id = (header->id + k + tv.tv_usec) & 0xffff; |
549 |
< |
k++; |
572 |
< |
} while (find_id(header->id)); |
573 |
< |
#endif /* HAVE_LRAND48 */ |
547 |
> |
header->id = (header->id + genrand_int32()) & 0xffff; |
548 |
> |
while (find_id(header->id)); |
549 |
> |
|
550 |
|
request->id = header->id; |
551 |
|
++request->sends; |
552 |
|
|
560 |
|
if (request->resend == 0) |
561 |
|
return; |
562 |
|
|
563 |
< |
switch(request->type) |
563 |
> |
switch (request->type) |
564 |
|
{ |
565 |
|
case T_PTR: |
566 |
|
do_query_number(NULL, &request->addr, request); |
696 |
|
else if (n == 0) |
697 |
|
return(0); /* no more answers left */ |
698 |
|
|
699 |
< |
strlcpy(request->name, hostbuf, HOSTLEN); |
699 |
> |
strlcpy(request->name, hostbuf, HOSTLEN + 1); |
700 |
|
|
701 |
|
return(1); |
702 |
|
break; |
761 |
|
* interest where it'll instantly be ready for read :-) -- adrian |
762 |
|
*/ |
763 |
|
comm_setselect(fd, COMM_SELECT_READ, res_readreply, NULL, 0); |
764 |
+ |
|
765 |
|
/* Better to cast the sizeof instead of rc */ |
766 |
|
if (rc <= (int)(sizeof(HEADER))) |
767 |
|
return; |
790 |
|
|
791 |
|
if ((header->rcode != NO_ERRORS) || (header->ancount == 0)) |
792 |
|
{ |
793 |
< |
if (SERVFAIL == header->rcode) |
793 |
> |
if (header->rcode == SERVFAIL || header->rcode == NXDOMAIN) |
794 |
|
{ |
795 |
|
/* |
796 |
< |
* If a bad error was returned, we stop here and dont send |
796 |
> |
* If a bad error was returned, stop here and don't |
797 |
|
* send any more (no retries granted). |
798 |
|
*/ |
799 |
|
(*request->query->callback)(request->query->ptr, NULL); |
800 |
|
rem_request(request); |
801 |
< |
} |
801 |
> |
} |
802 |
> |
#ifdef IPV6 |
803 |
|
else |
804 |
|
{ |
805 |
|
/* |
806 |
|
* If we havent already tried this, and we're looking up AAAA, try A |
807 |
|
* now |
808 |
|
*/ |
831 |
– |
|
832 |
– |
#ifdef IPV6 |
809 |
|
if (request->state == REQ_AAAA && request->type == T_AAAA) |
810 |
|
{ |
811 |
|
request->timeout += 4; |
812 |
|
resend_query(request); |
813 |
|
} |
838 |
– |
else if (request->type == T_PTR && request->state != REQ_INT && |
839 |
– |
request->addr.ss.ss_family == AF_INET6) |
840 |
– |
{ |
841 |
– |
request->state = REQ_INT; |
842 |
– |
request->timeout += 4; |
843 |
– |
request->retries--; |
844 |
– |
resend_query(request); |
845 |
– |
} |
846 |
– |
#endif |
814 |
|
} |
815 |
+ |
#endif |
816 |
|
|
817 |
|
return; |
818 |
|
} |
819 |
+ |
|
820 |
|
/* |
821 |
|
* If this fails there was an error decoding the received packet, |
822 |
|
* try it again and hope it works the next time. |