Commit 39c41e94 authored by Daniel Salzman's avatar Daniel Salzman

log: some extensions and cleanup

parent 7f7d4224
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -112,9 +112,10 @@ __attribute__((format(printf, 3, 4)));
*
* \see log_fmt
*
* \param zone Zone name in wire format.
* \param priority Message priority.
* \param src Message source (LOG_SOURCE_SERVER...LOG_SOURCE_ZONE).
* \param zone Zone name in wire format.
* \param param Optional key-value parameter for structured logging.
* \param fmt Content of the logged message.
*/
void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone,
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -96,7 +96,7 @@ static int ds_query_consume(knot_layer_t *layer, knot_pkt_t *pkt)
uint16_t rcode = knot_pkt_ext_rcode(pkt);
if (rcode != KNOT_RCODE_NOERROR) {
ns_log((rcode == KNOT_RCODE_NXDOMAIN ? LOG_NOTICE : LOG_WARNING),
data->zone_name, LOG_OPERATION_PARENT,
data->zone_name, LOG_OPERATION_DS_CHECK,
LOG_DIRECTION_OUT, data->remote, "failed (%s)", knot_pkt_ext_rcode_name(pkt));
return KNOT_STATE_FAIL;
}
......@@ -124,7 +124,7 @@ static int ds_query_consume(knot_layer_t *layer, knot_pkt_t *pkt)
}
}
ns_log(LOG_INFO, data->zone_name, LOG_OPERATION_PARENT,
ns_log(LOG_INFO, data->zone_name, LOG_OPERATION_DS_CHECK,
LOG_DIRECTION_OUT, data->remote, "KSK submission attempt: %s",
(match ? "positive" : "negative"));
......@@ -191,7 +191,7 @@ static int try_ds(const knot_dname_t *zone_name, const conf_remote_t *parent, zo
}
if (ret != KNOT_EOK && !data.result_logged) {
ns_log(LOG_WARNING, zone_name, LOG_OPERATION_PARENT,
ns_log(LOG_WARNING, zone_name, LOG_OPERATION_DS_CHECK,
LOG_DIRECTION_OUT, data.remote, "failed (%s)", knot_strerror(ret));
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -20,21 +20,23 @@
#include "knot/common/log.h"
#include "libknot/dname.h"
enum log_operation {
typedef enum {
LOG_OPERATION_AXFR,
LOG_OPERATION_IXFR,
LOG_OPERATION_NOTIFY,
LOG_OPERATION_REFRESH,
LOG_OPERATION_UPDATE,
LOG_OPERATION_PARENT,
};
LOG_OPERATION_DS_CHECK,
LOG_OPERATION_DS_PUSH,
} log_operation_t;
enum log_direction {
typedef enum {
LOG_DIRECTION_NONE,
LOG_DIRECTION_IN,
LOG_DIRECTION_OUT,
};
} log_direction_t;
static inline const char *log_operation_name(enum log_operation operation)
static inline const char *log_operation_name(log_operation_t operation)
{
switch (operation) {
case LOG_OPERATION_AXFR:
......@@ -47,44 +49,40 @@ static inline const char *log_operation_name(enum log_operation operation)
return "refresh";
case LOG_OPERATION_UPDATE:
return "DDNS";
case LOG_OPERATION_PARENT:
return "parent DS check";
case LOG_OPERATION_DS_CHECK:
return "DS check";
case LOG_OPERATION_DS_PUSH:
return "DS push";
default:
return "?";
}
}
static inline const char *log_direction_name(enum log_direction direction)
static inline const char *log_direction_name(log_direction_t direction)
{
switch (direction) {
case LOG_DIRECTION_IN:
return "incoming";
return ", incoming";
case LOG_DIRECTION_OUT:
return "outgoing";
return ", outgoing";
case LOG_DIRECTION_NONE:
default:
return "?";
return "";
}
}
/*!
* \brief Generate log message for server communication.
*
* If this macro was a function:
*
* void ns_log(int priority, const knot_dname_t *zone, enum log_operation op,
* enum log_direction dir, const struct sockaddr *remote,
* const char *fmt, ...);
*
* Example output:
*
* [example.com] NOTIFY, outgoing, 2001:db8::1@53: serial 123
*
* [example.com] NOTIFY, outgoing, remote 2001:db8::1@53, serial 123
*/
#define ns_log(priority, zone, op, dir, remote, fmt, ...) \
do { \
char address[SOCKADDR_STRLEN] = ""; \
sockaddr_tostr(address, sizeof(address), remote); \
log_fmt_zone(priority, LOG_SOURCE_ZONE, zone, NULL, "%s, %s, %s: " fmt, \
log_fmt_zone(priority, LOG_SOURCE_ZONE, zone, NULL, "%s%s, remote %s, " fmt, \
log_operation_name(op), log_direction_name(dir), address, \
## __VA_ARGS__); \
} while (0)
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -16,7 +16,6 @@
#include <assert.h>
#include "knot/common/log.h"
#include "knot/nameserver/notify.h"
#include "knot/nameserver/internet.h"
#include "knot/nameserver/log.h"
......
......@@ -35,8 +35,8 @@ void xfr_stats_add(struct xfr_stats *stats, unsigned bytes);
void xfr_stats_end(struct xfr_stats *stats);
static inline
void xfr_log_finished(const knot_dname_t *zone, enum log_operation op,
enum log_direction dir, const struct sockaddr *remote,
void xfr_log_finished(const knot_dname_t *zone, log_operation_t op,
log_direction_t dir, const struct sockaddr *remote,
const struct xfr_stats *stats)
{
ns_log(LOG_INFO, zone, op, dir, remote,
......
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