Commit 966c3e28 authored by Marek Vavrusa's avatar Marek Vavrusa

Cleanup, universal query processing log messages.

parent 2f757367
......@@ -154,8 +154,9 @@ int acl_insert(acl_t *acl, const sockaddr_t *addr, knot_tsig_key_t *key)
return KNOT_ENOMEM;
}
memcpy(&match->addr, addr, sizeof(sockaddr_t));
sockaddr_copy(&match->addr, addr);
match->key = key;
add_tail(acl, &match->n);
return KNOT_EOK;
......
......@@ -38,11 +38,6 @@
#include "libknot/nameserver/ns_proc_query.h"
#include "libknot/dnssec/random.h"
/* Messages. */
#define NOTIFY_MSG "NOTIFY of '%s' from %s: "
#define NOTIFY_XMSG "received serial %u."
/*----------------------------------------------------------------------------*/
/* Non-API functions */
/*----------------------------------------------------------------------------*/
......@@ -125,6 +120,10 @@ static int notify_reschedule(knot_nameserver_t *ns,
return KNOT_EOK;
}
/* NOTIFY-specific logging (internal, expects 'qdata' variable set). */
#define NOTIFY_LOG(severity, msg...) \
QUERY_LOG(severity, qdata, "NOTIFY", msg)
int internet_notify(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *qdata)
{
if (pkt == NULL || ns == NULL || qdata == NULL) {
......@@ -162,17 +161,13 @@ int internet_notify(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *q
int ret = notify_reschedule(ns, qdata->zone, NULL /*! \todo API */);
/* Format resulting log message. */
char *qname_str = knot_dname_to_str(knot_pkt_qname(pkt));
char *addr_str = strdup("(noaddr)"); /* xfr_remote_str(from, NULL); */ /*! \todo API */
if (ret != KNOT_EOK) {
next_state = NS_PROC_NOOP; /* RFC1996: Ignore. */
log_server_warning(NOTIFY_MSG "%s\n", qname_str, addr_str, knot_strerror(ret));
NOTIFY_LOG(LOG_ERR, "%s", knot_strerror(ret));
} else {
next_state = NS_PROC_DONE;
log_server_info(NOTIFY_MSG NOTIFY_XMSG "\n", qname_str, addr_str, serial);
NOTIFY_LOG(LOG_ERR, "received serial %u.", serial);
}
free(qname_str);
free(addr_str);
return next_state;
}
......@@ -590,13 +590,6 @@ int knot_dname_cmp_wire(const knot_dname_t *d1, const knot_dname_t *d2,
bool knot_dname_is_equal(const knot_dname_t *d1, const knot_dname_t *d2)
{
if (d1 == d2) {
return true;
}
if (d1 == NULL || d1 == NULL) {
return false;
}
while(*d1 != '\0' || *d2 != '\0') {
if (knot_label_is_equal(d1, d2)) {
d1 = knot_wire_next_label(d1, NULL);
......
......@@ -147,7 +147,7 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb process_item, struct query_data
/* AXFR-specific logging (internal, expects 'qdata' variable set). */
#define AXFR_LOG(severity, msg...) \
XFER_LOG(severity, qdata, "Outgoing AXFR", msg)
ANSWER_LOG(severity, qdata, "Outgoing AXFR", msg)
int axfr_answer(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *qdata)
{
......
......@@ -33,17 +33,6 @@
struct query_data;
/*! \brief Transfers logging common base. */
#define XFER_LOG(severity, qdata, what, msg, ...) do { \
zonedata_t *zone_data = (zonedata_t *)knot_zone_data((qdata)->zone); \
sockaddr_t *addr = &(qdata)->param->query_source; \
char addr_str[SOCKADDR_STRLEN]; \
sockaddr_tostr(addr, addr_str, sizeof(addr_str)); \
log_msg(LOG_SERVER, severity, what " of '%s' to '%s:%d': " msg "\n", \
zone_data->conf->name, addr_str, sockaddr_portnum(addr), \
##__VA_ARGS__); \
} while (0)
/*! \brief Generic transfer processing state. */
struct xfr_proc {
list_t nodes; /* Items to process (ptrnode_t). */
......
......@@ -24,11 +24,12 @@ struct ixfr_proc {
unsigned state;
knot_changesets_t *changesets;
struct query_data *qdata;
const knot_rrset_t *soa_from, *soa_to;
};
/* IXFR-specific logging (internal, expects 'qdata' variable set). */
#define IXFR_LOG(severity, msg...) \
XFER_LOG(severity, qdata, "Outgoing IXFR", msg)
ANSWER_LOG(severity, qdata, "Outgoing IXFR", msg)
/*! \brief Helper macro for putting RRs into packet. */
#define IXFR_SAFE_PUT(pkt, rr) \
......@@ -114,7 +115,7 @@ static int ixfr_process_item(knot_pkt_t *pkt, const void *item, struct xfr_proc
}
/* Finished change set. */
struct query_data *qdata = ixfr->qdata;
struct query_data *qdata = ixfr->qdata; /*< Required for IXFR_LOG() */
IXFR_LOG(LOG_INFO, "Serial %u -> %u.", chgset->serial_from, chgset->serial_to);
return ret;
......@@ -211,6 +212,12 @@ static int ixfr_answer_init(struct query_data *qdata)
ptrlist_add(&xfer->proc.nodes, chs, mm);
dbg_ns("%s: preparing %u -> %u\n", __func__, chs->serial_from, chs->serial_to);
}
/* Keep first and last serial. */
chs = HEAD(chgsets->sets);
xfer->soa_from = chs->soa_from;
chs = TAIL(chgsets->sets);
xfer->soa_to = chs->soa_to;
return KNOT_EOK;
}
......@@ -252,17 +259,17 @@ int ixfr_answer(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *qdata
int ret = KNOT_EOK;
mm_ctx_t *mm = qdata->mm;
struct timeval now = {0};
const knot_pktsection_t *authority = knot_pkt_section(qdata->query, KNOT_AUTHORITY);
const knot_rrset_t *their_soa = authority->rr[0];
struct ixfr_proc *ixfr = (struct ixfr_proc*)qdata->ext;
/* Initialize on first call. */
if (qdata->ext == NULL) {
ret = ixfr_answer_init(qdata);
switch(ret) {
case KNOT_EOK: /* OK */
ixfr = (struct ixfr_proc*)qdata->ext;
IXFR_LOG(LOG_INFO, "Started (serial %u -> %u).",
knot_rdata_soa_serial(their_soa),
knot_zone_serial(qdata->zone->contents));
knot_rdata_soa_serial(ixfr->soa_from),
knot_rdata_soa_serial(ixfr->soa_to));
break;
case KNOT_EUPTODATE: /* Our zone is same age/older, send SOA. */
IXFR_LOG(LOG_INFO, "Zone is up-to-date.");
......@@ -282,7 +289,6 @@ int ixfr_answer(knot_pkt_t *pkt, knot_nameserver_t *ns, struct query_data *qdata
knot_pkt_tsig_set(pkt, qdata->sign.tsig_key);
/* Answer current packet (or continue). */
struct ixfr_proc *ixfr = (struct ixfr_proc*)qdata->ext;
ret = xfr_process_list(pkt, &ixfr_process_item, qdata);
switch(ret) {
case KNOT_ESPACE: /* Couldn't write more, send packet and continue. */
......
......@@ -35,6 +35,25 @@ extern const ns_proc_module_t _ns_proc_query;
#define NS_PROC_QUERY (&_ns_proc_query)
#define NS_PROC_QUERY_ID 1
/*! \brief Query processing logging common base. */
#define NS_PROC_LOG(severity, qdata, what, msg, ...) do { \
zonedata_t *zone_data = (zonedata_t *)knot_zone_data((qdata)->zone); \
sockaddr_t *addr = &(qdata)->param->query_source; \
char addr_str[SOCKADDR_STRLEN]; \
sockaddr_tostr(addr, addr_str, sizeof(addr_str)); \
log_msg(LOG_SERVER, severity, what msg "\n", \
zone_data->conf->name, addr_str, sockaddr_portnum(addr), \
##__VA_ARGS__); \
} while (0)
/*! \brief Query logging common base. */
#define QUERY_LOG(severity, qdata, what, msg...) \
NS_PROC_LOG(severity, qdata, what " of '%s' from '%s:%d': ", msg)
/*! \brief Answer logging common base. */
#define ANSWER_LOG(severity, qdata, what, msg...) \
NS_PROC_LOG(severity, qdata, what " of '%s' to '%s:%d': ", msg)
/* Query processing specific flags. */
enum ns_proc_query_flag {
NS_QUERY_NO_AXFR = NS_PROCFLAG << 1, /* Don't process AXFR */
......
......@@ -602,10 +602,12 @@ static int knot_pkt_merge_rr(knot_pkt_t *pkt, knot_rrset_t *rr, unsigned flags)
int rc = knot_rrset_merge_sort((knot_rrset_t *)pkt->rr[i],
rr, &merged, &deleted_rrs);
if (rc != KNOT_EOK) {
dbg_packet("%s: failed to merge RR %p (%d)\n", __func__, rr, rc);
return rc;
}
knot_rrset_deep_free(&rr, 1);
dbg_packet("%s: merged RR %p\n", __func__, rr);
knot_rrset_deep_free(&rr, 1);
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