Commit 00145bbc authored by Jan Kadlec's avatar Jan Kadlec

zone-events: added doxygen for IXFR processing + cleanup

parent 380672f3
......@@ -37,12 +37,12 @@ struct xfr_proc;
/*! \brief IXFR-in processing states. */
enum ixfrin_states {
IXFR_START = 0,
IXFR_SOA_FROM = 1,
IXFR_SOA_TO = 2,
IXFR_DEL = 3,
IXFR_ADD = 4,
IXFR_DONE = 5
IXFR_START = 0, /* IXFR-in starting, expecting final SOA. */
IXFR_SOA_FROM = 1, /* Expecting starting SOA. */
IXFR_SOA_TO = 2, /* Expecting ending SOA. */
IXFR_DEL = 3, /* Expecting RR to delete. */
IXFR_ADD = 4, /* Expecting RR to add. */
IXFR_DONE = 5 /* Processing done, IXFR-in complete. */
};
/*! \brief Extended structure for IXFR-in processing. */
......
......@@ -254,6 +254,9 @@ int xfrin_process_axfr_packet(knot_pkt_t *pkt, struct xfr_proc *proc)
/*----------------------------------------------------------------------------*/
/* ------------------------- IXFR-in processing ----------------------------- */
/*! \brief Stores starting SOA into changesets structure. */
static int solve_start(const knot_rrset_t *rr, knot_changesets_t *changesets, mm_ctx_t *mm)
{
assert(changesets->first_soa == NULL);
......@@ -270,6 +273,10 @@ static int solve_start(const knot_rrset_t *rr, knot_changesets_t *changesets, mm
return NS_PROC_MORE;
}
/*!
* \brief Decides what to do with a starting SOA - either ends the processing or
* creates a new changeset and stores the SOA into it.
*/
static int solve_soa_from(const knot_rrset_t *rr, knot_changesets_t *changesets,
int *state, mm_ctx_t *mm)
{
......@@ -299,6 +306,7 @@ static int solve_soa_from(const knot_rrset_t *rr, knot_changesets_t *changesets,
return NS_PROC_MORE;
}
/*! \brief Stores ending SOA into changeset. */
static int solve_soa_to(const knot_rrset_t *rr, knot_changeset_t *change, mm_ctx_t *mm)
{
if (rr->type != KNOT_RRTYPE_SOA) {
......@@ -314,8 +322,10 @@ static int solve_soa_to(const knot_rrset_t *rr, knot_changeset_t *change, mm_ctx
return NS_PROC_MORE;
}
/*! \brief Adds single RR into given section of changeset. */
static int add_part(const knot_rrset_t *rr, knot_changeset_t *change, int part, mm_ctx_t *mm)
{
assert(rr->type != KNOT_RRTYPE_SOA);
knot_rrset_t *copy = knot_rrset_copy(rr, mm);
if (copy) {
int ret = knot_changeset_add_rrset(change, copy, part);
......@@ -329,58 +339,75 @@ static int add_part(const knot_rrset_t *rr, knot_changeset_t *change, int part,
}
}
/*! \brief Adds single RR into REMOVE section of changeset. */
static int solve_del(const knot_rrset_t *rr, knot_changeset_t *change, mm_ctx_t *mm)
{
return add_part(rr, change, KNOT_CHANGESET_REMOVE, mm);
}
/*! \brief Adds single RR into ADD section of changeset. */
static int solve_add(const knot_rrset_t *rr, knot_changeset_t *change, mm_ctx_t *mm)
{
return add_part(rr, change, KNOT_CHANGESET_ADD, mm);
}
/*!
* \brief Processes single RR according to current IXFR-in state. The states
* correspond with IXFR-in message structure, in the order they are
* mentioned in the code.
* \param rr RR to process.
* \param changesets Output changesets.
* \param state Current IXFR-in state.
* \param next Output parameter - set to true if next RR should be fetched.
* \param mm Memory context used to create RR copies.
* \return NS_PROC_MORE, NS_PROC_DONE, NS_PROC_FAIL.
*/
static int ixfrin_step(const knot_rrset_t *rr, knot_changesets_t *changesets,
int *state, bool *next, mm_ctx_t *mm)
{
switch (*state) {
case IXFR_START:
case IXFR_START:
*state = IXFR_SOA_FROM;
*next = true;
return solve_start(rr, changesets, mm);
case IXFR_SOA_FROM:
*state = IXFR_DEL;
*next = true;
return solve_soa_from(rr, changesets, state, mm);
case IXFR_DEL:
if (rr->type == KNOT_RRTYPE_SOA) {
// Encountered SOA, do not consume the RR.
*state = IXFR_SOA_TO;
*next = false;
return NS_PROC_MORE;
}
*next = true;
return solve_del(rr, knot_changesets_get_last(changesets), mm);
case IXFR_SOA_TO:
*state = IXFR_ADD;
*next = true;
return solve_soa_to(rr, knot_changesets_get_last(changesets), mm);
case IXFR_ADD:
if (rr->type == KNOT_RRTYPE_SOA) {
// Encountered SOA, do not consume the RR.
*state = IXFR_SOA_FROM;
*next = true;
return solve_start(rr, changesets, mm);
case IXFR_SOA_FROM:
*state = IXFR_DEL;
*next = true;
return solve_soa_from(rr, changesets, state, mm);
case IXFR_DEL:
if (rr->type == KNOT_RRTYPE_SOA) {
*state = IXFR_SOA_TO;
*next = false;
return NS_PROC_MORE;
}
*next = true;
return solve_del(rr, knot_changesets_get_last(changesets), mm);
case IXFR_SOA_TO:
*state = IXFR_ADD;
*next = true;
return solve_soa_to(rr, knot_changesets_get_last(changesets), mm);
case IXFR_ADD:
if (rr->type == KNOT_RRTYPE_SOA) {
*state = IXFR_SOA_FROM;
*next = false;
return NS_PROC_MORE;
}
*next = true;
return solve_add(rr, knot_changesets_get_last(changesets), mm);
default:
assert(0);
*next = false;
return NS_PROC_MORE;
}
*next = true;
return solve_add(rr, knot_changesets_get_last(changesets), mm);
default:
return NS_PROC_FAIL;
}
}
/*! \brief Checks whether journal node limit has not been exceeded. */
static bool journal_limit_exceeded(struct ixfrin_proc *proc)
{
return proc->changesets->count > JOURNAL_NCOUNT;
}
/*! \brief Checks whether RR belongs into zone. */
static bool out_of_zone(const knot_rrset_t *rr, struct ixfrin_proc *proc)
{
return !knot_dname_is_sub(rr->owner, proc->zone->name) &&
......@@ -390,18 +417,20 @@ static bool out_of_zone(const knot_rrset_t *rr, struct ixfrin_proc *proc)
int xfrin_process_ixfr_packet(knot_pkt_t *pkt, struct ixfrin_proc *proc)
{
uint16_t rr_id = 0;
const knot_rrset_t *rr = NULL;
knot_changesets_t *changesets = proc->changesets;
const knot_pktsection_t *answer = knot_pkt_section(pkt, KNOT_ANSWER);
const knot_rrset_t *rr = NULL;
xfrin_take_rr(answer, &rr, &rr_id);
knot_changesets_t *changesets = proc->changesets;
int ret = NS_PROC_NOOP;
while (rr) {
if (journal_limit_exceeded(proc)) {
// Will revert to AXFR.
assert(proc->state != IXFR_DONE);
return NS_PROC_DONE;
}
if (out_of_zone(rr, proc)) {
xfrin_take_rr(answer, &rr, &rr_id);
continue;
}
......@@ -494,7 +523,6 @@ static void xfrin_cleanup_failed_update(zone_contents_t **new_contents)
// destroy the shallow copy of zone
xfrin_zone_contents_free(new_contents);
}
}
/*----------------------------------------------------------------------------*/
......@@ -877,7 +905,7 @@ static int xfrin_remove_empty_nodes(zone_contents_t *z)
/*----------------------------------------------------------------------------*/
int xfrin_prepare_zone_copy(zone_contents_t *old_contents, zone_contents_t **new_contents)
static int xfrin_prepare_zone_copy(zone_contents_t *old_contents, zone_contents_t **new_contents)
{
if (old_contents == NULL || new_contents == NULL) {
return KNOT_EINVAL;
......@@ -939,10 +967,6 @@ int xfrin_finalize_updated_zone(zone_contents_t *contents_copy,
* - PROFIT
*/
/*
* Select and remove empty nodes from zone trees. Do not free them right
* away as they may be referenced by some domain names.
*/
int ret = xfrin_remove_empty_nodes(contents_copy);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to remove empty nodes: %s\n",
......
......@@ -79,27 +79,13 @@ int xfrin_transfer_needed(const zone_contents_t *zone,
*/
int xfrin_process_axfr_packet(knot_pkt_t *pkt, struct xfr_proc *proc);
/*!
* \brief Destroys the whole changesets structure.
*
* Frees all RRSets present in the changesets and all their data. Also frees
* the changesets structure and sets the parameter to NULL.
*
* \param changesets Changesets to destroy.
*/
void xfrin_free_changesets(knot_changesets_t **changesets);
/*!
* \brief Parses IXFR reply packet and fills in the changesets structure.
*
* \param pkt Packet containing the IXFR reply in wire format.
* \param size Size of the packet in bytes.
* \param changesets Changesets to be filled in.
* \param pkt Packet containing the IXFR reply in wire format.
* \param proc Processing context.
*
* \retval KNOT_EOK
* \retval KNOT_EINVAL
* \retval KNOT_EMALF
* \retval KNOT_ENOMEM
* \return NS_PROC_MORE, NS_PROC_DONE, NS_PROC_FAIL
*/
int xfrin_process_ixfr_packet(knot_pkt_t *pkt, struct ixfrin_proc *proc);
......@@ -128,9 +114,6 @@ int xfrin_apply_changesets(zone_t *zone,
int xfrin_apply_changesets_directly(zone_contents_t *contents,
knot_changesets_t *chsets);
int xfrin_prepare_zone_copy(zone_contents_t *old_contents,
zone_contents_t **new_contents);
/*!
* \brief Sets pointers and NSEC3 nodes after signing/DDNS.
* \param contents_copy Contents to be updated.
......@@ -145,15 +128,6 @@ zone_contents_t *xfrin_switch_zone(zone_t *zone, zone_contents_t *new_contents);
void xfrin_rollback_update(knot_changesets_t *chgs,
zone_contents_t **new_contents);
int xfrin_copy_rrset(zone_node_t *node, uint16_t type,
knot_rrset_t **rrset);
int xfrin_copy_old_rrset(knot_rrset_t *old, knot_rrset_t **copy);
int xfrin_replace_rrset_in_node(zone_node_t *node,
knot_rrset_t *rrset_new,
zone_contents_t *contents);
void xfrin_cleanup_successful_update(knot_changesets_t *chgs);
/* @note Exported because of update.c */
......
......@@ -70,12 +70,6 @@ typedef struct zone_contents_t {
uint8_t flags;
} zone_contents_t;
/*!< \brief Helper linked list list for CNAME loop checking */
typedef struct cname_chain {
const zone_node_t *node;
struct cname_chain *next;
} cname_chain_t;
/*!
* \brief Signature of callback for zone contents apply functions.
*/
......
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