99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley/*
f6b909274159da7aaad8463c90f15018136cf6cbTinderbox User * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2009, 2012, 2015-2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \author
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * Principal Author: Bob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <config.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <stdlib.h>
142784f574e0b63e8bbcccb762eb8727ac7c76feBrian Wellington#include <string.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/app.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <isc/commandline.h>
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews#include <isc/entropy.h>
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews#include <isc/hash.h>
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson#include <isc/netaddr.h>
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont#include <isc/print.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <isc/task.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <isc/timer.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <isc/util.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <dns/adb.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <dns/cache.h>
558ab0f6a8046499bfe3e39ea4789036313b72b3Michael Graff#include <dns/dispatch.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <dns/events.h>
de4ef688d73a449d4c1218adbb35a4f70a71e672Brian Wellington#include <dns/forward.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley#include <dns/log.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/resolver.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/result.h>
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic isc_mem_t *mctx = NULL;
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrewsstatic isc_entropy_t *ectx = NULL;
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafssonstatic isc_taskmgr_t *taskmgr;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic dns_view_t *view = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic dns_adbfind_t *find = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic isc_task_t *task = NULL;
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrewsstatic dns_fixedname_t fixed;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic dns_fixedname_t target;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic isc_log_t *lctx;
6af51ff1a30dd977c4fc6c342a0661bb4f6501a5Bob Halleystatic isc_logconfig_t *lcfg;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic unsigned int level = 0;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic void adb_callback(isc_task_t *task, isc_event_t *event);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic void
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleylog_init(void) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_logdestination_t destination;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley unsigned int flags;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley /*
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * Setup a logging context.
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
6af51ff1a30dd977c4fc6c342a0661bb4f6501a5Bob Halley RUNTIME_CHECK(isc_log_create(mctx, &lctx, &lcfg) == ISC_R_SUCCESS);
c90f5e8d1edbd5c277f2ee320167a12a30ba7c7bMichael Graff isc_log_setcontext(lctx);
6af51ff1a30dd977c4fc6c342a0661bb4f6501a5Bob Halley dns_log_init(lctx);
c90f5e8d1edbd5c277f2ee320167a12a30ba7c7bMichael Graff dns_log_setcontext(lctx);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley /*
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * Create and install the default channel.
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley destination.file.stream = stderr;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley destination.file.name = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley destination.file.versions = ISC_LOG_ROLLNEVER;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley destination.file.maximum_size = 0;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley flags = ISC_LOG_PRINTTIME;
6af51ff1a30dd977c4fc6c342a0661bb4f6501a5Bob Halley RUNTIME_CHECK(isc_log_createchannel(lcfg, "_default",
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_LOG_TOFILEDESC,
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_LOG_DYNAMIC,
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley &destination, flags) ==
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_R_SUCCESS);
6af51ff1a30dd977c4fc6c342a0661bb4f6501a5Bob Halley RUNTIME_CHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL) ==
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_log_setdebuglevel(lctx, level);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley}
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic void
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrewsprint_addresses(dns_adbfind_t *adbfind) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_adbaddrinfo_t *address;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrews for (address = ISC_LIST_HEAD(adbfind->list);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley address != NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley address = ISC_LIST_NEXT(address, publink)) {
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson isc_netaddr_t netaddr;
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson char text[ISC_NETADDR_FORMATSIZE];
315879710704bbcf66df301664cd90df8ad31265David Lawrence isc_netaddr_fromsockaddr(&netaddr, &address->sockaddr);
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson isc_netaddr_format(&netaddr, text, sizeof(text));
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson printf("%s\n", text);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley}
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic void
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleyprint_name(dns_name_t *name) {
e605e98f3e4be079f545b26bb53ba02a6d04b0b6Andreas Gustafsson char text[DNS_NAME_FORMATSIZE];
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson dns_name_format(name, text, sizeof(text));
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson printf("%s\n", text);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley}
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic void
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleydo_find(isc_boolean_t want_event) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_result_t result;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_boolean_t done = ISC_FALSE;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley unsigned int options;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley options = DNS_ADBFIND_INET | DNS_ADBFIND_INET6;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (want_event)
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley options |= DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_EMPTYEVENT;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_fixedname_init(&target);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley result = dns_adb_createfind(view->adb, task, adb_callback, NULL,
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrews dns_fixedname_name(&fixed),
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews dns_rootname, 0, options, 0,
315879710704bbcf66df301664cd90df8ad31265David Lawrence dns_fixedname_name(&target), 0,
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley &find);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (result == ISC_R_SUCCESS) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (!ISC_LIST_EMPTY(find->list)) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley /*
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * We have at least some of the addresses for the
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * name.
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley INSIST((find->options & DNS_ADBFIND_WANTEVENT) == 0);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley print_addresses(find);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley done = ISC_TRUE;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley } else {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley /*
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * We don't know any of the addresses for this
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * name.
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if ((find->options & DNS_ADBFIND_WANTEVENT) == 0) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley /*
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * And ADB isn't going to send us any events
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * either. This query loses.
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley done = ISC_TRUE;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley /*
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * If the DNS_ADBFIND_WANTEVENT flag was set, we'll
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley * get an event when something happens.
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley */
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley } else if (result == DNS_R_ALIAS) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley print_name(dns_fixedname_name(&target));
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley done = ISC_TRUE;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley } else {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley printf("dns_adb_createfind() returned %s\n",
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_result_totext(result));
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley done = ISC_TRUE;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (done) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (find != NULL)
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_adb_destroyfind(&find);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_app_shutdown();
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley}
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic void
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleyadb_callback(isc_task_t *etask, isc_event_t *event) {
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff unsigned int type = event->ev_type;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley REQUIRE(etask == task);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_event_free(&event);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_adb_destroyfind(&find);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (type == DNS_EVENT_ADBMOREADDRESSES)
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley do_find(ISC_FALSE);
808af432356c7592e80bd41416eca61e7bc8791dBob Halley else if (type == DNS_EVENT_ADBNOMOREADDRESSES) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley printf("no more addresses\n");
808af432356c7592e80bd41416eca61e7bc8791dBob Halley isc_app_shutdown();
808af432356c7592e80bd41416eca61e7bc8791dBob Halley } else {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley printf("unexpected ADB event type %u\n", type);
808af432356c7592e80bd41416eca61e7bc8791dBob Halley isc_app_shutdown();
808af432356c7592e80bd41416eca61e7bc8791dBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley}
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleystatic void
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrewsrun(isc_task_t *xtask, isc_event_t *event) {
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrews UNUSED(xtask);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley do_find(ISC_TRUE);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_event_free(&event);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley}
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleyint
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halleymain(int argc, char *argv[]) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_boolean_t verbose = ISC_FALSE;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley unsigned int workers = 2;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_timermgr_t *timermgr;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley int ch;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_socketmgr_t *socketmgr;
558ab0f6a8046499bfe3e39ea4789036313b72b3Michael Graff dns_dispatchmgr_t *dispatchmgr;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_cache_t *cache;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_buffer_t b;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_result_register();
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley mctx = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS);
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews == ISC_R_SUCCESS);
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley while ((ch = isc_commandline_parse(argc, argv, "d:vw:")) != -1) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley switch (ch) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley case 'd':
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley level = (unsigned int)atoi(isc_commandline_argument);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley break;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley case 'v':
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley verbose = ISC_TRUE;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley break;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley case 'w':
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley workers = (unsigned int)atoi(isc_commandline_argument);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley break;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley log_init();
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (verbose) {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley printf("%u workers\n", workers);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley printf("IPv4: %s\n", isc_result_totext(isc_net_probeipv4()));
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley printf("IPv6: %s\n", isc_result_totext(isc_net_probeipv6()));
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley taskmgr = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &taskmgr) ==
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley task = NULL;
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley RUNTIME_CHECK(isc_task_create(taskmgr, 0, &task) ==
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_R_SUCCESS);
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson isc_task_setname(task, "byname", NULL);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
558ab0f6a8046499bfe3e39ea4789036313b72b3Michael Graff dispatchmgr = NULL;
4e21e54a0394d0f87798620a95c1f675c0b0d09cMichael Graff RUNTIME_CHECK(dns_dispatchmgr_create(mctx, NULL, &dispatchmgr)
558ab0f6a8046499bfe3e39ea4789036313b72b3Michael Graff == ISC_R_SUCCESS);
558ab0f6a8046499bfe3e39ea4789036313b72b3Michael Graff
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley timermgr = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley socketmgr = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley cache = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(dns_cache_create(mctx, taskmgr, timermgr,
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_rdataclass_in, "rbt", 0, NULL,
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley &cache) == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley view = NULL;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(dns_view_create(mctx, dns_rdataclass_in, "default",
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley &view) == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson {
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson unsigned int attrs;
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson dns_dispatch_t *disp4 = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_dispatch_t *disp6 = NULL;
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson if (isc_net_probeipv4() == ISC_R_SUCCESS) {
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson isc_sockaddr_t any4;
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson isc_sockaddr_any(&any4);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP;
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson socketmgr,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson taskmgr, &any4,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson 512, 6, 1024,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson 17, 19, attrs,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson attrs, &disp4)
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson == ISC_R_SUCCESS);
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson INSIST(disp4 != NULL);
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson }
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson if (isc_net_probeipv6() == ISC_R_SUCCESS) {
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson isc_sockaddr_t any6;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson isc_sockaddr_any6(&any6);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP;
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson socketmgr,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson taskmgr, &any6,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson 512, 6, 1024,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson 17, 19, attrs,
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson attrs, &disp6)
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson == ISC_R_SUCCESS);
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson INSIST(disp6 != NULL);
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
4e8fe357a619ae2b789b15df7e3d6abf782b4a71Evan Hunt RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10, 1,
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson socketmgr,
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson timermgr, 0,
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson dispatchmgr,
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson disp4, disp6) ==
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff ISC_R_SUCCESS);
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson if (disp4 != NULL)
7cbfebb762d0d9ba77699e2c15530278e0e4980eAndreas Gustafsson dns_dispatch_detach(&disp4);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (disp6 != NULL)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_dispatch_detach(&disp6);
95b41befcb9e75df2b451ceeb9f8812ccedcc25fAndreas Gustafsson }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley {
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley struct in_addr ina;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_sockaddr_t sa;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_sockaddrlist_t sal;
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_LIST_INIT(sal);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ina.s_addr = inet_addr("127.0.0.1");
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_sockaddr_fromin(&sa, &ina, 53);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_LIST_APPEND(sal, &sa, link);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
de4ef688d73a449d4c1218adbb35a4f70a71e672Brian Wellington RUNTIME_CHECK(dns_fwdtable_add(view->fwdtable, dns_rootname,
de4ef688d73a449d4c1218adbb35a4f70a71e672Brian Wellington &sal, dns_fwdpolicy_only)
de4ef688d73a449d4c1218adbb35a4f70a71e672Brian Wellington == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley }
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_view_setcache(view, cache);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_view_freeze(view);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_cache_detach(&cache);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley printf("name = %s\n", argv[isc_commandline_index]);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_buffer_init(&b, argv[isc_commandline_index],
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence strlen(argv[isc_commandline_index]));
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_buffer_add(&b, strlen(argv[isc_commandline_index]));
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrews dns_fixedname_init(&fixed);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_fixedname_init(&target);
c2687b0594673a6e2b8558cc92d9936af069edacMark Andrews RUNTIME_CHECK(dns_name_fromtext(dns_fixedname_name(&fixed), &b,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 dns_rootname, 0, NULL) ==
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley RUNTIME_CHECK(isc_app_onrun(mctx, task, run, NULL) == ISC_R_SUCCESS);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley (void)isc_app_run();
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley dns_view_detach(&view);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_task_shutdown(task);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_task_detach(&task);
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson
bfa633fc0e5dea8f65676c5393993ba7053a9899Andreas Gustafsson dns_dispatchmgr_destroy(&dispatchmgr);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_taskmgr_destroy(&taskmgr);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_socketmgr_destroy(&socketmgr);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_timermgr_destroy(&timermgr);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_log_destroy(&lctx);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews isc_hash_destroy();
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews isc_entropy_detach(&ectx);
9297259c7abecc78470fdeca173c101137e4b5bbMark Andrews
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley if (verbose)
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_mem_stats(mctx, stdout);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_mem_destroy(&mctx);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley isc_app_finish();
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley return (0);
99a9539ccde4a3769fd890bdae5bcce3a3492fbaBob Halley}