adb_test.c revision 499b34cea04a46823d003d4c0520c8b03e8513cb
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews/*
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews * Copyright (C) 1999-2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
60988462e5d6db53205851d056e3482a29239be9Evan Hunt * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
60988462e5d6db53205851d056e3482a29239be9Evan Hunt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
60988462e5d6db53205851d056e3482a29239be9Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews */
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews/* $Id: adb_test.c,v 1.61 2001/01/09 21:40:48 bwelling Exp $ */
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <config.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <stdlib.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <string.h>
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki#include <unistd.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews#include <isc/app.h>
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews#include <isc/buffer.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <isc/task.h>
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki#include <isc/timer.h>
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki#include <isc/socket.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <isc/util.h>
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <dns/adb.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <dns/cache.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <dns/dispatch.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <dns/db.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <dns/log.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <dns/rootns.h>
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews#include <dns/result.h>
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewstypedef struct client client_t;
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrewsstruct client {
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews dns_name_t name;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews const char *target;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki ISC_LINK(client_t) link;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki dns_adbfind_t *find;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews};
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_mem_t *mctx;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_mempool_t *cmp;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_log_t *lctx;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_logconfig_t *lcfg;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_taskmgr_t *taskmgr;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_socketmgr_t *socketmgr;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_timermgr_t *timermgr;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecickidns_dispatchmgr_t *dispatchmgr;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_task_t *t1, *t2;
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrewsdns_view_t *view;
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrewsdns_db_t *rootdb;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark AndrewsISC_LIST(client_t) clients;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_mutex_t client_lock;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsisc_stdtime_t now;
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrewsdns_adb_t *adb;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsstatic void
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewscheck_result(isc_result_t result, const char *format, ...) {
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews va_list args;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews if (result == ISC_R_SUCCESS)
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews return;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews va_start(args, format);
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews vfprintf(stderr, format, args);
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews va_end(args);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews fprintf(stderr, ": %s\n", isc_result_totext(result));
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki exit(1);
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki}
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrewsstatic client_t *
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsnew_client(void) {
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews client_t *client;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews client = isc_mempool_get(cmp);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews INSIST(client != NULL);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews dns_name_init(&client->name, NULL);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews ISC_LINK_INIT(client, link);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews client->find = NULL;
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews return (client);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews}
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecickistatic void
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsfree_client(client_t **c) {
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews client_t *client;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews INSIST(c != NULL);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews client = *c;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews *c = NULL;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews INSIST(client != NULL);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews dns_name_free(&client->name, mctx);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews INSIST(!ISC_LINK_LINKED(client, link));
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews INSIST(client->find == NULL);
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews isc_mempool_put(cmp, client);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews}
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsstatic inline void
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark AndrewsCLOCK(void) {
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews}
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsstatic inline void
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark AndrewsCUNLOCK(void) {
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews}
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsstatic void
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrewslookup_callback(isc_task_t *task, isc_event_t *ev) {
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews client_t *client;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews client = ev->ev_arg;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews INSIST(client->find == ev->ev_sender);
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews printf("NAME %s:\n\tTask %p got event %p type %08x from %p, client %p\n\terr4: %s err6: %s\n",
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews client->target,
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews task, ev, ev->ev_type, client->find, client,
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews isc_result_totext(client->find->result_v4),
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews isc_result_totext(client->find->result_v6));
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki isc_event_free(&ev);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews ev = NULL;
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews CLOCK();
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews dns_adb_dumpfind(client->find, stderr);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews dns_adb_destroyfind(&client->find);
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews ISC_LIST_UNLINK(clients, client, link);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews free_client(&client);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews CUNLOCK();
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews}
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecickistatic void
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecickicreate_managers(void) {
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_result_t result;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews taskmgr = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = isc_taskmgr_create(mctx, 5, 0, &taskmgr);
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki check_result(result, "isc_taskmgr_create");
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews timermgr = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = isc_timermgr_create(mctx, &timermgr);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "isc_timermgr_create");
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews socketmgr = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = isc_socketmgr_create(mctx, &socketmgr);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "isc_socketmgr_create");
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dispatchmgr = NULL;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki result = dns_dispatchmgr_create(mctx, NULL, &dispatchmgr);
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki check_result(result, "dns_dispatchmgr_create");
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews}
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrewsstatic void
ea8278253210df030a24f0c89342b43fe279a127Mark Andrewscreate_view(void) {
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki dns_cache_t *cache;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki isc_result_t result;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews /*
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews * View.
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews */
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews view = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "dns_view_create");
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews /*
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki * Cache.
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki */
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews cache = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews "rbt", 0, NULL, &cache);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "dns_cache_create");
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_view_setcache(view, cache);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_cache_detach(&cache);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews {
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews unsigned int attrs;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_sockaddr_t any4, any6;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_dispatch_t *disp4 = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_dispatch_t *disp6 = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_sockaddr_any(&any4);
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki isc_sockaddr_any6(&any6);
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews taskmgr, &any4, 512, 6, 1024,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews 17, 19, attrs, attrs, &disp4)
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki == ISC_R_SUCCESS);
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki INSIST(disp4 != NULL);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews taskmgr, &any6, 512, 6, 1024,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews 17, 19, attrs, attrs, &disp6)
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews == ISC_R_SUCCESS);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews INSIST(disp6 != NULL);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10,
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki socketmgr,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews timermgr, 0,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dispatchmgr,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews disp4, disp6) ==
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews ISC_R_SUCCESS);
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki }
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews rootdb = NULL;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = dns_rootns_create(mctx, dns_rdataclass_in, NULL, &rootdb);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "dns_rootns_create()");
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_view_sethints(view, rootdb);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_db_detach(&rootdb);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_view_freeze(view);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews}
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrewsstatic void
ea8278253210df030a24f0c89342b43fe279a127Mark Andrewslookup(const char *target) {
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_name_t name;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews unsigned char namedata[256];
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews client_t *client;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_buffer_t t, namebuf;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_result_t result;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews unsigned int options;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews INSIST(target != NULL);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews client = new_client();
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_buffer_init(&t, target, strlen(target));
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_buffer_add(&t, strlen(target));
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki isc_buffer_init(&namebuf, namedata, sizeof(namedata));
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_name_init(&name, NULL);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = dns_name_fromtext(&name, &t, dns_rootname, ISC_FALSE,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews &namebuf);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "dns_name_fromtext %s", target);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = dns_name_dup(&name, mctx, &client->name);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "dns_name_dup %s", target);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews options = 0;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews options |= DNS_ADBFIND_INET;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews options |= DNS_ADBFIND_INET6;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews options |= DNS_ADBFIND_WANTEVENT;
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews options |= DNS_ADBFIND_HINTOK;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki options |= DNS_ADBFIND_GLUEOK;
cc51cd2d2076e33117c60c9effcb8caccde4983bWitold Krecicki result = dns_adb_createfind(adb, t2, lookup_callback, client,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews &client->name, dns_rootname, options,
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews now, NULL, view->dstport, &client->find);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews#if 0
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews check_result(result, "dns_adb_createfind()");
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews#endif
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews dns_adb_dumpfind(client->find, stderr);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0) {
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews client->target = target;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews ISC_LIST_APPEND(clients, client, link);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews } else {
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews printf("NAME %s: err4 %s, err6 %s\n",
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews target, isc_result_totext(client->find->result_v4),
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews isc_result_totext(client->find->result_v6));
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews dns_adb_destroyfind(&client->find);
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrews free_client(&client);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews }
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews}
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
e27d55e3ee06b6edcf625b8920a5c809da7f0b98Mark Andrewsint
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrewsmain(int argc, char **argv) {
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews isc_result_t result;
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews isc_logdestination_t destination;
0ce9fba8f0efa1f8107fbcf194009ce1199769e9Evan Hunt
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews UNUSED(argc);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews UNUSED(argv);
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews dns_result_register();
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews result = isc_app_start();
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews check_result(result, "isc_app_start()");
2cd8fa3ef9b168429dcf76603e7b95c58317dd28Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews isc_stdtime_get(&now);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews result = isc_mutex_init(&client_lock);
ea8278253210df030a24f0c89342b43fe279a127Mark Andrews 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, 2);
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 */
lookup("www.firstcard.com.");
lookup("dns04.flame.org.");
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();
sleep(20);
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);
}