Back to index

tor  0.2.3.18-rc
Classes | Defines | Typedefs | Functions
eventdns.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  evdns_server_request
struct  evdns_server_question

Defines

#define DNS_ERR_NONE   0
#define DNS_ERR_FORMAT   1
#define DNS_ERR_SERVERFAILED   2
#define DNS_ERR_NOTEXIST   3
#define DNS_ERR_NOTIMPL   4
#define DNS_ERR_REFUSED   5
#define DNS_ERR_TRUNCATED   65
#define DNS_ERR_UNKNOWN   66
#define DNS_ERR_TIMEOUT   67
#define DNS_ERR_SHUTDOWN   68
#define DNS_IPv4_A   1
#define DNS_PTR   2
#define DNS_IPv6_AAAA   3
#define DNS_QUERY_NO_SEARCH   1
#define DNS_OPTION_SEARCH   1
#define DNS_OPTION_NAMESERVERS   2
#define DNS_OPTION_MISC   4
#define DNS_OPTIONS_ALL   7
#define DNS_NO_SEARCH   1
#define EVDNS_ANSWER_SECTION   0
#define EVDNS_AUTHORITY_SECTION   1
#define EVDNS_ADDITIONAL_SECTION   2
#define EVDNS_TYPE_A   1
#define EVDNS_TYPE_NS   2
#define EVDNS_TYPE_CNAME   5
#define EVDNS_TYPE_SOA   6
#define EVDNS_TYPE_PTR   12
#define EVDNS_TYPE_MX   15
#define EVDNS_TYPE_TXT   16
#define EVDNS_TYPE_AAAA   28
#define EVDNS_QTYPE_AXFR   252
#define EVDNS_QTYPE_ALL   255
#define EVDNS_CLASS_INET   1

Typedefs

typedef void(* evdns_callback_type )(int result, char type, int count, int ttl, void *addresses, void *arg)
typedef void(* evdns_debug_log_fn_type )(int is_warning, const char *msg)
typedef void(* evdns_request_callback_fn_type )(struct evdns_server_request *, void *)

Functions

int evdns_init (void)
void evdns_shutdown (int fail_requests)
const char * evdns_err_to_string (int err)
int evdns_nameserver_add (uint32_t address)
int evdns_count_nameservers (void)
int evdns_clear_nameservers_and_suspend (void)
int evdns_resume (void)
int evdns_nameserver_ip_add (const char *ip_as_string)
int evdns_nameserver_sockaddr_add (const struct sockaddr *sa, socklen_t len)
void evdns_set_default_outgoing_bind_address (const struct sockaddr *addr, socklen_t addrlen)
int evdns_resolve_ipv4 (const char *name, int flags, evdns_callback_type callback, void *ptr)
int evdns_resolve_ipv6 (const char *name, int flags, evdns_callback_type callback, void *ptr)
int evdns_resolve_reverse (const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr)
int evdns_resolve_reverse_ipv6 (const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr)
int evdns_set_option (const char *option, const char *val, int flags)
int evdns_resolv_conf_parse (int flags, const char *)
void evdns_search_clear (void)
void evdns_search_add (const char *domain)
void evdns_search_ndots_set (const int ndots)
void evdns_set_log_fn (evdns_debug_log_fn_type fn)
void evdns_set_transaction_id_fn (uint16_t(*fn)(void))
void evdns_set_random_bytes_fn (void(*fn)(char *, size_t))
struct evdns_server_portevdns_add_server_port (tor_socket_t socket, int is_tcp, evdns_request_callback_fn_type callback, void *user_data)
void evdns_close_server_port (struct evdns_server_port *port)
int evdns_server_request_add_reply (struct evdns_server_request *req, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data)
int evdns_server_request_add_a_reply (struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl)
int evdns_server_request_add_aaaa_reply (struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl)
int evdns_server_request_add_ptr_reply (struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl)
int evdns_server_request_add_cname_reply (struct evdns_server_request *req, const char *name, const char *cname, int ttl)
int evdns_server_request_get_requesting_addr (struct evdns_server_request *req, struct sockaddr *sa, int addr_len)
int evdns_server_request_respond (struct evdns_server_request *req, int err)
int evdns_server_request_drop (struct evdns_server_request *req)

