2 This file is part of systemd.
4 Copyright 2014 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
21 #include "dns-domain.h"
23 #include "hostname-util.h"
24 #include "local-addresses.h"
25 #include "resolved-dns-query.h"
26 #include "resolved-dns-synthesize.h"
27 #include "resolved-etc-hosts.h"
28 #include "string-util.h"
30 /* How long to wait for the query in total */
31 #define QUERY_TIMEOUT_USEC (30 * USEC_PER_SEC)
34 #define QUERIES_MAX 2048
35 #define AUXILIARY_QUERIES_MAX 64
37 static int dns_query_candidate_new(DnsQueryCandidate
**ret
, DnsQuery
*q
, DnsScope
*s
) {
44 c
= new0(DnsQueryCandidate
, 1);
51 LIST_PREPEND(candidates_by_query
, q
->candidates
, c
);
52 LIST_PREPEND(candidates_by_scope
, s
->query_candidates
, c
);
58 static void dns_query_candidate_stop(DnsQueryCandidate
*c
) {
63 while ((t
= set_steal_first(c
->transactions
))) {
64 set_remove(t
->notify_query_candidates
, c
);
65 dns_transaction_gc(t
);
69 DnsQueryCandidate
* dns_query_candidate_free(DnsQueryCandidate
*c
) {
74 dns_query_candidate_stop(c
);
76 set_free(c
->transactions
);
77 dns_search_domain_unref(c
->search_domain
);
80 LIST_REMOVE(candidates_by_query
, c
->query
->candidates
, c
);
83 LIST_REMOVE(candidates_by_scope
, c
->scope
->query_candidates
, c
);
90 static int dns_query_candidate_next_search_domain(DnsQueryCandidate
*c
) {
91 DnsSearchDomain
*next
= NULL
;
95 if (c
->search_domain
&& c
->search_domain
->linked
)
96 next
= c
->search_domain
->domains_next
;
98 next
= dns_scope_get_search_domains(c
->scope
);
101 if (!next
) /* We hit the end of the list */
104 if (!next
->route_only
)
107 /* Skip over route-only domains */
108 next
= next
->domains_next
;
111 dns_search_domain_unref(c
->search_domain
);
112 c
->search_domain
= dns_search_domain_ref(next
);
117 static int dns_query_candidate_add_transaction(DnsQueryCandidate
*c
, DnsResourceKey
*key
) {
124 t
= dns_scope_find_transaction(c
->scope
, key
, true);
126 r
= dns_transaction_new(&t
, c
->scope
, key
);
130 if (set_contains(c
->transactions
, t
))
134 r
= set_ensure_allocated(&c
->transactions
, NULL
);
138 r
= set_ensure_allocated(&t
->notify_query_candidates
, NULL
);
142 r
= set_put(t
->notify_query_candidates
, c
);
146 r
= set_put(c
->transactions
, t
);
148 (void) set_remove(t
->notify_query_candidates
, c
);
155 dns_transaction_gc(t
);
159 static int dns_query_candidate_go(DnsQueryCandidate
*c
) {
167 /* Start the transactions that are not started yet */
168 SET_FOREACH(t
, c
->transactions
, i
) {
169 if (t
->state
!= DNS_TRANSACTION_NULL
)
172 r
= dns_transaction_go(t
);
179 /* If there was nothing to start, then let's proceed immediately */
181 dns_query_candidate_notify(c
);
186 static DnsTransactionState
dns_query_candidate_state(DnsQueryCandidate
*c
) {
187 DnsTransactionState state
= DNS_TRANSACTION_NO_SERVERS
;
193 if (c
->error_code
!= 0)
194 return DNS_TRANSACTION_ERRNO
;
196 SET_FOREACH(t
, c
->transactions
, i
) {
200 case DNS_TRANSACTION_NULL
:
201 /* If there's a NULL transaction pending, then
202 * this means not all transactions where
203 * started yet, and we were called from within
204 * the stackframe that is supposed to start
205 * remaining transactions. In this case,
206 * simply claim the candidate is pending. */
208 case DNS_TRANSACTION_PENDING
:
209 case DNS_TRANSACTION_VALIDATING
:
210 /* If there's one transaction currently in
211 * VALIDATING state, then this means there's
212 * also one in PENDING state, hence we can
213 * return PENDING immediately. */
214 return DNS_TRANSACTION_PENDING
;
216 case DNS_TRANSACTION_SUCCESS
:
221 if (state
!= DNS_TRANSACTION_SUCCESS
)
231 static bool dns_query_candidate_is_routable(DnsQueryCandidate
*c
, uint16_t type
) {
236 /* Checks whether the specified RR type matches an address family that is routable on the link(s) the scope of
237 * this candidate belongs to. Specifically, whether there's a routable IPv4 address on it if we query an A RR,
238 * or a routable IPv6 address if we query an AAAA RR. */
240 if (!c
->query
->suppress_unroutable_family
)
243 if (c
->scope
->protocol
!= DNS_PROTOCOL_DNS
)
246 family
= dns_type_to_af(type
);
251 return link_relevant(c
->scope
->link
, family
, false);
253 return manager_routable(c
->scope
->manager
, family
);
256 static int dns_query_candidate_setup_transactions(DnsQueryCandidate
*c
) {
257 DnsQuestion
*question
;
263 dns_query_candidate_stop(c
);
265 question
= dns_query_question_for_protocol(c
->query
, c
->scope
->protocol
);
267 /* Create one transaction per question key */
268 DNS_QUESTION_FOREACH(key
, question
) {
269 _cleanup_(dns_resource_key_unrefp
) DnsResourceKey
*new_key
= NULL
;
270 DnsResourceKey
*qkey
;
272 if (!dns_query_candidate_is_routable(c
, key
->type
))
275 if (c
->search_domain
) {
276 r
= dns_resource_key_new_append_suffix(&new_key
, key
, c
->search_domain
->name
);
284 if (!dns_scope_good_key(c
->scope
, qkey
))
287 r
= dns_query_candidate_add_transaction(c
, qkey
);
297 dns_query_candidate_stop(c
);
301 void dns_query_candidate_notify(DnsQueryCandidate
*c
) {
302 DnsTransactionState state
;
307 state
= dns_query_candidate_state(c
);
309 if (DNS_TRANSACTION_IS_LIVE(state
))
312 if (state
!= DNS_TRANSACTION_SUCCESS
&& c
->search_domain
) {
314 r
= dns_query_candidate_next_search_domain(c
);
319 /* OK, there's another search domain to try, let's do so. */
321 r
= dns_query_candidate_setup_transactions(c
);
326 /* New transactions where queued. Start them and wait */
328 r
= dns_query_candidate_go(c
);
338 dns_query_ready(c
->query
);
342 log_warning_errno(r
, "Failed to follow search domains: %m");
344 dns_query_ready(c
->query
);
347 static void dns_query_stop(DnsQuery
*q
) {
348 DnsQueryCandidate
*c
;
352 q
->timeout_event_source
= sd_event_source_unref(q
->timeout_event_source
);
354 LIST_FOREACH(candidates_by_query
, c
, q
->candidates
)
355 dns_query_candidate_stop(c
);
358 static void dns_query_free_candidates(DnsQuery
*q
) {
361 while (q
->candidates
)
362 dns_query_candidate_free(q
->candidates
);
365 static void dns_query_reset_answer(DnsQuery
*q
) {
368 q
->answer
= dns_answer_unref(q
->answer
);
370 q
->answer_dnssec_result
= _DNSSEC_RESULT_INVALID
;
372 q
->answer_authenticated
= false;
373 q
->answer_protocol
= _DNS_PROTOCOL_INVALID
;
374 q
->answer_family
= AF_UNSPEC
;
375 q
->answer_search_domain
= dns_search_domain_unref(q
->answer_search_domain
);
378 DnsQuery
*dns_query_free(DnsQuery
*q
) {
382 while (q
->auxiliary_queries
)
383 dns_query_free(q
->auxiliary_queries
);
385 if (q
->auxiliary_for
) {
386 assert(q
->auxiliary_for
->n_auxiliary_queries
> 0);
387 q
->auxiliary_for
->n_auxiliary_queries
--;
388 LIST_REMOVE(auxiliary_queries
, q
->auxiliary_for
->auxiliary_queries
, q
);
391 dns_query_free_candidates(q
);
393 dns_question_unref(q
->question_idna
);
394 dns_question_unref(q
->question_utf8
);
396 dns_query_reset_answer(q
);
398 sd_bus_message_unref(q
->request
);
399 sd_bus_track_unref(q
->bus_track
);
401 free(q
->request_address_string
);
404 LIST_REMOVE(queries
, q
->manager
->dns_queries
, q
);
405 q
->manager
->n_dns_queries
--;
416 DnsQuestion
*question_utf8
,
417 DnsQuestion
*question_idna
,
418 int ifindex
, uint64_t flags
) {
420 _cleanup_(dns_query_freep
) DnsQuery
*q
= NULL
;
424 char key_str
[DNS_RESOURCE_KEY_STRING_MAX
];
428 if (dns_question_size(question_utf8
) > 0) {
429 r
= dns_question_is_valid_for_query(question_utf8
);
438 /* If the IDNA and UTF8 questions are the same, merge their references */
439 r
= dns_question_is_equal(question_idna
, question_utf8
);
443 question_idna
= question_utf8
;
445 if (dns_question_size(question_idna
) > 0) {
446 r
= dns_question_is_valid_for_query(question_idna
);
456 if (!good
) /* don't allow empty queries */
459 if (m
->n_dns_queries
>= QUERIES_MAX
)
462 q
= new0(DnsQuery
, 1);
466 q
->question_utf8
= dns_question_ref(question_utf8
);
467 q
->question_idna
= dns_question_ref(question_idna
);
468 q
->ifindex
= ifindex
;
470 q
->answer_dnssec_result
= _DNSSEC_RESULT_INVALID
;
471 q
->answer_protocol
= _DNS_PROTOCOL_INVALID
;
472 q
->answer_family
= AF_UNSPEC
;
474 /* First dump UTF8 question */
475 DNS_QUESTION_FOREACH(key
, question_utf8
)
476 log_debug("Looking up RR for %s.",
477 dns_resource_key_to_string(key
, key_str
, sizeof key_str
));
479 /* And then dump the IDNA question, but only what hasn't been dumped already through the UTF8 question. */
480 DNS_QUESTION_FOREACH(key
, question_idna
) {
481 r
= dns_question_contains(question_utf8
, key
);
487 log_debug("Looking up IDNA RR for %s.",
488 dns_resource_key_to_string(key
, key_str
, sizeof key_str
));
491 LIST_PREPEND(queries
, m
->dns_queries
, q
);
502 int dns_query_make_auxiliary(DnsQuery
*q
, DnsQuery
*auxiliary_for
) {
504 assert(auxiliary_for
);
506 /* Ensure that that the query is not auxiliary yet, and
507 * nothing else is auxiliary to it either */
508 assert(!q
->auxiliary_for
);
509 assert(!q
->auxiliary_queries
);
511 /* Ensure that the unit we shall be made auxiliary for isn't
512 * auxiliary itself */
513 assert(!auxiliary_for
->auxiliary_for
);
515 if (auxiliary_for
->n_auxiliary_queries
>= AUXILIARY_QUERIES_MAX
)
518 LIST_PREPEND(auxiliary_queries
, auxiliary_for
->auxiliary_queries
, q
);
519 q
->auxiliary_for
= auxiliary_for
;
521 auxiliary_for
->n_auxiliary_queries
++;
525 static void dns_query_complete(DnsQuery
*q
, DnsTransactionState state
) {
527 assert(!DNS_TRANSACTION_IS_LIVE(state
));
528 assert(DNS_TRANSACTION_IS_LIVE(q
->state
));
530 /* Note that this call might invalidate the query. Callers
531 * should hence not attempt to access the query or transaction
532 * after calling this function. */
541 static int on_query_timeout(sd_event_source
*s
, usec_t usec
, void *userdata
) {
542 DnsQuery
*q
= userdata
;
547 dns_query_complete(q
, DNS_TRANSACTION_TIMEOUT
);
551 static int dns_query_add_candidate(DnsQuery
*q
, DnsScope
*s
) {
552 DnsQueryCandidate
*c
;
558 r
= dns_query_candidate_new(&c
, q
, s
);
562 /* If this a single-label domain on DNS, we might append a suitable search domain first. */
563 if ((q
->flags
& SD_RESOLVED_NO_SEARCH
) == 0) {
564 r
= dns_scope_name_needs_search_domain(s
, dns_question_first_name(q
->question_idna
));
568 /* OK, we need a search domain now. Let's find one for this scope */
570 r
= dns_query_candidate_next_search_domain(c
);
571 if (r
<= 0) /* if there's no search domain, then we won't add any transaction. */
576 r
= dns_query_candidate_setup_transactions(c
);
583 dns_query_candidate_free(c
);
587 static int dns_query_synthesize_reply(DnsQuery
*q
, DnsTransactionState
*state
) {
588 _cleanup_(dns_answer_unrefp
) DnsAnswer
*answer
= NULL
;
594 /* Tries to synthesize localhost RR replies (and others) where appropriate. Note that this is done *after* the
595 * the normal lookup finished. The data from the network hence takes precedence over the data we
596 * synthesize. (But note that many scopes refuse to resolve certain domain names) */
599 DNS_TRANSACTION_RCODE_FAILURE
,
600 DNS_TRANSACTION_NO_SERVERS
,
601 DNS_TRANSACTION_TIMEOUT
,
602 DNS_TRANSACTION_ATTEMPTS_MAX_REACHED
,
603 DNS_TRANSACTION_NETWORK_DOWN
,
604 DNS_TRANSACTION_NOT_FOUND
))
607 r
= dns_synthesize_answer(
616 dns_query_reset_answer(q
);
620 q
->answer_rcode
= DNS_RCODE_SUCCESS
;
621 q
->answer_protocol
= dns_synthesize_protocol(q
->flags
);
622 q
->answer_family
= dns_synthesize_family(q
->flags
);
623 q
->answer_authenticated
= true;
625 *state
= DNS_TRANSACTION_SUCCESS
;
630 static int dns_query_try_etc_hosts(DnsQuery
*q
) {
631 _cleanup_(dns_answer_unrefp
) DnsAnswer
*answer
= NULL
;
636 /* Looks in /etc/hosts for matching entries. Note that this is done *before* the normal lookup is done. The
637 * data from /etc/hosts hence takes precedence over the network. */
639 r
= manager_etc_hosts_lookup(
646 dns_query_reset_answer(q
);
650 q
->answer_rcode
= DNS_RCODE_SUCCESS
;
651 q
->answer_protocol
= dns_synthesize_protocol(q
->flags
);
652 q
->answer_family
= dns_synthesize_family(q
->flags
);
653 q
->answer_authenticated
= true;
658 int dns_query_go(DnsQuery
*q
) {
659 DnsScopeMatch found
= DNS_SCOPE_NO
;
660 DnsScope
*s
, *first
= NULL
;
661 DnsQueryCandidate
*c
;
666 if (q
->state
!= DNS_TRANSACTION_NULL
)
669 r
= dns_query_try_etc_hosts(q
);
673 dns_query_complete(q
, DNS_TRANSACTION_SUCCESS
);
677 LIST_FOREACH(scopes
, s
, q
->manager
->dns_scopes
) {
681 name
= dns_question_first_name(dns_query_question_for_protocol(q
, s
->protocol
));
685 match
= dns_scope_good_domain(s
, q
->ifindex
, q
->flags
, name
);
689 if (match
== DNS_SCOPE_NO
)
694 if (match
== DNS_SCOPE_YES
) {
698 assert(match
== DNS_SCOPE_MAYBE
);
705 if (found
== DNS_SCOPE_NO
) {
706 DnsTransactionState state
= DNS_TRANSACTION_NO_SERVERS
;
708 r
= dns_query_synthesize_reply(q
, &state
);
712 dns_query_complete(q
, state
);
716 r
= dns_query_add_candidate(q
, first
);
720 LIST_FOREACH(scopes
, s
, first
->scopes_next
) {
724 name
= dns_question_first_name(dns_query_question_for_protocol(q
, s
->protocol
));
728 match
= dns_scope_good_domain(s
, q
->ifindex
, q
->flags
, name
);
735 r
= dns_query_add_candidate(q
, s
);
740 dns_query_reset_answer(q
);
742 r
= sd_event_add_time(
744 &q
->timeout_event_source
,
745 clock_boottime_or_monotonic(),
746 now(clock_boottime_or_monotonic()) + QUERY_TIMEOUT_USEC
, 0,
747 on_query_timeout
, q
);
751 (void) sd_event_source_set_description(q
->timeout_event_source
, "query-timeout");
753 q
->state
= DNS_TRANSACTION_PENDING
;
756 /* Start the transactions */
757 LIST_FOREACH(candidates_by_query
, c
, q
->candidates
) {
758 r
= dns_query_candidate_go(c
);
775 static void dns_query_accept(DnsQuery
*q
, DnsQueryCandidate
*c
) {
776 DnsTransactionState state
= DNS_TRANSACTION_NO_SERVERS
;
777 bool has_authenticated
= false, has_non_authenticated
= false;
778 DnssecResult dnssec_result_authenticated
= _DNSSEC_RESULT_INVALID
, dnssec_result_non_authenticated
= _DNSSEC_RESULT_INVALID
;
786 r
= dns_query_synthesize_reply(q
, &state
);
790 dns_query_complete(q
, state
);
794 if (c
->error_code
!= 0) {
795 /* If the candidate had an error condition of its own, start with that. */
796 state
= DNS_TRANSACTION_ERRNO
;
797 q
->answer
= dns_answer_unref(q
->answer
);
799 q
->answer_dnssec_result
= _DNSSEC_RESULT_INVALID
;
800 q
->answer_errno
= c
->error_code
;
803 SET_FOREACH(t
, c
->transactions
, i
) {
807 case DNS_TRANSACTION_SUCCESS
: {
808 /* We found a successfuly reply, merge it into the answer */
809 r
= dns_answer_extend(&q
->answer
, t
->answer
);
813 q
->answer_rcode
= t
->answer_rcode
;
816 if (t
->answer_authenticated
) {
817 has_authenticated
= true;
818 dnssec_result_authenticated
= t
->answer_dnssec_result
;
820 has_non_authenticated
= true;
821 dnssec_result_non_authenticated
= t
->answer_dnssec_result
;
824 state
= DNS_TRANSACTION_SUCCESS
;
828 case DNS_TRANSACTION_NULL
:
829 case DNS_TRANSACTION_PENDING
:
830 case DNS_TRANSACTION_VALIDATING
:
831 case DNS_TRANSACTION_ABORTED
:
832 /* Ignore transactions that didn't complete */
836 /* Any kind of failure? Store the data away,
837 * if there's nothing stored yet. */
839 if (state
== DNS_TRANSACTION_SUCCESS
)
842 q
->answer
= dns_answer_unref(q
->answer
);
843 q
->answer_rcode
= t
->answer_rcode
;
844 q
->answer_dnssec_result
= t
->answer_dnssec_result
;
845 q
->answer_errno
= t
->answer_errno
;
852 if (state
== DNS_TRANSACTION_SUCCESS
) {
853 q
->answer_authenticated
= has_authenticated
&& !has_non_authenticated
;
854 q
->answer_dnssec_result
= q
->answer_authenticated
? dnssec_result_authenticated
: dnssec_result_non_authenticated
;
857 q
->answer_protocol
= c
->scope
->protocol
;
858 q
->answer_family
= c
->scope
->family
;
860 dns_search_domain_unref(q
->answer_search_domain
);
861 q
->answer_search_domain
= dns_search_domain_ref(c
->search_domain
);
863 r
= dns_query_synthesize_reply(q
, &state
);
867 dns_query_complete(q
, state
);
871 q
->answer_errno
= -r
;
872 dns_query_complete(q
, DNS_TRANSACTION_ERRNO
);
875 void dns_query_ready(DnsQuery
*q
) {
877 DnsQueryCandidate
*bad
= NULL
, *c
;
878 bool pending
= false;
881 assert(DNS_TRANSACTION_IS_LIVE(q
->state
));
883 /* Note that this call might invalidate the query. Callers
884 * should hence not attempt to access the query or transaction
885 * after calling this function, unless the block_ready
886 * counter was explicitly bumped before doing so. */
888 if (q
->block_ready
> 0)
891 LIST_FOREACH(candidates_by_query
, c
, q
->candidates
) {
892 DnsTransactionState state
;
894 state
= dns_query_candidate_state(c
);
897 case DNS_TRANSACTION_SUCCESS
:
898 /* One of the candidates is successful,
899 * let's use it, and copy its data out */
900 dns_query_accept(q
, c
);
903 case DNS_TRANSACTION_NULL
:
904 case DNS_TRANSACTION_PENDING
:
905 case DNS_TRANSACTION_VALIDATING
:
906 /* One of the candidates is still going on,
907 * let's maybe wait for it */
912 /* Any kind of failure */
921 dns_query_accept(q
, bad
);
924 static int dns_query_cname_redirect(DnsQuery
*q
, const DnsResourceRecord
*cname
) {
925 _cleanup_(dns_question_unrefp
) DnsQuestion
*nq_idna
= NULL
, *nq_utf8
= NULL
;
930 q
->n_cname_redirects
++;
931 if (q
->n_cname_redirects
> CNAME_MAX
)
934 r
= dns_question_cname_redirect(q
->question_idna
, cname
, &nq_idna
);
938 log_debug("Following CNAME/DNAME %s → %s.", dns_question_first_name(q
->question_idna
), dns_question_first_name(nq_idna
));
940 k
= dns_question_is_equal(q
->question_idna
, q
->question_utf8
);
944 /* Same question? Shortcut new question generation */
945 nq_utf8
= dns_question_ref(nq_idna
);
948 k
= dns_question_cname_redirect(q
->question_utf8
, cname
, &nq_utf8
);
952 log_debug("Following UTF8 CNAME/DNAME %s → %s.", dns_question_first_name(q
->question_utf8
), dns_question_first_name(nq_utf8
));
955 if (r
== 0 && k
== 0) /* No actual cname happened? */
958 if (q
->answer_protocol
== DNS_PROTOCOL_DNS
) {
959 /* Don't permit CNAME redirects from unicast DNS to LLMNR or MulticastDNS, so that global resources
960 * cannot invade the local namespace. The opposite way we permit: local names may redirect to global
963 q
->flags
&= ~(SD_RESOLVED_LLMNR
|SD_RESOLVED_MDNS
); /* mask away the local protocols */
966 /* Turn off searching for the new name */
967 q
->flags
|= SD_RESOLVED_NO_SEARCH
;
969 dns_question_unref(q
->question_idna
);
970 q
->question_idna
= nq_idna
;
973 dns_question_unref(q
->question_utf8
);
974 q
->question_utf8
= nq_utf8
;
977 dns_query_free_candidates(q
);
978 dns_query_reset_answer(q
);
980 q
->state
= DNS_TRANSACTION_NULL
;
985 int dns_query_process_cname(DnsQuery
*q
) {
986 _cleanup_(dns_resource_record_unrefp
) DnsResourceRecord
*cname
= NULL
;
987 DnsQuestion
*question
;
988 DnsResourceRecord
*rr
;
993 if (!IN_SET(q
->state
, DNS_TRANSACTION_SUCCESS
, DNS_TRANSACTION_NULL
))
994 return DNS_QUERY_NOMATCH
;
996 question
= dns_query_question_for_protocol(q
, q
->answer_protocol
);
998 DNS_ANSWER_FOREACH(rr
, q
->answer
) {
999 r
= dns_question_matches_rr(question
, rr
, DNS_SEARCH_DOMAIN_NAME(q
->answer_search_domain
));
1003 return DNS_QUERY_MATCH
; /* The answer matches directly, no need to follow cnames */
1005 r
= dns_question_matches_cname_or_dname(question
, rr
, DNS_SEARCH_DOMAIN_NAME(q
->answer_search_domain
));
1008 if (r
> 0 && !cname
)
1009 cname
= dns_resource_record_ref(rr
);
1013 return DNS_QUERY_NOMATCH
; /* No match and no cname to follow */
1015 if (q
->flags
& SD_RESOLVED_NO_CNAME
)
1018 /* OK, let's actually follow the CNAME */
1019 r
= dns_query_cname_redirect(q
, cname
);
1023 /* Let's see if the answer can already answer the new
1024 * redirected question */
1025 r
= dns_query_process_cname(q
);
1026 if (r
!= DNS_QUERY_NOMATCH
)
1029 /* OK, it cannot, let's begin with the new query */
1030 r
= dns_query_go(q
);
1034 return DNS_QUERY_RESTARTED
; /* We restarted the query for a new cname */
1037 static int on_bus_track(sd_bus_track
*t
, void *userdata
) {
1038 DnsQuery
*q
= userdata
;
1043 log_debug("Client of active query vanished, aborting query.");
1044 dns_query_complete(q
, DNS_TRANSACTION_ABORTED
);
1048 int dns_query_bus_track(DnsQuery
*q
, sd_bus_message
*m
) {
1054 if (!q
->bus_track
) {
1055 r
= sd_bus_track_new(sd_bus_message_get_bus(m
), &q
->bus_track
, on_bus_track
, q
);
1060 r
= sd_bus_track_add_sender(q
->bus_track
, m
);
1067 DnsQuestion
* dns_query_question_for_protocol(DnsQuery
*q
, DnsProtocol protocol
) {
1072 case DNS_PROTOCOL_DNS
:
1073 return q
->question_idna
;
1075 case DNS_PROTOCOL_MDNS
:
1076 case DNS_PROTOCOL_LLMNR
:
1077 return q
->question_utf8
;
1084 const char *dns_query_string(DnsQuery
*q
) {
1088 /* Returns a somewhat useful human-readable lookup key string for this query */
1090 if (q
->request_address_string
)
1091 return q
->request_address_string
;
1093 if (q
->request_address_valid
) {
1094 r
= in_addr_to_string(q
->request_family
, &q
->request_address
, &q
->request_address_string
);
1096 return q
->request_address_string
;
1099 name
= dns_question_first_name(q
->question_utf8
);
1103 return dns_question_first_name(q
->question_idna
);