From: Jan Doskočil Date: Tue, 9 Dec 2025 15:24:24 +0000 (+0100) Subject: dnstap: responses-with-queries as part of dt_message_fill X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=799f0185d20e4e3656f5c3b3ebcc539eee348ad3;p=thirdparty%2Fknot-dns.git dnstap: responses-with-queries as part of dt_message_fill refactoring --- diff --git a/src/contrib/dnstap/message.c b/src/contrib/dnstap/message.c index 2f3b9b2b15..0ece7c503a 100644 --- a/src/contrib/dnstap/message.c +++ b/src/contrib/dnstap/message.c @@ -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; diff --git a/src/contrib/dnstap/message.h b/src/contrib/dnstap/message.h index ef24dada63..e3067a1081 100644 --- a/src/contrib/dnstap/message.h +++ b/src/contrib/dnstap/message.h @@ -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); diff --git a/src/knot/modules/dnstap/dnstap.c b/src/knot/modules/dnstap/dnstap.c index f5c4663785..f9de9fe5ea 100644 --- a/src/knot/modules/dnstap/dnstap.c +++ b/src/knot/modules/dnstap/dnstap.c @@ -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; diff --git a/src/utils/kdig/kdig_exec.c b/src/utils/kdig/kdig_exec.c index ab14acbffd..61e4ef98ab 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); + wire, wire_len, mtime, NULL, 0); if (ret != KNOT_EOK) { return ret; }