Class Documentation

struct evdns_server_request

Definition at line 293 of file eventdns.h.

Collaboration diagram for evdns_server_request:
Class Members
int flags
int nquestions
struct evdns_server_question ** questions
struct evdns_server_question

Definition at line 298 of file eventdns.h.

Class Members
int dns_question_class
char name
int type

Define Documentation

#define DNS_ERR_FORMAT   1

Definition at line 218 of file eventdns.h.

#define DNS_ERR_NONE   0

Definition at line 216 of file eventdns.h.

#define DNS_ERR_NOTEXIST   3

Definition at line 223 of file eventdns.h.

#define DNS_ERR_NOTIMPL   4

Definition at line 225 of file eventdns.h.

#define DNS_ERR_REFUSED   5

Definition at line 228 of file eventdns.h.

#define DNS_ERR_SERVERFAILED   2

Definition at line 221 of file eventdns.h.

#define DNS_ERR_SHUTDOWN   68

Definition at line 236 of file eventdns.h.

#define DNS_ERR_TIMEOUT   67

Definition at line 234 of file eventdns.h.

#define DNS_ERR_TRUNCATED   65

Definition at line 230 of file eventdns.h.

#define DNS_ERR_UNKNOWN   66

Definition at line 232 of file eventdns.h.

#define DNS_IPv4_A   1

Definition at line 238 of file eventdns.h.

#define DNS_IPv6_AAAA   3

Definition at line 240 of file eventdns.h.

#define DNS_NO_SEARCH   1

Definition at line 289 of file eventdns.h.

#define DNS_OPTION_MISC   4

Definition at line 246 of file eventdns.h.

#define DNS_OPTION_NAMESERVERS   2

Definition at line 245 of file eventdns.h.

#define DNS_OPTION_SEARCH   1

Definition at line 244 of file eventdns.h.

#define DNS_OPTIONS_ALL   7

Definition at line 247 of file eventdns.h.

#define DNS_PTR   2

Definition at line 239 of file eventdns.h.

#define DNS_QUERY_NO_SEARCH   1

Definition at line 242 of file eventdns.h.

#define EVDNS_ADDITIONAL_SECTION   2

Definition at line 306 of file eventdns.h.

#define EVDNS_ANSWER_SECTION   0

Definition at line 304 of file eventdns.h.

#define EVDNS_AUTHORITY_SECTION   1

Definition at line 305 of file eventdns.h.

#define EVDNS_CLASS_INET   1

Definition at line 320 of file eventdns.h.

#define EVDNS_QTYPE_ALL   255

Definition at line 318 of file eventdns.h.

#define EVDNS_QTYPE_AXFR   252

Definition at line 317 of file eventdns.h.

#define EVDNS_TYPE_A   1

Definition at line 308 of file eventdns.h.

#define EVDNS_TYPE_AAAA   28

Definition at line 315 of file eventdns.h.

#define EVDNS_TYPE_CNAME   5

Definition at line 310 of file eventdns.h.

#define EVDNS_TYPE_MX   15

Definition at line 313 of file eventdns.h.

#define EVDNS_TYPE_NS   2

Definition at line 309 of file eventdns.h.

#define EVDNS_TYPE_PTR   12

Definition at line 312 of file eventdns.h.

#define EVDNS_TYPE_SOA   6

Definition at line 311 of file eventdns.h.

#define EVDNS_TYPE_TXT   16

Definition at line 314 of file eventdns.h.


Typedef Documentation

typedef void(* evdns_callback_type)(int result, char type, int count, int ttl, void *addresses, void *arg)

Definition at line 256 of file eventdns.h.

typedef void(* evdns_debug_log_fn_type)(int is_warning, const char *msg)

Definition at line 283 of file eventdns.h.

typedef void(* evdns_request_callback_fn_type)(struct evdns_server_request *, void *)

Definition at line 303 of file eventdns.h.


Function Documentation

struct evdns_server_port* evdns_add_server_port ( tor_socket_t  socket,
int  is_tcp,
evdns_request_callback_fn_type  callback,
void *  user_data 
) [read]

Definition at line 1571 of file eventdns.c.

