Commit de3adda6 authored by Jan Kadlec's avatar Jan Kadlec

xfrin: xfr-in cleanup, doxygen.

- File xfr-in.c-> apply.c
- Removed obsolete API functions
- Doxygen and fuction reoraganization.
parent 6d2a7162
......@@ -155,8 +155,8 @@ src/knot/updates/changesets.c
src/knot/updates/changesets.h
src/knot/updates/ddns.c
src/knot/updates/ddns.h
src/knot/updates/xfr-in.c
src/knot/updates/xfr-in.h
src/knot/updates/apply.c
src/knot/updates/apply.h
src/knot/worker/pool.c
src/knot/worker/pool.h
src/knot/worker/queue.c
......
......@@ -271,8 +271,8 @@ libknotd_la_SOURCES = \
knot/updates/changesets.h \
knot/updates/ddns.c \
knot/updates/ddns.h \
knot/updates/xfr-in.c \
knot/updates/xfr-in.h \
knot/updates/apply.c \
knot/updates/apply.h \
knot/worker/pool.c \
knot/worker/pool.h \
knot/worker/queue.c \
......
......@@ -18,7 +18,7 @@
#include "knot/nameserver/internet.h"
#include "knot/nameserver/process_query.h"
#include "knot/nameserver/process_answer.h"
#include "knot/updates/xfr-in.h"
#include "knot/updates/apply.h"
#include "knot/zone/zonefile.h"
#include "common/debug.h"
#include "common/descriptor.h"
......@@ -297,7 +297,7 @@ static int axfr_answer_finalize(struct answer_data *data)
}
/* Switch contents. */
zone_contents_t *old_contents = xfrin_switch_zone(zone, proc->zone);
zone_contents_t *old_contents = update_switch_contents(zone, proc->zone);
AXFRIN_LOG(LOG_INFO, "Serial %u -> %u",
zone_contents_serial(old_contents),
zone_contents_serial(proc->zone));
......
......@@ -3,7 +3,7 @@
#include "knot/nameserver/internet.h"
#include "knot/nameserver/process_query.h"
#include "knot/nameserver/process_answer.h"
#include "knot/updates/xfr-in.h"
#include "knot/updates/apply.h"
#include "common/debug.h"
#include "common/descriptor.h"
#include "libknot/util/utils.h"
......@@ -292,6 +292,7 @@ enum ixfrin_states {
/*! \brief Extended structure for IXFR-in processing. */
struct ixfrin_proc {
struct xfr_proc *xfr_proc; /* Generic transfer processing context. */
int state; /* IXFR-in state. */
knot_changesets_t *changesets; /* Created changesets. */
zone_t *zone; /* Modified zone. */
......
#include "knot/nameserver/update.h"
#include "knot/nameserver/internet.h"
#include "knot/nameserver/process_query.h"
#include "knot/updates/xfr-in.h"
#include "knot/updates/apply.h"
#include "knot/dnssec/zone-sign.h"
#include "common/debug.h"
#include "knot/dnssec/zone-events.h"
......@@ -168,7 +168,7 @@ static int sign_update(zone_t *zone, const zone_contents_t *old_contents,
// Apply DNSSEC changeset
zone_contents_set_gen_old(new_contents);
ret = xfrin_apply_changesets_directly(new_contents, sec_chs);
ret = apply_changesets_directly(new_contents, sec_chs);
if (ret != KNOT_EOK) {
knot_changesets_free(&sec_chs, NULL);
return ret;
......@@ -218,7 +218,7 @@ static int process_authenticated(uint16_t *rcode, struct query_data *qdata)
zone_contents_t *new_contents = NULL;
const bool change_made = !knot_changeset_is_empty(ddns_ch);
if (change_made) {
ret = xfrin_apply_changesets(zone, ddns_chs, &new_contents);
ret = apply_changesets(zone, ddns_chs, &new_contents);
if (ret != KNOT_EOK) {
if (ret == KNOT_ETTL) {
*rcode = KNOT_RCODE_REFUSED;
......@@ -238,7 +238,7 @@ static int process_authenticated(uint16_t *rcode, struct query_data *qdata)
if (zone->conf->dnssec_enable) {
ret = sign_update(zone, zone->contents, new_contents, ddns_ch);
if (ret != KNOT_EOK) {
xfrin_rollback_update(ddns_chs, &new_contents);
update_rollback(ddns_chs, &new_contents);
knot_changesets_free(&ddns_chs, NULL);
*rcode = KNOT_RCODE_SERVFAIL;
return ret;
......@@ -248,19 +248,17 @@ static int process_authenticated(uint16_t *rcode, struct query_data *qdata)
// Write changes to journal if all went well. (DNSSEC merged)
ret = zone_change_store(zone, ddns_chs);
if (ret != KNOT_EOK) {
xfrin_rollback_update(ddns_chs, &new_contents);
update_rollback(ddns_chs, &new_contents);
knot_changesets_free(&ddns_chs, NULL);
*rcode = KNOT_RCODE_SERVFAIL;
return ret;
}
// Switch zone contents.
zone_contents_t *old_contents = xfrin_switch_zone(zone, new_contents);
// Wait for readers.
synchronize_rcu();
xfrin_zone_contents_free(&old_contents);
zone_contents_t *old_contents = update_switch_contents(zone, new_contents);
update_free_old_zone(&old_contents);
xfrin_cleanup_successful_update(ddns_chs);
update_cleanup(ddns_chs);
knot_changesets_free(&ddns_chs, NULL);
/* Trim extra heap. */
......
......@@ -32,7 +32,7 @@
#include "knot/server/net.h"
#include "knot/server/udp-handler.h"
#include "knot/server/tcp-handler.h"
#include "knot/updates/xfr-in.h"
#include "knot/updates/apply.h"
#include "knot/nameserver/axfr.h"
#include "knot/nameserver/ixfr.h"
#include "knot/nameserver/internet.h"
......@@ -590,7 +590,7 @@ static int xfr_task_finalize(knot_ns_xfr_t *rq)
ret = zones_save_zone(rq);
if (ret == KNOT_EOK) {
zone_contents_t *old_contents = NULL;
old_contents = xfrin_switch_zone(rq->zone, rq->new_contents);
old_contents = update_switch_contents(rq->zone, rq->new_contents);
zone_contents_deep_free(&old_contents);
} else {
log_zone_error("%s %s\n",
......
/*!
* \file xfr-in.h
* \file apply.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* \brief XFR client API.
* \brief Changesets application and update helpers.
*
* \addtogroup xfr
* @{
......@@ -24,31 +25,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _KNOT_XFR_IN_H_
#define _KNOT_XFR_IN_H_
#pragma once
#include <stdint.h>
#include <string.h>
#include "libknot/dname.h"
#include "knot/zone/zone.h"
#include "libknot/packet/pkt.h"
#include "knot/server/xfr-handler.h"
#include "knot/updates/changesets.h"
struct xfr_proc;
struct ixfrin_proc;
/*----------------------------------------------------------------------------*/
typedef enum xfrin_transfer_result {
XFRIN_RES_COMPLETE = 1,
XFRIN_RES_SOA_ONLY = 2,
XFRIN_RES_FALLBACK = 3
} xfrin_transfer_result_t;
/*----------------------------------------------------------------------------*/
/*!
* \brief Checks if a zone transfer is required by comparing the zone's SOA with
* the one received from master server.
......@@ -63,33 +48,17 @@ typedef enum xfrin_transfer_result {
int xfrin_transfer_needed(const zone_contents_t *zone,
knot_pkt_t *soa_response);
/*!
* \brief Processes one incoming packet of AXFR transfer by updating the given
* zone.
*
* \param pkt Incoming packet in wire format.
* \param size Size of the packet in bytes.
* \param zone Zone being built. If there is no such zone (i.e. this is the
* first packet, \a *zone may be set to NULL, in which case a new
* zone structure is created).
*
* \retval KNOT_EOK
*
* \todo Refactor!!!
*/
int xfrin_process_axfr_packet(knot_pkt_t *pkt, struct xfr_proc *proc);
/*!
* \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(zone_t *zone,
knot_changesets_t *chsets,
zone_contents_t **new_contents);
int apply_changesets(zone_t *zone, knot_changesets_t *chsets,
zone_contents_t **new_contents);
/*!
* \brief Applies changesets directly to the zone, without copying it.
......@@ -101,28 +70,40 @@ int xfrin_apply_changesets(zone_t *zone,
* \retval KNOT_EINVAL if given one of the arguments is NULL.
* \return Other error code if the application went wrong.
*/
int xfrin_apply_changesets_directly(zone_contents_t *contents,
knot_changesets_t *chsets);
int apply_changesets_directly(zone_contents_t *contents,
knot_changesets_t *chsets);
/*!
* \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.
* \brief Switches zone contents in the zone.
*
* \param zone Zone whose contents we want to switch.
* \param new_contents New zone contents.
*
* \return KNOT_E*
*/
int xfrin_finalize_updated_zone(zone_contents_t *contents_copy,
bool set_nsec3_names);
zone_contents_t *xfrin_switch_zone(zone_t *zone, zone_contents_t *new_contents);
zone_contents_t *update_switch_contents(zone_t *zone,
zone_contents_t *new_contents);
void xfrin_rollback_update(knot_changesets_t *chgs,
zone_contents_t **new_contents);
void xfrin_cleanup_successful_update(knot_changesets_t *chgs);
/*!
* \brief Cleanups successful update. (IXFR, DNSSEC, DDNS).
* \param chgs Changesets used to create the update.
*/
void update_cleanup(knot_changesets_t *chgs);
/* @note Exported because of update.c */
void xfrin_zone_contents_free(zone_contents_t **contents);
/*!
* \brief Rollbacks failed update (IXFR, DNSSEC, DDNS).
*
* \param chgs Changesets used to create the update.
* \param new_contents Created zone contents.
*/
void update_rollback(knot_changesets_t *chgs, zone_contents_t **new_contents);
#endif /* _KNOTXFR_IN_H_ */
/*!
* \brief Frees old zone contents - i.e. contents that were used to create the
* shallow copy, but are now obsolete.
* \note Exported because of update.c, zone.c.
* \param contents Contents to free.
*/
void update_free_old_zone(zone_contents_t **contents);
/*! @} */
......@@ -20,7 +20,7 @@
#include "knot/updates/ddns.h"
#include "knot/updates/changesets.h"
#include "knot/updates/xfr-in.h"
#include "knot/updates/apply.h"
#include "knot/zone/semantic-check.h"
#include "common/debug.h"
#include "libknot/packet/pkt.h"
......@@ -31,6 +31,8 @@
#include "common/descriptor.h"
#include "common/lists.h"
#warning merge with update.c
/* ----------------------------- prereq check ------------------------------- */
/*!< \brief Clears prereq RRSet list. */
......
......@@ -21,7 +21,7 @@
#include "knot/zone/contents.h"
#include "knot/zone/zonefile.h"
#include "knot/dnssec/zone-events.h"
#include "knot/updates/xfr-in.h"
#include "knot/updates/apply.h"
#include "libknot/rdata.h"
zone_contents_t *zone_load_contents(conf_zone_t *conf)
......@@ -109,7 +109,7 @@ int zone_load_journal(zone_contents_t *contents, conf_zone_t *conf)
}
/* Apply changesets. */
ret = xfrin_apply_changesets_directly(contents, chsets);
ret = apply_changesets_directly(contents, chsets);
log_zone_info("Zone '%s' serial %u -> %u: %s\n",
conf->name,
serial, zone_contents_serial(contents),
......
......@@ -26,7 +26,7 @@
#include "knot/zone/zone.h"
#include "knot/zone/zonefile.h"
#include "knot/zone/contents.h"
#include "knot/updates/xfr-in.h"
#include "knot/updates/apply.h"
#include "knot/nameserver/requestor.h"
#include "libknot/common.h"
#include "libknot/dname.h"
......@@ -159,7 +159,7 @@ int zone_change_commit(zone_contents_t *contents, knot_changesets_t *chset)
}
/* Apply DNSSEC changeset to the new zone. */
return xfrin_apply_changesets_directly(contents, chset);
return apply_changesets_directly(contents, chset);
}
int zone_change_store(zone_t *zone, knot_changesets_t *chset)
......@@ -195,7 +195,7 @@ int zone_change_apply_and_store(knot_changesets_t *chs,
/* Now, try to apply the changesets to the zone. */
zone_contents_t *new_contents;
ret = xfrin_apply_changesets(zone, chs, &new_contents);
ret = apply_changesets(zone, chs, &new_contents);
if (ret != KNOT_EOK) {
log_zone_error("%s Failed to apply changesets.\n", msgpref);
/* Free changesets, but not the data. */
......@@ -207,18 +207,18 @@ int zone_change_apply_and_store(knot_changesets_t *chs,
ret = zone_change_store(zone, chs);
if (ret != KNOT_EOK) {
log_zone_error("%s Failed to store changesets.\n", msgpref);
xfrin_rollback_update(chs, &new_contents);
update_rollback(chs, &new_contents);
/* Free changesets, but not the data. */
knot_changesets_free(&chs, rr_mm);
return ret; // propagate the error above
}
/* Switch zone contents. */
zone_contents_t *old_contents = xfrin_switch_zone(zone, new_contents);
xfrin_zone_contents_free(&old_contents);
zone_contents_t *old_contents = update_switch_contents(zone, new_contents);
update_free_old_zone(&old_contents);
/* Free changesets, but not the data. */
xfrin_cleanup_successful_update(chs);
update_cleanup(chs);
knot_changesets_free(&chs, rr_mm);
assert(ret == KNOT_EOK);
return KNOT_EOK;
......
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