]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: make sure "resolvectl monitor" can properly deal with stub queries
authorLennart Poettering <lennart@poettering.net>
Tue, 31 Oct 2023 22:00:41 +0000 (23:00 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Nov 2023 22:00:45 +0000 (23:00 +0100)
If we receive a query via the two stubs we store the original packet
instead of just the question object. Hence when we send monitor info to
subscribed clients we need to extract its question and also include it
in the returned data.

Fixes: #29580
src/resolve/resolved-dns-query.c
src/resolve/resolved-manager.c
src/resolve/resolved-manager.h

index 58a7b2d878db4d6ccb049adfaf714700e5bcabce..7eb6b9736e2465014751414608c63431a5fec5d0 100644 (file)
@@ -586,7 +586,7 @@ void dns_query_complete(DnsQuery *q, DnsTransactionState state) {
 
         q->state = state;
 
-        (void) manager_monitor_send(q->manager, q->state, q->answer_rcode, q->answer_errno, q->question_idna, q->question_utf8, q->collected_questions, q->answer);
+        (void) manager_monitor_send(q->manager, q->state, q->answer_rcode, q->answer_errno, q->question_idna, q->question_utf8, q->question_bypass, q->collected_questions, q->answer);
 
         dns_query_stop(q);
         if (q->complete)
index fd800cedfe0f1eda9505fd8ff258f854bd047a64..fc8d7412fbad6f200c37454eb92755926f6f58fc 100644 (file)
@@ -1105,6 +1105,7 @@ int manager_monitor_send(
                 int error,
                 DnsQuestion *question_idna,
                 DnsQuestion *question_utf8,
+                DnsPacket *question_bypass,
                 DnsQuestion *collected_questions,
                 DnsAnswer *answer) {
 
@@ -1119,11 +1120,22 @@ int manager_monitor_send(
         if (set_isempty(m->varlink_subscription))
                 return 0;
 
-        /* Merge both questions format into one */
+        /* Merge all questions into one */
         r = dns_question_merge(question_idna, question_utf8, &merged);
         if (r < 0)
                 return log_error_errno(r, "Failed to merge UTF8/IDNA questions: %m");
 
+        if (question_bypass) {
+                _cleanup_(dns_question_unrefp) DnsQuestion *merged2 = NULL;
+
+                r = dns_question_merge(merged, question_bypass->question, &merged2);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to merge UTF8/IDNA questions and DNS packet question: %m");
+
+                dns_question_unref(merged);
+                merged = TAKE_PTR(merged2);
+        }
+
         /* Convert the current primary question to JSON */
         r = dns_question_to_json(merged, &jquestion);
         if (r < 0)
index 16b883bd2192f09259966a05b349160938c39799..5cd5e834d39f081829d016ffe858956c523f817a 100644 (file)
@@ -176,7 +176,7 @@ int manager_start(Manager *m);
 
 uint32_t manager_find_mtu(Manager *m);
 
-int manager_monitor_send(Manager *m, int state, int rcode, int error, DnsQuestion *question_idna, DnsQuestion *question_utf8, DnsQuestion *collected_questions, DnsAnswer *answer);
+int manager_monitor_send(Manager *m, int state, int rcode, int error, DnsQuestion *question_idna, DnsQuestion *question_utf8, DnsPacket *question_bypass, DnsQuestion *collected_questions, DnsAnswer *answer);
 
 int manager_write(Manager *m, int fd, DnsPacket *p);
 int manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *destination, uint16_t port, const union in_addr_union *source, DnsPacket *p);