adb_test.c revision 1a69a1a78cfaa86f3b68bbc965232b7876d4da2a
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
28d9fd53819cc163629c867466b20d8ebcae8842David Lawrence * Copyright (C) 1999, 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
15a44745412679c30a6d022733925af70a38b715David Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
15a44745412679c30a6d022733925af70a38b715David Lawrence * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15a44745412679c30a6d022733925af70a38b715David Lawrence * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
15a44745412679c30a6d022733925af70a38b715David Lawrence * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15a44745412679c30a6d022733925af70a38b715David Lawrence * SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#include <config.h>
96805adfc95a9e0c5b800869dd4afe55b5616f12James Brister
96805adfc95a9e0c5b800869dd4afe55b5616f12James Brister#include <stdlib.h>
3761c433912beabe43abeed2c3513b6201c59f64Mark Andrews#include <unistd.h>
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#include <isc/app.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <isc/buffer.h>
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff#include <isc/task.h>
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff#include <isc/timer.h>
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff#include <isc/socket.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <isc/util.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <dns/adb.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <dns/cache.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <dns/db.h>
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews#include <dns/log.h>
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews#include <dns/rootns.h>
96805adfc95a9e0c5b800869dd4afe55b5616f12James Brister#include <dns/result.h>
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrewstypedef struct client client_t;
c661868379d709416c773f6d53b5cec69c88e00fMark Andrewsstruct client {
34b394b43e2207e8f8f3703f0402422121455638David Lawrence dns_name_t name;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews ISC_LINK(client_t) link;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews dns_adbfind_t *find;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews};
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrenceisc_mem_t *mctx;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_mempool_t *cmp;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_log_t *lctx;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_logconfig_t *lcfg;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_taskmgr_t *taskmgr;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_socketmgr_t *socketmgr;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_timermgr_t *timermgr;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_task_t *t1, *t2;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_view_t *view;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_db_t *rootdb;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark AndrewsISC_LIST(client_t) clients;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_mutex_t client_lock;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_stdtime_t now;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_adb_t *adb;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewscheck_result(isc_result_t result, char *format, ...) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews va_list args;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result == ISC_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews va_start(args, format);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews vfprintf(stderr, format, args);
62c1de9d9485003ea5af13061f1d30f081442ee9Michael Graff va_end(args);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews fprintf(stderr, "\n");
62c1de9d9485003ea5af13061f1d30f081442ee9Michael Graff exit(1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
96805adfc95a9e0c5b800869dd4afe55b5616f12James Bristerstatic client_t *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsnew_client(void) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews client_t *client;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence client = isc_mempool_get(cmp);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(client != NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&client->name, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_LINK_INIT(client, link);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews client->find = NULL;
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews
96805adfc95a9e0c5b800869dd4afe55b5616f12James Brister return (client);
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews}
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic void
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsfree_client(client_t **c) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews client_t *client;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(c != NULL);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff client = *c;
62c1de9d9485003ea5af13061f1d30f081442ee9Michael Graff *c = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(client != NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_free(&client->name, mctx);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(!ISC_LINK_LINKED(client, link));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(client->find == NULL);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence isc_mempool_put(cmp, client);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic inline void
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark AndrewsCLOCK(void) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson}
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic inline void
62c1de9d9485003ea5af13061f1d30f081442ee9Michael GraffCUNLOCK(void) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewslookup_callback(isc_task_t *task, isc_event_t *ev) {
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews client_t *client;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews client = ev->ev_arg;
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley INSIST(client->find == ev->ev_sender);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews printf("Task %p got event %p type %08x from %p, client %p\n",
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews task, ev, ev->ev_type, client->find, client);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_event_free(&ev);
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CLOCK();
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_adb_dumpfind(client->find, stderr);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews dns_adb_destroyfind(&client->find);
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson ISC_LIST_UNLINK(clients, client, link);
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson free_client(&client);
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CUNLOCK();
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic void
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewscreate_managers(void) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_result_t result;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews taskmgr = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = isc_taskmgr_create(mctx, 2, 0, &taskmgr);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews check_result(result, "isc_taskmgr_create");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews timermgr = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = isc_timermgr_create(mctx, &timermgr);
7c0539bea56022274da04263eb41fbb5b8835c38Mark Andrews check_result(result, "isc_timermgr_create");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews socketmgr = NULL;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff result = isc_socketmgr_create(mctx, &socketmgr);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence check_result(result, "isc_socketmgr_create");
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews}
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrewsstatic void
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrewscreate_view(void) {
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews dns_cache_t *cache;
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews isc_result_t result;
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /*
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews * View.
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews */
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews view = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews check_result(result, "dns_view_create");
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence /*
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews * Cache.
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews */
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews cache = NULL;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews result = dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews "rbt", 0, NULL, &cache);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews check_result(result, "dns_cache_create");
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews dns_view_setcache(view, cache);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_cache_detach(&cache);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews /*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Resolver.
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews *
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews * XXXRTH hardwired number of tasks. Also, we'll need to
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews * see if we are dealing with a shared dispatcher in this view.
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews */
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews result = dns_view_createresolver(view, taskmgr, 16, socketmgr,
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews timermgr, 0, NULL, NULL);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews check_result(result, "dns_view_createresolver()");
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews rootdb = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_rootns_create(mctx, dns_rdataclass_in, NULL, &rootdb);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews check_result(result, "dns_rootns_create()");
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley dns_view_sethints(view, rootdb);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence dns_db_detach(&rootdb);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_view_freeze(view);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews}
f1f3bb3aa0ef5c4811e09953c4528a2f28a2a5b2David Lawrence
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafssonstatic void
9281e7aa775026dc47c01745fdcc438645146877Mark Andrewslookup(char *target) {
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_name_t name;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews unsigned char namedata[256];
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews client_t *client;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews isc_buffer_t t, namebuf;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews isc_result_t result;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley unsigned int options;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence INSIST(target != NULL);
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley client = new_client();
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley isc_buffer_init(&t, target, strlen(target));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_buffer_add(&t, strlen(target));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_buffer_init(&namebuf, namedata, sizeof(namedata));
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley dns_name_init(&name, NULL);
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley result = dns_name_fromtext(&name, &t, dns_rootname, ISC_FALSE,
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley &namebuf);
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley check_result(result, "dns_name_fromtext %s", target);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
f1b0e9107d5fc7669920b76b4e32f93e9d16c85cBob Halley result = dns_name_dup(&name, mctx, &client->name);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley check_result(result, "dns_name_dup %s", target);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff options = 0;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence options |= DNS_ADBFIND_INET;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley options |= DNS_ADBFIND_INET6;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley options |= DNS_ADBFIND_WANTEVENT;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley options |= DNS_ADBFIND_HINTOK;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley options |= DNS_ADBFIND_GLUEOK;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley result = dns_adb_createfind(adb, t2, lookup_callback, client,
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley &client->name, dns_rootname, options,
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley now, NULL, &client->find);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley check_result(result, "dns_adb_lookup()");
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_adb_dumpfind(client->find, stderr);
62c1de9d9485003ea5af13061f1d30f081442ee9Michael Graff
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0)
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley ISC_LIST_APPEND(clients, client, link);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley else {
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_adb_destroyfind(&client->find);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley free_client(&client);
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews }
}
int
main(int argc, char **argv) {
isc_result_t result;
isc_logdestination_t destination;
UNUSED(argc);
UNUSED(argv);
dns_result_register();
result = isc_app_start();
check_result(result, "isc_app_start()");
isc_stdtime_get(&now);
result = isc_mutex_init(&client_lock);
check_result(result, "isc_mutex_init(&client_lock)");
ISC_LIST_INIT(clients);
/*
* EVERYTHING needs a memory context.
*/
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
cmp = NULL;
RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp)
== ISC_R_SUCCESS);
isc_mempool_setname(cmp, "adb test clients");
result = isc_log_create(mctx, &lctx, &lcfg);
check_result(result, "isc_log_create()");
isc_log_setcontext(lctx);
dns_log_init(lctx);
dns_log_setcontext(lctx);
/*
* Create and install the default channel.
*/
destination.file.stream = stderr;
destination.file.name = NULL;
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
result = isc_log_createchannel(lcfg, "_default",
ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC,
&destination, ISC_LOG_PRINTTIME);
check_result(result, "isc_log_createchannel()");
result = isc_log_usechannel(lcfg, "_default", NULL, NULL);
check_result(result, "isc_log_usechannel()");
/*
* Set the initial debug level.
*/
isc_log_setdebuglevel(lctx, 99);
create_managers();
t1 = NULL;
result = isc_task_create(taskmgr, 0, &t1);
check_result(result, "isc_task_create t1");
t2 = NULL;
result = isc_task_create(taskmgr, 0, &t2);
check_result(result, "isc_task_create t2");
printf("task 1 = %p\n", t1);
printf("task 2 = %p\n", t2);
create_view();
adb = view->adb;
/*
* Lock the entire client list here. This will cause all events
* for found names to block as well.
*/
CLOCK();
lookup("f.root-servers.net."); /* Should be in hints */
lookup("www.iengines.com"); /* should fetch */
lookup("www.isc.org"); /* should fetch */
lookup("www.flame.org"); /* should fetch */
lookup("kechara.flame.org."); /* should fetch */
lookup("moghedien.flame.org."); /* should fetch */
lookup("mailrelay.flame.org."); /* should fetch */
lookup("ipv4v6.flame.org."); /* should fetch */
lookup("nonexistant.flame.org."); /* should fail to be found */
lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */
lookup("i.root-servers.net."); /* Should be in hints */
CUNLOCK();
sleep(10);
dns_adb_dump(adb, stderr);
sleep(10);
CLOCK();
lookup("f.root-servers.net."); /* Should be in hints */
lookup("www.iengines.com"); /* should fetch */
lookup("www.isc.org"); /* should fetch */
lookup("www.flame.org"); /* should fetch */
lookup("kechara.flame.org."); /* should fetch */
lookup("moghedien.flame.org."); /* should fetch */
lookup("mailrelay.flame.org."); /* should fetch */
lookup("ipv4v6.flame.org."); /* should fetch */
lookup("nonexistant.flame.org."); /* should fail to be found */
lookup("foobar.badns.flame.org."); /* should fail utterly (NS) */
lookup("i.root-servers.net."); /* Should be in hints */
CUNLOCK();
dns_adb_dump(adb, stderr);
isc_task_detach(&t1);
isc_task_detach(&t2);
isc_mem_stats(mctx, stdout);
dns_adb_dump(adb, stderr);
isc_app_run();
dns_adb_dump(adb, stderr);
dns_view_detach(&view);
adb = NULL;
isc_socketmgr_destroy(&socketmgr);
isc_timermgr_destroy(&timermgr);
fprintf(stderr, "Destroying task manager\n");
isc_taskmgr_destroy(&taskmgr);
isc_log_destroy(&lctx);
isc_mempool_destroy(&cmp);
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
isc_app_finish();
return (0);
}