Commit 5110b975 authored by Lubos Slovak's avatar Lubos Slovak

SOA adding in UPDATE.

refs #2111 @35m
parent 3d4a9633
......@@ -1989,11 +1989,102 @@ static knot_node_t *xfrin_add_new_node(knot_zone_contents_t *contents,
/*----------------------------------------------------------------------------*/
static int xfrin_replace_soa_in_node(knot_node_t *node,
knot_rrset_t *soa_new,
knot_changes_t *changes,
knot_zone_contents_t *contents)
{
// remove the SOA RRSet from the node
dbg_xfrin_verb("Removing SOA.\n");
knot_rrset_t *soa_old = knot_node_remove_rrset(node, KNOT_RRTYPE_SOA);
assert(soa_old != NULL);
// add the old RRSet to the list of old RRSets
int ret = xfrin_changes_check_rrsets(&changes->old_rrsets,
&changes->old_rrsets_count,
&changes->old_rrsets_allocated, 1);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add old RRSet to list.\n");
return ret;
}
// save also the SOA RDATA, because RDATA are not deleted with the RRSet
// The count should be 1, but just to be sure....
int count = knot_rrset_rdata_rr_count(soa_old);
ret = xfrin_changes_check_rdata(&changes->old_rdata,
&changes->old_rdata_types,
changes->old_rdata_count,
&changes->old_rdata_allocated, count);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add old RDATA to list.\n");
return ret;
}
// save the SOA to the new RRSet, so that it is deleted if the
// apply fails
ret = xfrin_changes_check_rrsets(&changes->new_rrsets,
&changes->new_rrsets_count,
&changes->new_rrsets_allocated, 1);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add new RRSet to list.\n");
return ret;
}
// The count should be 1, but just to be sure....
count = knot_rrset_rdata_rr_count(soa_new);
// save the new SOA RDATA
ret = xfrin_changes_check_rdata(&changes->new_rdata,
&changes->new_rdata_types,
changes->new_rdata_count,
&changes->new_rdata_allocated, count);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add new RDATA to list.\n");
return ret;
}
changes->old_rrsets[changes->old_rrsets_count++] = soa_old;
/*! \todo Maybe check if the SOA does not have more RDATA? */
dbg_xfrin_verb("Adding RDATA from old SOA to the list of old RDATA.\n");
xfrin_changes_add_rdata(changes->old_rdata, changes->old_rdata_types,
&changes->old_rdata_count, soa_old->rdata,
KNOT_RRTYPE_SOA);
// store RRSIGs from the old SOA to the new SOA
knot_rrset_set_rrsigs(soa_new, knot_rrset_get_rrsigs(soa_old));
// insert the new SOA RRSet to the node
dbg_xfrin_verb("Adding SOA.\n");
//ret = knot_node_add_rrset(node, soa_new, 0);
ret = knot_zone_contents_add_rrset(contents, soa_new, &node,
KNOT_RRSET_DUPL_SKIP, 1);
if (ret < 0) {
dbg_xfrin("Failed to add RRSet to node.\n");
return KNOT_ERROR;
}
assert(ret == 0);
changes->new_rrsets[changes->new_rrsets_count++] = soa_new;
dbg_xfrin_verb("Adding RDATA from new SOA to the list of new RDATA.\n");
xfrin_changes_add_rdata(changes->new_rdata,
changes->new_rdata_types,
&changes->new_rdata_count,
knot_rrset_get_rdata(soa_new),
knot_rrset_type(soa_new));
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
static int xfrin_apply_add_normal(knot_changes_t *changes,
knot_rrset_t *add,
knot_node_t *node,
knot_rrset_t **rrset,
knot_zone_contents_t *contents)
knot_zone_contents_t *contents,
knot_changeset_type_t chtype)
{
assert(changes != NULL);
assert(add != NULL);
......@@ -2007,6 +2098,27 @@ dbg_xfrin_exec_detail(
dbg_xfrin_detail("applying rrset:\n");
knot_rrset_dump(add, 0);
);
/*
* DDNS special case: Adding SOA.
* 1) If trying to add SOA to non-apex node, or the
* serial is less than the current serial, ignore.
* 2) Otherwise, replace the current SOA.
*/
if (chtype == KNOT_CHANGESET_TYPE_DDNS
&& knot_rrset_type(add) == KNOT_RRTYPE_SOA) {
if (knot_node_rrset(node, KNOT_RRTYPE_SOA) == NULL
|| ns_serial_compare(knot_rdata_soa_serial(knot_rrset_rdata(
knot_node_rrset(node, KNOT_RRTYPE_SOA))),
knot_rdata_soa_serial(knot_rrset_rdata(add)
)) > 0
) {
return KNOT_EOK;
} else {
return xfrin_replace_soa_in_node(node, add, changes,
contents);
}
}
int copied = 0;
/*! \note Reusing RRSet from previous function caused it not to be
......@@ -2093,6 +2205,7 @@ dbg_xfrin_exec_detail(
*
* TODO: add the 'add' rrset to list of old RRSets?
*/
dbg_xfrin_detail("Merging RRSets with owners: %s, %s types: %s, %s\n",
(*rrset)->owner->name, add->owner->name,
knot_rrtype_to_string((*rrset)->type),
......@@ -2742,7 +2855,8 @@ dbg_xfrin_exec_detail(
contents);
} else {
ret = xfrin_apply_add_normal(changes, chset->add[i],
node, &rrset, contents);
node, &rrset, contents,
chset->type);
}
assert(ret != KNOT_EOK);
......@@ -2822,97 +2936,18 @@ static int xfrin_apply_replace_soa(knot_zone_contents_t *contents,
knot_node_t *node = knot_zone_contents_get_apex(contents);
assert(node != NULL);
int ret = 0;
assert(node != NULL);
// set the node copy as the apex of the contents
contents->apex = node;
// remove the SOA RRSet from the apex
dbg_xfrin_verb("Removing SOA.\n");
knot_rrset_t *rrset = knot_node_remove_rrset(node, KNOT_RRTYPE_SOA);
assert(rrset != NULL);
// add the old RRSet to the list of old RRSets
ret = xfrin_changes_check_rrsets(&changes->old_rrsets,
&changes->old_rrsets_count,
&changes->old_rrsets_allocated, 1);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add old RRSet to list.\n");
return ret;
}
// save also the SOA RDATA, because RDATA are not deleted with the
// RRSet
ret = xfrin_changes_check_rdata(&changes->old_rdata,
&changes->old_rdata_types,
changes->old_rdata_count,
&changes->old_rdata_allocated, 1);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add old RDATA to list.\n");
return ret;
}
// save the SOA to the new RRSet, so that it is deleted if the
// apply fails
ret = xfrin_changes_check_rrsets(&changes->new_rrsets,
&changes->new_rrsets_count,
&changes->new_rrsets_allocated, 1);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add new RRSet to list.\n");
return ret;
int ret = xfrin_replace_soa_in_node(node, chset->soa_to, changes,
contents);
if (ret == KNOT_EOK) {
// remove the SOA from the changeset, so it will not be deleted
// after successful apply
chset->soa_to = NULL;
}
int count = knot_rrset_rdata_rr_count(rrset);
count += knot_rrset_rdata_rr_count(chset->soa_to);
// save the new SOA RDATA
ret = xfrin_changes_check_rdata(&changes->new_rdata,
&changes->new_rdata_types,
changes->new_rdata_count,
&changes->new_rdata_allocated, count);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to add new RDATA to list.\n");
return ret;
}
changes->old_rrsets[changes->old_rrsets_count++] = rrset;
/*! \todo Maybe check if the SOA does not have more RDATA? */
dbg_xfrin_verb("Adding RDATA from old SOA to the list of old RDATA.\n");
xfrin_changes_add_rdata(changes->old_rdata, changes->old_rdata_types,
&changes->old_rdata_count, rrset->rdata,
KNOT_RRTYPE_SOA);
// store RRSIGs from the old SOA to the new SOA
knot_rrset_set_rrsigs(chset->soa_to, knot_rrset_get_rrsigs(rrset));
// insert the new SOA RRSet to the node
dbg_xfrin_verb("Adding SOA.\n");
//ret = knot_node_add_rrset(node, chset->soa_to, 0);
ret = knot_zone_contents_add_rrset(contents, chset->soa_to, &node,
KNOT_RRSET_DUPL_SKIP, 1);
if (ret < 0) {
dbg_xfrin("Failed to add RRSet to node.\n");
return KNOT_ERROR;
}
assert(ret == 0);
changes->new_rrsets[changes->new_rrsets_count++] = chset->soa_to;
dbg_xfrin_verb("Adding RDATA from new SOA to the list of new RDATA.\n");
xfrin_changes_add_rdata(changes->new_rdata,
changes->new_rdata_types,
&changes->new_rdata_count,
knot_rrset_get_rdata(chset->soa_to),
knot_rrset_type(chset->soa_to));
// remove the SOA from the changeset, so it will not be deleted after
// successful apply
chset->soa_to = NULL;
return KNOT_EOK;
return ret;
}
/*----------------------------------------------------------------------------*/
......
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