Commit 779fc052 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

changesets: fixed equal rdata with different ttl cancel out

parent 54f688c1
......@@ -339,7 +339,7 @@ int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
knot_rdataset_t *changed_rrs = node_rdataset(node, rr->type);
// Subtract changeset RRS from node RRS.
ret = knot_rdataset_subtract(changed_rrs, &rr->rrs, NULL);
ret = knot_rdataset_subtract(changed_rrs, &rr->rrs, false, NULL);
if (ret != KNOT_EOK) {
clear_new_rrs(node, rr->type);
return ret;
......
......@@ -156,7 +156,7 @@ static void check_redundancy(zone_contents_t *counterpart, const knot_rrset_t *r
// Subtract the data from node's RRSet.
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
int ret = knot_rdataset_subtract(rrs, &rr->rrs, NULL);
int ret = knot_rdataset_subtract(rrs, &rr->rrs, true, NULL);
if (ret != KNOT_EOK) {
return;
}
......@@ -424,7 +424,7 @@ static int preapply_fix_rrset(const knot_rrset_t *apply, bool adding, void *data
ret = knot_rdataset_intersect(zrdataset, &apply->rrs, &fixrrset->rrs, ctx->mm);
} else {
if (zrdataset != NULL) {
ret = knot_rdataset_subtract(&fixrrset->rrs, zrdataset, ctx->mm);
ret = knot_rdataset_subtract(&fixrrset->rrs, zrdataset, true, ctx->mm);
}
}
if (ret == KNOT_EOK && !knot_rrset_empty(fixrrset)) {
......
......@@ -632,7 +632,7 @@ static int remove_rr(zone_contents_t *z, const knot_rrset_t *rr,
knot_rdataset_t *node_rrs = node_rdataset(node, rr->type);
// Subtract changeset RRS from node RRS.
int ret = knot_rdataset_subtract(node_rrs, &rr->rrs, NULL);
int ret = knot_rdataset_subtract(node_rrs, &rr->rrs, false, NULL);
if (ret != KNOT_EOK) {
return ret;
}
......
......@@ -385,7 +385,7 @@ int knot_rdataset_intersect(const knot_rdataset_t *a, const knot_rdataset_t *b,
_public_
int knot_rdataset_subtract(knot_rdataset_t *from, const knot_rdataset_t *what,
knot_mm_t *mm)
bool cmp_ttl, knot_mm_t *mm)
{
if (from == NULL || what == NULL) {
return KNOT_EINVAL;
......@@ -401,6 +401,12 @@ int knot_rdataset_subtract(knot_rdataset_t *from, const knot_rdataset_t *what,
const knot_rdata_t *to_remove = knot_rdataset_at(what, i);
int pos_to_remove = find_rr_pos(from, to_remove);
if (pos_to_remove >= 0) {
if (cmp_ttl) {
const knot_rdata_t *from_remove = knot_rdataset_at(from, pos_to_remove);
if (knot_rdata_ttl(from_remove) != knot_rdata_ttl(to_remove)) {
continue;
}
}
int ret = remove_rr_at(from, pos_to_remove, mm);
if (ret != KNOT_EOK) {
return ret;
......
......@@ -177,13 +177,14 @@ int knot_rdataset_intersect(const knot_rdataset_t *a, const knot_rdataset_t *b,
/*!
* \brief Does set-like RRS subtraction. \a from RRS is changed.
* \param from RRS to subtract from.
* \param what RRS to subtract.
* \param mm Memory context use to reallocated \a from data.
* \param from RRS to subtract from.
* \param what RRS to subtract.
* \param cmp_ttl Compare TTL indicator.
* \param mm Memory context use to reallocated \a from data.
* \return KNOT_E*
*/
int knot_rdataset_subtract(knot_rdataset_t *from, const knot_rdataset_t *what,
knot_mm_t *mm);
bool cmp_ttl, knot_mm_t *mm);
/*!
* \brief Sorts the dataset. Removes the element if found to be duplicate.
......
......@@ -29,7 +29,7 @@
int main(int argc, char *argv[])
{
plan(34);
plan(35);
// Test init
knot_rdataset_t rdataset;
......@@ -153,32 +153,36 @@ int main(int argc, char *argv[])
knot_rdataset_clear(&intersection, NULL);
// Test subtract
ok(knot_rdataset_subtract(NULL, NULL, NULL) == KNOT_EINVAL,
ok(knot_rdataset_subtract(NULL, NULL, false, NULL) == KNOT_EINVAL,
"rdataset: subtract NULL.");
ret = knot_rdataset_copy(&copy, &rdataset, NULL);
assert(ret == KNOT_EOK);
ok(knot_rdataset_subtract(&copy, &copy, NULL) == KNOT_EOK &&
ok(knot_rdataset_subtract(&copy, &copy, true, NULL) == KNOT_EOK &&
copy.rr_count == 0, "rdataset: subtract self.");
ret = knot_rdataset_copy(&copy, &rdataset, NULL);
assert(ret == KNOT_EOK);
ret = knot_rdataset_subtract(&copy, &rdataset, NULL);
ret = knot_rdataset_subtract(&copy, &rdataset, true, NULL);
bool subtract_ok = ret == KNOT_EOK && copy.rr_count == 0;
ok(subtract_ok, "rdataset: subtract identical.");
RDATASET_INIT_WITH(rdataset_lo, rdata_lo);
RDATASET_INIT_WITH(rdataset_gt, rdata_gt);
data_before = rdataset_lo.data;
ret = knot_rdataset_subtract(&rdataset_lo, &rdataset_gt, NULL);
ret = knot_rdataset_subtract(&rdataset_lo, &rdataset_gt, true, NULL);
subtract_ok = ret == KNOT_EOK && rdataset_lo.rr_count == 1 &&
rdataset_lo.data == data_before;
ok(subtract_ok, "rdataset: subtract no common.");
ret = knot_rdataset_subtract(&rdataset, &rdataset_gt, NULL);
ret = knot_rdataset_subtract(&rdataset, &rdataset_gt, true, NULL);
subtract_ok = ret == KNOT_EOK && rdataset.rr_count == 2;
ok(subtract_ok, "rdataset: subtract different TTL disabled.");
ret = knot_rdataset_subtract(&rdataset, &rdataset_gt, false, NULL);
subtract_ok = ret == KNOT_EOK && knot_rdataset_eq(&rdataset, &rdataset_lo);
ok(subtract_ok, "rdataset: subtract normal.");
ok(subtract_ok, "rdataset: subtract different TTL enabled.");
ret = knot_rdataset_subtract(&rdataset, &rdataset_lo, NULL);
ret = knot_rdataset_subtract(&rdataset, &rdataset_lo, true, NULL);
subtract_ok = ret == KNOT_EOK && rdataset.rr_count == 0 &&
rdataset.data == NULL;
ok(subtract_ok, "rdataset: subtract last.");
......
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