2 * Copyright (c) 2003-2007 Niels Provos <provos@citi.umich.edu>
3 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "../util-internal.h"
35 #include "event2/event-config.h"
37 #include <sys/types.h>
39 #ifdef EVENT__HAVE_SYS_TIME_H
42 #include <sys/queue.h>
44 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
50 #ifdef EVENT__HAVE_NETINET_IN6_H
51 #include <netinet/in6.h>
62 #include "event2/dns.h"
63 #include "event2/dns_compat.h"
64 #include "event2/dns_struct.h"
65 #include "event2/event.h"
66 #include "event2/event_compat.h"
67 #include "event2/event_struct.h"
68 #include "event2/util.h"
69 #include "event2/listener.h"
70 #include "event2/bufferevent.h"
71 #include "log-internal.h"
73 #include "regress_testutils.h"
75 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
77 static int dns_ok = 0;
78 static int dns_got_cancel = 0;
79 static int dns_err = 0;
83 dns_gethostbyname_cb(int result, char type, int count, int ttl,
84 void *addresses, void *arg)
88 if (result == DNS_ERR_TIMEOUT) {
89 printf("[Timed out] ");
94 if (result != DNS_ERR_NONE) {
95 printf("[Error code %d] ", result);
99 TT_BLATHER(("type: %d, count: %d, ttl: %d: ", type, count, ttl));
102 case DNS_IPv6_AAAA: {
103 #if defined(EVENT__HAVE_STRUCT_IN6_ADDR) && defined(EVENT__HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN)
104 struct in6_addr *in6_addrs = addresses;
105 char buf[INET6_ADDRSTRLEN+1];
107 /* a resolution that's not valid does not help */
110 for (i = 0; i < count; ++i) {
111 const char *b = evutil_inet_ntop(AF_INET6, &in6_addrs[i], buf,sizeof(buf));
113 TT_BLATHER(("%s ", b));
115 TT_BLATHER(("%s ", strerror(errno)));
121 struct in_addr *in_addrs = addresses;
123 /* a resolution that's not valid does not help */
126 for (i = 0; i < count; ++i)
127 TT_BLATHER(("%s ", inet_ntoa(in_addrs[i])));
131 /* may get at most one PTR */
135 TT_BLATHER(("%s ", *(char **)addresses));
145 event_loopexit(NULL);
147 event_base_loopexit((struct event_base *)arg, NULL);
151 dns_gethostbyname(void)
154 evdns_resolve_ipv4("www.monkey.org", 0, dns_gethostbyname_cb, NULL);
157 tt_int_op(dns_ok, ==, DNS_IPv4_A);
164 dns_gethostbyname6(void)
167 evdns_resolve_ipv6("www.ietf.org", 0, dns_gethostbyname_cb, NULL);
170 if (!dns_ok && dns_err == DNS_ERR_TIMEOUT) {
174 tt_int_op(dns_ok, ==, DNS_IPv6_AAAA);
181 dns_gethostbyaddr(void)
184 in.s_addr = htonl(0x7f000001ul); /* 127.0.0.1 */
186 evdns_resolve_reverse(&in, 0, dns_gethostbyname_cb, NULL);
189 tt_int_op(dns_ok, ==, DNS_PTR);
196 dns_resolve_reverse(void *ptr)
199 struct event_base *base = event_base_new();
200 struct evdns_base *dns = evdns_base_new(base, 1/* init name servers */);
201 struct evdns_request *req = NULL;
205 in.s_addr = htonl(0x7f000001ul); /* 127.0.0.1 */
208 req = evdns_base_resolve_reverse(
209 dns, &in, 0, dns_gethostbyname_cb, base);
212 event_base_dispatch(base);
214 tt_int_op(dns_ok, ==, DNS_PTR);
218 evdns_base_free(dns, 0);
220 event_base_free(base);
223 static int n_server_responses = 0;
226 dns_server_request_cb(struct evdns_server_request *req, void *data)
229 const char TEST_ARPA[] = "11.11.168.192.in-addr.arpa";
230 const char TEST_IN6[] =
231 "f.e.f.e." "0.0.0.0." "0.0.0.0." "1.1.1.1."
232 "a.a.a.a." "0.0.0.0." "0.0.0.0." "0.f.f.f.ip6.arpa";
234 for (i = 0; i < req->nquestions; ++i) {
235 const int qtype = req->questions[i]->type;
236 const int qclass = req->questions[i]->dns_question_class;
237 const char *qname = req->questions[i]->name;
240 ans.s_addr = htonl(0xc0a80b0bUL); /* 192.168.11.11 */
241 if (qtype == EVDNS_TYPE_A &&
242 qclass == EVDNS_CLASS_INET &&
243 !evutil_ascii_strcasecmp(qname, "zz.example.com")) {
244 r = evdns_server_request_add_a_reply(req, qname,
245 1, &ans.s_addr, 12345);
248 } else if (qtype == EVDNS_TYPE_AAAA &&
249 qclass == EVDNS_CLASS_INET &&
250 !evutil_ascii_strcasecmp(qname, "zz.example.com")) {
251 char addr6[17] = "abcdefghijklmnop";
252 r = evdns_server_request_add_aaaa_reply(req,
253 qname, 1, addr6, 123);
256 } else if (qtype == EVDNS_TYPE_PTR &&
257 qclass == EVDNS_CLASS_INET &&
258 !evutil_ascii_strcasecmp(qname, TEST_ARPA)) {
259 r = evdns_server_request_add_ptr_reply(req, NULL,
260 qname, "ZZ.EXAMPLE.COM", 54321);
263 } else if (qtype == EVDNS_TYPE_PTR &&
264 qclass == EVDNS_CLASS_INET &&
265 !evutil_ascii_strcasecmp(qname, TEST_IN6)){
266 r = evdns_server_request_add_ptr_reply(req, NULL,
268 "ZZ-INET6.EXAMPLE.COM", 54322);
271 } else if (qtype == EVDNS_TYPE_A &&
272 qclass == EVDNS_CLASS_INET &&
273 !evutil_ascii_strcasecmp(qname, "drop.example.com")) {
274 if (evdns_server_request_drop(req)<0)
278 printf("Unexpected question %d %d \"%s\" ",
279 qtype, qclass, qname);
283 r = evdns_server_request_respond(req, 0);
285 printf("Couldn't send reply. ");
291 dns_server_gethostbyname_cb(int result, char type, int count, int ttl,
292 void *addresses, void *arg)
294 if (result == DNS_ERR_CANCEL) {
295 if (arg != (void*)(char*)90909) {
296 printf("Unexpected cancelation");
302 if (result != DNS_ERR_NONE) {
303 printf("Unexpected result %d. ", result);
308 printf("Unexpected answer count %d. ", count);
314 struct in_addr *in_addrs = addresses;
315 if (in_addrs[0].s_addr != htonl(0xc0a80b0bUL) || ttl != 12345) {
316 printf("Bad IPv4 response \"%s\" %d. ",
317 inet_ntoa(in_addrs[0]), ttl);
323 case DNS_IPv6_AAAA: {
324 #if defined (EVENT__HAVE_STRUCT_IN6_ADDR) && defined(EVENT__HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN)
325 struct in6_addr *in6_addrs = addresses;
326 char buf[INET6_ADDRSTRLEN+1];
327 if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16)
329 const char *b = evutil_inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf));
330 printf("Bad IPv6 response \"%s\" %d. ", b, ttl);
338 char **addrs = addresses;
339 if (arg != (void*)6) {
340 if (strcmp(addrs[0], "ZZ.EXAMPLE.COM") ||
342 printf("Bad PTR response \"%s\" %d. ",
348 if (strcmp(addrs[0], "ZZ-INET6.EXAMPLE.COM") ||
350 printf("Bad ipv6 PTR response \"%s\" %d. ",
359 printf("Bad response type %d. ", type);
363 if (++n_server_responses == 3) {
364 event_loopexit(NULL);
371 evutil_socket_t sock=-1;
372 struct sockaddr_in my_addr;
373 struct sockaddr_storage ss;
375 struct evdns_server_port *port=NULL;
376 struct in_addr resolve_addr;
377 struct in6_addr resolve_addr6;
378 struct evdns_base *base=NULL;
379 struct evdns_request *req=NULL;
383 base = evdns_base_new(NULL, 0);
385 /* Now configure a nameserver port. */
386 sock = socket(AF_INET, SOCK_DGRAM, 0);
388 tt_abort_perror("socket");
391 evutil_make_socket_nonblocking(sock);
393 memset(&my_addr, 0, sizeof(my_addr));
394 my_addr.sin_family = AF_INET;
395 my_addr.sin_port = 0; /* kernel picks */
396 my_addr.sin_addr.s_addr = htonl(0x7f000001UL);
397 if (bind(sock, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0) {
398 tt_abort_perror("bind");
401 if (getsockname(sock, (struct sockaddr*)&ss, &slen) < 0) {
402 tt_abort_perror("getsockname");
405 port = evdns_add_server_port(sock, 0, dns_server_request_cb, NULL);
407 /* Add ourself as the only nameserver, and make sure we really are
408 * the only nameserver. */
409 evdns_base_nameserver_sockaddr_add(base, (struct sockaddr*)&ss, slen, 0);
410 tt_int_op(evdns_base_count_nameservers(base), ==, 1);
412 struct sockaddr_storage ss2;
415 memset(&ss2, 0, sizeof(ss2));
417 slen2 = evdns_base_get_nameserver_addr(base, 0, (struct sockaddr *)&ss2, 3);
418 tt_int_op(slen2, ==, slen);
419 tt_int_op(ss2.ss_family, ==, 0);
420 slen2 = evdns_base_get_nameserver_addr(base, 0, (struct sockaddr *)&ss2, sizeof(ss2));
421 tt_int_op(slen2, ==, slen);
422 tt_mem_op(&ss2, ==, &ss, slen);
424 slen2 = evdns_base_get_nameserver_addr(base, 1, (struct sockaddr *)&ss2, sizeof(ss2));
425 tt_int_op(-1, ==, slen2);
428 /* Send some queries. */
429 evdns_base_resolve_ipv4(base, "zz.example.com", DNS_QUERY_NO_SEARCH,
430 dns_server_gethostbyname_cb, NULL);
431 evdns_base_resolve_ipv6(base, "zz.example.com", DNS_QUERY_NO_SEARCH,
432 dns_server_gethostbyname_cb, NULL);
433 resolve_addr.s_addr = htonl(0xc0a80b0bUL); /* 192.168.11.11 */
434 evdns_base_resolve_reverse(base, &resolve_addr, 0,
435 dns_server_gethostbyname_cb, NULL);
436 memcpy(resolve_addr6.s6_addr,
437 "\xff\xf0\x00\x00\x00\x00\xaa\xaa"
438 "\x11\x11\x00\x00\x00\x00\xef\xef", 16);
439 evdns_base_resolve_reverse_ipv6(base, &resolve_addr6, 0,
440 dns_server_gethostbyname_cb, (void*)6);
442 req = evdns_base_resolve_ipv4(base,
443 "drop.example.com", DNS_QUERY_NO_SEARCH,
444 dns_server_gethostbyname_cb, (void*)(char*)90909);
446 evdns_cancel_request(base, req);
450 tt_assert(dns_got_cancel);
455 evdns_close_server_port(port);
457 evutil_closesocket(sock);
459 evdns_base_free(base, 0);
462 static int n_replies_left;
463 static struct event_base *exit_base;
464 static struct evdns_server_port *exit_port;
466 struct generic_dns_callback_result {
477 generic_dns_callback(int result, char type, int count, int ttl, void *addresses,
481 struct generic_dns_callback_result *res = arg;
482 res->result = result;
487 if (type == DNS_IPv4_A)
489 else if (type == DNS_IPv6_AAAA)
491 else if (type == DNS_PTR)
492 len = strlen(addresses)+1;
494 res->addrs_len = len = 0;
498 res->addrs_len = len;
501 memcpy(res->addrs_buf, addresses, len);
502 res->addrs = res->addrs_buf;
506 if (n_replies_left == 0) {
508 evdns_close_server_port(exit_port);
511 event_base_loopexit(exit_base, NULL);
515 static struct regress_dns_server_table search_table[] = {
516 { "host.a.example.com", "err", "3", 0, 0 },
517 { "host.b.example.com", "err", "3", 0, 0 },
518 { "host.c.example.com", "A", "11.22.33.44", 0, 0 },
519 { "host2.a.example.com", "err", "3", 0, 0 },
520 { "host2.b.example.com", "A", "200.100.0.100", 0, 0 },
521 { "host2.c.example.com", "err", "3", 0, 0 },
522 { "hostn.a.example.com", "errsoa", "0", 0, 0 },
523 { "hostn.b.example.com", "errsoa", "3", 0, 0 },
524 { "hostn.c.example.com", "err", "0", 0, 0 },
526 { "host", "err", "3", 0, 0 },
527 { "host2", "err", "3", 0, 0 },
528 { "*", "err", "3", 0, 0 },
529 { NULL, NULL, NULL, 0, 0 }
532 dns_search_test_impl(void *arg, int lower)
534 struct regress_dns_server_table table[ARRAY_SIZE(search_table)];
535 struct basic_test_data *data = arg;
536 struct event_base *base = data->base;
537 struct evdns_base *dns = NULL;
538 ev_uint16_t portnum = 0;
541 struct generic_dns_callback_result r[8];
544 for (i = 0; i < ARRAY_SIZE(table); ++i) {
545 table[i] = search_table[i];
546 table[i].lower = lower;
549 tt_assert(regress_dnsserver(base, &portnum, table));
550 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
552 dns = evdns_base_new(base, 0);
553 tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
555 evdns_base_search_add(dns, "a.example.com");
556 evdns_base_search_add(dns, "b.example.com");
557 evdns_base_search_add(dns, "c.example.com");
559 n_replies_left = ARRAY_SIZE(r);
562 evdns_base_resolve_ipv4(dns, "host", 0, generic_dns_callback, &r[0]);
563 evdns_base_resolve_ipv4(dns, "host2", 0, generic_dns_callback, &r[1]);
564 evdns_base_resolve_ipv4(dns, "host", DNS_NO_SEARCH, generic_dns_callback, &r[2]);
565 evdns_base_resolve_ipv4(dns, "host2", DNS_NO_SEARCH, generic_dns_callback, &r[3]);
566 evdns_base_resolve_ipv4(dns, "host3", 0, generic_dns_callback, &r[4]);
567 evdns_base_resolve_ipv4(dns, "hostn.a.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[5]);
568 evdns_base_resolve_ipv4(dns, "hostn.b.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[6]);
569 evdns_base_resolve_ipv4(dns, "hostn.c.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[7]);
571 event_base_dispatch(base);
573 tt_int_op(r[0].type, ==, DNS_IPv4_A);
574 tt_int_op(r[0].count, ==, 1);
575 tt_int_op(((ev_uint32_t*)r[0].addrs)[0], ==, htonl(0x0b16212c));
576 tt_int_op(r[1].type, ==, DNS_IPv4_A);
577 tt_int_op(r[1].count, ==, 1);
578 tt_int_op(((ev_uint32_t*)r[1].addrs)[0], ==, htonl(0xc8640064));
579 tt_int_op(r[2].result, ==, DNS_ERR_NOTEXIST);
580 tt_int_op(r[3].result, ==, DNS_ERR_NOTEXIST);
581 tt_int_op(r[4].result, ==, DNS_ERR_NOTEXIST);
582 tt_int_op(r[5].result, ==, DNS_ERR_NODATA);
583 tt_int_op(r[5].ttl, ==, 42);
584 tt_int_op(r[6].result, ==, DNS_ERR_NOTEXIST);
585 tt_int_op(r[6].ttl, ==, 42);
586 tt_int_op(r[7].result, ==, DNS_ERR_NODATA);
587 tt_int_op(r[7].ttl, ==, 0);
591 evdns_base_free(dns, 0);
593 regress_clean_dnsserver();
596 dns_search_empty_test(void *arg)
598 struct basic_test_data *data = arg;
599 struct event_base *base = data->base;
600 struct evdns_base *dns = NULL;
602 dns = evdns_base_new(base, 0);
604 evdns_base_search_add(dns, "whatever.example.com");
609 tt_ptr_op(evdns_base_resolve_ipv4(dns, "", 0, generic_dns_callback, NULL), ==, NULL);
613 evdns_base_free(dns, 0);
616 dns_search_test(void *arg)
618 return dns_search_test_impl(arg, 0);
621 dns_search_lower_test(void *arg)
623 return dns_search_test_impl(arg, 1);
626 static int request_count = 0;
627 static struct evdns_request *current_req = NULL;
630 search_cancel_server_cb(struct evdns_server_request *req, void *data)
632 const char *question;
634 if (req->nquestions != 1)
635 TT_DIE(("Only handling one question at a time; got %d",
638 question = req->questions[0]->name;
640 TT_BLATHER(("got question, %s", question));
642 tt_assert(request_count > 0);
643 tt_assert(!evdns_server_request_respond(req, 3));
645 if (!--request_count)
646 evdns_cancel_request(NULL, current_req);
653 dns_search_cancel_test(void *arg)
655 struct basic_test_data *data = arg;
656 struct event_base *base = data->base;
657 struct evdns_base *dns = NULL;
658 struct evdns_server_port *port = NULL;
659 ev_uint16_t portnum = 0;
660 struct generic_dns_callback_result r1;
663 port = regress_get_dnsserver(base, &portnum, NULL,
664 search_cancel_server_cb, NULL);
666 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
668 dns = evdns_base_new(base, 0);
669 tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
671 evdns_base_search_add(dns, "a.example.com");
672 evdns_base_search_add(dns, "b.example.com");
673 evdns_base_search_add(dns, "c.example.com");
674 evdns_base_search_add(dns, "d.example.com");
680 current_req = evdns_base_resolve_ipv4(dns, "host", 0,
681 generic_dns_callback, &r1);
682 event_base_dispatch(base);
684 tt_int_op(r1.result, ==, DNS_ERR_CANCEL);
688 evdns_close_server_port(port);
690 evdns_base_free(dns, 0);
694 fail_server_cb(struct evdns_server_request *req, void *data)
696 const char *question;
700 /* Drop the first N requests that we get. */
703 tt_want(! evdns_server_request_drop(req));
707 if (req->nquestions != 1)
708 TT_DIE(("Only handling one question at a time; got %d",
711 question = req->questions[0]->name;
713 if (!evutil_ascii_strcasecmp(question, "google.com")) {
714 /* Detect a probe, and get out of the loop. */
715 event_base_loopexit(exit_base, NULL);
718 tt_assert(evutil_inet_pton(AF_INET, "16.32.64.128", &in));
719 evdns_server_request_add_a_reply(req, question, 1, &in.s_addr,
721 tt_assert(! evdns_server_request_respond(req, 0))
724 tt_want(! evdns_server_request_drop(req));
728 dns_retry_test_impl(void *arg, int flags)
730 struct basic_test_data *data = arg;
731 struct event_base *base = data->base;
732 struct evdns_server_port *port = NULL;
733 struct evdns_base *dns = NULL;
735 ev_uint16_t portnum = 0;
738 struct generic_dns_callback_result r1;
740 port = regress_get_dnsserver(base, &portnum, NULL,
741 fail_server_cb, &drop_count);
743 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
745 dns = evdns_base_new(base, flags);
746 tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
747 tt_assert(! evdns_base_set_option(dns, "timeout", "0.2"));
748 tt_assert(! evdns_base_set_option(dns, "max-timeouts:", "10"));
749 tt_assert(! evdns_base_set_option(dns, "initial-probe-timeout", "0.1"));
751 evdns_base_resolve_ipv4(dns, "host.example.com", 0,
752 generic_dns_callback, &r1);
757 event_base_dispatch(base);
759 tt_int_op(drop_count, ==, 0);
761 tt_int_op(r1.type, ==, DNS_IPv4_A);
762 tt_int_op(r1.count, ==, 1);
763 tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0x10204080));
765 /* Now try again, but this time have the server get treated as
766 * failed, so we can send it a test probe. */
768 tt_assert(! evdns_base_set_option(dns, "max-timeouts:", "2"));
769 tt_assert(! evdns_base_set_option(dns, "attempts:", "3"));
770 memset(&r1, 0, sizeof(r1));
772 evdns_base_resolve_ipv4(dns, "host.example.com", 0,
773 generic_dns_callback, &r1);
777 /* This will run until it answers the "google.com" probe request. */
778 event_base_dispatch(base);
780 /* We'll treat the server as failed here. */
781 tt_int_op(r1.result, ==, DNS_ERR_TIMEOUT);
783 /* It should work this time. */
784 tt_int_op(drop_count, ==, 0);
785 evdns_base_resolve_ipv4(dns, "host.example.com", 0,
786 generic_dns_callback, &r1);
788 event_base_dispatch(base);
789 tt_int_op(r1.result, ==, DNS_ERR_NONE);
790 tt_int_op(r1.type, ==, DNS_IPv4_A);
791 tt_int_op(r1.count, ==, 1);
792 tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0x10204080));
796 evdns_base_free(dns, 0);
798 evdns_close_server_port(port);
801 dns_retry_test(void *arg)
803 dns_retry_test_impl(arg, 0);
806 dns_retry_disable_when_inactive_test(void *arg)
808 dns_retry_test_impl(arg, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
811 static struct regress_dns_server_table internal_error_table[] = {
812 /* Error 4 (NOTIMPL) makes us reissue the request to another server
815 XXXX we should reissue under a much wider set of circumstances!
817 { "foof.example.com", "err", "4", 0, 0 },
818 { NULL, NULL, NULL, 0, 0 }
821 static struct regress_dns_server_table reissue_table[] = {
822 { "foof.example.com", "A", "240.15.240.15", 0, 0 },
823 { NULL, NULL, NULL, 0, 0 }
827 dns_reissue_test_impl(void *arg, int flags)
829 struct basic_test_data *data = arg;
830 struct event_base *base = data->base;
831 struct evdns_server_port *port1 = NULL, *port2 = NULL;
832 struct evdns_base *dns = NULL;
833 struct generic_dns_callback_result r1;
834 ev_uint16_t portnum1 = 0, portnum2=0;
835 char buf1[64], buf2[64];
837 port1 = regress_get_dnsserver(base, &portnum1, NULL,
838 regress_dns_server_cb, internal_error_table);
840 port2 = regress_get_dnsserver(base, &portnum2, NULL,
841 regress_dns_server_cb, reissue_table);
843 evutil_snprintf(buf1, sizeof(buf1), "127.0.0.1:%d", (int)portnum1);
844 evutil_snprintf(buf2, sizeof(buf2), "127.0.0.1:%d", (int)portnum2);
846 dns = evdns_base_new(base, flags);
847 tt_assert(!evdns_base_nameserver_ip_add(dns, buf1));
848 tt_assert(! evdns_base_set_option(dns, "timeout:", "0.3"));
849 tt_assert(! evdns_base_set_option(dns, "max-timeouts:", "2"));
850 tt_assert(! evdns_base_set_option(dns, "attempts:", "5"));
852 memset(&r1, 0, sizeof(r1));
853 evdns_base_resolve_ipv4(dns, "foof.example.com", 0,
854 generic_dns_callback, &r1);
856 /* Add this after, so that we are sure to get a reissue. */
857 tt_assert(!evdns_base_nameserver_ip_add(dns, buf2));
862 event_base_dispatch(base);
863 tt_int_op(r1.result, ==, DNS_ERR_NONE);
864 tt_int_op(r1.type, ==, DNS_IPv4_A);
865 tt_int_op(r1.count, ==, 1);
866 tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0xf00ff00f));
868 /* Make sure we dropped at least once. */
869 tt_int_op(internal_error_table[0].seen, >, 0);
873 evdns_base_free(dns, 0);
875 evdns_close_server_port(port1);
877 evdns_close_server_port(port2);
880 dns_reissue_test(void *arg)
882 dns_reissue_test_impl(arg, 0);
885 dns_reissue_disable_when_inactive_test(void *arg)
887 dns_reissue_test_impl(arg, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
892 dumb_bytes_fn(char *p, size_t n)
895 /* This gets us 6 bits of entropy per transaction ID, which means we
896 * will have probably have collisions and need to pick again. */
898 p[i] = (char)(rand() & 7);
903 dns_inflight_test_impl(void *arg, int flags)
905 struct basic_test_data *data = arg;
906 struct event_base *base = data->base;
907 struct evdns_base *dns = NULL;
908 struct evdns_server_port *dns_port = NULL;
909 ev_uint16_t portnum = 0;
911 int disable_when_inactive = flags & EVDNS_BASE_DISABLE_WHEN_INACTIVE;
913 struct generic_dns_callback_result r[20];
916 dns_port = regress_get_dnsserver(base, &portnum, NULL,
917 regress_dns_server_cb, reissue_table);
919 if (disable_when_inactive) {
920 exit_port = dns_port;
923 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
925 dns = evdns_base_new(base, flags);
926 tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
927 tt_assert(! evdns_base_set_option(dns, "max-inflight:", "3"));
928 tt_assert(! evdns_base_set_option(dns, "randomize-case:", "0"));
931 evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r[i]);
936 event_base_dispatch(base);
939 tt_int_op(r[i].type, ==, DNS_IPv4_A);
940 tt_int_op(r[i].count, ==, 1);
941 tt_int_op(((ev_uint32_t*)r[i].addrs)[0], ==, htonl(0xf00ff00f));
946 evdns_base_free(dns, 0);
948 evdns_close_server_port(exit_port);
950 } else if (! disable_when_inactive) {
951 evdns_close_server_port(dns_port);
956 dns_inflight_test(void *arg)
958 dns_inflight_test_impl(arg, 0);
962 dns_disable_when_inactive_test(void *arg)
964 dns_inflight_test_impl(arg, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
968 dns_disable_when_inactive_no_ns_test(void *arg)
970 struct basic_test_data *data = arg;
971 struct event_base *base = data->base, *inactive_base;
972 struct evdns_base *dns = NULL;
973 ev_uint16_t portnum = 0;
975 struct generic_dns_callback_result r;
977 inactive_base = event_base_new();
978 tt_assert(inactive_base);
980 /** Create dns server with inactive base, to avoid replying to clients */
981 tt_assert(regress_dnsserver(inactive_base, &portnum, search_table));
982 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
984 dns = evdns_base_new(base, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
985 tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
986 tt_assert(! evdns_base_set_option(dns, "timeout:", "0.1"));
988 evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r);
992 event_base_dispatch(base);
994 tt_int_op(n_replies_left, ==, 0);
996 tt_int_op(r.result, ==, DNS_ERR_TIMEOUT);
997 tt_int_op(r.count, ==, 0);
998 tt_ptr_op(r.addrs, ==, NULL);
1002 evdns_base_free(dns, 0);
1003 regress_clean_dnsserver();
1005 event_base_free(inactive_base);
1008 /* === Test for bufferevent_socket_connect_hostname */
1010 static int total_connected_or_failed = 0;
1011 static int total_n_accepted = 0;
1012 static struct event_base *be_connect_hostname_base = NULL;
1014 /* Implements a DNS server for the connect_hostname test and the
1015 * getaddrinfo_async test */
1017 be_getaddrinfo_server_cb(struct evdns_server_request *req, void *data)
1024 for (i=0;i<req->nquestions;++i) {
1025 const int qtype = req->questions[i]->type;
1026 const int qclass = req->questions[i]->dns_question_class;
1027 const char *qname = req->questions[i]->name;
1029 struct in6_addr ans6;
1030 memset(&ans6, 0, sizeof(ans6));
1032 TT_BLATHER(("Got question about %s, type=%d", qname, qtype));
1034 if (qtype == EVDNS_TYPE_A &&
1035 qclass == EVDNS_CLASS_INET &&
1036 !evutil_ascii_strcasecmp(qname, "nobodaddy.example.com")) {
1037 ans.s_addr = htonl(0x7f000001);
1038 evdns_server_request_add_a_reply(req, qname,
1039 1, &ans.s_addr, 2000);
1041 } else if (!evutil_ascii_strcasecmp(qname,
1042 "nosuchplace.example.com")) {
1043 /* ok, just say notfound. */
1044 } else if (!evutil_ascii_strcasecmp(qname,
1045 "both.example.com")) {
1046 if (qtype == EVDNS_TYPE_A) {
1047 ans.s_addr = htonl(0x50502020);
1048 evdns_server_request_add_a_reply(req, qname,
1049 1, &ans.s_addr, 2000);
1051 } else if (qtype == EVDNS_TYPE_AAAA) {
1052 ans6.s6_addr[0] = 0x80;
1053 ans6.s6_addr[1] = 0xff;
1054 ans6.s6_addr[14] = 0xbb;
1055 ans6.s6_addr[15] = 0xbb;
1056 evdns_server_request_add_aaaa_reply(req, qname,
1057 1, &ans6.s6_addr, 2000);
1060 evdns_server_request_add_cname_reply(req, qname,
1061 "both-canonical.example.com", 1000);
1062 } else if (!evutil_ascii_strcasecmp(qname,
1063 "v4only.example.com") ||
1064 !evutil_ascii_strcasecmp(qname, "v4assert.example.com")) {
1065 if (qtype == EVDNS_TYPE_A) {
1066 ans.s_addr = htonl(0x12345678);
1067 evdns_server_request_add_a_reply(req, qname,
1068 1, &ans.s_addr, 2000);
1070 } else if (!evutil_ascii_strcasecmp(qname,
1071 "v4assert.example.com")) {
1072 TT_FAIL(("Got an AAAA request for v4assert"));
1074 } else if (!evutil_ascii_strcasecmp(qname,
1075 "v6only.example.com") ||
1076 !evutil_ascii_strcasecmp(qname, "v6assert.example.com")) {
1077 if (qtype == EVDNS_TYPE_AAAA) {
1078 ans6.s6_addr[0] = 0x0b;
1079 ans6.s6_addr[1] = 0x0b;
1080 ans6.s6_addr[14] = 0xf0;
1081 ans6.s6_addr[15] = 0x0d;
1082 evdns_server_request_add_aaaa_reply(req, qname,
1083 1, &ans6.s6_addr, 2000);
1085 } else if (!evutil_ascii_strcasecmp(qname,
1086 "v6assert.example.com")) {
1087 TT_FAIL(("Got a A request for v6assert"));
1089 } else if (!evutil_ascii_strcasecmp(qname,
1090 "v6timeout.example.com")) {
1091 if (qtype == EVDNS_TYPE_A) {
1092 ans.s_addr = htonl(0xabcdef01);
1093 evdns_server_request_add_a_reply(req, qname,
1094 1, &ans.s_addr, 2000);
1096 } else if (qtype == EVDNS_TYPE_AAAA) {
1097 /* Let the v6 request time out.*/
1098 evdns_server_request_drop(req);
1101 } else if (!evutil_ascii_strcasecmp(qname,
1102 "v4timeout.example.com")) {
1103 if (qtype == EVDNS_TYPE_AAAA) {
1104 ans6.s6_addr[0] = 0x0a;
1105 ans6.s6_addr[1] = 0x0a;
1106 ans6.s6_addr[14] = 0xff;
1107 ans6.s6_addr[15] = 0x01;
1108 evdns_server_request_add_aaaa_reply(req, qname,
1109 1, &ans6.s6_addr, 2000);
1111 } else if (qtype == EVDNS_TYPE_A) {
1112 /* Let the v4 request time out.*/
1113 evdns_server_request_drop(req);
1116 } else if (!evutil_ascii_strcasecmp(qname,
1117 "v6timeout-nonexist.example.com")) {
1118 if (qtype == EVDNS_TYPE_A) {
1119 /* Fall through, give an nexist. */
1120 } else if (qtype == EVDNS_TYPE_AAAA) {
1121 /* Let the v6 request time out.*/
1122 evdns_server_request_drop(req);
1125 } else if (!evutil_ascii_strcasecmp(qname,
1126 "all-timeout.example.com")) {
1127 /* drop all requests */
1128 evdns_server_request_drop(req);
1131 TT_GRIPE(("Got weird request for %s",qname));
1135 TT_BLATHER(("answering"));
1136 evdns_server_request_respond(req, 0);
1138 TT_BLATHER(("saying nexist."));
1139 evdns_server_request_respond(req, 3);
1143 /* Implements a listener for connect_hostname test. */
1145 nil_accept_cb(struct evconnlistener *l, evutil_socket_t fd, struct sockaddr *s,
1146 int socklen, void *arg)
1151 /* don't do anything with the socket; let it close when we exit() */
1152 if (total_n_accepted >= 3 && total_connected_or_failed >= 5)
1153 event_base_loopexit(be_connect_hostname_base,
1157 struct be_conn_hostname_result {
1162 /* Bufferevent event callback for the connect_hostname test: remembers what
1165 be_connect_hostname_event_cb(struct bufferevent *bev, short what, void *ctx)
1167 struct be_conn_hostname_result *got = ctx;
1169 TT_BLATHER(("Got a bufferevent event %d", what));
1172 if ((what & BEV_EVENT_CONNECTED) || (what & BEV_EVENT_ERROR)) {
1174 if ((r = bufferevent_socket_get_dns_error(bev))) {
1176 TT_BLATHER(("DNS error %d: %s", r,
1177 evutil_gai_strerror(r)));
1178 } ++total_connected_or_failed;
1179 TT_BLATHER(("Got %d connections or errors.", total_connected_or_failed));
1181 if (total_n_accepted >= 3 && total_connected_or_failed >= 5)
1182 event_base_loopexit(be_connect_hostname_base,
1186 TT_FAIL(("Two events on one bufferevent. %d,%d",
1187 got->what, (int)what));
1192 test_bufferevent_connect_hostname(void *arg)
1194 struct basic_test_data *data = arg;
1195 struct evconnlistener *listener = NULL;
1196 struct bufferevent *be1=NULL, *be2=NULL, *be3=NULL, *be4=NULL, *be5=NULL;
1197 struct be_conn_hostname_result be1_outcome={0,0}, be2_outcome={0,0},
1198 be3_outcome={0,0}, be4_outcome={0,0}, be5_outcome={0,0};
1200 struct evdns_base *dns=NULL;
1201 struct evdns_server_port *port=NULL;
1202 struct sockaddr_in sin;
1203 int listener_port=-1;
1204 ev_uint16_t dns_port=0;
1205 int n_accept=0, n_dns=0;
1208 be_connect_hostname_base = data->base;
1210 /* Bind an address and figure out what port it's on. */
1211 memset(&sin, 0, sizeof(sin));
1212 sin.sin_family = AF_INET;
1213 sin.sin_addr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */
1215 listener = evconnlistener_new_bind(data->base, nil_accept_cb,
1217 LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC,
1218 -1, (struct sockaddr *)&sin, sizeof(sin));
1219 tt_assert(listener);
1220 listener_port = regress_get_socket_port(
1221 evconnlistener_get_fd(listener));
1223 port = regress_get_dnsserver(data->base, &dns_port, NULL,
1224 be_getaddrinfo_server_cb, &n_dns);
1226 tt_int_op(dns_port, >=, 0);
1228 /* Start an evdns_base that uses the server as its resolver. */
1229 dns = evdns_base_new(data->base, 0);
1230 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)dns_port);
1231 evdns_base_nameserver_ip_add(dns, buf);
1233 /* Now, finally, at long last, launch the bufferevents. One should do
1234 * a failing lookup IP, one should do a successful lookup by IP,
1235 * and one should do a successful lookup by hostname. */
1236 be1 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE);
1237 be2 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE);
1238 be3 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE);
1239 be4 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE);
1240 be5 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE);
1242 bufferevent_setcb(be1, NULL, NULL, be_connect_hostname_event_cb,
1244 bufferevent_setcb(be2, NULL, NULL, be_connect_hostname_event_cb,
1246 bufferevent_setcb(be3, NULL, NULL, be_connect_hostname_event_cb,
1248 bufferevent_setcb(be4, NULL, NULL, be_connect_hostname_event_cb,
1250 bufferevent_setcb(be5, NULL, NULL, be_connect_hostname_event_cb,
1253 /* Use the blocking resolver. This one will fail if your resolver
1254 * can't resolve localhost to 127.0.0.1 */
1255 tt_assert(!bufferevent_socket_connect_hostname(be4, NULL, AF_INET,
1256 "localhost", listener_port));
1257 /* Use the blocking resolver with a nonexistent hostname. */
1258 tt_assert(!bufferevent_socket_connect_hostname(be5, NULL, AF_INET,
1259 "nonesuch.nowhere.example.com", 80));
1261 /* The blocking resolver will use the system nameserver, which
1262 * might tell us anything. (Yes, some twits even pretend that
1263 * example.com is real.) Let's see what answer to expect. */
1264 struct evutil_addrinfo hints, *ai = NULL;
1265 memset(&hints, 0, sizeof(hints));
1266 hints.ai_family = AF_INET;
1267 hints.ai_socktype = SOCK_STREAM;
1268 hints.ai_protocol = IPPROTO_TCP;
1269 expect_err5 = evutil_getaddrinfo(
1270 "nonesuch.nowhere.example.com", "80", &hints, &ai);
1272 /* Launch an async resolve that will fail. */
1273 tt_assert(!bufferevent_socket_connect_hostname(be1, dns, AF_INET,
1274 "nosuchplace.example.com", listener_port));
1275 /* Connect to the IP without resolving. */
1276 tt_assert(!bufferevent_socket_connect_hostname(be2, dns, AF_INET,
1277 "127.0.0.1", listener_port));
1278 /* Launch an async resolve that will succeed. */
1279 tt_assert(!bufferevent_socket_connect_hostname(be3, dns, AF_INET,
1280 "nobodaddy.example.com", listener_port));
1282 event_base_dispatch(data->base);
1284 tt_int_op(be1_outcome.what, ==, BEV_EVENT_ERROR);
1285 tt_int_op(be1_outcome.dnserr, ==, EVUTIL_EAI_NONAME);
1286 tt_int_op(be2_outcome.what, ==, BEV_EVENT_CONNECTED);
1287 tt_int_op(be2_outcome.dnserr, ==, 0);
1288 tt_int_op(be3_outcome.what, ==, BEV_EVENT_CONNECTED);
1289 tt_int_op(be3_outcome.dnserr, ==, 0);
1290 tt_int_op(be4_outcome.what, ==, BEV_EVENT_CONNECTED);
1291 tt_int_op(be4_outcome.dnserr, ==, 0);
1293 tt_int_op(be5_outcome.what, ==, BEV_EVENT_ERROR);
1294 tt_int_op(be5_outcome.dnserr, ==, expect_err5);
1297 tt_int_op(n_accept, ==, 3);
1298 tt_int_op(n_dns, ==, 2);
1302 evconnlistener_free(listener);
1304 evdns_close_server_port(port);
1306 evdns_base_free(dns, 0);
1308 bufferevent_free(be1);
1310 bufferevent_free(be2);
1312 bufferevent_free(be3);
1314 bufferevent_free(be4);
1316 bufferevent_free(be5);
1320 struct gai_outcome {
1322 struct evutil_addrinfo *ai;
1325 static int n_gai_results_pending = 0;
1326 static struct event_base *exit_base_on_no_pending_results = NULL;
1329 gai_cb(int err, struct evutil_addrinfo *res, void *ptr)
1331 struct gai_outcome *go = ptr;
1334 if (--n_gai_results_pending <= 0 && exit_base_on_no_pending_results)
1335 event_base_loopexit(exit_base_on_no_pending_results, NULL);
1336 if (n_gai_results_pending < 900)
1337 TT_BLATHER(("Got an answer; expecting %d more.",
1338 n_gai_results_pending));
1342 cancel_gai_cb(evutil_socket_t fd, short what, void *ptr)
1344 struct evdns_getaddrinfo_request *r = ptr;
1345 evdns_getaddrinfo_cancel(r);
1349 test_getaddrinfo_async(void *arg)
1351 struct basic_test_data *data = arg;
1352 struct evutil_addrinfo hints, *a;
1353 struct gai_outcome local_outcome;
1354 struct gai_outcome a_out[12];
1356 struct evdns_getaddrinfo_request *r;
1358 struct evdns_server_port *port = NULL;
1359 ev_uint16_t dns_port = 0;
1360 int n_dns_questions = 0;
1361 struct evdns_base *dns_base;
1363 memset(a_out, 0, sizeof(a_out));
1364 memset(&local_outcome, 0, sizeof(local_outcome));
1366 dns_base = evdns_base_new(data->base, 0);
1367 tt_assert(dns_base);
1370 evdns_base_load_hosts(dns_base, NULL);
1372 tt_assert(! evdns_base_set_option(dns_base, "timeout", "0.3"));
1373 tt_assert(! evdns_base_set_option(dns_base, "getaddrinfo-allow-skew", "0.2"));
1375 n_gai_results_pending = 10000; /* don't think about exiting yet. */
1377 /* 1. Try some cases that will never hit the asynchronous resolver. */
1378 /* 1a. Simple case with a symbolic service name */
1379 memset(&hints, 0, sizeof(hints));
1380 hints.ai_family = PF_UNSPEC;
1381 hints.ai_socktype = SOCK_STREAM;
1382 memset(&local_outcome, 0, sizeof(local_outcome));
1383 r = evdns_getaddrinfo(dns_base, "1.2.3.4", "http",
1384 &hints, gai_cb, &local_outcome);
1386 if (!local_outcome.err) {
1387 tt_ptr_op(local_outcome.ai,!=,NULL);
1388 test_ai_eq(local_outcome.ai, "1.2.3.4:80", SOCK_STREAM, IPPROTO_TCP);
1389 evutil_freeaddrinfo(local_outcome.ai);
1390 local_outcome.ai = NULL;
1392 TT_BLATHER(("Apparently we have no getservbyname."));
1395 /* 1b. EVUTIL_AI_NUMERICHOST is set */
1396 memset(&hints, 0, sizeof(hints));
1397 hints.ai_family = PF_UNSPEC;
1398 hints.ai_flags = EVUTIL_AI_NUMERICHOST;
1399 memset(&local_outcome, 0, sizeof(local_outcome));
1400 r = evdns_getaddrinfo(dns_base, "www.google.com", "80",
1401 &hints, gai_cb, &local_outcome);
1402 tt_ptr_op(r,==,NULL);
1403 tt_int_op(local_outcome.err,==,EVUTIL_EAI_NONAME);
1404 tt_ptr_op(local_outcome.ai,==,NULL);
1406 /* 1c. We give a numeric address (ipv6) */
1407 memset(&hints, 0, sizeof(hints));
1408 memset(&local_outcome, 0, sizeof(local_outcome));
1409 hints.ai_family = PF_UNSPEC;
1410 hints.ai_protocol = IPPROTO_TCP;
1411 r = evdns_getaddrinfo(dns_base, "f::f", "8008",
1412 &hints, gai_cb, &local_outcome);
1414 tt_int_op(local_outcome.err,==,0);
1415 tt_assert(local_outcome.ai);
1416 tt_ptr_op(local_outcome.ai->ai_next,==,NULL);
1417 test_ai_eq(local_outcome.ai, "[f::f]:8008", SOCK_STREAM, IPPROTO_TCP);
1418 evutil_freeaddrinfo(local_outcome.ai);
1419 local_outcome.ai = NULL;
1421 /* 1d. We give a numeric address (ipv4) */
1422 memset(&hints, 0, sizeof(hints));
1423 memset(&local_outcome, 0, sizeof(local_outcome));
1424 hints.ai_family = PF_UNSPEC;
1425 r = evdns_getaddrinfo(dns_base, "5.6.7.8", NULL,
1426 &hints, gai_cb, &local_outcome);
1428 tt_int_op(local_outcome.err,==,0);
1429 tt_assert(local_outcome.ai);
1430 a = ai_find_by_protocol(local_outcome.ai, IPPROTO_TCP);
1432 test_ai_eq(a, "5.6.7.8", SOCK_STREAM, IPPROTO_TCP);
1433 a = ai_find_by_protocol(local_outcome.ai, IPPROTO_UDP);
1435 test_ai_eq(a, "5.6.7.8", SOCK_DGRAM, IPPROTO_UDP);
1436 evutil_freeaddrinfo(local_outcome.ai);
1437 local_outcome.ai = NULL;
1439 /* 1e. nodename is NULL (bind) */
1440 memset(&hints, 0, sizeof(hints));
1441 memset(&local_outcome, 0, sizeof(local_outcome));
1442 hints.ai_family = PF_UNSPEC;
1443 hints.ai_socktype = SOCK_DGRAM;
1444 hints.ai_flags = EVUTIL_AI_PASSIVE;
1445 r = evdns_getaddrinfo(dns_base, NULL, "9090",
1446 &hints, gai_cb, &local_outcome);
1448 tt_int_op(local_outcome.err,==,0);
1449 tt_assert(local_outcome.ai);
1450 /* we should get a v4 address of 0.0.0.0... */
1451 a = ai_find_by_family(local_outcome.ai, PF_INET);
1453 test_ai_eq(a, "0.0.0.0:9090", SOCK_DGRAM, IPPROTO_UDP);
1454 /* ... and a v6 address of ::0 */
1455 a = ai_find_by_family(local_outcome.ai, PF_INET6);
1457 test_ai_eq(a, "[::]:9090", SOCK_DGRAM, IPPROTO_UDP);
1458 evutil_freeaddrinfo(local_outcome.ai);
1459 local_outcome.ai = NULL;
1461 /* 1f. nodename is NULL (connect) */
1462 memset(&hints, 0, sizeof(hints));
1463 memset(&local_outcome, 0, sizeof(local_outcome));
1464 hints.ai_family = PF_UNSPEC;
1465 hints.ai_socktype = SOCK_STREAM;
1466 r = evdns_getaddrinfo(dns_base, NULL, "2",
1467 &hints, gai_cb, &local_outcome);
1469 tt_int_op(local_outcome.err,==,0);
1470 tt_assert(local_outcome.ai);
1471 /* we should get a v4 address of 127.0.0.1 .... */
1472 a = ai_find_by_family(local_outcome.ai, PF_INET);
1474 test_ai_eq(a, "127.0.0.1:2", SOCK_STREAM, IPPROTO_TCP);
1475 /* ... and a v6 address of ::1 */
1476 a = ai_find_by_family(local_outcome.ai, PF_INET6);
1478 test_ai_eq(a, "[::1]:2", SOCK_STREAM, IPPROTO_TCP);
1479 evutil_freeaddrinfo(local_outcome.ai);
1480 local_outcome.ai = NULL;
1482 /* 1g. We find localhost immediately. (pf_unspec) */
1483 memset(&hints, 0, sizeof(hints));
1484 memset(&local_outcome, 0, sizeof(local_outcome));
1485 hints.ai_family = PF_UNSPEC;
1486 hints.ai_socktype = SOCK_STREAM;
1487 r = evdns_getaddrinfo(dns_base, "LOCALHOST", "80",
1488 &hints, gai_cb, &local_outcome);
1490 tt_int_op(local_outcome.err,==,0);
1491 tt_assert(local_outcome.ai);
1492 /* we should get a v4 address of 127.0.0.1 .... */
1493 a = ai_find_by_family(local_outcome.ai, PF_INET);
1495 test_ai_eq(a, "127.0.0.1:80", SOCK_STREAM, IPPROTO_TCP);
1496 /* ... and a v6 address of ::1 */
1497 a = ai_find_by_family(local_outcome.ai, PF_INET6);
1499 test_ai_eq(a, "[::1]:80", SOCK_STREAM, IPPROTO_TCP);
1500 evutil_freeaddrinfo(local_outcome.ai);
1501 local_outcome.ai = NULL;
1503 /* 1g. We find localhost immediately. (pf_inet6) */
1504 memset(&hints, 0, sizeof(hints));
1505 memset(&local_outcome, 0, sizeof(local_outcome));
1506 hints.ai_family = PF_INET6;
1507 hints.ai_socktype = SOCK_STREAM;
1508 r = evdns_getaddrinfo(dns_base, "LOCALHOST", "9999",
1509 &hints, gai_cb, &local_outcome);
1511 tt_int_op(local_outcome.err,==,0);
1512 tt_assert(local_outcome.ai);
1513 a = local_outcome.ai;
1514 test_ai_eq(a, "[::1]:9999", SOCK_STREAM, IPPROTO_TCP);
1515 tt_ptr_op(a->ai_next, ==, NULL);
1516 evutil_freeaddrinfo(local_outcome.ai);
1517 local_outcome.ai = NULL;
1519 /* 2. Okay, now we can actually test the asynchronous resolver. */
1520 /* Start a dummy local dns server... */
1521 port = regress_get_dnsserver(data->base, &dns_port, NULL,
1522 be_getaddrinfo_server_cb, &n_dns_questions);
1524 tt_int_op(dns_port, >=, 0);
1525 /* ... and tell the evdns_base about it. */
1526 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", dns_port);
1527 evdns_base_nameserver_ip_add(dns_base, buf);
1529 memset(&hints, 0, sizeof(hints));
1530 hints.ai_family = PF_UNSPEC;
1531 hints.ai_socktype = SOCK_STREAM;
1532 hints.ai_flags = EVUTIL_AI_CANONNAME;
1533 /* 0: Request for both.example.com should return both addresses. */
1534 r = evdns_getaddrinfo(dns_base, "both.example.com", "8000",
1535 &hints, gai_cb, &a_out[0]);
1538 /* 1: Request for v4only.example.com should return one address. */
1539 r = evdns_getaddrinfo(dns_base, "v4only.example.com", "8001",
1540 &hints, gai_cb, &a_out[1]);
1543 /* 2: Request for v6only.example.com should return one address. */
1545 r = evdns_getaddrinfo(dns_base, "v6only.example.com", "8002",
1546 &hints, gai_cb, &a_out[2]);
1549 /* 3: PF_INET request for v4assert.example.com should not generate a
1550 * v6 request. The server will fail the test if it does. */
1551 hints.ai_family = PF_INET;
1552 r = evdns_getaddrinfo(dns_base, "v4assert.example.com", "8003",
1553 &hints, gai_cb, &a_out[3]);
1556 /* 4: PF_INET6 request for v6assert.example.com should not generate a
1557 * v4 request. The server will fail the test if it does. */
1558 hints.ai_family = PF_INET6;
1559 r = evdns_getaddrinfo(dns_base, "v6assert.example.com", "8004",
1560 &hints, gai_cb, &a_out[4]);
1563 /* 5: PF_INET request for nosuchplace.example.com should give NEXIST. */
1564 hints.ai_family = PF_INET;
1565 r = evdns_getaddrinfo(dns_base, "nosuchplace.example.com", "8005",
1566 &hints, gai_cb, &a_out[5]);
1569 /* 6: PF_UNSPEC request for nosuchplace.example.com should give NEXIST.
1571 hints.ai_family = PF_UNSPEC;
1572 r = evdns_getaddrinfo(dns_base, "nosuchplace.example.com", "8006",
1573 &hints, gai_cb, &a_out[6]);
1576 /* 7: PF_UNSPEC request for v6timeout.example.com should give an ipv4
1578 hints.ai_family = PF_UNSPEC;
1579 r = evdns_getaddrinfo(dns_base, "v6timeout.example.com", "8007",
1580 &hints, gai_cb, &a_out[7]);
1583 /* 8: PF_UNSPEC request for v6timeout-nonexist.example.com should give
1585 hints.ai_family = PF_UNSPEC;
1586 r = evdns_getaddrinfo(dns_base, "v6timeout-nonexist.example.com",
1587 "8008", &hints, gai_cb, &a_out[8]);
1590 /* 9: AI_ADDRCONFIG should at least not crash. Can't test it more
1591 * without knowing what kind of internet we have. */
1592 hints.ai_flags |= EVUTIL_AI_ADDRCONFIG;
1593 r = evdns_getaddrinfo(dns_base, "both.example.com",
1594 "8009", &hints, gai_cb, &a_out[9]);
1597 /* 10: PF_UNSPEC for v4timeout.example.com should give an ipv6 address
1599 hints.ai_family = PF_UNSPEC;
1601 r = evdns_getaddrinfo(dns_base, "v4timeout.example.com", "8010",
1602 &hints, gai_cb, &a_out[10]);
1605 /* 11: timeout.example.com: cancel it after 100 msec. */
1606 r = evdns_getaddrinfo(dns_base, "all-timeout.example.com", "8011",
1607 &hints, gai_cb, &a_out[11]);
1612 tv.tv_usec = 100*1000; /* 100 msec */
1613 event_base_once(data->base, -1, EV_TIMEOUT, cancel_gai_cb,
1617 /* XXXXX There are more tests we could do, including:
1619 - A test to elicit NODATA.
1623 n_gai_results_pending = 12;
1624 exit_base_on_no_pending_results = data->base;
1626 event_base_dispatch(data->base);
1628 /* 0: both.example.com */
1629 tt_int_op(a_out[0].err, ==, 0);
1630 tt_assert(a_out[0].ai);
1631 tt_assert(a_out[0].ai->ai_next);
1632 tt_assert(!a_out[0].ai->ai_next->ai_next);
1633 a = ai_find_by_family(a_out[0].ai, PF_INET);
1635 test_ai_eq(a, "80.80.32.32:8000", SOCK_STREAM, IPPROTO_TCP);
1636 a = ai_find_by_family(a_out[0].ai, PF_INET6);
1638 test_ai_eq(a, "[80ff::bbbb]:8000", SOCK_STREAM, IPPROTO_TCP);
1639 tt_assert(a_out[0].ai->ai_canonname);
1640 tt_str_op(a_out[0].ai->ai_canonname, ==, "both-canonical.example.com");
1642 /* 1: v4only.example.com */
1643 tt_int_op(a_out[1].err, ==, 0);
1644 tt_assert(a_out[1].ai);
1645 tt_assert(! a_out[1].ai->ai_next);
1646 test_ai_eq(a_out[1].ai, "18.52.86.120:8001", SOCK_STREAM, IPPROTO_TCP);
1647 tt_assert(a_out[1].ai->ai_canonname == NULL);
1650 /* 2: v6only.example.com */
1651 tt_int_op(a_out[2].err, ==, 0);
1652 tt_assert(a_out[2].ai);
1653 tt_assert(! a_out[2].ai->ai_next);
1654 test_ai_eq(a_out[2].ai, "[b0b::f00d]:8002", SOCK_STREAM, IPPROTO_TCP);
1656 /* 3: v4assert.example.com */
1657 tt_int_op(a_out[3].err, ==, 0);
1658 tt_assert(a_out[3].ai);
1659 tt_assert(! a_out[3].ai->ai_next);
1660 test_ai_eq(a_out[3].ai, "18.52.86.120:8003", SOCK_STREAM, IPPROTO_TCP);
1662 /* 4: v6assert.example.com */
1663 tt_int_op(a_out[4].err, ==, 0);
1664 tt_assert(a_out[4].ai);
1665 tt_assert(! a_out[4].ai->ai_next);
1666 test_ai_eq(a_out[4].ai, "[b0b::f00d]:8004", SOCK_STREAM, IPPROTO_TCP);
1668 /* 5: nosuchplace.example.com (inet) */
1669 tt_int_op(a_out[5].err, ==, EVUTIL_EAI_NONAME);
1670 tt_assert(! a_out[5].ai);
1672 /* 6: nosuchplace.example.com (unspec) */
1673 tt_int_op(a_out[6].err, ==, EVUTIL_EAI_NONAME);
1674 tt_assert(! a_out[6].ai);
1676 /* 7: v6timeout.example.com */
1677 tt_int_op(a_out[7].err, ==, 0);
1678 tt_assert(a_out[7].ai);
1679 tt_assert(! a_out[7].ai->ai_next);
1680 test_ai_eq(a_out[7].ai, "171.205.239.1:8007", SOCK_STREAM, IPPROTO_TCP);
1682 /* 8: v6timeout-nonexist.example.com */
1683 tt_int_op(a_out[8].err, ==, EVUTIL_EAI_NONAME);
1684 tt_assert(! a_out[8].ai);
1686 /* 9: both (ADDRCONFIG) */
1687 tt_int_op(a_out[9].err, ==, 0);
1688 tt_assert(a_out[9].ai);
1689 a = ai_find_by_family(a_out[9].ai, PF_INET);
1691 test_ai_eq(a, "80.80.32.32:8009", SOCK_STREAM, IPPROTO_TCP);
1693 tt_assert(ai_find_by_family(a_out[9].ai, PF_INET6));
1694 a = ai_find_by_family(a_out[9].ai, PF_INET6);
1696 test_ai_eq(a, "[80ff::bbbb]:8009", SOCK_STREAM, IPPROTO_TCP);
1698 tt_assert(ai_find_by_family(a_out[9].ai, PF_INET));
1700 /* 10: v4timeout.example.com */
1701 tt_int_op(a_out[10].err, ==, 0);
1702 tt_assert(a_out[10].ai);
1703 tt_assert(! a_out[10].ai->ai_next);
1704 test_ai_eq(a_out[10].ai, "[a0a::ff01]:8010", SOCK_STREAM, IPPROTO_TCP);
1706 /* 11: cancelled request. */
1707 tt_int_op(a_out[11].err, ==, EVUTIL_EAI_CANCEL);
1708 tt_assert(a_out[11].ai == NULL);
1711 if (local_outcome.ai)
1712 evutil_freeaddrinfo(local_outcome.ai);
1713 for (i=0;i<(int)ARRAY_SIZE(a_out);++i) {
1715 evutil_freeaddrinfo(a_out[i].ai);
1718 evdns_close_server_port(port);
1720 evdns_base_free(dns_base, 0);
1723 struct gaic_request_status {
1725 struct event_base *base;
1726 struct evdns_base *dns_base;
1727 struct evdns_getaddrinfo_request *request;
1728 struct event cancel_event;
1732 #define GAIC_MAGIC 0x1234abcd
1734 static int pending = 0;
1737 gaic_cancel_request_cb(evutil_socket_t fd, short what, void *arg)
1739 struct gaic_request_status *status = arg;
1741 tt_assert(status->magic == GAIC_MAGIC);
1742 status->canceled = 1;
1743 evdns_getaddrinfo_cancel(status->request);
1746 event_base_loopexit(status->base, NULL);
1750 gaic_server_cb(struct evdns_server_request *req, void *arg)
1752 ev_uint32_t answer = 0x7f000001;
1753 tt_assert(req->nquestions);
1754 evdns_server_request_add_a_reply(req, req->questions[0]->name, 1,
1756 evdns_server_request_respond(req, 0);
1759 evdns_server_request_respond(req, DNS_ERR_REFUSED);
1764 gaic_getaddrinfo_cb(int result, struct evutil_addrinfo *res, void *arg)
1766 struct gaic_request_status *status = arg;
1767 struct event_base *base = status->base;
1768 tt_assert(status->magic == GAIC_MAGIC);
1770 if (result == EVUTIL_EAI_CANCEL) {
1771 tt_assert(status->canceled);
1773 event_del(&status->cancel_event);
1775 memset(status, 0xf0, sizeof(*status));
1780 event_base_loopexit(base, NULL);
1784 gaic_launch(struct event_base *base, struct evdns_base *dns_base)
1786 struct gaic_request_status *status = calloc(1,sizeof(*status));
1787 struct timeval tv = { 0, 10000 };
1788 status->magic = GAIC_MAGIC;
1789 status->base = base;
1790 status->dns_base = dns_base;
1791 event_assign(&status->cancel_event, base, -1, 0, gaic_cancel_request_cb,
1793 status->request = evdns_getaddrinfo(dns_base,
1794 "foobar.bazquux.example.com", "80", NULL, gaic_getaddrinfo_cb,
1796 event_add(&status->cancel_event, &tv);
1800 #ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
1801 /* FIXME: We should move this to regress_main.c if anything else needs it.*/
1803 /* Trivial replacements for malloc/free/realloc to check for memory leaks.
1804 * Not threadsafe. */
1805 static int allocated_chunks = 0;
1808 cnt_malloc(size_t sz)
1810 allocated_chunks += 1;
1815 cnt_realloc(void *old, size_t sz)
1818 allocated_chunks += 1;
1820 allocated_chunks -= 1;
1821 return realloc(old, sz);
1827 allocated_chunks -= 1;
1831 struct testleak_env_t {
1832 struct event_base *base;
1833 struct evdns_base *dns_base;
1834 struct evdns_request *req;
1835 struct generic_dns_callback_result r;
1839 testleak_setup(const struct testcase_t *testcase)
1841 struct testleak_env_t *env;
1843 allocated_chunks = 0;
1845 /* Reset allocation counter, to start allocations from the very beginning.
1846 * (this will avoid false-positive negative numbers for allocated_chunks)
1848 libevent_global_shutdown();
1850 event_set_mem_functions(cnt_malloc, cnt_realloc, cnt_free);
1852 event_enable_debug_mode();
1854 /* not mm_calloc: we don't want to mess with the count. */
1855 env = calloc(1, sizeof(struct testleak_env_t));
1856 env->base = event_base_new();
1857 env->dns_base = evdns_base_new(env->base, 0);
1858 env->req = evdns_base_resolve_ipv4(
1859 env->dns_base, "example.com", DNS_QUERY_NO_SEARCH,
1860 generic_dns_callback, &env->r);
1865 testleak_cleanup(const struct testcase_t *testcase, void *env_)
1868 struct testleak_env_t *env = env_;
1870 #ifdef EVENT__DISABLE_DEBUG_MODE
1871 tt_int_op(allocated_chunks, ==, 0);
1873 libevent_global_shutdown();
1874 tt_int_op(allocated_chunks, ==, 0);
1880 evdns_base_free(env->dns_base, 0);
1882 event_base_free(env->base);
1888 static struct testcase_setup_t testleak_funcs = {
1889 testleak_setup, testleak_cleanup
1893 test_dbg_leak_cancel(void *env_)
1895 /* cancel, loop, free/dns, free/base */
1896 struct testleak_env_t *env = env_;
1897 int send_err_shutdown = 1;
1898 evdns_cancel_request(env->dns_base, env->req);
1901 /* `req` is freed in callback, that's why one loop is required. */
1902 event_base_loop(env->base, EVLOOP_NONBLOCK);
1904 /* send_err_shutdown means nothing as soon as our request is
1905 * already canceled */
1906 evdns_base_free(env->dns_base, send_err_shutdown);
1908 event_base_free(env->base);
1913 dbg_leak_resume(void *env_, int cancel, int send_err_shutdown)
1915 /* cancel, loop, free/dns, free/base */
1916 struct testleak_env_t *env = env_;
1918 evdns_cancel_request(env->dns_base, env->req);
1919 tt_assert(!evdns_base_resume(env->dns_base));
1921 /* TODO: No nameservers, request can't be processed, must be errored */
1922 tt_assert(!evdns_base_resume(env->dns_base));
1925 event_base_loop(env->base, EVLOOP_NONBLOCK);
1927 * Because we don't cancel request, and want our callback to recieve
1928 * DNS_ERR_SHUTDOWN, we use deferred callback, and there was:
1929 * - one extra malloc(),
1930 * @see reply_schedule_callback()
1931 * - and one missing free
1932 * @see request_finished() (req->handle->pending_cb = 1)
1933 * than we don't need to count in testleak_cleanup(), but we can clean them
1934 * if we will run loop once again, but *after* evdns base freed.
1936 evdns_base_free(env->dns_base, send_err_shutdown);
1938 event_base_loop(env->base, EVLOOP_NONBLOCK);
1941 event_base_free(env->base);
1945 #define IMPL_DBG_LEAK_RESUME(name, cancel, send_err_shutdown) \
1947 test_dbg_leak_##name##_(void *env_) \
1949 dbg_leak_resume(env_, cancel, send_err_shutdown); \
1951 IMPL_DBG_LEAK_RESUME(resume, 0, 0)
1952 IMPL_DBG_LEAK_RESUME(cancel_and_resume, 1, 0)
1953 IMPL_DBG_LEAK_RESUME(resume_send_err, 0, 1)
1954 IMPL_DBG_LEAK_RESUME(cancel_and_resume_send_err, 1, 1)
1957 test_dbg_leak_shutdown(void *env_)
1959 /* free/dns, loop, free/base */
1960 struct testleak_env_t *env = env_;
1961 int send_err_shutdown = 1;
1963 /* `req` is freed both with `send_err_shutdown` and without it,
1964 * the only difference is `evdns_callback` call */
1967 evdns_base_free(env->dns_base, send_err_shutdown);
1970 /* `req` is freed in callback, that's why one loop is required */
1971 event_base_loop(env->base, EVLOOP_NONBLOCK);
1972 event_base_free(env->base);
1978 test_getaddrinfo_async_cancel_stress(void *ptr)
1980 struct event_base *base;
1981 struct evdns_base *dns_base = NULL;
1982 struct evdns_server_port *server = NULL;
1983 evutil_socket_t fd = -1;
1984 struct sockaddr_in sin;
1985 struct sockaddr_storage ss;
1989 base = event_base_new();
1990 dns_base = evdns_base_new(base, 0);
1992 memset(&sin, 0, sizeof(sin));
1993 sin.sin_family = AF_INET;
1995 sin.sin_addr.s_addr = htonl(0x7f000001);
1996 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
1997 tt_abort_perror("socket");
1999 evutil_make_socket_nonblocking(fd);
2000 if (bind(fd, (struct sockaddr*)&sin, sizeof(sin))<0) {
2001 tt_abort_perror("bind");
2003 server = evdns_add_server_port_with_base(base, fd, 0, gaic_server_cb,
2006 memset(&ss, 0, sizeof(ss));
2008 if (getsockname(fd, (struct sockaddr*)&ss, &slen)<0) {
2009 tt_abort_perror("getsockname");
2011 evdns_base_nameserver_sockaddr_add(dns_base,
2012 (struct sockaddr*)&ss, slen, 0);
2014 for (i = 0; i < 1000; ++i) {
2015 gaic_launch(base, dns_base);
2018 event_base_dispatch(base);
2022 evdns_base_free(dns_base, 1);
2024 evdns_close_server_port(server);
2026 event_base_free(base);
2028 evutil_closesocket(fd);
2032 dns_client_fail_requests_test(void *arg)
2034 struct basic_test_data *data = arg;
2035 struct event_base *base = data->base;
2036 struct evdns_base *dns = NULL;
2037 struct evdns_server_port *dns_port = NULL;
2038 ev_uint16_t portnum = 0;
2041 struct generic_dns_callback_result r[20];
2044 dns_port = regress_get_dnsserver(base, &portnum, NULL,
2045 regress_dns_server_cb, reissue_table);
2046 tt_assert(dns_port);
2048 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
2050 dns = evdns_base_new(base, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
2051 tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
2053 for (i = 0; i < 20; ++i)
2054 evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r[i]);
2056 n_replies_left = 20;
2059 evdns_base_free(dns, 1 /** fail requests */);
2060 /** run defered callbacks, to trigger UAF */
2061 event_base_dispatch(base);
2063 tt_int_op(n_replies_left, ==, 0);
2064 for (i = 0; i < 20; ++i)
2065 tt_int_op(r[i].result, ==, DNS_ERR_SHUTDOWN);
2068 evdns_close_server_port(dns_port);
2072 getaddrinfo_cb(int err, struct evutil_addrinfo *res, void *ptr)
2074 generic_dns_callback(err, 0, 0, 0, NULL, ptr);
2077 dns_client_fail_requests_getaddrinfo_test(void *arg)
2079 struct basic_test_data *data = arg;
2080 struct event_base *base = data->base;
2081 struct evdns_base *dns = NULL;
2082 struct evdns_server_port *dns_port = NULL;
2083 ev_uint16_t portnum = 0;
2086 struct generic_dns_callback_result r[20];
2089 dns_port = regress_get_dnsserver(base, &portnum, NULL,
2090 regress_dns_server_cb, reissue_table);
2091 tt_assert(dns_port);
2093 evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
2095 dns = evdns_base_new(base, EVDNS_BASE_DISABLE_WHEN_INACTIVE);
2096 tt_assert(!evdns_base_nameserver_ip_add(dns, buf));
2098 for (i = 0; i < 20; ++i)
2099 tt_assert(evdns_getaddrinfo(dns, "foof.example.com", "ssh", NULL, getaddrinfo_cb, &r[i]));
2101 n_replies_left = 20;
2104 evdns_base_free(dns, 1 /** fail requests */);
2105 /** run defered callbacks, to trigger UAF */
2106 event_base_dispatch(base);
2108 tt_int_op(n_replies_left, ==, 0);
2109 for (i = 0; i < 20; ++i)
2110 tt_int_op(r[i].result, ==, EVUTIL_EAI_FAIL);
2113 evdns_close_server_port(dns_port);
2117 #define DNS_LEGACY(name, flags) \
2118 { #name, run_legacy_test_fn, flags|TT_LEGACY, &legacy_setup, \
2121 struct testcase_t dns_testcases[] = {
2122 DNS_LEGACY(server, TT_FORK|TT_NEED_BASE),
2123 DNS_LEGACY(gethostbyname, TT_FORK|TT_NEED_BASE|TT_NEED_DNS|TT_OFF_BY_DEFAULT),
2124 DNS_LEGACY(gethostbyname6, TT_FORK|TT_NEED_BASE|TT_NEED_DNS|TT_OFF_BY_DEFAULT),
2125 DNS_LEGACY(gethostbyaddr, TT_FORK|TT_NEED_BASE|TT_NEED_DNS|TT_OFF_BY_DEFAULT),
2126 { "resolve_reverse", dns_resolve_reverse, TT_FORK|TT_OFF_BY_DEFAULT, NULL, NULL },
2127 { "search_empty", dns_search_empty_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2128 { "search", dns_search_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2129 { "search_lower", dns_search_lower_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2130 { "search_cancel", dns_search_cancel_test,
2131 TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2132 { "retry", dns_retry_test, TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
2133 { "retry_disable_when_inactive", dns_retry_disable_when_inactive_test,
2134 TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
2135 { "reissue", dns_reissue_test, TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
2136 { "reissue_disable_when_inactive", dns_reissue_disable_when_inactive_test,
2137 TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },
2138 { "inflight", dns_inflight_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2139 { "bufferevent_connect_hostname", test_bufferevent_connect_hostname,
2140 TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2141 { "disable_when_inactive", dns_disable_when_inactive_test,
2142 TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2143 { "disable_when_inactive_no_ns", dns_disable_when_inactive_no_ns_test,
2144 TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2146 { "getaddrinfo_async", test_getaddrinfo_async,
2147 TT_FORK|TT_NEED_BASE, &basic_setup, (char*)"" },
2148 { "getaddrinfo_cancel_stress", test_getaddrinfo_async_cancel_stress,
2149 TT_FORK, NULL, NULL },
2151 #ifdef EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED
2152 { "leak_shutdown", test_dbg_leak_shutdown, TT_FORK, &testleak_funcs, NULL },
2153 { "leak_cancel", test_dbg_leak_cancel, TT_FORK, &testleak_funcs, NULL },
2155 { "leak_resume", test_dbg_leak_resume_, TT_FORK, &testleak_funcs, NULL },
2156 { "leak_cancel_and_resume", test_dbg_leak_cancel_and_resume_,
2157 TT_FORK, &testleak_funcs, NULL },
2158 { "leak_resume_send_err", test_dbg_leak_resume_send_err_,
2159 TT_FORK, &testleak_funcs, NULL },
2160 { "leak_cancel_and_resume_send_err", test_dbg_leak_cancel_and_resume_send_err_,
2161 TT_FORK, &testleak_funcs, NULL },
2164 { "client_fail_requests", dns_client_fail_requests_test,
2165 TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
2166 { "client_fail_requests_getaddrinfo",
2167 dns_client_fail_requests_getaddrinfo_test,
2168 TT_FORK|TT_NEED_BASE, &basic_setup, NULL },