Debian Codegraph @

src/resolve/resolved-dns-query.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "dns-packet.h"
5 #include "in-addr-util.h"
6 #include "list.h"
7 #include "resolved-dns-browse-services.h"
8 #include "resolved-dns-transaction.h"
9 #include "resolved-forward.h"
10
11 typedef struct DnsQueryCandidate {
12 unsigned n_ref;
13 int error_code;
14 uint64_t generation;
15
16 DnsQuery *query;
17 DnsScope *scope;
18
19 DnsSearchDomain *search_domain;
20
21 Set *transactions;
22 sd_event_source *timeout_event_source;
23
24 LIST_FIELDS(DnsQueryCandidate, candidates_by_query);
25 LIST_FIELDS(DnsQueryCandidate, candidates_by_scope);
26 } DnsQueryCandidate;
27
28 typedef struct DnsQuery {
29 Manager *manager;
30
31 /* The question, formatted in IDNA for use on classic DNS, and as UTF8 for use in LLMNR or mDNS. Note
32 * that even on classic DNS some labels might use UTF8 encoding. Specifically, DNS-SD service names
33 * (in contrast to their domain suffixes) use UTF-8 encoding even on DNS. Thus, the difference
34 * between these two fields is mostly relevant only for explicit *hostname* lookups as well as the
35 * domain suffixes of service lookups.
36 *
37 * Note that questions may consist of multiple RR keys at once, but they must be for the same domain
38 * name. This is used for A+AAAA and TXT+SRV lookups: we'll allocate a single DnsQuery object for
39 * them instead of two separate ones. That allows us minor optimizations with response handling:
40 * CNAME/DNAMEs of the first reply we get can already be used to follow the CNAME/DNAME chain for
41 * both, and we can take benefit of server replies that oftentimes put A responses into AAAA queries
42 * and vice versa (in the additional section). */
43 DnsQuestion *question_idna;
44 DnsQuestion *question_utf8;
45
46 /* If this is not a question by ourselves, but a "bypass" request, we propagate the original packet
47 * here, and use that instead. */
48 DnsPacket *question_bypass;
49
50 /* When we follow a CNAME redirect, we save the original question here, for informational/monitoring
51 * purposes. We'll keep adding to this whenever we go one step in the redirect, so that in the end
52 * this will contain the complete set of CNAME questions. */
53 DnsQuestion *collected_questions;
54
55 uint64_t flags;
56 int ifindex;
57
58 /* When resolving a service, we first create a TXT+SRV query, and then for the hostnames we discover
59 * auxiliary A+AAAA queries. This pointer always points from the auxiliary queries back to the
60 * TXT+SRV query. */
61 int auxiliary_result;
62 DnsQuery *auxiliary_for;
63 LIST_HEAD(DnsQuery, auxiliary_queries);
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 int answer_ede_rcode;
72 char *answer_ede_msg;
73 DnssecResult answer_dnssec_result;
74 uint64_t answer_query_flags;
75 DnsProtocol answer_protocol;
76 int answer_family;
77 DnsPacket *answer_full_packet;
78 DnsSearchDomain *answer_search_domain;
79
80 DnsTransactionState state;
81 int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
82
83 unsigned block_ready;
84
85 uint8_t n_auxiliary_queries;
86 uint8_t n_cname_redirects;
87
88 bool previous_redirect_unauthenticated:1;
89 bool previous_redirect_non_confidential:1;
90 bool previous_redirect_non_synthetic:1;
91 bool request_address_valid:1;
92
93 /* Bus + Varlink client information */
94 sd_bus_message *bus_request;
95 sd_varlink *varlink_request;
96 int request_family;
97 union in_addr_union request_address;
98 unsigned block_all_complete;
99 char *request_address_string;
100
101 /* DNS stub information */
102 DnsPacket *request_packet;
103 DnsStream *request_stream;
104 DnsAnswer *reply_answer;
105 DnsAnswer *reply_authoritative;
106 DnsAnswer *reply_additional;
107 DnsStubListenerExtra *stub_listener_extra;
108
109 /* Browser Service and Dnssd Discovered Service Information */
110 DnssdDiscoveredService *dnsservice_request;
111 DnsServiceBrowser *service_browser_request;
112
113 /* Pending query to any installed hooks */
114 HookQuery *hook_query;
115
116 /* Completion callback */
117 void (*complete)(DnsQuery* q);
118
119 sd_bus_track *bus_track;
120
121 LIST_FIELDS(DnsQuery, queries);
122 LIST_FIELDS(DnsQuery, auxiliary_queries);
123
124 /* Note: fields should be ordered to minimize alignment gaps. Use pahole! */
125 } DnsQuery;
126
127 enum {
128 DNS_QUERY_MATCH,
129 DNS_QUERY_NOMATCH,
130 DNS_QUERY_CNAME,
131 };
132
133 DECLARE_TRIVIAL_REF_UNREF_FUNC(DnsQueryCandidate, dns_query_candidate);
134 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQueryCandidate*, dns_query_candidate_unref);
135
136 void dns_query_candidate_notify(DnsQueryCandidate *c);
137
138 int dns_query_new(Manager *m, DnsQuery **ret, DnsQuestion *question_utf8, DnsQuestion *question_idna, DnsPacket *question_bypass, int ifindex, uint64_t flags);
139 DnsQuery *dns_query_free(DnsQuery *q);
140
141 int dns_query_make_auxiliary(DnsQuery *q, DnsQuery *auxiliary_for);
142
143 int dns_query_go(DnsQuery *q);
144 void dns_query_ready(DnsQuery *q);
145
146 int dns_query_process_cname_one(DnsQuery *q);
147 int dns_query_process_cname_many(DnsQuery *q);
148
149 void dns_query_complete(DnsQuery *q, DnsTransactionState state);
150
151 DnsQuestion* dns_query_question_for_protocol(DnsQuery *q, DnsProtocol protocol);
152
153 const char* dns_query_string(DnsQuery *q);
154
155 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);
156
157 bool dns_query_fully_authenticated(DnsQuery *q);
158 bool dns_query_fully_confidential(DnsQuery *q);
159 bool dns_query_fully_authoritative(DnsQuery *q);
160
161 int validate_and_mangle_query_flags(Manager *manager, uint64_t *flags, const char *name, uint64_t ok);
162
163 uint64_t dns_query_reply_flags_make(DnsQuery *q);