Commit 335bdb7c authored by Jan Kadlec's avatar Jan Kadlec

zone-events: ixfr: better logging, state switching, merged in and out

contexts.

- Also removed knot_ from changesets
parent 93b6a42a
......@@ -142,8 +142,8 @@ static int connect_nsec_nodes(zone_node_t *a, zone_node_t *b,
dbg_dnssec_detail("Adding new NSEC to changeset.\n");
// Add new NSEC to the changeset (no matter if old was removed)
return knot_changeset_add_rrset(data->changeset, new_nsec,
KNOT_CHANGESET_ADD);
return changeset_add_rrset(data->changeset, new_nsec,
CHANGESET_ADD);
}
/* - API - iterations ------------------------------------------------------- */
......@@ -205,7 +205,7 @@ int knot_nsec_chain_iterate_create(knot_zone_tree_t *nodes,
* \brief Add entry for removed NSEC to the changeset.
*/
int knot_nsec_changeset_remove(const zone_node_t *n,
knot_changeset_t *changeset)
changeset_t *changeset)
{
if (changeset == NULL) {
return KNOT_EINVAL;
......@@ -219,8 +219,8 @@ int knot_nsec_changeset_remove(const zone_node_t *n,
}
if (nsec) {
// update changeset
result = knot_changeset_add_rrset(changeset, nsec,
KNOT_CHANGESET_REMOVE);
result = changeset_add_rrset(changeset, nsec,
CHANGESET_REMOVE);
if (result != KNOT_EOK) {
knot_rrset_free(&nsec, NULL);
return result;
......@@ -253,8 +253,8 @@ int knot_nsec_changeset_remove(const zone_node_t *n,
}
// store RRSIG
result = knot_changeset_add_rrset(changeset, synth_rrsigs,
KNOT_CHANGESET_REMOVE);
result = changeset_add_rrset(changeset, synth_rrsigs,
CHANGESET_REMOVE);
if (result != KNOT_EOK) {
knot_rrset_free(&synth_rrsigs, NULL);
return result;
......@@ -288,7 +288,7 @@ bool knot_nsec_empty_nsec_and_rrsigs_in_node(const zone_node_t *n)
* \brief Create new NSEC chain, add differences from current into a changeset.
*/
int knot_nsec_create_chain(const zone_contents_t *zone, uint32_t ttl,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(zone);
assert(zone->nodes);
......
......@@ -39,7 +39,7 @@
*/
typedef struct {
uint32_t ttl; // TTL for NSEC(3) records
knot_changeset_t *changeset; // Changeset for NSEC(3) changes
changeset_t *changeset; // Changeset for NSEC(3) changes
const zone_contents_t *zone; // Updated zone
} nsec_chain_iterate_data_t;
......@@ -96,7 +96,7 @@ int knot_nsec_chain_iterate_create(knot_zone_tree_t *nodes,
* \return Error code, KNOT_EOK if successful.
*/
int knot_nsec_changeset_remove(const zone_node_t *n,
knot_changeset_t *changeset);
changeset_t *changeset);
/*!
* \brief Checks whether the node is empty or eventually contains only NSEC and
......@@ -119,6 +119,6 @@ bool knot_nsec_empty_nsec_and_rrsigs_in_node(const zone_node_t *n);
* \return Error code, KNOT_EOK if successful.
*/
int knot_nsec_create_chain(const zone_contents_t *zone, uint32_t ttl,
knot_changeset_t *changeset);
changeset_t *changeset);
#endif // _KNOT_DNSSEC_NSEC_CHAIN_FIX_H_
......@@ -415,7 +415,7 @@ static int connect_nsec3_nodes(zone_node_t *a, zone_node_t *b,
*/
static int create_nsec3_nodes(const zone_contents_t *zone, uint32_t ttl,
knot_zone_tree_t *nsec3_nodes,
knot_changeset_t *chgset)
changeset_t *chgset)
{
assert(zone);
assert(nsec3_nodes);
......@@ -583,7 +583,7 @@ static void reset_nodes(const zone_contents_t *zone)
* \brief Create new NSEC3 chain, add differences from current into a changeset.
*/
int knot_nsec3_create_chain(const zone_contents_t *zone, uint32_t ttl,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(zone);
assert(changeset);
......
......@@ -40,6 +40,6 @@
* \return KNOT_E*
*/
int knot_nsec3_create_chain(const zone_contents_t *zone, uint32_t ttl,
knot_changeset_t *changeset);
changeset_t *changeset);
#endif // _KNOT_DNSSEC_NSEC3_CHAIN_FIX_H_
......@@ -64,7 +64,7 @@ static int init_dnssec_structs(const zone_contents_t *zone,
}
static int zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
knot_changeset_t *out_ch, bool force,
changeset_t *out_ch, bool force,
knot_update_serial_t soa_up, uint32_t *refresh_at)
{
assert(zone);
......@@ -79,7 +79,7 @@ static int zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
uint32_t new_serial = zone_contents_next_serial(zone, zone_config->serial_policy);
dbg_dnssec_verb("Changeset empty before generating NSEC chain: %d\n",
knot_changeset_is_empty(out_ch));
changeset_is_empty(out_ch));
// Init needed structs
knot_zone_keys_t zone_keys = { '\0' };
......@@ -102,7 +102,7 @@ static int zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
return result;
}
dbg_dnssec_verb("Changeset empty after generating NSEC chain: %d\n",
knot_changeset_is_empty(out_ch));
changeset_is_empty(out_ch));
// add missing signatures
result = knot_zone_sign(zone, &zone_keys, &policy, out_ch,
......@@ -115,16 +115,16 @@ static int zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
return result;
}
dbg_dnssec_verb("Changeset emtpy after signing: %d\n",
knot_changeset_is_empty(out_ch));
changeset_is_empty(out_ch));
// Check if only SOA changed
if (knot_changeset_is_empty(out_ch) &&
if (changeset_is_empty(out_ch) &&
!knot_zone_sign_soa_expired(zone, &zone_keys, &policy)) {
log_zone_info("%s No signing performed, zone is valid.\n",
msgpref);
free(msgpref);
knot_free_zone_keys(&zone_keys);
assert(knot_changeset_is_empty(out_ch));
assert(changeset_is_empty(out_ch));
return KNOT_EOK;
}
......@@ -153,7 +153,7 @@ static int zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
}
int knot_dnssec_zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
knot_changeset_t *out_ch,
changeset_t *out_ch,
knot_update_serial_t soa_up, uint32_t *refresh_at)
{
if (zone == NULL || zone_config == NULL || out_ch == NULL) {
......@@ -164,7 +164,7 @@ int knot_dnssec_zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
}
int knot_dnssec_zone_sign_force(zone_contents_t *zone, const conf_zone_t *zone_config,
knot_changeset_t *out_ch, uint32_t *refresh_at)
changeset_t *out_ch, uint32_t *refresh_at)
{
if (zone == NULL || zone_config == NULL || out_ch == NULL) {
return KNOT_EINVAL;
......@@ -175,8 +175,8 @@ int knot_dnssec_zone_sign_force(zone_contents_t *zone, const conf_zone_t *zone_c
int knot_dnssec_sign_changeset(const zone_contents_t *zone,
conf_zone_t *zone_config,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
const changeset_t *in_ch,
changeset_t *out_ch,
uint32_t *refresh_at)
{
if (!refresh_at || zone == NULL || in_ch == NULL || out_ch == NULL) {
......
......@@ -44,7 +44,7 @@
* \return Error code, KNOT_EOK if successful.
*/
int knot_dnssec_zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
knot_changeset_t *out_ch,
changeset_t *out_ch,
knot_update_serial_t soa_up, uint32_t *refresh_at);
/*!
......@@ -59,7 +59,7 @@ int knot_dnssec_zone_sign(zone_contents_t *zone, const conf_zone_t *zone_config,
* \return Error code, KNOT_EOK if successful.
*/
int knot_dnssec_zone_sign_force(zone_contents_t *zone, const conf_zone_t *zone_config,
knot_changeset_t *out_ch,
changeset_t *out_ch,
uint32_t *refresh_at);
/*!
......@@ -76,8 +76,8 @@ int knot_dnssec_zone_sign_force(zone_contents_t *zone, const conf_zone_t *zone_c
*/
int knot_dnssec_sign_changeset(const zone_contents_t *zone,
conf_zone_t *zone_config,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
const changeset_t *in_ch,
changeset_t *out_ch,
uint32_t *refresh_at);
#endif // _KNOT_DNSSEC_ZONE_EVENTS_H_
......
......@@ -44,7 +44,7 @@
* \return KNOT_E*
*/
static int delete_nsec3_chain(const zone_contents_t *zone,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(zone);
assert(changeset);
......@@ -149,14 +149,14 @@ static int mark_nsec3(knot_rrset_t *rrset, void *data)
* For each NSEC3 RRSet in the changeset finds its node and marks it with the
* 'removed' flag.
*/
static int mark_removed_nsec3(knot_changeset_t *out_ch,
static int mark_removed_nsec3(changeset_t *out_ch,
const zone_contents_t *zone)
{
if (knot_zone_tree_is_empty(zone->nsec3_nodes)) {
return KNOT_EOK;
}
int ret = knot_changeset_apply(out_ch, KNOT_CHANGESET_REMOVE,
int ret = changeset_apply(out_ch, CHANGESET_REMOVE,
mark_nsec3, (void *)zone->nsec3_nodes);
return ret;
}
......@@ -246,7 +246,7 @@ knot_dname_t *knot_nsec3_hash_to_dname(const uint8_t *hash, size_t hash_size,
* \brief Create NSEC or NSEC3 chain in the zone.
*/
int knot_zone_create_nsec_chain(const zone_contents_t *zone,
knot_changeset_t *changeset,
changeset_t *changeset,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy)
{
......
......@@ -81,7 +81,7 @@ knot_dname_t *knot_create_nsec3_owner(const knot_dname_t *owner,
* \return Error code, KNOT_EOK if successful.
*/
int knot_zone_create_nsec_chain(const zone_contents_t *zone,
knot_changeset_t *changeset,
changeset_t *changeset,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy);
......
......@@ -212,7 +212,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
const knot_rrset_t *rrsigs,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset,
changeset_t *changeset,
uint32_t *expires_at)
{
assert(changeset);
......@@ -274,8 +274,8 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
}
if (to_remove != NULL && result == KNOT_EOK) {
result = knot_changeset_add_rrset(changeset, to_remove,
KNOT_CHANGESET_REMOVE);
result = changeset_add_rrset(changeset, to_remove,
CHANGESET_REMOVE);
}
if (to_remove != NULL && result != KNOT_EOK) {
......@@ -302,7 +302,7 @@ static int add_missing_rrsigs(const knot_rrset_t *covered,
const knot_rrset_t *rrsigs,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(!knot_rrset_empty(covered));
assert(zone_keys);
......@@ -337,8 +337,8 @@ static int add_missing_rrsigs(const knot_rrset_t *covered,
}
if (to_add != NULL && result == KNOT_EOK) {
result = knot_changeset_add_rrset(changeset, to_add,
KNOT_CHANGESET_ADD);
result = changeset_add_rrset(changeset, to_add,
CHANGESET_ADD);
}
if (to_add != NULL && result != KNOT_EOK) {
......@@ -358,7 +358,7 @@ static int add_missing_rrsigs(const knot_rrset_t *covered,
*/
static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type,
const knot_rrset_t *rrsigs,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(owner);
assert(changeset);
......@@ -376,8 +376,8 @@ static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type,
return KNOT_EOK;
}
ret = knot_changeset_add_rrset(changeset, synth_rrsig,
KNOT_CHANGESET_REMOVE);
ret = changeset_add_rrset(changeset, synth_rrsig,
CHANGESET_REMOVE);
if (ret != KNOT_EOK) {
knot_rrset_free(&synth_rrsig, NULL);
}
......@@ -399,7 +399,7 @@ static int force_resign_rrset(const knot_rrset_t *covered,
const knot_rrset_t *rrsigs,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(!knot_rrset_empty(covered));
......@@ -429,7 +429,7 @@ static int resign_rrset(const knot_rrset_t *covered,
const knot_rrset_t *rrsigs,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset,
changeset_t *changeset,
uint32_t *expires_at)
{
assert(!knot_rrset_empty(covered));
......@@ -453,7 +453,7 @@ static int resign_rrset(const knot_rrset_t *covered,
static int remove_standalone_rrsigs(const zone_node_t *node,
const knot_rrset_t *rrsigs,
knot_changeset_t *changeset)
changeset_t *changeset)
{
if (rrsigs == NULL) {
return KNOT_EOK;
......@@ -476,8 +476,8 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
knot_rrset_free(&to_remove, NULL);
return ret;
}
ret = knot_changeset_add_rrset(changeset,
to_remove, KNOT_CHANGESET_REMOVE);
ret = changeset_add_rrset(changeset,
to_remove, CHANGESET_REMOVE);
if (ret != KNOT_EOK) {
knot_rrset_free(&to_remove, NULL);
return ret;
......@@ -502,7 +502,7 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
static int sign_node_rrsets(const zone_node_t *node,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset,
changeset_t *changeset,
uint32_t *expires_at)
{
assert(node);
......@@ -548,7 +548,7 @@ static int sign_node_rrsets(const zone_node_t *node,
typedef struct node_sign_args {
const knot_zone_keys_t *zone_keys;
const knot_dnssec_policy_t *policy;
knot_changeset_t *changeset;
changeset_t *changeset;
uint32_t expires_at;
} node_sign_args_t;
......@@ -594,7 +594,7 @@ static int sign_node(zone_node_t **node, void *data)
static int zone_tree_sign(knot_zone_tree_t *tree,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset,
changeset_t *changeset,
uint32_t *expires_at)
{
assert(zone_keys);
......@@ -623,7 +623,7 @@ typedef struct {
const zone_contents_t *zone;
const knot_zone_keys_t *zone_keys;
const knot_dnssec_policy_t *policy;
knot_changeset_t *changeset;
changeset_t *changeset;
hattrie_t *signed_tree;
} changeset_signing_data_t;
......@@ -738,7 +738,7 @@ static int rrset_add_zone_key(knot_rrset_t *rrset,
static int remove_invalid_dnskeys(const knot_rrset_t *soa,
const knot_rrset_t *dnskeys,
const knot_zone_keys_t *zone_keys,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(soa->type == KNOT_RRTYPE_SOA);
assert(changeset);
......@@ -802,8 +802,8 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
done:
if (to_remove != NULL && result == KNOT_EOK) {
result = knot_changeset_add_rrset(changeset, to_remove,
KNOT_CHANGESET_REMOVE);
result = changeset_add_rrset(changeset, to_remove,
CHANGESET_REMOVE);
}
if (to_remove != NULL && result != KNOT_EOK) {
......@@ -840,7 +840,7 @@ static knot_rrset_t *create_dnskey_rrset_from_soa(const knot_rrset_t *soa)
static int add_missing_dnskeys(const knot_rrset_t *soa,
const knot_rrset_t *dnskeys,
const knot_zone_keys_t *zone_keys,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(soa);
assert(soa->type == KNOT_RRTYPE_SOA);
......@@ -883,8 +883,8 @@ static int add_missing_dnskeys(const knot_rrset_t *soa,
}
if (to_add != NULL && result == KNOT_EOK) {
result = knot_changeset_add_rrset(changeset, to_add,
KNOT_CHANGESET_ADD);
result = changeset_add_rrset(changeset, to_add,
CHANGESET_ADD);
}
if (to_add != NULL && result != KNOT_EOK) {
......@@ -910,7 +910,7 @@ static int update_dnskeys_rrsigs(const knot_rrset_t *dnskeys,
const knot_rrset_t *soa,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(zone_keys);
assert(changeset);
......@@ -988,7 +988,7 @@ fail:
static int update_dnskeys(const zone_contents_t *zone,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(zone);
assert(zone->apex);
......@@ -1003,7 +1003,7 @@ static int update_dnskeys(const zone_contents_t *zone,
}
int result;
size_t changes_before = knot_changeset_size(changeset);
size_t changes_before = changeset_size(changeset);
result = remove_invalid_dnskeys(&soa, &dnskeys, zone_keys, changeset);
if (result != KNOT_EOK) {
......@@ -1025,7 +1025,7 @@ static int update_dnskeys(const zone_contents_t *zone,
}
}
bool modified = (knot_changeset_size(changeset) != changes_before);
bool modified = (changeset_size(changeset) != changes_before);
bool signatures_exist = (!knot_rrset_empty(&dnskeys) &&
all_signatures_exist(&dnskeys, &dnskey_rrsig,
zone_keys, policy));
......@@ -1259,7 +1259,7 @@ static void knot_zone_clear_sorted_changes(hattrie_t *t)
int knot_zone_sign(const zone_contents_t *zone,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset,
changeset_t *changeset,
uint32_t *refresh_at)
{
if (!zone || !zone_keys || !policy || !changeset || !refresh_at) {
......@@ -1327,7 +1327,7 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
uint32_t new_serial,
knot_changeset_t *changeset)
changeset_t *changeset)
{
if (knot_rrset_empty(soa) || !zone_keys || !policy || !changeset) {
return KNOT_EINVAL;
......@@ -1404,8 +1404,8 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
* \brief Sign changeset created by DDNS or zone-diff.
*/
int knot_zone_sign_changeset(const zone_contents_t *zone,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
const changeset_t *in_ch,
changeset_t *out_ch,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy)
{
......@@ -1424,14 +1424,14 @@ int knot_zone_sign_changeset(const zone_contents_t *zone,
}
// Sign all RRs that are new in changeset
int ret = knot_changeset_apply((knot_changeset_t *)in_ch,
KNOT_CHANGESET_ADD,
int ret = changeset_apply((changeset_t *)in_ch,
CHANGESET_ADD,
sign_changeset_wrap, &args);
// Sign all RRs that are removed in changeset
if (ret == KNOT_EOK) {
ret = knot_changeset_apply((knot_changeset_t *)in_ch,
KNOT_CHANGESET_REMOVE,
ret = changeset_apply((changeset_t *)in_ch,
CHANGESET_REMOVE,
sign_changeset_wrap, &args);
}
......@@ -1446,7 +1446,7 @@ int knot_zone_sign_changeset(const zone_contents_t *zone,
*/
int knot_zone_sign_nsecs_in_changeset(const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset)
changeset_t *changeset)
{
assert(zone_keys);
assert(policy);
......@@ -1457,7 +1457,7 @@ int knot_zone_sign_nsecs_in_changeset(const knot_zone_keys_t *zone_keys,
.policy = policy,
.changeset = changeset };
return knot_changeset_apply(changeset, KNOT_CHANGESET_ADD,
return changeset_apply(changeset, CHANGESET_ADD,
add_rrsigs_for_nsec, &data);
}
......
......@@ -62,7 +62,7 @@ typedef struct signed_info {
int knot_zone_sign(const zone_contents_t *zone,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *out_ch, uint32_t *refresh_at);
changeset_t *out_ch, uint32_t *refresh_at);
/*!
* \brief Update and sign SOA and store performed changes in changeset.
......@@ -77,7 +77,7 @@ int knot_zone_sign(const zone_contents_t *zone,
int knot_zone_sign_update_soa(const knot_rrset_t *soa, const knot_rrset_t *rrsigs,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
uint32_t new_serial, knot_changeset_t *changeset);
uint32_t new_serial, changeset_t *changeset);
/*!
* \brief Check if zone SOA signatures are expired.
......@@ -105,8 +105,8 @@ bool knot_zone_sign_soa_expired(const zone_contents_t *zone,
* \return Error code, KNOT_EOK if successful.
*/
int knot_zone_sign_changeset(const zone_contents_t *zone,
const knot_changeset_t *in_ch,
knot_changeset_t *out_ch,
const changeset_t *in_ch,
changeset_t *out_ch,
const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy);
......@@ -121,7 +121,7 @@ int knot_zone_sign_changeset(const zone_contents_t *zone,
*/
int knot_zone_sign_nsecs_in_changeset(const knot_zone_keys_t *zone_keys,
const knot_dnssec_policy_t *policy,
knot_changeset_t *changeset);
changeset_t *changeset);
/*!
* \brief Checks whether RRSet in a node has to be signed. Will not return
......
......@@ -235,7 +235,7 @@ static void axfr_answer_cleanup(struct answer_data *data)
{
struct xfr_proc *proc = data->ext;
if (proc) {
zone_contents_deep_free(&proc->zone);
zone_contents_deep_free(&proc->contents);
mm_free(data->mm, proc);
data->ext = NULL;
}
......@@ -260,7 +260,7 @@ static int axfr_answer_init(struct answer_data *data)
}
memset(proc, 0, sizeof(struct xfr_proc));
proc->zone = new_contents;
proc->contents = new_contents;
gettimeofday(&proc->tstamp, NULL);
/* Set up cleanup callback. */
......@@ -284,23 +284,23 @@ static int axfr_answer_finalize(struct answer_data *data)
* marked authoritative / delegation point.
*/
struct xfr_proc *proc = data->ext;
int rc = zone_contents_adjust_full(proc->zone, NULL, NULL);
int rc = zone_contents_adjust_full(proc->contents, NULL, NULL);
if (rc != KNOT_EOK) {
return rc;
}
/* Write zone file. */
zone_t *zone = data->param->zone;
rc = zonefile_write(zone->conf->file, proc->zone, data->param->remote);
rc = zonefile_write(zone->conf->file, proc->contents, data->param->remote);
if (rc != KNOT_EOK) {
return rc;
}
/* Switch contents. */
zone_contents_t *old_contents = update_switch_contents(zone, proc->zone);
zone_contents_t *old_contents = update_switch_contents(zone, proc->contents);
AXFRIN_LOG(LOG_INFO, "Serial %u -> %u",
zone_contents_serial(old_contents),
zone_contents_serial(proc->zone));
zone_contents_serial(proc->contents));
AXFRIN_LOG(LOG_INFO, "Finished in %.02fs (%u messages, ~%.01fkB).",
time_diff(&proc->tstamp, &now) / 1000.0,
......@@ -308,7 +308,7 @@ static int axfr_answer_finalize(struct answer_data *data)
/* Do not free new contents with cleanup. */
zone_contents_deep_free(&old_contents);
proc->zone = NULL;
proc->contents = NULL;
return KNOT_EOK;
}
......@@ -322,7 +322,7 @@ static int process_axfr_packet(knot_pkt_t *pkt, struct xfr_proc *proc)
++proc->npkts;
// Init zone creator
zcreator_t zc = {.z = proc->zone, .master = false, .ret = KNOT_EOK };
zcreator_t zc = {.z = proc->contents, .master = false, .ret = KNOT_EOK };
const knot_pktsection_t *answer = knot_pkt_section(pkt, KNOT_ANSWER);
for (uint16_t i = 0; i < answer->count; ++i) {
......
......@@ -39,7 +39,7 @@ struct xfr_proc {
unsigned npkts; /* Packets processed. */
unsigned nbytes; /* Bytes processed. */
struct timeval tstamp; /* Start time. */
zone_contents_t *zone; /* Processed zone. */
zone_contents_t *contents; /* Processed zone. */
};
/*! \brief Generic transfer processing (reused for IXFR).
......
......@@ -11,22 +11,27 @@
/* ------------------------ IXFR-out processing ----------------------------- */
/*! \brief Current IXFR answer sections. */
enum {
SOA_REMOVE = 0,
REMOVE,
SOA_ADD,
ADD
/*! \brief IXFR-in processing states. */
enum ixfr_states {
IXFR_START = 0, /* IXFR-in starting, expecting final SOA. */
IXFR_SOA_DEL, /* Expecting starting SOA. */
IXFR_SOA_ADD, /* Expecting ending SOA. */
IXFR_DEL, /* Expecting RR to delete. */
IXFR_ADD, /* Expecting RR to add. */
IXFR_DONE /* Processing done, IXFR-in complete. */
};
/*! \brief Extended structure for IXFR-out processing. */
struct ixfrout_proc {
struct xfr_proc proc;
/*! \brief Extended structure for IXFR-in/IXFR-out processing. */
struct ixfr_proc {
struct xfr_proc proc; /* Generic transfer processing context. */
node_t *cur;
unsigned state;
knot_changesets_t *changesets;
int state; /* IXFR-in state. */
changesets_t *changesets; /* Processed changesets. */
zone_t *zone; /* Modified zone - for journal access. */
mm_ctx_t *mm; /* Memory context for RR allocations. */
struct query_data *qdata;
const knot_rrset_t *soa_from, *soa_to;
const knot_rrset_t *soa_from;
const knot_rrset_t *soa_to;
};
/* IXFR-out-specific logging (internal, expects 'qdata' variable set). */
......@@ -40,7 +45,7 @@ struct ixfrout_proc {
return ret; \
}
static int ixfr_put_rrlist(knot_pkt_t *pkt, struct ixfrout_proc *ixfr, list_t *list)
static int ixfr_put_rrlist(knot_pkt_t *pkt, struct ixfr_proc *ixfr, list_t *list)
{
assert(pkt);
assert(ixfr);
......@@ -76,44 +81,45 @@ static int ixfr_put_rrlist(knot_pkt_t *pkt, struct ixfrout_proc *ixfr, list_t *l
* with next empty answer and it must resume the processing exactly where
* it's left off.
*/
static int ixfr_process_changeset(knot_pkt_t *pkt, const void *item, struct xfr_proc *xfer)
static int ixfr_process_changeset(knot_pkt_t *pkt, const void *item,
struct xfr_proc *xfer)
{
int ret = KNOT_EOK;
struct ixfrout_proc *ixfr = (struct ixfrout_proc *)xfer;
knot_changeset_t *chgset = (knot_changeset_t *)item;
struct ixfr_proc *ixfr = (struct ixfr_proc *)xfer;
changeset_t *chgset = (changeset_t *)item;
/* Put former SOA. */
if (ixfr->state == SOA_REMOVE) {
if (ixfr->state == IXFR_SOA_DEL) {
IXFR_SAFE_PUT(pkt, chgset->soa_from);
dbg_ns("%s: put 'REMOVE' SOA\n", __func__);
ixfr->state = REMOVE;
ixfr->state = IXFR_DEL;
}
/* Put REMOVE RRSets. */
if (ixfr->state == REMOVE) {
if (ixfr->state == IXFR_DEL) {
ret = ixfr_put_rrlist(pkt, ixfr, &chgset->remove);
if (ret != KNOT_EOK) {
return ret;
}
dbg_ns("%s: put 'REMOVE' RRs\n", __func__);
ixfr->state = SOA_ADD;
ixfr->state = IXFR_SOA_ADD;
}
/* Put next SOA. */
if (ixfr->state == SOA_ADD) {
if (ixfr->state == IXFR_SOA_ADD) {
IXFR_SAFE_PUT(pkt, chgset->soa_to);
dbg_ns("%s: put 'ADD' SOA\n", __func__);
ixfr->state = ADD;
dbg_ns("%s: put 'IXFR_ADD' SOA\n", __func__);
ixfr->state = IXFR_ADD;
}
/* Put REMOVE RRSets. */
if (ixfr->state == ADD) {
if (ixfr->state == IXFR_ADD) {
ret = ixfr_put_rrlist(pkt, ixfr, &chgset->add);
if (ret != KNOT_EOK) {
return ret;
}
dbg_ns("%s: put 'ADD' RRs\n", __func__);
ixfr->state = SOA_REMOVE;
dbg_ns("%s: put 'IXFR_ADD' RRs\n", __func__);
ixfr->state = IXFR_SOA_DEL;
}
/* Finished change set. */
......@@ -125,7 +131,7 @@ static int ixfr_process_changeset(knot_pkt_t *pkt, const void *item, struct xfr_
#undef IXFR_SAFE_PUT
static int ixfr_load_chsets(knot_changesets_t **chgsets, const zone_t *zone,