adb_test.c revision efc8a09e19dfcfafa92fd2ad113073a4f5295e9b
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1998, 1999 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Permission to use, copy, modify, and distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * 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.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
33f87146a856eb6c3dfd55a8ee9c173c94f82150Andreas Gustafsson#include <config.h>
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley#include <stdio.h>
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley#include <stdlib.h>
94e25967cda41b886e33ec254b917d21df21a187Bob Halley#include <unistd.h>
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#include <string.h>
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/app.h>
94e25967cda41b886e33ec254b917d21df21a187Bob Halley#include <isc/assertions.h>
6e3a8256eed85f6704861d269ccfb35bdaeed5ffDavid Lawrence#include <isc/buffer.h>
6e3a8256eed85f6704861d269ccfb35bdaeed5ffDavid Lawrence#include <isc/error.h>
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews#include <isc/mem.h>
33f87146a856eb6c3dfd55a8ee9c173c94f82150Andreas Gustafsson#include <isc/task.h>
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews#include <isc/thread.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/timer.h>
94e25967cda41b886e33ec254b917d21df21a187Bob Halley#include <isc/result.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <isc/sockaddr.h>
94e25967cda41b886e33ec254b917d21df21a187Bob Halley#include <isc/socket.h>
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#include <isc/net.h>
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#include <dns/address.h>
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#include <dns/db.h>
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#include <dns/master.h>
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#include <dns/name.h>
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrenceisc_mem_t *mctx;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrenceisc_taskmgr_t *manager;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrenceisc_socketmgr_t *socketmgr;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrenceisc_timermgr_t *timermgr;
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrewsunsigned char namestorage1[512];
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrewsunsigned char namestorage2[512];
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrewsunsigned char namestorage3[512];
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrewsunsigned char namestorage4[512];
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleydns_view_t *view;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleydns_db_t *ns_g_rootns;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleystatic void lookup_callback(isc_task_t *, isc_event_t *);
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halleystatic void fatal(char *, ...);
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halleystatic inline void check_result(isc_result_t, char *);
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsstatic void
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsfatal(char *format, ...)
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews{
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews va_list args;
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews va_start(args, format);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews vfprintf(stderr, format, args);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews va_end(args);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews fprintf(stderr, "\n");
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews exit(1);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews}
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsstatic inline void
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewscheck_result(isc_result_t result, char *msg)
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews{
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews if (result != ISC_R_SUCCESS)
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews fatal("%s: %s", msg, isc_result_totext(result));
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews}
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsstatic char root_ns[] =
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews";\n"
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews"; Internet Root Nameservers\n"
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews";\n"
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews"; Thu Sep 23 17:57:37 PDT 1999\n"
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews";\n"
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews"$TTL 518400\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS F.ROOT-SERVERS.NET.\n"
3740b569ae76295b941d57a724a43beb75b533baBob Halley". 518400 IN NS B.ROOT-SERVERS.NET.\n"
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence". 518400 IN NS J.ROOT-SERVERS.NET.\n"
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence". 518400 IN NS K.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS L.ROOT-SERVERS.NET.\n"
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence". 518400 IN NS M.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS I.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS E.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS D.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS A.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS H.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley". 518400 IN NS C.ROOT-SERVERS.NET.\n"
3740b569ae76295b941d57a724a43beb75b533baBob Halley". 518400 IN NS G.ROOT-SERVERS.NET.\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"F.ROOT-SERVERS.NET. 3600000 IN A 192.5.5.241\n"
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence"B.ROOT-SERVERS.NET. 3600000 IN A 128.9.0.107\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"J.ROOT-SERVERS.NET. 3600000 IN A 198.41.0.10\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"K.ROOT-SERVERS.NET. 3600000 IN A 193.0.14.129\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"L.ROOT-SERVERS.NET. 3600000 IN A 198.32.64.12\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"M.ROOT-SERVERS.NET. 3600000 IN A 202.12.27.33\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"I.ROOT-SERVERS.NET. 3600000 IN A 192.36.148.17\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"E.ROOT-SERVERS.NET. 3600000 IN A 192.203.230.10\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"D.ROOT-SERVERS.NET. 3600000 IN A 128.8.10.90\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"A.ROOT-SERVERS.NET. 3600000 IN A 198.41.0.4\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"H.ROOT-SERVERS.NET. 3600000 IN A 128.63.2.53\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"C.ROOT-SERVERS.NET. 3600000 IN A 192.33.4.12\n"
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley"G.ROOT-SERVERS.NET. 3600000 IN A 192.112.36.4\n";
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halleyisc_result_t
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halleyns_rootns_init(void)
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley{
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence dns_result_t result, eresult;
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_buffer_t source;
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence size_t len;
232fd751edcb5dd2b1fd2666e039efe83d2e2b55Michael Sawyer int soacount, nscount;
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence dns_rdatacallbacks_t callbacks;
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence REQUIRE(ns_g_rootns == NULL);
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence result = dns_db_create(mctx, "rbt", dns_rootname, ISC_FALSE,
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley dns_rdataclass_in, 0, NULL, &ns_g_rootns);
3740b569ae76295b941d57a724a43beb75b533baBob Halley if (result != ISC_R_SUCCESS)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley return (result);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley dns_rdatacallbacks_init(&callbacks);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley len = strlen(root_ns);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley isc_buffer_init(&source, root_ns, len, ISC_BUFFERTYPE_TEXT);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley isc_buffer_add(&source, len);
3740b569ae76295b941d57a724a43beb75b533baBob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley result = dns_db_beginload(ns_g_rootns, &callbacks.add,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence &callbacks.add_private);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley if (result != ISC_R_SUCCESS)
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley return (result);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley result = dns_master_loadbuffer(&source, &ns_g_rootns->origin,
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley &ns_g_rootns->origin,
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley ns_g_rootns->rdclass, ISC_FALSE,
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley &soacount, &nscount, &callbacks,
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley ns_g_rootns->mctx);
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews eresult = dns_db_endload(ns_g_rootns, &callbacks.add_private);
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley if (result == ISC_R_SUCCESS)
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley result = eresult;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley if (result != ISC_R_SUCCESS)
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews goto db_detach;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley return (DNS_R_SUCCESS);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
94e25967cda41b886e33ec254b917d21df21a187Bob Halley db_detach:
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews dns_db_detach(&ns_g_rootns);
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews
94e25967cda41b886e33ec254b917d21df21a187Bob Halley return (result);
94e25967cda41b886e33ec254b917d21df21a187Bob Halley}
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrencevoid
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrencens_rootns_destroy(void)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence{
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence REQUIRE(ns_g_rootns != NULL);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_db_detach(&ns_g_rootns);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence}
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsstatic void
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrewslookup_callback(isc_task_t *task, isc_event_t *ev)
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews{
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_name_t *name;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_adbhandle_t *handle;
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence printf("Task %p got event %p type %08x from %p, arg %p\n",
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence task, ev, ev->type, ev->sender, ev->arg);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence name = ev->arg;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence handle = ev->sender;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_event_free(&ev);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_app_shutdown();
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley}
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
94e25967cda41b886e33ec254b917d21df21a187Bob Halleyvoid
94e25967cda41b886e33ec254b917d21df21a187Bob Halleycreate_managers(void)
94e25967cda41b886e33ec254b917d21df21a187Bob Halley{
94e25967cda41b886e33ec254b917d21df21a187Bob Halley isc_result_t result;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley manager = NULL;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley result = isc_taskmgr_create(mctx, 2, 0, &manager);
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews check_result(result, "isc_taskmgr_create");
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley timermgr = NULL;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley result = isc_timermgr_create(mctx, &timermgr);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "isc_timermgr_create");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley socketmgr = NULL;
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews result = isc_socketmgr_create(mctx, &socketmgr);
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews check_result(result, "isc_socketmgr_create");
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley}
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halleyvoid
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrencecreate_view(void)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence{
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_db_t *db;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_result_t result;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * View.
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews */
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews view = NULL;
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews check_result(result, "dns_view_create");
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Cache.
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence db = NULL;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_db_create(mctx, "rbt", dns_rootname, ISC_TRUE,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_rdataclass_in, 0, NULL, &db);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_view_create");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_view_setcachedb(view, db);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_db_detach(&db);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Resolver.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence *
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * XXXRTH hardwired number of tasks. Also, we'll need to
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley * see if we are dealing with a shared dispatcher in this view.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_view_createresolver(view, manager, 16, socketmgr,
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley timermgr, NULL);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_view_createresolver");
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley result = ns_rootns_init();
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley check_result(result, "ns_rootns_init()");
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley /*
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * We have default hints for class IN.
3740b569ae76295b941d57a724a43beb75b533baBob Halley */
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley dns_view_sethints(view, ns_g_rootns);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
94e25967cda41b886e33ec254b917d21df21a187Bob Halley dns_view_freeze(view);
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley}
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halleyvoid
94e25967cda41b886e33ec254b917d21df21a187Bob Halleydestroy_view(void)
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley{
94e25967cda41b886e33ec254b917d21df21a187Bob Halley dns_view_detach(&view);
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ns_rootns_destroy();
94e25967cda41b886e33ec254b917d21df21a187Bob Halley}
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
94e25967cda41b886e33ec254b917d21df21a187Bob Halleyint
94e25967cda41b886e33ec254b917d21df21a187Bob Halleymain(int argc, char **argv)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence{
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_task_t *t1, *t2;
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley isc_sockaddr_t sockaddr;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence struct in_addr ina;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_result_t result;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_name_t name1, name2, name3, name4;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_t t, namebuf;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_adb_t *adb;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_adbhandle_t *handle;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_adbaddrinfo_t *ai;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_stdtime_t now;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence (void)argc;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence (void)argv;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley dns_result_register();
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley result = isc_app_start();
c89ac488df58cf6a37918cd00236eedf015830f8Andreas Gustafsson check_result(result, "isc_app_start()");
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = isc_stdtime_get(&now);
94e25967cda41b886e33ec254b917d21df21a187Bob Halley check_result(result, "isc_stdtime_get()");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * EVERYTHING needs a memory context.
94e25967cda41b886e33ec254b917d21df21a187Bob Halley */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence mctx = NULL;
3740b569ae76295b941d57a724a43beb75b533baBob Halley RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence create_managers();
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence t1 = NULL;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = isc_task_create(manager, NULL, 0, &t1);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "isc_task_create t1");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence t2 = NULL;
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = isc_task_create(manager, NULL, 0, &t2);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley check_result(result, "isc_task_create t2");
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley printf("task 1 = %p\n", t1);
94e25967cda41b886e33ec254b917d21df21a187Bob Halley printf("task 2 = %p\n", t2);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley create_view();
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley
94e25967cda41b886e33ec254b917d21df21a187Bob Halley /*
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Create the address database.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley adb = NULL;
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence result = dns_adb_create(mctx, view, &adb);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence check_result(result, "dns_adb_create");
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence#define NAME1 "kechara.flame.org."
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence#define NAME2 "moghedien.isc.org."
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence#define NAME3 "nonexistant.flame.org."
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence#define NAME4 "f.root-servers.net."
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&t, NAME1, sizeof NAME1 - 1, ISC_BUFFERTYPE_TEXT);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_add(&t, strlen(NAME1));
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence isc_buffer_init(&namebuf, namestorage1, sizeof namestorage1,
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence ISC_BUFFERTYPE_BINARY);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence dns_name_init(&name1, NULL);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence result = dns_name_fromtext(&name1, &t, dns_rootname, ISC_FALSE,
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence &namebuf);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence check_result(result, "dns_name_fromtext NAME1");
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence isc_buffer_init(&t, NAME2, sizeof NAME2 - 1, ISC_BUFFERTYPE_TEXT);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence isc_buffer_add(&t, strlen(NAME2));
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&namebuf, namestorage2, sizeof namestorage2,
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence ISC_BUFFERTYPE_BINARY);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence dns_name_init(&name2, NULL);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence result = dns_name_fromtext(&name2, &t, dns_rootname, ISC_FALSE,
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence &namebuf);
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence check_result(result, "dns_name_fromtext NAME2");
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_buffer_init(&t, NAME3, sizeof NAME3 - 1, ISC_BUFFERTYPE_TEXT);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_add(&t, strlen(NAME3));
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_buffer_init(&namebuf, namestorage3, sizeof namestorage3,
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence ISC_BUFFERTYPE_BINARY);
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence dns_name_init(&name3, NULL);
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence result = dns_name_fromtext(&name3, &t, dns_rootname, ISC_FALSE,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence &namebuf);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_name_fromtext NAME3");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&t, NAME4, sizeof NAME4 - 1, ISC_BUFFERTYPE_TEXT);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_add(&t, strlen(NAME4));
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&namebuf, namestorage4, sizeof namestorage4,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence ISC_BUFFERTYPE_BINARY);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_name_init(&name4, NULL);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_name_fromtext(&name4, &t, dns_rootname, ISC_FALSE,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence &namebuf);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_name_fromtext NAME4");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Store this address for this name.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence ina.s_addr = inet_addr("1.2.3.4");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_sockaddr_fromin(&sockaddr, &ina, 53);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_adb_insert(adb, &name1, &sockaddr);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_adb_insert 1.2.3.4");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence printf("Added 1.2.3.4 -> NAME1\n");
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence ina.s_addr = inet_addr("1.2.3.5");
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence isc_sockaddr_fromin(&sockaddr, &ina, 53);
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence result = dns_adb_insert(adb, &name1, &sockaddr);
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence check_result(result, "dns_adb_insert 1.2.3.5");
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence printf("Added 1.2.3.5 -> NAME1\n");
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence result = dns_adb_insert(adb, &name2, &sockaddr);
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence check_result(result, "dns_adb_insert 1.2.3.5");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence printf("Added 1.2.3.5 -> NAME2\n");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence ina.s_addr = inet_addr("1.2.3.6");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_sockaddr_fromin(&sockaddr, &ina, 53);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_adb_insert(adb, &name1, &sockaddr);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_adb_insert 1.2.3.6");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence printf("Added 1.2.3.6 -> NAME1\n");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence * Try to look up a name or two.
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence */
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence handle = NULL;
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence result = dns_adb_lookup(adb, t2, lookup_callback, &name1,
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence &name1, &name1, now, &handle);
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence check_result(result, "dns_adb_lookup name1");
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence check_result(handle->result, "handle->result");
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence dns_adb_dump(adb, stderr);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence dns_adb_dumphandle(adb, handle, stderr);
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Mark one entry as lame, then look this name up again.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence ai = ISC_LIST_HEAD(handle->list);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence INSIST(ai != NULL);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence ai = ISC_LIST_NEXT(ai, link);
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence INSIST(ai != NULL);
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence result = dns_adb_marklame(adb, ai, &name1, now + 10 * 60);
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence check_result(result, "dns_adb_marklame()");
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence /*
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * And while we're here, add some goodness to it and tweak up
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * the srtt value a bit.
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence */
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson dns_adb_adjustgoodness(adb, ai, 100);
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson dns_adb_adjustgoodness(adb, ai, -50);
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson INSIST(ai->goodness == 50);
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson dns_adb_adjustsrtt(adb, ai, 10000, 0);
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson dns_adb_adjustsrtt(adb, ai, 10, 10);
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson
6184f9fc1e65ef131ea308a1a92882595bb1aeeaAndreas Gustafsson dns_adb_done(adb, &handle);
6184f9fc1e65ef131ea308a1a92882595bb1aeeaAndreas Gustafsson
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson /*
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson * look it up again
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson */
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson result = dns_adb_lookup(adb, t2, lookup_callback, &name1,
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson &name1, &name1, now, &handle);
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson check_result(result, "dns_adb_lookup name1");
check_result(handle->result, "handle->result");
dns_adb_dump(adb, stderr);
dns_adb_dumphandle(adb, handle, stderr);
/*
* delete one of the names
*/
result = dns_adb_deletename(adb, &name2);
check_result(result, "dns_adb_deletename name2");
dns_adb_dump(adb, stderr);
dns_adb_done(adb, &handle);
/*
* look up a name that doesn't exit.
*/
result = dns_adb_lookup(adb, t2, lookup_callback, &name3,
&name3, &name3, now, &handle);
if (result == ISC_R_SUCCESS) {
check_result(handle->result, "handle->result");
check_result(result, "dns_adb_lookup name3");
dns_adb_dump(adb, stderr);
dns_adb_dumphandle(adb, handle, stderr);
} else {
fprintf(stderr, "lookup of name3: %s\n",
isc_result_totext(result));
}
dns_adb_dump(adb, stderr);
if (handle != NULL)
dns_adb_done(adb, &handle);
/*
* Look up a host that will be in the hints database
*/
result = dns_adb_lookup(adb, t2, lookup_callback, &name4,
&name4, dns_rootname, now, &handle);
if (result == ISC_R_SUCCESS) {
check_result(handle->result, "handle->result");
check_result(result, "dns_adb_lookup name4");
dns_adb_dump(adb, stderr);
dns_adb_dumphandle(adb, handle, stderr);
} else {
fprintf(stderr, "lookup of name4: %s\n",
isc_result_totext(result));
}
dns_adb_dump(adb, stderr);
if (handle != NULL) {
dns_adb_dumphandle(adb, handle, stderr);
dns_adb_done(adb, &handle);
}
isc_task_detach(&t1);
isc_task_detach(&t2);
isc_mem_stats(mctx, stdout);
dns_adb_dump(adb, stderr);
dns_adb_destroy(&adb);
isc_app_run();
destroy_view();
isc_socketmgr_destroy(&socketmgr);
isc_timermgr_destroy(&timermgr);
fprintf(stderr, "Destroying task manager\n");
isc_taskmgr_destroy(&manager);
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
isc_app_finish();
return (0);
}