diff --git a/src/req.c b/src/req.c index 554447df..65d07c48 100644 --- a/src/req.c +++ b/src/req.c @@ -31,7 +31,6 @@ hsk_dns_req_init(hsk_dns_req_t *req) { req->edns = false; req->dnssec = false; memset(req->tld, 0x00, sizeof(req->tld)); - memset(req->namestr, 0x00, sizeof(req->namestr)); memset(&req->ss, 0x00, sizeof(struct sockaddr_storage)); req->addr = (struct sockaddr *)&req->ss; } diff --git a/src/req.h b/src/req.h index 020e7443..f9639b6f 100644 --- a/src/req.h +++ b/src/req.h @@ -27,9 +27,6 @@ typedef struct { size_t max_size; bool dnssec; - // For Unbound - char namestr[HSK_DNS_MAX_NAME_STRING]; - // HSK stuff uint8_t tld[HSK_DNS_MAX_LABEL + 2]; diff --git a/src/rs.c b/src/rs.c index fe92062d..70769569 100644 --- a/src/rs.c +++ b/src/rs.c @@ -377,15 +377,9 @@ hsk_rs_onrecv( goto fail; } - // Unbound's name resolution API expects a single null-terminated string. - // Since 0x00 is a valid byte mid-label in wire format we need to - // convert `req->name` to presentation format (i.e. "\000" for 0x00) - if (!hsk_dns_name_to_string(req->name, req->namestr)) - goto fail; - rc = hsk_rs_worker_resolve( ns->rs_worker, - req->namestr, + req->name, req->type, req->class, (void *)req, diff --git a/src/rs_worker.c b/src/rs_worker.c index f3bf950a..aae10d6f 100644 --- a/src/rs_worker.c +++ b/src/rs_worker.c @@ -444,7 +444,7 @@ hsk_rs_worker_free(hsk_rs_worker_t *worker) { } int -hsk_rs_worker_resolve(hsk_rs_worker_t *worker, char *name, int rrtype, +hsk_rs_worker_resolve(hsk_rs_worker_t *worker, uint8_t *name, int rrtype, int rrclass, void *data, ub_callback_type callback) { if (!callback) return HSK_EBADARGS; @@ -468,7 +468,14 @@ hsk_rs_worker_resolve(hsk_rs_worker_t *worker, char *name, int rrtype, // avoid racing with the callback. hsk_rs_pending_enqueue(worker->rs_pending, rsp); - int rc = ub_resolve_async(worker->ub, name, rrtype, rrclass, (void *)rsp, + // Unbound's name resolution API expects a single null-terminated string. + // Since 0x00 is a valid byte mid-label in wire format we need to + // convert `req->name` to presentation format (i.e. "\000" for 0x00) + char namestr[HSK_DNS_MAX_NAME_STRING]; + if (!hsk_dns_name_to_string(name, namestr)) + return HSK_EFAILURE; + + int rc = ub_resolve_async(worker->ub, namestr, rrtype, rrclass, (void *)rsp, after_resolve_onthread, &rsp->async_id); if (rc) { // Remove the response since it couldn't be sent. @@ -476,7 +483,7 @@ hsk_rs_worker_resolve(hsk_rs_worker_t *worker, char *name, int rrtype, hsk_rs_worker_log(worker, "unbound error: %s\n", ub_strerror(rc)); return HSK_EFAILURE; } - hsk_rs_worker_log(worker, "request %d: %s\n", rsp->async_id, name); + hsk_rs_worker_log(worker, "request %d: %s\n", rsp->async_id, namestr); return HSK_SUCCESS; } diff --git a/src/rs_worker.h b/src/rs_worker.h index d68afefd..29f7a046 100644 --- a/src/rs_worker.h +++ b/src/rs_worker.h @@ -144,7 +144,7 @@ hsk_rs_worker_close(hsk_rs_worker_t *worker); // to libunbound. The result callback occurs in the libuv event loop. When the // callback occurs, ownership of the ub_result is passed to the callback. int -hsk_rs_worker_resolve(hsk_rs_worker_t *worker, char *name, int rrtype, +hsk_rs_worker_resolve(hsk_rs_worker_t *worker, uint8_t *name, int rrtype, int rrclass, void *data, ub_callback_type callback); #endif