mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
Convert dispatch to netmgr
The flow of operations in dispatch is changing and will now be similar for both UDP and TCP queries: 1) Call dns_dispatch_addresponse() to assign a query ID and register that we'll be listening for a response with that ID soon. the parameters for this function include callback functions to inform the caller when the socket is connected and when the message has been sent, as well as a task action that will be sent when the response arrives. (later this could become a netmgr callback, but at this stage to minimize disruption to the calling code, we continue to use isc_task for the response event.) on successful completion of this function, a dispatch entry object will be instantiated. 2) Call dns_dispatch_connect() on the dispatch entry. this runs isc_nm_udpconnect() or isc_nm_tcpdnsconnect(), as needed, and begins listening for responses. the caller is informed via a callback function when the connection is established. 3) Call dns_dispatch_send() on the dispatch entry. this runs isc_nm_send() to send a request. 4) Call dns_dispatch_removeresponse() to terminate listening and close the connection. Implementation comments below: - As we will be using netmgr buffers now. code to send the length in TCP queries has also been removed as that is handled by the netmgr. - TCP dispatches can be used by multiple simultaneous queries, so dns_dispatch_connect() now checks whether the dispatch is already connected before calling isc_nm_tcpdnsconnect() again. - Running dns_dispatch_getnext() from a non-network thread caused a crash due to assertions in the netmgr read functions that appear to be unnecessary now. the assertions have been removed. - fctx->nqueries was formerly incremented when the connection was successful, but is now incremented when the query is started and decremented if the connection fails. - It's no longer necessary for each dispatch to have a pool of tasks, so there's now a single task per dispatch. - Dispatch code to avoid UDP ports already in use has been removed. - dns_resolver and dns_request have been modified to use netmgr callback functions instead of task events. some additional changes were needed to handle shutdown processing correctly. - Timeout processing is not yet fully converted to use netmgr timeouts. - Fixed a lock order cycle reported by TSAN (view -> zone-> adb -> view) by by calling dns_zt functions without holding the view lock.
This commit is contained in:
parent
9ee60e7a17
commit
308bc46a59
@ -1725,7 +1725,6 @@ main(int argc, char *argv[]) {
|
|||||||
isc_appctx_t *actx = NULL;
|
isc_appctx_t *actx = NULL;
|
||||||
isc_nm_t *netmgr = NULL;
|
isc_nm_t *netmgr = NULL;
|
||||||
isc_taskmgr_t *taskmgr = NULL;
|
isc_taskmgr_t *taskmgr = NULL;
|
||||||
isc_socketmgr_t *socketmgr = NULL;
|
|
||||||
isc_timermgr_t *timermgr = NULL;
|
isc_timermgr_t *timermgr = NULL;
|
||||||
dns_master_style_t *style = NULL;
|
dns_master_style_t *style = NULL;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
@ -1744,8 +1743,8 @@ main(int argc, char *argv[]) {
|
|||||||
isc_mem_create(&mctx);
|
isc_mem_create(&mctx);
|
||||||
|
|
||||||
CHECK(isc_appctx_create(mctx, &actx));
|
CHECK(isc_appctx_create(mctx, &actx));
|
||||||
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr,
|
|
||||||
&socketmgr);
|
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr, NULL);
|
||||||
|
|
||||||
parse_args(argc, argv);
|
parse_args(argc, argv);
|
||||||
|
|
||||||
@ -1763,7 +1762,7 @@ main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create client */
|
/* Create client */
|
||||||
result = dns_client_create(mctx, actx, taskmgr, socketmgr, timermgr, 0,
|
result = dns_client_create(mctx, actx, taskmgr, netmgr, timermgr, 0,
|
||||||
&client, srcaddr4, srcaddr6);
|
&client, srcaddr4, srcaddr6);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
delv_log(ISC_LOG_ERROR, "dns_client_create: %s",
|
delv_log(ISC_LOG_ERROR, "dns_client_create: %s",
|
||||||
@ -1846,7 +1845,9 @@ cleanup:
|
|||||||
if (client != NULL) {
|
if (client != NULL) {
|
||||||
dns_client_detach(&client);
|
dns_client_detach(&client);
|
||||||
}
|
}
|
||||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
|
||||||
|
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, NULL);
|
||||||
|
|
||||||
if (actx != NULL) {
|
if (actx != NULL) {
|
||||||
isc_appctx_destroy(&actx);
|
isc_appctx_destroy(&actx);
|
||||||
}
|
}
|
||||||
|
@ -1315,8 +1315,8 @@ get_view_querysource_dispatch(const cfg_obj_t **maps, int af,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatch_createudp(named_g_dispatchmgr, named_g_socketmgr,
|
result = dns_dispatch_createudp(named_g_dispatchmgr, named_g_taskmgr,
|
||||||
named_g_taskmgr, &sa, attrs, &disp);
|
&sa, attrs, &disp);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
isc_sockaddr_t any;
|
isc_sockaddr_t any;
|
||||||
char buf[ISC_SOCKADDR_FORMATSIZE];
|
char buf[ISC_SOCKADDR_FORMATSIZE];
|
||||||
@ -4716,7 +4716,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
|
|||||||
ndisp = 4 * ISC_MIN(named_g_udpdisp, MAX_UDP_DISPATCH);
|
ndisp = 4 * ISC_MIN(named_g_udpdisp, MAX_UDP_DISPATCH);
|
||||||
CHECK(dns_view_createresolver(
|
CHECK(dns_view_createresolver(
|
||||||
view, named_g_taskmgr, RESOLVER_NTASKS_PERCPU * named_g_cpus,
|
view, named_g_taskmgr, RESOLVER_NTASKS_PERCPU * named_g_cpus,
|
||||||
ndisp, named_g_socketmgr, named_g_timermgr, resopts,
|
ndisp, named_g_netmgr, named_g_timermgr, resopts,
|
||||||
named_g_dispatchmgr, dispatch4, dispatch6));
|
named_g_dispatchmgr, dispatch4, dispatch6));
|
||||||
|
|
||||||
if (dscp4 == -1) {
|
if (dscp4 == -1) {
|
||||||
@ -9862,7 +9862,8 @@ run_server(isc_task_t *task, isc_event_t *event) {
|
|||||||
|
|
||||||
isc_event_free(&event);
|
isc_event_free(&event);
|
||||||
|
|
||||||
CHECKFATAL(dns_dispatchmgr_create(named_g_mctx, &named_g_dispatchmgr),
|
CHECKFATAL(dns_dispatchmgr_create(named_g_mctx, named_g_netmgr,
|
||||||
|
&named_g_dispatchmgr),
|
||||||
"creating dispatch manager");
|
"creating dispatch manager");
|
||||||
|
|
||||||
dns_dispatchmgr_setstats(named_g_dispatchmgr, server->resolverstats);
|
dns_dispatchmgr_setstats(named_g_dispatchmgr, server->resolverstats);
|
||||||
@ -10357,8 +10358,8 @@ named_add_reserved_dispatch(named_server_t *server,
|
|||||||
dispatch->dispatchgen = server->dispatchgen;
|
dispatch->dispatchgen = server->dispatchgen;
|
||||||
dispatch->dispatch = NULL;
|
dispatch->dispatch = NULL;
|
||||||
|
|
||||||
result = dns_dispatch_createudp(named_g_dispatchmgr, named_g_socketmgr,
|
result = dns_dispatch_createudp(named_g_dispatchmgr, named_g_taskmgr,
|
||||||
named_g_taskmgr, &dispatch->addr, attrs,
|
&dispatch->addr, attrs,
|
||||||
&dispatch->dispatch);
|
&dispatch->dispatch);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <isc/log.h>
|
#include <isc/log.h>
|
||||||
#include <isc/managers.h>
|
#include <isc/managers.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
|
#include <isc/netmgr.h>
|
||||||
#include <isc/nonce.h>
|
#include <isc/nonce.h>
|
||||||
#include <isc/parseint.h>
|
#include <isc/parseint.h>
|
||||||
#include <isc/portset.h>
|
#include <isc/portset.h>
|
||||||
@ -38,11 +39,9 @@
|
|||||||
#include <isc/random.h>
|
#include <isc/random.h>
|
||||||
#include <isc/region.h>
|
#include <isc/region.h>
|
||||||
#include <isc/sockaddr.h>
|
#include <isc/sockaddr.h>
|
||||||
#include <isc/socket.h>
|
|
||||||
#include <isc/stdio.h>
|
#include <isc/stdio.h>
|
||||||
#include <isc/string.h>
|
#include <isc/string.h>
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
|
||||||
#include <isc/types.h>
|
#include <isc/types.h>
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
@ -131,8 +130,6 @@ static isc_log_t *glctx = NULL;
|
|||||||
static isc_mem_t *gmctx = NULL;
|
static isc_mem_t *gmctx = NULL;
|
||||||
static dns_dispatchmgr_t *dispatchmgr = NULL;
|
static dns_dispatchmgr_t *dispatchmgr = NULL;
|
||||||
static dns_requestmgr_t *requestmgr = NULL;
|
static dns_requestmgr_t *requestmgr = NULL;
|
||||||
static isc_socketmgr_t *socketmgr = NULL;
|
|
||||||
static isc_timermgr_t *timermgr = NULL;
|
|
||||||
static dns_dispatch_t *dispatchv4 = NULL;
|
static dns_dispatch_t *dispatchv4 = NULL;
|
||||||
static dns_dispatch_t *dispatchv6 = NULL;
|
static dns_dispatch_t *dispatchv6 = NULL;
|
||||||
static dns_message_t *updatemsg = NULL;
|
static dns_message_t *updatemsg = NULL;
|
||||||
@ -917,11 +914,12 @@ setup_system(void) {
|
|||||||
|
|
||||||
irs_resconf_destroy(&resconf);
|
irs_resconf_destroy(&resconf);
|
||||||
|
|
||||||
result = dns_dispatchmgr_create(gmctx, &dispatchmgr);
|
result = isc_managers_create(gmctx, 1, 0, 0, &netmgr, &taskmgr, NULL,
|
||||||
check_result(result, "dns_dispatchmgr_create");
|
NULL);
|
||||||
|
check_result(result, "isc_managers_create");
|
||||||
|
|
||||||
isc_managers_create(gmctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr,
|
result = dns_dispatchmgr_create(gmctx, netmgr, &dispatchmgr);
|
||||||
&socketmgr);
|
check_result(result, "dns_dispatchmgr_create");
|
||||||
|
|
||||||
result = isc_task_create(taskmgr, 0, &global_task);
|
result = isc_task_create(taskmgr, 0, &global_task);
|
||||||
check_result(result, "isc_task_create");
|
check_result(result, "isc_task_create");
|
||||||
@ -937,21 +935,20 @@ setup_system(void) {
|
|||||||
|
|
||||||
if (have_ipv6) {
|
if (have_ipv6) {
|
||||||
isc_sockaddr_any6(&bind_any6);
|
isc_sockaddr_any6(&bind_any6);
|
||||||
result = dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr,
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr,
|
||||||
&bind_any6, 0, &dispatchv6);
|
&bind_any6, 0, &dispatchv6);
|
||||||
check_result(result, "dns_dispatch_createudp (v6)");
|
check_result(result, "dns_dispatch_createudp (v6)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (have_ipv4) {
|
if (have_ipv4) {
|
||||||
isc_sockaddr_any(&bind_any);
|
isc_sockaddr_any(&bind_any);
|
||||||
result = dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr,
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr, &bind_any,
|
||||||
&bind_any, 0, &dispatchv4);
|
0, &dispatchv4);
|
||||||
check_result(result, "dns_dispatch_createudp (v4)");
|
check_result(result, "dns_dispatch_createudp (v4)");
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_requestmgr_create(gmctx, timermgr, socketmgr, taskmgr,
|
result = dns_requestmgr_create(gmctx, taskmgr, dispatchmgr, dispatchv4,
|
||||||
dispatchmgr, dispatchv4, dispatchv6,
|
dispatchv6, &requestmgr);
|
||||||
&requestmgr);
|
|
||||||
check_result(result, "dns_requestmgr_create");
|
check_result(result, "dns_requestmgr_create");
|
||||||
|
|
||||||
if (keystr != NULL) {
|
if (keystr != NULL) {
|
||||||
@ -3322,7 +3319,7 @@ cleanup(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ddebug("Shutting down managers");
|
ddebug("Shutting down managers");
|
||||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL);
|
||||||
|
|
||||||
ddebug("Destroying event");
|
ddebug("Destroying event");
|
||||||
isc_event_free(&global_event);
|
isc_event_free(&global_event);
|
||||||
|
@ -23,12 +23,11 @@
|
|||||||
#include <isc/managers.h>
|
#include <isc/managers.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
#include <isc/net.h>
|
#include <isc/net.h>
|
||||||
|
#include <isc/netmgr.h>
|
||||||
#include <isc/parseint.h>
|
#include <isc/parseint.h>
|
||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
#include <isc/sockaddr.h>
|
#include <isc/sockaddr.h>
|
||||||
#include <isc/socket.h>
|
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/dispatch.h>
|
#include <dns/dispatch.h>
|
||||||
@ -70,7 +69,8 @@ static void
|
|||||||
recvresponse(isc_task_t *task, isc_event_t *event) {
|
recvresponse(isc_task_t *task, isc_event_t *event) {
|
||||||
dns_requestevent_t *reqev = (dns_requestevent_t *)event;
|
dns_requestevent_t *reqev = (dns_requestevent_t *)event;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
dns_message_t *query = NULL, *response = NULL;
|
dns_message_t *query = NULL;
|
||||||
|
dns_message_t *response = NULL;
|
||||||
isc_buffer_t outbuf;
|
isc_buffer_t outbuf;
|
||||||
char output[1024];
|
char output[1024];
|
||||||
|
|
||||||
@ -203,8 +203,6 @@ main(int argc, char *argv[]) {
|
|||||||
isc_nm_t *netmgr = NULL;
|
isc_nm_t *netmgr = NULL;
|
||||||
isc_taskmgr_t *taskmgr = NULL;
|
isc_taskmgr_t *taskmgr = NULL;
|
||||||
isc_task_t *task = NULL;
|
isc_task_t *task = NULL;
|
||||||
isc_timermgr_t *timermgr = NULL;
|
|
||||||
isc_socketmgr_t *socketmgr = NULL;
|
|
||||||
dns_dispatchmgr_t *dispatchmgr = NULL;
|
dns_dispatchmgr_t *dispatchmgr = NULL;
|
||||||
dns_dispatch_t *dispatchv4 = NULL;
|
dns_dispatch_t *dispatchv4 = NULL;
|
||||||
dns_view_t *view = NULL;
|
dns_view_t *view = NULL;
|
||||||
@ -267,18 +265,15 @@ main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||||
|
|
||||||
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr,
|
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, NULL, NULL);
|
||||||
&socketmgr);
|
|
||||||
|
|
||||||
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
||||||
RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr));
|
RUNCHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr));
|
||||||
|
|
||||||
RUNCHECK(dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr,
|
RUNCHECK(dns_dispatch_createudp(dispatchmgr, taskmgr,
|
||||||
have_src ? &srcaddr : &bind_any, 0,
|
have_src ? &srcaddr : &bind_any, 0,
|
||||||
&dispatchv4));
|
&dispatchv4));
|
||||||
RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr,
|
RUNCHECK(dns_requestmgr_create(mctx, taskmgr, dispatchmgr, dispatchv4,
|
||||||
dispatchmgr, dispatchv4, NULL,
|
NULL, &requestmgr));
|
||||||
&requestmgr));
|
|
||||||
|
|
||||||
RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
|
RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
|
||||||
RUNCHECK(isc_app_onrun(mctx, task, sendqueries, NULL));
|
RUNCHECK(isc_app_onrun(mctx, task, sendqueries, NULL));
|
||||||
@ -296,7 +291,7 @@ main(int argc, char *argv[]) {
|
|||||||
isc_task_shutdown(task);
|
isc_task_shutdown(task);
|
||||||
isc_task_detach(&task);
|
isc_task_detach(&task);
|
||||||
|
|
||||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL);
|
||||||
|
|
||||||
dst_lib_destroy();
|
dst_lib_destroy();
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@
|
|||||||
#include <isc/commandline.h>
|
#include <isc/commandline.h>
|
||||||
#include <isc/managers.h>
|
#include <isc/managers.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
|
#include <isc/netmgr.h>
|
||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
#include <isc/sockaddr.h>
|
#include <isc/sockaddr.h>
|
||||||
#include <isc/socket.h>
|
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
#include <isc/timer.h>
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
@ -58,13 +58,11 @@ isc_mem_t *ctxs_mctx = NULL;
|
|||||||
isc_appctx_t *ctxs_actx = NULL;
|
isc_appctx_t *ctxs_actx = NULL;
|
||||||
isc_nm_t *ctxs_netmgr = NULL;
|
isc_nm_t *ctxs_netmgr = NULL;
|
||||||
isc_taskmgr_t *ctxs_taskmgr = NULL;
|
isc_taskmgr_t *ctxs_taskmgr = NULL;
|
||||||
isc_socketmgr_t *ctxs_socketmgr = NULL;
|
|
||||||
isc_timermgr_t *ctxs_timermgr = NULL;
|
isc_timermgr_t *ctxs_timermgr = NULL;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ctxs_destroy(void) {
|
ctxs_destroy(void) {
|
||||||
isc_managers_destroy(&ctxs_netmgr, &ctxs_taskmgr, &ctxs_timermgr,
|
isc_managers_destroy(&ctxs_netmgr, &ctxs_taskmgr, &ctxs_timermgr, NULL);
|
||||||
&ctxs_socketmgr);
|
|
||||||
|
|
||||||
if (ctxs_actx != NULL) {
|
if (ctxs_actx != NULL) {
|
||||||
isc_appctx_destroy(&ctxs_actx);
|
isc_appctx_destroy(&ctxs_actx);
|
||||||
@ -87,7 +85,7 @@ ctxs_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isc_managers_create(ctxs_mctx, 1, 0, 0, &ctxs_netmgr, &ctxs_taskmgr,
|
isc_managers_create(ctxs_mctx, 1, 0, 0, &ctxs_netmgr, &ctxs_taskmgr,
|
||||||
&ctxs_timermgr, &ctxs_socketmgr);
|
&ctxs_timermgr, NULL);
|
||||||
|
|
||||||
result = isc_app_ctxstart(ctxs_actx);
|
result = isc_app_ctxstart(ctxs_actx);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
@ -102,7 +100,7 @@ fail:
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *algname;
|
static char *algname = NULL;
|
||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
printdata(dns_rdataset_t *rdataset, dns_name_t *owner) {
|
printdata(dns_rdataset_t *rdataset, dns_name_t *owner) {
|
||||||
@ -281,9 +279,9 @@ main(int argc, char *argv[]) {
|
|||||||
isc_buffer_t b;
|
isc_buffer_t b;
|
||||||
dns_fixedname_t qname0;
|
dns_fixedname_t qname0;
|
||||||
unsigned int namelen;
|
unsigned int namelen;
|
||||||
dns_name_t *qname, *name;
|
dns_name_t *qname = NULL, *name = NULL;
|
||||||
dns_rdatatype_t type = dns_rdatatype_a;
|
dns_rdatatype_t type = dns_rdatatype_a;
|
||||||
dns_rdataset_t *rdataset;
|
dns_rdataset_t *rdataset = NULL;
|
||||||
dns_namelist_t namelist;
|
dns_namelist_t namelist;
|
||||||
unsigned int clientopt, resopt = 0;
|
unsigned int clientopt, resopt = 0;
|
||||||
bool is_sep = false;
|
bool is_sep = false;
|
||||||
@ -406,7 +404,7 @@ main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
clientopt = 0;
|
clientopt = 0;
|
||||||
result = dns_client_create(ctxs_mctx, ctxs_actx, ctxs_taskmgr,
|
result = dns_client_create(ctxs_mctx, ctxs_actx, ctxs_taskmgr,
|
||||||
ctxs_socketmgr, ctxs_timermgr, clientopt,
|
ctxs_netmgr, ctxs_timermgr, clientopt,
|
||||||
&client, addr4, addr6);
|
&client, addr4, addr6);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
fprintf(stderr, "dns_client_create failed: %u, %s\n", result,
|
fprintf(stderr, "dns_client_create failed: %u, %s\n", result,
|
||||||
|
@ -18,13 +18,12 @@
|
|||||||
#include <isc/log.h>
|
#include <isc/log.h>
|
||||||
#include <isc/managers.h>
|
#include <isc/managers.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
|
#include <isc/netmgr.h>
|
||||||
#include <isc/nonce.h>
|
#include <isc/nonce.h>
|
||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
#include <isc/random.h>
|
#include <isc/random.h>
|
||||||
#include <isc/sockaddr.h>
|
#include <isc/sockaddr.h>
|
||||||
#include <isc/socket.h>
|
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/dispatch.h>
|
#include <dns/dispatch.h>
|
||||||
@ -86,7 +85,6 @@ recvquery(isc_task_t *task, isc_event_t *event) {
|
|||||||
|
|
||||||
query = reqev->ev_arg;
|
query = reqev->ev_arg;
|
||||||
|
|
||||||
response = NULL;
|
|
||||||
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
|
dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response);
|
||||||
|
|
||||||
result = dns_request_getresponse(reqev->request, response,
|
result = dns_request_getresponse(reqev->request, response,
|
||||||
@ -190,9 +188,6 @@ main(int argc, char *argv[]) {
|
|||||||
char *ourkeyname = NULL;
|
char *ourkeyname = NULL;
|
||||||
isc_nm_t *netmgr = NULL;
|
isc_nm_t *netmgr = NULL;
|
||||||
isc_taskmgr_t *taskmgr = NULL;
|
isc_taskmgr_t *taskmgr = NULL;
|
||||||
isc_timermgr_t *timermgr = NULL;
|
|
||||||
isc_socketmgr_t *socketmgr = NULL;
|
|
||||||
isc_socket_t *sock = NULL;
|
|
||||||
isc_sockaddr_t bind_any;
|
isc_sockaddr_t bind_any;
|
||||||
dns_dispatchmgr_t *dispatchmgr = NULL;
|
dns_dispatchmgr_t *dispatchmgr = NULL;
|
||||||
dns_dispatch_t *dispatchv4 = NULL;
|
dns_dispatch_t *dispatchv4 = NULL;
|
||||||
@ -227,18 +222,16 @@ main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||||
|
|
||||||
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr,
|
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, NULL, NULL);
|
||||||
&socketmgr);
|
|
||||||
|
|
||||||
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
||||||
RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr));
|
RUNCHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr));
|
||||||
|
|
||||||
isc_sockaddr_any(&bind_any);
|
isc_sockaddr_any(&bind_any);
|
||||||
RUNCHECK(dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr,
|
RUNCHECK(dns_dispatch_createudp(dispatchmgr, taskmgr, &bind_any, 0,
|
||||||
&bind_any, 0, &dispatchv4));
|
&dispatchv4));
|
||||||
RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr,
|
RUNCHECK(dns_requestmgr_create(mctx, taskmgr, dispatchmgr, dispatchv4,
|
||||||
dispatchmgr, dispatchv4, NULL,
|
NULL, &requestmgr));
|
||||||
&requestmgr));
|
|
||||||
|
|
||||||
RUNCHECK(dns_tsigkeyring_create(mctx, &ring));
|
RUNCHECK(dns_tsigkeyring_create(mctx, &ring));
|
||||||
RUNCHECK(dns_tkeyctx_create(mctx, &tctx));
|
RUNCHECK(dns_tkeyctx_create(mctx, &tctx));
|
||||||
@ -247,9 +240,6 @@ main(int argc, char *argv[]) {
|
|||||||
dns_view_setkeyring(view, ring);
|
dns_view_setkeyring(view, ring);
|
||||||
dns_tsigkeyring_detach(&ring);
|
dns_tsigkeyring_detach(&ring);
|
||||||
|
|
||||||
RUNCHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp,
|
|
||||||
&sock));
|
|
||||||
|
|
||||||
RUNCHECK(isc_app_onrun(mctx, task, sendquery, NULL));
|
RUNCHECK(isc_app_onrun(mctx, task, sendquery, NULL));
|
||||||
|
|
||||||
type = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_KEY;
|
type = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_KEY;
|
||||||
@ -268,8 +258,7 @@ main(int argc, char *argv[]) {
|
|||||||
dns_dispatchmgr_destroy(&dispatchmgr);
|
dns_dispatchmgr_destroy(&dispatchmgr);
|
||||||
isc_task_shutdown(task);
|
isc_task_shutdown(task);
|
||||||
isc_task_detach(&task);
|
isc_task_detach(&task);
|
||||||
isc_socket_detach(&sock);
|
isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL);
|
||||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
|
||||||
|
|
||||||
dst_key_free(&ourkey);
|
dst_key_free(&ourkey);
|
||||||
dns_tsigkey_detach(&initialkey);
|
dns_tsigkey_detach(&initialkey);
|
||||||
|
@ -22,9 +22,7 @@
|
|||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
#include <isc/random.h>
|
#include <isc/random.h>
|
||||||
#include <isc/sockaddr.h>
|
#include <isc/sockaddr.h>
|
||||||
#include <isc/socket.h>
|
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/dispatch.h>
|
#include <dns/dispatch.h>
|
||||||
@ -134,9 +132,6 @@ main(int argc, char **argv) {
|
|||||||
char *keyname = NULL;
|
char *keyname = NULL;
|
||||||
isc_nm_t *netmgr = NULL;
|
isc_nm_t *netmgr = NULL;
|
||||||
isc_taskmgr_t *taskmgr = NULL;
|
isc_taskmgr_t *taskmgr = NULL;
|
||||||
isc_timermgr_t *timermgr = NULL;
|
|
||||||
isc_socketmgr_t *socketmgr = NULL;
|
|
||||||
isc_socket_t *sock = NULL;
|
|
||||||
isc_sockaddr_t bind_any;
|
isc_sockaddr_t bind_any;
|
||||||
dns_dispatchmgr_t *dispatchmgr = NULL;
|
dns_dispatchmgr_t *dispatchmgr = NULL;
|
||||||
dns_dispatch_t *dispatchv4 = NULL;
|
dns_dispatch_t *dispatchv4 = NULL;
|
||||||
@ -171,17 +166,15 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||||
|
|
||||||
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr,
|
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, NULL, NULL);
|
||||||
&socketmgr);
|
|
||||||
|
|
||||||
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
||||||
RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr));
|
RUNCHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr));
|
||||||
isc_sockaddr_any(&bind_any);
|
isc_sockaddr_any(&bind_any);
|
||||||
RUNCHECK(dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr,
|
RUNCHECK(dns_dispatch_createudp(dispatchmgr, taskmgr, &bind_any, 0,
|
||||||
&bind_any, 0, &dispatchv4));
|
&dispatchv4));
|
||||||
RUNCHECK(dns_requestmgr_create(mctx, timermgr, socketmgr, taskmgr,
|
RUNCHECK(dns_requestmgr_create(mctx, taskmgr, dispatchmgr, dispatchv4,
|
||||||
dispatchmgr, dispatchv4, NULL,
|
NULL, &requestmgr));
|
||||||
&requestmgr));
|
|
||||||
|
|
||||||
RUNCHECK(dns_tsigkeyring_create(mctx, &ring));
|
RUNCHECK(dns_tsigkeyring_create(mctx, &ring));
|
||||||
RUNCHECK(dns_tkeyctx_create(mctx, &tctx));
|
RUNCHECK(dns_tkeyctx_create(mctx, &tctx));
|
||||||
@ -189,9 +182,6 @@ main(int argc, char **argv) {
|
|||||||
RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
|
RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
|
||||||
dns_view_setkeyring(view, ring);
|
dns_view_setkeyring(view, ring);
|
||||||
|
|
||||||
RUNCHECK(isc_socket_create(socketmgr, PF_INET, isc_sockettype_udp,
|
|
||||||
&sock));
|
|
||||||
|
|
||||||
RUNCHECK(isc_app_onrun(mctx, task, sendquery, NULL));
|
RUNCHECK(isc_app_onrun(mctx, task, sendquery, NULL));
|
||||||
|
|
||||||
type = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_KEY;
|
type = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_KEY;
|
||||||
@ -211,8 +201,7 @@ main(int argc, char **argv) {
|
|||||||
dns_dispatchmgr_destroy(&dispatchmgr);
|
dns_dispatchmgr_destroy(&dispatchmgr);
|
||||||
isc_task_shutdown(task);
|
isc_task_shutdown(task);
|
||||||
isc_task_detach(&task);
|
isc_task_detach(&task);
|
||||||
isc_socket_detach(&sock);
|
isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL);
|
||||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
|
||||||
|
|
||||||
dns_tsigkeyring_detach(&ring);
|
dns_tsigkeyring_detach(&ring);
|
||||||
|
|
||||||
|
@ -24,15 +24,14 @@
|
|||||||
#include <isc/managers.h>
|
#include <isc/managers.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
#include <isc/net.h>
|
#include <isc/net.h>
|
||||||
|
#include <isc/netmgr.h>
|
||||||
#include <isc/nonce.h>
|
#include <isc/nonce.h>
|
||||||
#include <isc/parseint.h>
|
#include <isc/parseint.h>
|
||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
#include <isc/random.h>
|
#include <isc/random.h>
|
||||||
#include <isc/sockaddr.h>
|
#include <isc/sockaddr.h>
|
||||||
#include <isc/socket.h>
|
|
||||||
#include <isc/string.h>
|
#include <isc/string.h>
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/byaddr.h>
|
#include <dns/byaddr.h>
|
||||||
@ -2068,8 +2067,6 @@ main(int argc, char *argv[]) {
|
|||||||
isc_nm_t *netmgr = NULL;
|
isc_nm_t *netmgr = NULL;
|
||||||
isc_taskmgr_t *taskmgr = NULL;
|
isc_taskmgr_t *taskmgr = NULL;
|
||||||
isc_task_t *task = NULL;
|
isc_task_t *task = NULL;
|
||||||
isc_timermgr_t *timermgr = NULL;
|
|
||||||
isc_socketmgr_t *socketmgr = NULL;
|
|
||||||
dns_dispatchmgr_t *dispatchmgr = NULL;
|
dns_dispatchmgr_t *dispatchmgr = NULL;
|
||||||
dns_dispatch_t *dispatchvx = NULL;
|
dns_dispatch_t *dispatchvx = NULL;
|
||||||
dns_view_t *view = NULL;
|
dns_view_t *view = NULL;
|
||||||
@ -2122,25 +2119,22 @@ main(int argc, char *argv[]) {
|
|||||||
fatal("can't choose between IPv4 and IPv6");
|
fatal("can't choose between IPv4 and IPv6");
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, &timermgr,
|
isc_managers_create(mctx, 1, 0, 0, &netmgr, &taskmgr, NULL, NULL);
|
||||||
&socketmgr);
|
|
||||||
|
|
||||||
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
RUNCHECK(isc_task_create(taskmgr, 0, &task));
|
||||||
RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr));
|
RUNCHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr));
|
||||||
|
|
||||||
if (have_ipv4) {
|
if (have_ipv4) {
|
||||||
isc_sockaddr_any(&bind_any);
|
isc_sockaddr_any(&bind_any);
|
||||||
} else {
|
} else {
|
||||||
isc_sockaddr_any6(&bind_any);
|
isc_sockaddr_any6(&bind_any);
|
||||||
}
|
}
|
||||||
RUNCHECK(dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr,
|
RUNCHECK(dns_dispatch_createudp(dispatchmgr, taskmgr,
|
||||||
have_src ? &srcaddr : &bind_any, 0,
|
have_src ? &srcaddr : &bind_any, 0,
|
||||||
&dispatchvx));
|
&dispatchvx));
|
||||||
|
|
||||||
RUNCHECK(dns_requestmgr_create(
|
RUNCHECK(dns_requestmgr_create(
|
||||||
mctx, timermgr, socketmgr, taskmgr, dispatchmgr,
|
mctx, taskmgr, dispatchmgr, have_ipv4 ? dispatchvx : NULL,
|
||||||
have_ipv4 ? dispatchvx : NULL, have_ipv6 ? dispatchvx : NULL,
|
have_ipv6 ? dispatchvx : NULL, &requestmgr));
|
||||||
&requestmgr));
|
|
||||||
|
|
||||||
RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
|
RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
|
||||||
|
|
||||||
@ -2186,7 +2180,7 @@ main(int argc, char *argv[]) {
|
|||||||
isc_task_shutdown(task);
|
isc_task_shutdown(task);
|
||||||
isc_task_detach(&task);
|
isc_task_detach(&task);
|
||||||
|
|
||||||
isc_managers_destroy(&netmgr, &taskmgr, &timermgr, &socketmgr);
|
isc_managers_destroy(&netmgr, &taskmgr, NULL, NULL);
|
||||||
|
|
||||||
dst_lib_destroy();
|
dst_lib_destroy();
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ struct dns_client {
|
|||||||
isc_appctx_t *actx;
|
isc_appctx_t *actx;
|
||||||
isc_taskmgr_t *taskmgr;
|
isc_taskmgr_t *taskmgr;
|
||||||
isc_task_t *task;
|
isc_task_t *task;
|
||||||
isc_socketmgr_t *socketmgr;
|
isc_nm_t *nm;
|
||||||
isc_timermgr_t *timermgr;
|
isc_timermgr_t *timermgr;
|
||||||
dns_dispatchmgr_t *dispatchmgr;
|
dns_dispatchmgr_t *dispatchmgr;
|
||||||
dns_dispatch_t *dispatchv4;
|
dns_dispatch_t *dispatchv4;
|
||||||
@ -202,8 +202,8 @@ cleanup:
|
|||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr,
|
getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr,
|
||||||
isc_socketmgr_t *socketmgr, isc_taskmgr_t *taskmgr,
|
isc_taskmgr_t *taskmgr, dns_dispatch_t **dispp,
|
||||||
dns_dispatch_t **dispp, const isc_sockaddr_t *localaddr) {
|
const isc_sockaddr_t *localaddr) {
|
||||||
dns_dispatch_t *disp = NULL;
|
dns_dispatch_t *disp = NULL;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
isc_sockaddr_t anyaddr;
|
isc_sockaddr_t anyaddr;
|
||||||
@ -213,8 +213,8 @@ getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr,
|
|||||||
localaddr = &anyaddr;
|
localaddr = &anyaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr,
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr, localaddr, 0,
|
||||||
localaddr, 0, &disp);
|
&disp);
|
||||||
if (result == ISC_R_SUCCESS) {
|
if (result == ISC_R_SUCCESS) {
|
||||||
*dispp = disp;
|
*dispp = disp;
|
||||||
}
|
}
|
||||||
@ -224,10 +224,9 @@ getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr,
|
|||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_taskmgr_t *taskmgr,
|
createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_taskmgr_t *taskmgr,
|
||||||
unsigned int ntasks, isc_socketmgr_t *socketmgr,
|
unsigned int ntasks, isc_nm_t *nm, isc_timermgr_t *timermgr,
|
||||||
isc_timermgr_t *timermgr, dns_dispatchmgr_t *dispatchmgr,
|
dns_dispatchmgr_t *dispatchmgr, dns_dispatch_t *dispatchv4,
|
||||||
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
|
dns_dispatch_t *dispatchv6, dns_view_t **viewp) {
|
||||||
dns_view_t **viewp) {
|
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
dns_view_t *view = NULL;
|
dns_view_t *view = NULL;
|
||||||
|
|
||||||
@ -243,8 +242,8 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_taskmgr_t *taskmgr,
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_view_createresolver(view, taskmgr, ntasks, 1, socketmgr,
|
result = dns_view_createresolver(view, taskmgr, ntasks, 1, nm, timermgr,
|
||||||
timermgr, 0, dispatchmgr, dispatchv4,
|
0, dispatchmgr, dispatchv4,
|
||||||
dispatchv6);
|
dispatchv6);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
dns_view_detach(&view);
|
dns_view_detach(&view);
|
||||||
@ -264,9 +263,8 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_taskmgr_t *taskmgr,
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
||||||
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
|
isc_nm_t *nm, isc_timermgr_t *timermgr, unsigned int options,
|
||||||
unsigned int options, dns_client_t **clientp,
|
dns_client_t **clientp, const isc_sockaddr_t *localaddr4,
|
||||||
const isc_sockaddr_t *localaddr4,
|
|
||||||
const isc_sockaddr_t *localaddr6) {
|
const isc_sockaddr_t *localaddr6) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
dns_client_t *client = NULL;
|
dns_client_t *client = NULL;
|
||||||
@ -278,27 +276,24 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
|||||||
REQUIRE(mctx != NULL);
|
REQUIRE(mctx != NULL);
|
||||||
REQUIRE(taskmgr != NULL);
|
REQUIRE(taskmgr != NULL);
|
||||||
REQUIRE(timermgr != NULL);
|
REQUIRE(timermgr != NULL);
|
||||||
REQUIRE(socketmgr != NULL);
|
REQUIRE(nm != NULL);
|
||||||
REQUIRE(clientp != NULL && *clientp == NULL);
|
REQUIRE(clientp != NULL && *clientp == NULL);
|
||||||
|
|
||||||
UNUSED(options);
|
UNUSED(options);
|
||||||
|
|
||||||
client = isc_mem_get(mctx, sizeof(*client));
|
client = isc_mem_get(mctx, sizeof(*client));
|
||||||
|
*client = (dns_client_t){
|
||||||
|
.actx = actx, .taskmgr = taskmgr, .timermgr = timermgr, .nm = nm
|
||||||
|
};
|
||||||
|
|
||||||
isc_mutex_init(&client->lock);
|
isc_mutex_init(&client->lock);
|
||||||
|
|
||||||
client->actx = actx;
|
|
||||||
client->taskmgr = taskmgr;
|
|
||||||
client->socketmgr = socketmgr;
|
|
||||||
client->timermgr = timermgr;
|
|
||||||
|
|
||||||
client->task = NULL;
|
|
||||||
result = isc_task_create(client->taskmgr, 0, &client->task);
|
result = isc_task_create(client->taskmgr, 0, &client->task);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup_lock;
|
goto cleanup_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatchmgr_create(mctx, &dispatchmgr);
|
result = dns_dispatchmgr_create(mctx, nm, &dispatchmgr);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup_task;
|
goto cleanup_task;
|
||||||
}
|
}
|
||||||
@ -311,8 +306,8 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
|||||||
*/
|
*/
|
||||||
client->dispatchv4 = NULL;
|
client->dispatchv4 = NULL;
|
||||||
if (localaddr4 != NULL || localaddr6 == NULL) {
|
if (localaddr4 != NULL || localaddr6 == NULL) {
|
||||||
result = getudpdispatch(AF_INET, dispatchmgr, socketmgr,
|
result = getudpdispatch(AF_INET, dispatchmgr, taskmgr,
|
||||||
taskmgr, &dispatchv4, localaddr4);
|
&dispatchv4, localaddr4);
|
||||||
if (result == ISC_R_SUCCESS) {
|
if (result == ISC_R_SUCCESS) {
|
||||||
client->dispatchv4 = dispatchv4;
|
client->dispatchv4 = dispatchv4;
|
||||||
}
|
}
|
||||||
@ -320,8 +315,8 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
|||||||
|
|
||||||
client->dispatchv6 = NULL;
|
client->dispatchv6 = NULL;
|
||||||
if (localaddr6 != NULL || localaddr4 == NULL) {
|
if (localaddr6 != NULL || localaddr4 == NULL) {
|
||||||
result = getudpdispatch(AF_INET6, dispatchmgr, socketmgr,
|
result = getudpdispatch(AF_INET6, dispatchmgr, taskmgr,
|
||||||
taskmgr, &dispatchv6, localaddr6);
|
&dispatchv6, localaddr6);
|
||||||
if (result == ISC_R_SUCCESS) {
|
if (result == ISC_R_SUCCESS) {
|
||||||
client->dispatchv6 = dispatchv6;
|
client->dispatchv6 = dispatchv6;
|
||||||
}
|
}
|
||||||
@ -337,8 +332,8 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
|||||||
|
|
||||||
/* Create the default view for class IN */
|
/* Create the default view for class IN */
|
||||||
result = createview(mctx, dns_rdataclass_in, taskmgr, RESOLVER_NTASKS,
|
result = createview(mctx, dns_rdataclass_in, taskmgr, RESOLVER_NTASKS,
|
||||||
socketmgr, timermgr, dispatchmgr, dispatchv4,
|
nm, timermgr, dispatchmgr, dispatchv4, dispatchv6,
|
||||||
dispatchv6, &view);
|
&view);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup_references;
|
goto cleanup_references;
|
||||||
}
|
}
|
||||||
@ -350,12 +345,10 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
|||||||
|
|
||||||
ISC_LIST_INIT(client->resctxs);
|
ISC_LIST_INIT(client->resctxs);
|
||||||
|
|
||||||
client->mctx = NULL;
|
|
||||||
isc_mem_attach(mctx, &client->mctx);
|
isc_mem_attach(mctx, &client->mctx);
|
||||||
|
|
||||||
client->find_timeout = DEF_FIND_TIMEOUT;
|
client->find_timeout = DEF_FIND_TIMEOUT;
|
||||||
client->find_udpretries = DEF_FIND_UDPRETRIES;
|
client->find_udpretries = DEF_FIND_UDPRETRIES;
|
||||||
client->attributes = 0;
|
|
||||||
|
|
||||||
client->magic = DNS_CLIENT_MAGIC;
|
client->magic = DNS_CLIENT_MAGIC;
|
||||||
|
|
||||||
|
1283
lib/dns/dispatch.c
1283
lib/dns/dispatch.c
File diff suppressed because it is too large
Load Diff
@ -89,9 +89,8 @@ typedef struct dns_clientresevent {
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
||||||
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
|
isc_nm_t *nm, isc_timermgr_t *timermgr, unsigned int options,
|
||||||
unsigned int options, dns_client_t **clientp,
|
dns_client_t **clientp, const isc_sockaddr_t *localaddr4,
|
||||||
const isc_sockaddr_t *localaddr4,
|
|
||||||
const isc_sockaddr_t *localaddr6);
|
const isc_sockaddr_t *localaddr6);
|
||||||
/*%<
|
/*%<
|
||||||
* Create a DNS client object with minimal internal resources, such as
|
* Create a DNS client object with minimal internal resources, such as
|
||||||
@ -113,7 +112,7 @@ dns_client_create(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr,
|
|||||||
*
|
*
|
||||||
*\li 'taskmgr' is a valid task manager.
|
*\li 'taskmgr' is a valid task manager.
|
||||||
*
|
*
|
||||||
*\li 'socketmgr' is a valid socket manager.
|
*\li 'nm' is a valid network manager.
|
||||||
*
|
*
|
||||||
*\li 'timermgr' is a valid timer manager.
|
*\li 'timermgr' is a valid timer manager.
|
||||||
*
|
*
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
* information regarding copyright ownership.
|
* information regarding copyright ownership.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <isc/netmgr.h>
|
||||||
|
|
||||||
#ifndef DNS_DISPATCH_H
|
#ifndef DNS_DISPATCH_H
|
||||||
#define DNS_DISPATCH_H 1
|
#define DNS_DISPATCH_H 1
|
||||||
|
|
||||||
@ -50,6 +52,7 @@
|
|||||||
#include <isc/buffer.h>
|
#include <isc/buffer.h>
|
||||||
#include <isc/lang.h>
|
#include <isc/lang.h>
|
||||||
#include <isc/mutex.h>
|
#include <isc/mutex.h>
|
||||||
|
#include <isc/netmgr.h>
|
||||||
#include <isc/socket.h>
|
#include <isc/socket.h>
|
||||||
#include <isc/types.h>
|
#include <isc/types.h>
|
||||||
|
|
||||||
@ -76,12 +79,9 @@ ISC_LANG_BEGINDECLS
|
|||||||
|
|
||||||
struct dns_dispatchevent {
|
struct dns_dispatchevent {
|
||||||
ISC_EVENT_COMMON(dns_dispatchevent_t); /*%< standard event common */
|
ISC_EVENT_COMMON(dns_dispatchevent_t); /*%< standard event common */
|
||||||
isc_result_t result; /*%< result code */
|
isc_result_t result; /*%< result code */
|
||||||
int32_t id; /*%< message id */
|
isc_region_t region; /*%< data region */
|
||||||
isc_sockaddr_t addr; /*%< address recv'd from */
|
isc_buffer_t buffer; /*%< data buffer */
|
||||||
struct in6_pktinfo pktinfo; /*%< reply info for v6 */
|
|
||||||
isc_buffer_t buffer; /*%< data buffer */
|
|
||||||
uint32_t attributes; /*%< mirrored from socket.h */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*%
|
/*%
|
||||||
@ -128,14 +128,16 @@ struct dns_dispatchset {
|
|||||||
#define DNS_DISPATCHOPT_FIXEDID 0x00000001U
|
#define DNS_DISPATCHOPT_FIXEDID 0x00000001U
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp);
|
dns_dispatchmgr_create(isc_mem_t *mctx, isc_nm_t *nm, dns_dispatchmgr_t **mgrp);
|
||||||
/*%<
|
/*%<
|
||||||
* Creates a new dispatchmgr object, and sets the available ports
|
* Creates a new dispatchmgr object, and sets the available ports
|
||||||
* to the default range (1024-65535).
|
* to the default range (1024-65535).
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
*\li "mctx" be a valid memory context.
|
*\li 'mctx' be a valid memory context.
|
||||||
*
|
*
|
||||||
|
*\li 'nm' is a valid network manager.
|
||||||
|
|
||||||
*\li mgrp != NULL && *mgrp == NULL
|
*\li mgrp != NULL && *mgrp == NULL
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
@ -205,9 +207,9 @@ dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, isc_stats_t *stats);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
|
dns_dispatch_createudp(dns_dispatchmgr_t *mgr, isc_taskmgr_t *taskmgr,
|
||||||
isc_taskmgr_t *taskmgr, const isc_sockaddr_t *localaddr,
|
const isc_sockaddr_t *localaddr, unsigned int attributes,
|
||||||
unsigned int attributes, dns_dispatch_t **dispp);
|
dns_dispatch_t **dispp);
|
||||||
/*%<
|
/*%<
|
||||||
* Create a new UDP dispatch.
|
* Create a new UDP dispatch.
|
||||||
*
|
*
|
||||||
@ -223,8 +225,8 @@ dns_dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
|
dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_taskmgr_t *taskmgr,
|
||||||
isc_taskmgr_t *taskmgr, const isc_sockaddr_t *localaddr,
|
const isc_sockaddr_t *localaddr,
|
||||||
const isc_sockaddr_t *destaddr, unsigned int attributes,
|
const isc_sockaddr_t *destaddr, unsigned int attributes,
|
||||||
isc_dscp_t dscp, dns_dispatch_t **dispp);
|
isc_dscp_t dscp, dns_dispatch_t **dispp);
|
||||||
/*%<
|
/*%<
|
||||||
@ -265,15 +267,13 @@ dns_dispatch_detach(dns_dispatch_t **dispp);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_dispatch_connect(dns_dispatch_t *disp, dns_dispentry_t *resp,
|
dns_dispatch_connect(dns_dispentry_t *resp);
|
||||||
isc_task_t *task, isc_taskaction_t action, void *arg);
|
|
||||||
/*%<
|
/*%<
|
||||||
* Connect the UDP socket in 'resp' or the TCP socket in 'disp' to the
|
* Connect to the remote server configured in 'resp' and run the
|
||||||
* remote server, and run the specified callback.
|
* connect callback that was set up via dns_dispatch_addresponse().
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
*\li 'resp' is NULL and 'disp' is valid, or
|
*\li 'resp' is valid.
|
||||||
*\li 'disp' is NULL and 'resp' is valid.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -288,29 +288,16 @@ dns_dispatch_cancel(dns_dispatch_t *disp, dns_dispentry_t *resp, bool sending,
|
|||||||
*\li 'disp' is NULL and 'resp' is valid.
|
*\li 'disp' is NULL and 'resp' is valid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
isc_result_t
|
void
|
||||||
dns_dispatch_send(dns_dispentry_t *resp, bool tcp, isc_task_t *task,
|
dns_dispatch_send(dns_dispentry_t *resp, isc_region_t *r, isc_dscp_t dscp);
|
||||||
isc_socketevent_t *sendevent, isc_region_t *r,
|
|
||||||
const isc_sockaddr_t *address, isc_dscp_t dscp,
|
|
||||||
isc_taskaction_t action, void *arg);
|
|
||||||
/*%<
|
/*%<
|
||||||
* Send region 'r' using the socket in 'resp', then run the specified
|
* Send region 'r' using the socket in 'resp', then run the specified
|
||||||
* callback. 'sendevent' must point to enough memory to hold an
|
* callback.
|
||||||
* isc_socketevent; it will be overwritten.
|
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
*\li 'resp' is valid.
|
*\li 'resp' is valid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
|
||||||
dns_dispatch_starttcp(dns_dispatch_t *disp);
|
|
||||||
/*%<
|
|
||||||
* Start processing of a TCP dispatch once the socket connects.
|
|
||||||
*
|
|
||||||
* Requires:
|
|
||||||
*\li 'disp' is valid.
|
|
||||||
*/
|
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *destaddr,
|
dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *destaddr,
|
||||||
const isc_sockaddr_t *localaddr, bool *connected,
|
const isc_sockaddr_t *localaddr, bool *connected,
|
||||||
@ -322,18 +309,29 @@ dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *destaddr,
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options,
|
dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options,
|
||||||
const isc_sockaddr_t *dest, isc_task_t *task,
|
unsigned int timeout, const isc_sockaddr_t *dest,
|
||||||
isc_taskaction_t action, void *arg, uint16_t *idp,
|
isc_task_t *task, isc_nm_cb_t connected,
|
||||||
dns_dispentry_t **resp, isc_socketmgr_t *sockmgr);
|
isc_nm_cb_t sent, isc_taskaction_t action,
|
||||||
|
isc_taskaction_t timeout_action, void *arg,
|
||||||
|
dns_messageid_t *idp, dns_dispentry_t **resp);
|
||||||
/*%<
|
/*%<
|
||||||
* Add a response entry for this dispatch.
|
* Add a response entry for this dispatch.
|
||||||
*
|
*
|
||||||
* "*idp" is filled in with the assigned message ID, and *resp is filled in
|
* "*idp" is filled in with the assigned message ID, and *resp is filled in
|
||||||
* to contain the magic token used to request event flow stop.
|
* to contain the magic token used to request event flow stop.
|
||||||
*
|
*
|
||||||
* Arranges for the given task to get a callback for response packets. When
|
* The 'connected' and 'sent' callbacks are run to inform the caller when
|
||||||
* the event is delivered, it must be returned using dns_dispatch_freeevent()
|
* the connection and send functions are complete.
|
||||||
* or through dns_dispatch_removeresponse() for another to be delivered.
|
*
|
||||||
|
* The specified 'task' is sent the 'action' callback for response packets.
|
||||||
|
* (Later, this should be updated to a network manager callback function,
|
||||||
|
* but for now we still use isc_task for this.) When the event is delivered,
|
||||||
|
* it must be returned using dns_dispatch_freeevent() or through
|
||||||
|
* dns_dispatch_removeresponse() for another to be delivered.
|
||||||
|
*
|
||||||
|
* On timeout, 'timeout_action' will be sent to the task.
|
||||||
|
*
|
||||||
|
* All three callback functions are sent 'arg' as a parameter.
|
||||||
*
|
*
|
||||||
* Requires:
|
* Requires:
|
||||||
*\li "idp" be non-NULL.
|
*\li "idp" be non-NULL.
|
||||||
@ -344,10 +342,6 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options,
|
|||||||
*
|
*
|
||||||
*\li "resp" be non-NULL and *resp be NULL
|
*\li "resp" be non-NULL and *resp be NULL
|
||||||
*
|
*
|
||||||
*\li "sockmgr" be NULL or a valid socket manager. If 'disp' has
|
|
||||||
* the DNS_DISPATCHATTR_EXCLUSIVE attribute, this must not be NULL,
|
|
||||||
* which also means dns_dispatch_addresponse() cannot be used.
|
|
||||||
*
|
|
||||||
* Ensures:
|
* Ensures:
|
||||||
*
|
*
|
||||||
*\li <id, dest> is a unique tuple. That means incoming messages
|
*\li <id, dest> is a unique tuple. That means incoming messages
|
||||||
@ -452,9 +446,9 @@ dns_dispatchset_get(dns_dispatchset_t *dset);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_dispatchset_create(isc_mem_t *mctx, isc_socketmgr_t *sockmgr,
|
dns_dispatchset_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||||
isc_taskmgr_t *taskmgr, dns_dispatch_t *source,
|
dns_dispatch_t *source, dns_dispatchset_t **dsetp,
|
||||||
dns_dispatchset_t **dsetp, int n);
|
int n);
|
||||||
/*%<
|
/*%<
|
||||||
* Given a valid dispatch 'source', create a dispatch set containing
|
* Given a valid dispatch 'source', create a dispatch set containing
|
||||||
* 'n' UDP dispatches, with the remainder filled out by clones of the
|
* 'n' UDP dispatches, with the remainder filled out by clones of the
|
||||||
|
@ -53,8 +53,7 @@ typedef struct dns_requestevent {
|
|||||||
ISC_LANG_BEGINDECLS
|
ISC_LANG_BEGINDECLS
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_requestmgr_create(isc_mem_t *mctx, isc_timermgr_t *timermgr,
|
dns_requestmgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||||
isc_socketmgr_t *socketmgr, isc_taskmgr_t *taskmgr,
|
|
||||||
dns_dispatchmgr_t *dispatchmgr,
|
dns_dispatchmgr_t *dispatchmgr,
|
||||||
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
|
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
|
||||||
dns_requestmgr_t **requestmgrp);
|
dns_requestmgr_t **requestmgrp);
|
||||||
@ -65,8 +64,6 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_timermgr_t *timermgr,
|
|||||||
*
|
*
|
||||||
*\li 'mctx' is a valid memory context.
|
*\li 'mctx' is a valid memory context.
|
||||||
*
|
*
|
||||||
*\li 'timermgr' is a valid timer manager.
|
|
||||||
*
|
|
||||||
*\li 'socketmgr' is a valid socket manager.
|
*\li 'socketmgr' is a valid socket manager.
|
||||||
*
|
*
|
||||||
*\li 'taskmgr' is a valid task manager.
|
*\li 'taskmgr' is a valid task manager.
|
||||||
|
@ -163,11 +163,10 @@ typedef enum { dns_quotatype_zone = 0, dns_quotatype_server } dns_quotatype_t;
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||||
unsigned int ntasks, unsigned int ndisp,
|
unsigned int ntasks, unsigned int ndisp, isc_nm_t *nm,
|
||||||
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
|
isc_timermgr_t *timermgr, unsigned int options,
|
||||||
unsigned int options, dns_dispatchmgr_t *dispatchmgr,
|
dns_dispatchmgr_t *dispatchmgr, dns_dispatch_t *dispatchv4,
|
||||||
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
|
dns_dispatch_t *dispatchv6, dns_resolver_t **resp);
|
||||||
dns_resolver_t **resp);
|
|
||||||
|
|
||||||
/*%<
|
/*%<
|
||||||
* Create a resolver.
|
* Create a resolver.
|
||||||
@ -185,7 +184,7 @@ dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
|||||||
*
|
*
|
||||||
*\li 'ntasks' > 0.
|
*\li 'ntasks' > 0.
|
||||||
*
|
*
|
||||||
*\li 'socketmgr' is a valid socket manager.
|
*\li 'nm' is a valid network manager.
|
||||||
*
|
*
|
||||||
*\li 'timermgr' is a valid timer manager.
|
*\li 'timermgr' is a valid timer manager.
|
||||||
*
|
*
|
||||||
@ -413,9 +412,6 @@ dns_resolver_dispatchv4(dns_resolver_t *resolver);
|
|||||||
dns_dispatch_t *
|
dns_dispatch_t *
|
||||||
dns_resolver_dispatchv6(dns_resolver_t *resolver);
|
dns_resolver_dispatchv6(dns_resolver_t *resolver);
|
||||||
|
|
||||||
isc_socketmgr_t *
|
|
||||||
dns_resolver_socketmgr(dns_resolver_t *resolver);
|
|
||||||
|
|
||||||
isc_taskmgr_t *
|
isc_taskmgr_t *
|
||||||
dns_resolver_taskmgr(dns_resolver_t *resolver);
|
dns_resolver_taskmgr(dns_resolver_t *resolver);
|
||||||
|
|
||||||
|
@ -393,9 +393,9 @@ dns_view_createzonetable(dns_view_t *view);
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||||
unsigned int ntasks, unsigned int ndisp,
|
unsigned int ntasks, unsigned int ndisp, isc_nm_t *nm,
|
||||||
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
|
isc_timermgr_t *timermgr, unsigned int options,
|
||||||
unsigned int options, dns_dispatchmgr_t *dispatchmgr,
|
dns_dispatchmgr_t *dispatchmgr,
|
||||||
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6);
|
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6);
|
||||||
/*%<
|
/*%<
|
||||||
* Create a resolver and address database for the view.
|
* Create a resolver and address database for the view.
|
||||||
@ -407,7 +407,7 @@ dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
|||||||
*\li 'view' does not have a resolver already.
|
*\li 'view' does not have a resolver already.
|
||||||
*
|
*
|
||||||
*\li The requirements of dns_resolver_create() apply to 'taskmgr',
|
*\li The requirements of dns_resolver_create() apply to 'taskmgr',
|
||||||
* 'ntasks', 'socketmgr', 'timermgr', 'options', 'dispatchv4', and
|
* 'ntasks', 'nm', 'timermgr', 'options', 'dispatchv4', and
|
||||||
* 'dispatchv6'.
|
* 'dispatchv6'.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#include <isc/magic.h>
|
#include <isc/magic.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/acl.h>
|
#include <dns/acl.h>
|
||||||
@ -50,8 +49,6 @@ struct dns_requestmgr {
|
|||||||
/* locked */
|
/* locked */
|
||||||
int32_t eref;
|
int32_t eref;
|
||||||
int32_t iref;
|
int32_t iref;
|
||||||
isc_timermgr_t *timermgr;
|
|
||||||
isc_socketmgr_t *socketmgr;
|
|
||||||
isc_taskmgr_t *taskmgr;
|
isc_taskmgr_t *taskmgr;
|
||||||
dns_dispatchmgr_t *dispatchmgr;
|
dns_dispatchmgr_t *dispatchmgr;
|
||||||
dns_dispatch_t *dispatchv4;
|
dns_dispatch_t *dispatchv4;
|
||||||
@ -74,7 +71,6 @@ struct dns_request {
|
|||||||
dns_requestevent_t *event;
|
dns_requestevent_t *event;
|
||||||
dns_dispatch_t *dispatch;
|
dns_dispatch_t *dispatch;
|
||||||
dns_dispentry_t *dispentry;
|
dns_dispentry_t *dispentry;
|
||||||
isc_timer_t *timer;
|
|
||||||
dns_requestmgr_t *requestmgr;
|
dns_requestmgr_t *requestmgr;
|
||||||
isc_buffer_t *tsig;
|
isc_buffer_t *tsig;
|
||||||
dns_tsigkey_t *tsigkey;
|
dns_tsigkey_t *tsigkey;
|
||||||
@ -115,16 +111,16 @@ static isc_result_t
|
|||||||
req_render(dns_message_t *message, isc_buffer_t **buffer, unsigned int options,
|
req_render(dns_message_t *message, isc_buffer_t **buffer, unsigned int options,
|
||||||
isc_mem_t *mctx);
|
isc_mem_t *mctx);
|
||||||
static void
|
static void
|
||||||
req_senddone(isc_task_t *task, isc_event_t *event);
|
|
||||||
static void
|
|
||||||
req_response(isc_task_t *task, isc_event_t *event);
|
req_response(isc_task_t *task, isc_event_t *event);
|
||||||
static void
|
static void
|
||||||
req_timeout(isc_task_t *task, isc_event_t *event);
|
req_timeout(isc_task_t *task, isc_event_t *event);
|
||||||
static void
|
static void
|
||||||
req_connected(isc_task_t *task, isc_event_t *event);
|
req_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *arg);
|
||||||
static void
|
static void
|
||||||
req_sendevent(dns_request_t *request, isc_result_t result);
|
req_sendevent(dns_request_t *request, isc_result_t result);
|
||||||
static void
|
static void
|
||||||
|
req_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg);
|
||||||
|
static void
|
||||||
req_cancel(dns_request_t *request);
|
req_cancel(dns_request_t *request);
|
||||||
static void
|
static void
|
||||||
req_destroy(dns_request_t *request);
|
req_destroy(dns_request_t *request);
|
||||||
@ -138,8 +134,7 @@ do_cancel(isc_task_t *task, isc_event_t *event);
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_requestmgr_create(isc_mem_t *mctx, isc_timermgr_t *timermgr,
|
dns_requestmgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
|
||||||
isc_socketmgr_t *socketmgr, isc_taskmgr_t *taskmgr,
|
|
||||||
dns_dispatchmgr_t *dispatchmgr,
|
dns_dispatchmgr_t *dispatchmgr,
|
||||||
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
|
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
|
||||||
dns_requestmgr_t **requestmgrp) {
|
dns_requestmgr_t **requestmgrp) {
|
||||||
@ -150,8 +145,6 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_timermgr_t *timermgr,
|
|||||||
req_log(ISC_LOG_DEBUG(3), "dns_requestmgr_create");
|
req_log(ISC_LOG_DEBUG(3), "dns_requestmgr_create");
|
||||||
|
|
||||||
REQUIRE(requestmgrp != NULL && *requestmgrp == NULL);
|
REQUIRE(requestmgrp != NULL && *requestmgrp == NULL);
|
||||||
REQUIRE(timermgr != NULL);
|
|
||||||
REQUIRE(socketmgr != NULL);
|
|
||||||
REQUIRE(taskmgr != NULL);
|
REQUIRE(taskmgr != NULL);
|
||||||
REQUIRE(dispatchmgr != NULL);
|
REQUIRE(dispatchmgr != NULL);
|
||||||
|
|
||||||
@ -171,8 +164,6 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_timermgr_t *timermgr,
|
|||||||
for (i = 0; i < DNS_REQUEST_NLOCKS; i++) {
|
for (i = 0; i < DNS_REQUEST_NLOCKS; i++) {
|
||||||
isc_mutex_init(&requestmgr->locks[i]);
|
isc_mutex_init(&requestmgr->locks[i]);
|
||||||
}
|
}
|
||||||
requestmgr->timermgr = timermgr;
|
|
||||||
requestmgr->socketmgr = socketmgr;
|
|
||||||
requestmgr->taskmgr = taskmgr;
|
requestmgr->taskmgr = taskmgr;
|
||||||
requestmgr->dispatchmgr = dispatchmgr;
|
requestmgr->dispatchmgr = dispatchmgr;
|
||||||
requestmgr->dispatchv4 = NULL;
|
requestmgr->dispatchv4 = NULL;
|
||||||
@ -410,12 +401,9 @@ mgr_gethash(dns_requestmgr_t *requestmgr) {
|
|||||||
return (requestmgr->hash % DNS_REQUEST_NLOCKS);
|
return (requestmgr->hash % DNS_REQUEST_NLOCKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline isc_result_t
|
static inline void
|
||||||
req_send(dns_request_t *request, isc_task_t *task,
|
req_send(dns_request_t *request) {
|
||||||
const isc_sockaddr_t *address) {
|
|
||||||
isc_result_t result;
|
|
||||||
isc_region_t r;
|
isc_region_t r;
|
||||||
bool tcp;
|
|
||||||
|
|
||||||
req_log(ISC_LOG_DEBUG(3), "req_send: request %p", request);
|
req_log(ISC_LOG_DEBUG(3), "req_send: request %p", request);
|
||||||
|
|
||||||
@ -423,14 +411,8 @@ req_send(dns_request_t *request, isc_task_t *task,
|
|||||||
|
|
||||||
isc_buffer_usedregion(request->query, &r);
|
isc_buffer_usedregion(request->query, &r);
|
||||||
|
|
||||||
tcp = dns_request_usedtcp(request);
|
|
||||||
|
|
||||||
request->flags |= DNS_REQUEST_F_SENDING;
|
request->flags |= DNS_REQUEST_F_SENDING;
|
||||||
result = dns_dispatch_send(request->dispentry, tcp, task,
|
dns_dispatch_send(request->dispentry, &r, request->dscp);
|
||||||
&request->sendevent, &r, address,
|
|
||||||
request->dscp, req_senddone, request);
|
|
||||||
INSIST(result == ISC_R_SUCCESS);
|
|
||||||
return (result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
@ -497,9 +479,9 @@ tcp_dispatch(bool newtcp, dns_requestmgr_t *requestmgr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatch_createtcp(
|
result = dns_dispatch_createtcp(requestmgr->dispatchmgr,
|
||||||
requestmgr->dispatchmgr, requestmgr->socketmgr,
|
requestmgr->taskmgr, srcaddr, destaddr,
|
||||||
requestmgr->taskmgr, srcaddr, destaddr, 0, dscp, dispatchp);
|
0, dscp, dispatchp);
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,9 +510,9 @@ udp_dispatch(dns_requestmgr_t *requestmgr, const isc_sockaddr_t *srcaddr,
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (dns_dispatch_createudp(
|
return (dns_dispatch_createudp(requestmgr->dispatchmgr,
|
||||||
requestmgr->dispatchmgr, requestmgr->socketmgr,
|
requestmgr->taskmgr, srcaddr, 0,
|
||||||
requestmgr->taskmgr, srcaddr, 0, dispatchp));
|
dispatchp));
|
||||||
}
|
}
|
||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
@ -548,25 +530,6 @@ get_dispatch(bool tcp, bool newtcp, dns_requestmgr_t *requestmgr,
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static isc_result_t
|
|
||||||
set_timer(isc_timer_t *timer, unsigned int timeout, unsigned int udpresend) {
|
|
||||||
isc_time_t expires;
|
|
||||||
isc_interval_t interval;
|
|
||||||
isc_result_t result;
|
|
||||||
isc_timertype_t timertype;
|
|
||||||
|
|
||||||
isc_interval_set(&interval, timeout, 0);
|
|
||||||
result = isc_time_nowplusinterval(&expires, &interval);
|
|
||||||
isc_interval_set(&interval, udpresend, 0);
|
|
||||||
|
|
||||||
timertype = udpresend != 0 ? isc_timertype_limited : isc_timertype_once;
|
|
||||||
if (result == ISC_R_SUCCESS) {
|
|
||||||
result = isc_timer_reset(timer, timertype, &expires, &interval,
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
|
dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
|
||||||
const isc_sockaddr_t *srcaddr,
|
const isc_sockaddr_t *srcaddr,
|
||||||
@ -617,19 +580,13 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
|
|||||||
udptimeout = 1;
|
udptimeout = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeout *= 1000;
|
||||||
|
udptimeout *= 1000;
|
||||||
|
|
||||||
request->udpcount = udpretries;
|
request->udpcount = udpretries;
|
||||||
request->dscp = dscp;
|
request->dscp = dscp;
|
||||||
|
|
||||||
/*
|
|
||||||
* Create timer now. We will set it below once.
|
|
||||||
*/
|
|
||||||
result = isc_timer_create(requestmgr->timermgr, isc_timertype_inactive,
|
|
||||||
NULL, NULL, task, req_timeout, request,
|
|
||||||
&request->timer);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
request->event = (dns_requestevent_t *)isc_event_allocate(
|
request->event = (dns_requestevent_t *)isc_event_allocate(
|
||||||
mctx, task, DNS_EVENT_REQUESTDONE, action, arg,
|
mctx, task, DNS_EVENT_REQUESTDONE, action, arg,
|
||||||
sizeof(dns_requestevent_t));
|
sizeof(dns_requestevent_t));
|
||||||
@ -661,8 +618,9 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatch_addresponse(
|
result = dns_dispatch_addresponse(
|
||||||
request->dispatch, dispopt, destaddr, task, req_response,
|
request->dispatch, dispopt, tcp ? timeout : udptimeout,
|
||||||
request, &id, &request->dispentry, requestmgr->socketmgr);
|
destaddr, task, req_connected, req_senddone, req_response,
|
||||||
|
req_timeout, request, &id, &request->dispentry);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
if ((options & DNS_REQUESTOPT_FIXEDID) != 0 && !newtcp) {
|
if ((options & DNS_REQUESTOPT_FIXEDID) != 0 && !newtcp) {
|
||||||
newtcp = true;
|
newtcp = true;
|
||||||
@ -674,9 +632,6 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
isc_buffer_allocate(mctx, &request->query, r.length + (tcp ? 2 : 0));
|
isc_buffer_allocate(mctx, &request->query, r.length + (tcp ? 2 : 0));
|
||||||
if (tcp) {
|
|
||||||
isc_buffer_putuint16(request->query, (uint16_t)r.length);
|
|
||||||
}
|
|
||||||
result = isc_buffer_copyregion(request->query, &r);
|
result = isc_buffer_copyregion(request->query, &r);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -684,9 +639,6 @@ again:
|
|||||||
|
|
||||||
/* Add message ID. */
|
/* Add message ID. */
|
||||||
isc_buffer_usedregion(request->query, &r);
|
isc_buffer_usedregion(request->query, &r);
|
||||||
if (tcp) {
|
|
||||||
isc_region_consume(&r, 2);
|
|
||||||
}
|
|
||||||
r.base[0] = (id >> 8) & 0xff;
|
r.base[0] = (id >> 8) & 0xff;
|
||||||
r.base[1] = id & 0xff;
|
r.base[1] = id & 0xff;
|
||||||
|
|
||||||
@ -701,24 +653,15 @@ again:
|
|||||||
ISC_LIST_APPEND(requestmgr->requests, request, link);
|
ISC_LIST_APPEND(requestmgr->requests, request, link);
|
||||||
UNLOCK(&requestmgr->lock);
|
UNLOCK(&requestmgr->lock);
|
||||||
|
|
||||||
result = set_timer(request->timer, timeout, tcp ? 0 : udptimeout);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto unlink;
|
|
||||||
}
|
|
||||||
|
|
||||||
request->destaddr = *destaddr;
|
request->destaddr = *destaddr;
|
||||||
if (tcp && !connected) {
|
if (!tcp || !connected) {
|
||||||
result = dns_dispatch_connect(request->dispatch, NULL, task,
|
result = dns_dispatch_connect(request->dispentry);
|
||||||
req_connected, request);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto unlink;
|
goto unlink;
|
||||||
}
|
}
|
||||||
request->flags |= DNS_REQUEST_F_CONNECTING | DNS_REQUEST_F_TCP;
|
request->flags |= DNS_REQUEST_F_CONNECTING | DNS_REQUEST_F_TCP;
|
||||||
} else {
|
} else {
|
||||||
result = req_send(request, task, connected ? NULL : destaddr);
|
req_send(request);
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto unlink;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req_log(ISC_LOG_DEBUG(3), "dns_request_createraw: request %p", request);
|
req_log(ISC_LOG_DEBUG(3), "dns_request_createraw: request %p", request);
|
||||||
@ -790,7 +733,6 @@ dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message,
|
|||||||
return (DNS_R_BLACKHOLED);
|
return (DNS_R_BLACKHOLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
request = NULL;
|
|
||||||
result = new_request(mctx, &request);
|
result = new_request(mctx, &request);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
return (result);
|
return (result);
|
||||||
@ -802,19 +744,13 @@ dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message,
|
|||||||
udptimeout = 1;
|
udptimeout = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeout *= 1000;
|
||||||
|
udptimeout *= 1000;
|
||||||
|
|
||||||
request->udpcount = udpretries;
|
request->udpcount = udpretries;
|
||||||
request->dscp = dscp;
|
request->dscp = dscp;
|
||||||
|
|
||||||
/*
|
|
||||||
* Create timer now. We will set it below once.
|
|
||||||
*/
|
|
||||||
result = isc_timer_create(requestmgr->timermgr, isc_timertype_inactive,
|
|
||||||
NULL, NULL, task, req_timeout, request,
|
|
||||||
&request->timer);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
request->event = (dns_requestevent_t *)isc_event_allocate(
|
request->event = (dns_requestevent_t *)isc_event_allocate(
|
||||||
mctx, task, DNS_EVENT_REQUESTDONE, action, arg,
|
mctx, task, DNS_EVENT_REQUESTDONE, action, arg,
|
||||||
sizeof(dns_requestevent_t));
|
sizeof(dns_requestevent_t));
|
||||||
@ -835,8 +771,9 @@ use_tcp:
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatch_addresponse(
|
result = dns_dispatch_addresponse(
|
||||||
request->dispatch, 0, destaddr, task, req_response, request,
|
request->dispatch, 0, tcp ? timeout : udptimeout, destaddr,
|
||||||
&id, &request->dispentry, requestmgr->socketmgr);
|
task, req_connected, req_senddone, req_response, req_timeout,
|
||||||
|
request, &id, &request->dispentry);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -880,24 +817,15 @@ use_tcp:
|
|||||||
ISC_LIST_APPEND(requestmgr->requests, request, link);
|
ISC_LIST_APPEND(requestmgr->requests, request, link);
|
||||||
UNLOCK(&requestmgr->lock);
|
UNLOCK(&requestmgr->lock);
|
||||||
|
|
||||||
result = set_timer(request->timer, timeout, tcp ? 0 : udptimeout);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto unlink;
|
|
||||||
}
|
|
||||||
|
|
||||||
request->destaddr = *destaddr;
|
request->destaddr = *destaddr;
|
||||||
if (tcp && !connected) {
|
if (!tcp || !connected) {
|
||||||
result = dns_dispatch_connect(request->dispatch, NULL, task,
|
result = dns_dispatch_connect(request->dispentry);
|
||||||
req_connected, request);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto unlink;
|
goto unlink;
|
||||||
}
|
}
|
||||||
request->flags |= DNS_REQUEST_F_CONNECTING | DNS_REQUEST_F_TCP;
|
request->flags |= DNS_REQUEST_F_CONNECTING | DNS_REQUEST_F_TCP;
|
||||||
} else {
|
} else {
|
||||||
result = req_send(request, task, connected ? NULL : destaddr);
|
req_send(request);
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto unlink;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req_log(ISC_LOG_DEBUG(3), "dns_request_createvia: request %p", request);
|
req_log(ISC_LOG_DEBUG(3), "dns_request_createvia: request %p", request);
|
||||||
@ -926,7 +854,6 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp, unsigned int options,
|
|||||||
isc_buffer_t *buf2 = NULL;
|
isc_buffer_t *buf2 = NULL;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
isc_region_t r;
|
isc_region_t r;
|
||||||
bool tcp = false;
|
|
||||||
dns_compress_t cctx;
|
dns_compress_t cctx;
|
||||||
bool cleanup_cctx = false;
|
bool cleanup_cctx = false;
|
||||||
|
|
||||||
@ -984,16 +911,11 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp, unsigned int options,
|
|||||||
* Copy rendered message to exact sized buffer.
|
* Copy rendered message to exact sized buffer.
|
||||||
*/
|
*/
|
||||||
isc_buffer_usedregion(buf1, &r);
|
isc_buffer_usedregion(buf1, &r);
|
||||||
if ((options & DNS_REQUESTOPT_TCP) != 0) {
|
if ((options & DNS_REQUESTOPT_TCP) == 0 && r.length > 512) {
|
||||||
tcp = true;
|
|
||||||
} else if (r.length > 512) {
|
|
||||||
result = DNS_R_USETCP;
|
result = DNS_R_USETCP;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
isc_buffer_allocate(mctx, &buf2, r.length + (tcp ? 2 : 0));
|
isc_buffer_allocate(mctx, &buf2, r.length);
|
||||||
if (tcp) {
|
|
||||||
isc_buffer_putuint16(buf2, (uint16_t)r.length);
|
|
||||||
}
|
|
||||||
result = isc_buffer_copyregion(buf2, &r);
|
result = isc_buffer_copyregion(buf2, &r);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1138,7 +1060,6 @@ dns_request_destroy(dns_request_t **requestp) {
|
|||||||
INSIST(!ISC_LINK_LINKED(request, link));
|
INSIST(!ISC_LINK_LINKED(request, link));
|
||||||
INSIST(request->dispentry == NULL);
|
INSIST(request->dispentry == NULL);
|
||||||
INSIST(request->dispatch == NULL);
|
INSIST(request->dispatch == NULL);
|
||||||
INSIST(request->timer == NULL);
|
|
||||||
|
|
||||||
req_destroy(request);
|
req_destroy(request);
|
||||||
}
|
}
|
||||||
@ -1147,12 +1068,11 @@ dns_request_destroy(dns_request_t **requestp) {
|
|||||||
*** Private: request.
|
*** Private: request.
|
||||||
***/
|
***/
|
||||||
static void
|
static void
|
||||||
req_connected(isc_task_t *task, isc_event_t *event) {
|
req_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
|
||||||
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
|
dns_request_t *request = (dns_request_t *)arg;
|
||||||
isc_result_t result;
|
|
||||||
dns_request_t *request = event->ev_arg;
|
UNUSED(handle);
|
||||||
|
|
||||||
REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
|
|
||||||
REQUIRE(VALID_REQUEST(request));
|
REQUIRE(VALID_REQUEST(request));
|
||||||
REQUIRE(DNS_REQUEST_CONNECTING(request));
|
REQUIRE(DNS_REQUEST_CONNECTING(request));
|
||||||
|
|
||||||
@ -1171,53 +1091,42 @@ req_connected(isc_task_t *task, isc_event_t *event) {
|
|||||||
send_if_done(request, ISC_R_CANCELED);
|
send_if_done(request, ISC_R_CANCELED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dns_dispatch_starttcp(request->dispatch);
|
if (eresult == ISC_R_SUCCESS) {
|
||||||
result = sevent->result;
|
req_send(request);
|
||||||
if (result == ISC_R_SUCCESS) {
|
} else {
|
||||||
result = req_send(request, task, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
req_cancel(request);
|
req_cancel(request);
|
||||||
send_if_done(request, ISC_R_CANCELED);
|
send_if_done(request, ISC_R_CANCELED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UNLOCK(&request->requestmgr->locks[request->hash]);
|
UNLOCK(&request->requestmgr->locks[request->hash]);
|
||||||
isc_event_free(&event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
req_senddone(isc_task_t *task, isc_event_t *event) {
|
req_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
|
||||||
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
|
dns_request_t *request = (dns_request_t *)arg;
|
||||||
dns_request_t *request = event->ev_arg;
|
|
||||||
|
|
||||||
REQUIRE(event->ev_type == ISC_SOCKEVENT_SENDDONE);
|
|
||||||
REQUIRE(VALID_REQUEST(request));
|
REQUIRE(VALID_REQUEST(request));
|
||||||
REQUIRE(DNS_REQUEST_SENDING(request));
|
REQUIRE(DNS_REQUEST_SENDING(request));
|
||||||
|
|
||||||
req_log(ISC_LOG_DEBUG(3), "req_senddone: request %p", request);
|
UNUSED(handle);
|
||||||
|
|
||||||
UNUSED(task);
|
req_log(ISC_LOG_DEBUG(3), "req_senddone: request %p", request);
|
||||||
|
|
||||||
LOCK(&request->requestmgr->locks[request->hash]);
|
LOCK(&request->requestmgr->locks[request->hash]);
|
||||||
request->flags &= ~DNS_REQUEST_F_SENDING;
|
request->flags &= ~DNS_REQUEST_F_SENDING;
|
||||||
|
|
||||||
if (DNS_REQUEST_CANCELED(request)) {
|
if (DNS_REQUEST_CANCELED(request)) {
|
||||||
/*
|
|
||||||
* Send delayed event.
|
|
||||||
*/
|
|
||||||
if (DNS_REQUEST_TIMEDOUT(request)) {
|
if (DNS_REQUEST_TIMEDOUT(request)) {
|
||||||
send_if_done(request, ISC_R_TIMEDOUT);
|
send_if_done(request, ISC_R_TIMEDOUT);
|
||||||
} else {
|
} else {
|
||||||
send_if_done(request, ISC_R_CANCELED);
|
send_if_done(request, ISC_R_CANCELED);
|
||||||
}
|
}
|
||||||
} else if (sevent->result != ISC_R_SUCCESS) {
|
} else if (eresult != ISC_R_SUCCESS) {
|
||||||
req_cancel(request);
|
req_cancel(request);
|
||||||
send_if_done(request, ISC_R_CANCELED);
|
send_if_done(request, ISC_R_CANCELED);
|
||||||
}
|
}
|
||||||
UNLOCK(&request->requestmgr->locks[request->hash]);
|
|
||||||
|
|
||||||
isc_event_free(&event);
|
UNLOCK(&request->requestmgr->locks[request->hash]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1266,7 +1175,6 @@ done:
|
|||||||
static void
|
static void
|
||||||
req_timeout(isc_task_t *task, isc_event_t *event) {
|
req_timeout(isc_task_t *task, isc_event_t *event) {
|
||||||
dns_request_t *request = event->ev_arg;
|
dns_request_t *request = event->ev_arg;
|
||||||
isc_result_t result;
|
|
||||||
|
|
||||||
REQUIRE(VALID_REQUEST(request));
|
REQUIRE(VALID_REQUEST(request));
|
||||||
|
|
||||||
@ -1274,13 +1182,9 @@ req_timeout(isc_task_t *task, isc_event_t *event) {
|
|||||||
|
|
||||||
UNUSED(task);
|
UNUSED(task);
|
||||||
LOCK(&request->requestmgr->locks[request->hash]);
|
LOCK(&request->requestmgr->locks[request->hash]);
|
||||||
if (event->ev_type == ISC_TIMEREVENT_TICK && request->udpcount-- != 0) {
|
if (request->udpcount-- != 0) {
|
||||||
if (!DNS_REQUEST_SENDING(request)) {
|
if (!DNS_REQUEST_SENDING(request)) {
|
||||||
result = req_send(request, task, &request->destaddr);
|
req_send(request);
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
req_cancel(request);
|
|
||||||
send_if_done(request, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
request->flags |= DNS_REQUEST_F_TIMEDOUT;
|
request->flags |= DNS_REQUEST_F_TIMEDOUT;
|
||||||
@ -1330,9 +1234,6 @@ req_destroy(dns_request_t *request) {
|
|||||||
if (request->dispatch != NULL) {
|
if (request->dispatch != NULL) {
|
||||||
dns_dispatch_detach(&request->dispatch);
|
dns_dispatch_detach(&request->dispatch);
|
||||||
}
|
}
|
||||||
if (request->timer != NULL) {
|
|
||||||
isc_timer_detach(&request->timer);
|
|
||||||
}
|
|
||||||
if (request->tsig != NULL) {
|
if (request->tsig != NULL) {
|
||||||
isc_buffer_free(&request->tsig);
|
isc_buffer_free(&request->tsig);
|
||||||
}
|
}
|
||||||
@ -1359,10 +1260,6 @@ req_cancel(dns_request_t *request) {
|
|||||||
*/
|
*/
|
||||||
request->flags |= DNS_REQUEST_F_CANCELED;
|
request->flags |= DNS_REQUEST_F_CANCELED;
|
||||||
|
|
||||||
if (request->timer != NULL) {
|
|
||||||
isc_timer_detach(&request->timer);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->dispentry != NULL) {
|
if (request->dispentry != NULL) {
|
||||||
dns_dispatch_cancel(NULL, request->dispentry,
|
dns_dispatch_cancel(NULL, request->dispentry,
|
||||||
DNS_REQUEST_SENDING(request),
|
DNS_REQUEST_SENDING(request),
|
||||||
|
@ -496,7 +496,7 @@ struct dns_resolver {
|
|||||||
isc_mutex_t lock;
|
isc_mutex_t lock;
|
||||||
isc_mutex_t primelock;
|
isc_mutex_t primelock;
|
||||||
dns_rdataclass_t rdclass;
|
dns_rdataclass_t rdclass;
|
||||||
isc_socketmgr_t *socketmgr;
|
isc_nm_t *nm;
|
||||||
isc_timermgr_t *timermgr;
|
isc_timermgr_t *timermgr;
|
||||||
isc_taskmgr_t *taskmgr;
|
isc_taskmgr_t *taskmgr;
|
||||||
dns_view_t *view;
|
dns_view_t *view;
|
||||||
@ -604,7 +604,7 @@ resquery_send(resquery_t *query);
|
|||||||
static void
|
static void
|
||||||
resquery_response(isc_task_t *task, isc_event_t *event);
|
resquery_response(isc_task_t *task, isc_event_t *event);
|
||||||
static void
|
static void
|
||||||
resquery_connected(isc_task_t *task, isc_event_t *event);
|
resquery_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg);
|
||||||
static void
|
static void
|
||||||
fctx_try(fetchctx_t *fctx, bool retrying, bool badcache);
|
fctx_try(fetchctx_t *fctx, bool retrying, bool badcache);
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
@ -1354,10 +1354,11 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
dns_adb_adjustsrtt(fctx->adb, query->addrinfo, rtt, factor);
|
dns_adb_adjustsrtt(fctx->adb, query->addrinfo, rtt, factor);
|
||||||
}
|
|
||||||
if ((query->options & DNS_FETCHOPT_TCP) == 0) {
|
if ((query->options & DNS_FETCHOPT_TCP) == 0) {
|
||||||
/* Inform the ADB that we're ending a UDP fetch */
|
/* Inform the ADB that we're ending a UDP fetch */
|
||||||
dns_adb_endudpfetch(fctx->adb, query->addrinfo);
|
dns_adb_endudpfetch(fctx->adb, query->addrinfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1428,7 +1429,9 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp,
|
|||||||
dns_dispatch_removeresponse(&query->dispentry, deventp);
|
dns_dispatch_removeresponse(&query->dispentry, deventp);
|
||||||
}
|
}
|
||||||
|
|
||||||
ISC_LIST_UNLINK(fctx->queries, query, link);
|
if (ISC_LINK_LINKED(query, link)) {
|
||||||
|
ISC_LIST_UNLINK(fctx->queries, query, link);
|
||||||
|
}
|
||||||
|
|
||||||
if (query->tsig != NULL) {
|
if (query->tsig != NULL) {
|
||||||
isc_buffer_free(&query->tsig);
|
isc_buffer_free(&query->tsig);
|
||||||
@ -1796,13 +1799,20 @@ fctx_done(fetchctx_t *fctx, isc_result_t result, int line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
process_sendevent(resquery_t *query, isc_event_t *event) {
|
resquery_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
|
||||||
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
|
resquery_t *query = (resquery_t *)arg;
|
||||||
bool destroy_query = false;
|
bool destroy_query = false;
|
||||||
bool retry = false;
|
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
fetchctx_t *fctx = NULL;
|
fetchctx_t *fctx = NULL;
|
||||||
|
|
||||||
|
QTRACE("senddone");
|
||||||
|
|
||||||
|
UNUSED(handle);
|
||||||
|
|
||||||
|
INSIST(RESQUERY_SENDING(query));
|
||||||
|
|
||||||
|
query->sends--;
|
||||||
|
|
||||||
fctx = query->fctx;
|
fctx = query->fctx;
|
||||||
|
|
||||||
if (RESQUERY_CANCELED(query)) {
|
if (RESQUERY_CANCELED(query)) {
|
||||||
@ -1810,7 +1820,7 @@ process_sendevent(resquery_t *query, isc_event_t *event) {
|
|||||||
destroy_query = true;
|
destroy_query = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (sevent->result) {
|
switch (eresult) {
|
||||||
case ISC_R_SUCCESS:
|
case ISC_R_SUCCESS:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1819,94 +1829,44 @@ process_sendevent(resquery_t *query, isc_event_t *event) {
|
|||||||
case ISC_R_NOPERM:
|
case ISC_R_NOPERM:
|
||||||
case ISC_R_ADDRNOTAVAIL:
|
case ISC_R_ADDRNOTAVAIL:
|
||||||
case ISC_R_CONNREFUSED:
|
case ISC_R_CONNREFUSED:
|
||||||
FCTXTRACE3("query canceled in sendevent(): "
|
FCTXTRACE3("query canceled in resquery_senddone(): "
|
||||||
"no route to host; no response",
|
"no route to host; no response",
|
||||||
sevent->result);
|
eresult);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No route to remote.
|
* No route to remote.
|
||||||
*/
|
*/
|
||||||
add_bad(fctx, query->rmessage, query->addrinfo,
|
add_bad(fctx, query->rmessage, query->addrinfo, eresult,
|
||||||
sevent->result, badns_unreachable);
|
badns_unreachable);
|
||||||
fctx_cancelquery(&query, NULL, NULL, true, false);
|
fctx_cancelquery(&query, NULL, NULL, true, false);
|
||||||
retry = true;
|
|
||||||
|
/*
|
||||||
|
* Behave as if the idle timer has expired. For TCP
|
||||||
|
* this may not actually reflect the latest timer.
|
||||||
|
*/
|
||||||
|
FCTX_ATTR_CLR(fctx, FCTX_ATTR_ADDRWAIT);
|
||||||
|
result = fctx_stopidletimer(fctx);
|
||||||
|
if (result != ISC_R_SUCCESS) {
|
||||||
|
fctx_done(fctx, result, __LINE__);
|
||||||
|
} else {
|
||||||
|
fctx_try(fctx, true, false);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
FCTXTRACE3("query canceled in sendevent() due to "
|
FCTXTRACE3("query canceled in resquery_senddone() "
|
||||||
"unexpected event result; responding",
|
"due to unexpected result; responding",
|
||||||
sevent->result);
|
eresult);
|
||||||
|
|
||||||
fctx_cancelquery(&query, NULL, NULL, false, false);
|
fctx_cancelquery(&query, NULL, NULL, false, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->ev_type == ISC_SOCKEVENT_CONNECT) {
|
|
||||||
isc_event_free(&event);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retry) {
|
|
||||||
/*
|
|
||||||
* Behave as if the idle timer has expired. For TCP
|
|
||||||
* this may not actually reflect the latest timer.
|
|
||||||
*/
|
|
||||||
FCTX_ATTR_CLR(fctx, FCTX_ATTR_ADDRWAIT);
|
|
||||||
result = fctx_stopidletimer(fctx);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
fctx_done(fctx, result, __LINE__);
|
|
||||||
} else {
|
|
||||||
fctx_try(fctx, true, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (destroy_query) {
|
if (destroy_query) {
|
||||||
resquery_destroy(&query);
|
resquery_destroy(&query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
resquery_udpconnected(isc_task_t *task, isc_event_t *event) {
|
|
||||||
resquery_t *query = event->ev_arg;
|
|
||||||
|
|
||||||
REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
|
|
||||||
|
|
||||||
QTRACE("udpconnected");
|
|
||||||
|
|
||||||
UNUSED(task);
|
|
||||||
|
|
||||||
INSIST(RESQUERY_CONNECTING(query));
|
|
||||||
|
|
||||||
query->connects--;
|
|
||||||
|
|
||||||
process_sendevent(query, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
resquery_senddone(isc_task_t *task, isc_event_t *event) {
|
|
||||||
resquery_t *query = event->ev_arg;
|
|
||||||
|
|
||||||
REQUIRE(event->ev_type == ISC_SOCKEVENT_SENDDONE);
|
|
||||||
|
|
||||||
QTRACE("senddone");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* XXXRTH
|
|
||||||
*
|
|
||||||
* Currently we don't wait for the senddone event before retrying
|
|
||||||
* a query. This means that if we get really behind, we may end
|
|
||||||
* up doing extra work!
|
|
||||||
*/
|
|
||||||
|
|
||||||
UNUSED(task);
|
|
||||||
|
|
||||||
INSIST(RESQUERY_SENDING(query));
|
|
||||||
|
|
||||||
query->sends--;
|
|
||||||
|
|
||||||
process_sendevent(query, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline isc_result_t
|
static inline isc_result_t
|
||||||
fctx_addopt(dns_message_t *message, unsigned int version, uint16_t udpsize,
|
fctx_addopt(dns_message_t *message, unsigned int version, uint16_t udpsize,
|
||||||
dns_ednsopt_t *ednsopts, size_t count) {
|
dns_ednsopt_t *ednsopts, size_t count) {
|
||||||
@ -1972,15 +1932,14 @@ fctx_setretryinterval(fetchctx_t *fctx, unsigned int rtt) {
|
|||||||
static isc_result_t
|
static isc_result_t
|
||||||
fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
|
fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
|
||||||
unsigned int options) {
|
unsigned int options) {
|
||||||
|
isc_result_t result;
|
||||||
dns_resolver_t *res = NULL;
|
dns_resolver_t *res = NULL;
|
||||||
isc_task_t *task = NULL;
|
isc_task_t *task = NULL;
|
||||||
isc_result_t result;
|
|
||||||
resquery_t *query = NULL;
|
resquery_t *query = NULL;
|
||||||
isc_sockaddr_t addr;
|
isc_sockaddr_t addr;
|
||||||
bool have_addr = false;
|
bool have_addr = false;
|
||||||
unsigned int srtt;
|
unsigned int srtt;
|
||||||
isc_dscp_t dscp = -1;
|
isc_dscp_t dscp = -1;
|
||||||
unsigned int bucketnum;
|
|
||||||
|
|
||||||
FCTXTRACE("query");
|
FCTXTRACE("query");
|
||||||
|
|
||||||
@ -2088,9 +2047,9 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
|
|||||||
query->dscp = dscp;
|
query->dscp = dscp;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatch_createtcp(
|
result = dns_dispatch_createtcp(res->dispatchmgr, res->taskmgr,
|
||||||
res->dispatchmgr, res->socketmgr, res->taskmgr, &addr,
|
&addr, &addrinfo->sockaddr, 0,
|
||||||
&addrinfo->sockaddr, 0, query->dscp, &query->dispatch);
|
query->dscp, &query->dispatch);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup_query;
|
goto cleanup_query;
|
||||||
}
|
}
|
||||||
@ -2107,9 +2066,9 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
|
|||||||
result = ISC_R_NOTIMPLEMENTED;
|
result = ISC_R_NOTIMPLEMENTED;
|
||||||
goto cleanup_query;
|
goto cleanup_query;
|
||||||
}
|
}
|
||||||
result = dns_dispatch_createudp(
|
result = dns_dispatch_createudp(res->dispatchmgr,
|
||||||
res->dispatchmgr, res->socketmgr, res->taskmgr,
|
res->taskmgr, &addr, 0,
|
||||||
&addr, 0, &query->dispatch);
|
&query->dispatch);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup_query;
|
goto cleanup_query;
|
||||||
}
|
}
|
||||||
@ -2150,49 +2109,34 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
|
|||||||
ISC_LINK_INIT(query, link);
|
ISC_LINK_INIT(query, link);
|
||||||
query->magic = QUERY_MAGIC;
|
query->magic = QUERY_MAGIC;
|
||||||
|
|
||||||
if ((query->options & DNS_FETCHOPT_TCP) != 0) {
|
if ((query->options & DNS_FETCHOPT_TCP) == 0) {
|
||||||
/*
|
|
||||||
* Connect to the remote server.
|
|
||||||
*/
|
|
||||||
result = dns_dispatch_connect(query->dispatch, NULL, task,
|
|
||||||
resquery_connected, query);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto cleanup_dispatch;
|
|
||||||
}
|
|
||||||
query->connects++;
|
|
||||||
QTRACE("connecting via TCP");
|
|
||||||
} else {
|
|
||||||
if (dns_adbentry_overquota(addrinfo->entry)) {
|
if (dns_adbentry_overquota(addrinfo->entry)) {
|
||||||
goto cleanup_dispatch;
|
goto cleanup_dispatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Inform the ADB that we're starting a UDP fetch */
|
/* Inform the ADB that we're starting a UDP fetch */
|
||||||
dns_adb_beginudpfetch(fctx->adb, addrinfo);
|
dns_adb_beginudpfetch(fctx->adb, addrinfo);
|
||||||
|
|
||||||
result = resquery_send(query);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto cleanup_dispatch;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fctx->querysent++;
|
LOCK(&res->buckets[fctx->bucketnum].lock);
|
||||||
|
|
||||||
ISC_LIST_APPEND(fctx->queries, query, link);
|
|
||||||
bucketnum = fctx->bucketnum;
|
|
||||||
LOCK(&res->buckets[bucketnum].lock);
|
|
||||||
fctx->nqueries++;
|
fctx->nqueries++;
|
||||||
UNLOCK(&res->buckets[bucketnum].lock);
|
UNLOCK(&res->buckets[fctx->bucketnum].lock);
|
||||||
if (isc_sockaddr_pf(&addrinfo->sockaddr) == PF_INET) {
|
|
||||||
inc_stats(res, dns_resstatscounter_queryv4);
|
/* Set up the dispatch and set the query ID */
|
||||||
} else {
|
/* XXX: timeout hard-coded to 10 seconds */
|
||||||
inc_stats(res, dns_resstatscounter_queryv6);
|
result = dns_dispatch_addresponse(
|
||||||
}
|
query->dispatch, 0, 10000, &query->addrinfo->sockaddr, task,
|
||||||
if (res->view->resquerystats != NULL) {
|
resquery_connected, resquery_senddone, resquery_response, NULL,
|
||||||
dns_rdatatypestats_increment(res->view->resquerystats,
|
query, &query->id, &query->dispentry);
|
||||||
fctx->type);
|
if (result != ISC_R_SUCCESS) {
|
||||||
|
goto cleanup_dispatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
/* Connect the socket */
|
||||||
|
query->connects++;
|
||||||
|
fctx_increference(fctx);
|
||||||
|
result = dns_dispatch_connect(query->dispentry);
|
||||||
|
return (result);
|
||||||
|
|
||||||
cleanup_dispatch:
|
cleanup_dispatch:
|
||||||
if (query->dispatch != NULL) {
|
if (query->dispatch != NULL) {
|
||||||
@ -2349,21 +2293,19 @@ issecuredomain(dns_view_t *view, const dns_name_t *name, dns_rdatatype_t type,
|
|||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
resquery_send(resquery_t *query) {
|
resquery_send(resquery_t *query) {
|
||||||
fetchctx_t *fctx = NULL;
|
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
|
fetchctx_t *fctx = query->fctx;
|
||||||
|
dns_resolver_t *res = fctx->res;
|
||||||
|
isc_buffer_t buffer;
|
||||||
dns_name_t *qname = NULL;
|
dns_name_t *qname = NULL;
|
||||||
dns_rdataset_t *qrdataset = NULL;
|
dns_rdataset_t *qrdataset = NULL;
|
||||||
isc_region_t r;
|
isc_region_t r;
|
||||||
dns_resolver_t *res = NULL;
|
|
||||||
isc_task_t *task = NULL;
|
|
||||||
isc_buffer_t tcpbuffer;
|
|
||||||
isc_buffer_t *buffer = NULL;
|
|
||||||
isc_netaddr_t ipaddr;
|
isc_netaddr_t ipaddr;
|
||||||
dns_tsigkey_t *tsigkey = NULL;
|
dns_tsigkey_t *tsigkey = NULL;
|
||||||
dns_peer_t *peer = NULL;
|
dns_peer_t *peer = NULL;
|
||||||
bool useedns;
|
|
||||||
dns_compress_t cctx;
|
dns_compress_t cctx;
|
||||||
bool cleanup_cctx = false;
|
bool cleanup_cctx = false;
|
||||||
|
bool useedns;
|
||||||
bool secure_domain;
|
bool secure_domain;
|
||||||
bool tcp = ((query->options & DNS_FETCHOPT_TCP) != 0);
|
bool tcp = ((query->options & DNS_FETCHOPT_TCP) != 0);
|
||||||
dns_ednsopt_t ednsopts[DNS_EDNSOPTIONS];
|
dns_ednsopt_t ednsopts[DNS_EDNSOPTIONS];
|
||||||
@ -2377,24 +2319,11 @@ resquery_send(resquery_t *query) {
|
|||||||
isc_buffer_t zb;
|
isc_buffer_t zb;
|
||||||
#endif /* HAVE_DNSTAP */
|
#endif /* HAVE_DNSTAP */
|
||||||
|
|
||||||
fctx = query->fctx;
|
|
||||||
QTRACE("send");
|
QTRACE("send");
|
||||||
|
|
||||||
res = fctx->res;
|
if (atomic_load_acquire(&res->exiting)) {
|
||||||
task = res->buckets[fctx->bucketnum].task;
|
FCTXTRACE("resquery_send: resolver shutting down");
|
||||||
|
return (ISC_R_SHUTTINGDOWN);
|
||||||
if (tcp) {
|
|
||||||
/*
|
|
||||||
* Reserve space for the TCP message length.
|
|
||||||
*/
|
|
||||||
isc_buffer_init(&tcpbuffer, query->data, sizeof(query->data));
|
|
||||||
isc_buffer_init(&query->buffer, query->data + 2,
|
|
||||||
sizeof(query->data) - 2);
|
|
||||||
buffer = &tcpbuffer;
|
|
||||||
} else {
|
|
||||||
isc_buffer_init(&query->buffer, query->data,
|
|
||||||
sizeof(query->data));
|
|
||||||
buffer = &query->buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_message_gettempname(fctx->qmessage, &qname);
|
result = dns_message_gettempname(fctx->qmessage, &qname);
|
||||||
@ -2406,17 +2335,6 @@ resquery_send(resquery_t *query) {
|
|||||||
goto cleanup_temps;
|
goto cleanup_temps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Get a query id from the dispatch.
|
|
||||||
*/
|
|
||||||
result = dns_dispatch_addresponse(query->dispatch, 0,
|
|
||||||
&query->addrinfo->sockaddr, task,
|
|
||||||
resquery_response, query, &query->id,
|
|
||||||
&query->dispentry, res->socketmgr);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto cleanup_temps;
|
|
||||||
}
|
|
||||||
|
|
||||||
fctx->qmessage->opcode = dns_opcode_query;
|
fctx->qmessage->opcode = dns_opcode_query;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2479,7 +2397,8 @@ resquery_send(resquery_t *query) {
|
|||||||
}
|
}
|
||||||
cleanup_cctx = true;
|
cleanup_cctx = true;
|
||||||
|
|
||||||
result = dns_message_renderbegin(fctx->qmessage, &cctx, &query->buffer);
|
isc_buffer_init(&buffer, query->data, sizeof(query->data));
|
||||||
|
result = dns_message_renderbegin(fctx->qmessage, &cctx, &buffer);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
goto cleanup_message;
|
goto cleanup_message;
|
||||||
}
|
}
|
||||||
@ -2490,7 +2409,6 @@ resquery_send(resquery_t *query) {
|
|||||||
goto cleanup_message;
|
goto cleanup_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
peer = NULL;
|
|
||||||
isc_netaddr_fromsockaddr(&ipaddr, &query->addrinfo->sockaddr);
|
isc_netaddr_fromsockaddr(&ipaddr, &query->addrinfo->sockaddr);
|
||||||
(void)dns_peerlist_peerbyaddr(fctx->res->view->peers, &ipaddr, &peer);
|
(void)dns_peerlist_peerbyaddr(fctx->res->view->peers, &ipaddr, &peer);
|
||||||
|
|
||||||
@ -2757,16 +2675,6 @@ resquery_send(resquery_t *query) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* If using TCP, write the length of the message at the beginning
|
|
||||||
* of the buffer.
|
|
||||||
*/
|
|
||||||
if (tcp) {
|
|
||||||
isc_buffer_usedregion(&query->buffer, &r);
|
|
||||||
isc_buffer_putuint16(&tcpbuffer, (uint16_t)r.length);
|
|
||||||
isc_buffer_add(&tcpbuffer, r.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Log the outgoing packet.
|
* Log the outgoing packet.
|
||||||
*/
|
*/
|
||||||
@ -2780,23 +2688,9 @@ resquery_send(resquery_t *query) {
|
|||||||
*/
|
*/
|
||||||
dns_message_reset(fctx->qmessage, DNS_MESSAGE_INTENTRENDER);
|
dns_message_reset(fctx->qmessage, DNS_MESSAGE_INTENTRENDER);
|
||||||
|
|
||||||
if (!tcp) {
|
isc_buffer_usedregion(&buffer, &r);
|
||||||
/* Connect the UDP socket */
|
|
||||||
result = dns_dispatch_connect(NULL, query->dispentry, task,
|
|
||||||
resquery_udpconnected, query);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
goto cleanup_message;
|
|
||||||
}
|
|
||||||
query->connects++;
|
|
||||||
}
|
|
||||||
|
|
||||||
isc_buffer_usedregion(buffer, &r);
|
dns_dispatch_send(query->dispentry, &r, query->dscp);
|
||||||
|
|
||||||
result = dns_dispatch_send(query->dispentry, tcp, task,
|
|
||||||
&query->sendevent, &r,
|
|
||||||
&query->addrinfo->sockaddr, query->dscp,
|
|
||||||
resquery_senddone, query);
|
|
||||||
INSIST(result == ISC_R_SUCCESS);
|
|
||||||
query->sends++;
|
query->sends++;
|
||||||
|
|
||||||
QTRACE("sent");
|
QTRACE("sent");
|
||||||
@ -2817,7 +2711,7 @@ resquery_send(resquery_t *query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dns_dt_send(fctx->res->view, dtmsgtype, la, &query->addrinfo->sockaddr,
|
dns_dt_send(fctx->res->view, dtmsgtype, la, &query->addrinfo->sockaddr,
|
||||||
tcp, &zr, &query->start, NULL, &query->buffer);
|
tcp, &zr, &query->start, NULL, &buffer);
|
||||||
#endif /* HAVE_DNSTAP */
|
#endif /* HAVE_DNSTAP */
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
@ -2846,40 +2740,40 @@ cleanup_temps:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resquery_connected(isc_task_t *task, isc_event_t *event) {
|
resquery_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
|
||||||
isc_socketevent_t *sevent = (isc_socketevent_t *)event;
|
resquery_t *query = (resquery_t *)arg;
|
||||||
resquery_t *query = event->ev_arg;
|
|
||||||
bool retry = false;
|
|
||||||
isc_interval_t interval;
|
isc_interval_t interval;
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
fetchctx_t *fctx;
|
fetchctx_t *fctx = NULL;
|
||||||
|
dns_resolver_t *res = NULL;
|
||||||
|
unsigned int bucketnum;
|
||||||
|
bool bucket_empty;
|
||||||
|
int pf;
|
||||||
|
|
||||||
REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
|
|
||||||
REQUIRE(VALID_QUERY(query));
|
REQUIRE(VALID_QUERY(query));
|
||||||
|
|
||||||
QTRACE("connected");
|
QTRACE("connected");
|
||||||
|
|
||||||
UNUSED(task);
|
UNUSED(handle);
|
||||||
|
|
||||||
/*
|
|
||||||
* XXXRTH
|
|
||||||
*
|
|
||||||
* Currently we don't wait for the connect event before retrying
|
|
||||||
* a query. This means that if we get really behind, we may end
|
|
||||||
* up doing extra work!
|
|
||||||
*/
|
|
||||||
|
|
||||||
query->connects--;
|
query->connects--;
|
||||||
fctx = query->fctx;
|
fctx = query->fctx;
|
||||||
|
res = fctx->res;
|
||||||
|
|
||||||
|
bucketnum = fctx->bucketnum;
|
||||||
|
|
||||||
|
if (atomic_load_acquire(&res->exiting)) {
|
||||||
|
eresult = ISC_R_SHUTTINGDOWN;
|
||||||
|
}
|
||||||
|
|
||||||
if (RESQUERY_CANCELED(query)) {
|
if (RESQUERY_CANCELED(query)) {
|
||||||
/*
|
/*
|
||||||
* This query was canceled while the connect() was in
|
* This query was canceled while the connect() was
|
||||||
* progress.
|
* in progress.
|
||||||
*/
|
*/
|
||||||
resquery_destroy(&query);
|
resquery_destroy(&query);
|
||||||
} else {
|
} else {
|
||||||
switch (sevent->result) {
|
switch (eresult) {
|
||||||
case ISC_R_SUCCESS:
|
case ISC_R_SUCCESS:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2890,8 +2784,7 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
|
|||||||
* received.
|
* received.
|
||||||
*/
|
*/
|
||||||
isc_interval_set(&interval,
|
isc_interval_set(&interval,
|
||||||
fctx->res->query_timeout / 1000 / 2,
|
res->query_timeout / 1000 / 2, 0);
|
||||||
0);
|
|
||||||
result = fctx_startidletimer(query->fctx, &interval);
|
result = fctx_startidletimer(query->fctx, &interval);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
FCTXTRACE("query canceled: idle timer failed; "
|
FCTXTRACE("query canceled: idle timer failed; "
|
||||||
@ -2904,7 +2797,7 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We are connected. Update the dispatcher and
|
* We are connected. Update the dispatcher and
|
||||||
* send the query.
|
* send the query.
|
||||||
*/
|
*/
|
||||||
dns_dispatch_changeattributes(
|
dns_dispatch_changeattributes(
|
||||||
@ -2920,6 +2813,20 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
|
|||||||
false);
|
false);
|
||||||
fctx_done(fctx, result, __LINE__);
|
fctx_done(fctx, result, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fctx->querysent++;
|
||||||
|
|
||||||
|
ISC_LIST_APPEND(fctx->queries, query, link);
|
||||||
|
pf = isc_sockaddr_pf(&query->addrinfo->sockaddr);
|
||||||
|
if (pf == PF_INET) {
|
||||||
|
inc_stats(res, dns_resstatscounter_queryv4);
|
||||||
|
} else {
|
||||||
|
inc_stats(res, dns_resstatscounter_queryv6);
|
||||||
|
}
|
||||||
|
if (res->view->resquerystats != NULL) {
|
||||||
|
dns_rdatatypestats_increment(
|
||||||
|
res->view->resquerystats, fctx->type);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ISC_R_NETUNREACH:
|
case ISC_R_NETUNREACH:
|
||||||
@ -2928,45 +2835,46 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
|
|||||||
case ISC_R_NOPERM:
|
case ISC_R_NOPERM:
|
||||||
case ISC_R_ADDRNOTAVAIL:
|
case ISC_R_ADDRNOTAVAIL:
|
||||||
case ISC_R_CONNECTIONRESET:
|
case ISC_R_CONNECTIONRESET:
|
||||||
FCTXTRACE3("query canceled in connected(): "
|
FCTXTRACE3("query canceled in resquery_connected(): "
|
||||||
"no route to host; no response",
|
"no route to host; no response",
|
||||||
sevent->result);
|
eresult);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do not query this server again in this fetch context
|
* Do not query this server again in this fetch context
|
||||||
* if the server is unavailable over TCP.
|
* if the server is unavailable over TCP.
|
||||||
*/
|
*/
|
||||||
add_bad(fctx, query->rmessage, query->addrinfo,
|
add_bad(fctx, query->rmessage, query->addrinfo, eresult,
|
||||||
sevent->result, badns_unreachable);
|
badns_unreachable);
|
||||||
fctx_cancelquery(&query, NULL, NULL, true, false);
|
fctx_cancelquery(&query, NULL, NULL, true, false);
|
||||||
retry = true;
|
|
||||||
|
/*
|
||||||
|
* Behave as if the idle timer has expired. For
|
||||||
|
* TCP connections this may not actually reflect
|
||||||
|
* the latest timer.
|
||||||
|
*/
|
||||||
|
FCTX_ATTR_CLR(fctx, FCTX_ATTR_ADDRWAIT);
|
||||||
|
result = fctx_stopidletimer(fctx);
|
||||||
|
if (result != ISC_R_SUCCESS) {
|
||||||
|
fctx_done(fctx, result, __LINE__);
|
||||||
|
} else {
|
||||||
|
fctx_try(fctx, true, false);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
FCTXTRACE3("query canceled in connected() due to "
|
FCTXTRACE3("query canceled in resquery_connected() "
|
||||||
"unexpected event result; responding",
|
"due to unexpected result; responding",
|
||||||
sevent->result);
|
eresult);
|
||||||
|
|
||||||
dns_dispatch_detach(&query->dispatch);
|
|
||||||
fctx_cancelquery(&query, NULL, NULL, false, false);
|
fctx_cancelquery(&query, NULL, NULL, false, false);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_event_free(&event);
|
LOCK(&res->buckets[bucketnum].lock);
|
||||||
|
bucket_empty = fctx_decreference(fctx);
|
||||||
if (retry) {
|
UNLOCK(&res->buckets[bucketnum].lock);
|
||||||
/*
|
if (bucket_empty) {
|
||||||
* Behave as if the idle timer has expired. For TCP
|
empty_bucket(res);
|
||||||
* connections this may not actually reflect the latest timer.
|
|
||||||
*/
|
|
||||||
FCTX_ATTR_CLR(fctx, FCTX_ATTR_ADDRWAIT);
|
|
||||||
result = fctx_stopidletimer(fctx);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
fctx_done(fctx, result, __LINE__);
|
|
||||||
} else {
|
|
||||||
fctx_try(fctx, true, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4140,7 +4048,6 @@ fctx_try(fetchctx_t *fctx, bool retrying, bool badcache) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fctx_increference(fctx);
|
fctx_increference(fctx);
|
||||||
|
|
||||||
result = fctx_query(fctx, addrinfo, fctx->options);
|
result = fctx_query(fctx, addrinfo, fctx->options);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
fctx_done(fctx, result, __LINE__);
|
fctx_done(fctx, result, __LINE__);
|
||||||
@ -5033,8 +4940,8 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type,
|
|||||||
(res->query_timeout - 1000));
|
(res->query_timeout - 1000));
|
||||||
/*
|
/*
|
||||||
* Compute an expiration time after which stale data will
|
* Compute an expiration time after which stale data will
|
||||||
* attempted to be served, if stale answers are enabled and
|
* be served, if stale answers are enabled and target RRset is
|
||||||
* target RRset is available in cache.
|
* available in cache.
|
||||||
*/
|
*/
|
||||||
isc_interval_set(
|
isc_interval_set(
|
||||||
&interval, res->view->staleanswerclienttimeout / 1000,
|
&interval, res->view->staleanswerclienttimeout / 1000,
|
||||||
@ -7521,6 +7428,7 @@ resquery_response(isc_task_t *task, isc_event_t *event) {
|
|||||||
if (atomic_load_acquire(&fctx->res->exiting)) {
|
if (atomic_load_acquire(&fctx->res->exiting)) {
|
||||||
result = ISC_R_SHUTTINGDOWN;
|
result = ISC_R_SHUTTINGDOWN;
|
||||||
FCTXTRACE("resolver shutting down");
|
FCTXTRACE("resolver shutting down");
|
||||||
|
rctx.finish = NULL;
|
||||||
rctx_done(&rctx, result);
|
rctx_done(&rctx, result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -9689,13 +9597,13 @@ rctx_done(respctx_t *rctx, isc_result_t result) {
|
|||||||
/*
|
/*
|
||||||
* Need to attach to the message until the scope
|
* Need to attach to the message until the scope
|
||||||
* of this function ends, since there are many places
|
* of this function ends, since there are many places
|
||||||
* where te message is used and/or may be destroyed
|
* where the message is used and/or may be destroyed
|
||||||
* before this function ends.
|
* before this function ends.
|
||||||
*/
|
*/
|
||||||
dns_message_t *message = NULL;
|
dns_message_t *message = NULL;
|
||||||
dns_message_attach(query->rmessage, &message);
|
dns_message_attach(query->rmessage, &message);
|
||||||
|
|
||||||
FCTXTRACE4("query canceled in response(); ",
|
FCTXTRACE4("query canceled in rctx_done(); ",
|
||||||
rctx->no_response ? "no response" : "responding", result);
|
rctx->no_response ? "no response" : "responding", result);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -10128,11 +10036,10 @@ spillattimer_countdown(isc_task_t *task, isc_event_t *event) {
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||||
unsigned int ntasks, unsigned int ndisp,
|
unsigned int ntasks, unsigned int ndisp, isc_nm_t *nm,
|
||||||
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
|
isc_timermgr_t *timermgr, unsigned int options,
|
||||||
unsigned int options, dns_dispatchmgr_t *dispatchmgr,
|
dns_dispatchmgr_t *dispatchmgr, dns_dispatch_t *dispatchv4,
|
||||||
dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
|
dns_dispatch_t *dispatchv6, dns_resolver_t **resp) {
|
||||||
dns_resolver_t **resp) {
|
|
||||||
dns_resolver_t *res = NULL;
|
dns_resolver_t *res = NULL;
|
||||||
isc_result_t result = ISC_R_SUCCESS;
|
isc_result_t result = ISC_R_SUCCESS;
|
||||||
unsigned int i, buckets_created = 0, dbuckets_created = 0;
|
unsigned int i, buckets_created = 0, dbuckets_created = 0;
|
||||||
@ -10154,7 +10061,7 @@ dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
|||||||
res = isc_mem_get(view->mctx, sizeof(*res));
|
res = isc_mem_get(view->mctx, sizeof(*res));
|
||||||
*res = (dns_resolver_t){ .mctx = view->mctx,
|
*res = (dns_resolver_t){ .mctx = view->mctx,
|
||||||
.rdclass = view->rdclass,
|
.rdclass = view->rdclass,
|
||||||
.socketmgr = socketmgr,
|
.nm = nm,
|
||||||
.timermgr = timermgr,
|
.timermgr = timermgr,
|
||||||
.taskmgr = taskmgr,
|
.taskmgr = taskmgr,
|
||||||
.dispatchmgr = dispatchmgr,
|
.dispatchmgr = dispatchmgr,
|
||||||
@ -10230,13 +10137,13 @@ dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dispatchv4 != NULL) {
|
if (dispatchv4 != NULL) {
|
||||||
dns_dispatchset_create(view->mctx, socketmgr, taskmgr,
|
dns_dispatchset_create(view->mctx, taskmgr, dispatchv4,
|
||||||
dispatchv4, &res->dispatches4, ndisp);
|
&res->dispatches4, ndisp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dispatchv6 != NULL) {
|
if (dispatchv6 != NULL) {
|
||||||
dns_dispatchset_create(view->mctx, socketmgr, taskmgr,
|
dns_dispatchset_create(view->mctx, taskmgr, dispatchv6,
|
||||||
dispatchv6, &res->dispatches6, ndisp);
|
&res->dispatches6, ndisp);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_mutex_init(&res->lock);
|
isc_mutex_init(&res->lock);
|
||||||
@ -10951,12 +10858,6 @@ dns_resolver_dispatchv6(dns_resolver_t *resolver) {
|
|||||||
return (dns_dispatchset_get(resolver->dispatches6));
|
return (dns_dispatchset_get(resolver->dispatches6));
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_socketmgr_t *
|
|
||||||
dns_resolver_socketmgr(dns_resolver_t *resolver) {
|
|
||||||
REQUIRE(VALID_RESOLVER(resolver));
|
|
||||||
return (resolver->socketmgr);
|
|
||||||
}
|
|
||||||
|
|
||||||
isc_taskmgr_t *
|
isc_taskmgr_t *
|
||||||
dns_resolver_taskmgr(dns_resolver_t *resolver) {
|
dns_resolver_taskmgr(dns_resolver_t *resolver) {
|
||||||
REQUIRE(VALID_RESOLVER(resolver));
|
REQUIRE(VALID_RESOLVER(resolver));
|
||||||
|
@ -20,16 +20,17 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
#define UNIT_TESTING
|
#define UNIT_TESTING
|
||||||
#include <cmocka.h>
|
#include <cmocka.h>
|
||||||
|
|
||||||
#include <isc/app.h>
|
#include <isc/app.h>
|
||||||
#include <isc/buffer.h>
|
#include <isc/buffer.h>
|
||||||
|
#include <isc/managers.h>
|
||||||
#include <isc/refcount.h>
|
#include <isc/refcount.h>
|
||||||
#include <isc/socket.h>
|
#include <isc/socket.h>
|
||||||
#include <isc/task.h>
|
#include <isc/task.h>
|
||||||
#include <isc/timer.h>
|
|
||||||
#include <isc/util.h>
|
#include <isc/util.h>
|
||||||
|
|
||||||
#include <dns/dispatch.h>
|
#include <dns/dispatch.h>
|
||||||
@ -38,18 +39,91 @@
|
|||||||
|
|
||||||
#include "dnstest.h"
|
#include "dnstest.h"
|
||||||
|
|
||||||
|
/* Timeouts in miliseconds */
|
||||||
|
#define T_INIT 120 * 1000
|
||||||
|
#define T_IDLE 120 * 1000
|
||||||
|
#define T_KEEPALIVE 120 * 1000
|
||||||
|
#define T_ADVERTISED 120 * 1000
|
||||||
|
#define T_CONNECT 30 * 1000
|
||||||
|
|
||||||
dns_dispatchmgr_t *dispatchmgr = NULL;
|
dns_dispatchmgr_t *dispatchmgr = NULL;
|
||||||
dns_dispatchset_t *dset = NULL;
|
dns_dispatchset_t *dset = NULL;
|
||||||
|
isc_nm_t *connect_nm = NULL;
|
||||||
|
static isc_sockaddr_t server_addr;
|
||||||
|
static isc_sockaddr_t connect_addr;
|
||||||
|
|
||||||
|
static int
|
||||||
|
setup_ephemeral_port(isc_sockaddr_t *addr, sa_family_t family) {
|
||||||
|
socklen_t addrlen = sizeof(*addr);
|
||||||
|
uv_os_sock_t fd;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
isc_sockaddr_fromin6(addr, &in6addr_loopback, 0);
|
||||||
|
|
||||||
|
fd = socket(AF_INET6, family, 0);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror("setup_ephemeral_port: socket()");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
r = bind(fd, (const struct sockaddr *)&addr->type.sa,
|
||||||
|
sizeof(addr->type.sin6));
|
||||||
|
if (r != 0) {
|
||||||
|
perror("setup_ephemeral_port: bind()");
|
||||||
|
close(fd);
|
||||||
|
return (r);
|
||||||
|
}
|
||||||
|
|
||||||
|
r = getsockname(fd, (struct sockaddr *)&addr->type.sa, &addrlen);
|
||||||
|
if (r != 0) {
|
||||||
|
perror("setup_ephemeral_port: getsockname()");
|
||||||
|
close(fd);
|
||||||
|
return (r);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if IPV6_RECVERR
|
||||||
|
#define setsockopt_on(socket, level, name) \
|
||||||
|
setsockopt(socket, level, name, &(int){ 1 }, sizeof(int))
|
||||||
|
|
||||||
|
r = setsockopt_on(fd, IPPROTO_IPV6, IPV6_RECVERR);
|
||||||
|
if (r != 0) {
|
||||||
|
perror("setup_ephemeral_port");
|
||||||
|
close(fd);
|
||||||
|
return (r);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_setup(void **state) {
|
_setup(void **state) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
|
uv_os_sock_t sock = -1;
|
||||||
|
|
||||||
UNUSED(state);
|
UNUSED(state);
|
||||||
|
|
||||||
result = dns_test_begin(NULL, true);
|
result = dns_test_begin(NULL, true);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
|
connect_addr = (isc_sockaddr_t){ .length = 0 };
|
||||||
|
isc_sockaddr_fromin6(&connect_addr, &in6addr_loopback, 0);
|
||||||
|
|
||||||
|
server_addr = (isc_sockaddr_t){ .length = 0 };
|
||||||
|
sock = setup_ephemeral_port(&server_addr, SOCK_DGRAM);
|
||||||
|
if (sock < 0) {
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
close(sock);
|
||||||
|
|
||||||
|
/* Create a secondary network manager */
|
||||||
|
isc_managers_create(dt_mctx, ncpus, 0, 0, &connect_nm, NULL, NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
isc_nm_settimeouts(netmgr, T_INIT, T_IDLE, T_KEEPALIVE, T_ADVERTISED);
|
||||||
|
isc_nm_settimeouts(connect_nm, T_INIT, T_IDLE, T_KEEPALIVE,
|
||||||
|
T_ADVERTISED);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +131,9 @@ static int
|
|||||||
_teardown(void **state) {
|
_teardown(void **state) {
|
||||||
UNUSED(state);
|
UNUSED(state);
|
||||||
|
|
||||||
|
isc_managers_destroy(&connect_nm, NULL, NULL, NULL);
|
||||||
|
assert_null(connect_nm);
|
||||||
|
|
||||||
dns_test_end();
|
dns_test_end();
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@ -68,20 +145,18 @@ make_dispatchset(unsigned int ndisps) {
|
|||||||
isc_sockaddr_t any;
|
isc_sockaddr_t any;
|
||||||
dns_dispatch_t *disp = NULL;
|
dns_dispatch_t *disp = NULL;
|
||||||
|
|
||||||
result = dns_dispatchmgr_create(dt_mctx, &dispatchmgr);
|
result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_sockaddr_any(&any);
|
isc_sockaddr_any(&any);
|
||||||
result = dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr, &any,
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr, &any, 0, &disp);
|
||||||
0, &disp);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dns_dispatchset_create(dt_mctx, socketmgr, taskmgr, disp,
|
result = dns_dispatchset_create(dt_mctx, taskmgr, disp, &dset, ndisps);
|
||||||
&dset, ndisps);
|
|
||||||
dns_dispatch_detach(&disp);
|
dns_dispatch_detach(&disp);
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
@ -155,68 +230,57 @@ dispatchset_get(void **state) {
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct {
|
||||||
|
isc_nmhandle_t *handle;
|
||||||
|
atomic_uint_fast32_t responses;
|
||||||
|
} testdata;
|
||||||
|
|
||||||
|
static dns_dispatch_t *dispatch = NULL;
|
||||||
|
static dns_dispentry_t *dispentry = NULL;
|
||||||
|
static atomic_bool first = ATOMIC_VAR_INIT(true);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
senddone(isc_task_t *task, isc_event_t *event) {
|
server_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||||
isc_socket_t *sock = event->ev_arg;
|
UNUSED(handle);
|
||||||
|
UNUSED(eresult);
|
||||||
|
UNUSED(cbarg);
|
||||||
|
|
||||||
UNUSED(task);
|
return;
|
||||||
|
|
||||||
isc_socket_detach(&sock);
|
|
||||||
isc_event_free(&event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nameserver(isc_task_t *task, isc_event_t *event) {
|
nameserver(isc_nmhandle_t *handle, isc_result_t eresult, isc_region_t *region,
|
||||||
isc_result_t result;
|
void *cbarg) {
|
||||||
isc_region_t region;
|
isc_region_t response;
|
||||||
isc_socket_t *dummy;
|
|
||||||
isc_socket_t *sock = event->ev_arg;
|
|
||||||
isc_socketevent_t *ev = (isc_socketevent_t *)event;
|
|
||||||
static unsigned char buf1[16];
|
static unsigned char buf1[16];
|
||||||
static unsigned char buf2[16];
|
static unsigned char buf2[16];
|
||||||
|
|
||||||
memmove(buf1, ev->region.base, 12);
|
UNUSED(eresult);
|
||||||
|
UNUSED(cbarg);
|
||||||
|
|
||||||
|
memmove(buf1, region->base, 12);
|
||||||
memset(buf1 + 12, 0, 4);
|
memset(buf1 + 12, 0, 4);
|
||||||
buf1[2] |= 0x80; /* qr=1 */
|
buf1[2] |= 0x80; /* qr=1 */
|
||||||
|
|
||||||
memmove(buf2, ev->region.base, 12);
|
memmove(buf2, region->base, 12);
|
||||||
memset(buf2 + 12, 1, 4);
|
memset(buf2 + 12, 1, 4);
|
||||||
buf2[2] |= 0x80; /* qr=1 */
|
buf2[2] |= 0x80; /* qr=1 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* send message to be discarded.
|
* send message to be discarded.
|
||||||
*/
|
*/
|
||||||
region.base = buf1;
|
response.base = buf1;
|
||||||
region.length = sizeof(buf1);
|
response.length = sizeof(buf1);
|
||||||
dummy = NULL;
|
isc_nm_send(handle, &response, server_senddone, NULL);
|
||||||
isc_socket_attach(sock, &dummy);
|
|
||||||
result = isc_socket_sendto(sock, ®ion, task, senddone, sock,
|
|
||||||
&ev->address, NULL);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
isc_socket_detach(&dummy);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* send nextitem message.
|
* send nextitem message.
|
||||||
*/
|
*/
|
||||||
region.base = buf2;
|
response.base = buf2;
|
||||||
region.length = sizeof(buf2);
|
response.length = sizeof(buf2);
|
||||||
dummy = NULL;
|
isc_nm_send(handle, &response, server_senddone, NULL);
|
||||||
isc_socket_attach(sock, &dummy);
|
|
||||||
result = isc_socket_sendto(sock, ®ion, task, senddone, sock,
|
|
||||||
&ev->address, NULL);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
|
||||||
isc_socket_detach(&dummy);
|
|
||||||
}
|
|
||||||
isc_event_free(&event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static dns_dispatch_t *dispatch = NULL;
|
|
||||||
static dns_dispentry_t *dispentry = NULL;
|
|
||||||
static atomic_bool first = ATOMIC_VAR_INIT(true);
|
|
||||||
static isc_sockaddr_t local;
|
|
||||||
static atomic_uint_fast32_t responses;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
response(isc_task_t *task, isc_event_t *event) {
|
response(isc_task_t *task, isc_event_t *event) {
|
||||||
dns_dispatchevent_t *devent = (dns_dispatchevent_t *)event;
|
dns_dispatchevent_t *devent = (dns_dispatchevent_t *)event;
|
||||||
@ -224,78 +288,81 @@ response(isc_task_t *task, isc_event_t *event) {
|
|||||||
|
|
||||||
UNUSED(task);
|
UNUSED(task);
|
||||||
|
|
||||||
atomic_fetch_add_relaxed(&responses, 1);
|
atomic_fetch_add_relaxed(&testdata.responses, 1);
|
||||||
if (atomic_compare_exchange_strong(&first, &exp_true, false)) {
|
if (atomic_compare_exchange_strong(&first, &exp_true, false)) {
|
||||||
isc_result_t result = dns_dispatch_getnext(dispentry, &devent);
|
isc_result_t result = dns_dispatch_getnext(dispentry, &devent);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
dns_dispatch_removeresponse(&dispentry, &devent);
|
dns_dispatch_removeresponse(&dispentry, &devent);
|
||||||
|
isc_nmhandle_detach(&testdata.handle);
|
||||||
isc_app_shutdown();
|
isc_app_shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
startit(isc_task_t *task, isc_event_t *event) {
|
connected(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||||
isc_result_t result;
|
isc_region_t *r = (isc_region_t *)cbarg;
|
||||||
isc_socket_t *sock = NULL;
|
|
||||||
|
|
||||||
isc_socket_attach(dns_dispatch_getentrysocket(dispentry), &sock);
|
UNUSED(eresult);
|
||||||
result = isc_socket_sendto(sock, event->ev_arg, task, senddone, sock,
|
|
||||||
&local, NULL);
|
isc_nmhandle_attach(handle, &testdata.handle);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
dns_dispatch_send(dispentry, r, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
client_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||||
|
UNUSED(handle);
|
||||||
|
UNUSED(eresult);
|
||||||
|
UNUSED(cbarg);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
startit(isc_task_t *task, isc_event_t *event) {
|
||||||
|
UNUSED(task);
|
||||||
|
dns_dispatch_connect(dispentry);
|
||||||
isc_event_free(&event);
|
isc_event_free(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test dispatch getnext */
|
/* test dispatch getnext */
|
||||||
static void
|
static void
|
||||||
dispatch_getnext(void **state) {
|
dispatch_getnext(void **state) {
|
||||||
isc_region_t region;
|
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
isc_socket_t *sock = NULL;
|
isc_region_t region;
|
||||||
|
isc_nmsocket_t *sock = NULL;
|
||||||
isc_task_t *task = NULL;
|
isc_task_t *task = NULL;
|
||||||
uint16_t id;
|
|
||||||
struct in_addr ina;
|
|
||||||
unsigned char message[12];
|
unsigned char message[12];
|
||||||
unsigned char rbuf[12];
|
unsigned char rbuf[12];
|
||||||
|
uint16_t id;
|
||||||
|
|
||||||
UNUSED(state);
|
UNUSED(state);
|
||||||
|
|
||||||
atomic_init(&responses, 0);
|
testdata.handle = NULL;
|
||||||
|
atomic_init(&testdata.responses, 0);
|
||||||
|
|
||||||
result = isc_task_create(taskmgr, 0, &task);
|
result = isc_task_create(taskmgr, 0, &task);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
result = dns_dispatchmgr_create(dt_mctx, &dispatchmgr);
|
result = dns_dispatchmgr_create(dt_mctx, connect_nm, &dispatchmgr);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
ina.s_addr = htonl(INADDR_LOOPBACK);
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr, &connect_addr, 0,
|
||||||
isc_sockaddr_fromin(&local, &ina, 0);
|
&dispatch);
|
||||||
result = dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr, &local,
|
|
||||||
0, &dispatch);
|
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a local udp nameserver on the loopback.
|
* Create a local udp nameserver on the loopback.
|
||||||
*/
|
*/
|
||||||
result = isc_socket_create(socketmgr, AF_INET, isc_sockettype_udp,
|
result = isc_nm_listenudp(netmgr, &server_addr, nameserver, NULL, 0,
|
||||||
&sock);
|
&sock);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
|
||||||
|
|
||||||
ina.s_addr = htonl(INADDR_LOOPBACK);
|
|
||||||
isc_sockaddr_fromin(&local, &ina, 0);
|
|
||||||
result = isc_socket_bind(sock, &local, 0);
|
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
|
||||||
|
|
||||||
result = isc_socket_getsockname(sock, &local);
|
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
region.base = rbuf;
|
region.base = rbuf;
|
||||||
region.length = sizeof(rbuf);
|
region.length = sizeof(rbuf);
|
||||||
result = isc_socket_recv(sock, ®ion, 1, task, nameserver, sock);
|
result = dns_dispatch_addresponse(
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
dispatch, 0, 10000, &server_addr, task, connected,
|
||||||
|
client_senddone, response, NULL, ®ion, &id, &dispentry);
|
||||||
result = dns_dispatch_addresponse(dispatch, 0, &local, task, response,
|
|
||||||
NULL, &id, &dispentry, socketmgr);
|
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
memset(message, 0, sizeof(message));
|
memset(message, 0, sizeof(message));
|
||||||
@ -304,19 +371,22 @@ dispatch_getnext(void **state) {
|
|||||||
|
|
||||||
region.base = message;
|
region.base = message;
|
||||||
region.length = sizeof(message);
|
region.length = sizeof(message);
|
||||||
result = isc_app_onrun(dt_mctx, task, startit, ®ion);
|
|
||||||
|
result = isc_app_onrun(dt_mctx, task, startit, NULL);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
result = isc_app_run();
|
result = isc_app_run();
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
assert_int_equal(atomic_load_acquire(&responses), 2);
|
assert_int_equal(atomic_load_acquire(&testdata.responses), 2);
|
||||||
|
|
||||||
|
isc_nm_stoplistening(sock);
|
||||||
|
isc_nmsocket_close(&sock);
|
||||||
|
assert_null(sock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shutdown nameserver.
|
* Shutdown nameserver.
|
||||||
*/
|
*/
|
||||||
isc_socket_cancel(sock, task, ISC_SOCKCANCEL_RECV);
|
|
||||||
isc_socket_detach(&sock);
|
|
||||||
isc_task_detach(&task);
|
isc_task_detach(&task);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include <isc/lex.h>
|
#include <isc/lex.h>
|
||||||
#include <isc/managers.h>
|
#include <isc/managers.h>
|
||||||
#include <isc/mem.h>
|
#include <isc/mem.h>
|
||||||
|
#include <isc/netmgr.h>
|
||||||
#include <isc/os.h>
|
#include <isc/os.h>
|
||||||
#include <isc/print.h>
|
#include <isc/print.h>
|
||||||
#include <isc/socket.h>
|
#include <isc/socket.h>
|
||||||
@ -96,10 +97,12 @@ cleanup_managers(void) {
|
|||||||
isc_task_shutdown(maintask);
|
isc_task_shutdown(maintask);
|
||||||
isc_task_destroy(&maintask);
|
isc_task_destroy(&maintask);
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_managers_destroy(netmgr == NULL ? NULL : &netmgr,
|
isc_managers_destroy(netmgr == NULL ? NULL : &netmgr,
|
||||||
taskmgr == NULL ? NULL : &taskmgr,
|
taskmgr == NULL ? NULL : &taskmgr,
|
||||||
timermgr == NULL ? NULL : &timermgr,
|
timermgr == NULL ? NULL : &timermgr,
|
||||||
socketmgr == NULL ? NULL : &socketmgr);
|
socketmgr == NULL ? NULL : &socketmgr);
|
||||||
|
|
||||||
if (app_running) {
|
if (app_running) {
|
||||||
isc_app_finish();
|
isc_app_finish();
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ extern isc_taskmgr_t *taskmgr;
|
|||||||
extern isc_task_t *maintask;
|
extern isc_task_t *maintask;
|
||||||
extern isc_timermgr_t *timermgr;
|
extern isc_timermgr_t *timermgr;
|
||||||
extern isc_socketmgr_t *socketmgr;
|
extern isc_socketmgr_t *socketmgr;
|
||||||
|
extern isc_nm_t *netmgr;
|
||||||
extern dns_zonemgr_t *zonemgr;
|
extern dns_zonemgr_t *zonemgr;
|
||||||
extern bool app_running;
|
extern bool app_running;
|
||||||
extern int ncpus;
|
extern int ncpus;
|
||||||
|
@ -50,15 +50,15 @@ _setup(void **state) {
|
|||||||
result = dns_test_begin(NULL, true);
|
result = dns_test_begin(NULL, true);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
result = dns_dispatchmgr_create(dt_mctx, &dispatchmgr);
|
result = dns_dispatchmgr_create(dt_mctx, netmgr, &dispatchmgr);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
result = dns_test_makeview("view", &view);
|
result = dns_test_makeview("view", &view);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
isc_sockaddr_any(&local);
|
isc_sockaddr_any(&local);
|
||||||
result = dns_dispatch_createudp(dispatchmgr, socketmgr, taskmgr, &local,
|
result = dns_dispatch_createudp(dispatchmgr, taskmgr, &local, 0,
|
||||||
0, &dispatch);
|
&dispatch);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@ -80,8 +80,8 @@ static void
|
|||||||
mkres(dns_resolver_t **resolverp) {
|
mkres(dns_resolver_t **resolverp) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
|
|
||||||
result = dns_resolver_create(view, taskmgr, 1, 1, socketmgr, timermgr,
|
result = dns_resolver_create(view, taskmgr, 1, 1, netmgr, timermgr, 0,
|
||||||
0, dispatchmgr, dispatch, NULL, resolverp);
|
dispatchmgr, dispatch, NULL, resolverp);
|
||||||
assert_int_equal(result, ISC_R_SUCCESS);
|
assert_int_equal(result, ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,6 +634,7 @@ view_flushanddetach(dns_view_t **viewp, bool flush) {
|
|||||||
dns_zone_t *mkzone = NULL, *rdzone = NULL;
|
dns_zone_t *mkzone = NULL, *rdzone = NULL;
|
||||||
|
|
||||||
isc_refcount_destroy(&view->references);
|
isc_refcount_destroy(&view->references);
|
||||||
|
|
||||||
if (!RESSHUTDOWN(view)) {
|
if (!RESSHUTDOWN(view)) {
|
||||||
dns_resolver_shutdown(view->resolver);
|
dns_resolver_shutdown(view->resolver);
|
||||||
}
|
}
|
||||||
@ -643,14 +644,14 @@ view_flushanddetach(dns_view_t **viewp, bool flush) {
|
|||||||
if (!REQSHUTDOWN(view)) {
|
if (!REQSHUTDOWN(view)) {
|
||||||
dns_requestmgr_shutdown(view->requestmgr);
|
dns_requestmgr_shutdown(view->requestmgr);
|
||||||
}
|
}
|
||||||
LOCK(&view->lock);
|
|
||||||
if (view->zonetable != NULL) {
|
if (view->zonetable != NULL && view->flush) {
|
||||||
if (view->flush) {
|
dns_zt_flushanddetach(&view->zonetable);
|
||||||
dns_zt_flushanddetach(&view->zonetable);
|
} else if (view->zonetable != NULL) {
|
||||||
} else {
|
dns_zt_detach(&view->zonetable);
|
||||||
dns_zt_detach(&view->zonetable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCK(&view->lock);
|
||||||
if (view->managed_keys != NULL) {
|
if (view->managed_keys != NULL) {
|
||||||
mkzone = view->managed_keys;
|
mkzone = view->managed_keys;
|
||||||
view->managed_keys = NULL;
|
view->managed_keys = NULL;
|
||||||
@ -796,9 +797,9 @@ dns_view_createzonetable(dns_view_t *view) {
|
|||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
||||||
unsigned int ntasks, unsigned int ndisp,
|
unsigned int ntasks, unsigned int ndisp, isc_nm_t *nm,
|
||||||
isc_socketmgr_t *socketmgr, isc_timermgr_t *timermgr,
|
isc_timermgr_t *timermgr, unsigned int options,
|
||||||
unsigned int options, dns_dispatchmgr_t *dispatchmgr,
|
dns_dispatchmgr_t *dispatchmgr,
|
||||||
dns_dispatch_t *dispatchv4,
|
dns_dispatch_t *dispatchv4,
|
||||||
dns_dispatch_t *dispatchv6) {
|
dns_dispatch_t *dispatchv6) {
|
||||||
isc_result_t result;
|
isc_result_t result;
|
||||||
@ -815,8 +816,8 @@ dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
|||||||
}
|
}
|
||||||
isc_task_setname(view->task, "view", view);
|
isc_task_setname(view->task, "view", view);
|
||||||
|
|
||||||
result = dns_resolver_create(view, taskmgr, ntasks, ndisp, socketmgr,
|
result = dns_resolver_create(view, taskmgr, ntasks, ndisp, nm, timermgr,
|
||||||
timermgr, options, dispatchmgr, dispatchv4,
|
options, dispatchmgr, dispatchv4,
|
||||||
dispatchv6, &view->resolver);
|
dispatchv6, &view->resolver);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
isc_task_detach(&view->task);
|
isc_task_detach(&view->task);
|
||||||
@ -841,11 +842,10 @@ dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
|||||||
atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_ADBSHUTDOWN);
|
atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_ADBSHUTDOWN);
|
||||||
isc_refcount_increment(&view->weakrefs);
|
isc_refcount_increment(&view->weakrefs);
|
||||||
|
|
||||||
result = dns_requestmgr_create(view->mctx, timermgr, socketmgr,
|
result = dns_requestmgr_create(
|
||||||
dns_resolver_taskmgr(view->resolver),
|
view->mctx, dns_resolver_taskmgr(view->resolver),
|
||||||
dns_resolver_dispatchmgr(view->resolver),
|
dns_resolver_dispatchmgr(view->resolver), dispatchv4,
|
||||||
dispatchv4, dispatchv6,
|
dispatchv6, &view->requestmgr);
|
||||||
&view->requestmgr);
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
dns_adb_shutdown(view->adb);
|
dns_adb_shutdown(view->adb);
|
||||||
dns_resolver_shutdown(view->resolver);
|
dns_resolver_shutdown(view->resolver);
|
||||||
@ -2502,12 +2502,12 @@ dns_view_setviewcommit(dns_view_t *view) {
|
|||||||
if (view->managed_keys != NULL) {
|
if (view->managed_keys != NULL) {
|
||||||
dns_zone_attach(view->managed_keys, &managed_keys);
|
dns_zone_attach(view->managed_keys, &managed_keys);
|
||||||
}
|
}
|
||||||
if (view->zonetable != NULL) {
|
|
||||||
dns_zt_setviewcommit(view->zonetable);
|
|
||||||
}
|
|
||||||
|
|
||||||
UNLOCK(&view->lock);
|
UNLOCK(&view->lock);
|
||||||
|
|
||||||
|
if (view->zonetable != NULL) {
|
||||||
|
dns_zt_setviewcommit(view->zonetable);
|
||||||
|
}
|
||||||
if (redirect != NULL) {
|
if (redirect != NULL) {
|
||||||
dns_zone_setviewcommit(redirect);
|
dns_zone_setviewcommit(redirect);
|
||||||
dns_zone_detach(&redirect);
|
dns_zone_detach(&redirect);
|
||||||
|
@ -483,6 +483,7 @@ dns_zt_setviewcommit(dns_zt_t *zt) {
|
|||||||
|
|
||||||
REQUIRE(VALID_ZT(zt));
|
REQUIRE(VALID_ZT(zt));
|
||||||
|
|
||||||
|
RWLOCK(&zt->rwlock, isc_rwlocktype_read);
|
||||||
dns_rbtnodechain_init(&chain);
|
dns_rbtnodechain_init(&chain);
|
||||||
|
|
||||||
result = dns_rbtnodechain_first(&chain, zt->table, NULL, NULL);
|
result = dns_rbtnodechain_first(&chain, zt->table, NULL, NULL);
|
||||||
@ -496,6 +497,7 @@ dns_zt_setviewcommit(dns_zt_t *zt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dns_rbtnodechain_invalidate(&chain);
|
dns_rbtnodechain_invalidate(&chain);
|
||||||
|
RWUNLOCK(&zt->rwlock, isc_rwlocktype_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -450,6 +450,16 @@ isc_nm_setstats(isc_nm_t *mgr, isc_stats_t *stats);
|
|||||||
* full range of socket-related stats counter numbers.
|
* full range of socket-related stats counter numbers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
isc_result_t
|
||||||
|
isc_nm_checkaddr(const isc_sockaddr_t *addr, isc_socktype_t type);
|
||||||
|
/*%<
|
||||||
|
* Check whether the specified address is available on the local system
|
||||||
|
* by opening a socket and immediately closing it.
|
||||||
|
*
|
||||||
|
* Requires:
|
||||||
|
*\li 'addr' is not NULL.
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
isc_nm_tcpdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
|
isc_nm_tcpdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer,
|
||||||
isc_nm_cb_t cb, void *cbarg, unsigned int timeout,
|
isc_nm_cb_t cb, void *cbarg, unsigned int timeout,
|
||||||
|
@ -91,7 +91,7 @@ isc_managers_destroy(isc_nm_t **netmgrp, isc_taskmgr_t **taskmgrp,
|
|||||||
/*
|
/*
|
||||||
* If we have a taskmgr to clean up, then we must also have a netmgr.
|
* If we have a taskmgr to clean up, then we must also have a netmgr.
|
||||||
*/
|
*/
|
||||||
REQUIRE(taskmgrp != NULL || netmgrp == NULL);
|
REQUIRE(taskmgrp == NULL || netmgrp != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The sequence of operations here is important:
|
* The sequence of operations here is important:
|
||||||
|
@ -2593,7 +2593,7 @@ isc_socket_close(isc_socket_t *sock) {
|
|||||||
int fd;
|
int fd;
|
||||||
isc_socketmgr_t *manager;
|
isc_socketmgr_t *manager;
|
||||||
isc__socketthread_t *thread;
|
isc__socketthread_t *thread;
|
||||||
fflush(stdout);
|
|
||||||
REQUIRE(VALID_SOCKET(sock));
|
REQUIRE(VALID_SOCKET(sock));
|
||||||
|
|
||||||
LOCK(&sock->lock);
|
LOCK(&sock->lock);
|
||||||
|
@ -482,7 +482,7 @@ ns_interface_listentcp(ns_interface_t *ifp) {
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#ifndef ISC_ALLOW_MAPPED
|
#ifndef ISC_ALLOW_MAPPED
|
||||||
isc_socket_ipv6only(ifp->tcpsocket,true);
|
isc_socket_ipv6only(ifp->tcpsocket, true);
|
||||||
#endif /* ifndef ISC_ALLOW_MAPPED */
|
#endif /* ifndef ISC_ALLOW_MAPPED */
|
||||||
|
|
||||||
if (ifp->dscp != -1) {
|
if (ifp->dscp != -1) {
|
||||||
|
@ -233,7 +233,7 @@ create_managers(void) {
|
|||||||
|
|
||||||
CHECK(ns_server_create(mctx, matchview, &sctx));
|
CHECK(ns_server_create(mctx, matchview, &sctx));
|
||||||
|
|
||||||
CHECK(dns_dispatchmgr_create(mctx, &dispatchmgr));
|
CHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr));
|
||||||
|
|
||||||
CHECK(ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, socketmgr,
|
CHECK(ns_interfacemgr_create(mctx, sctx, taskmgr, timermgr, socketmgr,
|
||||||
netmgr, dispatchmgr, maintask, NULL, ncpus,
|
netmgr, dispatchmgr, maintask, NULL, ncpus,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user