]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-query.h
dns-query: export CNAME_MAX, so that we can use it in other files, too
[thirdparty/systemd.git] / src / resolve / resolved-dns-query.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
74b2466e
LP
2#pragma once
3
74b2466e 4#include "sd-bus.h"
71d35b6b 5
faa133f3 6#include "set.h"
9581bb84 7#include "varlink.h"
74b2466e 8
801ad6a6 9typedef struct DnsQueryCandidate DnsQueryCandidate;
74b2466e 10typedef struct DnsQuery DnsQuery;
0354029b 11typedef struct DnsStubListenerExtra DnsStubListenerExtra;
74b2466e 12
faa133f3 13#include "resolved-dns-answer.h"
71d35b6b 14#include "resolved-dns-question.h"
801ad6a6 15#include "resolved-dns-search-domain.h"
be28f72d 16#include "resolved-dns-transaction.h"
801ad6a6
LP
17
18struct DnsQueryCandidate {
0e0fd08f
ZJS
19 unsigned n_ref;
20 int error_code;
21
801ad6a6
LP
22 DnsQuery *query;
23 DnsScope *scope;
24
25 DnsSearchDomain *search_domain;
26
801ad6a6
LP
27 Set *transactions;
28
29 LIST_FIELDS(DnsQueryCandidate, candidates_by_query);
30 LIST_FIELDS(DnsQueryCandidate, candidates_by_scope);
31};
74b2466e
LP
32
33struct DnsQuery {
34 Manager *manager;
45ec7efb 35
c805014a
ZJS
36 /* When resolving a service, we first create a TXT+SRV query, and then for the hostnames we discover
37 * auxiliary A+AAAA queries. This pointer always points from the auxiliary queries back to the
38 * TXT+SRV query. */
45ec7efb
LP
39 DnsQuery *auxiliary_for;
40 LIST_HEAD(DnsQuery, auxiliary_queries);
41 unsigned n_auxiliary_queries;
42 int auxiliary_result;
43
c805014a
ZJS
44 /* The question, formatted in IDNA for use on classic DNS, and as UTF8 for use in LLMNR or mDNS. Note
45 * that even on classic DNS some labels might use UTF8 encoding. Specifically, DNS-SD service names
46 * (in contrast to their domain suffixes) use UTF-8 encoding even on DNS. Thus, the difference
47 * between these two fields is mostly relevant only for explicit *hostname* lookups as well as the
48 * domain suffixes of service lookups. */
23b298bc
LP
49 DnsQuestion *question_idna;
50 DnsQuestion *question_utf8;
51
775ae354
LP
52 /* If this is not a question by ourselves, but a "bypass" request, we propagate the original packet
53 * here, and use that instead. */
54 DnsPacket *question_bypass;
55
51323288
LP
56 uint64_t flags;
57 int ifindex;
58
ec2c5e43 59 DnsTransactionState state;
faa133f3 60 unsigned n_cname_redirects;
74b2466e 61
801ad6a6 62 LIST_HEAD(DnsQueryCandidate, candidates);
74b2466e
LP
63 sd_event_source *timeout_event_source;
64
322345fd 65 /* Discovered data */
faa133f3 66 DnsAnswer *answer;
faa133f3 67 int answer_rcode;
019036a4 68 DnssecResult answer_dnssec_result;
6f055e43 69 uint64_t answer_query_flags;
ae6a4bbf
LP
70 DnsProtocol answer_protocol;
71 int answer_family;
801ad6a6 72 DnsSearchDomain *answer_search_domain;
7cc6ed7b 73 int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
28830a64 74 bool previous_redirect_unauthenticated;
43fc4baa 75 bool previous_redirect_non_confidential;
775ae354 76 DnsPacket *answer_full_packet;
74b2466e 77
9581bb84 78 /* Bus + Varlink client information */
c9de4e0f 79 sd_bus_message *bus_request;
9581bb84 80 Varlink *varlink_request;
0dd25fb9 81 int request_family;
45ec7efb 82 bool request_address_valid;
74b2466e 83 union in_addr_union request_address;
45ec7efb 84 unsigned block_all_complete;
23b298bc 85 char *request_address_string;
74b2466e 86
b30bf55d 87 /* DNS stub information */
775ae354
LP
88 DnsPacket *request_packet;
89 DnsStream *request_stream;
90 DnsAnswer *reply_answer;
91 DnsAnswer *reply_authoritative;
92 DnsAnswer *reply_additional;
0354029b 93 DnsStubListenerExtra *stub_listener_extra;
b30bf55d 94
322345fd 95 /* Completion callback */
74b2466e 96 void (*complete)(DnsQuery* q);
faa133f3
LP
97 unsigned block_ready;
98
82bd6ddd
LP
99 sd_bus_track *bus_track;
100
74b2466e 101 LIST_FIELDS(DnsQuery, queries);
45ec7efb 102 LIST_FIELDS(DnsQuery, auxiliary_queries);
74b2466e
LP
103};
104
7588460a
TG
105enum {
106 DNS_QUERY_MATCH,
107 DNS_QUERY_NOMATCH,
108 DNS_QUERY_RESTARTED,
109};
110
0e0fd08f
ZJS
111DnsQueryCandidate* dns_query_candidate_ref(DnsQueryCandidate*);
112DnsQueryCandidate* dns_query_candidate_unref(DnsQueryCandidate*);
113DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQueryCandidate*, dns_query_candidate_unref);
7877e5ca 114
547973de 115void dns_query_candidate_notify(DnsQueryCandidate *c);
801ad6a6 116
775ae354 117int dns_query_new(Manager *m, DnsQuery **q, DnsQuestion *question_utf8, DnsQuestion *question_idna, DnsPacket *question_bypass, int family, uint64_t flags);
74b2466e 118DnsQuery *dns_query_free(DnsQuery *q);
322345fd 119
45ec7efb
LP
120int dns_query_make_auxiliary(DnsQuery *q, DnsQuery *auxiliary_for);
121
322345fd 122int dns_query_go(DnsQuery *q);
faa133f3 123void dns_query_ready(DnsQuery *q);
74b2466e 124
45ec7efb 125int dns_query_process_cname(DnsQuery *q);
74b2466e 126
65a01e82 127void dns_query_complete(DnsQuery *q, DnsTransactionState state);
82bd6ddd 128
23b298bc
LP
129DnsQuestion* dns_query_question_for_protocol(DnsQuery *q, DnsProtocol protocol);
130
131const char *dns_query_string(DnsQuery *q);
132
74b2466e 133DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free);
28830a64
LP
134
135bool dns_query_fully_authenticated(DnsQuery *q);
43fc4baa 136bool dns_query_fully_confidential(DnsQuery *q);
4ad017cd 137bool dns_query_fully_synthetic(DnsQuery *q);
43fc4baa
LP
138
139static inline uint64_t dns_query_reply_flags_make(DnsQuery *q) {
140 assert(q);
141
142 return SD_RESOLVED_FLAGS_MAKE(q->answer_protocol,
143 q->answer_family,
144 dns_query_fully_authenticated(q),
5c1790d1
LP
145 dns_query_fully_confidential(q)) |
146 (q->answer_query_flags & (SD_RESOLVED_FROM_MASK|SD_RESOLVED_SYNTHETIC));
43fc4baa 147}
e0ae456a
LP
148
149#define CNAME_REDIRECT_MAX 16