]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
dnstap: responses-with-queries as part of dt_message_fill
authorJan Doskočil <jan.doskocil@nic.cz>
Tue, 9 Dec 2025 15:24:24 +0000 (16:24 +0100)
committerJan Doskočil <jan.doskocil@nic.cz>
Tue, 9 Dec 2025 15:24:24 +0000 (16:24 +0100)
refactoring

src/contrib/dnstap/message.c
src/contrib/dnstap/message.h
src/knot/modules/dnstap/dnstap.c
src/utils/kdig/kdig_exec.c

index 2f3b9b2b15115ae4b721eb984cc864b273dfafaf..0ece7c503acaa41c396cda9a3d2d07b10f24e626 100644 (file)
@@ -62,7 +62,9 @@ int dt_message_fill(Dnstap__Message             *m,
                     const int                   protocol,
                     const void                  *wire,
                     const size_t                len_wire,
-                    const struct timespec       *mtime)
+                    const struct timespec       *mtime,
+                    const void                  *wire_q,
+                    const size_t                len_wire_q)
 {
        if (m == NULL) {
                return KNOT_EINVAL;
@@ -113,6 +115,13 @@ int dt_message_fill(Dnstap__Message             *m,
                        m->has_response_time_sec = 1;
                        m->has_response_time_nsec = 1;
                }
+               /* Also add query message if 'responses-with-queries' is enabled and this is a response. */
+               if (wire_q != NULL) {
+                       // Message.query_message
+                       m->query_message.len = len_wire_q;
+                       m->query_message.data = (uint8_t *)wire_q;
+                       m->has_query_message = 1;
+               }
        }
 
        return KNOT_EOK;
index ef24dada630eb4b76fac6a3bccaeede891c8aa3e..e3067a1081e3a15155e7cdb5afa3264312ac98a4 100644 (file)
@@ -37,6 +37,9 @@
  * \param mtime
  *     Message time. May be NULL.
  *
+ * \param *_q
+ *     Symmetrical query parameters in case responses-with-queries is enabled.
+ *
  * \retval KNOT_EOK
  * \retval KNOT_EINVAL
  */
@@ -47,4 +50,6 @@ int dt_message_fill(Dnstap__Message             *m,
                     const int                   protocol,
                     const void                  *wire,
                     const size_t                len_wire,
-                    const struct timespec       *mtime);
+                    const struct timespec       *mtime,
+                    const void                  *wire_q,
+                    const size_t                len_wire_q);
index f5c4663785a2456f30b37f66e6d375e6a6c35363..f9de9fe5ea51b585351bbf06f89f586fb9bc531d 100644 (file)
@@ -97,7 +97,9 @@ static knotd_state_t log_message(knotd_state_t state, const knot_pkt_t *pkt,
        int ret = dt_message_fill(&msg, msgtype,
                                  (const struct sockaddr *)knotd_qdata_remote_addr(qdata),
                                  (const struct sockaddr *)knotd_qdata_local_addr(qdata),
-                                 qdata->params->proto, pkt->wire, pkt->size, &tv);
+                                 qdata->params->proto, pkt->wire, pkt->size, &tv,
+                                 (ctx->with_queries && qdata->query != NULL) ? qdata->query->wire : NULL,
+                                 qdata->query->size);
        if (ret != KNOT_EOK) {
                return state;
        }
@@ -118,16 +120,6 @@ static knotd_state_t log_message(knotd_state_t state, const knot_pkt_t *pkt,
                dnstap.has_version = 1;
        }
 
-       /* Also add query message if 'responses-with-queries' is enabled and this is a response. */
-       if (ctx->with_queries &&
-           msgtype == DNSTAP__MESSAGE__TYPE__AUTH_RESPONSE &&
-           qdata->query != NULL)
-       {
-               msg.query_message.len = qdata->query->size;
-               msg.query_message.data = qdata->query->wire;
-               msg.has_query_message = 1;
-       }
-
        /* Pack the message. */
        uint8_t *frame = NULL;
        size_t size = 0;
index ab14acbffd3f38fcf916616192c87506c5a0c649..61e4ef98ab045b7621f276e128c8dcbaf4b8dc30 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);
+                             wire, wire_len, mtime, NULL, 0);
        if (ret != KNOT_EOK) {
                return ret;
        }