Commit 5c5313a0 authored by Marek Vavruša's avatar Marek Vavruša

Merge remote-tracking branch 'origin/new_node' into new_node

parents df0ca867 aca66c5e
......@@ -50,18 +50,6 @@ static knot_rrset_t *create_empty_rrsigs_for(const knot_rrset_t *covered)
covered->rclass, NULL);
}
/*!
* \brief Create empty RRSet from given template RRSet.
*/
static knot_rrset_t *new_rrset_from(const knot_rrset_t *tpl)
{
if (!tpl) {
return NULL;
}
return knot_rrset_new(tpl->owner, tpl->type, tpl->rclass, NULL);
}
/*- private API - signing of in-zone nodes -----------------------------------*/
/*!
......@@ -238,7 +226,6 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
knot_rrset_t synth_rrsig;
knot_rrset_init(&synth_rrsig, rrsigs->owner, KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN);
result = knot_synth_rrsig(covered->type, &rrsigs->rrs,
&synth_rrsig.rrs, NULL);
if (result != KNOT_EOK) {
......@@ -377,7 +364,6 @@ static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type,
if (synth_rrsig == NULL) {
return KNOT_ENOMEM;
}
int ret = knot_synth_rrsig(type, &rrsigs->rrs, &synth_rrsig->rrs, NULL);
if (ret != KNOT_EOK) {
knot_rrset_free(&synth_rrsig, NULL);
......@@ -474,7 +460,10 @@ static int remove_standalone_rrsigs(const knot_node_t *node,
for (uint16_t i = 0; i < rrsigs_rdata_count; ++i) {
uint16_t type_covered = knot_rrs_rrsig_type_covered(&rrsigs->rrs, i);
if (!knot_node_rrtype_exists(node, type_covered)) {
knot_rrset_t *to_remove = new_rrset_from(rrsigs);
knot_rrset_t *to_remove = knot_rrset_new(rrsigs->owner,
rrsigs->type,
rrsigs->rclass,
NULL);
if (to_remove == NULL) {
return KNOT_ENOMEM;
}
......@@ -786,7 +775,10 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
dbg_dnssec_detail("removing DNSKEY with tag %d\n", keytag);
if (to_remove == NULL) {
to_remove = new_rrset_from(dnskeys);
to_remove = knot_rrset_new(dnskeys->owner,
dnskeys->type,
dnskeys->rclass,
NULL);
if (to_remove == NULL) {
result = KNOT_ENOMEM;
break;
......@@ -1012,27 +1004,22 @@ static int update_dnskeys(const knot_zone_contents_t *zone,
if (result != KNOT_EOK) {
return result;
}
knot_rrset_t *dnskey_rrsig = knot_rrset_new(apex->owner,
KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN,
NULL);
if (dnskey_rrsig == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_t dnskey_rrsig;
knot_rrset_init(&dnskey_rrsig, apex->owner, KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN);
result = knot_synth_rrsig(KNOT_RRTYPE_DNSKEY, &rrsigs.rrs,
&dnskey_rrsig->rrs, NULL);
&dnskey_rrsig.rrs, NULL);
if (result != KNOT_EOK) {
if (result != KNOT_ENOENT) {
knot_rrset_free(&dnskey_rrsig, NULL);
return result;
}
}
bool modified = (knot_changeset_size(changeset) != changes_before);
bool signatures_exist = (!knot_rrset_empty(&dnskeys) &&
all_signatures_exist(&dnskeys, dnskey_rrsig,
all_signatures_exist(&dnskeys, &dnskey_rrsig,
zone_keys, policy));
knot_rrset_free(&dnskey_rrsig, NULL);
knot_rrs_clear(&dnskey_rrsig.rrs, NULL);
if (!modified && signatures_exist) {
return KNOT_EOK;
}
......
......@@ -40,29 +40,6 @@ static int wildcard_visit(struct query_data *qdata, const knot_node_t *node, con
return KNOT_EOK;
}
int move_rrset(knot_rrset_t *dst, const knot_rrset_t *src, mm_ctx_t *mm)
{
if (dst == NULL || src == NULL) {
return KNOT_EINVAL;
}
knot_dname_t *owner_cpy = knot_dname_copy(src->owner, mm);
if (owner_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_init(dst, owner_cpy, src->type, src->rclass);
int ret = knot_rrs_copy(&dst->rrs, &src->rrs, mm);
if (ret != KNOT_EOK) {
knot_dname_free(&dst->owner, mm);
return ret;
}
dst->additional = src->additional;
return KNOT_EOK;
}
/*! \brief Synthetizes a CNAME RR from a DNAME. */
static int dname_cname_synth(const knot_rrset_t *dname_rr,
const knot_dname_t *qname,
......@@ -86,6 +63,7 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
int labels = knot_dname_labels(dname_wire, NULL);
knot_dname_t *cname = knot_dname_replace_suffix(qname, labels, dname_tgt);
if (cname == NULL) {
knot_dname_free(&owner_copy, mm);
return KNOT_ENOMEM;
}
......@@ -95,8 +73,14 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
memcpy(cname_rdata, cname, cname_size);
knot_dname_free(&cname, NULL);
return knot_rrset_add_rr(cname_rrset, cname_rdata, cname_size,
knot_rrset_rr_ttl(dname_rr, 0), mm);
int ret = knot_rrset_add_rr(cname_rrset, cname_rdata, cname_size,
knot_rrset_rr_ttl(dname_rr, 0), mm);
if (ret != KNOT_EOK) {
knot_dname_free(&owner_copy, mm);
return ret;
}
return KNOT_EOK;
}
/*!
......@@ -138,17 +122,26 @@ static int put_rrsig(const knot_dname_t *sig_owner, uint16_t type,
if (ret != KNOT_EOK) {
return ret;
}
knot_dname_t *owner_copy = knot_dname_copy(sig_owner, qdata->mm);
knot_rrset_t synth_rrsig;
knot_rrset_init(&synth_rrsig, owner_copy, rrsigs->type, rrsigs->rclass);
synth_rrsig.rrs = synth_rrs;
/* Create rrsig info structure. */
struct rrsig_info *info = mm_alloc(qdata->mm, sizeof(struct rrsig_info));
if (info == NULL) {
ERR_ALLOC_FAILED;
knot_rrset_clear(&synth_rrsig, qdata->mm);
knot_rrs_clear(&synth_rrs, qdata->mm);
return KNOT_ENOMEM;
}
info->synth_rrsig = synth_rrsig;
/* Store RRSIG into info structure. */
knot_dname_t *owner_copy = knot_dname_copy(sig_owner, qdata->mm);
if (owner_copy == NULL) {
free(info);
knot_rrs_clear(&synth_rrs, qdata->mm);
return KNOT_ENOMEM;
}
knot_rrset_init(&info->synth_rrsig, owner_copy, rrsigs->type, rrsigs->rclass);
/* Store filtered signature. */
info->synth_rrsig.rrs = synth_rrs;
info->rrinfo = rrinfo;
add_tail(&qdata->rrsigs, &info->n);
......@@ -249,8 +242,15 @@ static int put_authority_soa(knot_pkt_t *pkt, struct query_data *qdata,
if (min < knot_rrset_rr_ttl(&soa_rrset, 0)) {
knot_rrset_t copy;
knot_dname_t *dname_cpy = knot_dname_copy(soa_rrset.owner, &pkt->mm);
if (dname_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_init(&copy, dname_cpy, soa_rrset.type, soa_rrset.rclass);
knot_rrs_copy(&copy.rrs, &soa_rrset.rrs, &pkt->mm);
int ret = knot_rrs_copy(&copy.rrs, &soa_rrset.rrs, &pkt->mm);
if (ret != KNOT_EOK) {
knot_dname_free(&dname_cpy, &pkt->mm);
return ret;
}
knot_rrset_rr_set_ttl(&copy, 0, min);
flags |= KNOT_PF_FREE;
......@@ -689,8 +689,14 @@ int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
knot_rrset_t to_add;
if (compr_hint == COMPR_HINT_NONE && expand) {
knot_dname_t *qname_cpy = knot_dname_copy(qdata->name, &pkt->mm);
if (qname_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_init(&to_add, qname_cpy, rr->type, rr->rclass);
knot_rrs_copy(&to_add.rrs, &rr->rrs, &pkt->mm);
int ret = knot_rrs_copy(&to_add.rrs, &rr->rrs, &pkt->mm);
if (ret != KNOT_EOK) {
knot_dname_free(&qname_cpy, &pkt->mm);
}
to_add.additional = rr->additional;
flags |= KNOT_PF_FREE;
} else {
......
......@@ -808,7 +808,7 @@ void nsec_clear_rrsigs(struct query_data *qdata)
struct rrsig_info *info = NULL;
WALK_LIST(info, qdata->rrsigs) {
knot_rrset_t *rrsig = &info->synth_rrsig;
knot_rrs_clear(&rrsig->rrs, qdata->mm);
knot_rrset_clear(rrsig, qdata->mm);
};
ptrlist_free(&qdata->rrsigs, qdata->mm);
......
......@@ -300,8 +300,7 @@ static int check_rrsig_rdata(err_handler_t *handler,
return KNOT_ENOMEM;
}
if (knot_rrs_rrsig_type_covered(rrsig, 0) !=
rrset->type) {
if (knot_rrs_rrsig_type_covered(rrsig, 0) != rrset->type) {
/* zoneparser would not let this happen
* but to be on the safe side
*/
......@@ -331,8 +330,7 @@ static int check_rrsig_rdata(err_handler_t *handler,
}
/* check original TTL */
uint32_t original_ttl =
knot_rrs_rrsig_original_ttl(rrsig, rr_pos);
uint32_t original_ttl = knot_rrs_rrsig_original_ttl(rrsig, rr_pos);
uint16_t rr_count = knot_rrset_rr_count(rrset);
for (uint16_t i = 0; i < rr_count; ++i) {
......@@ -362,8 +360,7 @@ static int check_rrsig_rdata(err_handler_t *handler,
/* dnskey is in the apex node */
if (!knot_rrset_empty(dnskey_rrset) &&
knot_dname_cmp(signer_name, dnskey_rrset->owner) != 0
) {
!knot_dname_is_equal(signer_name, dnskey_rrset->owner)) {
err_handler_handle_error(handler, node,
ZC_ERR_RRSIG_RDATA_DNSKEY_OWNER,
info_str);
......@@ -438,7 +435,8 @@ static int check_rrsig_in_rrset(err_handler_t *handler,
if (ret < 0 || ret >= sizeof(info_str)) {
return KNOT_ENOMEM;
}
knot_rrs_t rrsigs = { 0 };
knot_rrs_t rrsigs;
knot_rrs_init(&rrsigs);
ret = knot_synth_rrsig(rrset->type,
knot_node_rrs(node, KNOT_RRTYPE_RRSIG),
&rrsigs, NULL);
......@@ -724,7 +722,8 @@ static int sem_check_node_mandatory(const knot_node_t *node,
if (cname_rrs) {
if (knot_node_rrset_count(node) != 1) {
/* With DNSSEC node can contain RRSIGs or NSEC */
if (!(knot_node_rrtype_exists(node, KNOT_RRTYPE_NSEC) || knot_node_rrtype_exists(node, KNOT_RRTYPE_RRSIG)) ||
if (!(knot_node_rrtype_exists(node, KNOT_RRTYPE_NSEC) ||
knot_node_rrtype_exists(node, KNOT_RRTYPE_RRSIG)) ||
knot_node_rrset_count(node) > 3) {
*fatal_error = true;
err_handler_handle_error(handler, node,
......
......@@ -155,11 +155,8 @@ static void loader_process(const zs_scanner_t *scanner)
}
knot_dname_to_lower(owner);
knot_rrset_t rr = {.owner = owner,
.type = scanner->r_type,
.rclass = scanner->r_class,
.additional = NULL};
knot_rrs_init(&rr.rrs);
knot_rrset_t rr;
knot_rrset_init(&rr, owner, scanner->r_type, scanner->r_class);
int ret = add_rdata_to_rr(&rr, scanner);
if (ret != KNOT_EOK) {
char *rr_name = knot_dname_to_str(rr.owner);
......
......@@ -49,38 +49,39 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
return KNOT_EINVAL;
}
knot_rrset_t *soa_rrset1 = knot_node_create_rrset(apex1, KNOT_RRTYPE_SOA);
knot_rrset_t *soa_rrset2 = knot_node_create_rrset(apex2, KNOT_RRTYPE_SOA);
if (soa_rrset1 == NULL || soa_rrset2 == NULL) {
knot_rrset_t soa_rrset1 = knot_node_rrset(apex1, KNOT_RRTYPE_SOA);
knot_rrset_t soa_rrset2 = knot_node_rrset(apex2, KNOT_RRTYPE_SOA);
if (knot_rrset_empty(&soa_rrset1) || knot_rrset_empty(&soa_rrset2)) {
return KNOT_EINVAL;
}
if (knot_rrset_rr_count(soa_rrset1) == 0 ||
knot_rrset_rr_count(soa_rrset2) == 0) {
knot_rrset_free(&soa_rrset1, NULL);
knot_rrset_free(&soa_rrset2, NULL);
if (knot_rrset_rr_count(&soa_rrset1) == 0 ||
knot_rrset_rr_count(&soa_rrset2) == 0) {
return KNOT_EINVAL;
}
int64_t soa_serial1 = knot_rrs_soa_serial(&soa_rrset1->rrs);
int64_t soa_serial2 = knot_rrs_soa_serial(&soa_rrset2->rrs);
int64_t soa_serial1 = knot_rrs_soa_serial(&soa_rrset1.rrs);
int64_t soa_serial2 = knot_rrs_soa_serial(&soa_rrset2.rrs);
if (knot_serial_compare(soa_serial1, soa_serial2) == 0) {
knot_rrset_free(&soa_rrset1, NULL);
knot_rrset_free(&soa_rrset2, NULL);
return KNOT_ENODIFF;
}
if (knot_serial_compare(soa_serial1, soa_serial2) > 0) {
knot_rrset_free(&soa_rrset1, NULL);
knot_rrset_free(&soa_rrset2, NULL);
return KNOT_ERANGE;
}
assert(changeset);
changeset->soa_from = soa_rrset1;
changeset->soa_to = soa_rrset2;
changeset->soa_from = knot_rrset_copy(&soa_rrset1, NULL);
if (changeset->soa_from == NULL) {
return KNOT_ENOMEM;
}
changeset->soa_to = knot_rrset_copy(&soa_rrset2, NULL);
if (changeset->soa_to == NULL) {
knot_rrset_free(&changeset->soa_from, NULL);
return KNOT_ENOMEM;
}
changeset->serial_from = soa_serial1;
changeset->serial_to = soa_serial2;
......
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