ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/irc_res.c
(Generate patch)

Comparing:
ircd-hybrid/src/irc_res.c (file contents), Revision 33 by knight, Sun Oct 2 20:50:00 2005 UTC vs.
ircd-hybrid-7.2/src/irc_res.c (file contents), Revision 984 by michael, Fri Aug 14 13:18:14 2009 UTC

# Line 30 | Line 30
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"
# Line 136 | Line 137 | res_ourserver(const struct irc_ssaddr *i
137    struct sockaddr_in *v4in = (struct sockaddr_in *)inp;
138    int ns;
139  
140 <  for (ns = 0;  ns < irc_nscount;  ns++)
140 >  for (ns = 0; ns < irc_nscount; ns++)
141    {
142      const struct irc_ssaddr *srv = &irc_nsaddr_list[ns];
143   #ifdef IPV6
# Line 256 | Line 257 | start_resolver(void)
257   void
258   init_resolver(void)
259   {
259 – #ifdef HAVE_SRAND48
260 –  srand48(CurrentTime);
261 – #endif
260    memset(&ResolverFileDescriptor, 0, sizeof(fde_t));
261    start_resolver();
262   }
# Line 320 | Line 318 | make_request(struct DNSQuery* query)
318    struct reslist *request;
319  
320    request = (struct reslist *)MyMalloc(sizeof(struct reslist));
323 –  memset(request, 0, sizeof(struct reslist));
321  
322    request->sentat  = CurrentTime;
323    request->retries = 3;
324    request->resend  = 1;
325    request->timeout = 4;    /* start at 4 and exponential inc. */
329 –  memset(&request->addr, 0, sizeof(request->addr));
326    request->query   = query;
327    request->state   = REQ_IDLE;
328  
# Line 458 | Line 454 | do_query_name(struct DNSQuery *query, co
454      request->type = type;
455      strcpy(request->name, host_name);
456   #ifdef IPV6
457 <    if (type == T_A)
462 <      request->state = REQ_A;
463 <    else
457 >    if (type != T_A)
458        request->state = REQ_AAAA;
459 < #else
466 <    request->state = REQ_A;
459 >    else
460   #endif
461 +    request->state = REQ_A;
462    }
463  
464    request->type = type;
# Line 550 | Line 544 | query_name(const char *name, int query_c
544        (unsigned char *)buf, sizeof(buf))) > 0)
545    {
546      HEADER *header = (HEADER *)buf;
547 < #ifndef HAVE_LRAND48
554 <    int k = 0;
555 <    struct timeval tv;
556 < #endif
547 >
548      /*
549       * generate an unique id
550       * NOTE: we don't have to worry about converting this to and from
551       * network byte order, the nameserver does not interpret this value
552       * and returns it unchanged
553       */
563 – #ifdef HAVE_LRAND48
554      do
555 <    {
556 <      header->id = (header->id + lrand48()) & 0xffff;
557 <    } while (find_id(header->id));
568 < #else
569 <    gettimeofday(&tv, NULL);
570 <    do
571 <    {
572 <      header->id = (header->id + k + tv.tv_usec) & 0xffff;
573 <      k++;
574 <    } while (find_id(header->id));
575 < #endif /* HAVE_LRAND48 */
555 >      header->id = (header->id + genrand_int32()) & 0xffff;
556 >    while (find_id(header->id));
557 >
558      request->id = header->id;
559      ++request->sends;
560  
# Line 586 | Line 568 | resend_query(struct reslist *request)
568    if (request->resend == 0)
569      return;
570  
571 <  switch(request->type)
571 >  switch (request->type)
572    {
573      case T_PTR:
574        do_query_number(NULL, &request->addr, request);
# Line 764 | Line 746 | proc_answer(struct reslist *request, HEA
746   static void
747   res_readreply(fde_t *fd, void *data)
748   {
749 <  char buf[sizeof(HEADER) + MAXPACKET];
749 >  char buf[sizeof(HEADER) + MAXPACKET]
750 >        /* Sparc and alpha need 16bit-alignment for accessing header->id
751 >         * (which is uint16_t). Because of the header = (HEADER*) buf;
752 >         * lateron, this is neeeded. --FaUl
753 >         */
754 > #if defined(__sparc__) || defined(__alpha__)  
755 >          __attribute__((aligned (16)))
756 > #endif
757 >          ;
758    HEADER *header;
759    struct reslist *request = NULL;
760    struct DNSReply *reply  = NULL;
# Line 779 | Line 769 | res_readreply(fde_t *fd, void *data)
769     * interest where it'll instantly be ready for read :-) -- adrian
770     */
771    comm_setselect(fd, COMM_SELECT_READ, res_readreply, NULL, 0);
772 +
773    /* Better to cast the sizeof instead of rc */
774    if (rc <= (int)(sizeof(HEADER)))
775      return;
# Line 807 | Line 798 | res_readreply(fde_t *fd, void *data)
798  
799    if ((header->rcode != NO_ERRORS) || (header->ancount == 0))
800    {
801 <    if (SERVFAIL == header->rcode)
802 <      resend_query(request);
801 >    if (header->rcode == SERVFAIL || header->rcode == NXDOMAIN)
802 >    {
803 >      /*
804 >       * If a bad error was returned, stop here and don't
805 >       * send any more (no retries granted).
806 >       */
807 >      (*request->query->callback)(request->query->ptr, NULL);
808 >      rem_request(request);
809 >    }
810 > #ifdef IPV6
811      else
812      {
813        /*
814         * If we havent already tried this, and we're looking up AAAA, try A
815         * now
816         */
818 –
819 – #ifdef IPV6
817        if (request->state == REQ_AAAA && request->type == T_AAAA)
818        {
819          request->timeout += 4;
# Line 827 | Line 824 | res_readreply(fde_t *fd, void *data)
824        {
825          request->state = REQ_INT;
826          request->timeout += 4;
827 <        request->retries--;
827 >        request->retries--;
828          resend_query(request);
829        }
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 –      }
830      }
831 + #endif
832  
833      return;
834    }
835 +
836    /*
837     * If this fails there was an error decoding the received packet,
838     * try it again and hope it works the next time.

Diff Legend

– Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)