From: Jan Doskočil Date: Tue, 9 Dec 2025 15:27:03 +0000 (+0100) Subject: dnstap: query time separate from response time X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fms;p=thirdparty%2Fknot-dns.git dnstap: query time separate from response time Microsoft compatibility measure. --- diff --git a/src/contrib/dnstap/message.c b/src/contrib/dnstap/message.c index 0ece7c503a..1a2c0b7208 100644 --- a/src/contrib/dnstap/message.c +++ b/src/contrib/dnstap/message.c @@ -64,7 +64,8 @@ int dt_message_fill(Dnstap__Message *m, const size_t len_wire, const struct timespec *mtime, const void *wire_q, - const size_t len_wire_q) + const size_t len_wire_q, + const struct timespec *mtime_q) { if (m == NULL) { return KNOT_EINVAL; @@ -121,6 +122,13 @@ int dt_message_fill(Dnstap__Message *m, m->query_message.len = len_wire_q; m->query_message.data = (uint8_t *)wire_q; m->has_query_message = 1; + // Message.query_time_sec, Message.query_time_nsec + if (mtime_q != NULL) { + m->query_time_sec = mtime_q->tv_sec; + m->query_time_nsec = mtime_q->tv_nsec; + m->has_query_time_sec = 1; + m->has_query_time_nsec = 1; + } } } diff --git a/src/contrib/dnstap/message.h b/src/contrib/dnstap/message.h index e3067a1081..5011af2231 100644 --- a/src/contrib/dnstap/message.h +++ b/src/contrib/dnstap/message.h @@ -52,4 +52,5 @@ int dt_message_fill(Dnstap__Message *m, const size_t len_wire, const struct timespec *mtime, const void *wire_q, - const size_t len_wire_q); + const size_t len_wire_q, + const struct timespec *mtime_q); diff --git a/src/knot/include/module.h b/src/knot/include/module.h index 6e02b504d9..a456d4f0e9 100644 --- a/src/knot/include/module.h +++ b/src/knot/include/module.h @@ -424,6 +424,7 @@ typedef struct { knot_mm_t *mm; /*!< Memory context. */ knotd_qdata_params_t *params; /*!< Low-level processing parameters. */ + struct timespec query_time; /*!< Time when the query was received. */ struct knotd_qdata_extra *extra; /*!< Private items (process_query.h). */ } knotd_qdata_t; diff --git a/src/knot/modules/dnstap/dnstap.c b/src/knot/modules/dnstap/dnstap.c index f9de9fe5ea..4244f7db0d 100644 --- a/src/knot/modules/dnstap/dnstap.c +++ b/src/knot/modules/dnstap/dnstap.c @@ -99,7 +99,7 @@ static knotd_state_t log_message(knotd_state_t state, const knot_pkt_t *pkt, (const struct sockaddr *)knotd_qdata_local_addr(qdata), qdata->params->proto, pkt->wire, pkt->size, &tv, (ctx->with_queries && qdata->query != NULL) ? qdata->query->wire : NULL, - qdata->query->size); + qdata->query->size, &qdata->query_time); if (ret != KNOT_EOK) { return state; } diff --git a/src/knot/nameserver/process_query.c b/src/knot/nameserver/process_query.c index 6f37928bfe..74a8165d7b 100644 --- a/src/knot/nameserver/process_query.c +++ b/src/knot/nameserver/process_query.c @@ -26,6 +26,10 @@ #include "contrib/macros.h" #include "contrib/mempattern.h" +#ifndef CLOCK_REALTIME_COARSE +#define CLOCK_REALTIME_COARSE CLOCK_REALTIME +#endif + /*! \brief Accessor to query-specific data. */ #define QUERY_DATA(ctx) ((knotd_qdata_t *)(ctx)->data) @@ -72,6 +76,7 @@ static int process_query_begin(knot_layer_t *ctx, void *params) /* Initialize persistent data. */ query_data_init(ctx, params, extra); + clock_gettime(CLOCK_REALTIME_COARSE, &QUERY_DATA(ctx)->query_time); /* Await packet. */ return KNOT_STATE_CONSUME; diff --git a/src/utils/kdig/kdig_exec.c b/src/utils/kdig/kdig_exec.c index 61e4ef98ab..b6538c4214 100644 --- a/src/utils/kdig/kdig_exec.c +++ b/src/utils/kdig/kdig_exec.c @@ -56,7 +56,7 @@ static int write_dnstap(dt_writer_t *writer, ret = dt_message_fill(&msg, msg_type, net->local_info->ai_addr, net->srv->ai_addr, protocol, - wire, wire_len, mtime, NULL, 0); + wire, wire_len, mtime, NULL, 0, NULL); if (ret != KNOT_EOK) { return ret; }