adb_test.c revision 1a0e33bc2044e1902493111db14cbf793083ac47
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews/*
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * Copyright (C) 1999 Internet Software Consortium.
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews *
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * Permission to use, copy, modify, and distribute this software for any
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * purpose with or without fee is hereby granted, provided that the above
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * copyright notice and this permission notice appear in all copies.
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews *
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * SOFTWARE.
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
6b7257f756eb0530cdf54df9a7fab8d51a5001c3David Lawrence#include <config.h>
6b7257f756eb0530cdf54df9a7fab8d51a5001c3David Lawrence
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <stdio.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <stdlib.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <unistd.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <string.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
8c8360e5c3e4b27641633c22d0fcfd3f1f3af2b5Michael Graff#include <isc/app.h>
8c8360e5c3e4b27641633c22d0fcfd3f1f3af2b5Michael Graff#include <isc/assertions.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <isc/buffer.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <isc/error.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <isc/mem.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <isc/task.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <isc/thread.h>
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley#include <isc/timer.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <isc/result.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <isc/sockaddr.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <isc/socket.h>
37d266d288410d1ead241c02a8a1dbcb0160be46Michael Graff#include <isc/net.h>
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <dns/adb.h>
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews#include <dns/cache.h>
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews#include <dns/db.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <dns/master.h>
d0783e645b149fcea7e7f22cd43f87b5d188b055Mark Andrews#include <dns/log.h>
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews#include <dns/name.h>
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley#include <dns/rootns.h>
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewstypedef struct client client_t;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstruct client {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_name_t name;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_LINK(client_t) link;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_adbfind_t *find;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews};
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_mem_t *mctx;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_mempool_t *cmp;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_log_t *lctx;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_taskmgr_t *taskmgr;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_socketmgr_t *socketmgr;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_timermgr_t *timermgr;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_task_t *t1, *t2;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_view_t *view;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_db_t *rootdb;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark AndrewsISC_LIST(client_t) clients;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_mutex_t client_lock;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_stdtime_t now;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsdns_adb_t *adb;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic void check_result(isc_result_t, char *, ...);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsisc_result_t ns_rootns_init(void);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid create_managers(void);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewsstatic void lookup_callback(isc_task_t *, isc_event_t *);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid create_view(void);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewsclient_t *new_client(void);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid free_client(client_t **);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void CLOCK(void);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void CUNLOCK(void);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid lookup(char *);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic void
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewscheck_result(isc_result_t result, char *format, ...)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews va_list args;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if (result == ISC_R_SUCCESS)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews va_start(args, format);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews vfprintf(stderr, format, args);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews va_end(args);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews fprintf(stderr, "\n");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews exit(1);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsclient_t *
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsnew_client(void)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client_t *client;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client = isc_mempool_get(cmp);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews INSIST(client != NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_name_init(&client->name, NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_LINK_INIT(client, link);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client->find = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (client);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsfree_client(client_t **c)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley client_t *client;
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews INSIST(c != NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client = *c;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews *c = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews INSIST(client != NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_name_free(&client->name, mctx);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews INSIST(!ISC_LINK_LINKED(client, link));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews INSIST(client->find == NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_mempool_put(cmp, client);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark AndrewsCLOCK(void)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark AndrewsCUNLOCK(void)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic void
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewslookup_callback(isc_task_t *task, isc_event_t *ev)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client_t *client;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client = ev->arg;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews INSIST(client->find == ev->sender);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews printf("Task %p got event %p type %08x from %p, client %p\n",
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews task, ev, ev->type, client->find, client);
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews isc_event_free(&ev);
6add3af8397580475ab9fa10ac8c1269465cff87Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews CLOCK();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_adb_dumpfind(client->find, stderr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_adb_destroyfind(&client->find);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_LIST_UNLINK(clients, client, link);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews free_client(&client);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews CUNLOCK();
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews}
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewscreate_managers(void)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_result_t result;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews taskmgr = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_taskmgr_create(mctx, 2, 0, &taskmgr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_taskmgr_create");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews timermgr = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_timermgr_create(mctx, &timermgr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_timermgr_create");
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews socketmgr = NULL;
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = isc_socketmgr_create(mctx, &socketmgr);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "isc_socketmgr_create");
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewscreate_view(void)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_cache_t *cache;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_result_t result;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /*
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * View.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews view = NULL;
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "dns_view_create");
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /*
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * Cache.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews cache = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews "rbt", 0, NULL, &cache);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews check_result(result, "dns_cache_create");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_view_setcache(view, cache);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_cache_detach(&cache);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /*
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Resolver.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews *
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * XXXRTH hardwired number of tasks. Also, we'll need to
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * see if we are dealing with a shared dispatcher in this view.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_view_createresolver(view, taskmgr, 16, socketmgr,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews timermgr, 0, NULL, NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "dns_view_createresolver()");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews rootdb = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_rootns_create(mctx, dns_rdataclass_in, NULL, &rootdb);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "dns_rootns_create()");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_view_sethints(view, rootdb);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_db_detach(&rootdb);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_view_freeze(view);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsvoid
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewslookup(char *target)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_name_t name;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned char namedata[256];
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client_t *client;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_t t, namebuf;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_result_t result;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned int options;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews INSIST(target != NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews client = new_client();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_init(&t, target, strlen(target), ISC_BUFFERTYPE_TEXT);
ea023072092112a831ca7c2943387ccbb422a3f2Mark Andrews isc_buffer_add(&t, strlen(target));
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_init(&namebuf, namedata, sizeof namedata,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_BUFFERTYPE_BINARY);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_name_init(&name, NULL);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = dns_name_fromtext(&name, &t, dns_rootname, ISC_FALSE,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews &namebuf);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "dns_name_fromtext %s", target);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_name_dup(&name, mctx, &client->name);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "dns_name_dup %s", target);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews options = 0;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews options |= DNS_ADBFIND_INET;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews options |= DNS_ADBFIND_INET6;
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews options |= DNS_ADBFIND_WANTEVENT;
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews options |= DNS_ADBFIND_HINTOK;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews options |= DNS_ADBFIND_GLUEOK;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_adb_createfind(adb, t2, lookup_callback, client,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews &client->name, dns_rootname, options,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews now, NULL, &client->find);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "dns_adb_lookup()");
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews dns_adb_dumpfind(client->find, stderr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_LIST_APPEND(clients, client, link);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews else {
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_adb_destroyfind(&client->find);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews free_client(&client);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews }
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsint
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsmain(int argc, char **argv)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews{
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley isc_result_t result;
35c842e05dc6382ce1d9161a658d3ff4b2c3d4c9Bob Halley isc_logdestination_t destination;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews (void)argc;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews (void)argv;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews dns_result_register();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_app_start();
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "isc_app_start()");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_stdtime_get(&now);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_mutex_init(&client_lock);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_mutex_init(&client_lock)");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_LIST_INIT(clients);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews /*
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * EVERYTHING needs a memory context.
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews mctx = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews cmp = NULL;
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews == ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_mempool_setname(cmp, "adb test clients");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_log_create(mctx, &lctx);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "isc_log_create()");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_log_init(lctx);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "dns_log_init()");
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /*
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Create and install the default channel.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews destination.file.stream = stderr;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews destination.file.name = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews destination.file.versions = ISC_LOG_ROLLNEVER;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews destination.file.maximum_size = 0;
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = isc_log_createchannel(lctx, "_default",
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_LOG_TOFILEDESC,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews ISC_LOG_DYNAMIC,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews &destination, ISC_LOG_PRINTTIME);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_log_createchannel()");
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = isc_log_usechannel(lctx, "_default", NULL, NULL);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "isc_log_usechannel()");
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /*
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Set the initial debug level.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_log_setdebuglevel(lctx, 99);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews create_managers();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews t1 = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_task_create(taskmgr, NULL, 0, &t1);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_task_create t1");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews t2 = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_task_create(taskmgr, NULL, 0, &t2);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_task_create t2");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews printf("task 1 = %p\n", t1);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews printf("task 2 = %p\n", t2);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews create_view();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews adb = view->adb;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews /*
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Lock the entire client list here. This will cause all events
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * for found names to block as well.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews CLOCK();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("f.root-servers.net."); /* Should be in hints */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("www.iengines.com"); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("www.isc.org"); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("www.flame.org"); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("kechara.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("moghedien.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("mailrelay.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("ipv4v6.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("nonexistant.flame.org."); /* should fail to be found */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("i.root-servers.net."); /* Should be in hints */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews CUNLOCK();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews sleep(10);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews dns_adb_dump(adb, stderr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews sleep(10);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews CLOCK();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("f.root-servers.net."); /* Should be in hints */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("www.iengines.com"); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("www.isc.org"); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("www.flame.org"); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("kechara.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("moghedien.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("mailrelay.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("ipv4v6.flame.org."); /* should fetch */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("nonexistant.flame.org."); /* should fail to be found */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("i.root-servers.net."); /* Should be in hints */
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews CUNLOCK();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_adb_dump(adb, stderr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_task_detach(&t1);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_task_detach(&t2);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_mem_stats(mctx, stdout);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_adb_dump(adb, stderr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_app_run();
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_adb_dump(adb, stderr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews dns_view_detach(&view);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews adb = NULL;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews isc_socketmgr_destroy(&socketmgr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_timermgr_destroy(&timermgr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews fprintf(stderr, "Destroying task manager\n");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_taskmgr_destroy(&taskmgr);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_log_destroy(&lctx);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_mempool_destroy(&cmp);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_mem_stats(mctx, stdout);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_mem_destroy(&mctx);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_app_finish();
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews return (0);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews}
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews