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

Completed zonediff except for RRSIG handling and special NSEC3 case.

- Debugging didn't work, printfs will have to be replaced.
- Several fixes
- Some debug code still present that has to be removed.
- no handling for RRSIGs
- not sure how will this perform in case of empty NSEC3 trees.

Refs #1752 @5h
parent 81d4892c
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,9 @@ struct zone_diff_param {
int ret;
};
#define printf_detail printf
#define printf_verb printf
static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
const knot_zone_contents_t *zone2,
knot_changeset_t *changeset)
......@@ -43,7 +46,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
const knot_node_t *apex1 = knot_zone_contents_apex(zone1);
const knot_node_t *apex2 = knot_zone_contents_apex(zone2);
if (apex1 == NULL || apex2 == NULL) {
dbg_zonediff("zone_diff: "
printf("zone_diff: "
"both zones must have apex nodes.\n");
return KNOT_EBADARG;
}
......@@ -51,14 +54,14 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
knot_rrset_t *soa_rrset1 = knot_node_get_rrset(apex1, KNOT_RRTYPE_SOA);
knot_rrset_t *soa_rrset2 = knot_node_get_rrset(apex2, KNOT_RRTYPE_SOA);
if (soa_rrset1 == NULL || soa_rrset2 == NULL) {
dbg_zonediff("zone_diff: "
printf("zone_diff: "
"both zones must have apex nodes.\n");
return KNOT_EBADARG;
}
if (knot_rrset_rdata(soa_rrset1) == NULL ||
knot_rrset_rdata(soa_rrset2) == NULL) {
dbg_zonediff("zone_diff: "
printf("zone_diff: "
"both zones must have apex nodes with SOA "
"RRs.\n");
return KNOT_EBADARG;
......@@ -67,18 +70,18 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
int64_t soa_serial1 =
knot_rdata_soa_serial(knot_rrset_rdata(soa_rrset1));
if (soa_serial1 == -1) {
dbg_zonediff("zone_diff: load_soas: Got bad SOA.\n");
printf("zone_diff: load_soas: Got bad SOA.\n");
}
int64_t soa_serial2 =
knot_rdata_soa_serial(knot_rrset_rdata(soa_rrset2));
if (soa_serial2 == -1) {
dbg_zonediff("zone_diff: load_soas: Got bad SOA.\n");
printf("zone_diff: load_soas: Got bad SOA.\n");
}
if (soa_serial1 >= soa_serial2) {
dbg_zonediff("zone_diff: "
printf("zone_diff: "
"second zone must have higher serial than the "
"first one.\n");
return KNOT_EBADARG;
......@@ -97,7 +100,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// knot_rdata_t *rr)
//{
// if (changeset == NULL || rrset == NULL || rr == NULL) {
// dbg_zonediff("zone_diff: add_rr: NULL arguments.\n");
// printf("zone_diff: add_rr: NULL arguments.\n");
// return KNOT_EBADARG;
// }
......@@ -116,7 +119,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// if (found_rrset) {
// int ret = knot_rrset_add_rdata(found_rrset, rr);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: add_rr: "
// printf("zone_diff: add_rr: "
// "Could not add rdata. Reason: %s.\n",
// knot_strerror(ret));
// return ret;
......@@ -133,14 +136,14 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// knot_rrset_class(rrset),
// knot_rrset_ttl(rrset));
// if (tmp_rrset == NULL) {
// dbg_zonediff("zone_diff: add_rr: "
// printf("zone_diff: add_rr: "
// "Could not create tmp rrset.\n");
// return KNOT_ERROR;
// }
// int ret = knot_rrset_add_rdata(tmp_rrset, rr);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: add_rr: "
// printf("zone_diff: add_rr: "
// "Could not add rdata to tmp rrset/\n");
// return ret;
// }
......@@ -148,7 +151,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// ret = knot_changeset_add_new_rr(changeset, tmp_rrset,
// XFRIN_CHANGESET_ADD);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: add_rr: "
// printf("zone_diff: add_rr: "
// "Could not add RRSet to list of RRSets to"
// "be removed.\n");
// return ret;
......@@ -163,7 +166,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// knot_rdata_t *rr)
//{
// if (changeset == NULL || rrset == NULL || rr == NULL) {
// dbg_zonediff("zone_diff: remove_rr: NULL arguments.\n");
// printf("zone_diff: remove_rr: NULL arguments.\n");
// return KNOT_EBADARG;
// }
......@@ -182,7 +185,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// if (found_rrset) {
// int ret = knot_rrset_add_rdata(found_rrset, rr);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: remove_rr: "
// printf("zone_diff: remove_rr: "
// "Could not add rdata. Reason: %s.\n",
// knot_strerror(ret));
// return ret;
......@@ -199,14 +202,14 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// knot_rrset_class(rrset),
// knot_rrset_ttl(rrset));
// if (tmp_rrset == NULL) {
// dbg_zonediff("zone_diff: remove_rr: "
// printf("zone_diff: remove_rr: "
// "Could not create tmp rrset.\n");
// return KNOT_ERROR;
// }
// int ret = knot_rrset_add_rdata(tmp_rrset, rr);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: remove_rr: "
// printf("zone_diff: remove_rr: "
// "Could not add rdata to tmp rrset/\n");
// return ret;
// }
......@@ -214,7 +217,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
// ret = knot_changeset_add_new_rr(changeset, tmp_rrset,
// XFRIN_CHANGESET_REMOVE);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: remove_rr: "
// printf("zone_diff: remove_rr: "
// "Could not add RRSet to list of RRSets to "
// "be removed.\n");
// return ret;
......@@ -231,17 +234,23 @@ static int knot_zone_diff_changeset_add_rrset(knot_changeset_t *changeset,
{
/* Remove all RRs of the RRSet. */
if (changeset == NULL || rrset == NULL) {
dbg_zonediff("zone_diff: add_rrset: NULL parameters.\n");
printf("zone_diff: add_rrset: NULL parameters.\n");
return KNOT_EBADARG;
}
dbg_zonediff_detail("zone_diff: add_rrset: Adding RRSet:\n");
if (knot_rrset_rdata_rr_count(rrset) == 0) {
printf_detail("zone_diff: Nothing to add.\n");
return KNOT_EOK;
}
printf_detail("zone_diff: add_rrset: Adding RRSet (%d RRs):\n",
knot_rrset_rdata_rr_count(rrset));
knot_rrset_dump(rrset, 1);
int ret = knot_changeset_add_new_rr(changeset, rrset,
XFRIN_CHANGESET_ADD);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: add_rrset: Could not add RRSet. "
printf("zone_diff: add_rrset: Could not add RRSet. "
"Reason: %s.\n", knot_strerror(ret));
return ret;
}
......@@ -252,13 +261,13 @@ static int knot_zone_diff_changeset_add_rrset(knot_changeset_t *changeset,
// rrset,
// tmp_rdata);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: add_rrset: Cannot add "
// printf("zone_diff: add_rrset: Cannot add "
// "RR\n");
// return ret;
// }
// }
// dbg_zonediff_detail("zone_diff: add_rrset: "
// printf_detail("zone_diff: add_rrset: "
// "RRSet succesfully added.\n");
return KNOT_EOK;
......@@ -269,21 +278,26 @@ static int knot_zone_diff_changeset_remove_rrset(knot_changeset_t *changeset,
{
/* Remove all RRs of the RRSet. */
if (changeset == NULL || rrset == NULL) {
dbg_zonediff("zone_diff: remove_rrset: NULL parameters.\n");
printf("zone_diff: remove_rrset: NULL parameters.\n");
return KNOT_EBADARG;
}
dbg_zonediff_detail("zone_diff: remove_rrset: Removing RRSet:\n");
if (knot_rrset_rdata_rr_count(rrset) == 0) {
printf_detail("zone_diff: Nothing to remove.\n");
return KNOT_EOK;
}
printf_detail("zone_diff: remove_rrset: Removing RRSet (%d RRs):\n",
knot_rrset_rdata_rr_count(rrset));
knot_rrset_dump(rrset, 1);
int ret = knot_changeset_add_new_rr(changeset, rrset,
XFRIN_CHANGESET_REMOVE);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: remove_rrset: Could not remove RRSet. "
printf("zone_diff: remove_rrset: Could not remove RRSet. "
"Reason: %s.\n", knot_strerror(ret));
return ret;
}
// const knot_rdata_t *tmp_rdata = NULL;
// while ((tmp_rdata = knot_rrset_rdata_next(rrset, tmp_rdata)) != NULL) {
......@@ -291,13 +305,13 @@ static int knot_zone_diff_changeset_remove_rrset(knot_changeset_t *changeset,
// rrset,
// tmp_rdata);
// if (ret != KNOT_EOK) {
// dbg_zonediff("zone_diff: remove_rrset: Cannot remove "
// printf("zone_diff: remove_rrset: Cannot remove "
// "RR\n");
// return ret;
// }
// }
// dbg_zonediff_detail("zone_diff: remove_rrset: "
// printf_detail("zone_diff: remove_rrset: "
// "RRSet succesfully removed.\n");
return KNOT_EOK;
......@@ -307,16 +321,16 @@ static int knot_zone_diff_changeset_remove_node(knot_changeset_t *changeset,
const knot_node_t *node)
{
if (changeset == NULL || node == NULL) {
dbg_zonediff("zone_diff: remove_node: NULL parameters.\n");
printf("zone_diff: remove_node: NULL parameters.\n");
return KNOT_EBADARG;
}
dbg_zonediff("zone_diff: remove_node: Removing node:\n");
printf("zone_diff: remove_node: Removing node:\n");
knot_node_dump(node, 1);
const knot_rrset_t **rrsets = knot_node_rrsets(node);
if (rrsets == NULL) {
dbg_zonediff_verb("zone_diff: remove_node: "
printf_verb("zone_diff: remove_node: "
"Nothing to remove.\n");
return KNOT_EOK;
}
......@@ -326,7 +340,7 @@ static int knot_zone_diff_changeset_remove_node(knot_changeset_t *changeset,
knot_rrset_t *rrset = NULL;
int ret = knot_rrset_deep_copy(rrsets[i], &rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: remove_node: Could not copy "
printf("zone_diff: remove_node: Could not copy "
"RRSet. Reason: %s.\n",
knot_strerror(ret));
return ret;
......@@ -335,7 +349,7 @@ static int knot_zone_diff_changeset_remove_node(knot_changeset_t *changeset,
ret = knot_zone_diff_changeset_remove_rrset(changeset,
rrset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: remove_node: Failed to "
printf("zone_diff: remove_node: Failed to "
"remove rrset. Error: %s\n",
ret);
return ret;
......@@ -356,12 +370,19 @@ static int knot_zone_diff_rdata_return_changes(const knot_rrset_t *rrset1,
* After the list has been traversed, we have a list of
* changed/removed rdatas. This has awful computation time.
*/
knot_rdata_t *changes_from_first_rdata = knot_rdata_new();
if (changes_from_first_rdata == NULL) {
dbg_zonediff("zone_diff: diff_rdata: "
"Could not create new rdata.\n");
return KNOT_ENOMEM;
}
// knot_rdata_t *changes_from_first_rdata = knot_rdata_new();
// if (changes_from_first_rdata == NULL) {
// printf("zone_diff: diff_rdata: "
// "Could not create new rdata.\n");
// return KNOT_ENOMEM;
// }
printf_detail("zone_diff: diff_rdata: Diff of %s, type=%s. "
"RR count 1=%d RR count 2=%d.\n",
knot_dname_to_str(rrset1->owner),
knot_rrtype_to_string(rrset1->type),
knot_rrset_rdata_rr_count(rrset1),
knot_rrset_rdata_rr_count(rrset2));
/* Create fake RRSet, it will be easier to handle. */
*changes = knot_rrset_new(knot_rrset_get_owner(rrset1),
......@@ -369,54 +390,65 @@ static int knot_zone_diff_rdata_return_changes(const knot_rrset_t *rrset1,
knot_rrset_class(rrset1),
knot_rrset_ttl(rrset1));
if (*changes == NULL) {
dbg_zonediff("zone_diff: diff_rdata: "
printf("zone_diff: diff_rdata: "
"Could not create RRSet with changes.\n");
return KNOT_ENOMEM;
}
int ret = knot_rrset_add_rdata(*changes,
changes_from_first_rdata);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_rdata: "
"Could not add rdata to RRSet.\n");
knot_rrset_free(changes);
return ret;
}
// int ret = knot_rrset_add_rdata(*changes,
// changes_from_first_rdata);
// if (ret != KNOT_EOK) {
// printf("zone_diff: diff_rdata: "
// "Could not add rdata to RRSet.\n");
// knot_rrset_free(changes);
// return ret;
// }
knot_rrtype_descriptor_t *desc =
knot_rrtype_descriptor_by_type(knot_rrset_type(rrset1));
assert(desc);
const knot_rdata_t *tmp_rdata = NULL;
while((tmp_rdata = knot_rrset_rdata_next(rrset1, tmp_rdata)) != NULL) {
const knot_rdata_t *tmp_rdata_second_rrset = NULL;
while (((tmp_rdata_second_rrset = knot_rrset_rdata_next(rrset2,
tmp_rdata_second_rrset)) != NULL) &&
const knot_rdata_t *tmp_rdata = knot_rrset_rdata(rrset1);
while(tmp_rdata != NULL) {
const knot_rdata_t *tmp_rdata_second_rrset =
knot_rrset_rdata(rrset2);
while ((tmp_rdata_second_rrset != NULL) &&
(knot_rdata_compare(tmp_rdata,
tmp_rdata_second_rrset,
desc->wireformat) != 0)) {
; /*!< \todo this is intentional, but not very cool. */
tmp_rdata_second_rrset =
knot_rrset_rdata_next(rrset2,
tmp_rdata_second_rrset);
}
if (tmp_rdata_second_rrset == NULL) {
/*
* This means that the while cycle above has finished
* because the list was traversed - there's no match.
*/
printf("zone_diff: diff_rdata: "
"No match for RR (type=%s owner=%s).\n",
knot_rrtype_to_string(knot_rrset_type(rrset1)),
knot_dname_to_str(rrset1->owner));
/* Make a copy of tmp_rdata. */
knot_rdata_t *tmp_rdata_copy =
knot_rdata_deep_copy(tmp_rdata,
knot_rrset_type(rrset1),
1);
ret = knot_rrset_add_rdata(*changes,
int ret = knot_rrset_add_rdata(*changes,
tmp_rdata_copy);
/*!< \todo dispose of the copy. */
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_rdata: "
printf("zone_diff: diff_rdata: "
"Could not add rdata to rrset.");
knot_rrset_deep_free(changes, 1, 1, 0);
return ret;
}
} else {
printf_detail("zone_diff: diff_rdata: "
"Found matching RR for type %s.\n",
knot_rrtype_to_string(rrset1->type));
}
tmp_rdata = knot_rrset_rdata_next(rrset1, tmp_rdata);
}
return KNOT_EOK;
}
......@@ -434,16 +466,20 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
int ret = knot_zone_diff_rdata_return_changes(rrset1, rrset2,
&to_remove);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_rdata: Could not get changes. "
printf("zone_diff: diff_rdata: Could not get changes. "
"Error: %s.\n", knot_strerror(ret));
return ret;
}
assert(to_remove);
printf_detail("zone_diff: diff_rdata: To remove:\n");
knot_rrset_dump(to_remove, 1);
//TODO free to_remove
ret = knot_zone_diff_changeset_remove_rrset(changeset,
to_remove);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_rdata: Could not remove RRs. "
printf("zone_diff: diff_rdata: Could not remove RRs. "
"Error: %s.\n", knot_strerror(ret));
return ret;
}
......@@ -451,18 +487,20 @@ static int knot_zone_diff_rdata(const knot_rrset_t *rrset1,
/* Get RRs to add to zone. */
knot_rrset_t *to_add = NULL;
ret = knot_zone_diff_rdata_return_changes(rrset2, rrset1,
&to_add);
&to_add);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_rdata: Could not get changes. "
printf("zone_diff: diff_rdata: Could not get changes. "
"Error: %s.\n", knot_strerror(ret));
return ret;
}
assert(to_add);
printf_detail("zone_diff: diff_rdata: To add:\n");
knot_rrset_dump(to_add, 1);
ret = knot_zone_diff_changeset_add_rrset(changeset,
to_add);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_rdata: Could not remove RRs. "
printf("zone_diff: diff_rdata: Could not remove RRs. "
"Error: %s.\n", knot_strerror(ret));
return ret;
}
......@@ -475,7 +513,7 @@ static int knot_zone_diff_rrsets(const knot_rrset_t *rrset1,
knot_changeset_t *changeset)
{
if (rrset1 == NULL || rrset2 == NULL || changeset == NULL) {
dbg_zonediff("zone_diff: diff_rrsets: NULL arguments.\n");
printf("zone_diff: diff_rrsets: NULL arguments.\n");
return KNOT_EBADARG;
}
......@@ -491,20 +529,20 @@ static int knot_zone_diff_rrsets(const knot_rrset_t *rrset1,
static void knot_zone_diff_node(knot_node_t *node, void *data)
{
if (node == NULL || data == NULL) {
dbg_zonediff("zone_diff: diff_node: NULL arguments.\n");
printf("zone_diff: diff_node: NULL arguments.\n");
return;
}
struct zone_diff_param *param = (struct zone_diff_param *)data;
if (param->changeset == NULL || param->contents == NULL) {
dbg_zonediff("zone_diff: diff_node: NULL arguments.\n");
printf("zone_diff: diff_node: NULL arguments.\n");
param->ret = KNOT_EBADARG;
return;
}
if (param->ret != KNOT_EOK) {
/* Error occured before, no point in continuing. */
dbg_zonediff_detail("zone_diff: diff_node: error: %s\n",
printf_detail("zone_diff: diff_node: error: %s\n",
knot_strerror(param->ret));
return;
}
......@@ -521,42 +559,62 @@ static void knot_zone_diff_node(knot_node_t *node, void *data)
knot_zone_contents_find_node(param->contents,
node_owner);
} else {
printf_verb("zone_diff: diff_node: NSEC3 zone.\n");
node_in_second_tree =
knot_zone_contents_find_nsec3_node(param->contents,
node_owner);
}
if (node_in_second_tree == NULL) {
printf_detail("zone_diff: diff_node: Node %s is not "
"in the second tree.\n",
knot_dname_to_str(node_owner));
int ret = knot_zone_diff_changeset_remove_node(param->changeset,
node);
node);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: failed to remove node.\n");
printf("zone_diff: failed to remove node.\n");
param->ret = ret;
return;
}
param->ret = KNOT_EOK;
return;
}
assert(node_in_second_tree != node);
printf_detail("zone_diff: diff_node: Node %s is present in "
"both trees.\n", knot_dname_to_str(node_owner));
/* The nodes are in both trees, we have to diff each RRSet. */
const knot_rrset_t **rrsets = knot_node_rrsets(node);
if (rrsets == NULL) {
dbg_zonediff("zone_diff: Node has no RRSets.\n");
printf("zone_diff: Node has no RRSets.\n");
param->ret = KNOT_EBADARG;
return;
}
for(uint i = 0; i < knot_node_rrset_count(node); i++) {
for (uint i = 0; i < knot_node_rrset_count(node); i++) {
/* Search for the RRSet in the node from the second tree. */
const knot_rrset_t *rrset = rrsets[i];
assert(rrset);
/* SOAs are handled explicitly. */
if (knot_rrset_type(rrset) == KNOT_RRTYPE_SOA) {
continue;
}
const knot_rrset_t *rrset_from_second_node =
knot_node_rrset(node_in_second_tree,
knot_rrset_type(rrset));
if (rrset_from_second_node == NULL) {
printf("zone_diff: diff_node: There is no counterpart "
"for RRSet of type %s in second tree.\n",
knot_rrtype_to_string(knot_rrset_type(rrset)));
/* RRSet has been removed. Make a copy and remove. */
knot_rrset_t *rrset_copy = NULL;
int ret = knot_rrset_deep_copy(rrset, &rrset_copy);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: Failed "
printf("zone_diff: diff_node: Failed "
"to copy RRSet. Reason: %s.\n",
knot_strerror(ret));
param->ret = ret;
......@@ -566,24 +624,79 @@ static void knot_zone_diff_node(knot_node_t *node, void *data)
param->changeset,
rrset_copy);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: diff_node: "
printf("zone_diff: diff_node: "
"Failed to remove RRSet.\n");
param->ret = ret;
return;
}
} else {
printf("zone_diff: diff_node: There is a counterpart "
"for RRSet of type %s in second tree.\n",
knot_rrtype_to_string(knot_rrset_type(rrset)));
/* Diff RRSets. */
int ret = knot_zone_diff_rrsets(rrset,
rrset_from_second_node,
param->changeset);
rrset_from_second_node,
param->changeset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: "
printf("zone_diff: "
"Failed to diff RRSets.\n");
param->ret = ret;
return;
}
}
}
/*! \todo free rrsets. */
/*! \todo move to one function with the code above. */
rrsets = knot_node_rrsets(node_in_second_tree);
if (rrsets == NULL) {
printf("zone_diff: Node has no RRSets.\n");
param->ret = KNOT_EBADARG;
return;
}
for (uint i = 0; i < knot_node_rrset_count(node_in_second_tree); i++) {
/* Search for the RRSet in the node from the second tree. */
const knot_rrset_t *rrset = rrsets[i];
assert(rrset);
/* SOAs are handled explicitly. */
if (knot_rrset_type(rrset) == KNOT_RRTYPE_SOA) {
continue;
}
const knot_rrset_t *rrset_from_first_node =
knot_node_rrset(node,
knot_rrset_type(rrset));
if (rrset_from_first_node == NULL) {
printf("zone_diff: diff_node: There is no counterpart "
"for RRSet of type %s in first tree.\n",
knot_rrtype_to_string(knot_rrset_type(rrset)));
/* RRSet has been added. Make a copy and add. */
knot_rrset_t *rrset_copy = NULL;
int ret = knot_rrset_deep_copy(rrset, &rrset_copy);
if (ret != KNOT_EOK) {
printf("zone_diff: diff_node: Failed "
"to copy RRSet. Reason: %s.\n",
knot_strerror(ret));
param->ret = ret;
return;
}
ret = knot_zone_diff_changeset_add_rrset(
param->changeset,
rrset_copy);
if (ret != KNOT_EOK) {
printf("zone_diff: diff_node: "
"Failed to add RRSet.\n");
param->ret = ret;
return;
}
} else {
/* Already handled. */
;
}
}
assert(param->ret == KNOT_EOK);
}
......@@ -592,10 +705,37 @@ static int knot_zone_diff_add_node(knot_node_t *node,
knot_changeset_t *changeset)
{
if (node == NULL || changeset == NULL) {
dbg_zonediff("zone_diff: NULL arguments.\n");
printf("zone_diff: add_node: NULL arguments.\n");
return KNOT_EBADARG;
}
/* Add all rrsets from node. */
const knot_rrset_t **rrsets = knot_node_rrsets(node);
if (rrsets == NULL) {
printf("zone_diff: Node has no RRSets.\n");
return KNOT_EBADARG;
}
for (uint i = 0; i < knot_node_rrset_count(node); i++) {
knot_rrset_t *rrset = NULL;
int ret = knot_rrset_deep_copy(rrsets[i], &rrset);
if (ret != KNOT_EOK) {
printf("zone_diff: remove_node: Could not copy "
"RRSet. Reason: %s.\n",
knot_strerror(ret));
return ret;
}
assert(rrset);
ret = knot_zone_diff_changeset_add_rrset(changeset,
rrset);
if (ret != KNOT_EOK) {
printf("zone_diff: add_node: Cannot add RRSet (%s).\n",
knot_strerror(ret));
return ret;
}
}
return KNOT_EOK;
}
......@@ -603,20 +743,20 @@ static int knot_zone_diff_add_node(knot_node_t *node,
static void knot_zone_diff_add_new_nodes(knot_node_t *node, void *data)
{
if (node == NULL || data == NULL) {
dbg_zonediff("zone_diff: add_new_nodes: NULL arguments.\n");
printf("zone_diff: add_new_nodes: NULL arguments.\n");
return;
}
struct zone_diff_param *param = (struct zone_diff_param *)data;
if (param->changeset == NULL || param->contents == NULL) {
dbg_zonediff("zone_diff: add_new_nodes: NULL arguments.\n");
printf("zone_diff: add_new_nodes: NULL arguments.\n");
param->ret = KNOT_EBADARG;
return;
}
if (param->ret != KNOT_EOK) {
/* Error occured before, no point in continuing. */
dbg_zonediff_detail("zone_diff: add_new_nodes: error: %s\n",
printf_detail("zone_diff: add_new_nodes: error: %s\n",
knot_strerror(param->ret));
return;
}
......@@ -644,10 +784,10 @@ static void knot_zone_diff_add_new_nodes(knot_node_t *node, void *data)
node_owner);
}
if (new_node) {
int ret = knot_zone_diff_add_node(new_node, param->changeset);
if (!new_node) {
int ret = knot_zone_diff_add_node(node, param->changeset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: add_new_nodes: Cannot add "
printf("zone_diff: add_new_nodes: Cannot add "
"node to changeset. Reason: %s.\n",
knot_strerror(ret));
}
......@@ -661,7 +801,7 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
knot_changeset_t **changeset)
{
if (zone1 == NULL || zone2 == NULL) {
dbg_zonediff("zone_diff: NULL argument(s).\n");
printf("zone_diff: NULL argument(s).\n");
return KNOT_EBADARG;
}
......@@ -676,11 +816,11 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
/* Settle SOAs first. */
int ret = knot_zone_diff_load_soas(zone1, zone2, *changeset);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: loas_SOAs failed with error: %s\n",
printf("zone_diff: loas_SOAs failed with error: %s\n",
knot_strerror(ret));
return ret;
}
/* Traverse one tree, compare every node, each RRSet with its rdata. */
struct zone_diff_param param;
param.contents = zone2;
......@@ -690,7 +830,7 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
ret = knot_zone_contents_tree_apply_inorder(zone1, knot_zone_diff_node,
&param);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: Tree traversal failed "
printf("zone_diff: Tree traversal failed "
"with error: %s. Error from inner function: %s\n",
knot_strerror(ret),
knot_strerror(param.ret));
......@@ -702,7 +842,7 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
ret = knot_zone_contents_nsec3_apply_inorder(zone1, knot_zone_diff_node,
&param);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: Tree traversal failed "
printf("zone_diff: Tree traversal failed "
"with error: %s\n",
knot_strerror(ret));
return ret;
......@@ -719,7 +859,7 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
knot_zone_diff_add_new_nodes,
&param);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: Tree traversal failed "
printf("zone_diff: Tree traversal failed "
"with error: %s. Error from inner function: %s\n",
knot_strerror(ret),
knot_strerror(param.ret));
......@@ -733,7 +873,7 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
knot_zone_diff_add_new_nodes,
&param);
if (ret != KNOT_EOK) {
dbg_zonediff("zone_diff: Tree traversal failed "
printf("zone_diff: Tree traversal failed "
"with error: %s\n",
knot_strerror(ret));
return ret;
......@@ -742,13 +882,19 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
return KNOT_EOK;
}
int knot_zone_diff_apply_diff_from_file(knot_zone_t *old_zone,
knot_zone_t *new_zone)
{
;
}
/* Mostly just for testing. We only shall diff zones in memory later. */
int knot_zone_diff_zones(const char *zonefile1, const char *zonefile2)
{
/* Compile test zones. */
int ret = zone_read("example.com.", "tmpzone1", "tmpzone1.db", 0);
int ret = zone_read("example.com.", zonefile1, "tmpzone1.db", 0);
assert(ret == KNOT_EOK);
ret = zone_read("example.com.", "tmpzone2", "tmpzone2.db", 0);
ret = zone_read("example.com.", zonefile2, "tmpzone2.db", 0);
assert(ret == KNOT_EOK);
/* Load test zones. */
zloader_t *loader = NULL;
......
......@@ -25,4 +25,8 @@ int knot_zone_contents_diff(knot_zone_contents_t *zone1,
knot_zone_contents_t *zone2,
knot_changeset_t **changeset);
int knot_zone_diff_zones(const char *zonefile1, const char *zonefile2);
int knot_zone_diff_apply_diff_from_file(knot_zone_t *old_zone,
knot_zone_t *new_zone);
#endif // _KNOT_ZONE_DIFF_H_
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