Commit 88b533b9 authored by Jan Kadlec's avatar Jan Kadlec

zone-events: IXFR-in logging improved.

parent 335bdb7c
......@@ -336,16 +336,15 @@ static int ixfrin_finalize(struct answer_data *adata)
#warning if we need to check serials, here's the place
assert(ixfr->state == IXFR_DONE);
int ret = zone_change_apply_and_store(ixfr->changesets,
int ret = zone_change_apply_and_store(&ixfr->changesets,
ixfr->zone, "IXFR", adata->mm);
if (ret != KNOT_EOK) {
IXFRIN_LOG(LOG_ERR, "Failed to apply changes to zone - %s",
knot_strerror(ret));
free(ixfr);
ixfrin_cleanup(adata);
return ret;
}
ixfr->changesets = NULL; // Free'd by apply_and_store()
ixfrin_cleanup(adata);
struct timeval now = {0};
......@@ -449,7 +448,8 @@ static int solve_add(const knot_rrset_t *rr, changeset_t *change, mm_ctx_t *mm)
static int ixfrin_next_state(struct ixfr_proc *proc, const knot_rrset_t *rr)
{
const bool soa = rr->type == KNOT_RRTYPE_SOA;
if (soa && proc->state != IXFR_START) {
if (soa &&
(proc->state == IXFR_SOA_ADD || proc->state == IXFR_ADD)) {
// Check end of transfer.
if (knot_rrset_equal(rr, proc->changesets->first_soa,
KNOT_RRSET_COMPARE_WHOLE)) {
......@@ -537,9 +537,15 @@ static bool out_of_zone(const knot_rrset_t *rr, struct ixfr_proc *proc)
static int xfrin_process_ixfr_packet(knot_pkt_t *pkt, struct answer_data *adata)
{
struct ixfr_proc *ixfr = (struct ixfr_proc *)adata->ext;
// Update counters.
ixfr->proc.npkts += 1;
ixfr->proc.nbytes += pkt->size;
// Process RRs in the message.
const knot_pktsection_t *answer = knot_pkt_section(pkt, KNOT_ANSWER);
for (uint16_t i = 0; i < answer->count; ++i) {
if (journal_limit_exceeded(ixfr)) {
IXFRIN_LOG(LOG_WARNING, "Journal is full.");
return NS_PROC_FAIL;
}
......@@ -550,6 +556,7 @@ static int xfrin_process_ixfr_packet(knot_pkt_t *pkt, struct answer_data *adata)
int ret = ixfrin_step(rr, ixfr);
if (ret != KNOT_EOK) {
IXFRIN_LOG(LOG_ERR, "Failed - %s", knot_strerror(ret));
return NS_PROC_FAIL;
}
......@@ -561,10 +568,6 @@ static int xfrin_process_ixfr_packet(knot_pkt_t *pkt, struct answer_data *adata)
#warning TODO TSIG
// Update counters.
ixfr->proc.npkts += 1;
ixfr->proc.nbytes += pkt->size;
return NS_PROC_MORE;
}
......@@ -655,6 +658,7 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
}
if (ret == NS_PROC_FAIL) {
ixfrin_cleanup(adata);
IXFRIN_LOG(LOG_ERR, "Failed.");
}
......
......@@ -278,6 +278,7 @@ int server_init(server_t *server)
}
/* Create zone events threads. */
#warning TODO: config option
server->workers = worker_pool_create(4); //! \todo config option
if (server->workers == NULL) {
dt_delete(&server->iosched);
......
......@@ -600,7 +600,7 @@ static int xfr_task_finalize(knot_ns_xfr_t *rq)
}
} else if (rq->type == XFR_TYPE_IIN) {
changesets_t *chs = (changesets_t *)rq->data;
ret = zone_change_apply_and_store(chs, rq->zone,
ret = zone_change_apply_and_store(&chs, rq->zone,
&rq->new_contents,
rq->msg);
rq->data = NULL; /* Freed or applied in prev function. */
......
......@@ -25,6 +25,7 @@
#include "knot/zone/zone.h"
#include "libknot/common.h"
#include "knot/updates/changesets.h"
#include "knot/zone/zonefile.h"
#include "common/lists.h"
#include "common/descriptor.h"
#include "libknot/util/utils.h"
......
......@@ -444,8 +444,7 @@ static int event_dnssec(zone_t *zone)
}
if (!changesets_empty(chs)) {
ret = zone_change_apply_and_store(chs, zone, "DNSSEC", NULL);
chs = NULL; // freed by zone_change_apply_and_store()
ret = zone_change_apply_and_store(&chs, zone, "DNSSEC", NULL);
if (ret != KNOT_EOK) {
log_zone_error("%s Could not sign zone (%s).\n",
msgpref, knot_strerror(ret));
......
......@@ -186,7 +186,7 @@ int zone_change_store(zone_t *zone, changesets_t *chset)
}
/*! \note @mvavrusa Moved from zones.c, this needs a common API. */
int zone_change_apply_and_store(changesets_t *chs,
int zone_change_apply_and_store(changesets_t **chs,
zone_t *zone,
const char *msgpref,
mm_ctx_t *rr_mm)
......@@ -195,21 +195,21 @@ int zone_change_apply_and_store(changesets_t *chs,
/* Now, try to apply the changesets to the zone. */
zone_contents_t *new_contents;
ret = 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. */
changesets_free(&chs, rr_mm);
changesets_free(chs, rr_mm);
return ret; // propagate the error above
}
/* Write changes to journal if all went well. */
ret = zone_change_store(zone, chs);
ret = zone_change_store(zone, *chs);
if (ret != KNOT_EOK) {
log_zone_error("%s Failed to store changesets.\n", msgpref);
update_rollback(chs, &new_contents);
update_rollback(*chs, &new_contents);
/* Free changesets, but not the data. */
changesets_free(&chs, rr_mm);
changesets_free(chs, rr_mm);
return ret; // propagate the error above
}
......@@ -218,8 +218,8 @@ int zone_change_apply_and_store(changesets_t *chs,
update_free_old_zone(&old_contents);
/* Free changesets, but not the data. */
update_cleanup(chs);
changesets_free(&chs, rr_mm);
update_cleanup(*chs);
changesets_free(chs, rr_mm);
assert(ret == KNOT_EOK);
return KNOT_EOK;
}
......
......@@ -116,7 +116,7 @@ changeset_t *zone_change_prepare(changesets_t *chset);
int zone_change_commit(zone_contents_t *contents, changesets_t *chset);
int zone_change_store(zone_t *zone, changesets_t *chset);
/*! \note @mvavrusa Moved from zones.c, this needs a common API. */
int zone_change_apply_and_store(changesets_t *chs,
int zone_change_apply_and_store(changesets_t **chs,
zone_t *zone,
const char *msgpref,
mm_ctx_t *rr_mm);
......
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