Commit acd6f105 authored by Dominik Taborsky's avatar Dominik Taborsky

ddns: simplify, copy data to keep possibly removed data accessible

parent 5213459f
......@@ -123,7 +123,7 @@ static void iter_next_node(changeset_iter_t *ch_it, hattrie_iter_t *t_it)
}
/*! \brief Gets next RRSet from trie iterators. */
static knot_rrset_t get_next_rr(changeset_iter_t *ch_it, hattrie_iter_t *t_it) // pun intented
static knot_rrset_t get_next_rr(changeset_iter_t *ch_it, hattrie_iter_t *t_it)
{
if (ch_it->node == NULL || ch_it->node_pos == ch_it->node->rrset_count) {
iter_next_node(ch_it, t_it);
......@@ -138,20 +138,6 @@ static knot_rrset_t get_next_rr(changeset_iter_t *ch_it, hattrie_iter_t *t_it) /
return node_rrset_at(ch_it->node, ch_it->node_pos++);
}
static bool intersection_exists(const knot_rrset_t *node_rr, const knot_rrset_t *inc_rr)
{
knot_rdataset_t intersection;
knot_rdataset_init(&intersection);
int ret = knot_rdataset_intersect(&node_rr->rrs, &inc_rr->rrs, &intersection, NULL);
if (ret != KNOT_EOK) {
return false;
}
const uint16_t rr_count = intersection.rr_count;
knot_rdataset_clear(&intersection, NULL);
return rr_count > 0;
}
static bool need_to_insert(zone_contents_t *counterpart, const knot_rrset_t *rr)
{
zone_node_t *node = zone_contents_find_node_for_rr(counterpart, rr);
......@@ -163,27 +149,23 @@ static bool need_to_insert(zone_contents_t *counterpart, const knot_rrset_t *rr)
return true;
}
knot_rrset_t node_rr = node_rrset(node, rr->type);
if (!intersection_exists(&node_rr, rr)) {
return true;
}
// Subtract the data from node's RRSet.
int ret = knot_rdataset_subtract(&node->rrs->rrs, &rr->rrs, NULL);
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
int ret = knot_rdataset_subtract(rrs, &rr->rrs, NULL);
if (ret != KNOT_EOK) {
return true;
}
if (knot_rrset_empty(&node_rr)) {
if (knot_rdataset_size(rrs) == 0) {
// Remove empty type.
node_remove_rdataset(node, rr->type);
}
if (node->rrset_count == 0) {
// Remove empty node.
zone_tree_t *t = knot_rrset_is_nsec3rel(rr) ?
counterpart->nsec3_nodes : counterpart->nodes;
zone_contents_delete_empty_node(counterpart, t, node);
if (node->rrset_count == 0) {
// Remove empty node.
zone_tree_t *t = knot_rrset_is_nsec3rel(rr) ?
counterpart->nsec3_nodes : counterpart->nodes;
zone_contents_delete_empty_node(counterpart, t, node);
}
}
return false;
......@@ -275,10 +257,22 @@ int changeset_add_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_r
/* Check if there's any removal and remove that, then add this
* addition anyway. Required to change TTLs. */
if (check_redundancy) {
/* If we delete the rrset, we need to hold a copy to add it later */
rrset = knot_rrset_copy(rrset, NULL);
if (rrset == NULL) {
return KNOT_ENOMEM;
}
need_to_insert(ch->remove, rrset);
}
return add_rr_to_contents(ch->add, &ch->soa_to, rrset);
int ret = add_rr_to_contents(ch->add, &ch->soa_to, rrset);
if (check_redundancy) {
knot_rrset_free((knot_rrset_t **)&rrset, NULL);
}
return ret;
}
int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_redundancy)
......@@ -286,10 +280,22 @@ int changeset_rem_rrset(changeset_t *ch, const knot_rrset_t *rrset, bool check_r
/* Check if there's any addition and remove that, then add this
* removal anyway. */
if (check_redundancy) {
/* If we delete the rrset, we need to hold a copy to add it later */
rrset = knot_rrset_copy(rrset, NULL);
if (rrset == NULL) {
return KNOT_ENOMEM;
}
need_to_insert(ch->add, rrset);
}
return add_rr_to_contents(ch->remove, &ch->soa_from, rrset);
int ret = add_rr_to_contents(ch->remove, &ch->soa_from, rrset);
if (check_redundancy) {
knot_rrset_free((knot_rrset_t **)&rrset, NULL);
}
return ret;
}
int changeset_merge(changeset_t *ch1, const changeset_t *ch2)
......
......@@ -520,23 +520,13 @@ static int process_rem_rr(const knot_rrset_t *rr,
return KNOT_EOK;
}
knot_rrset_t intersection;
knot_rrset_init(&intersection, to_modify.owner, to_modify.type,
KNOT_CLASS_IN);
int ret = knot_rdataset_intersect(&to_modify.rrs, &rr->rrs,
&intersection.rrs, NULL);
if (ret != KNOT_EOK) {
return ret;
}
if (knot_rrset_empty(&intersection)) {
// No such RR
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
if (!knot_rdataset_member(rrs, rr->rrs.data, false)) {
// Node does not contain this RR
return KNOT_EOK;
}
assert(intersection.rrs.rr_count == 1);
ret = zone_update_remove(update, &intersection);
knot_rdataset_clear(&intersection.rrs, NULL);
return ret;
return rem_rr_to_chgset(rr, update);
}
/*!< \brief Removes RRSet from zone. */
......
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