Commit 4d864b4c authored by Vladimír Čunát's avatar Vladimír Čunát

kr_zonecut_move(): new function

It's more efficient for some our use cases,
and hopefully also more idiomatic.
parent 8d9e9f8e
...@@ -246,13 +246,13 @@ static int ns_fetch_cut(struct kr_query *qry, const knot_dname_t *requested_name ...@@ -246,13 +246,13 @@ static int ns_fetch_cut(struct kr_query *qry, const knot_dname_t *requested_name
if (ret == kr_error(ENOENT)) { if (ret == kr_error(ENOENT)) {
/* No cached cut found, start from SBELT /* No cached cut found, start from SBELT
* and issue priming query. */ * and issue priming query. */
kr_zonecut_deinit(&cut_found);
ret = kr_zonecut_set_sbelt(req->ctx, &qry->zone_cut); ret = kr_zonecut_set_sbelt(req->ctx, &qry->zone_cut);
if (ret != 0) { if (ret != 0) {
return KR_STATE_FAIL; return KR_STATE_FAIL;
} }
VERBOSE_MSG(qry, "=> using root hints\n"); VERBOSE_MSG(qry, "=> using root hints\n");
qry->flags.AWAIT_CUT = false; qry->flags.AWAIT_CUT = false;
kr_zonecut_deinit(&cut_found);
return KR_STATE_DONE; return KR_STATE_DONE;
} else if (ret != kr_ok()) { } else if (ret != kr_ok()) {
kr_zonecut_deinit(&cut_found); kr_zonecut_deinit(&cut_found);
...@@ -295,12 +295,8 @@ static int ns_fetch_cut(struct kr_query *qry, const knot_dname_t *requested_name ...@@ -295,12 +295,8 @@ static int ns_fetch_cut(struct kr_query *qry, const knot_dname_t *requested_name
qry->flags.AWAIT_CUT = false; qry->flags.AWAIT_CUT = false;
return KR_STATE_DONE; return KR_STATE_DONE;
} }
/* Copy fetched name */ /* Use the found zone cut. */
qry->zone_cut.name = knot_dname_copy(cut_found.name, qry->zone_cut.pool); kr_zonecut_move(&qry->zone_cut, &cut_found);
/* Copy fetched address set */
kr_zonecut_copy(&qry->zone_cut, &cut_found);
/* Copy fetched ta & keys */
kr_zonecut_copy_trust(&qry->zone_cut, &cut_found);
/* Check if there's a non-terminal between target and current cut. */ /* Check if there's a non-terminal between target and current cut. */
struct kr_cache *cache = &req->ctx->cache; struct kr_cache *cache = &req->ctx->cache;
check_empty_nonterms(qry, pkt, cache, qry->timestamp.tv_sec); check_empty_nonterms(qry, pkt, cache, qry->timestamp.tv_sec);
......
...@@ -98,6 +98,13 @@ void kr_zonecut_deinit(struct kr_zonecut *cut) ...@@ -98,6 +98,13 @@ void kr_zonecut_deinit(struct kr_zonecut *cut)
knot_rrset_free(cut->trust_anchor, cut->pool); knot_rrset_free(cut->trust_anchor, cut->pool);
} }
void kr_zonecut_move(struct kr_zonecut *to, const struct kr_zonecut *from)
{
if (!to || !from) abort();
kr_zonecut_deinit(to);
memcpy(to, from, sizeof(*to));
}
void kr_zonecut_set(struct kr_zonecut *cut, const knot_dname_t *name) void kr_zonecut_set(struct kr_zonecut *cut, const knot_dname_t *name)
{ {
if (!cut || !name) { if (!cut || !name) {
......
...@@ -53,6 +53,14 @@ int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, knot_mm_t ...@@ -53,6 +53,14 @@ int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, knot_mm_t
KR_EXPORT KR_EXPORT
void kr_zonecut_deinit(struct kr_zonecut *cut); void kr_zonecut_deinit(struct kr_zonecut *cut);
/**
* Move a zonecut, transferring ownership of any pointed-to memory.
* @param to the target - it gets deinit-ed
* @param from the source - not modified, but shouldn't be used afterward
*/
KR_EXPORT
void kr_zonecut_move(struct kr_zonecut *to, const struct kr_zonecut *from);
/** /**
* Reset zone cut to given name and clear address list. * Reset zone cut to given name and clear address list.
* @note This clears the address list even if the name doesn't change. TA and DNSKEY don't change. * @note This clears the address list even if the name doesn't change. TA and DNSKEY don't change.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment