]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-transaction.h
portabled: implement container host os-release interface
[thirdparty/systemd.git] / src / resolve / resolved-dns-transaction.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "sd-event.h"
5
6 typedef struct DnsTransaction DnsTransaction;
7 typedef enum DnsTransactionState DnsTransactionState;
8 typedef enum DnsTransactionSource DnsTransactionSource;
9
10 #include "resolved-dns-answer.h"
11 #include "resolved-dns-dnssec.h"
12 #include "resolved-dns-packet.h"
13 #include "resolved-dns-question.h"
14 #include "resolved-dns-server.h"
15
16 enum DnsTransactionState {
17 DNS_TRANSACTION_NULL,
18 DNS_TRANSACTION_PENDING,
19 DNS_TRANSACTION_VALIDATING,
20 DNS_TRANSACTION_RCODE_FAILURE,
21 DNS_TRANSACTION_SUCCESS,
22 DNS_TRANSACTION_NO_SERVERS,
23 DNS_TRANSACTION_TIMEOUT,
24 DNS_TRANSACTION_ATTEMPTS_MAX_REACHED,
25 DNS_TRANSACTION_INVALID_REPLY,
26 DNS_TRANSACTION_ERRNO,
27 DNS_TRANSACTION_ABORTED,
28 DNS_TRANSACTION_DNSSEC_FAILED,
29 DNS_TRANSACTION_NO_TRUST_ANCHOR,
30 DNS_TRANSACTION_RR_TYPE_UNSUPPORTED,
31 DNS_TRANSACTION_NETWORK_DOWN,
32 DNS_TRANSACTION_NOT_FOUND, /* like NXDOMAIN, but when LLMNR/TCP connections fail */
33 _DNS_TRANSACTION_STATE_MAX,
34 _DNS_TRANSACTION_STATE_INVALID = -1
35 };
36
37 #define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
38
39 enum DnsTransactionSource {
40 DNS_TRANSACTION_NETWORK,
41 DNS_TRANSACTION_CACHE,
42 DNS_TRANSACTION_ZONE,
43 DNS_TRANSACTION_TRUST_ANCHOR,
44 _DNS_TRANSACTION_SOURCE_MAX,
45 _DNS_TRANSACTION_SOURCE_INVALID = -1
46 };
47
48 struct DnsTransaction {
49 DnsScope *scope;
50
51 DnsResourceKey *key;
52
53 DnsTransactionState state;
54
55 uint16_t id;
56
57 bool tried_stream:1;
58
59 bool initial_jitter_scheduled:1;
60 bool initial_jitter_elapsed:1;
61
62 bool clamp_ttl:1;
63
64 bool probing:1;
65
66 DnsPacket *sent, *received;
67
68 DnsAnswer *answer;
69 int answer_rcode;
70 DnssecResult answer_dnssec_result;
71 DnsTransactionSource answer_source;
72 uint32_t answer_nsec_ttl;
73 int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
74
75 /* Indicates whether the primary answer is authenticated,
76 * i.e. whether the RRs from answer which directly match the
77 * question are authenticated, or, if there are none, whether
78 * the NODATA or NXDOMAIN case is. It says nothing about
79 * additional RRs listed in the answer, however they have
80 * their own DNS_ANSWER_AUTHORIZED FLAGS. Note that this bit
81 * is defined different than the AD bit in DNS packets, as
82 * that covers more than just the actual primary answer. */
83 bool answer_authenticated;
84
85 /* Contains DNSKEY, DS, SOA RRs we already verified and need
86 * to authenticate this reply */
87 DnsAnswer *validated_keys;
88
89 usec_t start_usec;
90 usec_t next_attempt_after;
91 sd_event_source *timeout_event_source;
92 unsigned n_attempts;
93
94 unsigned n_picked_servers;
95
96 /* UDP connection logic, if we need it */
97 int dns_udp_fd;
98 sd_event_source *dns_udp_event_source;
99
100 /* TCP connection logic, if we need it */
101 DnsStream *stream;
102
103 /* The active server */
104 DnsServer *server;
105
106 /* The features of the DNS server at time of transaction start */
107 DnsServerFeatureLevel current_feature_level;
108
109 /* If we got SERVFAIL back, we retry the lookup, using a lower feature level than we used before. */
110 DnsServerFeatureLevel clamp_feature_level;
111
112 /* Query candidates this transaction is referenced by and that
113 * shall be notified about this specific transaction
114 * completing. */
115 Set *notify_query_candidates, *notify_query_candidates_done;
116
117 /* Zone items this transaction is referenced by and that shall
118 * be notified about completion. */
119 Set *notify_zone_items, *notify_zone_items_done;
120
121 /* Other transactions that this transactions is referenced by
122 * and that shall be notified about completion. This is used
123 * when transactions want to validate their RRsets, but need
124 * another DNSKEY or DS RR to do so. */
125 Set *notify_transactions, *notify_transactions_done;
126
127 /* The opposite direction: the transactions this transaction
128 * created in order to request DNSKEY or DS RRs. */
129 Set *dnssec_transactions;
130
131 unsigned block_gc;
132
133 LIST_FIELDS(DnsTransaction, transactions_by_scope);
134 LIST_FIELDS(DnsTransaction, transactions_by_stream);
135 };
136
137 int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
138 DnsTransaction* dns_transaction_free(DnsTransaction *t);
139
140 bool dns_transaction_gc(DnsTransaction *t);
141 int dns_transaction_go(DnsTransaction *t);
142
143 void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
144 void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
145
146 void dns_transaction_notify(DnsTransaction *t, DnsTransaction *source);
147 int dns_transaction_validate_dnssec(DnsTransaction *t);
148 int dns_transaction_request_dnssec_keys(DnsTransaction *t);
149
150 const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
151 DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
152
153 const char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
154 DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
155
156 /* LLMNR Jitter interval, see RFC 4795 Section 7 */
157 #define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
158
159 /* mDNS Jitter interval, see RFC 6762 Section 5.2 */
160 #define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
161 #define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
162
163 /* mDNS probing interval, see RFC 6762 Section 8.1 */
164 #define MDNS_PROBING_INTERVAL_USEC (250 * USEC_PER_MSEC)
165
166 /* Maximum attempts to send DNS requests, across all DNS servers */
167 #define DNS_TRANSACTION_ATTEMPTS_MAX 24
168
169 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
170 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
171
172 /* Maximum attempts to send MDNS requests, see RFC 6762 Section 8.1 */
173 #define MDNS_TRANSACTION_ATTEMPTS_MAX 3
174
175 #define TRANSACTION_ATTEMPTS_MAX(p) (((p) == DNS_PROTOCOL_LLMNR) ? \
176 LLMNR_TRANSACTION_ATTEMPTS_MAX : \
177 (((p) == DNS_PROTOCOL_MDNS) ? \
178 MDNS_TRANSACTION_ATTEMPTS_MAX : \
179 DNS_TRANSACTION_ATTEMPTS_MAX))