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