]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-transaction.h
resolved: implement LLMNR uniqueness verification
[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
27 enum DnsTransactionState {
28 DNS_TRANSACTION_NULL,
29 DNS_TRANSACTION_PENDING,
30 DNS_TRANSACTION_FAILURE,
31 DNS_TRANSACTION_SUCCESS,
32 DNS_TRANSACTION_NO_SERVERS,
33 DNS_TRANSACTION_TIMEOUT,
34 DNS_TRANSACTION_ATTEMPTS_MAX_REACHED,
35 DNS_TRANSACTION_INVALID_REPLY,
36 DNS_TRANSACTION_RESOURCES,
37 DNS_TRANSACTION_ABORTED,
38 _DNS_TRANSACTION_STATE_MAX,
39 _DNS_TRANSACTION_STATE_INVALID = -1
40 };
41
42 #include "resolved-dns-scope.h"
43 #include "resolved-dns-rr.h"
44 #include "resolved-dns-packet.h"
45 #include "resolved-dns-question.h"
46 #include "resolved-dns-answer.h"
47 #include "resolved-dns-stream.h"
48
49 struct DnsTransaction {
50 DnsScope *scope;
51
52 DnsQuestion *question;
53
54 DnsTransactionState state;
55 uint16_t id;
56
57 DnsPacket *sent, *received;
58 DnsAnswer *cached;
59 int cached_rcode;
60
61 sd_event_source *timeout_event_source;
62 unsigned n_attempts;
63
64 /* TCP connection logic, if we need it */
65 DnsStream *stream;
66
67 /* Queries this transaction is referenced by and that shall be
68 * notified about this specific transaction completing. */
69 Set *queries;
70
71 /* Zone items this transaction is referenced by and that shall
72 * be notified about completion. */
73 Set *zone_items;
74
75 unsigned block_gc;
76
77 LIST_FIELDS(DnsTransaction, transactions_by_scope);
78 };
79
80 int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsQuestion *q);
81 DnsTransaction* dns_transaction_free(DnsTransaction *t);
82
83 void dns_transaction_gc(DnsTransaction *t);
84 int dns_transaction_go(DnsTransaction *t);
85
86 void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p);
87 void dns_transaction_complete(DnsTransaction *t, DnsTransactionState state);
88
89 const char* dns_transaction_state_to_string(DnsTransactionState p) _const_;
90 DnsTransactionState dns_transaction_state_from_string(const char *s) _pure_;
91
92 /* After how much time to repeat classic DNS requests */
93 #define DNS_TRANSACTION_TIMEOUT_USEC (5 * USEC_PER_SEC)
94
95 /* After how much time to repeat LLMNR requests, see RFC 4795 Section 7 */
96 #define LLMNR_TRANSACTION_TIMEOUT_USEC (1 * USEC_PER_SEC)
97
98 /* LLMNR Jitter interval, see RFC 4795 Section 7 */
99 #define LLMNR_TRANSACTION_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
100
101 /* Maximum attempts to send DNS requests, across all DNS servers */
102 #define DNS_TRANSACTION_ATTEMPTS_MAX 8
103
104 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
105 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
106
107 #define TRANSACTION_TIMEOUT_USEC(p) (p == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_TIMEOUT_USEC : DNS_TRANSACTION_TIMEOUT_USEC)
108 #define TRANSACTION_ATTEMPTS_MAX(p) (p == DNS_PROTOCOL_LLMNR ? LLMNR_TRANSACTION_ATTEMPTS_MAX : DNS_TRANSACTION_ATTEMPTS_MAX)