20 |
|
*/ |
21 |
|
|
22 |
|
#include "stdinc.h" |
23 |
– |
#include "tools.h" |
24 |
– |
#include "client.h" |
23 |
|
#include "list.h" |
24 |
< |
#include "common.h" |
24 |
> |
#include "balloc.h" |
25 |
> |
#include "client.h" |
26 |
|
#include "event.h" |
27 |
|
#include "irc_string.h" |
28 |
|
#include "sprintf_irc.h" |
29 |
|
#include "ircd.h" |
30 |
|
#include "numeric.h" |
31 |
< |
#include "restart.h" |
31 |
> |
#include "rng_mt.h" |
32 |
|
#include "fdlist.h" |
33 |
|
#include "fileio.h" /* for fbopen / fbclose / fbputs */ |
34 |
|
#include "s_bsd.h" |
38 |
|
#include "irc_res.h" |
39 |
|
#include "irc_reslib.h" |
40 |
|
#include "irc_getnameinfo.h" |
41 |
+ |
#include "common.h" |
42 |
|
|
43 |
|
#if (CHAR_BIT != 8) |
44 |
|
#error this code needs to be able to address individual octets |
69 |
|
#ifdef IPV6 |
70 |
|
REQ_AAAA, /* Looking up an AAAA */ |
71 |
|
#endif |
72 |
< |
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 */ |
72 |
> |
REQ_CNAME /* We got a CNAME in response, we better get a real answer next */ |
73 |
|
} request_state; |
74 |
|
|
75 |
|
struct reslist |
87 |
|
time_t timeout; |
88 |
|
struct irc_ssaddr addr; |
89 |
|
char *name; |
90 |
< |
struct DNSQuery *query; /* query callback for this request */ |
90 |
> |
dns_callback_fnc callback; |
91 |
> |
void *callback_ctx; |
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 |
> |
static BlockHeap *dns_heap = NULL; |
97 |
|
|
98 |
|
static void rem_request(struct reslist *request); |
99 |
< |
static struct reslist *make_request(struct DNSQuery *query); |
100 |
< |
static void do_query_name(struct DNSQuery *query, |
101 |
< |
const char* name, struct reslist *request, int); |
102 |
< |
static void do_query_number(struct DNSQuery *query, |
99 |
> |
static struct reslist *make_request(dns_callback_fnc callback, void *); |
100 |
> |
static void do_query_name(dns_callback_fnc callback, void *, |
101 |
> |
const char *, struct reslist *, int); |
102 |
> |
static void do_query_number(dns_callback_fnc callback, void *ctx, |
103 |
|
const struct irc_ssaddr *, |
104 |
|
struct reslist *request); |
105 |
|
static void query_name(const char *name, int query_class, int query_type, |
108 |
|
static void resend_query(struct reslist *request); |
109 |
|
static int proc_answer(struct reslist *request, HEADER *header, char *, char *); |
110 |
|
static struct reslist *find_id(int id); |
110 |
– |
static struct DNSReply *make_dnsreply(struct reslist *request); |
111 |
– |
|
112 |
– |
extern struct irc_ssaddr irc_nsaddr_list[IRCD_MAXNS]; |
113 |
– |
extern int irc_nscount; |
114 |
– |
extern char irc_domain[HOSTLEN+1]; |
111 |
|
|
112 |
|
|
113 |
|
/* |
125 |
|
res_ourserver(const struct irc_ssaddr *inp) |
126 |
|
{ |
127 |
|
#ifdef IPV6 |
128 |
< |
struct sockaddr_in6 *v6; |
129 |
< |
struct sockaddr_in6 *v6in = (struct sockaddr_in6 *)inp; |
128 |
> |
const struct sockaddr_in6 *v6; |
129 |
> |
const struct sockaddr_in6 *v6in = (const struct sockaddr_in6 *)inp; |
130 |
|
#endif |
131 |
< |
struct sockaddr_in *v4; |
132 |
< |
struct sockaddr_in *v4in = (struct sockaddr_in *)inp; |
131 |
> |
const struct sockaddr_in *v4; |
132 |
> |
const struct sockaddr_in *v4in = (const struct sockaddr_in *)inp; |
133 |
|
int ns; |
134 |
|
|
135 |
< |
for (ns = 0; ns < irc_nscount; ns++) |
135 |
> |
for (ns = 0; ns < irc_nscount; ns++) |
136 |
|
{ |
137 |
|
const struct irc_ssaddr *srv = &irc_nsaddr_list[ns]; |
138 |
|
#ifdef IPV6 |
139 |
< |
v6 = (struct sockaddr_in6 *)srv; |
139 |
> |
v6 = (const struct sockaddr_in6 *)srv; |
140 |
|
#endif |
141 |
< |
v4 = (struct sockaddr_in *)srv; |
141 |
> |
v4 = (const struct sockaddr_in *)srv; |
142 |
|
|
143 |
|
/* could probably just memcmp(srv, inp, srv.ss_len) here |
144 |
|
* but we'll air on the side of caution - stu |
194 |
|
{ |
195 |
|
if (--request->retries <= 0) |
196 |
|
{ |
197 |
< |
(*request->query->callback)(request->query->ptr, NULL); |
197 |
> |
(*request->callback)(request->callback_ctx, NULL, NULL); |
198 |
|
rem_request(request); |
199 |
|
continue; |
200 |
|
} |
252 |
|
void |
253 |
|
init_resolver(void) |
254 |
|
{ |
255 |
< |
#ifdef HAVE_SRAND48 |
260 |
< |
srand48(CurrentTime); |
261 |
< |
#endif |
255 |
> |
dns_heap = BlockHeapCreate("dns", sizeof(struct reslist), DNS_HEAP_SIZE); |
256 |
|
memset(&ResolverFileDescriptor, 0, sizeof(fde_t)); |
257 |
|
start_resolver(); |
258 |
|
} |
269 |
|
} |
270 |
|
|
271 |
|
/* |
278 |
– |
* add_local_domain - Add the domain to hostname, if it is missing |
279 |
– |
* (as suggested by eps@TOASTER.SFSU.EDU) |
280 |
– |
*/ |
281 |
– |
void |
282 |
– |
add_local_domain(char *hname, size_t size) |
283 |
– |
{ |
284 |
– |
/* try to fix up unqualified names |
285 |
– |
*/ |
286 |
– |
if (strchr(hname, '.') == NULL) |
287 |
– |
{ |
288 |
– |
if (irc_domain[0]) |
289 |
– |
{ |
290 |
– |
size_t len = strlen(hname); |
291 |
– |
|
292 |
– |
if ((strlen(irc_domain) + len + 2) < size) |
293 |
– |
{ |
294 |
– |
hname[len++] = '.'; |
295 |
– |
strcpy(hname + len, irc_domain); |
296 |
– |
} |
297 |
– |
} |
298 |
– |
} |
299 |
– |
} |
300 |
– |
|
301 |
– |
/* |
272 |
|
* rem_request - remove a request from the list. |
273 |
|
* This must also free any memory that has been allocated for |
274 |
|
* temporary storage of DNS results. |
277 |
|
rem_request(struct reslist *request) |
278 |
|
{ |
279 |
|
dlinkDelete(&request->node, &request_list); |
280 |
+ |
|
281 |
|
MyFree(request->name); |
282 |
< |
MyFree(request); |
282 |
> |
BlockHeapFree(dns_heap, request); |
283 |
|
} |
284 |
|
|
285 |
|
/* |
286 |
|
* make_request - Create a DNS request record for the server. |
287 |
|
*/ |
288 |
|
static struct reslist * |
289 |
< |
make_request(struct DNSQuery* query) |
289 |
> |
make_request(dns_callback_fnc callback, void *ctx) |
290 |
|
{ |
291 |
< |
struct reslist *request; |
321 |
< |
|
322 |
< |
request = (struct reslist *)MyMalloc(sizeof(struct reslist)); |
323 |
< |
memset(request, 0, sizeof(struct reslist)); |
291 |
> |
struct reslist *request = BlockHeapAlloc(dns_heap); |
292 |
|
|
293 |
< |
request->sentat = CurrentTime; |
294 |
< |
request->retries = 3; |
295 |
< |
request->resend = 1; |
296 |
< |
request->timeout = 4; /* start at 4 and exponential inc. */ |
297 |
< |
memset(&request->addr, 0, sizeof(request->addr)); |
298 |
< |
request->query = query; |
299 |
< |
request->state = REQ_IDLE; |
293 |
> |
request->sentat = CurrentTime; |
294 |
> |
request->retries = 3; |
295 |
> |
request->resend = 1; |
296 |
> |
request->timeout = 4; /* start at 4 and exponential inc. */ |
297 |
> |
request->state = REQ_IDLE; |
298 |
> |
request->callback = callback; |
299 |
> |
request->callback_ctx = ctx; |
300 |
|
|
301 |
|
dlinkAdd(request, &request->node, &request_list); |
302 |
< |
return(request); |
302 |
> |
return request; |
303 |
|
} |
304 |
|
|
305 |
|
/* |
307 |
|
* for which there no longer exist clients or conf lines. |
308 |
|
*/ |
309 |
|
void |
310 |
< |
delete_resolver_queries(const struct DNSQuery *query) |
310 |
> |
delete_resolver_queries(const void *vptr) |
311 |
|
{ |
312 |
< |
dlink_node *ptr; |
345 |
< |
dlink_node *next_ptr; |
346 |
< |
struct reslist *request; |
312 |
> |
dlink_node *ptr = NULL, *next_ptr = NULL; |
313 |
|
|
314 |
|
DLINK_FOREACH_SAFE(ptr, next_ptr, request_list.head) |
315 |
|
{ |
316 |
< |
if ((request = ptr->data) != NULL) |
317 |
< |
{ |
318 |
< |
if (query == request->query) |
319 |
< |
rem_request(request); |
354 |
< |
} |
316 |
> |
struct reslist *request = ptr->data; |
317 |
> |
|
318 |
> |
if (request->callback_ctx == vptr) |
319 |
> |
rem_request(request); |
320 |
|
} |
321 |
|
} |
322 |
|
|
376 |
|
* |
377 |
|
*/ |
378 |
|
void |
379 |
< |
gethost_byname_type(const char *name, struct DNSQuery *query, int type) |
379 |
> |
gethost_byname_type(dns_callback_fnc callback, void *ctx, const char *name, int type) |
380 |
|
{ |
381 |
|
assert(name != 0); |
382 |
< |
do_query_name(query, name, NULL, type); |
382 |
> |
do_query_name(callback, ctx, name, NULL, type); |
383 |
|
} |
384 |
|
|
385 |
|
/* |
386 |
|
* gethost_byname - wrapper for _type - send T_AAAA first if IPV6 supported |
387 |
|
*/ |
388 |
|
void |
389 |
< |
gethost_byname(const char *name, struct DNSQuery *query) |
389 |
> |
gethost_byname(dns_callback_fnc callback, void *ctx, const char *name) |
390 |
|
{ |
391 |
|
#ifdef IPV6 |
392 |
< |
gethost_byname_type(name, query, T_AAAA); |
392 |
> |
gethost_byname_type(callback, ctx, name, T_AAAA); |
393 |
|
#else |
394 |
< |
gethost_byname_type(name, query, T_A); |
394 |
> |
gethost_byname_type(callback, ctx, name, T_A); |
395 |
|
#endif |
396 |
|
} |
397 |
|
|
399 |
|
* gethost_byaddr - get host name from address |
400 |
|
*/ |
401 |
|
void |
402 |
< |
gethost_byaddr(const struct irc_ssaddr *addr, struct DNSQuery *query) |
402 |
> |
gethost_byaddr(dns_callback_fnc callback, void *ctx, const struct irc_ssaddr *addr) |
403 |
|
{ |
404 |
< |
do_query_number(query, addr, NULL); |
404 |
> |
do_query_number(callback, ctx, addr, NULL); |
405 |
|
} |
406 |
|
|
407 |
|
/* |
408 |
|
* do_query_name - nameserver lookup name |
409 |
|
*/ |
410 |
|
static void |
411 |
< |
do_query_name(struct DNSQuery *query, const char *name, |
411 |
> |
do_query_name(dns_callback_fnc callback, void *ctx, const char *name, |
412 |
|
struct reslist *request, int type) |
413 |
|
{ |
414 |
|
char host_name[HOSTLEN + 1]; |
415 |
|
|
416 |
< |
strlcpy(host_name, name, HOSTLEN); |
452 |
< |
add_local_domain(host_name, HOSTLEN); |
416 |
> |
strlcpy(host_name, name, sizeof(host_name)); |
417 |
|
|
418 |
|
if (request == NULL) |
419 |
|
{ |
420 |
< |
request = make_request(query); |
421 |
< |
request->name = (char *)MyMalloc(strlen(host_name) + 1); |
420 |
> |
request = make_request(callback, ctx); |
421 |
> |
request->name = MyMalloc(strlen(host_name) + 1); |
422 |
|
request->type = type; |
423 |
|
strcpy(request->name, host_name); |
424 |
|
#ifdef IPV6 |
425 |
< |
if (type == T_A) |
462 |
< |
request->state = REQ_A; |
463 |
< |
else |
425 |
> |
if (type != T_A) |
426 |
|
request->state = REQ_AAAA; |
427 |
< |
#else |
466 |
< |
request->state = REQ_A; |
427 |
> |
else |
428 |
|
#endif |
429 |
+ |
request->state = REQ_A; |
430 |
|
} |
431 |
|
|
432 |
|
request->type = type; |
437 |
|
* do_query_number - Use this to do reverse IP# lookups. |
438 |
|
*/ |
439 |
|
static void |
440 |
< |
do_query_number(struct DNSQuery *query, const struct irc_ssaddr *addr, |
440 |
> |
do_query_number(dns_callback_fnc callback, void *ctx, |
441 |
> |
const struct irc_ssaddr *addr, |
442 |
|
struct reslist *request) |
443 |
|
{ |
444 |
|
char ipbuf[128]; |
445 |
|
const unsigned char *cp; |
446 |
< |
#ifdef IPV6 |
484 |
< |
const char *intarpa; |
485 |
< |
#endif |
446 |
> |
|
447 |
|
if (addr->ss.ss_family == AF_INET) |
448 |
|
{ |
449 |
< |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
449 |
> |
const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr; |
450 |
|
cp = (const unsigned char*)&v4->sin_addr.s_addr; |
451 |
|
|
452 |
|
ircsprintf(ipbuf, "%u.%u.%u.%u.in-addr.arpa.", |
456 |
|
#ifdef IPV6 |
457 |
|
else if (addr->ss.ss_family == AF_INET6) |
458 |
|
{ |
459 |
< |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
459 |
> |
const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr; |
460 |
|
cp = (const unsigned char *)&v6->sin6_addr.s6_addr; |
461 |
|
|
462 |
< |
if (request != NULL && request->state == REQ_INT) |
463 |
< |
intarpa = "int"; |
503 |
< |
else |
504 |
< |
intarpa = "arpa"; |
505 |
< |
|
506 |
< |
(void)sprintf(ipbuf, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." |
507 |
< |
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.%s.", |
462 |
> |
sprintf(ipbuf, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x." |
463 |
> |
"%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa.", |
464 |
|
(unsigned int)(cp[15]&0xf), (unsigned int)(cp[15]>>4), |
465 |
|
(unsigned int)(cp[14]&0xf), (unsigned int)(cp[14]>>4), |
466 |
|
(unsigned int)(cp[13]&0xf), (unsigned int)(cp[13]>>4), |
476 |
|
(unsigned int)(cp[3]&0xf), (unsigned int)(cp[3]>>4), |
477 |
|
(unsigned int)(cp[2]&0xf), (unsigned int)(cp[2]>>4), |
478 |
|
(unsigned int)(cp[1]&0xf), (unsigned int)(cp[1]>>4), |
479 |
< |
(unsigned int)(cp[0]&0xf), (unsigned int)(cp[0]>>4), intarpa); |
479 |
> |
(unsigned int)(cp[0]&0xf), (unsigned int)(cp[0]>>4)); |
480 |
|
} |
481 |
|
#endif |
482 |
|
if (request == NULL) |
483 |
|
{ |
484 |
< |
request = make_request(query); |
484 |
> |
request = make_request(callback, ctx); |
485 |
|
request->type = T_PTR; |
486 |
|
memcpy(&request->addr, addr, sizeof(struct irc_ssaddr)); |
487 |
< |
request->name = (char *)MyMalloc(HOSTLEN + 1); |
487 |
> |
request->name = MyMalloc(HOSTLEN + 1); |
488 |
|
} |
489 |
|
|
490 |
|
query_name(ipbuf, C_IN, T_PTR, request); |
506 |
|
(unsigned char *)buf, sizeof(buf))) > 0) |
507 |
|
{ |
508 |
|
HEADER *header = (HEADER *)buf; |
509 |
< |
#ifndef HAVE_LRAND48 |
554 |
< |
int k = 0; |
555 |
< |
struct timeval tv; |
556 |
< |
#endif |
509 |
> |
|
510 |
|
/* |
511 |
|
* generate an unique id |
512 |
|
* NOTE: we don't have to worry about converting this to and from |
513 |
|
* network byte order, the nameserver does not interpret this value |
514 |
|
* and returns it unchanged |
515 |
|
*/ |
563 |
– |
#ifdef HAVE_LRAND48 |
564 |
– |
do |
565 |
– |
{ |
566 |
– |
header->id = (header->id + lrand48()) & 0xffff; |
567 |
– |
} while (find_id(header->id)); |
568 |
– |
#else |
569 |
– |
gettimeofday(&tv, NULL); |
516 |
|
do |
517 |
< |
{ |
518 |
< |
header->id = (header->id + k + tv.tv_usec) & 0xffff; |
519 |
< |
k++; |
574 |
< |
} while (find_id(header->id)); |
575 |
< |
#endif /* HAVE_LRAND48 */ |
517 |
> |
header->id = (header->id + genrand_int32()) & 0xffff; |
518 |
> |
while (find_id(header->id)); |
519 |
> |
|
520 |
|
request->id = header->id; |
521 |
|
++request->sends; |
522 |
|
|
530 |
|
if (request->resend == 0) |
531 |
|
return; |
532 |
|
|
533 |
< |
switch(request->type) |
533 |
> |
switch (request->type) |
534 |
|
{ |
535 |
|
case T_PTR: |
536 |
< |
do_query_number(NULL, &request->addr, request); |
536 |
> |
do_query_number(NULL, NULL, &request->addr, request); |
537 |
|
break; |
538 |
|
case T_A: |
539 |
< |
do_query_name(NULL, request->name, request, request->type); |
539 |
> |
do_query_name(NULL, NULL, request->name, request, request->type); |
540 |
|
break; |
541 |
|
#ifdef IPV6 |
542 |
|
case T_AAAA: |
543 |
|
/* didnt work, try A */ |
544 |
|
if (request->state == REQ_AAAA) |
545 |
< |
do_query_name(NULL, request->name, request, T_A); |
545 |
> |
do_query_name(NULL, NULL, request->name, request, T_A); |
546 |
|
#endif |
547 |
|
default: |
548 |
|
break; |
666 |
|
else if (n == 0) |
667 |
|
return(0); /* no more answers left */ |
668 |
|
|
669 |
< |
strlcpy(request->name, hostbuf, HOSTLEN); |
669 |
> |
strlcpy(request->name, hostbuf, HOSTLEN + 1); |
670 |
|
|
671 |
|
return(1); |
672 |
|
break; |
708 |
|
static void |
709 |
|
res_readreply(fde_t *fd, void *data) |
710 |
|
{ |
711 |
< |
char buf[sizeof(HEADER) + MAXPACKET]; |
711 |
> |
char buf[sizeof(HEADER) + MAXPACKET] |
712 |
> |
/* Sparc and alpha need 16bit-alignment for accessing header->id |
713 |
> |
* (which is uint16_t). Because of the header = (HEADER*) buf; |
714 |
> |
* lateron, this is neeeded. --FaUl |
715 |
> |
*/ |
716 |
> |
#if defined(__sparc__) || defined(__alpha__) |
717 |
> |
__attribute__((aligned (16))) |
718 |
> |
#endif |
719 |
> |
; |
720 |
|
HEADER *header; |
721 |
|
struct reslist *request = NULL; |
770 |
– |
struct DNSReply *reply = NULL; |
722 |
|
int rc; |
772 |
– |
int answer_count; |
723 |
|
socklen_t len = sizeof(struct irc_ssaddr); |
724 |
|
struct irc_ssaddr lsin; |
725 |
|
|
729 |
|
* interest where it'll instantly be ready for read :-) -- adrian |
730 |
|
*/ |
731 |
|
comm_setselect(fd, COMM_SELECT_READ, res_readreply, NULL, 0); |
732 |
+ |
|
733 |
|
/* Better to cast the sizeof instead of rc */ |
734 |
|
if (rc <= (int)(sizeof(HEADER))) |
735 |
|
return; |
744 |
|
header->arcount = ntohs(header->arcount); |
745 |
|
|
746 |
|
/* |
747 |
< |
* response for an id which we have already received an answer for |
797 |
< |
* just ignore this response. |
747 |
> |
* check against possibly fake replies |
748 |
|
*/ |
749 |
< |
if (0 == (request = find_id(header->id))) |
749 |
> |
if (!res_ourserver(&lsin)) |
750 |
|
return; |
751 |
|
|
752 |
|
/* |
753 |
< |
* check against possibly fake replies |
753 |
> |
* response for an id which we have already received an answer for |
754 |
> |
* just ignore this response. |
755 |
|
*/ |
756 |
< |
if (!res_ourserver(&lsin)) |
756 |
> |
if (!(request = find_id(header->id))) |
757 |
|
return; |
758 |
|
|
759 |
|
if ((header->rcode != NO_ERRORS) || (header->ancount == 0)) |
760 |
|
{ |
761 |
< |
if (SERVFAIL == header->rcode) |
762 |
< |
resend_query(request); |
761 |
> |
if (header->rcode == SERVFAIL || header->rcode == NXDOMAIN) |
762 |
> |
{ |
763 |
> |
/* |
764 |
> |
* If a bad error was returned, stop here and don't |
765 |
> |
* send any more (no retries granted). |
766 |
> |
*/ |
767 |
> |
(*request->callback)(request->callback_ctx, NULL, NULL); |
768 |
> |
rem_request(request); |
769 |
> |
} |
770 |
> |
#ifdef IPV6 |
771 |
|
else |
772 |
|
{ |
773 |
|
/* |
774 |
|
* If we havent already tried this, and we're looking up AAAA, try A |
775 |
|
* now |
776 |
|
*/ |
818 |
– |
|
819 |
– |
#ifdef IPV6 |
777 |
|
if (request->state == REQ_AAAA && request->type == T_AAAA) |
778 |
|
{ |
779 |
|
request->timeout += 4; |
780 |
|
resend_query(request); |
781 |
|
} |
825 |
– |
else if (request->type == T_PTR && request->state != REQ_INT && |
826 |
– |
request->addr.ss.ss_family == AF_INET6) |
827 |
– |
{ |
828 |
– |
request->state = REQ_INT; |
829 |
– |
request->timeout += 4; |
830 |
– |
request->retries--; |
831 |
– |
resend_query(request); |
832 |
– |
} |
833 |
– |
else |
834 |
– |
#endif |
835 |
– |
{ |
836 |
– |
/* |
837 |
– |
* If a bad error was returned, we stop here and dont send |
838 |
– |
* send any more (no retries granted). |
839 |
– |
*/ |
840 |
– |
(*request->query->callback)(request->query->ptr, NULL); |
841 |
– |
rem_request(request); |
842 |
– |
} |
782 |
|
} |
783 |
+ |
#endif |
784 |
|
|
785 |
|
return; |
786 |
|
} |
787 |
+ |
|
788 |
|
/* |
789 |
|
* If this fails there was an error decoding the received packet, |
790 |
|
* try it again and hope it works the next time. |
791 |
|
*/ |
792 |
< |
answer_count = proc_answer(request, header, buf, buf + rc); |
852 |
< |
|
853 |
< |
if (answer_count) |
792 |
> |
if (proc_answer(request, header, buf, buf + rc)) |
793 |
|
{ |
794 |
|
if (request->type == T_PTR) |
795 |
|
{ |
799 |
|
* got a PTR response with no name, something bogus is happening |
800 |
|
* don't bother trying again, the client address doesn't resolve |
801 |
|
*/ |
802 |
< |
(*request->query->callback)(request->query->ptr, reply); |
802 |
> |
(*request->callback)(request->callback_ctx, NULL, NULL); |
803 |
|
rem_request(request); |
804 |
|
return; |
805 |
|
} |
811 |
|
*/ |
812 |
|
#ifdef IPV6 |
813 |
|
if (request->addr.ss.ss_family == AF_INET6) |
814 |
< |
gethost_byname_type(request->name, request->query, T_AAAA); |
814 |
> |
gethost_byname_type(request->callback, request->callback_ctx, request->name, T_AAAA); |
815 |
|
else |
816 |
|
#endif |
817 |
< |
gethost_byname_type(request->name, request->query, T_A); |
817 |
> |
gethost_byname_type(request->callback, request->callback_ctx, request->name, T_A); |
818 |
|
rem_request(request); |
819 |
|
} |
820 |
|
else |
822 |
|
/* |
823 |
|
* got a name and address response, client resolved |
824 |
|
*/ |
825 |
< |
reply = make_dnsreply(request); |
887 |
< |
(*request->query->callback)(request->query->ptr, reply); |
888 |
< |
MyFree(reply); |
825 |
> |
(*request->callback)(request->callback_ctx, &request->addr, request->name); |
826 |
|
rem_request(request); |
827 |
|
} |
828 |
|
} |
838 |
|
} |
839 |
|
} |
840 |
|
|
904 |
– |
static struct DNSReply * |
905 |
– |
make_dnsreply(struct reslist *request) |
906 |
– |
{ |
907 |
– |
struct DNSReply *cp; |
908 |
– |
assert(request != 0); |
909 |
– |
|
910 |
– |
cp = (struct DNSReply *)MyMalloc(sizeof(struct DNSReply)); |
911 |
– |
|
912 |
– |
cp->h_name = request->name; |
913 |
– |
memcpy(&cp->addr, &request->addr, sizeof(cp->addr)); |
914 |
– |
return(cp); |
915 |
– |
} |
916 |
– |
|
841 |
|
void |
842 |
|
report_dns_servers(struct Client *source_p) |
843 |
|
{ |
844 |
|
int i; |
845 |
< |
char ipaddr[HOSTIPLEN]; |
845 |
> |
char ipaddr[HOSTIPLEN + 1]; |
846 |
|
|
847 |
|
for (i = 0; i < irc_nscount; i++) |
848 |
|
{ |
849 |
|
irc_getnameinfo((struct sockaddr *)&(irc_nsaddr_list[i]), |
850 |
< |
irc_nsaddr_list[i].ss_len, ipaddr, HOSTIPLEN, NULL, 0, |
851 |
< |
NI_NUMERICHOST); |
850 |
> |
irc_nsaddr_list[i].ss_len, ipaddr, |
851 |
> |
sizeof(ipaddr), NULL, 0, NI_NUMERICHOST); |
852 |
|
sendto_one(source_p, form_str(RPL_STATSALINE), |
853 |
|
me.name, source_p->name, ipaddr); |
854 |
|
} |