Commit e5370973 authored by Jan Kadlec's avatar Jan Kadlec

Zone adjusting cleanup, missing docu added.

- Dropped unused adjusting functions
- Moved one into xfr-in.c
- Removed obsolete API parameters for changeset application funtion
parent 5fd26c1d
......@@ -1274,7 +1274,7 @@ static int zones_process_update_auth(knot_zone_t *zone,
}
} else {
// Set NSEC3 nodes if no new signatures were created (or auto DNSSEC is off)
ret = knot_zone_contents_adjust_nsec3_tree(new_contents);
ret = knot_zone_contents_adjust_nsec3_pointers(new_contents);
if (ret != KNOT_EOK) {
zones_store_changesets_rollback(transaction);
zones_free_merged_changesets(chgsets, sec_chs);
......@@ -2600,7 +2600,7 @@ int zones_store_and_apply_chgsets(knot_changesets_t *chs,
}
/* Now, try to apply the changesets to the zone. */
apply_ret = xfrin_apply_changesets(zone, chs, new_contents, true, NULL);
apply_ret = xfrin_apply_changesets(zone, chs, new_contents);
if (apply_ret != KNOT_EOK) {
log_zone_error("%s Failed to apply changesets.\n", msgpref);
......@@ -3055,8 +3055,7 @@ int zones_journal_apply(knot_zone_t *zone)
chsets->count, zd->conf->name);
knot_zone_contents_t *contents = NULL;
int apply_ret = xfrin_apply_changesets(zone, chsets,
&contents, true,
NULL);
&contents);
if (apply_ret != KNOT_EOK) {
log_server_error("Failed to apply changesets to"
" '%s' - Apply failed: %s\n",
......@@ -3212,8 +3211,7 @@ int zones_do_diff_and_sign(const conf_zone_t *z, knot_zone_t *zone,
/* Apply DNSSEC changeset. */
if (new_signatures) {
ret = xfrin_apply_changesets(zone, sec_chs,
&new_contents, true,
NULL);
&new_contents);
if (ret != KNOT_EOK) {
zones_store_changesets_rollback(transaction);
zones_free_merged_changesets(diff_chs, sec_chs);
......
......@@ -29,6 +29,7 @@
#include "libknot/dname.h"
#include "libknot/zone/zone.h"
#include "libknot/dnssec/zone-nsec.h"
#include "libknot/dnssec/zone-sign.h"
#include "libknot/packet/query.h"
#include "libknot/common.h"
#include "libknot/updates/changesets.h"
......@@ -2506,6 +2507,42 @@ static int xfrin_remove_empty_nodes(knot_zone_contents_t *z)
/*----------------------------------------------------------------------------*/
static int adjust_nsec3_changes(knot_zone_contents_t *contents,
hattrie_t *changes)
{
if (contents->nsec3_nodes == NULL) {
return KNOT_EOK;
}
hattrie_iter_t *itt = hattrie_iter_begin(changes, false);
if (itt == NULL) {
return KNOT_ENOMEM;
}
while (!hattrie_iter_finished(itt)) {
signed_info_t *val = (signed_info_t *)(*hattrie_iter_val(itt));
const knot_dname_t *dname = val->dname;
assert(dname);
const knot_dname_t *hash = val->hashed_dname;
if (hash) {
knot_node_t *nsec3_node =
knot_zone_contents_get_nsec3_node(contents, hash);
if (nsec3_node) {
knot_node_t *normal_node =
knot_zone_contents_get_node(contents,
dname);
if (normal_node) {
normal_node->nsec3_node = nsec3_node;
}
}
}
hattrie_iter_next(itt);
}
hattrie_iter_free(itt);
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
int xfrin_prepare_zone_copy(knot_zone_contents_t *old_contents,
knot_zone_contents_t **new_contents)
{
......@@ -2567,7 +2604,7 @@ int xfrin_prepare_zone_copy(knot_zone_contents_t *old_contents,
/*----------------------------------------------------------------------------*/
int xfrin_finalize_updated_zone(knot_zone_contents_t *contents_copy,
bool set_nsec3,
bool set_nsec3_names,
const hattrie_t *sorted_changes)
{
if (contents_copy == NULL) {
......@@ -2595,11 +2632,11 @@ int xfrin_finalize_updated_zone(knot_zone_contents_t *contents_copy,
}
dbg_xfrin("Adjusting zone contents.\n");
if (set_nsec3) {
if (set_nsec3_names) {
if (sorted_changes) {
ret = knot_zone_contents_adjust_pointers(contents_copy);
ret = knot_zone_contents_adjust_nsec3_changes(contents_copy,
(void *)sorted_changes);
ret = adjust_nsec3_changes(contents_copy,
(void *)sorted_changes);
} else {
ret = knot_zone_contents_adjust_full(contents_copy,
NULL, NULL);
......@@ -2665,8 +2702,7 @@ int xfrin_apply_changesets_dnssec(knot_zone_contents_t *z_old,
int xfrin_apply_changesets(knot_zone_t *zone,
knot_changesets_t *chsets,
knot_zone_contents_t **new_contents,
bool full_adjust, const hattrie_t *sorted_changes)
knot_zone_contents_t **new_contents)
{
if (zone == NULL || chsets == NULL || EMPTY_LIST(chsets->sets)
|| new_contents == NULL) {
......@@ -2714,8 +2750,7 @@ int xfrin_apply_changesets(knot_zone_t *zone,
*/
dbg_xfrin_verb("Finalizing updated zone...\n");
ret = xfrin_finalize_updated_zone(contents_copy,
full_adjust, sorted_changes);
ret = xfrin_finalize_updated_zone(contents_copy, true, NULL);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to finalize updated zone: %s\n",
knot_strerror(ret));
......
......@@ -177,12 +177,28 @@ void xfrin_free_changesets(knot_changesets_t **changesets);
*/
int xfrin_process_ixfr_packet(knot_ns_xfr_t *xfr);
/*!
* \brief Applies changesets *with* zone shallow copy.
*
* \param zone Zone to be updated.
* \param chsets Changes to be made.
* \param new_contents New zone will be returned using this arg.
* \return KNOT_E*
*/
int xfrin_apply_changesets(knot_zone_t *zone,
knot_changesets_t *chsets,
knot_zone_contents_t **new_contents,
bool full_adjust,
const hattrie_t *sorted_changes);
knot_zone_contents_t **new_contents);
/*!
* \brief Applies changesets *without* zone shallow copy.
*
* \param z_old Old contents for possible rollbacks.
* \param z_new Post DDNS/reload zone.
* \param sec_chsets Changes with RRSIGs/NSEC(3)s.
* \param chsets DDNS/reload changes, for rollback.
* \param sorted_changes Used for node->nsec3 node mapping.
* \return KNOT_E*
*/
int xfrin_apply_changesets_dnssec(knot_zone_contents_t *z_old,
knot_zone_contents_t *z_new,
knot_changesets_t *sec_chsets,
......@@ -192,8 +208,16 @@ int xfrin_apply_changesets_dnssec(knot_zone_contents_t *z_old,
int xfrin_prepare_zone_copy(knot_zone_contents_t *old_contents,
knot_zone_contents_t **new_contents);
/*!
* \brief Sets pointers and NSEC3 nodes after signing/DDNS.
* \param contents_copy Contents to be updated.
* \param set_nsec3_names Set to true if NSEC3 hashes should be set.
* \param sorted_changes If this is non-NULL, it is used for normal node->NSEC3
* node mapping, no hashes are calculated.
* \return KNOT_E*
*/
int xfrin_finalize_updated_zone(knot_zone_contents_t *contents_copy,
bool set_nsec3,
bool set_nsec3_names,
const hattrie_t *sorted_changes);
int xfrin_switch_zone(knot_zone_t *zone,
......
......@@ -1295,73 +1295,40 @@ static int knot_zone_contents_adjust_nodes(knot_zone_tree_t *nodes,
/*----------------------------------------------------------------------------*/
int knot_zone_contents_adjust_pointers(knot_zone_contents_t *contents)
static int knot_zone_contents_adjust_nsec3_tree(knot_zone_contents_t *contents)
{
if (contents->nsec3_nodes == NULL) {
return KNOT_EOK;
}
// adjusting parameters
knot_zone_adjust_arg_t adjust_arg = { .first_node = NULL,
.previous_node = NULL,
.zone = contents };
int ret = knot_zone_contents_adjust_nodes(contents->nodes, &adjust_arg,
adjust_pointers);
if (ret != KNOT_EOK) {
return ret;
}
return knot_zone_contents_adjust_nsec3_tree(contents);
return knot_zone_contents_adjust_nodes(contents->nsec3_nodes,
&adjust_arg,
knot_zone_contents_adjust_nsec3_node);
}
/*----------------------------------------------------------------------------*/
int knot_zone_contents_adjust_nsec3_pointers(knot_zone_contents_t *contents)
int knot_zone_contents_adjust_pointers(knot_zone_contents_t *contents)
{
if (contents->nsec3_nodes == NULL) {
return KNOT_EOK;
}
// adjusting parameters
knot_zone_adjust_arg_t adjust_arg = { .first_node = NULL,
.previous_node = NULL,
.zone = contents };
return knot_zone_contents_adjust_nodes(contents->nodes, &adjust_arg,
adjust_nsec3_pointers);
}
int knot_zone_contents_adjust_nsec3_changes(knot_zone_contents_t *contents,
void *data)
{
if (contents->nsec3_nodes == NULL) {
return KNOT_EOK;
}
hattrie_iter_t *itt = hattrie_iter_begin((hattrie_t *)data,
false);
if (itt == NULL) {
return KNOT_ENOMEM;
}
while (!hattrie_iter_finished(itt)) {
signed_info_t *val = (signed_info_t *)(*hattrie_iter_val(itt));
const knot_dname_t *dname = val->dname;
assert(dname);
const knot_dname_t *hash = val->hashed_dname;
if (hash) {
knot_node_t *nsec3_node =
knot_zone_contents_get_nsec3_node(contents, hash);
if (nsec3_node) {
knot_node_t *normal_node =
knot_zone_contents_get_node(contents,
dname);
if (normal_node) {
normal_node->nsec3_node = nsec3_node;
}
}
}
hattrie_iter_next(itt);
int ret = knot_zone_contents_adjust_nodes(contents->nodes, &adjust_arg,
adjust_pointers);
if (ret != KNOT_EOK) {
return ret;
}
hattrie_iter_free(itt);
return KNOT_EOK;
return knot_zone_contents_adjust_nsec3_tree(contents);
}
/*----------------------------------------------------------------------------*/
int knot_zone_contents_adjust_nsec3_tree(knot_zone_contents_t *contents)
int knot_zone_contents_adjust_nsec3_pointers(knot_zone_contents_t *contents)
{
if (contents->nsec3_nodes == NULL) {
return KNOT_EOK;
......@@ -1370,9 +1337,8 @@ int knot_zone_contents_adjust_nsec3_tree(knot_zone_contents_t *contents)
knot_zone_adjust_arg_t adjust_arg = { .first_node = NULL,
.previous_node = NULL,
.zone = contents };
return knot_zone_contents_adjust_nodes(contents->nsec3_nodes,
&adjust_arg,
knot_zone_contents_adjust_nsec3_node);
return knot_zone_contents_adjust_nodes(contents->nodes, &adjust_arg,
adjust_nsec3_pointers);
}
/*----------------------------------------------------------------------------*/
......
......@@ -329,22 +329,15 @@ knot_node_t *knot_zone_contents_get_apex(
/*!
* \brief Sets parent and previous pointers and node flags. (cheap operation)
* For both normal and NSEC3 tree
*/
int knot_zone_contents_adjust_pointers(knot_zone_contents_t *contents);
/*!
* \brief Sets NSEC3 nodes for normal nodes. (costly operation)
* \brief Sets NSEC3 nodes for normal nodes. (costly operation, calculates hash)
*/
int knot_zone_contents_adjust_nsec3_pointers(knot_zone_contents_t *);
int knot_zone_contents_adjust_nsec3_changes(knot_zone_contents_t *contents,
void *data);
/*!
* \brief Sets parent and previous pointers and node flags. (cheap operation)
*/
int knot_zone_contents_adjust_nsec3_tree(knot_zone_contents_t *);
/*!
* \brief Sets parent and previous pointers, sets node flags and NSEC3 links.
* This has to be called before the zone can be served.
......
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