2014-02-16 13:03:17 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
2014-02-16 13:03:17 -08: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
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
2014-02-16 13:03:17 -08:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
2021-05-20 15:53:50 +02:00
|
|
|
#include <bind.keys.h>
|
|
|
|
#include <inttypes.h>
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <netdb.h>
|
2014-02-26 19:00:05 -08:00
|
|
|
#include <netinet/in.h>
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <signal.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2021-05-20 15:53:50 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
2014-02-26 19:00:05 -08:00
|
|
|
#include <unistd.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2024-11-21 16:22:51 +11:00
|
|
|
#include <openssl/opensslv.h>
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <openssl/provider.h>
|
|
|
|
#endif
|
|
|
|
|
2023-03-27 22:40:57 +02:00
|
|
|
#include <isc/async.h>
|
2018-08-07 16:46:53 +02:00
|
|
|
#include <isc/attributes.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isc/base64.h>
|
|
|
|
#include <isc/buffer.h>
|
2024-11-21 16:22:51 +11:00
|
|
|
#include <isc/fips.h>
|
2019-09-18 19:45:20 -07:00
|
|
|
#include <isc/hex.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isc/log.h>
|
2021-04-27 00:07:43 +02:00
|
|
|
#include <isc/managers.h>
|
2019-09-18 19:45:20 -07:00
|
|
|
#include <isc/md.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isc/mem.h>
|
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
|
|
|
#include <isc/netmgr.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isc/parseint.h>
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <isc/random.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isc/sockaddr.h>
|
2014-02-16 16:30:47 -08:00
|
|
|
#include <isc/string.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isc/timer.h>
|
2022-12-08 14:18:22 +00:00
|
|
|
#include <isc/tls.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <dns/acl.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <dns/byaddr.h>
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <dns/cache.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <dns/client.h>
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <dns/dispatch.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <dns/fixedname.h>
|
|
|
|
#include <dns/keytable.h>
|
|
|
|
#include <dns/keyvalues.h>
|
|
|
|
#include <dns/masterdump.h>
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <dns/message.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataclass.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
#include <dns/rdatatype.h>
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <dns/request.h>
|
|
|
|
#include <dns/result.h>
|
|
|
|
#include <dns/rootns.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <dns/secalg.h>
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <dns/stats.h>
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <dns/view.h>
|
|
|
|
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <dst/dst.h>
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <isccfg/namedconf.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
#include <ns/client.h>
|
|
|
|
#include <ns/interfacemgr.h>
|
|
|
|
#include <ns/server.h>
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
#include <irs/resconf.h>
|
|
|
|
|
|
|
|
#define CHECK(r) \
|
|
|
|
do { \
|
|
|
|
result = (r); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
goto cleanup; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define MAXNAME (DNS_NAME_MAXTEXT + 1)
|
|
|
|
|
2024-12-05 09:52:38 +01:00
|
|
|
#define MAX_QUERIES 50
|
2024-11-11 14:06:28 +01:00
|
|
|
#define MAX_TOTAL 200
|
2024-06-25 14:30:20 -07:00
|
|
|
#define MAX_RESTARTS 11
|
|
|
|
|
2014-04-23 11:14:12 -07:00
|
|
|
/* Variables used internally by delv. */
|
2023-02-14 17:28:55 -08:00
|
|
|
char *progname = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
static isc_mem_t *mctx = NULL;
|
2023-01-31 13:30:12 -08:00
|
|
|
static dns_view_t *view = NULL;
|
|
|
|
static ns_server_t *sctx = NULL;
|
|
|
|
static ns_interface_t *ifp = NULL;
|
|
|
|
static dns_dispatch_t *dispatch = NULL;
|
|
|
|
static dns_db_t *roothints = NULL;
|
|
|
|
static isc_stats_t *resstats = NULL;
|
|
|
|
static dns_stats_t *resquerystats = NULL;
|
2023-02-14 17:28:55 -08:00
|
|
|
static FILE *logfp = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
/* Managers */
|
|
|
|
static isc_nm_t *netmgr = NULL;
|
|
|
|
static isc_loopmgr_t *loopmgr = NULL;
|
2023-01-31 13:30:12 -08:00
|
|
|
static dns_dispatchmgr_t *dispatchmgr = NULL;
|
|
|
|
static dns_requestmgr_t *requestmgr = NULL;
|
|
|
|
static ns_interfacemgr_t *interfacemgr = NULL;
|
2022-07-26 13:03:45 +02:00
|
|
|
|
2022-12-08 14:18:22 +00:00
|
|
|
/* TLS */
|
|
|
|
static isc_tlsctx_cache_t *tlsctx_client_cache = NULL;
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
/* Configurables */
|
|
|
|
static char *server = NULL;
|
|
|
|
static const char *port = "53";
|
2023-01-31 13:30:12 -08:00
|
|
|
static uint32_t destport = 53;
|
2014-02-16 13:03:17 -08:00
|
|
|
static isc_sockaddr_t *srcaddr4 = NULL, *srcaddr6 = NULL;
|
2014-02-18 01:53:21 +11:00
|
|
|
static isc_sockaddr_t a4, a6;
|
2014-02-16 13:03:17 -08:00
|
|
|
static char *curqname = NULL, *qname = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool classset = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
static dns_rdatatype_t qtype = dns_rdatatype_none;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool typeset = false;
|
2023-03-24 17:50:32 -07:00
|
|
|
static const char *hintfile = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
static unsigned int styleflags = 0;
|
2018-03-28 14:19:37 +02:00
|
|
|
static uint32_t splitwidth = 0xffffffff;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool showcomments = true, showdnssec = true, showtrust = true,
|
|
|
|
rrcomments = true, noclass = false, nocrypto = false, nottl = false,
|
2019-07-20 17:24:41 -04:00
|
|
|
multiline = false, short_form = false, print_unknown_format = false,
|
2023-01-31 13:30:12 -08:00
|
|
|
yaml = false, fulltrace = false;
|
2018-04-17 08:29:14 -07:00
|
|
|
|
2024-06-25 18:48:18 -07:00
|
|
|
static uint32_t maxqueries = MAX_QUERIES;
|
2024-11-11 14:06:28 +01:00
|
|
|
static uint32_t maxtotal = MAX_TOTAL;
|
2024-06-25 18:48:18 -07:00
|
|
|
static uint32_t restarts = MAX_RESTARTS;
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool resolve_trace = false, validator_trace = false,
|
2023-02-01 23:19:36 -08:00
|
|
|
message_trace = false, send_trace = false;
|
2018-04-17 08:29:14 -07:00
|
|
|
|
|
|
|
static bool use_ipv4 = true, use_ipv6 = true;
|
|
|
|
|
2019-08-06 09:34:27 -07:00
|
|
|
static bool cdflag = false, no_sigs = false, root_validation = true;
|
2023-03-03 00:46:36 -08:00
|
|
|
static bool qmin = false, qmin_strict = false;
|
2018-04-17 08:29:14 -07:00
|
|
|
|
|
|
|
static bool use_tcp = false;
|
2014-11-21 09:37:04 -08:00
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
static char *anchorfile = NULL;
|
|
|
|
static char *trust_anchor = NULL;
|
2018-10-05 12:00:42 -07:00
|
|
|
static int num_keys = 0;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-08-06 09:34:27 -07:00
|
|
|
static dns_fixedname_t afn;
|
|
|
|
static dns_name_t *anchor_name = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static dns_master_style_t *style = NULL;
|
|
|
|
static dns_fixedname_t qfn;
|
|
|
|
|
2023-02-03 14:57:17 -08:00
|
|
|
/* Default trust anchors */
|
2019-12-04 11:06:40 +01:00
|
|
|
static char anchortext[] = TRUST_ANCHORS;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2024-11-21 16:22:51 +11:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
|
|
|
static OSSL_PROVIDER *fips = NULL, *base = NULL;
|
|
|
|
#endif
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
/*
|
|
|
|
* Static function prototypes
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
static isc_result_t
|
|
|
|
get_reverse(char *reverse, size_t len, char *value, bool strict);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
static isc_result_t
|
|
|
|
parse_uint(uint32_t *uip, const char *value, uint32_t max, const char *desc);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void) {
|
2020-04-02 18:51:06 -07:00
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: delv [@server] {q-opt} {d-opt} [domain] [q-type] "
|
|
|
|
"[q-class]\n"
|
|
|
|
"Where: domain is in the Domain Name System\n"
|
|
|
|
" q-class is one of (in,hs,ch,...) [default: in]\n"
|
|
|
|
" q-type is one of "
|
|
|
|
"(a,any,mx,ns,soa,hinfo,axfr,txt,...) "
|
|
|
|
"[default:a]\n"
|
|
|
|
" q-opt is one of:\n"
|
|
|
|
" -4 (use IPv4 query "
|
|
|
|
"transport "
|
|
|
|
"only)\n"
|
|
|
|
" -6 (use IPv6 query "
|
|
|
|
"transport "
|
|
|
|
"only)\n"
|
|
|
|
" -a anchor-file (specify root trust "
|
|
|
|
"anchor)\n"
|
|
|
|
" -b address[#port] (bind to source "
|
|
|
|
"address/port)\n"
|
|
|
|
" -c class (option included for "
|
|
|
|
"compatibility;\n"
|
|
|
|
" -d level (set debugging level)\n"
|
|
|
|
" -h (print help and exit)\n"
|
|
|
|
" -i (disable DNSSEC "
|
|
|
|
"validation)\n"
|
|
|
|
" -m (enable memory usage "
|
|
|
|
"debugging)\n"
|
|
|
|
" -p port (specify port number)\n"
|
|
|
|
" -q name (specify query name)\n"
|
|
|
|
" -t type (specify query type)\n"
|
|
|
|
" only IN is supported)\n"
|
|
|
|
" -v (print version and "
|
|
|
|
"exit)\n"
|
|
|
|
" -x dot-notation (shortcut for reverse "
|
|
|
|
"lookups)\n"
|
|
|
|
" d-opt is of the form +keyword[=value], where "
|
|
|
|
"keyword "
|
|
|
|
"is:\n"
|
|
|
|
" +[no]all (Set or clear all "
|
|
|
|
"display "
|
|
|
|
"flags)\n"
|
|
|
|
" +[no]class (Control display of "
|
|
|
|
"class)\n"
|
|
|
|
" +[no]comments (Control display of "
|
|
|
|
"comment lines)\n"
|
|
|
|
" +[no]crypto (Control display of "
|
|
|
|
"cryptographic\n"
|
|
|
|
" fields in records)\n"
|
|
|
|
" +[no]dnssec (Display DNSSEC "
|
|
|
|
"records)\n"
|
|
|
|
" +[no]mtrace (Trace messages "
|
|
|
|
"received)\n"
|
2023-01-31 13:30:12 -08:00
|
|
|
" +[no]ns (Run internal name "
|
|
|
|
"server)\n"
|
2020-04-02 18:51:06 -07:00
|
|
|
" +[no]multiline (Print records in an "
|
|
|
|
"expanded format)\n"
|
2023-03-03 00:46:36 -08:00
|
|
|
" +[no]qmin[=mode] (QNAME minimization: "
|
|
|
|
"relaxed or strict)\n"
|
2020-04-02 18:51:06 -07:00
|
|
|
" +[no]root (DNSSEC validation trust "
|
|
|
|
"anchor)\n"
|
|
|
|
" +[no]rrcomments (Control display of "
|
|
|
|
"per-record "
|
|
|
|
"comments)\n"
|
|
|
|
" +[no]rtrace (Trace resolver "
|
|
|
|
"fetches)\n"
|
|
|
|
" +[no]short (Short form answer)\n"
|
|
|
|
" +[no]split=## (Split hex/base64 fields "
|
|
|
|
"into chunks)\n"
|
2023-02-01 23:19:36 -08:00
|
|
|
" +[no]strace (Trace messages "
|
|
|
|
"sent)\n"
|
2020-04-02 18:51:06 -07:00
|
|
|
" +[no]tcp (TCP mode)\n"
|
|
|
|
" +[no]ttl (Control display of ttls "
|
|
|
|
"in records)\n"
|
|
|
|
" +[no]trust (Control display of "
|
|
|
|
"trust "
|
|
|
|
"level)\n"
|
|
|
|
" +[no]unknownformat (Print RDATA in RFC 3597 "
|
|
|
|
"\"unknown\" format)\n"
|
|
|
|
" +[no]vtrace (Trace validation "
|
|
|
|
"process)\n"
|
|
|
|
" +[no]yaml (Present the results as "
|
|
|
|
"YAML)\n");
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
2024-07-11 16:15:40 +03:00
|
|
|
ISC_NORETURN static void
|
2018-08-07 16:46:53 +02:00
|
|
|
fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
2014-02-19 07:25:29 +11:00
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
static void
|
|
|
|
fatal(const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
fprintf(stderr, "%s: ", progname);
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
2024-02-07 14:44:39 +01:00
|
|
|
_exit(EXIT_FAILURE);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
2014-02-19 07:25:29 +11:00
|
|
|
static void
|
|
|
|
warn(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
static void
|
|
|
|
warn(const char *format, ...) {
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
fprintf(stderr, "%s: warning: ", progname);
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2014-04-23 11:14:12 -07:00
|
|
|
static void
|
|
|
|
delv_log(int level, const char *fmt, ...) ISC_FORMAT_PRINTF(2, 3);
|
2014-02-19 07:25:29 +11:00
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
static void
|
2014-04-23 11:14:12 -07:00
|
|
|
delv_log(int level, const char *fmt, ...) {
|
2014-02-16 13:03:17 -08:00
|
|
|
va_list ap;
|
|
|
|
char msgbuf[2048];
|
|
|
|
|
2024-08-13 18:20:26 +02:00
|
|
|
if (!isc_log_wouldlog(level)) {
|
2014-02-16 13:03:17 -08:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
|
|
|
vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
|
2024-08-14 13:25:50 +02:00
|
|
|
isc_log_write(DELV_LOGCATEGORY_DEFAULT, DELV_LOGMODULE_DEFAULT, level,
|
|
|
|
"%s", msgbuf);
|
2014-02-16 13:03:17 -08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int loglevel = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_logging(FILE *errout) {
|
2023-02-01 23:19:36 -08:00
|
|
|
int packetlevel = 10;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2024-08-14 14:38:07 +02:00
|
|
|
isc_log_setdebuglevel(loglevel);
|
|
|
|
|
2024-08-14 13:25:50 +02:00
|
|
|
isc_logconfig_t *logconfig = isc_logconfig_get();
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
isc_log_settag(logconfig, ";; ");
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2024-08-14 14:38:07 +02:00
|
|
|
isc_log_createandusechannel(
|
|
|
|
logconfig, "default_stderr", ISC_LOG_TOFILEDESC,
|
|
|
|
ISC_LOG_DYNAMIC, ISC_LOGDESTINATION_FILE(errout),
|
|
|
|
ISC_LOG_PRINTPREFIX, ISC_LOGCATEGORY_DEFAULT,
|
|
|
|
ISC_LOGMODULE_DEFAULT);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
if (resolve_trace && loglevel < 1) {
|
2024-08-14 14:38:07 +02:00
|
|
|
isc_log_createandusechannel(
|
|
|
|
logconfig, "resolver", ISC_LOG_TOFILEDESC,
|
|
|
|
ISC_LOG_DEBUG(1), ISC_LOGDESTINATION_FILE(errout),
|
|
|
|
ISC_LOG_PRINTPREFIX, DNS_LOGCATEGORY_RESOLVER,
|
|
|
|
DNS_LOGMODULE_RESOLVER);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (validator_trace && loglevel < 3) {
|
2024-08-14 14:38:07 +02:00
|
|
|
isc_log_createandusechannel(
|
|
|
|
logconfig, "validator", ISC_LOG_TOFILEDESC,
|
|
|
|
ISC_LOG_DEBUG(3), ISC_LOGDESTINATION_FILE(errout),
|
|
|
|
ISC_LOG_PRINTPREFIX, DNS_LOGCATEGORY_DNSSEC,
|
|
|
|
DNS_LOGMODULE_VALIDATOR);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
2023-02-01 23:19:36 -08:00
|
|
|
if (send_trace) {
|
|
|
|
packetlevel = 11;
|
|
|
|
}
|
|
|
|
if ((message_trace || send_trace) && loglevel < packetlevel) {
|
2024-08-14 14:38:07 +02:00
|
|
|
isc_log_createandusechannel(
|
|
|
|
logconfig, "messages", ISC_LOG_TOFILEDESC,
|
|
|
|
ISC_LOG_DEBUG(packetlevel),
|
|
|
|
ISC_LOGDESTINATION_FILE(errout), ISC_LOG_PRINTPREFIX,
|
|
|
|
DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_PACKETS);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_status(dns_rdataset_t *rdataset) {
|
2019-07-20 17:24:41 -04:00
|
|
|
char buf[1024] = { 0 };
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
REQUIRE(rdataset != NULL);
|
|
|
|
|
2019-07-20 17:24:41 -04:00
|
|
|
if (!showtrust || !dns_rdataset_isassociated(rdataset)) {
|
2014-02-16 13:03:17 -08:00
|
|
|
return;
|
2019-07-20 17:24:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-07-20 17:24:41 -04:00
|
|
|
if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) {
|
|
|
|
strlcat(buf, "negative response", sizeof(buf));
|
|
|
|
strlcat(buf, (yaml ? "_" : ", "), sizeof(buf));
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
switch (rdataset->trust) {
|
|
|
|
case dns_trust_none:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "untrusted", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_pending_additional:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "signed additional data", sizeof(buf));
|
|
|
|
if (!yaml) {
|
|
|
|
strlcat(buf, ", ", sizeof(buf));
|
|
|
|
}
|
|
|
|
strlcat(buf, "pending validation", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_pending_answer:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "signed answer", sizeof(buf));
|
|
|
|
if (!yaml) {
|
|
|
|
strlcat(buf, ", ", sizeof(buf));
|
|
|
|
}
|
|
|
|
strlcat(buf, "pending validation", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_additional:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "unsigned additional data", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_glue:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "glue data", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_answer:
|
2019-08-06 09:34:27 -07:00
|
|
|
if (root_validation) {
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "unsigned answer", sizeof(buf));
|
|
|
|
} else {
|
|
|
|
strlcat(buf, "answer not validated", sizeof(buf));
|
2019-08-06 09:34:27 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_authauthority:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "authority data", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_authanswer:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "authoritative", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_secure:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "fully validated", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case dns_trust_ultimate:
|
2019-07-20 17:24:41 -04:00
|
|
|
strlcat(buf, "ultimate trust", sizeof(buf));
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-07-20 17:24:41 -04:00
|
|
|
if (yaml) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
/* Convert spaces to underscores for YAML */
|
|
|
|
for (p = buf; p != NULL && *p != '\0'; p++) {
|
|
|
|
if (*p == ' ') {
|
|
|
|
*p = '_';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" - %s:\n", buf);
|
|
|
|
} else {
|
|
|
|
printf("; %s\n", buf);
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
static void
|
2022-07-26 13:03:45 +02:00
|
|
|
printdata(dns_rdataset_t *rdataset, dns_name_t *owner) {
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
static dns_trust_t trust;
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool first = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_buffer_t target;
|
|
|
|
isc_region_t r;
|
|
|
|
char *t = NULL;
|
|
|
|
int len = 2048;
|
|
|
|
|
|
|
|
if (!dns_rdataset_isassociated(rdataset)) {
|
|
|
|
char namebuf[DNS_NAME_FORMATSIZE];
|
|
|
|
dns_name_format(owner, namebuf, sizeof(namebuf));
|
2023-01-31 13:30:12 -08:00
|
|
|
delv_log(ISC_LOG_DEBUG(4), "warning: empty rdataset %s",
|
|
|
|
namebuf);
|
|
|
|
return;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!showdnssec && rdataset->type == dns_rdatatype_rrsig) {
|
2023-01-31 13:30:12 -08:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
if (first || rdataset->trust != trust) {
|
2019-07-20 17:24:41 -04:00
|
|
|
if (!first && showtrust && !short_form && !yaml) {
|
2014-02-16 13:03:17 -08:00
|
|
|
putchar('\n');
|
2019-07-20 17:24:41 -04:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
print_status(rdataset);
|
|
|
|
trust = rdataset->trust;
|
2018-04-17 08:29:14 -07:00
|
|
|
first = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
t = isc_mem_get(mctx, len);
|
|
|
|
|
|
|
|
isc_buffer_init(&target, t, len);
|
|
|
|
if (short_form) {
|
|
|
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
|
|
|
for (result = dns_rdataset_first(rdataset);
|
|
|
|
result == ISC_R_SUCCESS;
|
|
|
|
result = dns_rdataset_next(rdataset))
|
|
|
|
{
|
|
|
|
if ((rdataset->attributes &
|
2022-11-02 19:33:14 +01:00
|
|
|
DNS_RDATASETATTR_NEGATIVE) != 0)
|
|
|
|
{
|
2014-02-16 13:03:17 -08:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
dns_rdataset_current(rdataset, &rdata);
|
|
|
|
result = dns_rdata_tofmttext(
|
2015-12-10 12:43:50 +11:00
|
|
|
&rdata, dns_rootname, styleflags, 0,
|
|
|
|
splitwidth, " ", &target);
|
2014-02-16 13:03:17 -08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
if (isc_buffer_availablelength(&target) < 1) {
|
2014-02-16 13:03:17 -08:00
|
|
|
result = ISC_R_NOSPACE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
isc_buffer_putstr(&target, "\n");
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
dns_rdata_reset(&rdata);
|
|
|
|
}
|
|
|
|
} else {
|
2019-11-18 20:46:58 +11:00
|
|
|
dns_indent_t indent = { " ", 2 };
|
2019-07-20 17:24:41 -04:00
|
|
|
if (!yaml && (rdataset->attributes &
|
2022-11-02 19:33:14 +01:00
|
|
|
DNS_RDATASETATTR_NEGATIVE) != 0)
|
|
|
|
{
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_buffer_putstr(&target, "; ");
|
2019-07-20 17:24:41 -04:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
result = dns_master_rdatasettotext(
|
2019-11-18 20:46:58 +11:00
|
|
|
owner, rdataset, style, yaml ? &indent : NULL,
|
|
|
|
&target);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result == ISC_R_NOSPACE) {
|
|
|
|
isc_mem_put(mctx, t, len);
|
|
|
|
len += 1024;
|
2014-02-16 13:25:53 -08:00
|
|
|
} else if (result == ISC_R_NOMORE) {
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
} else {
|
2014-02-16 13:03:17 -08:00
|
|
|
CHECK(result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
} while (result == ISC_R_NOSPACE);
|
|
|
|
|
|
|
|
isc_buffer_usedregion(&target, &r);
|
|
|
|
printf("%.*s", (int)r.length, (char *)r.base);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (t != NULL) {
|
|
|
|
isc_mem_put(mctx, t, len);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2022-07-26 13:03:45 +02:00
|
|
|
setup_style(void) {
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
styleflags |= DNS_STYLEFLAG_REL_OWNER;
|
2019-07-20 17:24:41 -04:00
|
|
|
if (yaml) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_YAML;
|
|
|
|
} else {
|
|
|
|
if (showcomments) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_COMMENT;
|
|
|
|
}
|
|
|
|
if (print_unknown_format) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT;
|
|
|
|
}
|
|
|
|
if (rrcomments) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
|
|
|
|
}
|
|
|
|
if (nottl) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_NO_TTL;
|
|
|
|
}
|
|
|
|
if (noclass) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_NO_CLASS;
|
|
|
|
}
|
|
|
|
if (nocrypto) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_NOCRYPTO;
|
|
|
|
}
|
|
|
|
if (multiline) {
|
|
|
|
styleflags |= DNS_STYLEFLAG_MULTILINE;
|
|
|
|
styleflags |= DNS_STYLEFLAG_COMMENT;
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
2019-07-20 17:24:41 -04:00
|
|
|
if (multiline || (nottl && noclass)) {
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_stylecreate(&style, styleflags, 24, 24, 24,
|
|
|
|
32, 80, 8, splitwidth, mctx);
|
2019-07-20 17:24:41 -04:00
|
|
|
} else if (nottl || noclass) {
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_stylecreate(&style, styleflags, 24, 24, 32,
|
|
|
|
40, 80, 8, splitwidth, mctx);
|
2019-07-20 17:24:41 -04:00
|
|
|
} else {
|
2018-04-03 13:09:55 +02:00
|
|
|
result = dns_master_stylecreate(&style, styleflags, 24, 32, 40,
|
|
|
|
48, 80, 8, splitwidth, mctx);
|
2019-07-20 17:24:41 -04:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
convert_name(dns_fixedname_t *fn, dns_name_t **name, const char *text) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t b;
|
2023-01-31 13:30:12 -08:00
|
|
|
dns_name_t *n = NULL;
|
2014-02-26 19:00:05 -08:00
|
|
|
unsigned int len;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
REQUIRE(fn != NULL && name != NULL && text != NULL);
|
|
|
|
len = strlen(text);
|
|
|
|
|
|
|
|
isc_buffer_constinit(&b, text, len);
|
|
|
|
isc_buffer_add(&b, len);
|
2018-03-28 14:38:09 +02:00
|
|
|
n = dns_fixedname_initname(fn);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
result = dns_name_fromtext(n, &b, dns_rootname, 0, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2023-01-31 13:30:12 -08:00
|
|
|
delv_log(ISC_LOG_ERROR, "failed to convert name %s: %s", text,
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_totext(result));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
*name = n;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2023-01-31 13:30:12 -08:00
|
|
|
key_fromconfig(const cfg_obj_t *key, dns_client_t *client, dns_view_t *toview) {
|
2019-09-18 19:45:20 -07:00
|
|
|
dns_rdata_dnskey_t dnskey;
|
|
|
|
dns_rdata_ds_t ds;
|
2019-12-02 09:29:02 +01:00
|
|
|
uint32_t rdata1, rdata2, rdata3;
|
2019-09-18 19:45:20 -07:00
|
|
|
const char *datastr = NULL, *keynamestr = NULL, *atstr = NULL;
|
|
|
|
unsigned char data[4096];
|
|
|
|
isc_buffer_t databuf;
|
2014-02-16 13:03:17 -08:00
|
|
|
unsigned char rrdata[4096];
|
|
|
|
isc_buffer_t rrdatabuf;
|
|
|
|
isc_region_t r;
|
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *keyname;
|
|
|
|
isc_result_t result;
|
2019-08-06 09:34:27 -07:00
|
|
|
bool match_root = false;
|
2019-09-18 19:45:20 -07:00
|
|
|
enum {
|
|
|
|
INITIAL_KEY,
|
|
|
|
STATIC_KEY,
|
|
|
|
INITIAL_DS,
|
|
|
|
STATIC_DS,
|
|
|
|
TRUSTED
|
|
|
|
} anchortype;
|
2020-05-20 14:22:40 +10:00
|
|
|
const cfg_obj_t *obj;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
REQUIRE(client != NULL || toview != NULL);
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
keynamestr = cfg_obj_asstring(cfg_tuple_get(key, "name"));
|
|
|
|
CHECK(convert_name(&fkeyname, &keyname, keynamestr));
|
|
|
|
|
2019-08-06 09:34:27 -07:00
|
|
|
if (!root_validation) {
|
2014-02-16 13:03:17 -08:00
|
|
|
return ISC_R_SUCCESS;
|
2019-08-06 09:34:27 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-08-06 09:34:27 -07:00
|
|
|
if (anchor_name) {
|
2017-10-03 00:28:31 -07:00
|
|
|
match_root = dns_name_equal(keyname, anchor_name);
|
2019-08-06 09:34:27 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-08-06 09:34:27 -07:00
|
|
|
if (!match_root) {
|
2014-02-16 13:03:17 -08:00
|
|
|
return ISC_R_SUCCESS;
|
2019-08-06 09:34:27 -07:00
|
|
|
}
|
2019-09-09 14:05:31 +02:00
|
|
|
|
|
|
|
if (!root_validation) {
|
2014-02-16 13:03:17 -08:00
|
|
|
return ISC_R_SUCCESS;
|
2019-08-06 09:34:27 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-09-09 14:05:31 +02:00
|
|
|
delv_log(ISC_LOG_DEBUG(3), "adding trust anchor %s", trust_anchor);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-09-15 22:15:29 -07:00
|
|
|
/* if DNSKEY, flags; if DS, key tag */
|
2019-12-02 09:29:02 +01:00
|
|
|
rdata1 = cfg_obj_asuint32(cfg_tuple_get(key, "rdata1"));
|
2019-09-15 22:15:29 -07:00
|
|
|
|
|
|
|
/* if DNSKEY, protocol; if DS, algorithm */
|
2019-12-02 09:29:02 +01:00
|
|
|
rdata2 = cfg_obj_asuint32(cfg_tuple_get(key, "rdata2"));
|
2019-09-15 22:15:29 -07:00
|
|
|
|
|
|
|
/* if DNSKEY, algorithm; if DS, digest type */
|
2019-12-02 09:29:02 +01:00
|
|
|
rdata3 = cfg_obj_asuint32(cfg_tuple_get(key, "rdata3"));
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-09-18 19:45:20 -07:00
|
|
|
/* What type of trust anchor is this? */
|
2020-05-20 14:22:40 +10:00
|
|
|
obj = cfg_tuple_get(key, "anchortype");
|
|
|
|
if (cfg_obj_isvoid(obj)) {
|
|
|
|
/*
|
|
|
|
* "anchortype" is not defined, this must be a static-key
|
2024-12-06 16:30:04 +01:00
|
|
|
* configured with trust-anchors.
|
2020-05-20 14:22:40 +10:00
|
|
|
*/
|
2019-09-18 19:45:20 -07:00
|
|
|
anchortype = STATIC_KEY;
|
|
|
|
} else {
|
2020-05-20 14:22:40 +10:00
|
|
|
atstr = cfg_obj_asstring(obj);
|
|
|
|
if (strcasecmp(atstr, "static-key") == 0) {
|
|
|
|
anchortype = STATIC_KEY;
|
|
|
|
} else if (strcasecmp(atstr, "static-ds") == 0) {
|
|
|
|
anchortype = STATIC_DS;
|
|
|
|
} else if (strcasecmp(atstr, "initial-key") == 0) {
|
|
|
|
anchortype = INITIAL_KEY;
|
|
|
|
} else if (strcasecmp(atstr, "initial-ds") == 0) {
|
|
|
|
anchortype = INITIAL_DS;
|
|
|
|
} else {
|
|
|
|
delv_log(ISC_LOG_ERROR,
|
|
|
|
"key '%s': invalid initialization method '%s'",
|
|
|
|
keynamestr, atstr);
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2019-09-18 19:45:20 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-09-18 19:45:20 -07:00
|
|
|
isc_buffer_init(&databuf, data, sizeof(data));
|
|
|
|
isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-12-02 09:29:02 +01:00
|
|
|
if (rdata1 > 0xffff) {
|
2014-02-16 13:03:17 -08:00
|
|
|
CHECK(ISC_R_RANGE);
|
2019-09-15 22:15:29 -07:00
|
|
|
}
|
2019-12-02 09:29:02 +01:00
|
|
|
if (rdata2 > 0xff) {
|
2014-02-16 13:03:17 -08:00
|
|
|
CHECK(ISC_R_RANGE);
|
2019-09-15 22:15:29 -07:00
|
|
|
}
|
2019-12-02 09:29:02 +01:00
|
|
|
if (rdata3 > 0xff) {
|
2014-02-16 13:03:17 -08:00
|
|
|
CHECK(ISC_R_RANGE);
|
2019-09-15 22:15:29 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-09-18 19:45:20 -07:00
|
|
|
switch (anchortype) {
|
|
|
|
case STATIC_KEY:
|
|
|
|
case INITIAL_KEY:
|
|
|
|
case TRUSTED:
|
|
|
|
dnskey.common.rdclass = dns_rdataclass_in;
|
|
|
|
dnskey.common.rdtype = dns_rdatatype_dnskey;
|
|
|
|
dnskey.mctx = NULL;
|
|
|
|
|
|
|
|
ISC_LINK_INIT(&dnskey.common, link);
|
|
|
|
|
2019-12-02 09:29:02 +01:00
|
|
|
dnskey.flags = (uint16_t)rdata1;
|
|
|
|
dnskey.protocol = (uint8_t)rdata2;
|
|
|
|
dnskey.algorithm = (uint8_t)rdata3;
|
2019-09-18 19:45:20 -07:00
|
|
|
|
|
|
|
datastr = cfg_obj_asstring(cfg_tuple_get(key, "data"));
|
|
|
|
CHECK(isc_base64_decodestring(datastr, &databuf));
|
|
|
|
isc_buffer_usedregion(&databuf, &r);
|
|
|
|
dnskey.datalen = r.length;
|
|
|
|
dnskey.data = r.base;
|
|
|
|
|
|
|
|
CHECK(dns_rdata_fromstruct(NULL, dnskey.common.rdclass,
|
|
|
|
dnskey.common.rdtype, &dnskey,
|
|
|
|
&rrdatabuf));
|
2023-01-31 13:30:12 -08:00
|
|
|
if (client != NULL) {
|
|
|
|
CHECK(dns_client_addtrustedkey(
|
|
|
|
client, dns_rdataclass_in, dns_rdatatype_dnskey,
|
|
|
|
keyname, &rrdatabuf));
|
|
|
|
} else if (toview != NULL) {
|
|
|
|
CHECK(dns_view_addtrustedkey(toview,
|
|
|
|
dns_rdatatype_dnskey,
|
|
|
|
keyname, &rrdatabuf));
|
|
|
|
}
|
2019-09-18 19:45:20 -07:00
|
|
|
break;
|
|
|
|
case INITIAL_DS:
|
|
|
|
case STATIC_DS:
|
|
|
|
ds.common.rdclass = dns_rdataclass_in;
|
|
|
|
ds.common.rdtype = dns_rdatatype_ds;
|
|
|
|
ds.mctx = NULL;
|
|
|
|
|
|
|
|
ISC_LINK_INIT(&ds.common, link);
|
|
|
|
|
2019-12-02 09:29:02 +01:00
|
|
|
ds.key_tag = (uint16_t)rdata1;
|
|
|
|
ds.algorithm = (uint8_t)rdata2;
|
|
|
|
ds.digest_type = (uint8_t)rdata3;
|
2019-09-18 19:45:20 -07:00
|
|
|
|
|
|
|
datastr = cfg_obj_asstring(cfg_tuple_get(key, "data"));
|
|
|
|
CHECK(isc_hex_decodestring(datastr, &databuf));
|
|
|
|
isc_buffer_usedregion(&databuf, &r);
|
|
|
|
|
|
|
|
switch (ds.digest_type) {
|
|
|
|
case DNS_DSDIGEST_SHA1:
|
|
|
|
if (r.length != ISC_SHA1_DIGESTLENGTH) {
|
|
|
|
CHECK(ISC_R_UNEXPECTEDEND);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DNS_DSDIGEST_SHA256:
|
|
|
|
if (r.length != ISC_SHA256_DIGESTLENGTH) {
|
|
|
|
CHECK(ISC_R_UNEXPECTEDEND);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DNS_DSDIGEST_SHA384:
|
|
|
|
if (r.length != ISC_SHA384_DIGESTLENGTH) {
|
|
|
|
CHECK(ISC_R_UNEXPECTEDEND);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-09-18 19:45:20 -07:00
|
|
|
ds.length = r.length;
|
|
|
|
ds.digest = r.base;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2019-09-18 19:45:20 -07:00
|
|
|
CHECK(dns_rdata_fromstruct(NULL, ds.common.rdclass,
|
|
|
|
ds.common.rdtype, &ds, &rrdatabuf));
|
2023-01-31 13:30:12 -08:00
|
|
|
if (client != NULL) {
|
|
|
|
CHECK(dns_client_addtrustedkey(
|
|
|
|
client, dns_rdataclass_in, dns_rdatatype_ds,
|
|
|
|
keyname, &rrdatabuf));
|
|
|
|
} else if (toview != NULL) {
|
|
|
|
CHECK(dns_view_addtrustedkey(toview, dns_rdatatype_ds,
|
|
|
|
keyname, &rrdatabuf));
|
|
|
|
}
|
2019-09-18 19:45:20 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2018-10-05 12:00:42 -07:00
|
|
|
num_keys++;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (result == DST_R_NOCRYPTO) {
|
2024-08-13 18:20:26 +02:00
|
|
|
cfg_obj_log(key, ISC_LOG_ERROR, "no crypto support");
|
2014-02-16 13:03:17 -08:00
|
|
|
} else if (result == DST_R_UNSUPPORTEDALG) {
|
2024-08-13 18:20:26 +02:00
|
|
|
cfg_obj_log(key, ISC_LOG_WARNING,
|
2014-02-16 13:03:17 -08:00
|
|
|
"skipping trusted key '%s': %s", keynamestr,
|
|
|
|
isc_result_totext(result));
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
2024-08-13 18:20:26 +02:00
|
|
|
cfg_obj_log(key, ISC_LOG_ERROR,
|
2014-02-16 13:03:17 -08:00
|
|
|
"failed to add trusted key '%s': %s", keynamestr,
|
|
|
|
isc_result_totext(result));
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2023-01-31 13:30:12 -08:00
|
|
|
load_keys(const cfg_obj_t *keys, dns_client_t *client, dns_view_t *toview) {
|
2014-02-16 13:03:17 -08:00
|
|
|
const cfg_listelt_t *elt, *elt2;
|
|
|
|
const cfg_obj_t *key, *keylist;
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
for (elt = cfg_list_first(keys); elt != NULL; elt = cfg_list_next(elt))
|
|
|
|
{
|
|
|
|
keylist = cfg_listelt_value(elt);
|
|
|
|
|
|
|
|
for (elt2 = cfg_list_first(keylist); elt2 != NULL;
|
2022-11-02 19:33:14 +01:00
|
|
|
elt2 = cfg_list_next(elt2))
|
|
|
|
{
|
2014-02-16 13:03:17 -08:00
|
|
|
key = cfg_listelt_value(elt2);
|
2023-01-31 13:30:12 -08:00
|
|
|
CHECK(key_fromconfig(key, client, toview));
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (result == DST_R_NOCRYPTO) {
|
|
|
|
result = ISC_R_SUCCESS;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2023-01-31 13:30:12 -08:00
|
|
|
setup_dnsseckeys(dns_client_t *client, dns_view_t *toview) {
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_t result;
|
|
|
|
cfg_parser_t *parser = NULL;
|
2019-12-04 11:06:40 +01:00
|
|
|
const cfg_obj_t *trust_anchors = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
cfg_obj_t *bindkeys = NULL;
|
|
|
|
|
2019-08-06 09:34:27 -07:00
|
|
|
if (!root_validation) {
|
2014-02-16 13:03:17 -08:00
|
|
|
return ISC_R_SUCCESS;
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2014-10-02 22:36:50 -07:00
|
|
|
if (trust_anchor == NULL) {
|
2014-02-16 13:03:17 -08:00
|
|
|
trust_anchor = isc_mem_strdup(mctx, ".");
|
2014-10-02 22:36:50 -07:00
|
|
|
}
|
|
|
|
|
2018-10-05 12:00:42 -07:00
|
|
|
if (trust_anchor != NULL) {
|
2017-10-03 00:28:31 -07:00
|
|
|
CHECK(convert_name(&afn, &anchor_name, trust_anchor));
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2024-08-13 18:20:26 +02:00
|
|
|
CHECK(cfg_parser_create(mctx, &parser));
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2023-02-03 14:57:17 -08:00
|
|
|
if (anchorfile != NULL) {
|
|
|
|
if (access(anchorfile, R_OK) != 0) {
|
2014-02-16 13:03:17 -08:00
|
|
|
fatal("Unable to read key file '%s'", anchorfile);
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2023-02-03 14:57:17 -08:00
|
|
|
|
|
|
|
result = cfg_parse_file(parser, anchorfile, &cfg_type_bindkeys,
|
2014-02-16 13:03:17 -08:00
|
|
|
&bindkeys);
|
2018-10-05 12:00:42 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2023-02-03 14:57:17 -08:00
|
|
|
fatal("Unable to load keys from '%s'", anchorfile);
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2023-02-03 14:57:17 -08:00
|
|
|
} else {
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_buffer_t b;
|
|
|
|
|
|
|
|
isc_buffer_init(&b, anchortext, sizeof(anchortext) - 1);
|
|
|
|
isc_buffer_add(&b, sizeof(anchortext) - 1);
|
2022-08-11 11:41:30 +02:00
|
|
|
cfg_parser_reset(parser);
|
2019-01-21 20:03:45 -08:00
|
|
|
result = cfg_parse_buffer(parser, &b, NULL, 0,
|
|
|
|
&cfg_type_bindkeys, 0, &bindkeys);
|
2018-10-05 12:00:42 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2014-02-16 13:03:17 -08:00
|
|
|
fatal("Unable to parse built-in keys");
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSIST(bindkeys != NULL);
|
2019-12-04 11:06:40 +01:00
|
|
|
cfg_map_get(bindkeys, "trust-anchors", &trust_anchors);
|
|
|
|
if (trust_anchors != NULL) {
|
2023-01-31 13:30:12 -08:00
|
|
|
CHECK(load_keys(trust_anchors, client, toview));
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
2018-10-05 12:00:42 -07:00
|
|
|
if (num_keys == 0) {
|
2014-02-16 13:03:17 -08:00
|
|
|
fatal("No trusted keys were loaded");
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
cleanup:
|
2018-11-19 13:31:36 +00:00
|
|
|
if (bindkeys != NULL) {
|
|
|
|
cfg_obj_destroy(parser, &bindkeys);
|
|
|
|
}
|
|
|
|
if (parser != NULL) {
|
|
|
|
cfg_parser_destroy(&parser);
|
|
|
|
}
|
2018-10-05 12:00:42 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2014-04-23 11:14:12 -07:00
|
|
|
delv_log(ISC_LOG_ERROR, "setup_dnsseckeys: %s",
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_totext(result));
|
2018-10-05 12:00:42 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
addserver(dns_client_t *client) {
|
2023-01-31 13:30:12 -08:00
|
|
|
struct addrinfo hints, *res = NULL, *cur = NULL;
|
2016-06-28 21:25:30 -04:00
|
|
|
int gaierror;
|
2014-02-16 13:03:17 -08:00
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
2023-01-31 13:30:12 -08:00
|
|
|
isc_sockaddr_t *sa = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_sockaddrlist_t servers;
|
|
|
|
isc_result_t result;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
|
|
|
|
ISC_LIST_INIT(servers);
|
|
|
|
|
2017-08-21 09:18:13 +02:00
|
|
|
if (inet_pton(AF_INET, server, &in4) == 1) {
|
|
|
|
if (!use_ipv4) {
|
|
|
|
fatal("Use of IPv4 disabled by -6");
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
sa = isc_mem_get(mctx, sizeof(*sa));
|
|
|
|
ISC_LINK_INIT(sa, link);
|
|
|
|
isc_sockaddr_fromin(sa, &in4, destport);
|
|
|
|
ISC_LIST_APPEND(servers, sa, link);
|
2017-08-21 09:18:13 +02:00
|
|
|
} else if (inet_pton(AF_INET6, server, &in6) == 1) {
|
|
|
|
if (!use_ipv6) {
|
|
|
|
fatal("Use of IPv6 disabled by -4");
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
sa = isc_mem_get(mctx, sizeof(*sa));
|
|
|
|
ISC_LINK_INIT(sa, link);
|
|
|
|
isc_sockaddr_fromin6(sa, &in6, destport);
|
|
|
|
ISC_LIST_APPEND(servers, sa, link);
|
|
|
|
} else {
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
if (!use_ipv6) {
|
|
|
|
hints.ai_family = AF_INET;
|
|
|
|
} else if (!use_ipv4) {
|
|
|
|
hints.ai_family = AF_INET6;
|
|
|
|
} else {
|
|
|
|
hints.ai_family = AF_UNSPEC;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
hints.ai_socktype = SOCK_DGRAM;
|
|
|
|
hints.ai_protocol = IPPROTO_UDP;
|
2016-06-28 21:25:30 -04:00
|
|
|
gaierror = getaddrinfo(server, port, &hints, &res);
|
|
|
|
if (gaierror != 0) {
|
2014-02-16 13:03:17 -08:00
|
|
|
delv_log(ISC_LOG_ERROR, "getaddrinfo failed: %s",
|
2016-06-28 21:25:30 -04:00
|
|
|
gai_strerror(gaierror));
|
2014-02-16 13:03:17 -08:00
|
|
|
return ISC_R_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-02-18 02:07:37 +11:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
for (cur = res; cur != NULL; cur = cur->ai_next) {
|
|
|
|
if (cur->ai_family != AF_INET &&
|
2022-11-02 19:33:14 +01:00
|
|
|
cur->ai_family != AF_INET6)
|
|
|
|
{
|
2014-02-18 02:07:37 +11:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2022-08-26 11:58:51 +02:00
|
|
|
sa = isc_mem_get(mctx, sizeof(*sa));
|
|
|
|
*sa = (isc_sockaddr_t){
|
|
|
|
.length = (unsigned int)cur->ai_addrlen,
|
|
|
|
};
|
2014-02-16 13:03:17 -08:00
|
|
|
ISC_LINK_INIT(sa, link);
|
2014-02-18 02:07:37 +11:00
|
|
|
memmove(&sa->type, cur->ai_addr, cur->ai_addrlen);
|
2014-02-16 13:03:17 -08:00
|
|
|
ISC_LIST_APPEND(servers, sa, link);
|
|
|
|
}
|
2014-02-18 02:07:37 +11:00
|
|
|
freeaddrinfo(res);
|
|
|
|
CHECK(result);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(dns_client_setservers(client, dns_rdataclass_in, name, &servers));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
while (!ISC_LIST_EMPTY(servers)) {
|
|
|
|
sa = ISC_LIST_HEAD(servers);
|
|
|
|
ISC_LIST_UNLINK(servers, sa, link);
|
|
|
|
isc_mem_put(mctx, sa, sizeof(*sa));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2014-04-23 11:14:12 -07:00
|
|
|
delv_log(ISC_LOG_ERROR, "addserver: %s",
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
findserver(dns_client_t *client) {
|
|
|
|
isc_result_t result;
|
|
|
|
irs_resconf_t *resconf = NULL;
|
|
|
|
isc_sockaddrlist_t *nameservers;
|
2023-01-31 13:30:12 -08:00
|
|
|
isc_sockaddr_t *sa = NULL, *next = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
result = irs_resconf_load(mctx, "/etc/resolv.conf", &resconf);
|
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
|
2014-04-23 11:14:12 -07:00
|
|
|
delv_log(ISC_LOG_ERROR, "irs_resconf_load: %s",
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_totext(result));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get nameservers from resolv.conf */
|
|
|
|
nameservers = irs_resconf_getnameservers(resconf);
|
|
|
|
for (sa = ISC_LIST_HEAD(*nameservers); sa != NULL; sa = next) {
|
|
|
|
next = ISC_LIST_NEXT(sa, link);
|
2014-02-24 09:38:28 +11:00
|
|
|
|
|
|
|
/* Set destination port */
|
|
|
|
if (sa->type.sa.sa_family == AF_INET && use_ipv4) {
|
|
|
|
sa->type.sin.sin_port = htons(destport);
|
|
|
|
continue;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
2014-02-24 09:38:28 +11:00
|
|
|
if (sa->type.sa.sa_family == AF_INET6 && use_ipv6) {
|
|
|
|
sa->type.sin6.sin6_port = htons(destport);
|
|
|
|
continue;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
2014-02-24 09:38:28 +11:00
|
|
|
|
|
|
|
/* Incompatible protocol family */
|
|
|
|
ISC_LIST_UNLINK(*nameservers, sa, link);
|
|
|
|
isc_mem_put(mctx, sa, sizeof(*sa));
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* None found, use localhost */
|
|
|
|
if (ISC_LIST_EMPTY(*nameservers)) {
|
|
|
|
if (use_ipv4) {
|
|
|
|
struct in_addr localhost;
|
|
|
|
localhost.s_addr = htonl(INADDR_LOOPBACK);
|
|
|
|
sa = isc_mem_get(mctx, sizeof(*sa));
|
|
|
|
isc_sockaddr_fromin(sa, &localhost, destport);
|
|
|
|
|
|
|
|
ISC_LINK_INIT(sa, link);
|
|
|
|
ISC_LIST_APPEND(*nameservers, sa, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_ipv6) {
|
|
|
|
sa = isc_mem_get(mctx, sizeof(*sa));
|
2014-02-24 09:38:28 +11:00
|
|
|
isc_sockaddr_fromin6(sa, &in6addr_loopback, destport);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
ISC_LINK_INIT(sa, link);
|
|
|
|
ISC_LIST_APPEND(*nameservers, sa, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_client_setservers(client, dns_rdataclass_in, NULL,
|
|
|
|
nameservers);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2014-04-23 11:14:12 -07:00
|
|
|
delv_log(ISC_LOG_ERROR, "dns_client_setservers: %s",
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (resconf != NULL) {
|
|
|
|
irs_resconf_destroy(&resconf);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2018-03-28 14:19:37 +02:00
|
|
|
parse_uint(uint32_t *uip, const char *value, uint32_t max, const char *desc) {
|
|
|
|
uint32_t n;
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_result_t result = isc_parse_uint32(&n, value, 10);
|
|
|
|
if (result == ISC_R_SUCCESS && n > max) {
|
|
|
|
result = ISC_R_RANGE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf("invalid %s '%s': %s\n", desc, value,
|
|
|
|
isc_result_totext(result));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
*uip = n;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
plus_option(char *option) {
|
|
|
|
isc_result_t result;
|
2018-05-01 16:03:46 +10:00
|
|
|
char *cmd, *value, *last = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool state = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2018-05-01 16:03:46 +10:00
|
|
|
INSIST(option != NULL);
|
|
|
|
|
2018-03-21 21:08:29 +00:00
|
|
|
cmd = strtok_r(option, "=", &last);
|
2014-02-16 13:03:17 -08:00
|
|
|
if (cmd == NULL) {
|
2018-03-21 21:08:29 +00:00
|
|
|
printf(";; Invalid option %s\n", option);
|
2014-02-16 13:03:17 -08:00
|
|
|
return;
|
2018-04-12 18:42:39 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (strncasecmp(cmd, "no", 2) == 0) {
|
|
|
|
cmd += 2;
|
2018-04-17 08:29:14 -07:00
|
|
|
state = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
2018-03-21 21:08:29 +00:00
|
|
|
value = strtok_r(NULL, "\0", &last);
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
#define FULLCHECK(A) \
|
|
|
|
do { \
|
|
|
|
size_t _l = strlen(cmd); \
|
|
|
|
if (_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) \
|
|
|
|
goto invalid_option; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
switch (cmd[0]) {
|
|
|
|
case 'a': /* all */
|
|
|
|
FULLCHECK("all");
|
|
|
|
showcomments = state;
|
|
|
|
rrcomments = state;
|
|
|
|
showtrust = state;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
switch (cmd[1]) {
|
|
|
|
case 'd': /* cdflag */
|
|
|
|
FULLCHECK("cdflag");
|
|
|
|
cdflag = state;
|
|
|
|
break;
|
|
|
|
case 'l': /* class */
|
|
|
|
FULLCHECK("class");
|
2018-04-17 08:29:14 -07:00
|
|
|
noclass = !state;
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case 'o': /* comments */
|
|
|
|
FULLCHECK("comments");
|
|
|
|
showcomments = state;
|
|
|
|
break;
|
|
|
|
case 'r': /* crypto */
|
|
|
|
FULLCHECK("crypto");
|
2018-04-17 08:29:14 -07:00
|
|
|
nocrypto = !state;
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
switch (cmd[1]) {
|
|
|
|
case 'n': /* dnssec */
|
|
|
|
FULLCHECK("dnssec");
|
|
|
|
showdnssec = state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2023-03-24 17:50:32 -07:00
|
|
|
case 'h':
|
|
|
|
switch (cmd[1]) {
|
|
|
|
case 'i': /* hint */
|
|
|
|
if (state) {
|
|
|
|
if (value == NULL) {
|
|
|
|
fatal("+hint: must specify hint file");
|
|
|
|
}
|
|
|
|
hintfile = value;
|
|
|
|
} else {
|
|
|
|
hintfile = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
case 'm':
|
|
|
|
switch (cmd[1]) {
|
2024-11-11 14:06:28 +01:00
|
|
|
case 'a':
|
|
|
|
switch (cmd[3]) {
|
|
|
|
case 'q': /* maxqueries */
|
|
|
|
FULLCHECK("maxqueries");
|
|
|
|
if (value == NULL) {
|
|
|
|
goto need_value;
|
|
|
|
}
|
|
|
|
if (!state) {
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
result = parse_uint(&maxqueries, value,
|
|
|
|
UINT_MAX, "maxqueries");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Couldn't parse maxqueries");
|
|
|
|
}
|
|
|
|
if (maxqueries == 0) {
|
|
|
|
fatal("maxqueries must be nonzero");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't': /* maxtotalqueries */
|
|
|
|
FULLCHECK("maxtotalqueries");
|
|
|
|
if (value == NULL) {
|
|
|
|
goto need_value;
|
|
|
|
}
|
|
|
|
if (!state) {
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
result = parse_uint(&maxtotal, value, UINT_MAX,
|
|
|
|
"maxtotalqueries");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Couldn't parse maxtotalqueries");
|
|
|
|
}
|
|
|
|
if (maxtotal == 0) {
|
|
|
|
fatal("maxtotalqueries must be "
|
|
|
|
"nonzero");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2024-06-25 18:48:18 -07:00
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
case 't': /* mtrace */
|
2023-02-01 23:19:36 -08:00
|
|
|
FULLCHECK("mtrace");
|
2014-02-16 13:03:17 -08:00
|
|
|
message_trace = state;
|
|
|
|
if (state) {
|
|
|
|
resolve_trace = state;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case 'u': /* multiline */
|
|
|
|
FULLCHECK("multiline");
|
|
|
|
multiline = state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2023-01-31 13:30:12 -08:00
|
|
|
case 'n':
|
|
|
|
switch (cmd[1]) {
|
|
|
|
case 's': /* ns */
|
|
|
|
FULLCHECK("ns");
|
|
|
|
fulltrace = state;
|
|
|
|
if (state) {
|
|
|
|
message_trace = state;
|
2023-02-01 23:19:36 -08:00
|
|
|
send_trace = state;
|
2023-01-31 13:30:12 -08:00
|
|
|
resolve_trace = state;
|
2023-02-14 17:28:55 -08:00
|
|
|
logfp = stdout;
|
2023-01-31 13:30:12 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2023-03-03 00:46:36 -08:00
|
|
|
case 'q': /* qmin */
|
|
|
|
FULLCHECK("qmin");
|
|
|
|
if (state) {
|
|
|
|
if (value == NULL || strcasecmp(value, "relaxed") == 0)
|
|
|
|
{
|
|
|
|
qmin = true;
|
|
|
|
} else if (strcasecmp(value, "strict") == 0) {
|
|
|
|
qmin = true;
|
|
|
|
qmin_strict = true;
|
|
|
|
} else {
|
|
|
|
fatal("Invalid qmin option '%s': "
|
|
|
|
"use 'relaxed' or 'strict'\n",
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qmin = false;
|
|
|
|
qmin_strict = false;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
case 'r':
|
|
|
|
switch (cmd[1]) {
|
2024-06-25 18:48:18 -07:00
|
|
|
case 'e': /* restarts */
|
|
|
|
FULLCHECK("restarts");
|
|
|
|
if (value == NULL) {
|
|
|
|
goto need_value;
|
|
|
|
}
|
|
|
|
if (!state) {
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
result = parse_uint(&restarts, value, 255, "restarts");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Couldn't parse restarts");
|
|
|
|
}
|
|
|
|
if (restarts == 0) {
|
|
|
|
fatal("restarts must be between 1..255");
|
|
|
|
}
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
case 'o': /* root */
|
|
|
|
FULLCHECK("root");
|
|
|
|
if (state && no_sigs) {
|
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
root_validation = state;
|
2014-10-02 22:36:50 -07:00
|
|
|
if (value != NULL) {
|
2014-02-16 13:03:17 -08:00
|
|
|
trust_anchor = isc_mem_strdup(mctx, value);
|
2014-10-02 22:36:50 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case 'r': /* rrcomments */
|
|
|
|
FULLCHECK("rrcomments");
|
|
|
|
rrcomments = state;
|
|
|
|
break;
|
|
|
|
case 't': /* rtrace */
|
|
|
|
FULLCHECK("rtrace");
|
|
|
|
resolve_trace = state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
switch (cmd[1]) {
|
|
|
|
case 'h': /* short */
|
|
|
|
FULLCHECK("short");
|
|
|
|
short_form = state;
|
|
|
|
if (short_form) {
|
2018-04-17 08:29:14 -07:00
|
|
|
multiline = false;
|
|
|
|
showcomments = false;
|
|
|
|
showtrust = false;
|
|
|
|
showdnssec = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'p': /* split */
|
|
|
|
FULLCHECK("split");
|
|
|
|
if (value != NULL && !state) {
|
|
|
|
goto invalid_option;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (!state) {
|
|
|
|
splitwidth = 0;
|
|
|
|
break;
|
|
|
|
} else if (value == NULL) {
|
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
result = parse_uint(&splitwidth, value, 1023, "split");
|
|
|
|
if (splitwidth % 4 != 0) {
|
|
|
|
splitwidth = ((splitwidth + 3) / 4) * 4;
|
|
|
|
warn("split must be a multiple of 4; "
|
|
|
|
"adjusting to %d",
|
|
|
|
splitwidth);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* There is an adjustment done in the
|
|
|
|
* totext_<rrtype>() functions which causes
|
|
|
|
* splitwidth to shrink. This is okay when we're
|
|
|
|
* using the default width but incorrect in this
|
|
|
|
* case, so we correct for it
|
|
|
|
*/
|
|
|
|
if (splitwidth) {
|
|
|
|
splitwidth += 3;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Couldn't parse split");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
2023-02-01 23:19:36 -08:00
|
|
|
case 't': /* strace */
|
|
|
|
FULLCHECK("strace");
|
|
|
|
send_trace = state;
|
|
|
|
if (state) {
|
|
|
|
message_trace = state;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-09 15:38:34 +05:30
|
|
|
case 'u':
|
|
|
|
FULLCHECK("unknownformat");
|
|
|
|
print_unknown_format = state;
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
case 't':
|
|
|
|
switch (cmd[1]) {
|
2014-11-21 09:37:04 -08:00
|
|
|
case 'c': /* tcp */
|
|
|
|
FULLCHECK("tcp");
|
|
|
|
use_tcp = state;
|
|
|
|
break;
|
2023-01-31 13:30:12 -08:00
|
|
|
case 'r':
|
2023-02-14 16:56:51 -08:00
|
|
|
switch (cmd[2]) {
|
|
|
|
case 'a': /* trace */
|
|
|
|
FULLCHECK("trace");
|
|
|
|
fatal("Invalid argument +trace. For "
|
|
|
|
"delegation path tracing, use +ns.");
|
|
|
|
break;
|
|
|
|
case 'u': /* trust */
|
|
|
|
FULLCHECK("trust");
|
|
|
|
showtrust = state;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case 't': /* ttl */
|
|
|
|
FULLCHECK("ttl");
|
2018-04-17 08:29:14 -07:00
|
|
|
nottl = !state;
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto invalid_option;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'v': /* vtrace */
|
|
|
|
FULLCHECK("vtrace");
|
|
|
|
validator_trace = state;
|
|
|
|
if (state) {
|
|
|
|
resolve_trace = state;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
2019-07-20 17:24:41 -04:00
|
|
|
case 'y': /* yaml */
|
|
|
|
FULLCHECK("yaml");
|
|
|
|
yaml = state;
|
|
|
|
if (state) {
|
|
|
|
rrcomments = false;
|
|
|
|
}
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
default:
|
|
|
|
invalid_option:
|
2024-06-25 18:48:18 -07:00
|
|
|
need_value:
|
2014-02-16 13:03:17 -08:00
|
|
|
fprintf(stderr, "Invalid option: +%s\n", option);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* options: "46a:b:c:d:himp:q:t:vx:";
|
|
|
|
*/
|
2024-11-21 16:22:51 +11:00
|
|
|
static const char *single_dash_opts = "46Fhimv";
|
|
|
|
static const char *dash_opts = "46abcdFhimpqtvx";
|
2018-11-14 11:30:50 +11:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
static bool
|
|
|
|
dash_option(char *option, char *next, bool *open_type_class) {
|
2014-02-16 13:03:17 -08:00
|
|
|
char opt, *value;
|
|
|
|
isc_result_t result;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool value_from_next;
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_textregion_t tr;
|
|
|
|
dns_rdatatype_t rdtype;
|
|
|
|
dns_rdataclass_t rdclass;
|
|
|
|
char textname[MAXNAME];
|
|
|
|
struct in_addr in4;
|
|
|
|
struct in6_addr in6;
|
|
|
|
in_port_t srcport;
|
2018-03-28 14:19:37 +02:00
|
|
|
uint32_t num;
|
2014-02-16 13:03:17 -08:00
|
|
|
char *hash;
|
|
|
|
|
|
|
|
while (strpbrk(option, single_dash_opts) == &option[0]) {
|
|
|
|
/*
|
|
|
|
* Since the -[46himv] options do not take an argument,
|
|
|
|
* account for them (in any number and/or combination)
|
|
|
|
* if they appear as the first character(s) of a q-opt.
|
|
|
|
*/
|
|
|
|
opt = option[0];
|
|
|
|
switch (opt) {
|
|
|
|
case '4':
|
|
|
|
if (isc_net_probeipv4() != ISC_R_SUCCESS) {
|
|
|
|
fatal("IPv4 networking not available");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (use_ipv6) {
|
|
|
|
isc_net_disableipv6();
|
2018-04-17 08:29:14 -07:00
|
|
|
use_ipv6 = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
if (isc_net_probeipv6() != ISC_R_SUCCESS) {
|
|
|
|
fatal("IPv6 networking not available");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (use_ipv4) {
|
|
|
|
isc_net_disableipv4();
|
2018-04-17 08:29:14 -07:00
|
|
|
use_ipv4 = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
break;
|
2024-11-21 16:22:51 +11:00
|
|
|
case 'F': /* FIPS */
|
|
|
|
/* handled in preparse_args() */
|
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
case 'h':
|
|
|
|
usage();
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
2014-02-16 13:03:17 -08:00
|
|
|
case 'i':
|
2018-04-17 08:29:14 -07:00
|
|
|
no_sigs = true;
|
|
|
|
root_validation = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
/* handled in preparse_args() */
|
|
|
|
break;
|
|
|
|
case 'v':
|
2022-03-07 17:07:45 +00:00
|
|
|
printf("delv %s\n", PACKAGE_VERSION);
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
2014-02-16 13:03:17 -08:00
|
|
|
default:
|
2021-10-11 12:50:17 +02:00
|
|
|
UNREACHABLE();
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
if (strlen(option) > 1U) {
|
|
|
|
option = &option[1];
|
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
return false;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
opt = option[0];
|
|
|
|
if (strlen(option) > 1U) {
|
2018-04-17 08:29:14 -07:00
|
|
|
value_from_next = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
value = &option[1];
|
|
|
|
} else {
|
2018-04-17 08:29:14 -07:00
|
|
|
value_from_next = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
value = next;
|
|
|
|
}
|
|
|
|
if (value == NULL) {
|
|
|
|
goto invalid_option;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
switch (opt) {
|
|
|
|
case 'a':
|
|
|
|
anchorfile = isc_mem_strdup(mctx, value);
|
|
|
|
return value_from_next;
|
|
|
|
case 'b':
|
|
|
|
hash = strchr(value, '#');
|
|
|
|
if (hash != NULL) {
|
|
|
|
result = parse_uint(&num, hash + 1, 0xffff, "port");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Couldn't parse port number");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
srcport = num;
|
|
|
|
*hash = '\0';
|
|
|
|
} else {
|
|
|
|
srcport = 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
if (inet_pton(AF_INET, value, &in4) == 1) {
|
|
|
|
if (srcaddr4 != NULL) {
|
|
|
|
fatal("Only one local address per family "
|
|
|
|
"can be specified\n");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_sockaddr_fromin(&a4, &in4, srcport);
|
|
|
|
srcaddr4 = &a4;
|
|
|
|
} else if (inet_pton(AF_INET6, value, &in6) == 1) {
|
|
|
|
if (srcaddr6 != NULL) {
|
|
|
|
fatal("Only one local address per family "
|
|
|
|
"can be specified\n");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_sockaddr_fromin6(&a6, &in6, srcport);
|
|
|
|
srcaddr6 = &a6;
|
|
|
|
} else {
|
|
|
|
if (hash != NULL) {
|
|
|
|
*hash = '#';
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
fatal("Invalid address %s", value);
|
|
|
|
}
|
|
|
|
if (hash != NULL) {
|
|
|
|
*hash = '#';
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return value_from_next;
|
|
|
|
case 'c':
|
|
|
|
if (classset) {
|
|
|
|
warn("extra query class");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
*open_type_class = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
tr.base = value;
|
|
|
|
tr.length = strlen(value);
|
|
|
|
result = dns_rdataclass_fromtext(&rdclass,
|
|
|
|
(isc_textregion_t *)&tr);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2018-04-17 08:29:14 -07:00
|
|
|
classset = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
} else if (rdclass != dns_rdataclass_in) {
|
|
|
|
warn("ignoring non-IN query class");
|
|
|
|
} else {
|
|
|
|
warn("ignoring invalid class");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return value_from_next;
|
|
|
|
case 'd':
|
|
|
|
result = parse_uint(&num, value, 99, "debug level");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Couldn't parse debug level");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
loglevel = num;
|
|
|
|
return value_from_next;
|
|
|
|
case 'p':
|
|
|
|
port = value;
|
2023-01-31 13:30:12 -08:00
|
|
|
result = parse_uint(&destport, port, 0xffff, "port");
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Couldn't parse port number");
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return value_from_next;
|
|
|
|
case 'q':
|
2014-10-02 22:36:50 -07:00
|
|
|
if (curqname != NULL) {
|
2014-02-16 13:03:17 -08:00
|
|
|
warn("extra query name");
|
2014-10-02 22:36:50 -07:00
|
|
|
isc_mem_free(mctx, curqname);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
2014-10-02 22:36:50 -07:00
|
|
|
curqname = isc_mem_strdup(mctx, value);
|
2014-02-16 13:03:17 -08:00
|
|
|
return value_from_next;
|
|
|
|
case 't':
|
2018-04-17 08:29:14 -07:00
|
|
|
*open_type_class = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
tr.base = value;
|
|
|
|
tr.length = strlen(value);
|
|
|
|
result = dns_rdatatype_fromtext(&rdtype,
|
|
|
|
(isc_textregion_t *)&tr);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
if (typeset) {
|
|
|
|
warn("extra query type");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (rdtype == dns_rdatatype_ixfr ||
|
2022-11-02 19:33:14 +01:00
|
|
|
rdtype == dns_rdatatype_axfr)
|
|
|
|
{
|
2014-02-16 13:03:17 -08:00
|
|
|
fatal("Transfer not supported");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
qtype = rdtype;
|
2018-04-17 08:29:14 -07:00
|
|
|
typeset = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
} else {
|
|
|
|
warn("ignoring invalid type");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return value_from_next;
|
|
|
|
case 'x':
|
|
|
|
result = get_reverse(textname, sizeof(textname), value, false);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2014-10-02 22:36:50 -07:00
|
|
|
if (curqname != NULL) {
|
|
|
|
isc_mem_free(mctx, curqname);
|
2014-02-16 13:03:17 -08:00
|
|
|
warn("extra query name");
|
2014-10-02 22:36:50 -07:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
curqname = isc_mem_strdup(mctx, textname);
|
|
|
|
if (typeset) {
|
|
|
|
warn("extra query type");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
qtype = dns_rdatatype_ptr;
|
2018-04-17 08:29:14 -07:00
|
|
|
typeset = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Invalid IP address %s\n", value);
|
2024-02-07 14:50:38 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
return value_from_next;
|
|
|
|
invalid_option:
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Invalid option: -%s\n", option);
|
|
|
|
usage();
|
|
|
|
}
|
2021-10-11 12:50:17 +02:00
|
|
|
UNREACHABLE();
|
2018-04-17 08:29:14 -07:00
|
|
|
return false;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for -m first to determine whether to enable
|
|
|
|
* memory debugging when setting up the memory context.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
preparse_args(int argc, char **argv) {
|
2018-04-17 08:29:14 -07:00
|
|
|
bool ipv4only = false, ipv6only = false;
|
2014-02-16 13:03:17 -08:00
|
|
|
char *option;
|
|
|
|
|
|
|
|
for (argc--, argv++; argc > 0; argc--, argv++) {
|
2018-11-13 16:41:54 -08:00
|
|
|
if (argv[0][0] != '-') {
|
2014-02-16 13:03:17 -08:00
|
|
|
continue;
|
2018-11-13 16:41:54 -08:00
|
|
|
}
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
option = &argv[0][1];
|
|
|
|
while (strpbrk(option, single_dash_opts) == &option[0]) {
|
2017-08-16 11:10:24 +02:00
|
|
|
switch (option[0]) {
|
2024-11-21 16:22:51 +11:00
|
|
|
case 'F':
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
|
|
|
fips = OSSL_PROVIDER_load(NULL, "fips");
|
|
|
|
if (fips == NULL) {
|
|
|
|
ERR_clear_error();
|
|
|
|
fatal("Failed to load FIPS provider");
|
|
|
|
}
|
|
|
|
base = OSSL_PROVIDER_load(NULL, "base");
|
|
|
|
if (base == NULL) {
|
|
|
|
OSSL_PROVIDER_unload(fips);
|
|
|
|
ERR_clear_error();
|
|
|
|
fatal("Failed to load base provider");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Already in FIPS mode? */
|
|
|
|
if (isc_fips_mode()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (isc_fips_set_mode(1) != ISC_R_SUCCESS) {
|
|
|
|
fatal("setting FIPS mode failed");
|
|
|
|
}
|
|
|
|
break;
|
2017-08-16 11:10:24 +02:00
|
|
|
case 'm':
|
2014-02-16 13:03:17 -08:00
|
|
|
isc_mem_debugging = ISC_MEM_DEBUGTRACE |
|
|
|
|
ISC_MEM_DEBUGRECORD;
|
2017-08-16 11:10:24 +02:00
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
if (ipv6only) {
|
|
|
|
fatal("only one of -4 and -6 allowed");
|
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
ipv4only = true;
|
2017-08-16 11:10:24 +02:00
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
if (ipv4only) {
|
|
|
|
fatal("only one of -4 and -6 allowed");
|
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
ipv6only = true;
|
2017-08-16 11:10:24 +02:00
|
|
|
break;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
option = &option[1];
|
|
|
|
}
|
2018-11-13 16:41:54 -08:00
|
|
|
|
2018-11-14 11:30:50 +11:00
|
|
|
if (strlen(option) == 0U) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-13 16:41:54 -08:00
|
|
|
|
2018-11-14 11:30:50 +11:00
|
|
|
/* Look for dash value option. */
|
|
|
|
if (strpbrk(option, dash_opts) != &option[0] ||
|
2022-11-02 19:33:14 +01:00
|
|
|
strlen(option) > 1U)
|
|
|
|
{
|
2018-11-14 11:30:50 +11:00
|
|
|
/* Error or value in option. */
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-13 16:41:54 -08:00
|
|
|
|
2018-11-14 11:30:50 +11:00
|
|
|
/* Dash value is next argument so we need to skip it. */
|
2018-11-13 16:41:54 -08:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
2018-11-14 11:30:50 +11:00
|
|
|
/* Handle missing argument */
|
2018-11-13 16:41:54 -08:00
|
|
|
if (argc == 0) {
|
2018-11-14 11:30:50 +11:00
|
|
|
break;
|
2018-11-13 16:41:54 -08:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Argument parsing is based on dig, but simplified: only one
|
|
|
|
* QNAME/QCLASS/QTYPE tuple can be specified, and options have
|
2014-04-23 11:14:12 -07:00
|
|
|
* been removed that aren't applicable to delv. The interface
|
2014-02-16 13:03:17 -08:00
|
|
|
* should be familiar to dig users, however.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
parse_args(int argc, char **argv) {
|
|
|
|
isc_result_t result;
|
|
|
|
isc_textregion_t tr;
|
|
|
|
dns_rdatatype_t rdtype;
|
|
|
|
dns_rdataclass_t rdclass;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool open_type_class = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
for (; argc > 0; argc--, argv++) {
|
|
|
|
if (argv[0][0] == '@') {
|
|
|
|
server = &argv[0][1];
|
|
|
|
} else if (argv[0][0] == '+') {
|
|
|
|
plus_option(&argv[0][1]);
|
|
|
|
} else if (argv[0][0] == '-') {
|
|
|
|
if (argc <= 1) {
|
|
|
|
if (dash_option(&argv[0][1], NULL,
|
2022-11-02 19:33:14 +01:00
|
|
|
&open_type_class))
|
|
|
|
{
|
2014-02-16 13:03:17 -08:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (dash_option(&argv[0][1], argv[1],
|
2022-11-02 19:33:14 +01:00
|
|
|
&open_type_class))
|
|
|
|
{
|
2014-02-16 13:03:17 -08:00
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Anything which isn't an option
|
|
|
|
*/
|
|
|
|
if (open_type_class) {
|
|
|
|
tr.base = argv[0];
|
|
|
|
tr.length = strlen(argv[0]);
|
|
|
|
result = dns_rdatatype_fromtext(
|
|
|
|
&rdtype, (isc_textregion_t *)&tr);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
if (typeset) {
|
|
|
|
warn("extra query type");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (rdtype == dns_rdatatype_ixfr ||
|
2022-11-02 19:33:14 +01:00
|
|
|
rdtype == dns_rdatatype_axfr)
|
|
|
|
{
|
2014-02-16 13:03:17 -08:00
|
|
|
fatal("Transfer not supported");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
qtype = rdtype;
|
2018-04-17 08:29:14 -07:00
|
|
|
typeset = true;
|
2014-02-16 13:03:17 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result = dns_rdataclass_fromtext(
|
|
|
|
&rdclass, (isc_textregion_t *)&tr);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
if (classset) {
|
|
|
|
warn("extra query class");
|
|
|
|
} else if (rdclass != dns_rdataclass_in)
|
|
|
|
{
|
|
|
|
warn("ignoring non-IN "
|
|
|
|
"query class");
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 22:36:50 -07:00
|
|
|
if (curqname == NULL) {
|
|
|
|
curqname = isc_mem_strdup(mctx, argv[0]);
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 17:00:45 +01:00
|
|
|
/* check consistency */
|
|
|
|
if (qmin && !fulltrace) {
|
|
|
|
fatal("'+qmin' cannot be used without '+ns'");
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
/*
|
|
|
|
* If no qname or qtype specified, search for root/NS
|
|
|
|
* If no qtype specified, use A
|
|
|
|
*/
|
|
|
|
if (!typeset) {
|
|
|
|
qtype = dns_rdatatype_a;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
if (curqname == NULL) {
|
|
|
|
qname = isc_mem_strdup(mctx, ".");
|
2014-10-02 22:36:50 -07:00
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
if (!typeset) {
|
|
|
|
qtype = dns_rdatatype_ns;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
} else {
|
2014-10-02 22:36:50 -07:00
|
|
|
qname = curqname;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
append_str(const char *text, int len, char **p, char *end) {
|
|
|
|
if (len > end - *p) {
|
|
|
|
return ISC_R_NOSPACE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
memmove(*p, text, len);
|
|
|
|
*p += len;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
reverse_octets(const char *in, char **p, char *end) {
|
|
|
|
char *dot = strchr(in, '.');
|
|
|
|
int len;
|
|
|
|
if (dot != NULL) {
|
|
|
|
isc_result_t result;
|
|
|
|
result = reverse_octets(dot + 1, p, end);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return result;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
result = append_str(".", 1, p, end);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return result;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
len = (int)(dot - in);
|
|
|
|
} else {
|
|
|
|
len = strlen(in);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return append_str(in, len, p, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2018-04-17 08:29:14 -07:00
|
|
|
get_reverse(char *reverse, size_t len, char *value, bool strict) {
|
2014-02-16 13:03:17 -08:00
|
|
|
int r;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_netaddr_t addr;
|
|
|
|
|
|
|
|
addr.family = AF_INET6;
|
|
|
|
r = inet_pton(AF_INET6, value, &addr.type.in6);
|
|
|
|
if (r > 0) {
|
|
|
|
/* This is a valid IPv6 address. */
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
dns_name_t *name;
|
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
name = dns_fixedname_initname(&fname);
|
2022-12-07 19:58:40 +00:00
|
|
|
result = dns_byaddr_createptrname(&addr, name);
|
2014-02-16 13:03:17 -08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return result;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
dns_name_format(name, reverse, (unsigned int)len);
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Not a valid IPv6 address. Assume IPv4.
|
|
|
|
* If 'strict' is not set, construct the
|
|
|
|
* in-addr.arpa name by blindly reversing
|
|
|
|
* octets whether or not they look like integers,
|
|
|
|
* so that this can be used for RFC2317 names
|
|
|
|
* and such.
|
|
|
|
*/
|
|
|
|
char *p = reverse;
|
|
|
|
char *end = reverse + len;
|
|
|
|
if (strict && inet_pton(AF_INET, value, &addr.type.in) != 1) {
|
|
|
|
return DNS_R_BADDOTTEDQUAD;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
result = reverse_octets(value, &p, end);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return result;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
result = append_str(".in-addr.arpa.", 15, &p, end);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return result;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
static void
|
|
|
|
resolve_cb(dns_client_t *client, const dns_name_t *query_name,
|
|
|
|
dns_namelist_t *namelist, isc_result_t result) {
|
|
|
|
char namestr[DNS_NAME_FORMATSIZE];
|
|
|
|
dns_rdataset_t *rdataset;
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS && !yaml) {
|
|
|
|
delv_log(ISC_LOG_ERROR, "resolution failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yaml) {
|
|
|
|
printf("type: DELV_RESULT\n");
|
|
|
|
dns_name_format(query_name, namestr, sizeof(namestr));
|
|
|
|
printf("query_name: %s\n", namestr);
|
|
|
|
printf("status: %s\n", isc_result_totext(result));
|
|
|
|
printf("records:\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dns_name_t *response_name = ISC_LIST_HEAD(*namelist);
|
|
|
|
response_name != NULL;
|
|
|
|
response_name = ISC_LIST_NEXT(response_name, link))
|
|
|
|
{
|
|
|
|
for (rdataset = ISC_LIST_HEAD(response_name->list);
|
|
|
|
rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link))
|
|
|
|
{
|
2023-01-31 13:30:12 -08:00
|
|
|
printdata(rdataset, response_name);
|
2022-07-26 13:03:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_client_freeresanswer(client, namelist);
|
|
|
|
isc_mem_put(mctx, namelist, sizeof(*namelist));
|
|
|
|
|
|
|
|
dns_client_detach(&client);
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-01-31 13:30:12 -08:00
|
|
|
run_resolve(void *arg) {
|
|
|
|
dns_client_t *client = NULL;
|
|
|
|
dns_namelist_t *namelist = NULL;
|
2022-07-26 13:03:45 +02:00
|
|
|
unsigned int resopt;
|
|
|
|
isc_result_t result;
|
2023-01-31 13:30:12 -08:00
|
|
|
dns_name_t *query_name = NULL;
|
|
|
|
|
|
|
|
UNUSED(arg);
|
2022-07-26 13:03:45 +02:00
|
|
|
|
|
|
|
namelist = isc_mem_get(mctx, sizeof(*namelist));
|
|
|
|
ISC_LIST_INIT(*namelist);
|
|
|
|
|
|
|
|
/* Construct QNAME */
|
|
|
|
CHECK(convert_name(&qfn, &query_name, qname));
|
|
|
|
|
|
|
|
/* Set up resolution options */
|
|
|
|
resopt = DNS_CLIENTRESOPT_NOCDFLAG;
|
|
|
|
if (no_sigs) {
|
|
|
|
resopt |= DNS_CLIENTRESOPT_NODNSSEC;
|
|
|
|
}
|
|
|
|
if (!root_validation) {
|
|
|
|
resopt |= DNS_CLIENTRESOPT_NOVALIDATE;
|
|
|
|
}
|
|
|
|
if (cdflag) {
|
|
|
|
resopt &= ~DNS_CLIENTRESOPT_NOCDFLAG;
|
|
|
|
}
|
|
|
|
if (use_tcp) {
|
|
|
|
resopt |= DNS_CLIENTRESOPT_TCP;
|
|
|
|
}
|
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
/* Create client */
|
|
|
|
CHECK(dns_client_create(mctx, loopmgr, netmgr, 0, tlsctx_client_cache,
|
|
|
|
&client, srcaddr4, srcaddr6));
|
2024-06-25 18:48:18 -07:00
|
|
|
dns_client_setmaxrestarts(client, restarts);
|
2024-11-11 14:06:28 +01:00
|
|
|
dns_client_setmaxqueries(client, maxtotal);
|
2022-07-26 13:03:45 +02:00
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
/* Set the nameserver */
|
|
|
|
if (server != NULL) {
|
|
|
|
addserver(client);
|
|
|
|
} else {
|
|
|
|
findserver(client);
|
2022-07-26 13:03:45 +02:00
|
|
|
}
|
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
CHECK(setup_dnsseckeys(client, NULL));
|
|
|
|
|
|
|
|
/* Perform resolution */
|
|
|
|
CHECK(dns_client_resolve(client, query_name, dns_rdataclass_in, qtype,
|
|
|
|
resopt, namelist, resolve_cb));
|
2022-07-26 13:03:45 +02:00
|
|
|
return;
|
|
|
|
cleanup:
|
|
|
|
if (!yaml) {
|
|
|
|
delv_log(ISC_LOG_ERROR, "resolution failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_put(mctx, namelist, sizeof(*namelist));
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
|
|
|
|
|
|
|
dns_client_detach(&client);
|
|
|
|
}
|
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
static void
|
|
|
|
shutdown_server(void) {
|
|
|
|
if (requestmgr != NULL) {
|
2023-07-25 10:30:09 +02:00
|
|
|
dns_requestmgr_shutdown(requestmgr);
|
2023-01-31 13:30:12 -08:00
|
|
|
dns_requestmgr_detach(&requestmgr);
|
|
|
|
}
|
|
|
|
if (interfacemgr != NULL) {
|
|
|
|
ns_interfacemgr_shutdown(interfacemgr);
|
|
|
|
ns_interfacemgr_detach(&interfacemgr);
|
|
|
|
}
|
|
|
|
if (dispatch != NULL) {
|
|
|
|
dns_dispatch_detach(&dispatch);
|
|
|
|
}
|
|
|
|
if (dispatchmgr != NULL) {
|
|
|
|
dns_dispatchmgr_detach(&dispatchmgr);
|
|
|
|
}
|
|
|
|
if (sctx != NULL) {
|
|
|
|
ns_server_detach(&sctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_loopmgr_shutdown(loopmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recvresponse(void *arg) {
|
|
|
|
dns_request_t *request = (dns_request_t *)arg;
|
|
|
|
dns_message_t *query = dns_request_getarg(request);
|
|
|
|
isc_result_t result = dns_request_getresult(request);
|
|
|
|
dns_message_t *response = NULL;
|
2023-04-17 14:49:55 -07:00
|
|
|
dns_name_t *prev = NULL;
|
2023-01-31 13:30:12 -08:00
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("request event result: %s", isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
2023-09-22 15:00:40 +02:00
|
|
|
dns_message_create(mctx, NULL, NULL, DNS_MESSAGE_INTENTPARSE,
|
|
|
|
&response);
|
2023-01-31 13:30:12 -08:00
|
|
|
|
|
|
|
result = dns_request_getresponse(request, response,
|
|
|
|
DNS_MESSAGEPARSE_PRESERVEORDER);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("request response failed: %s", isc_result_totext(result));
|
|
|
|
}
|
|
|
|
if (response->rcode != dns_rcode_noerror) {
|
|
|
|
result = dns_result_fromrcode(response->rcode);
|
|
|
|
delv_log(ISC_LOG_INFO, "response code: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (result = dns_message_firstname(response, DNS_SECTION_ANSWER);
|
|
|
|
result == ISC_R_SUCCESS;
|
|
|
|
result = dns_message_nextname(response, DNS_SECTION_ANSWER))
|
|
|
|
{
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
dns_rdataset_t *rdataset = NULL;
|
2023-04-17 14:49:55 -07:00
|
|
|
dns_rdatatype_t prevtype = 0;
|
2023-01-31 13:30:12 -08:00
|
|
|
|
|
|
|
dns_message_currentname(response, DNS_SECTION_ANSWER, &name);
|
2023-04-17 14:49:55 -07:00
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL;
|
|
|
|
rdataset = ISC_LIST_NEXT(rdataset, link))
|
|
|
|
{
|
|
|
|
dns_rdataset_t rds, sigs;
|
|
|
|
int options = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The response message contains the answer the
|
|
|
|
* resolver found, but it doesn't contain the
|
2023-04-17 14:49:55 -07:00
|
|
|
* trust status. if we're not displaying that,
|
|
|
|
* fine, we can just print that version.
|
2023-01-31 13:30:12 -08:00
|
|
|
*/
|
|
|
|
if (!showtrust) {
|
|
|
|
printdata(rdataset, name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-04-17 14:49:55 -07:00
|
|
|
/*
|
|
|
|
* ... but if we are printing the trust status
|
|
|
|
* (which is the default behavior)), we'll need
|
|
|
|
* to retrieve a copy of the rdataset from the cache.
|
|
|
|
* if we do that for ever record, it will produce
|
|
|
|
* duplicate output, so we check here whether we've
|
|
|
|
* already printed this name and type.
|
|
|
|
*/
|
|
|
|
if (prev != NULL && dns_name_equal(prev, name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prev = name;
|
|
|
|
|
|
|
|
if (prevtype == rdataset->type) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prevtype = rdataset->type;
|
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
/* do the cache lookup */
|
|
|
|
if (rdataset->type == dns_rdatatype_rrsig) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_rdataset_init(&rds);
|
|
|
|
dns_rdataset_init(&sigs);
|
|
|
|
|
|
|
|
if (cdflag) {
|
|
|
|
options |= DNS_DBFIND_PENDINGOK;
|
|
|
|
}
|
|
|
|
result = dns_view_simplefind(view, name, rdataset->type,
|
|
|
|
0, options, false, &rds,
|
|
|
|
&sigs);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
printdata(&rds, name);
|
|
|
|
dns_rdataset_disassociate(&rds);
|
|
|
|
if (dns_rdataset_isassociated(&sigs)) {
|
|
|
|
printdata(&sigs, name);
|
|
|
|
dns_rdataset_disassociate(&sigs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
dns_message_detach(&query);
|
|
|
|
dns_message_detach(&response);
|
|
|
|
dns_request_destroy(&request);
|
|
|
|
|
2023-02-14 17:28:55 -08:00
|
|
|
dns_view_detach(&view);
|
2023-01-31 13:30:12 -08:00
|
|
|
shutdown_server();
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
accept_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
|
|
|
|
UNUSED(handle);
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sendquery(void *arg) {
|
|
|
|
isc_nmsocket_t *sock = (isc_nmsocket_t *)arg;
|
|
|
|
isc_sockaddr_t peer = isc_nmsocket_getaddr(sock);
|
|
|
|
isc_result_t result;
|
|
|
|
dns_message_t *message = NULL;
|
|
|
|
dns_name_t *query_name = NULL, *mname = NULL;
|
|
|
|
dns_rdataset_t *mrdataset = NULL;
|
|
|
|
dns_rdataset_t *opt = NULL;
|
|
|
|
dns_request_t *request = NULL;
|
|
|
|
|
|
|
|
/* Construct query message */
|
|
|
|
CHECK(convert_name(&qfn, &query_name, qname));
|
|
|
|
|
2023-09-22 15:00:40 +02:00
|
|
|
dns_message_create(mctx, NULL, NULL, DNS_MESSAGE_INTENTRENDER,
|
|
|
|
&message);
|
2023-01-31 13:30:12 -08:00
|
|
|
message->opcode = dns_opcode_query;
|
|
|
|
message->flags = DNS_MESSAGEFLAG_RD | DNS_MESSAGEFLAG_AD;
|
|
|
|
if (cdflag) {
|
|
|
|
message->flags |= DNS_MESSAGEFLAG_CD;
|
|
|
|
}
|
|
|
|
message->rdclass = dns_rdataclass_in;
|
|
|
|
message->id = (dns_messageid_t)isc_random16();
|
|
|
|
|
|
|
|
dns_message_gettempname(message, &mname);
|
|
|
|
dns_message_gettemprdataset(message, &mrdataset);
|
|
|
|
dns_name_clone(query_name, mname);
|
|
|
|
dns_rdataset_makequestion(mrdataset, dns_rdataclass_in, qtype);
|
|
|
|
ISC_LIST_APPEND(mname->list, mrdataset, link);
|
|
|
|
dns_message_addname(message, mname, DNS_SECTION_QUESTION);
|
|
|
|
mrdataset = NULL;
|
|
|
|
mname = NULL;
|
|
|
|
|
|
|
|
CHECK(dns_message_buildopt(message, &opt, 0, 0, DNS_MESSAGEEXTFLAG_DO,
|
|
|
|
NULL, 0));
|
|
|
|
CHECK(dns_message_setopt(message, opt));
|
|
|
|
|
2023-07-25 10:30:09 +02:00
|
|
|
CHECK(dns_requestmgr_create(mctx, loopmgr, dispatchmgr, NULL, NULL,
|
2023-01-31 13:30:12 -08:00
|
|
|
&requestmgr));
|
|
|
|
|
2023-02-14 17:28:55 -08:00
|
|
|
dns_view_attach(view, &(dns_view_t *){ NULL });
|
2023-01-31 13:30:12 -08:00
|
|
|
CHECK(dns_request_create(requestmgr, message, NULL, &peer, NULL, NULL,
|
2024-03-26 00:13:45 -07:00
|
|
|
DNS_REQUESTOPT_TCP, NULL, 1, 0, 0, isc_loop(),
|
|
|
|
recvresponse, message, &request));
|
2023-01-31 13:30:12 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (message != NULL) {
|
|
|
|
dns_message_detach(&message);
|
|
|
|
}
|
|
|
|
|
|
|
|
shutdown_server();
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
matchview(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
|
2024-03-25 11:07:47 +00:00
|
|
|
dns_message_t *message, dns_aclenv_t *env, ns_server_t *lsctx,
|
2024-05-08 18:42:48 +00:00
|
|
|
isc_loop_t *loop, isc_job_cb cb, void *cbarg,
|
|
|
|
isc_result_t *sigresultp, isc_result_t *viewpatchresultp,
|
|
|
|
dns_view_t **viewp) {
|
2023-01-31 13:30:12 -08:00
|
|
|
UNUSED(srcaddr);
|
|
|
|
UNUSED(destaddr);
|
|
|
|
UNUSED(message);
|
|
|
|
UNUSED(env);
|
2024-03-25 11:07:47 +00:00
|
|
|
UNUSED(lsctx);
|
2024-05-08 18:42:48 +00:00
|
|
|
UNUSED(loop);
|
|
|
|
UNUSED(cb);
|
|
|
|
UNUSED(cbarg);
|
2023-01-31 13:30:12 -08:00
|
|
|
UNUSED(sigresultp);
|
|
|
|
|
|
|
|
*viewp = view;
|
2024-05-08 18:42:48 +00:00
|
|
|
*viewpatchresultp = ISC_R_SUCCESS;
|
2023-01-31 13:30:12 -08:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_server(void *arg) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_cache_t *cache = NULL;
|
|
|
|
isc_sockaddr_t addr, any;
|
|
|
|
struct in_addr in;
|
|
|
|
|
|
|
|
UNUSED(arg);
|
|
|
|
|
2023-04-03 10:43:32 -07:00
|
|
|
RUNTIME_CHECK(inet_pton(AF_INET, "127.0.0.1", &in));
|
2023-01-31 13:30:12 -08:00
|
|
|
isc_sockaddr_fromin(&addr, &in, 0);
|
|
|
|
|
2023-06-26 11:09:26 +02:00
|
|
|
ns_server_create(mctx, matchview, &sctx);
|
2023-01-31 13:30:12 -08:00
|
|
|
|
2023-09-15 14:38:02 +02:00
|
|
|
CHECK(dns_dispatchmgr_create(mctx, loopmgr, netmgr, &dispatchmgr));
|
2023-01-31 13:30:12 -08:00
|
|
|
isc_sockaddr_any(&any);
|
|
|
|
CHECK(dns_dispatch_createudp(dispatchmgr, &any, &dispatch));
|
|
|
|
CHECK(ns_interfacemgr_create(mctx, sctx, loopmgr, netmgr, dispatchmgr,
|
2024-07-02 09:22:54 +02:00
|
|
|
NULL, &interfacemgr));
|
2023-01-31 13:30:12 -08:00
|
|
|
|
2024-11-14 19:51:29 +01:00
|
|
|
CHECK(dns_view_create(mctx, loopmgr, dispatchmgr, dns_rdataclass_in,
|
|
|
|
"_default", &view));
|
2024-03-27 11:32:25 +11:00
|
|
|
CHECK(dns_cache_create(loopmgr, dns_rdataclass_in, "", mctx, &cache));
|
2023-01-31 13:30:12 -08:00
|
|
|
dns_view_setcache(view, cache, false);
|
|
|
|
dns_cache_detach(&cache);
|
|
|
|
dns_view_setdstport(view, destport);
|
2024-06-25 18:48:18 -07:00
|
|
|
dns_view_setmaxrestarts(view, restarts);
|
2024-11-11 14:06:28 +01:00
|
|
|
dns_view_setmaxqueries(view, maxtotal);
|
2023-01-31 13:30:12 -08:00
|
|
|
|
2023-03-24 17:50:32 -07:00
|
|
|
CHECK(dns_rootns_create(mctx, dns_rdataclass_in, hintfile, &roothints));
|
2023-01-31 13:30:12 -08:00
|
|
|
dns_view_sethints(view, roothints);
|
|
|
|
dns_db_detach(&roothints);
|
|
|
|
|
2023-03-03 00:46:36 -08:00
|
|
|
view->qminimization = qmin;
|
|
|
|
view->qmin_strict = qmin_strict;
|
|
|
|
|
2023-04-15 14:49:45 -07:00
|
|
|
dns_view_initsecroots(view);
|
2023-01-31 13:30:12 -08:00
|
|
|
CHECK(setup_dnsseckeys(NULL, view));
|
|
|
|
|
2024-03-26 00:13:45 -07:00
|
|
|
CHECK(dns_view_createresolver(view, netmgr, 0, tlsctx_client_cache,
|
|
|
|
dispatch, NULL));
|
2024-06-25 18:48:18 -07:00
|
|
|
dns_resolver_setmaxqueries(view->resolver, maxqueries);
|
2023-01-31 13:30:12 -08:00
|
|
|
|
2023-06-26 10:58:30 +02:00
|
|
|
isc_stats_create(mctx, &resstats, dns_resstatscounter_max);
|
2023-01-31 13:30:12 -08:00
|
|
|
dns_resolver_setstats(view->resolver, resstats);
|
|
|
|
isc_stats_detach(&resstats);
|
|
|
|
|
2023-06-26 10:58:30 +02:00
|
|
|
dns_rdatatypestats_create(mctx, &resquerystats);
|
2023-01-31 13:30:12 -08:00
|
|
|
dns_resolver_setquerystats(view->resolver, resquerystats);
|
|
|
|
dns_stats_detach(&resquerystats);
|
|
|
|
|
|
|
|
dns_view_freeze(view);
|
|
|
|
|
|
|
|
ns_interface_create(interfacemgr, &addr, NULL, &ifp);
|
|
|
|
|
|
|
|
CHECK(isc_nm_listenstreamdns(netmgr, ISC_NM_LISTEN_ONE, &addr,
|
|
|
|
ns_client_request, ifp, accept_cb, ifp, 10,
|
2023-05-19 14:28:52 +03:00
|
|
|
NULL, NULL, ISC_NM_PROXY_NONE,
|
|
|
|
&ifp->tcplistensocket));
|
2023-01-31 13:30:12 -08:00
|
|
|
ifp->flags |= NS_INTERFACEFLAG_LISTENING;
|
2024-03-26 02:13:53 -07:00
|
|
|
isc_async_current(sendquery, ifp->tcplistensocket);
|
2023-01-31 13:30:12 -08:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
cleanup:
|
2023-03-24 17:50:32 -07:00
|
|
|
if (view != NULL) {
|
|
|
|
dns_view_detach(&view);
|
|
|
|
}
|
2023-01-31 13:30:12 -08:00
|
|
|
shutdown_server();
|
|
|
|
}
|
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
isc_result_t result;
|
2023-01-31 13:30:12 -08:00
|
|
|
isc_loop_t *loop = NULL;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
progname = argv[0];
|
2023-02-14 17:28:55 -08:00
|
|
|
logfp = stderr;
|
|
|
|
|
2017-08-16 11:10:24 +02:00
|
|
|
preparse_args(argc, argv);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2014-02-26 19:00:05 -08:00
|
|
|
argc--;
|
|
|
|
argv++;
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2022-10-29 14:22:56 -07:00
|
|
|
isc_managers_create(&mctx, 1, &loopmgr, &netmgr);
|
2023-01-31 13:30:12 -08:00
|
|
|
loop = isc_loop_main(loopmgr);
|
2021-09-15 01:40:31 -07:00
|
|
|
|
2014-02-16 13:03:17 -08:00
|
|
|
parse_args(argc, argv);
|
|
|
|
|
2022-07-26 13:03:45 +02:00
|
|
|
CHECK(setup_style());
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2023-02-14 17:28:55 -08:00
|
|
|
setup_logging(logfp);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2023-03-24 17:50:32 -07:00
|
|
|
if (!fulltrace && hintfile != NULL) {
|
|
|
|
delv_log(ISC_LOG_WARNING,
|
|
|
|
"WARNING: not using internal name server mode, "
|
|
|
|
"hint file will be ignored");
|
|
|
|
}
|
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
if (fulltrace && server != NULL) {
|
|
|
|
delv_log(ISC_LOG_WARNING,
|
|
|
|
"WARNING: using internal name server mode: "
|
|
|
|
"'@%s' will be ignored",
|
|
|
|
server);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
isc_tlsctx_cache_create(mctx, &tlsctx_client_cache);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
2023-01-31 13:30:12 -08:00
|
|
|
isc_loop_setup(loop, fulltrace ? run_server : run_resolve, NULL);
|
2022-07-26 13:03:45 +02:00
|
|
|
isc_loopmgr_run(loopmgr);
|
2014-02-16 13:03:17 -08:00
|
|
|
|
|
|
|
cleanup:
|
2023-01-31 13:30:12 -08:00
|
|
|
if (tlsctx_client_cache != NULL) {
|
|
|
|
isc_tlsctx_cache_detach(&tlsctx_client_cache);
|
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (trust_anchor != NULL) {
|
|
|
|
isc_mem_free(mctx, trust_anchor);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (anchorfile != NULL) {
|
|
|
|
isc_mem_free(mctx, anchorfile);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (qname != NULL) {
|
|
|
|
isc_mem_free(mctx, qname);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-02-16 13:03:17 -08:00
|
|
|
if (style != NULL) {
|
|
|
|
dns_master_styledestroy(&style, mctx);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2021-01-14 13:02:57 -08:00
|
|
|
|
2022-10-29 14:22:56 -07:00
|
|
|
isc_managers_destroy(&mctx, &loopmgr, &netmgr);
|
2022-07-26 13:03:45 +02:00
|
|
|
|
2024-11-21 16:22:51 +11:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
|
|
|
if (base != NULL) {
|
|
|
|
OSSL_PROVIDER_unload(base);
|
|
|
|
}
|
|
|
|
if (fips != NULL) {
|
|
|
|
OSSL_PROVIDER_unload(fips);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-19 07:15:27 +11:00
|
|
|
return 0;
|
2014-02-16 13:03:17 -08:00
|
|
|
}
|