]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-transaction.h
resolved: explicitly handle case when the trust anchor is empty
[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_NO_TRUST_ANCHOR,
43 _DNS_TRANSACTION_STATE_MAX,
44 _DNS_TRANSACTION_STATE_INVALID = -1
45 };
46
47 #define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
48
49 enum DnsTransactionSource {
50 DNS_TRANSACTION_NETWORK,
51 DNS_TRANSACTION_CACHE,
52 DNS_TRANSACTION_ZONE,
53 DNS_TRANSACTION_TRUST_ANCHOR,
54 _DNS_TRANSACTION_SOURCE_MAX,
55 _DNS_TRANSACTION_SOURCE_INVALID = -1
56 };
57
58 #include "resolved-dns-answer.h"
59 #include "resolved-dns-packet.h"
60 #include "resolved-dns-question.h"
61 #include "resolved-dns-scope.h"
62
63 struct DnsTransaction {
64 DnsScope *scope;
65
66 DnsResourceKey *key;
67 char *key_string;
68
69 DnsTransactionState state;
70
71 uint16_t id;
72
73 bool tried_stream:1;
74
75 bool initial_jitter_scheduled:1;
76 bool initial_jitter_elapsed:1;
77
78 DnsPacket *sent, *received;
79
80 DnsAnswer *answer;
81 int answer_rcode;
82 DnssecResult answer_dnssec_result;
83 DnsTransactionSource answer_source;
84
85 /* Indicates whether the primary answer is authenticated,
86 * i.e. whether the RRs from answer which directly match the
87 * question are authenticated, or, if there are none, whether
88 * the NODATA or NXDOMAIN case is. It says nothing about
89 * additional RRs listed in the answer, however they have
90 * their own DNS_ANSWER_AUTHORIZED FLAGS. Note that this bit
91 * is defined different than the AD bit in DNS packets, as
92 * that covers more than just the actual primary answer. */
93 bool answer_authenticated;
94
95 /* Contains DNSKEY, DS, SOA RRs we already verified and need
96 * to authenticate this reply */
97 DnsAnswer *validated_keys;
98
99 usec_t start_usec;
100 usec_t next_attempt_after;
101 sd_event_source *timeout_event_source;
102 unsigned n_attempts;
103
104 /* UDP connection logic, if we need it */
105 int dns_udp_fd;
106 sd_event_source *dns_udp_event_source;
107
108 /* TCP connection logic, if we need it */
109 DnsStream *stream;
110
111 /* The active server */
112 DnsServer *server;
113
114 /* The features of the DNS server at time of transaction start */
115 DnsServerFeatureLevel current_features;
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;
121
122 /* Zone items this transaction is referenced by and that shall
123 * be notified about completion. */
124 Set *notify_zone_items;
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;
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_key_string(DnsTransaction *t);
155
156 const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
157 DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
158
159 const char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
160 DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
161
162 /* LLMNR Jitter interval, see RFC 4795 Section 7 */
163 #define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
164
165 /* mDNS Jitter interval, see RFC 6762 Section 5.2 */
166 #define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
167 #define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
168
169 /* Maximum attempts to send DNS requests, across all DNS servers */
170 #define DNS_TRANSACTION_ATTEMPTS_MAX 16
171
172 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
173 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
174
175 #define TRANSACTION_ATTEMPTS_MAX(p) ((p) == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)