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