adb_test.c revision 1a0e33bc2044e1902493111db14cbf793083ac47
7e4d75a5daeaaf8a7f559f9bd7fbf540184e235cMark Andrews * Copyright (C) 1999 Internet Software Consortium.
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 * 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
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic void check_result(isc_result_t, char *, ...);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrewsstatic void lookup_callback(isc_task_t *, isc_event_t *);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void CLOCK(void);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void CUNLOCK(void);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewscheck_result(isc_result_t result, char *format, ...)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RUNTIME_CHECK(isc_mutex_lock(&client_lock) == ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewsstatic inline void
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RUNTIME_CHECK(isc_mutex_unlock(&client_lock) == ISC_R_SUCCESS);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrewslookup_callback(isc_task_t *task, isc_event_t *ev)
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews printf("Task %p got event %p type %08x from %p, client %p\n",
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_taskmgr_create(mctx, 2, 0, &taskmgr);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = isc_socketmgr_create(mctx, &socketmgr);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews result = dns_view_create(mctx, dns_rdataclass_in, "_default", &view);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in,
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 result = dns_view_createresolver(view, taskmgr, 16, socketmgr,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "dns_view_createresolver()");
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_rootns_create(mctx, dns_rdataclass_in, NULL, &rootdb);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews unsigned int options;
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_init(&t, target, strlen(target), ISC_BUFFERTYPE_TEXT);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews isc_buffer_init(&namebuf, namedata, sizeof namedata,
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = dns_name_fromtext(&name, &t, dns_rootname, ISC_FALSE,
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "dns_name_fromtext %s", target);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_name_dup(&name, mctx, &client->name);
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews check_result(result, "dns_name_dup %s", target);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = dns_adb_createfind(adb, t2, lookup_callback, client,
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_mutex_init(&client_lock)");
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews * EVERYTHING needs a memory context.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
af9cfbc64363b61aa5903dd916e9fbc152084d4cMark Andrews RUNTIME_CHECK(isc_mempool_create(mctx, sizeof(client_t), &cmp)
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Create and install the default channel.
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = isc_log_createchannel(lctx, "_default",
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews check_result(result, "isc_log_createchannel()");
1a03b5e68553c37e9cc0097368909dfc37fb8cefMark Andrews result = isc_log_usechannel(lctx, "_default", NULL, NULL);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Set the initial debug level.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_task_create(taskmgr, NULL, 0, &t1);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews result = isc_task_create(taskmgr, NULL, 0, &t2);
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * Lock the entire client list here. This will cause all events
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews * for found names to block as well.
7d2b275f7e9238e2c709737601f6260b5a9a4ee1Mark Andrews lookup("f.root-servers.net."); /* Should be in hints */
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 lookup("f.root-servers.net."); /* Should be in hints */
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 */