{
       struct evdns_server_port *port;
       if (!(port = mm_malloc(sizeof(struct evdns_server_port))))
              return NULL;
       memset(port, 0, sizeof(struct evdns_server_port));

       assert(!is_tcp); /* TCP sockets not yet implemented */
       port->socket = socket;
       port->refcnt = 1;
       port->choked = 0;
       port->closing = 0;
       port->user_callback = cb;
       port->user_data = user_data;
       port->pending_replies = NULL;

       event_set(&port->event, port->socket, EV_READ | EV_PERSIST,
                       server_port_ready_callback, port);
       if (event_add(&port->event, NULL)<0) {
              mm_free(port);
              return NULL;
       }
       return port;
}

Here is the call graph for this function:

Definition at line 2178 of file eventdns.c.

{
       struct nameserver *server = server_head, *started_at = server_head;
       struct evdns_request *req = req_head, *req_started_at = req_head;

       if (!server)
              return 0;
       while (1) {
              struct nameserver *next = server->next;
              (void) event_del(&server->event);
              CLEAR(&server->event);
              del_timeout_event(server);
              if (server->socket >= 0)
                     CLOSE_SOCKET(server->socket);
              CLEAR(server);
              mm_free(server);
              if (next == started_at)
                     break;
              server = next;
       }
       server_head = NULL;
       global_good_nameservers = 0;

       while (req) {
              struct evdns_request *next = req->next;
              req->tx_count = req->reissue_count = 0;
              req->ns = NULL;
              /* ???? What to do about searches? */
              del_timeout_event(req);
              req->trans_id = 0;
              req->transmit_me = 0;

              global_requests_waiting++;
              evdns_request_insert(req, &req_waiting_head);
              /* We want to insert these suspended elements at the front of
               * the waiting queue, since they were pending before any of
               * the waiting entries were added. This is a circular list,
               * so we can just shift the start back by one.*/
              req_waiting_head = req_waiting_head->prev;

              if (next == req_started_at)
                     break;
              req = next;
       }
       req_head = NULL;
       global_requests_inflight = 0;

       return 0;
}

Here is the call graph for this function:

void evdns_close_server_port ( struct evdns_server_port port)

Definition at line 1598 of file eventdns.c.

