Skip to content

Commit

Permalink
req: don't compute presentation format until it's needed by unbound
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Sep 28, 2022
1 parent bf6108b commit e307bb7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/req.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions src/req.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
8 changes: 1 addition & 7 deletions src/rs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/rs_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -468,15 +468,22 @@ 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.
hsk_rs_pending_remove(worker->rs_pending, rsp);
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rs_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e307bb7

Please sign in to comment.