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-7.2/src/irc_res.c (file contents):
Revision 411 by adx, Wed Feb 8 14:42:01 2006 UTC vs.
Revision 986 by michael, Sat Aug 15 21:12:34 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 69 | Line 70 | typedef enum
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
# Line 92 | Line 92 | 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);
# Line 136 | Line 136 | res_ourserver(const struct irc_ssaddr *i
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
# Line 256 | Line 256 | start_resolver(void)
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   }
# Line 446 | Line 443 | do_query_name(struct DNSQuery *query, co
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;
# Line 478 | Line 473 | do_query_number(struct DNSQuery *query,
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;
# Line 496 | Line 489 | do_query_number(struct DNSQuery *query,
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),
# Line 518 | Line 506 | do_query_number(struct DNSQuery *query,
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)
# Line 526 | Line 514 | do_query_number(struct DNSQuery *query,
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);
# Line 548 | Line 536 | query_name(const char *name, int query_c
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  
# Line 584 | Line 560 | resend_query(struct reslist *request)
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);
# Line 720 | Line 696 | proc_answer(struct reslist *request, HEA
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;
# Line 785 | Line 761 | res_readreply(fde_t *fd, void *data)
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;
# Line 813 | Line 790 | res_readreply(fde_t *fd, void *data)
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.

Diff Legend

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