]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-query.h
0c836d799c3269e87982b541f1b4cf4311e2704a
[thirdparty/systemd.git] / src / resolve / resolved-dns-query.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2014 Lennart Poettering
6 ***/
7
8 #include "sd-bus.h"
9
10 #include "set.h"
11
12 typedef struct DnsQueryCandidate DnsQueryCandidate;
13 typedef struct DnsQuery DnsQuery;
14
15 #include "resolved-dns-answer.h"
16 #include "resolved-dns-question.h"
17 #include "resolved-dns-stream.h"
18 #include "resolved-dns-search-domain.h"
19
20 struct DnsQueryCandidate {
21 DnsQuery *query;
22 DnsScope *scope;
23
24 DnsSearchDomain *search_domain;
25
26 int error_code;
27 Set *transactions;
28
29 LIST_FIELDS(DnsQueryCandidate, candidates_by_query);
30 LIST_FIELDS(DnsQueryCandidate, candidates_by_scope);
31 };
32
33 struct DnsQuery {
34 Manager *manager;
35
36 /* When resolving a service, we first create a TXT+SRV query,
37 * and then for the hostnames we discover auxiliary A+AAAA
38 * queries. This pointer always points from the auxiliary
39 * queries back to the TXT+SRV query. */
40 DnsQuery *auxiliary_for;
41 LIST_HEAD(DnsQuery, auxiliary_queries);
42 unsigned n_auxiliary_queries;
43 int auxiliary_result;
44
45 /* The question, formatted in IDNA for use on classic DNS, and as UTF8 for use in LLMNR or mDNS. Note that even
46 * on classic DNS some labels might use UTF8 encoding. Specifically, DNS-SD service names (in contrast to their
47 * domain suffixes) use UTF-8 encoding even on DNS. Thus, the difference between these two fields is mostly
48 * relevant only for explicit *hostname* lookups as well as the domain suffixes of service lookups. */
49 DnsQuestion *question_idna;
50 DnsQuestion *question_utf8;
51
52 uint64_t flags;
53 int ifindex;
54
55 /* If true, A or AAAA RR lookups will be suppressed on links with no routable address of the matching address
56 * family */
57 bool suppress_unroutable_family;
58
59 /* If true, the RR TTLs of the answer will be clamped by their current left validity in the cache */
60 bool clamp_ttl;
61
62 DnsTransactionState state;
63 unsigned n_cname_redirects;
64
65 LIST_HEAD(DnsQueryCandidate, candidates);
66 sd_event_source *timeout_event_source;
67
68 /* Discovered data */
69 DnsAnswer *answer;
70 int answer_rcode;
71 DnssecResult answer_dnssec_result;
72 bool answer_authenticated;
73 DnsProtocol answer_protocol;
74 int answer_family;
75 DnsSearchDomain *answer_search_domain;
76 int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
77 bool previous_redirect_unauthenticated;
78
79 /* Bus client information */
80 sd_bus_message *request;
81 int request_family;
82 bool request_address_valid;
83 union in_addr_union request_address;
84 unsigned block_all_complete;
85 char *request_address_string;
86
87 /* DNS stub information */
88 DnsPacket *request_dns_packet;
89 DnsStream *request_dns_stream;
90 DnsPacket *reply_dns_packet;
91
92 /* Completion callback */
93 void (*complete)(DnsQuery* q);
94 unsigned block_ready;
95
96 sd_bus_track *bus_track;
97
98 LIST_FIELDS(DnsQuery, queries);
99 LIST_FIELDS(DnsQuery, auxiliary_queries);
100 };
101
102 enum {
103 DNS_QUERY_MATCH,
104 DNS_QUERY_NOMATCH,
105 DNS_QUERY_RESTARTED,
106 };
107
108 DnsQueryCandidate* dns_query_candidate_free(DnsQueryCandidate *c);
109 void dns_query_candidate_notify(DnsQueryCandidate *c);
110
111 int dns_query_new(Manager *m, DnsQuery **q, DnsQuestion *question_utf8, DnsQuestion *question_idna, int family, uint64_t flags);
112 DnsQuery *dns_query_free(DnsQuery *q);
113
114 int dns_query_make_auxiliary(DnsQuery *q, DnsQuery *auxiliary_for);
115
116 int dns_query_go(DnsQuery *q);
117 void dns_query_ready(DnsQuery *q);
118
119 int dns_query_process_cname(DnsQuery *q);
120
121 int dns_query_bus_track(DnsQuery *q, sd_bus_message *m);
122
123 DnsQuestion* dns_query_question_for_protocol(DnsQuery *q, DnsProtocol protocol);
124
125 const char *dns_query_string(DnsQuery *q);
126
127 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);
128
129 bool dns_query_fully_authenticated(DnsQuery *q);