]>
Commit | Line | Data |
---|---|---|
74b2466e LP |
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 | #include <inttypes.h> | |
25 | ||
26 | #include "sd-bus.h" | |
27 | #include "util.h" | |
faa133f3 | 28 | #include "set.h" |
74b2466e LP |
29 | |
30 | typedef struct DnsQuery DnsQuery; | |
31 | typedef struct DnsQueryTransaction DnsQueryTransaction; | |
32 | ||
33 | #include "resolved.h" | |
34 | #include "resolved-dns-scope.h" | |
35 | #include "resolved-dns-rr.h" | |
36 | #include "resolved-dns-packet.h" | |
faa133f3 LP |
37 | #include "resolved-dns-question.h" |
38 | #include "resolved-dns-answer.h" | |
74b2466e LP |
39 | |
40 | typedef enum DnsQueryState { | |
41 | DNS_QUERY_NULL, | |
8ba9fd9c | 42 | DNS_QUERY_PENDING, |
74b2466e LP |
43 | DNS_QUERY_FAILURE, |
44 | DNS_QUERY_SUCCESS, | |
ad867662 | 45 | DNS_QUERY_NO_SERVERS, |
74b2466e LP |
46 | DNS_QUERY_TIMEOUT, |
47 | DNS_QUERY_ATTEMPTS_MAX, | |
48 | DNS_QUERY_INVALID_REPLY, | |
faa133f3 LP |
49 | DNS_QUERY_RESOURCES, |
50 | DNS_QUERY_ABORTED, | |
74b2466e LP |
51 | } DnsQueryState; |
52 | ||
53 | struct DnsQueryTransaction { | |
74b2466e LP |
54 | DnsScope *scope; |
55 | ||
faa133f3 LP |
56 | DnsQuestion *question; |
57 | ||
74b2466e LP |
58 | DnsQueryState state; |
59 | uint16_t id; | |
60 | ||
faa133f3 LP |
61 | DnsPacket *sent, *received; |
62 | DnsAnswer *cached; | |
7e8e0422 | 63 | int cached_rcode; |
faa133f3 | 64 | |
74b2466e LP |
65 | sd_event_source *timeout_event_source; |
66 | unsigned n_attempts; | |
67 | ||
ad867662 LP |
68 | /* TCP connection logic */ |
69 | int tcp_fd; | |
70 | sd_event_source *tcp_event_source; | |
71 | size_t tcp_written, tcp_read; | |
72 | be16_t tcp_read_size; | |
74b2466e | 73 | |
faa133f3 LP |
74 | /* Queries this transaction is referenced by and that shall by |
75 | * notified about this specific transaction completing. */ | |
76 | Set *queries; | |
77 | ||
78 | unsigned block_gc; | |
322345fd | 79 | |
74b2466e LP |
80 | LIST_FIELDS(DnsQueryTransaction, transactions_by_scope); |
81 | }; | |
82 | ||
83 | struct DnsQuery { | |
84 | Manager *manager; | |
faa133f3 | 85 | DnsQuestion *question; |
74b2466e LP |
86 | |
87 | DnsQueryState state; | |
faa133f3 | 88 | unsigned n_cname_redirects; |
74b2466e LP |
89 | |
90 | sd_event_source *timeout_event_source; | |
91 | ||
322345fd | 92 | /* Discovered data */ |
faa133f3 LP |
93 | DnsAnswer *answer; |
94 | int answer_ifindex; | |
95 | int answer_rcode; | |
74b2466e | 96 | |
8ba9fd9c | 97 | /* Bus client information */ |
74b2466e | 98 | sd_bus_message *request; |
0dd25fb9 | 99 | int request_family; |
74b2466e LP |
100 | const char *request_hostname; |
101 | union in_addr_union request_address; | |
102 | ||
322345fd | 103 | /* Completion callback */ |
74b2466e | 104 | void (*complete)(DnsQuery* q); |
faa133f3 LP |
105 | unsigned block_ready; |
106 | ||
107 | Set *transactions; | |
74b2466e | 108 | |
74b2466e LP |
109 | LIST_FIELDS(DnsQuery, queries); |
110 | }; | |
111 | ||
322345fd | 112 | DnsQueryTransaction* dns_query_transaction_free(DnsQueryTransaction *t); |
faa133f3 LP |
113 | void dns_query_transaction_complete(DnsQueryTransaction *t, DnsQueryState state); |
114 | ||
115 | void dns_query_transaction_process_reply(DnsQueryTransaction *t, DnsPacket *p); | |
322345fd | 116 | |
faa133f3 | 117 | int dns_query_new(Manager *m, DnsQuery **q, DnsQuestion *question); |
74b2466e | 118 | DnsQuery *dns_query_free(DnsQuery *q); |
322345fd LP |
119 | |
120 | int dns_query_go(DnsQuery *q); | |
faa133f3 | 121 | void dns_query_ready(DnsQuery *q); |
74b2466e | 122 | |
faa133f3 | 123 | int dns_query_cname_redirect(DnsQuery *q, const char *name); |
74b2466e LP |
124 | |
125 | DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free); |