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