Commit cefa010b authored by Jan Kadlec's avatar Jan Kadlec

changeset: Fixed RRSet adding in diff.

parent bca98b71
......@@ -427,7 +427,7 @@ static int create_nsec3_nodes(const zone_contents_t *zone, uint32_t ttl,
int result = KNOT_EOK;
int sorted = false;
const bool sorted = false;
hattrie_iter_t *it = hattrie_iter_begin(zone->nodes, sorted);
while (!hattrie_iter_finished(it)) {
zone_node_t *node = (zone_node_t *)*hattrie_iter_val(it);
......
......@@ -121,11 +121,11 @@ static int sign_update(zone_t *zone, const zone_contents_t *old_contents,
}
// Merge changesets
changeset_merge(ddns_ch, &sec_ch);
// Free the DNSSEC changeset's SOA from (not used anymore)
knot_rrset_free(&sec_ch.soa_from, NULL);
ret = changeset_merge(ddns_ch, &sec_ch);
changeset_clear(&sec_ch, NULL);
if (ret != KNOT_EOK) {
return ret;
}
// Plan next zone resign.
const time_t resign_time = zone_events_get_time(zone, ZONE_EVENT_DNSSEC);
......
......@@ -149,7 +149,9 @@ int changeset_merge(changeset_t *ch1, changeset_t *ch2)
// Use soa_to and serial from the second changeset
// soa_to from the first changeset is redundant, delete it
knot_rrset_free(&ch1->soa_to, NULL);
knot_rrset_free(&ch2->soa_from, NULL);
ch1->soa_to = ch2->soa_to;
ch2->soa_to = NULL;
return KNOT_EOK;
}
......
......@@ -284,7 +284,11 @@ static void remove_header_from_list(zone_contents_t *z, const knot_rrset_t *rr)
return;
}
node_remove_rdataset(n, rr->type);
knot_rdataset_t *rrs = node_rdataset(n, rr->type);
if (rrs) {
knot_rdataset_clear(rrs, NULL);
node_remove_rdataset(n, rr->type);
}
}
/*!< \brief Removes RR from list, owner check. */
......@@ -710,7 +714,9 @@ static int process_rem_rrset(const knot_rrset_t *rrset,
// Remove all previously added RRs with this owner and type from chgset
remove_header_from_list(changeset->add, rrset);
if (node == NULL) {
// no such node in zone, ignore
return KNOT_EOK;
}
......
......@@ -204,17 +204,22 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
}
}
int ret = changeset_rem_rrset(changeset, &to_remove);
knot_rdataset_clear(&to_remove.rrs, NULL);
if (ret != KNOT_EOK) {
if (!knot_rrset_empty(&to_remove)) {
int ret = changeset_rem_rrset(changeset, &to_remove);
knot_rdataset_clear(&to_remove.rrs, NULL);
if (ret != KNOT_EOK) {
knot_rdataset_clear(&to_add.rrs, NULL);
return ret;
}
}
if (!knot_rrset_empty(&to_add)) {
int ret = changeset_add_rrset(changeset, &to_add);
knot_rdataset_clear(&to_add.rrs, NULL);
return ret;
}
ret = changeset_add_rrset(changeset, &to_add);
knot_rdataset_clear(&to_add.rrs, NULL);
return ret;
return KNOT_EOK;
}
static int knot_zone_diff_rrsets(const knot_rrset_t *rrset1,
......@@ -229,7 +234,6 @@ static int knot_zone_diff_rrsets(const knot_rrset_t *rrset1,
static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
{
if (node_ptr == NULL || *node_ptr == NULL || data == NULL) {
dbg_zonediff("zone_diff: diff_node: NULL arguments.\n");
return KNOT_EINVAL;
}
......@@ -237,7 +241,6 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
struct zone_diff_param *param = (struct zone_diff_param *)data;
if (param->changeset == NULL) {
dbg_zonediff("zone_diff: diff_node: NULL arguments.\n");
return KNOT_EINVAL;
}
......@@ -252,36 +255,19 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
zone_tree_find(param->nodes, node_owner, &node_in_second_tree);
if (node_in_second_tree == NULL) {
dbg_zonediff_detail("zone_diff: diff_node: Node %p is not "
"in the second tree.\n",
node_owner);
int ret = knot_zone_diff_remove_node(param->changeset, node);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: failed to remove node.\n");
}
return ret;
return knot_zone_diff_remove_node(param->changeset, node);
}
assert(node_in_second_tree != node);
dbg_zonediff_detail("zone_diff: diff_node: Node %p is present in "
"both trees.\n", node_owner);
/* The nodes are in both trees, we have to diff each RRSet. */
if (node->rrset_count == 0) {
dbg_zonediff("zone_diff: Node in first tree has no RRSets.\n");
/*
* If there are no RRs in the first tree, all of the RRs
* in the second tree will have to be inserted to ADD section.
*/
int ret = knot_zone_diff_add_node(node_in_second_tree,
param->changeset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: "
"Could not add node from second tree. "
"Reason: %s.\n", knot_strerror(ret));
}
return ret;
return knot_zone_diff_add_node(node_in_second_tree,
param->changeset);
}
for (uint i = 0; i < node->rrset_count; i++) {
......@@ -300,8 +286,6 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
int ret = changeset_rem_rrset(
param->changeset, &rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: "
"Failed to remove RRSet.\n");
return ret;
}
} else {
......@@ -310,8 +294,6 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
&rrset_from_second_node,
param->changeset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: "
"Failed to diff RRSets.\n");
return ret;
}
}
......@@ -332,8 +314,6 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
int ret = changeset_add_rrset(
param->changeset, &rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: "
"Failed to add RRSet.\n");
return ret;
}
}
......@@ -417,16 +397,13 @@ static int knot_zone_diff_load_content(const zone_contents_t *zone1,
const zone_contents_t *zone2,
changeset_t *changeset)
{
int result;
result = knot_zone_diff_load_trees(zone1->nodes, zone2->nodes, changeset);
if (result != KNOT_EOK)
return result;
result = knot_zone_diff_load_trees(zone1->nsec3_nodes, zone2->nsec3_nodes,
changeset);
int ret = knot_zone_diff_load_trees(zone1->nodes, zone2->nodes, changeset);
if (ret != KNOT_EOK) {
return ret;
}
return result;
return knot_zone_diff_load_trees(zone1->nsec3_nodes, zone2->nsec3_nodes,
changeset);
}
static int zone_contents_diff(const zone_contents_t *zone1,
......
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