]>
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" | |
28 | ||
29 | typedef struct DnsQuery DnsQuery; | |
30 | typedef struct DnsQueryTransaction DnsQueryTransaction; | |
31 | ||
32 | #include "resolved.h" | |
33 | #include "resolved-dns-scope.h" | |
34 | #include "resolved-dns-rr.h" | |
35 | #include "resolved-dns-packet.h" | |
36 | ||
37 | typedef enum DnsQueryState { | |
38 | DNS_QUERY_NULL, | |
39 | DNS_QUERY_SENT, | |
40 | DNS_QUERY_FAILURE, | |
41 | DNS_QUERY_SUCCESS, | |
42 | DNS_QUERY_SKIPPED, | |
43 | DNS_QUERY_TIMEOUT, | |
44 | DNS_QUERY_ATTEMPTS_MAX, | |
45 | DNS_QUERY_INVALID_REPLY, | |
46 | } DnsQueryState; | |
47 | ||
48 | struct DnsQueryTransaction { | |
49 | DnsQuery *query; | |
50 | DnsScope *scope; | |
51 | ||
52 | DnsQueryState state; | |
53 | uint16_t id; | |
54 | ||
55 | sd_event_source *timeout_event_source; | |
56 | unsigned n_attempts; | |
57 | ||
58 | DnsPacket *packet; | |
59 | ||
60 | LIST_FIELDS(DnsQueryTransaction, transactions_by_query); | |
61 | LIST_FIELDS(DnsQueryTransaction, transactions_by_scope); | |
62 | }; | |
63 | ||
64 | struct DnsQuery { | |
65 | Manager *manager; | |
66 | ||
67 | DnsResourceKey *keys; | |
68 | unsigned n_keys; | |
69 | ||
70 | DnsQueryState state; | |
71 | ||
72 | sd_event_source *timeout_event_source; | |
73 | ||
74 | uint16_t rcode; | |
75 | DnsPacket *packet; | |
76 | ||
77 | sd_bus_message *request; | |
78 | unsigned char request_family; | |
79 | const char *request_hostname; | |
80 | union in_addr_union request_address; | |
81 | ||
82 | void (*complete)(DnsQuery* q); | |
83 | ||
84 | LIST_HEAD(DnsQueryTransaction, transactions); | |
85 | LIST_FIELDS(DnsQuery, queries); | |
86 | }; | |
87 | ||
88 | int dns_query_new(Manager *m, DnsQuery **q, DnsResourceKey *keys, unsigned n_keys); | |
89 | DnsQuery *dns_query_free(DnsQuery *q); | |
90 | int dns_query_start(DnsQuery *q); | |
91 | void dns_query_finish(DnsQuery *q); | |
92 | ||
93 | DnsQueryTransaction* dns_query_transaction_free(DnsQueryTransaction *t); | |
94 | int dns_query_transaction_start(DnsQueryTransaction *t); | |
95 | int dns_query_transaction_reply(DnsQueryTransaction *t, DnsPacket *p); | |
96 | ||
97 | DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuery*, dns_query_free); |