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