diff options
Diffstat (limited to 'sbin/unwind/resolver.c')
-rw-r--r-- | sbin/unwind/resolver.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c index d8b742c205a..708d5485f4a 100644 --- a/sbin/unwind/resolver.c +++ b/sbin/unwind/resolver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolver.c,v 1.2 2019/01/24 15:32:08 florian Exp $ */ +/* $OpenBSD: resolver.c,v 1.3 2019/01/24 15:33:44 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -28,7 +28,6 @@ #include <netinet/in.h> #include <net/if.h> #include <arpa/inet.h> -#include <arpa/nameser.h> #include <errno.h> #include <event.h> @@ -43,17 +42,22 @@ #include <time.h> #include <unistd.h> -#include <unbound.h> -#include <unbound-event.h> +#include <assert.h> +#include "libunbound/config.h" +#include "libunbound/libunbound/unbound.h" +#include "libunbound/unbound-event.h" +#include "libunbound/sldns/rrdef.h" +#include "libunbound/sldns/pkthdr.h" +#include "libunbound/sldns/sbuffer.h" +#include "libunbound/sldns/wire2str.h" #include <openssl/crypto.h> -#include "asr_private.h" #include "uw_log.h" #include "unwind.h" #include "resolver.h" -#define CHROOT_DIR "/etc/unwind" +#define CHROOT "/etc/unwind" #define DB_DIR "/trustanchor/" #define ROOT_KEY DB_DIR"root.key" @@ -163,7 +167,7 @@ resolver(int debug, int verbose) if ((pw = getpwnam(UNWIND_USER)) == NULL) fatal("getpwnam"); - if (chroot(CHROOT_DIR) == -1) + if (chroot(CHROOT) == -1) fatal("chroot"); if (chdir("/") == -1) fatal("chdir(\"/\")"); @@ -474,11 +478,10 @@ resolve_done(void *arg, int rcode, void *answer_packet, int answer_len, { struct query_imsg *query_imsg; struct unwind_resolver *res; - struct asr_unpack p; - struct asr_dns_header h; struct timespec tp, elapsed; int64_t ms; size_t i; + char *str; clock_gettime(CLOCK_MONOTONIC, &tp); @@ -504,19 +507,22 @@ resolve_done(void *arg, int rcode, void *answer_packet, int answer_len, log_debug("%s: rcode: %d", __func__, rcode); - _asr_unpack_init(&p, answer_packet, answer_len); - - if (_asr_unpack_header(&p, &h) == -1) { - log_warnx("bad packet: %s", strerror(p.err)); + if (answer_len < LDNS_HEADER_SIZE) { + log_warnx("bad packet: too short"); goto servfail; } - if (rcode == SERVFAIL) { + if (rcode == LDNS_RCODE_SERVFAIL) { if (res->stop != 1) check_resolver(res); goto servfail; } + if ((str = sldns_wire2str_pkt(answer_packet, answer_len)) != NULL) { + log_debug("%s", str); + free(str); + } + query_imsg->err = 0; if (res->state == VALIDATING) @@ -748,7 +754,8 @@ check_resolver(struct unwind_resolver *res) data->check_res = check_res; data->res = res; - if ((err = ub_resolve_event(check_res->ctx, ".", T_NS, C_IN, data, + if ((err = ub_resolve_event(check_res->ctx, ".", LDNS_RR_TYPE_NS, + LDNS_RR_CLASS_IN, data, check_resolver_done, NULL)) != 0) { log_warn("%s: ub_resolve_event: err: %d, %s", __func__, err, ub_strerror(err)); @@ -763,26 +770,28 @@ check_resolver_done(void *arg, int rcode, void *answer_packet, int answer_len, int sec, char *why_bogus, int was_ratelimited) { struct check_resolver_data *data; - struct asr_unpack p; - struct asr_dns_header h; + char *str; data = (struct check_resolver_data *)arg; log_debug("%s: rcode: %d", __func__, rcode); - _asr_unpack_init(&p, answer_packet, answer_len); - - if (_asr_unpack_header(&p, &h) == -1) { + if (answer_len < LDNS_HEADER_SIZE) { data->res->state = DEAD; - log_warnx("bad packet: %s", strerror(p.err)); + log_warnx("bad packet: too short"); goto out; } - if (rcode == SERVFAIL) { + if (rcode == LDNS_RCODE_SERVFAIL) { data->res->state = DEAD; goto out; } + if ((str = sldns_wire2str_pkt(answer_packet, answer_len)) != NULL) { + log_debug("%s", str); + free(str); + } + if (sec == 2) data->res->state = VALIDATING; else if (rcode == 0) { |