Commit a8110642 authored by Karel Slaný's avatar Karel Slaný

lib/zonecut: implemented function for trust anchor copying

parent 453150e3
......@@ -499,7 +499,7 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
if (want_secured && !qry->zone_cut.key && qry->stype != KNOT_RRTYPE_DNSKEY) {
struct kr_query *next = kr_rplan_push(rplan, qry, qry->zone_cut.name, KNOT_CLASS_IN, KNOT_RRTYPE_DNSKEY);
if (!next) {
return kr_error(ENOMEM);
return KNOT_STATE_FAIL;
}
next->flags |= QUERY_AWAIT_CUT;
return KNOT_STATE_PRODUCE;
......@@ -516,11 +516,16 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
if (want_secured && !qry->zone_cut.key && qry->stype != KNOT_RRTYPE_DNSKEY) {
struct kr_query *next = kr_rplan_push(rplan, qry, qry->zone_cut.name, KNOT_CLASS_IN, KNOT_RRTYPE_DNSKEY);
if (!next) {
return kr_error(ENOMEM);
return KNOT_STATE_FAIL;
}
int ret = kr_zonecut_copy_whole(&next->zone_cut, &qry->zone_cut);
kr_zonecut_set(&next->zone_cut, qry->zone_cut.name);
int ret = kr_zonecut_copy(&next->zone_cut, &qry->zone_cut);
if (ret != 0) {
return ret;
return KNOT_STATE_FAIL;
}
ret = kr_zonecut_copy_trust(&next->zone_cut, &qry->zone_cut);
if (ret != 0) {
return KNOT_STATE_FAIL;
}
return KNOT_STATE_PRODUCE;
}
......
......@@ -153,55 +153,32 @@ int kr_zonecut_copy(struct kr_zonecut *dst, const struct kr_zonecut *src)
return map_walk((map_t *)&src->nsset, copy_addr_set, dst);
}
int kr_zonecut_copy_whole(struct kr_zonecut *dst, const struct kr_zonecut *src)
int kr_zonecut_copy_trust(struct kr_zonecut *dst, const struct kr_zonecut *src)
{
if (!dst || !src) {
return kr_error(EINVAL);
}
kr_zonecut_deinit(dst);
memset(dst, 0, sizeof(*dst));
int ret;
dst->pool = src->pool;
dst->nsset = map_make();
dst->nsset.malloc = (map_alloc_f) mm_alloc;
dst->nsset.free = (map_free_f) mm_free;
dst->nsset.baton = dst->pool;
dst->name = knot_dname_copy(src->name, dst->pool);
if (!dst->name) {
ret = kr_error(ENOMEM);
goto fail;
}
ret = map_walk((map_t *)&src->nsset, copy_addr_set, dst);
if (ret != 0) {
goto fail;
}
knot_rrset_t *key_copy = NULL;
knot_rrset_t *ta_copy = NULL;
if (src->key) {
dst->key = knot_rrset_copy(src->key, dst->pool);
if (!dst->key) {
ret = kr_error(ENOMEM);
goto fail;
key_copy = knot_rrset_copy(src->key, dst->pool);
if (!key_copy) {
return kr_error(ENOMEM);
}
}
if (src->trust_anchor) {
dst->trust_anchor = knot_rrset_copy(src->trust_anchor, dst->pool);
if (!dst->trust_anchor) {
ret = kr_error(ENOMEM);
goto fail;
ta_copy = knot_rrset_copy(src->trust_anchor, dst->pool);
if (!ta_copy) {
knot_rrset_free(&key_copy, dst->pool);
return kr_error(ENOMEM);
}
}
return kr_ok();
knot_rrset_free(&dst->key, dst->pool);
dst->key = key_copy;
knot_rrset_free(&dst->trust_anchor, dst->pool);
dst->trust_anchor = ta_copy;
fail:
kr_zonecut_deinit(dst);
memset(dst, 0, sizeof(*dst));
return ret;
return kr_ok();
}
/** @internal Filter ANY or loopback addresses. */
......
......@@ -58,7 +58,7 @@ void kr_zonecut_deinit(struct kr_zonecut *cut);
void kr_zonecut_set(struct kr_zonecut *cut, const knot_dname_t *name);
/**
* Copy zone cut, including all data.
* Copy zone cut, including all data. Does not copy keys and trust anchor.
* @param dst destination zone cut
* @param src source zone cut
* @return 0 or an error code
......@@ -66,12 +66,12 @@ void kr_zonecut_set(struct kr_zonecut *cut, const knot_dname_t *name);
int kr_zonecut_copy(struct kr_zonecut *dst, const struct kr_zonecut *src);
/**
* Copy zone cut, including all data, really.
* Copy zone trust anchor and keys.
* @param dst destination zone cut
* @param src source zone cut
* @return 0 or an error code
*/
int kr_zonecut_copy_whole(struct kr_zonecut *dst, const struct kr_zonecut *src);
int kr_zonecut_copy_trust(struct kr_zonecut *dst, const struct kr_zonecut *src);
/**
* Add address record to the zone cut.
......
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