static isc_result_t make_zone(const char *name, dns_zone_t **zonep) { isc_result_t result; dns_view_t *view = NULL; dns_zone_t *zone = NULL; isc_buffer_t buffer; dns_fixedname_t fixorigin; dns_name_t *origin; CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view)); CHECK(dns_zone_create(&zone, mctx)); isc_buffer_init(&buffer, name, strlen(name)); isc_buffer_add(&buffer, strlen(name)); dns_fixedname_init(&fixorigin); origin = dns_fixedname_name(&fixorigin); CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL)); CHECK(dns_zone_setorigin(zone, origin)); dns_zone_setview(zone, view); dns_zone_settype(zone, dns_zone_master); dns_zone_setclass(zone, view->rdclass); dns_view_detach(&view); *zonep = zone; return (ISC_R_SUCCESS); cleanup: if (zone != NULL) dns_zone_detach(&zone); if (view != NULL) dns_view_detach(&view); return (result); }
void ns_lwdmanager_detach(ns_lwresd_t **lwresdp) { ns_lwresd_t *lwresd; isc_mem_t *mctx; isc_boolean_t done = ISC_FALSE; INSIST(lwresdp != NULL && *lwresdp != NULL); INSIST(VALID_LWRESD(*lwresdp)); lwresd = *lwresdp; *lwresdp = NULL; LOCK(&lwresd->lock); INSIST(lwresd->refs > 0); lwresd->refs--; if (lwresd->refs == 0) done = ISC_TRUE; UNLOCK(&lwresd->lock); if (!done) return; dns_view_detach(&lwresd->view); if (lwresd->search != NULL) ns_lwsearchlist_detach(&lwresd->search); mctx = lwresd->mctx; lwresd->magic = 0; isc_mem_put(mctx, lwresd, sizeof(*lwresd)); isc_mem_detach(&mctx); }
/* * Create a zone with origin 'name', return a pointer to the zone object in * 'zonep'. If 'view' is set, add the zone to that view; otherwise, create * a new view for the purpose. * * If the created view is going to be needed by the caller subsequently, * then 'keepview' should be set to true; this will prevent the view * from being detached. In this case, the caller is responsible for * detaching the view. */ isc_result_t dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, isc_boolean_t keepview) { isc_result_t result; dns_zone_t *zone = NULL; isc_buffer_t buffer; dns_fixedname_t fixorigin; dns_name_t *origin; if (view == NULL) CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view)); else if (!keepview) keepview = ISC_TRUE; zone = *zonep; if (zone == NULL) CHECK(dns_zone_create(&zone, mctx)); isc_buffer_constinit(&buffer, name, strlen(name)); isc_buffer_add(&buffer, strlen(name)); dns_fixedname_init(&fixorigin); origin = dns_fixedname_name(&fixorigin); CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL)); CHECK(dns_zone_setorigin(zone, origin)); dns_zone_setview(zone, view); dns_zone_settype(zone, dns_zone_master); dns_zone_setclass(zone, view->rdclass); dns_view_addzone(view, zone); if (!keepview) dns_view_detach(&view); *zonep = zone; return (ISC_R_SUCCESS); cleanup: if (zone != NULL) dns_zone_detach(&zone); if (view != NULL) dns_view_detach(&view); return (result); }
static void teardown(void) { /* 7 */ dns_dispatch_detach(&dispatch_v4); /* 6 */ dns_view_detach(&view); /* 5 */ dns_dispatchmgr_destroy(&dispatch_manager); /* 4 */ isc_socketmgr_destroy(&socket_manager); /* 3 */ isc_taskmgr_destroy(&task_manager); /* 2 */ isc_timermgr_destroy(&timer_manager); /* 1 */ isc_mem_destroy(&mctx); }
/* * Create a view. */ isc_result_t dns_test_makeview(const char *name, dns_view_t **viewp) { isc_result_t result; dns_view_t *view = NULL; CHECK(dns_view_create(mctx, dns_rdataclass_in, name, &view)); *viewp = view; return (ISC_R_SUCCESS); cleanup: if (view != NULL) dns_view_detach(&view); return (result); }
int main(int argc, char **argv) { isc_result_t result; isc_logdestination_t destination; UNUSED(argc); UNUSED(argv); dns_result_register(); result = isc_app_start(); check_result(result, "isc_app_start()"); isc_stdtime_get(&now); result = isc_mutex_init(&client_lock); check_result(result, "isc_mutex_init(&client_lock)"); ISC_LIST_INIT(clients); /* * EVERYTHING needs a memory context. */ 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_entropy_create(mctx, &ectx); check_result(result, "isc_entropy_create()"); result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE); check_result(result, "isc_hash_create()"); 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; fprintf(stderr, "Destroying socket manager\n"); isc_socketmgr_destroy(&socketmgr); fprintf(stderr, "Destroying timer manager\n"); isc_timermgr_destroy(&timermgr); fprintf(stderr, "Destroying task manager\n"); isc_taskmgr_destroy(&taskmgr); isc_log_destroy(&lctx); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mempool_destroy(&cmp); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
int main(int argc, char *argv[]) { isc_mem_t *mctx; isc_boolean_t verbose = ISC_FALSE; unsigned int workers = 2; isc_taskmgr_t *taskmgr; isc_task_t *task; isc_timermgr_t *timermgr; dns_view_t *view; int ch; isc_socketmgr_t *socketmgr; dns_dispatchmgr_t *dispatchmgr; isc_netaddr_t na; dns_byaddr_t *byaddr; isc_result_t result; unsigned int options = 0; dns_cache_t *cache; RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS); dns_result_register(); mctx = NULL; RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); while ((ch = isc_commandline_parse(argc, argv, "nvw:")) != -1) { switch (ch) { case 'n': /* * We only try nibbles, so do nothing for this option. */ break; case 'v': verbose = ISC_TRUE; break; case 'w': workers = (unsigned int)atoi(isc_commandline_argument); break; } } if (verbose) { printf("%u workers\n", workers); printf("IPv4: %s\n", isc_result_totext(isc_net_probeipv4())); printf("IPv6: %s\n", isc_result_totext(isc_net_probeipv6())); } taskmgr = NULL; RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &taskmgr) == ISC_R_SUCCESS); task = NULL; RUNTIME_CHECK(isc_task_create(taskmgr, 0, &task) == ISC_R_SUCCESS); isc_task_setname(task, "byaddr", NULL); dispatchmgr = NULL; RUNTIME_CHECK(dns_dispatchmgr_create(mctx, NULL, &dispatchmgr) == ISC_R_SUCCESS); timermgr = NULL; RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS); socketmgr = NULL; RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS); cache = NULL; RUNTIME_CHECK(dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in, "rbt", 0, NULL, &cache) == ISC_R_SUCCESS); view = NULL; RUNTIME_CHECK(dns_view_create(mctx, dns_rdataclass_in, "default", &view) == ISC_R_SUCCESS); { unsigned int attrs; dns_dispatch_t *disp4 = NULL; dns_dispatch_t *disp6 = NULL; if (isc_net_probeipv4() == ISC_R_SUCCESS) { isc_sockaddr_t any4; isc_sockaddr_any(&any4); attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP; RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &any4, 512, 6, 1024, 17, 19, attrs, attrs, &disp4) == ISC_R_SUCCESS); INSIST(disp4 != NULL); } if (isc_net_probeipv6() == ISC_R_SUCCESS) { isc_sockaddr_t any6; isc_sockaddr_any6(&any6); attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP; RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &any6, 512, 6, 1024, 17, 19, attrs, attrs, &disp6) == ISC_R_SUCCESS); INSIST(disp6 != NULL); } RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10, 1, socketmgr, timermgr, 0, dispatchmgr, disp4, disp6) == ISC_R_SUCCESS); if (disp4 != NULL) dns_dispatch_detach(&disp4); if (disp6 != NULL) dns_dispatch_detach(&disp6); } { struct in_addr ina; isc_sockaddr_t sa; isc_sockaddrlist_t sal; ISC_LIST_INIT(sal); ina.s_addr = inet_addr("127.0.0.1"); isc_sockaddr_fromin(&sa, &ina, 53); ISC_LIST_APPEND(sal, &sa, link); RUNTIME_CHECK(dns_fwdtable_add(view->fwdtable, dns_rootname, &sal, dns_fwdpolicy_only) == ISC_R_SUCCESS); } dns_view_setcache(view, cache); dns_view_freeze(view); dns_cache_detach(&cache); printf("address = %s\n", argv[isc_commandline_index]); na.family = AF_INET; if (inet_pton(AF_INET, argv[isc_commandline_index], (char *)&na.type.in) != 1) { na.family = AF_INET6; if (inet_pton(AF_INET6, argv[isc_commandline_index], (char *)&na.type.in6) != 1) { printf("unknown address format\n"); exit(1); } } result = dns_byaddr_create(mctx, &na, view, options, task, done, NULL, &byaddr); if (result != ISC_R_SUCCESS) { printf("dns_byaddr_create() returned %s\n", isc_result_totext(result)); RUNTIME_CHECK(0); } (void)isc_app_run(); /* * XXXRTH if we get a control-C before we get to isc_app_run(), * we're in trouble (because we might try to destroy things before * they've been created. */ dns_view_detach(&view); isc_task_shutdown(task); isc_task_detach(&task); dns_dispatchmgr_destroy(&dispatchmgr); isc_taskmgr_destroy(&taskmgr); isc_socketmgr_destroy(&socketmgr); isc_timermgr_destroy(&timermgr); if (verbose) isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
/* * Handle lwresd manager objects */ isc_result_t ns_lwdmanager_create(isc_mem_t *mctx, const cfg_obj_t *lwres, ns_lwresd_t **lwresdp) { ns_lwresd_t *lwresd; const char *vname; dns_rdataclass_t vclass; const cfg_obj_t *obj, *viewobj, *searchobj; const cfg_listelt_t *element; isc_result_t result; INSIST(lwresdp != NULL && *lwresdp == NULL); lwresd = isc_mem_get(mctx, sizeof(ns_lwresd_t)); if (lwresd == NULL) return (ISC_R_NOMEMORY); lwresd->mctx = NULL; isc_mem_attach(mctx, &lwresd->mctx); lwresd->view = NULL; lwresd->search = NULL; lwresd->refs = 1; obj = NULL; (void)cfg_map_get(lwres, "ndots", &obj); if (obj != NULL) lwresd->ndots = cfg_obj_asuint32(obj); else lwresd->ndots = 1; RUNTIME_CHECK(isc_mutex_init(&lwresd->lock) == ISC_R_SUCCESS); lwresd->shutting_down = ISC_FALSE; viewobj = NULL; (void)cfg_map_get(lwres, "view", &viewobj); if (viewobj != NULL) { vname = cfg_obj_asstring(cfg_tuple_get(viewobj, "name")); obj = cfg_tuple_get(viewobj, "class"); result = ns_config_getclass(obj, dns_rdataclass_in, &vclass); if (result != ISC_R_SUCCESS) goto fail; } else { vname = "_default"; vclass = dns_rdataclass_in; } result = dns_viewlist_find(&ns_g_server->viewlist, vname, vclass, &lwresd->view); if (result != ISC_R_SUCCESS) { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, ISC_LOG_WARNING, "couldn't find view %s", vname); goto fail; } searchobj = NULL; (void)cfg_map_get(lwres, "search", &searchobj); if (searchobj != NULL) { lwresd->search = NULL; result = ns_lwsearchlist_create(lwresd->mctx, &lwresd->search); if (result != ISC_R_SUCCESS) { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, ISC_LOG_WARNING, "couldn't create searchlist"); goto fail; } for (element = cfg_list_first(searchobj); element != NULL; element = cfg_list_next(element)) { const cfg_obj_t *search; const char *searchstr; isc_buffer_t namebuf; dns_fixedname_t fname; dns_name_t *name; search = cfg_listelt_value(element); searchstr = cfg_obj_asstring(search); dns_fixedname_init(&fname); name = dns_fixedname_name(&fname); isc_buffer_init(&namebuf, searchstr, strlen(searchstr)); isc_buffer_add(&namebuf, strlen(searchstr)); result = dns_name_fromtext(name, &namebuf, dns_rootname, 0, NULL); if (result != ISC_R_SUCCESS) { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, ISC_LOG_WARNING, "invalid name %s in searchlist", searchstr); continue; } result = ns_lwsearchlist_append(lwresd->search, name); if (result != ISC_R_SUCCESS) { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, ISC_LOG_WARNING, "couldn't update searchlist"); goto fail; } } } lwresd->magic = LWRESD_MAGIC; *lwresdp = lwresd; return (ISC_R_SUCCESS); fail: if (lwresd->view != NULL) dns_view_detach(&lwresd->view); if (lwresd->search != NULL) ns_lwsearchlist_detach(&lwresd->search); if (lwresd->mctx != NULL) isc_mem_detach(&lwresd->mctx); isc_mem_put(mctx, lwresd, sizeof(ns_lwresd_t)); return (result); }
int main(int argc, char *argv[]) { isc_boolean_t verbose = ISC_FALSE; unsigned int workers = 2; isc_timermgr_t *timermgr; int ch; isc_socketmgr_t *socketmgr; dns_dispatchmgr_t *dispatchmgr; dns_cache_t *cache; isc_buffer_t b; RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS); dns_result_register(); mctx = NULL; RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE) == ISC_R_SUCCESS); while ((ch = isc_commandline_parse(argc, argv, "d:vw:")) != -1) { switch (ch) { case 'd': level = (unsigned int)atoi(isc_commandline_argument); break; case 'v': verbose = ISC_TRUE; break; case 'w': workers = (unsigned int)atoi(isc_commandline_argument); break; } } log_init(); if (verbose) { printf("%u workers\n", workers); printf("IPv4: %s\n", isc_result_totext(isc_net_probeipv4())); printf("IPv6: %s\n", isc_result_totext(isc_net_probeipv6())); } taskmgr = NULL; RUNTIME_CHECK(isc_taskmgr_create(mctx, workers, 0, &taskmgr) == ISC_R_SUCCESS); task = NULL; RUNTIME_CHECK(isc_task_create(taskmgr, 0, &task) == ISC_R_SUCCESS); isc_task_setname(task, "byname", NULL); dispatchmgr = NULL; RUNTIME_CHECK(dns_dispatchmgr_create(mctx, NULL, &dispatchmgr) == ISC_R_SUCCESS); timermgr = NULL; RUNTIME_CHECK(isc_timermgr_create(mctx, &timermgr) == ISC_R_SUCCESS); socketmgr = NULL; RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS); cache = NULL; RUNTIME_CHECK(dns_cache_create(mctx, taskmgr, timermgr, dns_rdataclass_in, "rbt", 0, NULL, &cache) == ISC_R_SUCCESS); view = NULL; RUNTIME_CHECK(dns_view_create(mctx, dns_rdataclass_in, "default", &view) == ISC_R_SUCCESS); { unsigned int attrs; dns_dispatch_t *disp4 = NULL; dns_dispatch_t *disp6 = NULL; if (isc_net_probeipv4() == ISC_R_SUCCESS) { isc_sockaddr_t any4; isc_sockaddr_any(&any4); attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP; RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &any4, 512, 6, 1024, 17, 19, attrs, attrs, &disp4) == ISC_R_SUCCESS); INSIST(disp4 != NULL); } if (isc_net_probeipv6() == ISC_R_SUCCESS) { isc_sockaddr_t any6; isc_sockaddr_any6(&any6); attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP; RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &any6, 512, 6, 1024, 17, 19, attrs, attrs, &disp6) == ISC_R_SUCCESS); INSIST(disp6 != NULL); } RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10, 1, socketmgr, timermgr, 0, dispatchmgr, disp4, disp6) == ISC_R_SUCCESS); if (disp4 != NULL) dns_dispatch_detach(&disp4); if (disp6 != NULL) dns_dispatch_detach(&disp6); } { struct in_addr ina; isc_sockaddr_t sa; isc_sockaddrlist_t sal; ISC_LIST_INIT(sal); ina.s_addr = inet_addr("127.0.0.1"); isc_sockaddr_fromin(&sa, &ina, 53); ISC_LIST_APPEND(sal, &sa, link); RUNTIME_CHECK(dns_fwdtable_add(view->fwdtable, dns_rootname, &sal, dns_fwdpolicy_only) == ISC_R_SUCCESS); } dns_view_setcache(view, cache); dns_view_freeze(view); dns_cache_detach(&cache); printf("name = %s\n", argv[isc_commandline_index]); isc_buffer_init(&b, argv[isc_commandline_index], strlen(argv[isc_commandline_index])); isc_buffer_add(&b, strlen(argv[isc_commandline_index])); dns_fixedname_init(&fixed); dns_fixedname_init(&target); RUNTIME_CHECK(dns_name_fromtext(dns_fixedname_name(&fixed), &b, dns_rootname, 0, NULL) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_app_onrun(mctx, task, run, NULL) == ISC_R_SUCCESS); (void)isc_app_run(); dns_view_detach(&view); isc_task_shutdown(task); isc_task_detach(&task); dns_dispatchmgr_destroy(&dispatchmgr); isc_taskmgr_destroy(&taskmgr); isc_socketmgr_destroy(&socketmgr); isc_timermgr_destroy(&timermgr); isc_log_destroy(&lctx); isc_hash_destroy(); isc_entropy_detach(&ectx); if (verbose) isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
int main(int argc, char *argv[]) { char *ourkeyname; isc_taskmgr_t *taskmgr; isc_timermgr_t *timermgr; isc_socketmgr_t *socketmgr; isc_socket_t *sock; unsigned int attrs, attrmask; isc_sockaddr_t bind_any; dns_dispatchmgr_t *dispatchmgr; dns_dispatch_t *dispatchv4; dns_view_t *view; isc_entropy_t *ectx; dns_tkeyctx_t *tctx; isc_log_t *log; isc_logconfig_t *logconfig; isc_task_t *task; isc_result_t result; int type; RUNCHECK(isc_app_start()); if (argc < 2) { fprintf(stderr, "I:no DH key provided\n"); exit(-1); } ourkeyname = argv[1]; if (argc >= 3) ownername_str = argv[2]; dns_result_register(); mctx = NULL; RUNCHECK(isc_mem_create(0, 0, &mctx)); ectx = NULL; RUNCHECK(isc_entropy_create(mctx, &ectx)); RUNCHECK(isc_entropy_createfilesource(ectx, "random.data")); RUNCHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)); log = NULL; logconfig = NULL; RUNCHECK(isc_log_create(mctx, &log, &logconfig)); RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY)); taskmgr = NULL; RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr)); task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); timermgr = NULL; RUNCHECK(isc_timermgr_create(mctx, &timermgr)); socketmgr = NULL; RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, NULL, &dispatchmgr)); isc_sockaddr_any(&bind_any); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | DNS_DISPATCHATTR_IPV4; attrmask = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP | DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6; dispatchv4 = NULL; RUNCHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &bind_any, 4096, 4, 2, 3, 5, attrs, attrmask, &dispatchv4)); requestmgr = NULL; RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr, dispatchmgr, dispatchv4, NULL, &requestmgr)); ring = NULL; RUNCHECK(dns_tsigkeyring_create(mctx, &ring)); tctx = NULL; RUNCHECK(dns_tkeyctx_create(mctx, ectx, &tctx)); view = NULL; RUNCHECK(dns_view_create(mctx, 0, "_test", &view)); dns_view_setkeyring(view, ring); dns_tsigkeyring_detach(&ring); sock = NULL; RUNCHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp, &sock)); RUNCHECK(isc_app_onrun(mctx, task, sendquery, NULL)); ourkey = NULL; type = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_KEY; result = dst_key_fromnamedfile(ourkeyname, NULL, type, mctx, &ourkey); CHECK("dst_key_fromnamedfile", result); isc_buffer_init(&nonce, noncedata, sizeof(noncedata)); result = isc_entropy_getdata(ectx, noncedata, sizeof(noncedata), NULL, ISC_ENTROPY_BLOCKING); CHECK("isc_entropy_getdata", result); isc_buffer_add(&nonce, sizeof(noncedata)); (void)isc_app_run(); dns_requestmgr_shutdown(requestmgr); dns_requestmgr_detach(&requestmgr); dns_dispatch_detach(&dispatchv4); dns_dispatchmgr_destroy(&dispatchmgr); isc_task_shutdown(task); isc_task_detach(&task); isc_taskmgr_destroy(&taskmgr); isc_socket_detach(&sock); isc_socketmgr_destroy(&socketmgr); isc_timermgr_destroy(&timermgr); dst_key_free(&ourkey); dns_tsigkey_detach(&initialkey); dns_tsigkey_detach(&tsigkey); dns_tkeyctx_destroy(&tctx); dns_view_detach(&view); isc_log_destroy(&log); dst_lib_destroy(); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
int main(int argc, char *argv[]) { isc_taskmgr_t *taskmgr; isc_timermgr_t *timermgr; isc_socketmgr_t *socketmgr; isc_socket_t *sock; unsigned int attrs, attrmask; isc_sockaddr_t bind_any; dns_dispatchmgr_t *dispatchmgr; dns_dispatch_t *dispatchv4; dns_view_t *view; isc_entropy_t *ectx; isc_task_t *task; isc_log_t *lctx = NULL; isc_logconfig_t *lcfg = NULL; isc_logdestination_t destination; UNUSED(argv); UNUSED(argc); RUNCHECK(isc_app_start()); dns_result_register(); mctx = NULL; RUNCHECK(isc_mem_create(0, 0, &mctx)); RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); 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; RUNCHECK(isc_log_createchannel(lcfg, "_default", ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME)); RUNCHECK(isc_log_usechannel(lcfg, "_default", NULL, NULL)); isc_log_setdebuglevel(lctx, 9); ectx = NULL; RUNCHECK(isc_entropy_create(mctx, &ectx)); RUNCHECK(isc_entropy_createfilesource(ectx, "/dev/urandom")); RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY)); taskmgr = NULL; RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr)); task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); timermgr = NULL; RUNCHECK(isc_timermgr_create(mctx, &timermgr)); socketmgr = NULL; RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, ectx, &dispatchmgr)); isc_sockaddr_any(&bind_any); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | DNS_DISPATCHATTR_IPV4; attrmask = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP | DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6; dispatchv4 = NULL; RUNCHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &bind_any, 4096, 4, 2, 3, 5, attrs, attrmask, &dispatchv4)); requestmgr = NULL; RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr, dispatchmgr, dispatchv4, NULL, &requestmgr)); ring = NULL; RUNCHECK(dns_tsigkeyring_create(mctx, &ring)); view = NULL; RUNCHECK(dns_view_create(mctx, 0, "_test", &view)); dns_view_setkeyring(view, ring); sock = NULL; RUNCHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp, &sock)); setup(); RUNCHECK(isc_app_onrun(mctx, task, console, NULL)); (void)isc_app_run(); if (tsigkey) dns_tsigkey_detach(&tsigkey); dns_requestmgr_shutdown(requestmgr); dns_requestmgr_detach(&requestmgr); dns_dispatch_detach(&dispatchv4); dns_dispatchmgr_destroy(&dispatchmgr); isc_timermgr_destroy(&timermgr); isc_task_detach(&task); isc_taskmgr_destroy(&taskmgr); isc_socket_detach(&sock); isc_socketmgr_destroy(&socketmgr); isc_mem_stats(mctx, stdout); dns_view_detach(&view); dst_lib_destroy(); isc_entropy_detach(&ectx); isc_mem_stats(mctx, stdout); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }
ATF_TC_BODY(send, tc) { isc_result_t result; dns_dtenv_t *dtenv = NULL; dns_dthandle_t handle; isc_uint8_t *data; size_t dsize; unsigned char zone[DNS_NAME_MAXWIRE]; unsigned char qambuffer[4096], rambuffer[4096]; unsigned char qrmbuffer[4096], rrmbuffer[4096]; isc_buffer_t zb, qamsg, ramsg, qrmsg, rrmsg; size_t qasize, qrsize, rasize, rrsize; dns_fixedname_t zfname; dns_name_t *zname; dns_dtmsgtype_t dt; dns_view_t *view = NULL; dns_compress_t cctx; isc_region_t zr; isc_sockaddr_t addr; struct in_addr in; isc_stdtime_t now; isc_time_t p, f; UNUSED(tc); cleanup(); result = dns_test_begin(NULL, ISC_TRUE); ATF_REQUIRE(result == ISC_R_SUCCESS); result = dns_test_makeview("test", &view); result = dns_dt_create(mctx, dns_dtmode_file, TAPFILE, 1, &dtenv); ATF_REQUIRE(result == ISC_R_SUCCESS); dns_dt_attach(dtenv, &view->dtenv); view->dttypes = DNS_DTTYPE_ALL; /* * Set up some test data */ dns_fixedname_init(&zfname); zname = dns_fixedname_name(&zfname); isc_buffer_constinit(&zb, "example.com.", 12); isc_buffer_add(&zb, 12); result = dns_name_fromtext(zname, &zb, NULL, 0, NULL); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); memset(&zr, 0, sizeof(zr)); isc_buffer_init(&zb, zone, sizeof(zone)); result = dns_compress_init(&cctx, -1, mctx); dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); result = dns_name_towire(zname, &cctx, &zb); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); dns_compress_invalidate(&cctx); isc_buffer_usedregion(&zb, &zr); in.s_addr = inet_addr("10.53.0.1"); isc_sockaddr_fromin(&addr, &in, 2112); isc_stdtime_get(&now); isc_time_set(&p, now - 3600, 0); /* past */ isc_time_set(&f, now + 3600, 0); /* future */ result = dns_test_getdata("testdata/dnstap/query.auth", qambuffer, sizeof(qambuffer), &qasize); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); isc_buffer_init(&qamsg, qambuffer, qasize); isc_buffer_add(&qamsg, qasize); result = dns_test_getdata("testdata/dnstap/response.auth", rambuffer, sizeof(rambuffer), &rasize); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); isc_buffer_init(&ramsg, rambuffer, rasize); isc_buffer_add(&ramsg, rasize); result = dns_test_getdata("testdata/dnstap/query.recursive", qrmbuffer, sizeof(qrmbuffer), &qrsize); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); isc_buffer_init(&qrmsg, qrmbuffer, qrsize); isc_buffer_add(&qrmsg, qrsize); result = dns_test_getdata("testdata/dnstap/response.recursive", rrmbuffer, sizeof(rrmbuffer), &rrsize); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); isc_buffer_init(&rrmsg, rrmbuffer, rrsize); isc_buffer_add(&rrmsg, rrsize); for (dt = DNS_DTTYPE_SQ; dt <= DNS_DTTYPE_TR; dt <<= 1) { isc_buffer_t *m; switch (dt) { case DNS_DTTYPE_AQ: m = &qamsg; break; case DNS_DTTYPE_AR: m = &ramsg; break; default: m = &qrmsg; if ((dt & DNS_DTTYPE_RESPONSE) != 0) m = &ramsg; break; } dns_dt_send(view, dt, &addr, ISC_FALSE, &zr, &p, &f, m); dns_dt_send(view, dt, &addr, ISC_FALSE, &zr, NULL, &f, m); dns_dt_send(view, dt, &addr, ISC_FALSE, &zr, &p, NULL, m); dns_dt_send(view, dt, &addr, ISC_FALSE, &zr, NULL, NULL, m); dns_dt_send(view, dt, &addr, ISC_TRUE, &zr, &p, &f, m); dns_dt_send(view, dt, &addr, ISC_TRUE, &zr, NULL, &f, m); dns_dt_send(view, dt, &addr, ISC_TRUE, &zr, &p, NULL, m); dns_dt_send(view, dt, &addr, ISC_TRUE, &zr, NULL, NULL, m); } dns_dt_detach(&view->dtenv); dns_dt_detach(&dtenv); dns_dt_shutdown(); dns_view_detach(&view); /* * XXX now read back and check content. */ result = dns_dt_open(TAPFILE, dns_dtmode_file, &handle); ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); while (dns_dt_getframe(&handle, &data, &dsize) == ISC_R_SUCCESS) { dns_dtdata_t *dtdata = NULL; isc_region_t r; static dns_dtmsgtype_t expected = DNS_DTTYPE_SQ; static int n = 0; r.base = data; r.length = dsize; result = dns_dt_parse(mctx, &r, &dtdata); ATF_CHECK_EQ(result, ISC_R_SUCCESS); if (result != ISC_R_SUCCESS) { n++; continue; } ATF_CHECK_EQ(dtdata->type, expected); if (++n % 8 == 0) expected <<= 1; dns_dtdata_free(&dtdata); } dns_dt_close(&handle); cleanup(); dns_test_end(); }
static void lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) { isc_result_t result; isc_boolean_t want_restart; isc_boolean_t send_event; dns_name_t *name, *fname, *prefix; dns_fixedname_t foundname, fixed; dns_rdata_t rdata = DNS_RDATA_INIT; unsigned int nlabels; int order; dns_namereln_t namereln; dns_rdata_cname_t cname; dns_rdata_dname_t dname; REQUIRE(VALID_LOOKUP(lookup)); LOCK(&lookup->lock); result = ISC_R_SUCCESS; name = dns_fixedname_name(&lookup->name); do { lookup->restarts++; want_restart = ISC_FALSE; send_event = ISC_TRUE; if (event == NULL && !lookup->canceled) { dns_fixedname_init(&foundname); fname = dns_fixedname_name(&foundname); INSIST(!dns_rdataset_isassociated(&lookup->rdataset)); INSIST(!dns_rdataset_isassociated (&lookup->sigrdataset)); /* * If we have restarted then clear the old node. */ if (lookup->event->node != NULL) { INSIST(lookup->event->db != NULL); dns_db_detachnode(lookup->event->db, &lookup->event->node); } if (lookup->event->db != NULL) dns_db_detach(&lookup->event->db); result = view_find(lookup, fname); if (result == ISC_R_NOTFOUND) { /* * We don't know anything about the name. * Launch a fetch. */ if (lookup->event->node != NULL) { INSIST(lookup->event->db != NULL); dns_db_detachnode(lookup->event->db, &lookup->event->node); } if (lookup->event->db != NULL) dns_db_detach(&lookup->event->db); result = start_fetch(lookup); if (result == ISC_R_SUCCESS) send_event = ISC_FALSE; goto done; } } else if (event != NULL) { result = event->result; fname = dns_fixedname_name(&event->foundname); dns_resolver_destroyfetch(&lookup->fetch); INSIST(event->rdataset == &lookup->rdataset); INSIST(event->sigrdataset == &lookup->sigrdataset); } else fname = NULL; /* Silence compiler warning. */ /* * If we've been canceled, forget about the result. */ if (lookup->canceled) result = ISC_R_CANCELED; switch (result) { case ISC_R_SUCCESS: result = build_event(lookup); if (event == NULL) break; if (event->db != NULL) dns_db_attach(event->db, &lookup->event->db); if (event->node != NULL) dns_db_attachnode(lookup->event->db, event->node, &lookup->event->node); break; case DNS_R_CNAME: /* * Copy the CNAME's target into the lookup's * query name and start over. */ result = dns_rdataset_first(&lookup->rdataset); if (result != ISC_R_SUCCESS) break; dns_rdataset_current(&lookup->rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &cname, NULL); dns_rdata_reset(&rdata); if (result != ISC_R_SUCCESS) break; result = dns_name_copy(&cname.cname, name, NULL); dns_rdata_freestruct(&cname); if (result == ISC_R_SUCCESS) { want_restart = ISC_TRUE; send_event = ISC_FALSE; } break; case DNS_R_DNAME: namereln = dns_name_fullcompare(name, fname, &order, &nlabels); INSIST(namereln == dns_namereln_subdomain); /* * Get the target name of the DNAME. */ result = dns_rdataset_first(&lookup->rdataset); if (result != ISC_R_SUCCESS) break; dns_rdataset_current(&lookup->rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &dname, NULL); dns_rdata_reset(&rdata); if (result != ISC_R_SUCCESS) break; /* * Construct the new query name and start over. */ dns_fixedname_init(&fixed); prefix = dns_fixedname_name(&fixed); dns_name_split(name, nlabels, prefix, NULL); result = dns_name_concatenate(prefix, &dname.dname, name, NULL); dns_rdata_freestruct(&dname); if (result == ISC_R_SUCCESS) { want_restart = ISC_TRUE; send_event = ISC_FALSE; } break; default: send_event = ISC_TRUE; } if (dns_rdataset_isassociated(&lookup->rdataset)) dns_rdataset_disassociate(&lookup->rdataset); if (dns_rdataset_isassociated(&lookup->sigrdataset)) dns_rdataset_disassociate(&lookup->sigrdataset); done: if (event != NULL) { if (event->node != NULL) dns_db_detachnode(event->db, &event->node); if (event->db != NULL) dns_db_detach(&event->db); isc_event_free(ISC_EVENT_PTR(&event)); } /* * Limit the number of restarts. */ if (want_restart && lookup->restarts == MAX_RESTARTS) { want_restart = ISC_FALSE; result = ISC_R_QUOTA; send_event = ISC_TRUE; } } while (want_restart); if (send_event) { lookup->event->result = result; lookup->event->ev_sender = lookup; isc_task_sendanddetach(&lookup->task, (isc_event_t **)(void *)&lookup->event); dns_view_detach(&lookup->view); } UNLOCK(&lookup->lock); }
int main(int argc, char *argv[]) { isc_sockaddr_t bind_any; struct in_addr inaddr; isc_result_t result; isc_log_t *lctx; isc_logconfig_t *lcfg; isc_entropy_t *ectx; isc_taskmgr_t *taskmgr; isc_task_t *task; isc_timermgr_t *timermgr; isc_socketmgr_t *socketmgr; dns_dispatchmgr_t *dispatchmgr; unsigned int attrs, attrmask; dns_dispatch_t *dispatchv4; dns_view_t *view; UNUSED(argv); if (argc > 1) have_src = ISC_TRUE; RUNCHECK(isc_app_start()); dns_result_register(); isc_sockaddr_any(&bind_any); result = ISC_R_FAILURE; if (inet_pton(AF_INET, "10.53.0.7", &inaddr) != 1) CHECK("inet_pton", result); isc_sockaddr_fromin(&srcaddr, &inaddr, 0); result = ISC_R_FAILURE; if (inet_pton(AF_INET, "10.53.0.4", &inaddr) != 1) CHECK("inet_pton", result); isc_sockaddr_fromin(&dstaddr, &inaddr, PORT); mctx = NULL; RUNCHECK(isc_mem_create(0, 0, &mctx)); lctx = NULL; lcfg = NULL; RUNCHECK(isc_log_create(mctx, &lctx, &lcfg)); ectx = NULL; RUNCHECK(isc_entropy_create(mctx, &ectx)); RUNCHECK(isc_entropy_createfilesource(ectx, "../random.data")); RUNCHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE)); RUNCHECK(dst_lib_init(mctx, ectx, ISC_ENTROPY_GOODONLY)); taskmgr = NULL; RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr)); task = NULL; RUNCHECK(isc_task_create(taskmgr, 0, &task)); timermgr = NULL; RUNCHECK(isc_timermgr_create(mctx, &timermgr)); socketmgr = NULL; RUNCHECK(isc_socketmgr_create(mctx, &socketmgr)); dispatchmgr = NULL; RUNCHECK(dns_dispatchmgr_create(mctx, ectx, &dispatchmgr)); attrs = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_MAKEQUERY | DNS_DISPATCHATTR_IPV4; attrmask = DNS_DISPATCHATTR_UDP | DNS_DISPATCHATTR_TCP | DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_IPV6; dispatchv4 = NULL; RUNCHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, have_src ? &srcaddr : &bind_any, 4096, 4, 2, 3, 5, attrs, attrmask, &dispatchv4)); requestmgr = NULL; RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr, dispatchmgr, dispatchv4, NULL, &requestmgr)); view = NULL; RUNCHECK(dns_view_create(mctx, 0, "_test", &view)); RUNCHECK(isc_app_onrun(mctx, task, sendqueries, NULL)); (void)isc_app_run(); dns_view_detach(&view); dns_requestmgr_shutdown(requestmgr); dns_requestmgr_detach(&requestmgr); dns_dispatch_detach(&dispatchv4); dns_dispatchmgr_destroy(&dispatchmgr); isc_socketmgr_destroy(&socketmgr); isc_timermgr_destroy(&timermgr); isc_task_shutdown(task); isc_task_detach(&task); isc_taskmgr_destroy(&taskmgr); dst_lib_destroy(); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_log_destroy(&lctx); isc_mem_destroy(&mctx); isc_app_finish(); return (0); }