2009-09-01 00:22:28 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2009-09-01 00:22:28 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2009-09-01 00:22:28 +00:00
|
|
|
*/
|
|
|
|
|
2014-02-26 19:00:05 -08:00
|
|
|
#ifndef WIN32
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <arpa/inet.h>
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <netdb.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <unistd.h>
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifndef WIN32 */
|
2014-02-26 19:00:05 -08:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2009-09-01 00:22:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <isc/app.h>
|
2018-08-07 16:46:53 +02:00
|
|
|
#include <isc/attributes.h>
|
2009-09-01 00:22:28 +00:00
|
|
|
#include <isc/base64.h>
|
|
|
|
#include <isc/buffer.h>
|
2014-02-26 19:00:05 -08:00
|
|
|
#include <isc/commandline.h>
|
2009-09-01 00:22:28 +00:00
|
|
|
#include <isc/lib.h>
|
2021-04-27 00:07:43 +02:00
|
|
|
#include <isc/managers.h>
|
2009-09-01 00:22:28 +00:00
|
|
|
#include <isc/mem.h>
|
2015-05-23 14:21:51 +02:00
|
|
|
#include <isc/print.h>
|
2009-09-01 00:22:28 +00:00
|
|
|
#include <isc/sockaddr.h>
|
2013-11-13 10:52:22 -08:00
|
|
|
#include <isc/socket.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <isc/task.h>
|
2013-11-13 10:52:22 -08:00
|
|
|
#include <isc/timer.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <isc/util.h>
|
2013-04-10 13:49:57 -07:00
|
|
|
|
2009-09-01 00:22:28 +00:00
|
|
|
#include <dns/client.h>
|
|
|
|
#include <dns/fixedname.h>
|
|
|
|
#include <dns/keyvalues.h>
|
|
|
|
#include <dns/lib.h>
|
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
#include <dns/rdatatype.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/secalg.h>
|
|
|
|
|
|
|
|
#include <dst/dst.h>
|
2020-03-09 16:17:26 +01:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <irs/resconf.h>
|
2009-09-01 00:22:28 +00:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
/*
|
|
|
|
* Global contexts
|
|
|
|
*/
|
|
|
|
|
|
|
|
isc_mem_t *ctxs_mctx = NULL;
|
|
|
|
isc_appctx_t *ctxs_actx = NULL;
|
|
|
|
isc_nm_t *ctxs_netmgr = NULL;
|
|
|
|
isc_taskmgr_t *ctxs_taskmgr = NULL;
|
|
|
|
isc_socketmgr_t *ctxs_socketmgr = NULL;
|
|
|
|
isc_timermgr_t *ctxs_timermgr = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
ctxs_destroy(void) {
|
2021-04-27 00:07:43 +02:00
|
|
|
isc_managers_destroy(&ctxs_netmgr, &ctxs_taskmgr, &ctxs_timermgr,
|
|
|
|
&ctxs_socketmgr);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
|
|
|
|
if (ctxs_actx != NULL) {
|
|
|
|
isc_appctx_destroy(&ctxs_actx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctxs_mctx != NULL) {
|
|
|
|
isc_mem_destroy(&ctxs_mctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
ctxs_init(void) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
isc_mem_create(&ctxs_mctx);
|
|
|
|
|
|
|
|
result = isc_appctx_create(ctxs_mctx, &ctxs_actx);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2021-04-27 00:07:43 +02:00
|
|
|
isc_managers_create(ctxs_mctx, 1, 0, 0, &ctxs_netmgr, &ctxs_taskmgr,
|
|
|
|
&ctxs_timermgr, &ctxs_socketmgr);
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
|
2021-05-06 10:23:54 +10:00
|
|
|
result = isc_app_ctxstart(ctxs_actx);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
ctxs_destroy();
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2009-09-01 00:22:28 +00:00
|
|
|
static char *algname;
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
printdata(dns_rdataset_t *rdataset, dns_name_t *owner) {
|
2009-09-01 00:22:28 +00:00
|
|
|
isc_buffer_t target;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_region_t r;
|
2020-02-13 14:44:37 -08:00
|
|
|
char t[4096];
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
if (!dns_rdataset_isassociated(rdataset)) {
|
|
|
|
printf("[WARN: empty]\n");
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_buffer_init(&target, t, sizeof(t));
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_rdataset_totext(rdataset, owner, false, false, &target);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-09-01 00:22:28 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
isc_buffer_usedregion(&target, &r);
|
|
|
|
printf("%.*s", (int)r.length, (char *)r.base);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2018-08-07 16:46:53 +02:00
|
|
|
ISC_NORETURN static void
|
|
|
|
usage(void);
|
2009-09-29 15:06:07 +00:00
|
|
|
|
2009-09-01 00:22:28 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
usage(void) {
|
2013-04-10 13:49:57 -07:00
|
|
|
fprintf(stderr, "resolve [-t RRtype] "
|
2020-02-12 13:59:18 +01:00
|
|
|
"[[-a algorithm] [-e] -k keyname -K keystring] "
|
|
|
|
"[-S domain:serveraddr_for_domain ] [-s server_address]"
|
|
|
|
"[-b address[#port]] hostname\n");
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
set_key(dns_client_t *client, char *keynamestr, char *keystr, bool is_sep) {
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
unsigned int namelen;
|
|
|
|
dns_name_t *keyname;
|
2009-09-01 00:22:28 +00:00
|
|
|
dns_rdata_dnskey_t keystruct;
|
2020-02-13 14:44:37 -08:00
|
|
|
unsigned char keydata[4096];
|
|
|
|
isc_buffer_t keydatabuf;
|
|
|
|
unsigned char rrdata[4096];
|
|
|
|
isc_buffer_t rrdatabuf;
|
|
|
|
isc_buffer_t b;
|
|
|
|
isc_textregion_t tr;
|
|
|
|
isc_region_t r;
|
|
|
|
dns_secalg_t alg;
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
if (algname != NULL) {
|
|
|
|
tr.base = algname;
|
|
|
|
tr.length = strlen(algname);
|
|
|
|
result = dns_secalg_fromtext(&alg, &tr);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "failed to identify the algorithm\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2009-09-01 00:22:28 +00:00
|
|
|
alg = DNS_KEYALG_RSASHA1;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
keystruct.common.rdclass = dns_rdataclass_in;
|
|
|
|
keystruct.common.rdtype = dns_rdatatype_dnskey;
|
|
|
|
keystruct.flags = DNS_KEYOWNER_ZONE; /* fixed */
|
2020-02-13 21:48:23 +01:00
|
|
|
if (is_sep) {
|
2009-09-02 23:48:03 +00:00
|
|
|
keystruct.flags |= DNS_KEYFLAG_KSK;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
keystruct.protocol = DNS_KEYPROTO_DNSSEC; /* fixed */
|
|
|
|
keystruct.algorithm = alg;
|
|
|
|
|
|
|
|
isc_buffer_init(&keydatabuf, keydata, sizeof(keydata));
|
|
|
|
isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
|
|
|
|
result = isc_base64_decodestring(keystr, &keydatabuf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "base64 decode failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
isc_buffer_usedregion(&keydatabuf, &r);
|
|
|
|
keystruct.datalen = r.length;
|
|
|
|
keystruct.data = r.base;
|
|
|
|
|
|
|
|
result = dns_rdata_fromstruct(NULL, keystruct.common.rdclass,
|
2020-02-12 13:59:18 +01:00
|
|
|
keystruct.common.rdtype, &keystruct,
|
|
|
|
&rrdatabuf);
|
2009-09-01 00:22:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "failed to construct key rdata\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
namelen = strlen(keynamestr);
|
|
|
|
isc_buffer_init(&b, keynamestr, namelen);
|
|
|
|
isc_buffer_add(&b, namelen);
|
2018-03-28 14:38:09 +02:00
|
|
|
keyname = dns_fixedname_initname(&fkeyname);
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(keyname, &b, dns_rootname, 0, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fprintf(stderr, "failed to construct key name\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
result = dns_client_addtrustedkey(client, dns_rdataclass_in,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_dnskey, keyname,
|
|
|
|
&rrdatabuf);
|
2009-09-01 00:22:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "failed to add key for %s\n", keynamestr);
|
2009-09-01 00:22:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-03 17:27:40 +11:00
|
|
|
addserver(dns_client_t *client, const char *addrstr, const char *port,
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *name_space) {
|
|
|
|
struct addrinfo hints, *res;
|
|
|
|
int gaierror;
|
|
|
|
isc_sockaddr_t sa;
|
2009-09-01 00:22:28 +00:00
|
|
|
isc_sockaddrlist_t servers;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t b;
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
dns_name_t *name = NULL;
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = AF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_DGRAM;
|
|
|
|
hints.ai_protocol = IPPROTO_UDP;
|
|
|
|
hints.ai_flags = AI_NUMERICHOST;
|
2016-06-28 21:25:30 -04:00
|
|
|
gaierror = getaddrinfo(addrstr, port, &hints, &res);
|
|
|
|
if (gaierror != 0) {
|
2009-09-01 00:22:28 +00:00
|
|
|
fprintf(stderr, "getaddrinfo failed: %s\n",
|
2016-06-28 21:25:30 -04:00
|
|
|
gai_strerror(gaierror));
|
2009-09-01 00:22:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
INSIST(res->ai_addrlen <= sizeof(sa.type));
|
2014-01-08 16:27:10 -08:00
|
|
|
memmove(&sa.type, res->ai_addr, res->ai_addrlen);
|
2014-02-26 19:00:05 -08:00
|
|
|
sa.length = (unsigned int)res->ai_addrlen;
|
2012-10-02 23:44:03 -07:00
|
|
|
freeaddrinfo(res);
|
2009-09-01 00:22:28 +00:00
|
|
|
ISC_LINK_INIT(&sa, link);
|
|
|
|
ISC_LIST_INIT(servers);
|
|
|
|
ISC_LIST_APPEND(servers, &sa, link);
|
|
|
|
|
2017-07-21 11:52:24 +10:00
|
|
|
if (name_space != NULL) {
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
unsigned int namelen = strlen(name_space);
|
2017-07-21 11:52:24 +10:00
|
|
|
isc_buffer_constinit(&b, name_space, namelen);
|
2009-09-01 00:22:28 +00:00
|
|
|
isc_buffer_add(&b, namelen);
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fname);
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2018-02-15 14:21:42 +11:00
|
|
|
fprintf(stderr, "failed to convert qname: %u\n",
|
2009-09-01 00:22:28 +00:00
|
|
|
result);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_client_setservers(client, dns_rdataclass_in, name,
|
|
|
|
&servers);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2018-02-15 14:21:42 +11:00
|
|
|
fprintf(stderr, "set server failed: %u\n", result);
|
2009-09-01 00:22:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-02-13 14:44:37 -08:00
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
int ch;
|
2009-09-01 00:22:28 +00:00
|
|
|
isc_textregion_t tr;
|
2020-02-13 14:44:37 -08:00
|
|
|
char *server = NULL;
|
|
|
|
char *altserver = NULL;
|
|
|
|
char *altserveraddr = NULL;
|
|
|
|
char *altservername = NULL;
|
|
|
|
dns_client_t *client = NULL;
|
|
|
|
char *keynamestr = NULL;
|
|
|
|
char *keystr = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t b;
|
|
|
|
dns_fixedname_t qname0;
|
|
|
|
unsigned int namelen;
|
|
|
|
dns_name_t *qname, *name;
|
|
|
|
dns_rdatatype_t type = dns_rdatatype_a;
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
dns_namelist_t namelist;
|
2021-03-22 18:16:28 -07:00
|
|
|
unsigned int clientopt, resopt = 0;
|
2020-02-13 14:44:37 -08:00
|
|
|
bool is_sep = false;
|
|
|
|
const char *port = "53";
|
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
|
|
|
isc_sockaddr_t a4, a6;
|
|
|
|
isc_sockaddr_t *addr4 = NULL, *addr6 = NULL;
|
2020-02-12 13:59:18 +01:00
|
|
|
|
|
|
|
while ((ch = isc_commandline_parse(argc, argv, "a:b:es:t:k:K:p:S:")) !=
|
|
|
|
-1) {
|
2009-09-01 00:22:28 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 't':
|
2014-02-26 19:00:05 -08:00
|
|
|
tr.base = isc_commandline_argument;
|
|
|
|
tr.length = strlen(isc_commandline_argument);
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_rdatatype_fromtext(&type, &tr);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "invalid RRtype: %s\n",
|
2014-02-26 19:00:05 -08:00
|
|
|
isc_commandline_argument);
|
2009-09-01 00:22:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'a':
|
2014-02-26 19:00:05 -08:00
|
|
|
algname = isc_commandline_argument;
|
2009-09-01 00:22:28 +00:00
|
|
|
break;
|
2013-11-13 10:52:22 -08:00
|
|
|
case 'b':
|
2020-02-12 13:59:18 +01:00
|
|
|
if (inet_pton(AF_INET, isc_commandline_argument,
|
|
|
|
&in4) == 1) {
|
2013-11-13 10:52:22 -08:00
|
|
|
if (addr4 != NULL) {
|
|
|
|
fprintf(stderr, "only one local "
|
|
|
|
"address per family "
|
|
|
|
"can be specified\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
isc_sockaddr_fromin(&a4, &in4, 0);
|
|
|
|
addr4 = &a4;
|
2020-02-12 13:59:18 +01:00
|
|
|
} else if (inet_pton(AF_INET6, isc_commandline_argument,
|
2014-02-26 19:00:05 -08:00
|
|
|
&in6) == 1) {
|
2013-11-13 10:52:22 -08:00
|
|
|
if (addr6 != NULL) {
|
|
|
|
fprintf(stderr, "only one local "
|
|
|
|
"address per family "
|
|
|
|
"can be specified\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
isc_sockaddr_fromin6(&a6, &in6, 0);
|
|
|
|
addr6 = &a6;
|
|
|
|
} else {
|
2014-02-26 19:00:05 -08:00
|
|
|
fprintf(stderr, "invalid address %s\n",
|
|
|
|
isc_commandline_argument);
|
2013-11-13 10:52:22 -08:00
|
|
|
exit(1);
|
|
|
|
}
|
2013-11-14 12:26:57 +11:00
|
|
|
break;
|
2009-09-01 00:22:28 +00:00
|
|
|
case 'e':
|
2018-04-17 08:29:14 -07:00
|
|
|
is_sep = true;
|
2009-09-01 00:22:28 +00:00
|
|
|
break;
|
2013-04-10 13:49:57 -07:00
|
|
|
case 'S':
|
2009-09-01 00:22:28 +00:00
|
|
|
if (altserver != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"alternate server "
|
2009-09-01 00:22:28 +00:00
|
|
|
"already defined: %s\n",
|
|
|
|
altserver);
|
|
|
|
exit(1);
|
|
|
|
}
|
2014-02-26 19:00:05 -08:00
|
|
|
altserver = isc_commandline_argument;
|
2009-09-01 00:22:28 +00:00
|
|
|
break;
|
2013-04-10 13:49:57 -07:00
|
|
|
case 's':
|
|
|
|
if (server != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"server "
|
2013-04-10 13:49:57 -07:00
|
|
|
"already defined: %s\n",
|
|
|
|
server);
|
|
|
|
exit(1);
|
|
|
|
}
|
2014-02-26 19:00:05 -08:00
|
|
|
server = isc_commandline_argument;
|
2013-04-10 13:49:57 -07:00
|
|
|
break;
|
2009-09-01 00:22:28 +00:00
|
|
|
case 'k':
|
2014-02-26 19:00:05 -08:00
|
|
|
keynamestr = isc_commandline_argument;
|
2009-09-01 00:22:28 +00:00
|
|
|
break;
|
|
|
|
case 'K':
|
2014-02-26 19:00:05 -08:00
|
|
|
keystr = isc_commandline_argument;
|
2009-09-01 00:22:28 +00:00
|
|
|
break;
|
2013-04-03 17:27:40 +11:00
|
|
|
case 'p':
|
2014-02-26 19:00:05 -08:00
|
|
|
port = isc_commandline_argument;
|
2013-04-03 17:27:40 +11:00
|
|
|
break;
|
2009-09-01 00:22:28 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:00:05 -08:00
|
|
|
argc -= isc_commandline_index;
|
|
|
|
argv += isc_commandline_index;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (argc < 1) {
|
2009-09-01 00:22:28 +00:00
|
|
|
usage();
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
if (altserver != NULL) {
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
cp = strchr(altserver, ':');
|
|
|
|
if (cp == NULL) {
|
|
|
|
fprintf(stderr, "invalid alternate server: %s\n",
|
|
|
|
altserver);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
altservername = altserver;
|
|
|
|
altserveraddr = cp + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_lib_register();
|
|
|
|
result = dns_lib_init();
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2018-02-15 14:21:42 +11:00
|
|
|
fprintf(stderr, "dns_lib_init failed: %u\n", result);
|
2009-09-01 00:22:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
result = ctxs_init();
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2013-11-13 10:52:22 -08:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-11-13 10:52:22 -08:00
|
|
|
|
2009-09-01 00:22:28 +00:00
|
|
|
clientopt = 0;
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
result = dns_client_create(ctxs_mctx, ctxs_actx, ctxs_taskmgr,
|
|
|
|
ctxs_socketmgr, ctxs_timermgr, clientopt,
|
|
|
|
&client, addr4, addr6);
|
2009-09-01 00:22:28 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2018-02-15 14:21:42 +11:00
|
|
|
fprintf(stderr, "dns_client_create failed: %u, %s\n", result,
|
2013-11-13 10:52:22 -08:00
|
|
|
isc_result_totext(result));
|
2009-09-01 00:22:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the nameserver */
|
2013-04-10 13:49:57 -07:00
|
|
|
if (server == NULL) {
|
2020-02-13 14:44:37 -08:00
|
|
|
irs_resconf_t *resconf = NULL;
|
2013-04-10 13:49:57 -07:00
|
|
|
isc_sockaddrlist_t *nameservers;
|
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
result = irs_resconf_load(ctxs_mctx, "/etc/resolv.conf",
|
|
|
|
&resconf);
|
2014-01-15 15:22:55 +11:00
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
|
2018-02-15 14:21:42 +11:00
|
|
|
fprintf(stderr, "irs_resconf_load failed: %u\n",
|
2013-04-12 14:41:10 +10:00
|
|
|
result);
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-04-10 13:49:57 -07:00
|
|
|
nameservers = irs_resconf_getnameservers(resconf);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_client_setservers(client, dns_rdataclass_in, NULL,
|
|
|
|
nameservers);
|
2013-04-10 13:49:57 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2013-11-13 10:52:22 -08:00
|
|
|
irs_resconf_destroy(&resconf);
|
2018-02-15 14:21:42 +11:00
|
|
|
fprintf(stderr, "dns_client_setservers failed: %u\n",
|
2013-04-10 13:49:57 -07:00
|
|
|
result);
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-11-13 10:52:22 -08:00
|
|
|
irs_resconf_destroy(&resconf);
|
2013-04-10 13:49:57 -07:00
|
|
|
} else {
|
|
|
|
addserver(client, server, port, NULL);
|
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
/* Set the alternate nameserver (when specified) */
|
2020-02-13 21:48:23 +01:00
|
|
|
if (altserver != NULL) {
|
2013-04-03 17:27:40 +11:00
|
|
|
addserver(client, altserveraddr, port, altservername);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
/* Install DNSSEC key (if given) */
|
|
|
|
if (keynamestr != NULL) {
|
|
|
|
if (keystr == NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "key string is missing "
|
|
|
|
"while key name is provided\n");
|
2009-09-01 00:22:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
set_key(client, keynamestr, keystr, is_sep);
|
2009-09-01 00:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct qname */
|
2013-04-10 13:49:57 -07:00
|
|
|
namelen = strlen(argv[0]);
|
|
|
|
isc_buffer_init(&b, argv[0], namelen);
|
2009-09-01 00:22:28 +00:00
|
|
|
isc_buffer_add(&b, namelen);
|
2018-03-28 14:38:09 +02:00
|
|
|
qname = dns_fixedname_initname(&qname0);
|
2009-09-01 00:22:28 +00:00
|
|
|
result = dns_name_fromtext(qname, &b, dns_rootname, 0, NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2018-02-15 14:21:42 +11:00
|
|
|
fprintf(stderr, "failed to convert qname: %u\n", result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
|
|
|
|
/* Perform resolution */
|
2020-02-13 21:48:23 +01:00
|
|
|
if (keynamestr == NULL) {
|
2009-09-01 00:22:28 +00:00
|
|
|
resopt |= DNS_CLIENTRESOPT_NODNSSEC;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
ISC_LIST_INIT(namelist);
|
|
|
|
result = dns_client_resolve(client, qname, dns_rdataclass_in, type,
|
|
|
|
resopt, &namelist);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(stderr, "resolution failed: %s\n",
|
|
|
|
dns_result_totext(result));
|
2009-09-01 00:22:28 +00:00
|
|
|
}
|
|
|
|
for (name = ISC_LIST_HEAD(namelist); name != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
name = ISC_LIST_NEXT(name, link))
|
|
|
|
{
|
2020-02-12 13:59:18 +01:00
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link))
|
|
|
|
{
|
2020-02-13 21:48:23 +01:00
|
|
|
if (printdata(rdataset, name) != ISC_R_SUCCESS) {
|
2009-09-01 00:22:28 +00:00
|
|
|
fprintf(stderr, "print data failed\n");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 00:22:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_client_freeresanswer(client, &namelist);
|
|
|
|
|
|
|
|
/* Cleanup */
|
2013-11-13 10:52:22 -08:00
|
|
|
cleanup:
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
if (client != NULL) {
|
|
|
|
dns_client_destroy(&client);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-11-13 10:52:22 -08:00
|
|
|
|
Refactor taskmgr to run on top of netmgr
This commit changes the taskmgr to run the individual tasks on the
netmgr internal workers. While an effort has been put into keeping the
taskmgr interface intact, couple of changes have been made:
* The taskmgr has no concept of universal privileged mode - rather the
tasks are either privileged or unprivileged (normal). The privileged
tasks are run as a first thing when the netmgr is unpaused. There
are now four different queues in in the netmgr:
1. priority queue - netievent on the priority queue are run even when
the taskmgr enter exclusive mode and netmgr is paused. This is
needed to properly start listening on the interfaces, free
resources and resume.
2. privileged task queue - only privileged tasks are queued here and
this is the first queue that gets processed when network manager
is unpaused using isc_nm_resume(). All netmgr workers need to
clean the privileged task queue before they all proceed normal
operation. Both task queues are processed when the workers are
finished.
3. task queue - only (traditional) task are scheduled here and this
queue along with privileged task queues are process when the
netmgr workers are finishing. This is needed to process the task
shutdown events.
4. normal queue - this is the queue with netmgr events, e.g. reading,
sending, callbacks and pretty much everything is processed here.
* The isc_taskmgr_create() now requires initialized netmgr (isc_nm_t)
object.
* The isc_nm_destroy() function now waits for indefinite time, but it
will print out the active objects when in tracing mode
(-DNETMGR_TRACE=1 and -DNETMGR_TRACE_VERBOSE=1), the netmgr has been
made a little bit more asynchronous and it might take longer time to
shutdown all the active networking connections.
* Previously, the isc_nm_stoplistening() was a synchronous operation.
This has been changed and the isc_nm_stoplistening() just schedules
the child sockets to stop listening and exits. This was needed to
prevent a deadlock as the the (traditional) tasks are now executed on
the netmgr threads.
* The socket selection logic in isc__nm_udp_send() was flawed, but
fortunatelly, it was broken, so we never hit the problem where we
created uvreq_t on a socket from nmhandle_t, but then a different
socket could be picked up and then we were trying to run the send
callback on a socket that had different threadid than currently
running.
2021-04-09 11:31:19 +02:00
|
|
|
ctxs_destroy();
|
2009-09-01 00:22:28 +00:00
|
|
|
dns_lib_shutdown();
|
|
|
|
|
2013-04-12 14:06:41 +10:00
|
|
|
return (0);
|
2009-09-01 00:22:28 +00:00
|
|
|
}
|