adb_test.c revision efc8a09e19dfcfafa92fd2ad113073a4f5295e9b
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 1998, 1999 Internet Software Consortium.
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.
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
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 *);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsstatic inline void
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews fatal("%s: %s", msg, isc_result_totext(result));
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewsstatic char root_ns[] =
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews"; Internet Root Nameservers\n"
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews"; Thu Sep 23 17:57:37 PDT 1999\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";
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence result = dns_db_create(mctx, "rbt", dns_rootname, ISC_FALSE,
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley isc_buffer_init(&source, root_ns, len, ISC_BUFFERTYPE_TEXT);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley result = dns_db_beginload(ns_g_rootns, &callbacks.add,
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley result = dns_master_loadbuffer(&source, &ns_g_rootns->origin,
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrews eresult = dns_db_endload(ns_g_rootns, &callbacks.add_private);
df0f58959ed82a2a43ca8d816ce9592541df9f2fMark Andrewslookup_callback(isc_task_t *task, isc_event_t *ev)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence printf("Task %p got event %p type %08x from %p, arg %p\n",
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley result = isc_taskmgr_create(mctx, 2, 0, &manager);
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews result = isc_socketmgr_create(mctx, &socketmgr);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_db_create(mctx, "rbt", dns_rootname, ISC_TRUE,
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 result = dns_view_createresolver(view, manager, 16, socketmgr,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_view_createresolver");
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * We have default hints for class IN.
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * EVERYTHING needs a memory context.
3740b569ae76295b941d57a724a43beb75b533baBob Halley RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = isc_task_create(manager, NULL, 0, &t1);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = isc_task_create(manager, NULL, 0, &t2);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Create the address database.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&t, NAME1, sizeof NAME1 - 1, ISC_BUFFERTYPE_TEXT);
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence isc_buffer_init(&namebuf, namestorage1, sizeof namestorage1,
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence result = dns_name_fromtext(&name1, &t, dns_rootname, ISC_FALSE,
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence check_result(result, "dns_name_fromtext NAME1");
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence isc_buffer_init(&t, NAME2, sizeof NAME2 - 1, ISC_BUFFERTYPE_TEXT);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&namebuf, namestorage2, sizeof namestorage2,
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence result = dns_name_fromtext(&name2, &t, dns_rootname, ISC_FALSE,
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence check_result(result, "dns_name_fromtext NAME2");
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_buffer_init(&t, NAME3, sizeof NAME3 - 1, ISC_BUFFERTYPE_TEXT);
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_buffer_init(&namebuf, namestorage3, sizeof namestorage3,
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence result = dns_name_fromtext(&name3, &t, dns_rootname, ISC_FALSE,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_name_fromtext NAME3");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&t, NAME4, sizeof NAME4 - 1, ISC_BUFFERTYPE_TEXT);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence isc_buffer_init(&namebuf, namestorage4, sizeof namestorage4,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_name_fromtext(&name4, &t, dns_rootname, ISC_FALSE,
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_name_fromtext NAME4");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Store this address for this name.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_adb_insert(adb, &name1, &sockaddr);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_adb_insert 1.2.3.4");
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence result = dns_adb_insert(adb, &name1, &sockaddr);
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence check_result(result, "dns_adb_insert 1.2.3.5");
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence result = dns_adb_insert(adb, &name2, &sockaddr);
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence check_result(result, "dns_adb_insert 1.2.3.5");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence result = dns_adb_insert(adb, &name1, &sockaddr);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence check_result(result, "dns_adb_insert 1.2.3.6");
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence * Try to look up a name or two.
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence result = dns_adb_lookup(adb, t2, lookup_callback, &name1,
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence check_result(result, "dns_adb_lookup name1");
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrence check_result(handle->result, "handle->result");
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Mark one entry as lame, then look this name up again.
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence result = dns_adb_marklame(adb, ai, &name1, now + 10 * 60);
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * And while we're here, add some goodness to it and tweak up
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * the srtt value a bit.
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson * look it up again
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson result = dns_adb_lookup(adb, t2, lookup_callback, &name1,
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson check_result(result, "dns_adb_lookup name1");
isc_app_run();
destroy_view();