1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 typedef struct DnsTransaction DnsTransaction
;
7 typedef enum DnsTransactionState DnsTransactionState
;
8 typedef enum DnsTransactionSource DnsTransactionSource
;
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"
16 enum DnsTransactionState
{
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
37 #define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
39 enum DnsTransactionSource
{
40 DNS_TRANSACTION_NETWORK
,
41 DNS_TRANSACTION_CACHE
,
43 DNS_TRANSACTION_TRUST_ANCHOR
,
44 _DNS_TRANSACTION_SOURCE_MAX
,
45 _DNS_TRANSACTION_SOURCE_INVALID
= -1
48 struct DnsTransaction
{
53 DnsTransactionState state
;
59 bool initial_jitter_scheduled
:1;
60 bool initial_jitter_elapsed
:1;
66 DnsPacket
*sent
, *received
;
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 */
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
;
85 /* Contains DNSKEY, DS, SOA RRs we already verified and need
86 * to authenticate this reply */
87 DnsAnswer
*validated_keys
;
90 usec_t next_attempt_after
;
91 sd_event_source
*timeout_event_source
;
94 unsigned n_picked_servers
;
96 /* UDP connection logic, if we need it */
98 sd_event_source
*dns_udp_event_source
;
100 /* TCP connection logic, if we need it */
103 /* The active server */
106 /* The features of the DNS server at time of transaction start */
107 DnsServerFeatureLevel current_feature_level
;
109 /* If we got SERVFAIL back, we retry the lookup, using a lower feature level than we used before. */
110 DnsServerFeatureLevel clamp_feature_level
;
112 /* Query candidates this transaction is referenced by and that
113 * shall be notified about this specific transaction
115 Set
*notify_query_candidates
, *notify_query_candidates_done
;
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
;
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
;
127 /* The opposite direction: the transactions this transaction
128 * created in order to request DNSKEY or DS RRs. */
129 Set
*dnssec_transactions
;
133 LIST_FIELDS(DnsTransaction
, transactions_by_scope
);
134 LIST_FIELDS(DnsTransaction
, transactions_by_stream
);
137 int dns_transaction_new(DnsTransaction
**ret
, DnsScope
*s
, DnsResourceKey
*key
);
138 DnsTransaction
* dns_transaction_free(DnsTransaction
*t
);
140 bool dns_transaction_gc(DnsTransaction
*t
);
141 int dns_transaction_go(DnsTransaction
*t
);
143 void dns_transaction_process_reply(DnsTransaction
*t
, DnsPacket
*p
);
144 void dns_transaction_complete(DnsTransaction
*t
, DnsTransactionState state
);
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
);
150 const char* dns_transaction_state_to_string(DnsTransactionState p
) _const_
;
151 DnsTransactionState
dns_transaction_state_from_string(const char *s
) _pure_
;
153 const char* dns_transaction_source_to_string(DnsTransactionSource p
) _const_
;
154 DnsTransactionSource
dns_transaction_source_from_string(const char *s
) _pure_
;
156 /* LLMNR Jitter interval, see RFC 4795 Section 7 */
157 #define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
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)
163 /* mDNS probing interval, see RFC 6762 Section 8.1 */
164 #define MDNS_PROBING_INTERVAL_USEC (250 * USEC_PER_MSEC)
166 /* Maximum attempts to send DNS requests, across all DNS servers */
167 #define DNS_TRANSACTION_ATTEMPTS_MAX 24
169 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
170 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
172 /* Maximum attempts to send MDNS requests, see RFC 6762 Section 8.1 */
173 #define MDNS_TRANSACTION_ATTEMPTS_MAX 3
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))