{
       port->closing = 1;
       if (--port->refcnt == 0)
              server_port_free(port);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int evdns_count_nameservers ( void  )

Definition at line 2163 of file eventdns.c.

{
       const struct nameserver *server = server_head;
       int n = 0;
       if (!server)
              return 0;
       do {
              ++n;
              server = server->next;
       } while (server != server_head);
       return n;
}
const char* evdns_err_to_string ( int  err)

Definition at line 3323 of file eventdns.c.

{
       switch (err) {
       case DNS_ERR_NONE: return "no error";
       case DNS_ERR_FORMAT: return "misformatted query";
       case DNS_ERR_SERVERFAILED: return "server failed";
       case DNS_ERR_NOTEXIST: return "name does not exist";
       case DNS_ERR_NOTIMPL: return "query not implemented";
       case DNS_ERR_REFUSED: return "refused";

       case DNS_ERR_TRUNCATED: return "reply truncated or ill-formed";
       case DNS_ERR_UNKNOWN: return "unknown";
       case DNS_ERR_TIMEOUT: return "request timed out";
       case DNS_ERR_SHUTDOWN: return "dns subsystem shut down";
       default: return "[Unknown error code]";
       }
}

Here is the caller graph for this function:

int evdns_init ( void  )

Definition at line 3310 of file eventdns.c.

{
              int res = 0;
#ifdef _WIN32
              evdns_config_windows_nameservers();
#else
              res = evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
#endif

              return (res);
}

Here is the call graph for this function:

int evdns_nameserver_add ( uint32_t  address)

Definition at line 2365 of file eventdns.c.

                                       {
       struct sockaddr_in sin;
       memset(&sin, 0, sizeof(sin));
       sin.sin_family = AF_INET;
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
       sin.sin_len = sizeof(sin);
#endif
       sin.sin_addr.s_addr = htonl(address);
       sin.sin_port = 53;
       return _evdns_nameserver_add_impl((struct sockaddr*) &sin, sizeof(sin));
}

Here is the call graph for this function:

int evdns_nameserver_ip_add ( const char *  ip_as_string)

Definition at line 2379 of file eventdns.c.

                                                  {
       int port;
       char buf[128];
       const char *cp, *addr_part, *port_part;
       int is_ipv6;
       /* recognized formats are:
        * [ipv6]:port
        * ipv6
        * [ipv6]
        * ipv4:port
        * ipv4
        */

       log(EVDNS_LOG_DEBUG, "Trying to add nameserver <%s>", ip_as_string);

       cp = strchr(ip_as_string, ':');
       if (*ip_as_string == '[') {
              size_t len;
              if (!(cp = strchr(ip_as_string, ']'))) {
                     log(EVDNS_LOG_DEBUG, "Nameserver missing closing ]");
                     return 4;
              }
              len = cp-(ip_as_string + 1);
              if (len > sizeof(buf)-1) {
                     log(EVDNS_LOG_DEBUG, "[Nameserver] does not fit in buffer.");
                     return 4;
              }
              memcpy(buf, ip_as_string+1, len);
              buf[len] = '\0';
              addr_part = buf;
              if (cp[1] == ':')
                     port_part = cp+2;
              else
                     port_part = NULL;
              is_ipv6 = 1;
       } else if (cp && strchr(cp+1, ':')) {
              is_ipv6 = 1;
              addr_part = ip_as_string;
              port_part = NULL;
       } else if (cp) {
              is_ipv6 = 0;
              if (cp - ip_as_string > (int)sizeof(buf)-1) {
                     log(EVDNS_LOG_DEBUG, "Nameserver does not fit in buffer.");
                     return 4;
              }
              memcpy(buf, ip_as_string, cp-ip_as_string);
              buf[cp-ip_as_string] = '\0';
              addr_part = buf;
              port_part = cp+1;
       } else {
              addr_part = ip_as_string;
              port_part = NULL;
              is_ipv6 = 0;
       }

       if (port_part == NULL) {
              port = 53;
       } else {
              port = strtoint(port_part);
              if (port <= 0 || port > 65535) {
                     log(EVDNS_LOG_DEBUG, "Nameserver port <%s> out of range",
                            port_part);
                     return 4;
              }
       }

       /* Tor-only.  needs a more general fix. */
       assert(addr_part);
       if (is_ipv6) {
              struct sockaddr_in6 sin6;
              memset(&sin6, 0, sizeof(sin6));
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
              sin6.sin6_len = sizeof(sin6);
#endif
              sin6.sin6_family = AF_INET6;
              sin6.sin6_port = htons(port);
              if (1 != tor_inet_pton(AF_INET6, addr_part, &sin6.sin6_addr)) {
                     log(EVDNS_LOG_DEBUG, "inet_pton(%s) failed", addr_part);
                     return 4;
              }
              return _evdns_nameserver_add_impl((struct sockaddr*)&sin6,
                                                                        sizeof(sin6));
       } else {
              struct sockaddr_in sin;
              memset(&sin, 0, sizeof(sin));
#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
              sin.sin_len = sizeof(sin);
#endif
              sin.sin_family = AF_INET;
              sin.sin_port = htons(port);
              if (!inet_aton(addr_part, &sin.sin_addr)) {
                     log(EVDNS_LOG_DEBUG, "inet_pton(%s) failed", addr_part);
                     return 4;
              }
              return _evdns_nameserver_add_impl((struct sockaddr*)&sin,
                                                                        sizeof(sin));
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int evdns_nameserver_sockaddr_add ( const struct sockaddr *  sa,
socklen_t  len 
)

Definition at line 2479 of file eventdns.c.

{
       return _evdns_nameserver_add_impl(sa, len);
}

Here is the call graph for this function:

int evdns_resolv_conf_parse ( int  flags,
const char *   
)

Definition at line 3039 of file eventdns.c.

                                                               {
       struct stat st;
       int fd, n, r;
       u8 *resolv;
       char *start;
       int err = 0;

       log(EVDNS_LOG_DEBUG, "Parsing resolv.conf file %s", filename);

       fd = tor_open_cloexec(filename, O_RDONLY, 0);
       if (fd < 0) {
              evdns_resolv_set_defaults(flags);
              return 1;
       }

       if (fstat(fd, &st)) { err = 2; goto out1; }
       if (!st.st_size) {
              evdns_resolv_set_defaults(flags);
              err = (flags & DNS_OPTION_NAMESERVERS) ? 6 : 0;
              goto out1;
       }
       if (st.st_size > 65535) { err = 3; goto out1; }   /* no resolv.conf should be any bigger */

       resolv = (u8 *) mm_malloc((size_t)st.st_size + 1);
       if (!resolv) { err = 4; goto out1; }

    n = 0;
       while ((r = (int)read(fd, resolv+n, (size_t)st.st_size-n)) > 0) {
              n += r;
              if (n == st.st_size)
                     break;
              assert(n < st.st_size);
       }
       if (r < 0) { err = 5; goto out2; }
       resolv[n] = 0;        /* we malloced an extra byte; this should be fine. */

       start = (char *) resolv;
       for (;;) {
              char *const newline = strchr(start, '\n');
              if (!newline) {
                     resolv_conf_parse_line(start, flags);
                     break;
              } else {
                     *newline = 0;
                     resolv_conf_parse_line(start, flags);
                     start = newline + 1;
              }
       }

       if (!server_head && (flags & DNS_OPTION_NAMESERVERS)) {
              /* no nameservers were configured. */
              evdns_nameserver_ip_add("127.0.0.1");
              err = 6;
       }
       if (flags & DNS_OPTION_SEARCH && (!global_search_state || global_search_state->num_domains == 0)) {
              search_set_from_hostname();
       }

out2:
       mm_free(resolv);
out1:
       close(fd);
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int evdns_resolve_ipv4 ( const char *  name,
int  flags,
evdns_callback_type  callback,
void *  ptr 
)

Definition at line 2591 of file eventdns.c.

                                                                               {
       log(EVDNS_LOG_DEBUG, "Resolve requested for %s", name);
       if (flags & DNS_QUERY_NO_SEARCH) {
              struct evdns_request *const req =
                     request_new(TYPE_A, name, flags, callback, ptr);
              if (req == NULL)
                     return (1);
              request_submit(req);
              return (0);
       } else {
              return (search_request_new(TYPE_A, name, flags, callback, ptr));
       }
}

Here is the call graph for this function:

int evdns_resolve_ipv6 ( const char *  name,
int  flags,
evdns_callback_type  callback,
void *  ptr 
)

Definition at line 2607 of file eventdns.c.

                                                                               {
       log(EVDNS_LOG_DEBUG, "Resolve requested for %s", name);
       if (flags & DNS_QUERY_NO_SEARCH) {
              struct evdns_request *const req =
                     request_new(TYPE_AAAA, name, flags, callback, ptr);
              if (req == NULL)
                     return (1);
              request_submit(req);
              return (0);
       } else {
              return (search_request_new(TYPE_AAAA, name, flags, callback, ptr));
       }
}

Here is the call graph for this function:

int evdns_resolve_reverse ( const struct in_addr *  in,
int  flags,
evdns_callback_type  callback,
void *  ptr 
)

Definition at line 2622 of file eventdns.c.

                                                                                                        {
       char buf[32];
       struct evdns_request *req;
       u32 a;
       assert(in);
       a = ntohl(in->s_addr);
       snprintf(buf, sizeof(buf), "%d.%d.%d.%d.in-addr.arpa",
                     (int)(u8)((a  )&0xff),
                     (int)(u8)((a>>8 )&0xff),
                     (int)(u8)((a>>16)&0xff),
                     (int)(u8)((a>>24)&0xff));
       log(EVDNS_LOG_DEBUG, "Resolve requested for %s (reverse)", buf);
       req = request_new(TYPE_PTR, buf, flags, callback, ptr);
       if (!req) return 1;
       request_submit(req);
       return 0;
}

Here is the call graph for this function:

int evdns_resolve_reverse_ipv6 ( const struct in6_addr in,
int  flags,
evdns_callback_type  callback,
void *  ptr 
)

Definition at line 2640 of file eventdns.c.

                                                                                                              {
       /* 32 nybbles, 32 periods, "ip6.arpa", NUL. */
       char buf[73];
       char *cp;
       struct evdns_request *req;
       int i;
       assert(in);
       cp = buf;
       for (i=15; i >= 0; --i) {
              u8 byte = in->s6_addr[i];
              *cp++ = "0123456789abcdef"[byte & 0x0f];
              *cp++ = '.';
              *cp++ = "0123456789abcdef"[byte >> 4];
              *cp++ = '.';
       }
       assert(cp + strlen("ip6.arpa") < buf+sizeof(buf));
       memcpy(cp, "ip6.arpa", strlen("ip6.arpa")+1);
       log(EVDNS_LOG_DEBUG, "Resolve requested for %s (reverse)", buf);
       req = request_new(TYPE_PTR, buf, flags, callback, ptr);
       if (!req) return 1;
       request_submit(req);
       return 0;
}

Here is the call graph for this function:

int evdns_resume ( void  )

Definition at line 2248 of file eventdns.c.

Here is the call graph for this function:

void evdns_search_add ( const char *  domain)

Definition at line 2770 of file eventdns.c.

                                     {
       search_postfix_add(domain);
}

Here is the call graph for this function:

void evdns_search_clear ( void  )

Definition at line 2728 of file eventdns.c.

Here is the call graph for this function:

void evdns_search_ndots_set ( const int  ndots)

Definition at line 2776 of file eventdns.c.

Here is the call graph for this function:

int evdns_server_request_add_a_reply ( struct evdns_server_request req,
const char *  name,
int  n,
const void *  addrs,
int  ttl 
)

Definition at line 1679 of file eventdns.c.

{
       return evdns_server_request_add_reply(
                req, EVDNS_ANSWER_SECTION, name, TYPE_A, CLASS_INET,
                ttl, n*4, 0, addrs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int evdns_server_request_add_aaaa_reply ( struct evdns_server_request req,
const char *  name,
int  n,
const void *  addrs,
int  ttl 
)

Definition at line 1688 of file eventdns.c.

{
       return evdns_server_request_add_reply(
                req, EVDNS_ANSWER_SECTION, name, TYPE_AAAA, CLASS_INET,
                ttl, n*16, 0, addrs);
}

Here is the call graph for this function:

int evdns_server_request_add_cname_reply ( struct evdns_server_request req,
const char *  name,
const char *  cname,
int  ttl 
)

Definition at line 1719 of file eventdns.c.

{
       return evdns_server_request_add_reply(
                req, EVDNS_ANSWER_SECTION, name, TYPE_CNAME, CLASS_INET,
                ttl, -1, 1, cname);
}

Here is the call graph for this function:

int evdns_server_request_add_ptr_reply ( struct evdns_server_request req,
struct in_addr *  in,
const char *  inaddr_name,
const char *  hostname,
int  ttl 
)

Definition at line 1697 of file eventdns.c.

{
       u32 a;
       char buf[32];
       assert(in || inaddr_name);
       assert(!(in && inaddr_name));
       if (in) {
              a = ntohl(in->s_addr);
              snprintf(buf, sizeof(buf), "%d.%d.%d.%d.in-addr.arpa",
                            (int)(u8)((a  )&0xff),
                            (int)(u8)((a>>8 )&0xff),
                            (int)(u8)((a>>16)&0xff),
                            (int)(u8)((a>>24)&0xff));
              inaddr_name = buf;
       }
       return evdns_server_request_add_reply(
                req, EVDNS_ANSWER_SECTION, inaddr_name, TYPE_PTR, CLASS_INET,
                ttl, -1, 1, hostname);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int evdns_server_request_add_reply ( struct evdns_server_request req,
int  section,
const char *  name,
int  type,
int  class,
int  ttl,
int  datalen,
int  is_name,
const char *  data 
)

Definition at line 1607 of file eventdns.c.

{
       struct server_request *req = TO_SERVER_REQUEST(_req);
       struct server_reply_item **itemp, *item;
       int *countp;

       if (req->response) /* have we already answered? */
              return (-1);

       switch (section) {
       case EVDNS_ANSWER_SECTION:
              itemp = &req->answer;
              countp = &req->n_answer;
              break;
       case EVDNS_AUTHORITY_SECTION:
              itemp = &req->authority;
              countp = &req->n_authority;
              break;
       case EVDNS_ADDITIONAL_SECTION:
              itemp = &req->additional;
              countp = &req->n_additional;
              break;
       default:
              return (-1);
       }
       while (*itemp) {
              itemp = &((*itemp)->next);
       }
       item = mm_malloc(sizeof(struct server_reply_item));
       if (!item)
              return -1;
       CLEAR(item);
       item->next = NULL;
       if (!(item->name = mm_strdup(name))) {
              CLEAR(item);
              mm_free(item);
              return -1;
       }
       item->type = type;
       item->class = class;
       item->ttl = ttl;
       item->is_name = is_name != 0;
       item->datalen = 0;
       item->data = NULL;
       if (data) {
              if (item->is_name) {
                     if (!(item->data = mm_strdup(data))) {
                            mm_free(item->name);
                            CLEAR(item);
                            mm_free(item);
                            return -1;
                     }
                     item->datalen = (u16)-1;
              } else {
                     if (!(item->data = mm_malloc(datalen))) {
                            mm_free(item->name);
                            CLEAR(item);
                            mm_free(item);
                            return -1;
                     }
                     item->datalen = datalen;
                     memcpy(item->data, data, datalen);
              }
       }

       *itemp = item;
       ++(*countp);
       return 0;
}

Here is the caller graph for this function:

Definition at line 1965 of file eventdns.c.

{
       struct server_request *req = TO_SERVER_REQUEST(_req);
       server_request_free(req);
       return 0;
}

Here is the call graph for this function:

int evdns_server_request_get_requesting_addr ( struct evdns_server_request req,
struct sockaddr *  sa,
int  addr_len 
)

Definition at line 1974 of file eventdns.c.

{
       struct server_request *req = TO_SERVER_REQUEST(_req);
       if (addr_len < (int)req->addrlen)
              return -1;
       memcpy(sa, &(req->addr), req->addrlen);
       return req->addrlen;
}

Here is the caller graph for this function:

int evdns_server_request_respond ( struct evdns_server_request req,
int  err 
)

Definition at line 1826 of file eventdns.c.

{
       struct server_request *req = TO_SERVER_REQUEST(_req);
       struct evdns_server_port *port = req->port;
       ssize_t r;
       if (!req->response) {
              if ((r = evdns_server_request_format_response(req, err))<0)
                     return (int)r;
       }

       r = sendto(port->socket, req->response, req->response_len, 0,
                        (struct sockaddr*) &req->addr, req->addrlen);
       if (r<0) {
              int error = last_error(port->socket);
              if (! error_is_eagain(error))
                     return -1;

              if (port->pending_replies) {
                     req->prev_pending = port->pending_replies->prev_pending;
                     req->next_pending = port->pending_replies;
                     req->prev_pending->next_pending =
                            req->next_pending->prev_pending = req;
              } else {
                     req->prev_pending = req->next_pending = req;
                     port->pending_replies = req;
                     port->choked = 1;

                     (void) event_del(&port->event);
                     CLEAR(&port->event);
                     event_set(&port->event, port->socket, (port->closing?0:EV_READ) | EV_WRITE | EV_PERSIST, server_port_ready_callback, port);

                     if (event_add(&port->event, NULL) < 0) {
                            log(EVDNS_LOG_WARN, "Error from libevent when adding event for DNS server");
                     }

              }

              return 1;
       }
       if (server_request_free(req))
              return 0;

       if (port->pending_replies)
              server_port_flush(port);

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void evdns_set_default_outgoing_bind_address ( const struct sockaddr *  addr,
socklen_t  addrlen 
)

Definition at line 2232 of file eventdns.c.

{
       memset(&global_bind_address, 0, sizeof(global_bind_address));
       if (addr) {
              assert(addrlen <= (socklen_t)sizeof(global_bind_address));
              memcpy(&global_bind_address, addr, addrlen);
              global_bind_addrlen = addrlen;
              global_bind_addr_is_set = 1;
       } else {
              global_bind_addr_is_set = 0;
       }
}

Definition at line 415 of file eventdns.c.

{
       evdns_log_fn = fn;
}

Here is the caller graph for this function:

int evdns_set_option ( const char *  option,
const char *  val,
int  flags 
)

Definition at line 2948 of file eventdns.c.

{
       if (!strncmp(option, "ndots:", 6)) {
              const int ndots = strtoint(val);
              if (ndots == -1) return -1;
              if (!(flags & DNS_OPTION_SEARCH)) return 0;
              log(EVDNS_LOG_DEBUG, "Setting ndots to %d", ndots);
              if (!global_search_state) global_search_state = search_state_new();
              if (!global_search_state) return -1;
              global_search_state->ndots = ndots;
       } else if (!strncmp(option, "timeout:", 8)) {
              const int timeout = strtoint(val);
              if (timeout == -1) return -1;
              if (!(flags & DNS_OPTION_MISC)) return 0;
              log(EVDNS_LOG_DEBUG, "Setting timeout to %d", timeout);
              global_timeout.tv_sec = timeout;
       } else if (!strncmp(option, "max-timeouts:", 12)) {
              const int maxtimeout = strtoint_clipped(val, 1, 255);
              if (maxtimeout == -1) return -1;
              if (!(flags & DNS_OPTION_MISC)) return 0;
              log(EVDNS_LOG_DEBUG, "Setting maximum allowed timeouts to %d",
                     maxtimeout);
              global_max_nameserver_timeout = maxtimeout;
       } else if (!strncmp(option, "max-inflight:", 13)) {
              const int maxinflight = strtoint_clipped(val, 1, 65000);
              if (maxinflight == -1) return -1;
              if (!(flags & DNS_OPTION_MISC)) return 0;
              log(EVDNS_LOG_DEBUG, "Setting maximum inflight requests to %d",
                     maxinflight);
              global_max_requests_inflight = maxinflight;
       } else if (!strncmp(option, "attempts:", 9)) {
              int retries = strtoint(val);
              if (retries == -1) return -1;
              if (retries > 255) retries = 255;
              if (!(flags & DNS_OPTION_MISC)) return 0;
              log(EVDNS_LOG_DEBUG, "Setting retries to %d", retries);
              global_max_retransmits = retries;
       } else if (!strncmp(option, "randomize-case:", 15)) {
              int randcase = strtoint(val);
              if (!(flags & DNS_OPTION_MISC)) return 0;
              log(EVDNS_LOG_DEBUG, "Setting randomize_case to %d", randcase);
              global_randomize_case = randcase;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void evdns_set_random_bytes_fn ( void(*)(char *, size_t)  fn)

Definition at line 1182 of file eventdns.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evdns_set_transaction_id_fn ( uint16_t(*)(void)  fn)

Definition at line 1172 of file eventdns.c.

Here is the call graph for this function:

void evdns_shutdown ( int  fail_requests)

Definition at line 3342 of file eventdns.c.

{
       struct nameserver *server, *server_next;
       struct search_domain *dom, *dom_next;

       while (req_head) {
              if (fail_requests)
                     reply_callback(req_head, 0, DNS_ERR_SHUTDOWN, NULL);
              request_finished(req_head, &req_head);
       }
       while (req_waiting_head) {
              if (fail_requests)
                     reply_callback(req_waiting_head, 0, DNS_ERR_SHUTDOWN, NULL);
              request_finished(req_waiting_head, &req_waiting_head);
       }
       global_requests_inflight = global_requests_waiting = 0;

       for (server = server_head; server; server = server_next) {
              server_next = server->next;
              if (server->socket >= 0)
                     CLOSE_SOCKET(server->socket);
              (void) event_del(&server->event);
              del_timeout_event(server);
              CLEAR(server);
              mm_free(server);
              if (server_next == server_head)
                     break;
       }
       server_head = NULL;
       global_good_nameservers = 0;

       if (global_search_state) {
              for (dom = global_search_state->head; dom; dom = dom_next) {
                     dom_next = dom->next;
                     CLEAR(dom);
                     mm_free(dom);
              }
              CLEAR(global_search_state);
              mm_free(global_search_state);
              global_search_state = NULL;
       }
       evdns_log_fn = NULL;
}