]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
dnstap: query time separate from response time ms
authorJan Doskočil <jan.doskocil@nic.cz>
Tue, 9 Dec 2025 15:27:03 +0000 (16:27 +0100)
committerJan Doskočil <jan.doskocil@nic.cz>
Tue, 9 Dec 2025 15:27:03 +0000 (16:27 +0100)
Microsoft compatibility measure.

src/contrib/dnstap/message.c
src/contrib/dnstap/message.h
src/knot/include/module.h
src/knot/modules/dnstap/dnstap.c
src/knot/nameserver/process_query.c
src/utils/kdig/kdig_exec.c

index 0ece7c503acaa41c396cda9a3d2d07b10f24e626..1a2c0b720899ee486b02eec44a9f08a3fca02242 100644 (file)
@@ -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;
+                       }
                }
        }
 
index e3067a1081e3a15155e7cdb5afa3264312ac98a4..5011af2231a308c761918831c52c20712f542d7f 100644 (file)
@@ -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);
index 6e02b504d99a5055c3345c67341a85b42f88abac..a456d4f0e9017b606291af5ac829999d28f9814b 100644 (file)
@@ -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;
 
index f9de9fe5ea51b585351bbf06f89f586fb9bc531d..4244f7db0deaf134a5d6e98a6a3da0aeb0eecde1 100644 (file)
@@ -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;
        }
index 6f37928bfe176e7a775d53ec194924d93040d4d3..74a8165d7b619d6add05cfc37115855d01f7b2cf 100644 (file)
 #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;
index 61e4ef98ab045b7621f276e128c8dcbaf4b8dc30..b6538c4214b70a1f83bd004a8a8925e9a77c3b5e 100644 (file)
@@ -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;
        }