Commit d420fe5e authored by Dominik Taborsky's avatar Dominik Taborsky

zone-api: cleanup, docs. Incremental version of zone_update is ready.

parent 821b509f
......@@ -139,7 +139,7 @@ static int process_normal(zone_t *zone, list_t *requests)
// Init zone update structure
zone_update_t up;
int ret = zone_update_init(&up, zone, UPDATE_INCREMENTAL | UPDATE_SIGN | UPDATE_REPLACE_CNAMES);
int ret = zone_update_init(&up, zone, UPDATE_INCREMENTAL | UPDATE_SIGN);
if (ret != KNOT_EOK) {
set_rcodes(requests, KNOT_RCODE_SERVFAIL);
return ret;
......
......@@ -900,17 +900,6 @@ int ddns_process_update(const zone_t *zone, const knot_pkt_t *query,
return KNOT_EINVAL;
}
//FIXME: temporary workaround
if (update->change.soa_from == NULL) {
// Copy base SOA RR.
update->change.soa_from =
node_create_rrset(update->zone->contents->apex, KNOT_RRTYPE_SOA);
if (update->change.soa_from == NULL) {
*rcode = ret_to_rcode(KNOT_ENOMEM);
return KNOT_ENOMEM;
}
}
uint32_t sn_old = knot_soa_serial(zone_update_from(update));
// Process all RRs in the authority section.
......@@ -936,33 +925,6 @@ int ddns_process_update(const zone_t *zone, const knot_pkt_t *query,
}
}
if (zone_update_to(update) == NULL) {
// No SOA in the update, create one according to the current policy
if (zone_update_no_change(update)) {
*rcode = KNOT_RCODE_NOERROR;
// No change, no new SOA
return KNOT_EOK;
}
knot_rrset_t *soa_cpy = node_create_rrset(zone_update_get_apex(update), KNOT_RRTYPE_SOA);
if (soa_cpy == NULL) {
*rcode = ret_to_rcode(KNOT_ENOMEM);
return KNOT_ENOMEM;
}
conf_val_t val = conf_zone_get(conf(), C_SERIAL_POLICY, zone->name);
uint32_t old_serial = knot_soa_serial(&soa_cpy->rrs);
uint32_t new_serial = serial_next(old_serial, conf_opt(&val));
if (serial_compare(old_serial, new_serial) >= 0) {
log_zone_warning(zone->name, "updated serial is lower "
"than current, serial %u -> %u",
old_serial, new_serial);
}
knot_soa_serial_set(&soa_cpy->rrs, new_serial);
update->change.soa_to = soa_cpy;
}
*rcode = KNOT_RCODE_NOERROR;
return KNOT_EOK;
}
......@@ -14,13 +14,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <urcu.h>
#include "knot/updates/zone-update.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/mempool.h"
#include "knot/common/log.h"
#include "knot/dnssec/zone-events.h"
#include "knot/updates/apply.h"
#include "knot/zone/serial.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/mempool.h"
#include <urcu.h>
static int add_to_node(zone_node_t *node, const zone_node_t *add_node,
mm_ctx_t *mm)
......@@ -125,12 +129,12 @@ static int init_incremental(zone_update_t *update, zone_t *zone)
}
assert(zone->contents);
//FIXME: JK's zone-api-version of zone_update has a cache, we're ignoring it for now.
//update->synth_nodes = zone_contents_new(zone->name);
//if (update->synth_nodes == NULL) {
// return KNOT_ENOMEM;
// zone_update_clear(update);
//}
// Copy base SOA RR.
update->change.soa_from =
node_create_rrset(update->zone->contents->apex, KNOT_RRTYPE_SOA);
if (update->change.soa_from == NULL) {
return KNOT_ENOMEM;
}
return KNOT_EOK;
}
......@@ -260,9 +264,7 @@ void zone_update_clear(zone_update_t *update)
int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset)
{
if (update->flags & UPDATE_WRITING_ITER) {
return changeset_add_rrset(&update->iteration_changes, rrset);
} else if (update->flags & UPDATE_INCREMENTAL) {
if (update->flags & UPDATE_INCREMENTAL) {
return changeset_add_rrset(&update->change, rrset);
} else if (update->flags & UPDATE_FULL) {
zone_node_t *n = NULL;
......@@ -274,9 +276,7 @@ int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset)
int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset)
{
if (update->flags & UPDATE_WRITING_ITER) {
return changeset_rem_rrset(&update->iteration_changes, rrset);
} else if (update->flags & UPDATE_INCREMENTAL) {
if (update->flags & UPDATE_INCREMENTAL) {
return changeset_rem_rrset(&update->change, rrset);
} else {
// Removing from zone during creation does not make sense, ignore.
......@@ -309,7 +309,6 @@ static bool dnskey_nsec3param_changed(zone_update_t *update)
apex_rr_changed(new_apex, old_apex, KNOT_RRTYPE_NSEC3PARAM));
}
//FIXME: update to new api
static int sign_update(zone_update_t *update,
zone_contents_t *new_contents,
changeset_t *sec_ch)
......@@ -359,18 +358,50 @@ static int sign_update(zone_update_t *update,
return KNOT_EOK;
}
static int set_new_soa(zone_update_t *update)
{
knot_rrset_t *soa_cpy = node_create_rrset(zone_update_get_apex(update), KNOT_RRTYPE_SOA);
if (soa_cpy == NULL) {
return KNOT_ENOMEM;
}
conf_val_t val = conf_zone_get(conf(), C_SERIAL_POLICY, update->zone->name);
uint32_t old_serial = knot_soa_serial(&soa_cpy->rrs);
uint32_t new_serial = serial_next(old_serial, conf_opt(&val));
if (serial_compare(old_serial, new_serial) >= 0) {
log_zone_warning(update->zone->name, "updated serial is lower "
"than current, serial %u -> %u",
old_serial, new_serial);
}
knot_soa_serial_set(&soa_cpy->rrs, new_serial);
update->change.soa_to = soa_cpy;
return KNOT_EOK;
}
int zone_update_commit(zone_update_t *update)
{
int ret = KNOT_EOK;
zone_contents_t *new_contents = NULL;
if (update->flags & UPDATE_INCREMENTAL) {
zone_contents_t *new_contents = NULL;
const bool change_made = !changeset_empty(&update->change);
if (!change_made) {
changeset_clear(&update->change);
return KNOT_EOK;
}
if (zone_update_to(update) == NULL) {
// No SOA in the update, create one according to the current policy
ret = set_new_soa(update);
if (ret != KNOT_EOK) {
return ret;
}
}
// Apply changes.
int ret = apply_changeset(update->zone, &update->change, &new_contents);
ret = apply_changeset(update->zone, &update->change, &new_contents);
if (ret != KNOT_EOK) {
changeset_clear(&update->change);
return ret;
......@@ -379,11 +410,11 @@ int zone_update_commit(zone_update_t *update)
assert(new_contents);
conf_val_t val = conf_zone_get(conf(), C_DNSSEC_SIGNING, update->zone->name);
bool dnssec_enable = conf_bool(&val);
bool dnssec_enable = update->flags & UPDATE_SIGN && conf_bool(&val);
// Sign the update.
changeset_t sec_ch;
if (update->flags & UPDATE_SIGN && dnssec_enable) {
if (dnssec_enable) {
ret = changeset_init(&sec_ch, update->zone->name);
if (ret != KNOT_EOK) {
changeset_clear(&update->change);
......
......@@ -27,28 +27,25 @@
#pragma once
#include "knot/updates/changesets.h"
#include "knot/zone/zone.h"
#include "knot/zone/contents.h"
#include "knot/zone/zone.h"
#include "libknot/internal/mempattern.h"
/*! \brief Structure for zone contents updating / querying \todo to be moved to new ZONE API */
/*! \brief Structure for zone contents updating / querying. */
typedef struct {
zone_t *zone; /*!< Zone being updated. */
zone_contents_t *new_cont; /*!< New zone contents for full updates. */
zone_contents_t *synth_nodes; /*!< Cache for synthesised nodes. */
zone_t *zone; /*!< Zone being updated. */
zone_contents_t *new_cont; /*!< New zone contents for full updates. */
changeset_t change; /*!< Changes we want to apply. */
mm_ctx_t mm; /*!< Memory context used for intermediate nodes. */
changeset_t iteration_changes;
uint8_t flags;
uint8_t flags; /*!< Zone update flags. */
mm_ctx_t mm; /*!< Memory context used for intermediate nodes. */
} zone_update_t;
typedef enum {
UPDATE_FULL = 1 << 0,
UPDATE_INCREMENTAL = 1 << 1,
UPDATE_SIGN = 1 << 2,
UPDATE_DIFF = 1 << 3,
UPDATE_REPLACE_CNAMES = 1 << 4,
UPDATE_WRITING_ITER = 1 << 5
UPDATE_FULL = 1 << 0, /*!< Replace the old zone by a complete new one. */
UPDATE_INCREMENTAL = 1 << 1, /*!< Apply changes to the old zone. */
UPDATE_SIGN = 1 << 2, /*!< Sign the resulting zone. */
UPDATE_DIFF = 1 << 3, /*!< In the case of full update, create a diff for journal. */
} zone_update_flags_t;
/*!
......@@ -57,6 +54,8 @@ typedef enum {
* \param update Zone update structure to init.
* \param zone Init with this zone.
* \param flags Flags to control the behavior of the update.
*
* \return KNOT_E*
*/
int zone_update_init(zone_update_t *update, zone_t *zone, zone_update_flags_t flags);
......@@ -69,14 +68,48 @@ int zone_update_init(zone_update_t *update, zone_t *zone, zone_update_flags_t fl
* \param update Zone update.
* \param dname Dname to search for.
*
* \return Node after zone update.
* \return Node after zone update.
*/
const zone_node_t *zone_update_get_node(zone_update_t *update,
const knot_dname_t *dname);
/*!
* \brief Returns updated zone apex.
*
* \note Returned node is either zone original or synthesized, do *not* free
* or modify.
*
* \param update Zone update.
*
* \return Returns apex after update.
*/
const zone_node_t *zone_update_get_apex(zone_update_t *update);
/*!
* \brief Returns the serial from the current apex.
*
* \param update Zone update.
*
* \return 0 if no apex was found, its serial otherwise.
*/
uint32_t zone_update_current_serial(zone_update_t *update);
/*!
* \brief Returns the SOA rdataset we're updating from.
*
* \param update Zone update.
*
* \return The original SOA rdataset.
*/
const knot_rdataset_t *zone_update_from(zone_update_t *update);
/*!
* \brief Returns the SOA rdataset we're updating to.
*
* \param update Zone update.
*
* \return NULL if no new SOA has been added, new SOA otherwise.
*/
const knot_rdataset_t *zone_update_to(zone_update_t *update);
/*!
......@@ -86,10 +119,38 @@ const knot_rdataset_t *zone_update_to(zone_update_t *update);
*/
void zone_update_clear(zone_update_t *update);
/*!
* \brief Adds an RRSet to the zone.
*
* \param update Zone update.
*
* \return KNOT_E*
*/
int zone_update_add(zone_update_t *update, const knot_rrset_t *rrset);
/*!
* \brief Removes an RRSet from the zone.
*
* \param update Zone update.
*
* \return KNOT_E*
*/
int zone_update_remove(zone_update_t *update, const knot_rrset_t *rrset);
/*!
* \brief Commits all changes to the zone, signs it, saves changes to journal.
*
* \param update Zone update.
*
* \return KNOT_E*
*/
int zone_update_commit(zone_update_t *update);
/*!
* \brief Returns bool whether there are any changes at all.
*
* \param update Zone update.
*/
bool zone_update_no_change(zone_update_t *up);
/*! @} */
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