Skip to content
Snippets Groups Projects
Commit c04a4b93 authored by Jan Kadlec's avatar Jan Kadlec
Browse files

changeset: Removed some redundant RR copies.

parent f4c00b05
No related branches found
No related tags found
No related merge requests found
......@@ -45,12 +45,12 @@
/*!
* \brief Create empty RRSIG RR set for a given RR set to be covered.
*/
static knot_rrset_t *create_empty_rrsigs_for(const knot_rrset_t *covered)
static knot_rrset_t create_empty_rrsigs_for(const knot_rrset_t *covered)
{
assert(!knot_rrset_empty(covered));
return knot_rrset_new(covered->owner, KNOT_RRTYPE_RRSIG,
covered->rclass, NULL);
knot_rrset_t ret;
knot_rrset_init(&ret, covered->owner, KNOT_RRTYPE_RRSIG, covered->rclass);
return ret;
}
/*- private API - signing of in-zone nodes -----------------------------------*/
......
......@@ -235,14 +235,14 @@ static int ixfr_answer_init(struct query_data *qdata)
/* Put all changesets to processing queue. */
xfer->changesets = chgsets;
changeset_t *chs = NULL;
WALK_LIST(chs, chgsets) {
WALK_LIST(chs, xfer->changesets) {
ptrlist_add(&xfer->proc.nodes, chs, mm);
}
/* Keep first and last serial. */
chs = HEAD(chgsets);
chs = HEAD(xfer->changesets);
xfer->soa_from = chs->soa_from;
chs = TAIL(chgsets);
chs = TAIL(xfer->changesets);
xfer->soa_to = chs->soa_to;
/* Set up cleanup callback. */
......
......@@ -125,6 +125,7 @@ static int sign_update(zone_t *zone, const zone_contents_t *old_contents,
// Free the DNSSEC changeset's SOA from (not used anymore)
knot_rrset_free(&sec_ch.soa_from, NULL);
changeset_clear(&sec_ch, NULL);
// Plan next zone resign.
const time_t resign_time = zone_events_get_time(zone, ZONE_EVENT_DNSSEC);
......
......@@ -76,9 +76,13 @@ bool changeset_empty(const changeset_t *ch)
return true;
}
if (ch->soa_to) {
return false;
}
changeset_iter_t *itt = changeset_iter_all(ch ,false);
if (itt == NULL) {
return false;
return true;
}
knot_rrset_t rr = changeset_iter_next(itt);
......
......@@ -290,10 +290,8 @@ static void remove_header_from_list(zone_contents_t *z, const knot_rrset_t *rr)
/*!< \brief Removes RR from list, owner check. */
static void remove_owner_from_list(zone_contents_t *z, const knot_dname_t *owner)
{
zone_node_t *n = NULL;
zone_tree_remove(z->nodes, owner, &n);
zone_node_t *n = (zone_node_t *)zone_contents_find_node(z, owner);
node_free_rrsets(n);
node_free(&n);
}
/* --------------------- true/false helper functions ------------------------ */
......@@ -428,7 +426,7 @@ static bool skip_soa(const knot_rrset_t *rr, int64_t sn)
/*!< \brief Checks whether record should be added or replaced. */
static bool skip_record_addition(changeset_t *changeset,
knot_rrset_t *rr)
const knot_rrset_t *rr)
{
if (!should_replace(rr)) {
return false;
......@@ -456,14 +454,7 @@ static bool skip_record_addition(changeset_t *changeset,
static int add_rr_to_chgset(const knot_rrset_t *rr, changeset_t *changeset,
int *apex_ns_rem)
{
knot_rrset_t *rr_copy = knot_rrset_copy(rr, NULL);
if (rr_copy == NULL) {
return KNOT_ENOMEM;
}
rr_copy->rclass = KNOT_CLASS_IN;
if (skip_record_addition(changeset, rr_copy)) {
if (skip_record_addition(changeset, rr)) {
return KNOT_EOK;
}
......@@ -472,26 +463,19 @@ static int add_rr_to_chgset(const knot_rrset_t *rr, changeset_t *changeset,
(*apex_ns_rem)--;
}
return changeset_add_rrset(changeset, rr_copy);
return changeset_add_rrset(changeset, rr);
}
/*!< \brief Adds RR into remove section of changeset if it is deemed worthy. */
static int rem_rr_to_chgset(const knot_rrset_t *rr, changeset_t *changeset,
int *apex_ns_rem)
{
knot_rrset_t *rr_copy = knot_rrset_copy(rr, NULL);
if (rr_copy == NULL) {
return KNOT_ENOMEM;
}
rr_copy->rclass = KNOT_CLASS_IN;
if (apex_ns_rem) {
// Decrease post update apex NS count.
(*apex_ns_rem)++;
}
return changeset_rem_rrset(changeset, rr_copy);
return changeset_rem_rrset(changeset, rr);
}
/*!< \brief Adds all RRs from RRSet into remove section of changeset. */
......
......@@ -90,85 +90,13 @@ static int knot_zone_diff_load_soas(const zone_contents_t *zone1,
return KNOT_EOK;
}
/*!< \todo Only use add or remove function, not both as they are the same. */
/*!< \todo Also, this might be all handled by function in changesets.h!!! */
static int knot_zone_diff_changeset_add_rrset(changeset_t *changeset,
const knot_rrset_t *rrset)
{
/* Remove all RRs of the RRSet. */
if (changeset == NULL || rrset == NULL) {
dbg_zonediff("zone_diff: add_rrset: NULL parameters.\n");
return KNOT_EINVAL;
}
if (rrset->rrs.rr_count == 0) {
dbg_zonediff_detail("zone_diff: Nothing to add.\n");
return KNOT_EOK;
}
knot_rrset_t *rrset_copy = knot_rrset_copy(rrset, NULL);
if (rrset_copy == NULL) {
dbg_zonediff("zone_diff: add_rrset: Cannot copy RRSet.\n");
return KNOT_ENOMEM;
}
int ret = changeset_add_rrset(changeset, rrset_copy);
if (ret != KNOT_EOK) {
/* We have to free the copy now! */
knot_rrset_free(&rrset_copy, NULL);
dbg_zonediff("zone_diff: add_rrset: Could not add RRSet. "
"Reason: %s.\n", knot_strerror(ret));
return ret;
}
return KNOT_EOK;
}
static int knot_zone_diff_changeset_remove_rrset(changeset_t *changeset,
const knot_rrset_t *rrset)
{
/* Remove all RRs of the RRSet. */
if (changeset == NULL) {
dbg_zonediff("zone_diff: remove_rrset: NULL parameters.\n");
return KNOT_EINVAL;
}
if (rrset == NULL) {
return KNOT_EOK;
}
if (rrset->rrs.rr_count == 0) {
/* RDATA are the same, however*/
dbg_zonediff_detail("zone_diff: Nothing to remove.\n");
return KNOT_EOK;
}
knot_rrset_t *rrset_copy = knot_rrset_copy(rrset, NULL);
if (rrset_copy == NULL) {
dbg_zonediff("zone_diff: remove_rrset: Cannot copy RRSet.\n");
return KNOT_ENOMEM;
}
int ret = changeset_rem_rrset(changeset, rrset_copy);
if (ret != KNOT_EOK) {
/* We have to free the copy now. */
knot_rrset_free(&rrset_copy, NULL);
dbg_zonediff("zone_diff: remove_rrset: Could not remove RRSet. "
"Reason: %s.\n", knot_strerror(ret));
return ret;
}
return KNOT_EOK;
}
static int knot_zone_diff_add_node(const zone_node_t *node,
changeset_t *changeset)
{
/* Add all rrsets from node. */
for (uint i = 0; i < node->rrset_count; i++) {
knot_rrset_t rrset = node_rrset_at(node, i);
int ret = knot_zone_diff_changeset_add_rrset(changeset,
&rrset);
int ret = changeset_add_rrset(changeset, &rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: add_node: Cannot add RRSet (%s).\n",
knot_strerror(ret));
......@@ -185,8 +113,7 @@ static int knot_zone_diff_remove_node(changeset_t *changeset,
/* Remove all the RRSets of the node. */
for (uint i = 0; i < node->rrset_count; i++) {
knot_rrset_t rrset = node_rrset_at(node, i);
int ret = knot_zone_diff_changeset_remove_rrset(changeset,
&rrset);
int ret = changeset_rem_rrset(changeset, &rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: remove_node: Failed to "
"remove rrset. Error: %s\n",
......@@ -279,7 +206,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
}
}
int ret = knot_zone_diff_changeset_remove_rrset(changeset, to_remove);
int ret = changeset_rem_rrset(changeset, to_remove);
if (ret != KNOT_EOK) {
knot_rrset_free(&to_remove, NULL);
dbg_zonediff("zone_diff: diff_rdata: Could not remove RRs. "
......@@ -302,7 +229,7 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
}
}
ret = knot_zone_diff_changeset_add_rrset(changeset, to_add);
ret = changeset_add_rrset(changeset, to_add);
if (ret != KNOT_EOK) {
knot_rrset_free(&to_add, NULL);
dbg_zonediff("zone_diff: diff_rdata: Could not remove RRs. "
......@@ -396,7 +323,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
node_rrset(node_in_second_tree, rrset.type);
if (knot_rrset_empty(&rrset_from_second_node)) {
/* RRSet has been removed. Make a copy and remove. */
int ret = knot_zone_diff_changeset_remove_rrset(
int ret = changeset_rem_rrset(
param->changeset, &rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: "
......@@ -428,7 +355,7 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
knot_rrset_t rrset_from_first_node = node_rrset(node, rrset.type);
if (knot_rrset_empty(&rrset_from_first_node)) {
/* RRSet has been added. Make a copy and add. */
int ret = knot_zone_diff_changeset_add_rrset(
int ret = changeset_add_rrset(
param->changeset, &rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: "
......
......@@ -185,8 +185,8 @@ int zone_load_post(zone_contents_t *contents, zone_t *zone, uint32_t *dnssec_ref
init_list(&apply);
add_head(&apply, &diff_change.n);
ret = zone_change_store(zone, &apply);
changeset_clear(&diff_change, NULL);
}
changeset_clear(&diff_change, NULL);
return ret;
}
......
......@@ -22,7 +22,7 @@
int main(int argc, char *argv[])
{
plan(22);
plan(23);
// Test with NULL changeset
ok(changeset_size(NULL) == 0, "changeset: NULL size");
......@@ -35,6 +35,9 @@ int main(int argc, char *argv[])
knot_dname_free(&d, NULL);
ok(ch != NULL, "changeset: new");
ok(changeset_empty(ch), "changeset: empty");
ch->soa_to = (knot_rrset_t *)0xdeadbeef;
ok(!changeset_empty(ch), "changseset: empty SOA");
ch->soa_to = NULL;
ok(changeset_size(ch) == 0, "changeset: empty size");
// Test additions.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment