Commit 9119f9a5 authored by Marek Vavruša's avatar Marek Vavruša

axfr/ixfr/notify: check RCODE, better log messages

parent a3dcda2a
......@@ -39,7 +39,7 @@ const error_table_t knot_error_msgs[] = {
{ KNOT_ERANGE, "Value is out of range." },
/* General errors. */
{ -10000 /*KNOT_ERROR*/, "General error." },
{ KNOT_ERROR, "Failed." },
{ KNOT_ENOTRUNNING, "Resource is not running." },
{ KNOT_EPARSEFAIL, "Parser failed." },
{ KNOT_EEXPIRED, "Resource is expired." },
......
......@@ -58,7 +58,7 @@ enum knot_error {
KNOT_ERANGE = err2code(ERANGE), /*!< Value is out of range. */
/* General errors. */
KNOT_ERROR = -10000, /*!< General error. */
KNOT_ERROR = -10000, /*!< Failed. */
KNOT_ENOTRUNNING, /*!< Resource is not running. */
KNOT_EPARSEFAIL, /*!< Parser fail. */
KNOT_EEXPIRED, /*!< Resource is expired. */
......
......@@ -289,9 +289,9 @@ static int axfr_answer_init(struct answer_data *data)
/* AXFR-specific logging (internal, expects 'data' variable set). */
#define AXFRIN_LOG(severity, msg...) \
ANSWER_LOG(severity, data, "Incoming AXFR", msg)
ANSWER_LOG(severity, adata, "Incoming AXFR", msg)
static int axfr_answer_finalize(struct answer_data *data)
static int axfr_answer_finalize(struct answer_data *adata)
{
struct timeval now;
gettimeofday(&now, NULL);
......@@ -300,7 +300,7 @@ static int axfr_answer_finalize(struct answer_data *data)
* Adjust zone so that node count is set properly and nodes are
* marked authoritative / delegation point.
*/
struct xfr_proc *proc = data->ext;
struct xfr_proc *proc = adata->ext;
int rc = zone_contents_adjust_full(proc->contents, NULL, NULL);
if (rc != KNOT_EOK) {
return rc;
......@@ -360,45 +360,51 @@ static int axfr_answer_packet(knot_pkt_t *pkt, struct xfr_proc *proc)
return NS_PROC_MORE;
}
int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *data)
int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata)
{
if (pkt == NULL || data == NULL) {
if (pkt == NULL || adata == NULL) {
return NS_PROC_FAIL;
}
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
knot_lookup_table_t *lut = knot_lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
AXFRIN_LOG(LOG_ERR, "Server responded with %s.", lut->name);
}
return NS_PROC_FAIL;
}
/* Initialize processing with first packet. */
if (data->ext == NULL) {
NS_NEED_TSIG_SIGNED(&data->param->tsig_ctx, 0);
if (!zone_transfer_needed(data->param->zone, pkt)) {
if (adata->ext == NULL) {
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
if (!zone_transfer_needed(adata->param->zone, pkt)) {
AXFRIN_LOG(LOG_INFO, "Zone is up-to-date.");
return NS_PROC_DONE;
}
AXFRIN_LOG(LOG_INFO, "Starting.");
int ret = axfr_answer_init(data);
int ret = axfr_answer_init(adata);
if (ret != KNOT_EOK) {
AXFRIN_LOG(LOG_ERR, "Failed.\n");
AXFRIN_LOG(LOG_ERR, "%s", knot_strerror(ret));
return NS_PROC_FAIL;
}
} else {
NS_NEED_TSIG_SIGNED(&data->param->tsig_ctx, 100);
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 100);
}
/* Process answer packet. */
int ret = axfr_answer_packet(pkt, (struct xfr_proc *)data->ext);
int ret = axfr_answer_packet(pkt, (struct xfr_proc *)adata->ext);
if (ret == NS_PROC_DONE) {
NS_NEED_TSIG_SIGNED(&data->param->tsig_ctx, 0);
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
/* This was the last packet, finalize zone and publish it. */
int fret = axfr_answer_finalize(data);
int fret = axfr_answer_finalize(adata);
if (fret != KNOT_EOK) {
ret = NS_PROC_FAIL;
}
}
if (ret == NS_PROC_FAIL) {
AXFRIN_LOG(LOG_ERR, "Failed.\n");
}
return ret;
}
......
......@@ -59,12 +59,10 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb put, struct query_data *qdata);
int axfr_query_process(knot_pkt_t *pkt, struct query_data *qdata);
/*!
* \brief Processes an AXFR respons message.
* \brief Processes an AXFR response message.
*
* \param pkt Processed packet.
* \param xfr Persistent transfer-specific data.
* \return NS_PROC_* processing states
*/
int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *data);
int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata);
/*! @} */
......@@ -628,6 +628,21 @@ int ixfr_query(knot_pkt_t *pkt, struct query_data *qdata)
int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
{
if (pkt == NULL || adata == NULL) {
return NS_PROC_FAIL;
}
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
knot_lookup_table_t *lut = knot_lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
IXFRIN_LOG(LOG_ERR, "Server responded with %s.", lut->name);
}
return NS_PROC_FAIL;
}
/* Initialize processing with first packet. */
if (adata->ext == NULL) {
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
if (!zone_transfer_needed(adata->param->zone, pkt)) {
......@@ -639,7 +654,7 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
// First packet with IXFR, init context
int ret = ixfrin_answer_init(adata);
if (ret != KNOT_EOK) {
IXFRIN_LOG(LOG_ERR, "Failed - %s", knot_strerror(ret));
IXFRIN_LOG(LOG_ERR, "%s", knot_strerror(ret));
return NS_PROC_FAIL;
}
} else {
......@@ -655,10 +670,6 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
}
}
if (ret == NS_PROC_FAIL) {
IXFRIN_LOG(LOG_ERR, "Failed - %s", knot_strerror(ret));
}
return ret;
}
......
......@@ -41,7 +41,7 @@ struct answer_data;
int ixfr_query(knot_pkt_t *pkt, struct query_data *qdata);
/*!
* \brief IXFR query response processing module.
* \brief IXFR response processing module.
*
* \retval MORE if more data are required.
* \retval FAIL if it encountered an error, retry over AXFR will be done.
......
......@@ -43,7 +43,7 @@
/*----------------------------------------------------------------------------*/
/* NOTIFY-specific logging (internal, expects 'qdata' variable set). */
#define NOTIFY_LOG(severity, msg...) \
#define NOTIFY_QLOG(severity, msg...) \
QUERY_LOG(severity, qdata, "NOTIFY", msg)
int notify_query(knot_pkt_t *pkt, struct query_data *qdata)
......@@ -70,23 +70,43 @@ int notify_query(knot_pkt_t *pkt, struct query_data *qdata)
const knot_rrset_t *soa = &answer->rr[0];
if (soa->type == KNOT_RRTYPE_SOA) {
serial = knot_soa_serial(&soa->rrs);
dbg_ns("%s: received serial %u\n", __func__, serial);
NOTIFY_QLOG(LOG_INFO, "received serial %u.", serial);
} else { /* Ignore */
dbg_ns("%s: NOTIFY answer != SOA_RR\n", __func__);
NOTIFY_QLOG(LOG_INFO, "received, doesn't have SOA.");
}
}
/* Incoming NOTIFY expires REFRESH timer and renews EXPIRE timer. */
zone_events_schedule(zone, ZONE_EVENT_REFRESH, ZONE_EVENT_NOW);
/* Format resulting log message. */
NOTIFY_LOG(LOG_INFO, "received serial %u.", serial);
return NS_PROC_DONE;
}
int notify_process_answer(knot_pkt_t *pkt, struct answer_data *data)
#undef NOTIFY_QLOG
/* NOTIFY-specific logging (internal, expects 'adata' variable set). */
#define NOTIFY_RLOG(severity, msg...) \
ANSWER_LOG(severity, adata, "NOTIFY", msg)
int notify_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
{
NS_NEED_TSIG_SIGNED(&data->param->tsig_ctx, 0);
if (pkt == NULL || adata == NULL) {
return NS_PROC_FAIL;
}
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
knot_lookup_table_t *lut = knot_lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
NOTIFY_RLOG(LOG_ERR, "Server responded with %s.", lut->name);
}
return NS_PROC_FAIL;
}
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
return NS_PROC_DONE; /* No processing. */
}
#undef NOTIFY_RLOG
......@@ -229,7 +229,7 @@ static int exec_request(struct request *last, struct timeval *timeout)
/* Expect complete request. */
if (last->state != NS_PROC_DONE) {
return KNOT_EMALF;
return KNOT_ERROR;
}
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