]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-transaction.h
Merge pull request #2306 from walyong/exec_v01
[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_ERRNO,
39 DNS_TRANSACTION_ABORTED,
40 DNS_TRANSACTION_DNSSEC_FAILED,
41 DNS_TRANSACTION_NO_TRUST_ANCHOR,
42 DNS_TRANSACTION_RR_TYPE_UNSUPPORTED,
43 DNS_TRANSACTION_NETWORK_DOWN,
44 DNS_TRANSACTION_NOT_FOUND, /* like NXDOMAIN, but when LLMNR/TCP connections fail */
45 _DNS_TRANSACTION_STATE_MAX,
46 _DNS_TRANSACTION_STATE_INVALID = -1
47 };
48
49 #define DNS_TRANSACTION_IS_LIVE(state) IN_SET((state), DNS_TRANSACTION_NULL, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_VALIDATING)
50
51 enum DnsTransactionSource {
52 DNS_TRANSACTION_NETWORK,
53 DNS_TRANSACTION_CACHE,
54 DNS_TRANSACTION_ZONE,
55 DNS_TRANSACTION_TRUST_ANCHOR,
56 _DNS_TRANSACTION_SOURCE_MAX,
57 _DNS_TRANSACTION_SOURCE_INVALID = -1
58 };
59
60 #include "resolved-dns-answer.h"
61 #include "resolved-dns-packet.h"
62 #include "resolved-dns-question.h"
63 #include "resolved-dns-scope.h"
64
65 struct DnsTransaction {
66 DnsScope *scope;
67
68 DnsResourceKey *key;
69 char *key_string;
70
71 DnsTransactionState state;
72
73 uint16_t id;
74
75 bool tried_stream:1;
76
77 bool initial_jitter_scheduled:1;
78 bool initial_jitter_elapsed:1;
79
80 DnsPacket *sent, *received;
81
82 DnsAnswer *answer;
83 int answer_rcode;
84 DnssecResult answer_dnssec_result;
85 DnsTransactionSource answer_source;
86 uint32_t answer_nsec_ttl;
87 int answer_errno; /* if state is DNS_TRANSACTION_ERRNO */
88
89 /* Indicates whether the primary answer is authenticated,
90 * i.e. whether the RRs from answer which directly match the
91 * question are authenticated, or, if there are none, whether
92 * the NODATA or NXDOMAIN case is. It says nothing about
93 * additional RRs listed in the answer, however they have
94 * their own DNS_ANSWER_AUTHORIZED FLAGS. Note that this bit
95 * is defined different than the AD bit in DNS packets, as
96 * that covers more than just the actual primary answer. */
97 bool answer_authenticated;
98
99 /* Contains DNSKEY, DS, SOA RRs we already verified and need
100 * to authenticate this reply */
101 DnsAnswer *validated_keys;
102
103 usec_t start_usec;
104 usec_t next_attempt_after;
105 sd_event_source *timeout_event_source;
106 unsigned n_attempts;
107
108 /* UDP connection logic, if we need it */
109 int dns_udp_fd;
110 sd_event_source *dns_udp_event_source;
111
112 /* TCP connection logic, if we need it */
113 DnsStream *stream;
114
115 /* The active server */
116 DnsServer *server;
117
118 /* The features of the DNS server at time of transaction start */
119 DnsServerFeatureLevel current_feature_level;
120
121 /* Query candidates this transaction is referenced by and that
122 * shall be notified about this specific transaction
123 * completing. */
124 Set *notify_query_candidates;
125
126 /* Zone items this transaction is referenced by and that shall
127 * be notified about completion. */
128 Set *notify_zone_items;
129
130 /* Other transactions that this transactions is referenced by
131 * and that shall be notified about completion. This is used
132 * when transactions want to validate their RRsets, but need
133 * another DNSKEY or DS RR to do so. */
134 Set *notify_transactions;
135
136 /* The opposite direction: the transactions this transaction
137 * created in order to request DNSKEY or DS RRs. */
138 Set *dnssec_transactions;
139
140 unsigned block_gc;
141
142 LIST_FIELDS(DnsTransaction, transactions_by_scope);
143 };
144
145 int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
146 DnsTransaction* dns_transaction_free(DnsTransaction *t);
147
148 bool dns_transaction_gc(DnsTransaction *t);
149 int dns_transaction_go(DnsTransaction *t);
150
151 void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
152 void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
153
154 void dns_transaction_notify(DnsTransaction *t, DnsTransaction *source);
155 int dns_transaction_validate_dnssec(DnsTransaction *t);
156 int dns_transaction_request_dnssec_keys(DnsTransaction *t);
157
158 const char *dns_transaction_key_string(DnsTransaction *t);
159
160 const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
161 DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
162
163 const char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
164 DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
165
166 /* LLMNR Jitter interval, see RFC 4795 Section 7 */
167 #define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
168
169 /* mDNS Jitter interval, see RFC 6762 Section 5.2 */
170 #define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
171 #define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
172
173 /* Maximum attempts to send DNS requests, across all DNS servers */
174 #define DNS_TRANSACTION_ATTEMPTS_MAX 16
175
176 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
177 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
178
179 #define TRANSACTION_ATTEMPTS_MAX(p) ((p) == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)