]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-transaction.h
Merge pull request #2092 from poettering/dnssec2
[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_FAILURE,
32 DNS_TRANSACTION_SUCCESS,
33 DNS_TRANSACTION_NO_SERVERS,
34 DNS_TRANSACTION_TIMEOUT,
35 DNS_TRANSACTION_ATTEMPTS_MAX_REACHED,
36 DNS_TRANSACTION_INVALID_REPLY,
37 DNS_TRANSACTION_RESOURCES,
38 DNS_TRANSACTION_ABORTED,
39 _DNS_TRANSACTION_STATE_MAX,
40 _DNS_TRANSACTION_STATE_INVALID = -1
41 };
42
43 enum DnsTransactionSource {
44 DNS_TRANSACTION_NETWORK,
45 DNS_TRANSACTION_CACHE,
46 DNS_TRANSACTION_ZONE,
47 DNS_TRANSACTION_TRUST_ANCHOR,
48 _DNS_TRANSACTION_SOURCE_MAX,
49 _DNS_TRANSACTION_SOURCE_INVALID = -1
50 };
51
52 #include "resolved-dns-answer.h"
53 #include "resolved-dns-packet.h"
54 #include "resolved-dns-question.h"
55 #include "resolved-dns-scope.h"
56
57 struct DnsTransaction {
58 DnsScope *scope;
59
60 DnsResourceKey *key;
61
62 DnsTransactionState state;
63 uint16_t id;
64
65 bool initial_jitter;
66
67 DnsPacket *sent, *received;
68
69 DnsAnswer *answer;
70 int answer_rcode;
71 DnsTransactionSource answer_source;
72 bool answer_authenticated;
73
74 usec_t start_usec;
75 sd_event_source *timeout_event_source;
76 unsigned n_attempts;
77
78 int dns_udp_fd;
79 sd_event_source *dns_udp_event_source;
80
81 /* The active server */
82 DnsServer *server;
83
84 /* the features of the DNS server at time of transaction start */
85 DnsServerFeatureLevel current_features;
86
87 /* TCP connection logic, if we need it */
88 DnsStream *stream;
89
90 /* Query candidates this transaction is referenced by and that
91 * shall be notified about this specific transaction
92 * completing. */
93 Set *query_candidates;
94
95 /* Zone items this transaction is referenced by and that shall
96 * be notified about completion. */
97 Set *zone_items;
98
99 unsigned block_gc;
100
101 LIST_FIELDS(DnsTransaction, transactions_by_scope);
102 };
103
104 int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key);
105 DnsTransaction* dns_transaction_free(DnsTransaction *t);
106
107 void dns_transaction_gc(DnsTransaction *t);
108 int dns_transaction_go(DnsTransaction *t);
109
110 void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
111 void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
112
113 const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
114 DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
115
116 const char* dns_transaction_source_to_string(DnsTransactionSource p) _const_;
117 DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
118
119 /* LLMNR Jitter interval, see RFC 4795 Section 7 */
120 #define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
121
122 /* Maximum attempts to send DNS requests, across all DNS servers */
123 #define DNS_TRANSACTION_ATTEMPTS_MAX 16
124
125 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
126 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
127
128 #define TRANSACTION_ATTEMPTS_MAX(p) ((p) == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)