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

Comparing ircd-hybrid/trunk/src/res.c (file contents):
Revision 4408 by michael, Wed Aug 6 21:19:38 2014 UTC vs.
Revision 4448 by michael, Sat Aug 9 19:20:10 2014 UTC

# Line 86 | Line 86 | typedef enum
86    REQ_IDLE,  /**< We're doing not much at all */
87    REQ_PTR,   /**< Looking up a PTR */
88    REQ_A,     /**< Looking up an A, possibly because AAAA failed */
89 #ifdef IPV6
89    REQ_AAAA,  /**< Looking up an AAAA */
91 #endif
90    REQ_CNAME  /**< We got a CNAME in response, we better get a real answer next */
91   } request_state;
92  
93   struct reslist
94   {
95 <  dlink_node node;                       /**< Doubly linked list node. */
96 <  int id;                                /**< Request ID (from request header). */
97 <  int sent;                              /**< Number of requests sent */
98 <  request_state state;                   /**< State the resolver machine is in */
99 <  char type;                             /**< Current request type. */
100 <  char retries;                          /**< Retry counter */
101 <  unsigned int sends;                    /**< Number of sends (>1 means resent). */
102 <  char resend;                           /**< Send flag; 0 == don't resend. */
103 <  time_t sentat;                         /**< Timestamp we last sent this request. */
104 <  time_t timeout;                        /**< When this request times out. */
105 <  struct irc_ssaddr addr;                /**< Address for this request. */
106 <  char name[RFC1035_MAX_DOMAIN_LENGTH];  /**< Hostname for this request. */
107 <  size_t namelength;                     /**< Actual hostname length. */
108 <  dns_callback_fnc callback;             /**< Callback function on completion. */
109 <  void *callback_ctx;                    /**< Context pointer for callback. */
95 >  dlink_node node;                           /**< Doubly linked list node. */
96 >  int id;                                    /**< Request ID (from request header). */
97 >  int sent;                                  /**< Number of requests sent */
98 >  request_state state;                       /**< State the resolver machine is in */
99 >  char type;                                 /**< Current request type. */
100 >  char retries;                              /**< Retry counter */
101 >  unsigned int sends;                        /**< Number of sends (>1 means resent). */
102 >  char resend;                               /**< Send flag; 0 == don't resend. */
103 >  time_t sentat;                             /**< Timestamp we last sent this request. */
104 >  time_t timeout;                            /**< When this request times out. */
105 >  struct irc_ssaddr addr;                    /**< Address for this request. */
106 >  char name[RFC1035_MAX_DOMAIN_LENGTH + 1];  /**< Hostname for this request. */
107 >  size_t namelength;                         /**< Actual hostname length. */
108 >  dns_callback_fnc callback;                 /**< Callback function on completion. */
109 >  void *callback_ctx;                        /**< Context pointer for callback. */
110   };
111  
112   static fde_t ResolverFileDescriptor;
# Line 162 | Line 160 | make_request(dns_callback_fnc callback,
160   static int
161   res_ourserver(const struct irc_ssaddr *inp)
162   {
165 #ifdef IPV6
163    const struct sockaddr_in6 *v6;
164    const struct sockaddr_in6 *v6in = (const struct sockaddr_in6 *)inp;
168 #endif
165    const struct sockaddr_in *v4;
166    const struct sockaddr_in *v4in = (const struct sockaddr_in *)inp;
167  
168    for (unsigned int i = 0; i < irc_nscount; ++i)
169    {
170      const struct irc_ssaddr *srv = &irc_nsaddr_list[i];
175 #ifdef IPV6
171      v6 = (const struct sockaddr_in6 *)srv;
177 #endif
172      v4 = (const struct sockaddr_in *)srv;
173  
174      /*
# Line 183 | Line 177 | res_ourserver(const struct irc_ssaddr *i
177       */
178      switch (srv->ss.ss_family)
179      {
186 #ifdef IPV6
180        case AF_INET6:
181          if (srv->ss.ss_family == inp->ss.ss_family)
182            if (v6->sin6_port == v6in->sin6_port)
# Line 191 | Line 184 | res_ourserver(const struct irc_ssaddr *i
184                          sizeof(struct in6_addr)))
185                return 1;
186          break;
194 #endif
187        case AF_INET:
188          if (srv->ss.ss_family == inp->ss.ss_family)
189            if (v4->sin_port == v4in->sin_port)
# Line 218 | Line 210 | start_resolver(void)
210    if (!ResolverFileDescriptor.flags.open)
211    {
212      if (comm_open(&ResolverFileDescriptor, irc_nsaddr_list[0].ss.ss_family,
213 <                  SOCK_DGRAM, 0, "Resolver socket") == -1)
213 >                  SOCK_DGRAM, 0, "UDP resolver socket") == -1)
214        return;
215  
216      /* At the moment, the resolver FD data is global .. */
# Line 353 | Line 345 | do_query_name(dns_callback_fnc callback,
345      request             = make_request(callback, ctx);
346      request->type       = type;
347      request->namelength = strlcpy(request->name, host_name, sizeof(request->name));
348 < #ifdef IPV6
348 >
349      if (type != T_A)
350        request->state = REQ_AAAA;
351      else
352 < #endif
361 <    request->state = REQ_A;
352 >      request->state = REQ_A;
353    }
354  
355    request->type = type;
# Line 384 | Line 375 | do_query_number(dns_callback_fnc callbac
375               (unsigned int)(cp[3]), (unsigned int)(cp[2]),
376               (unsigned int)(cp[1]), (unsigned int)(cp[0]));
377    }
387 #ifdef IPV6
378    else if (addr->ss.ss_family == AF_INET6)
379    {
380      const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr;
# Line 410 | Line 400 | do_query_number(dns_callback_fnc callbac
400               (unsigned int)(cp[1] & 0xf), (unsigned int)(cp[1] >> 4),
401               (unsigned int)(cp[0] & 0xf), (unsigned int)(cp[0] >> 4));
402    }
403 < #endif
403 >
404    if (request == NULL)
405    {
406      request       = make_request(callback, ctx);
# Line 438 | Line 428 | gethost_byname_type(dns_callback_fnc cal
428   void
429   gethost_byname(dns_callback_fnc callback, void *ctx, const char *name)
430   {
441 #ifdef IPV6
431    gethost_byname_type(callback, ctx, name, T_AAAA);
443 #else
444  gethost_byname_type(callback, ctx, name, T_A);
445 #endif
432   }
433  
434   /*
# Line 468 | Line 454 | resend_query(struct reslist *request)
454      case T_A:
455        do_query_name(NULL, NULL, request->name, request, request->type);
456        break;
471 #ifdef IPV6
457      case T_AAAA:  /* Didn't work, try A */
458        if (request->state == REQ_AAAA)
459          do_query_name(NULL, NULL, request->name, request, T_A);
475 #endif
460      default:
461        break;
462    }
# Line 490 | Line 474 | proc_answer(struct reslist *request, HEA
474    int n;                       /* temp count */
475    int rd_length;
476    struct sockaddr_in *v4;      /* conversion */
493 #ifdef IPV6
477    struct sockaddr_in6 *v6;
478 < #endif
478 >
479    current = (unsigned char *)buf + sizeof(HEADER);
480  
481    for (; header->qdcount > 0; --header->qdcount)
# Line 556 | Line 539 | proc_answer(struct reslist *request, HEA
539          memcpy(&v4->sin_addr, current, sizeof(struct in_addr));
540          return 1;
541          break;
559 #ifdef IPV6
542        case T_AAAA:
543          if (request->type != T_AAAA)
544            return 0;
# Line 570 | Line 552 | proc_answer(struct reslist *request, HEA
552          memcpy(&v6->sin6_addr, current, sizeof(struct in6_addr));
553          return 1;
554          break;
573 #endif
555        case T_PTR:
556          if (request->type != T_PTR)
557            return 0;
# Line 665 | Line 646 | res_readreply(fde_t *fd, void *data)
646          (*request->callback)(request->callback_ctx, NULL, NULL, 0);
647          rem_request(request);
648        }
668 #ifdef IPV6
649        else
650        {
651          /*
# Line 677 | Line 657 | res_readreply(fde_t *fd, void *data)
657            resend_query(request);
658          }
659        }
660 < #endif
660 >
661        continue;
662      }
663  
# Line 709 | Line 689 | res_readreply(fde_t *fd, void *data)
689        /*
690         * Lookup the 'authoritative' name that we were given for the ip#.
691         */
712 #ifdef IPV6
692        if (request->addr.ss.ss_family == AF_INET6)
693          gethost_byname_type(request->callback, request->callback_ctx, request->name, T_AAAA);
694        else
695 < #endif
717 <      gethost_byname_type(request->callback, request->callback_ctx, request->name, T_A);
695 >        gethost_byname_type(request->callback, request->callback_ctx, request->name, T_A);
696        rem_request(request);
697      }
698      else
# Line 790 | Line 768 | timeout_query_list(void)
768   * timeout_resolver - check request list
769   */
770   static void
771 < timeout_resolver(void *notused)
771 > timeout_resolver(void *unused)
772   {
773    timeout_query_list();
774   }
# Line 809 | Line 787 | init_resolver(void)
787    };
788  
789    dns_pool = mp_pool_new(sizeof(struct reslist), MP_CHUNK_SIZE_DNS);
812  memset(&ResolverFileDescriptor, 0, sizeof(fde_t));
813  start_resolver();
790  
791 +  start_resolver();
792    event_add(&event_timeout_resolver, NULL);
793   }

Diff Legend

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