]>
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 | ||
3c0cf502 LP |
24 | #include "in-addr-util.h" |
25 | ||
74b2466e | 26 | typedef struct DnsServer DnsServer; |
74b2466e | 27 | |
4e945a6f LP |
28 | typedef enum DnsServerType { |
29 | DNS_SERVER_SYSTEM, | |
30 | DNS_SERVER_FALLBACK, | |
31 | DNS_SERVER_LINK, | |
32 | } DnsServerType; | |
33 | ||
be808ea0 TG |
34 | typedef enum DnsServerFeatureLevel { |
35 | DNS_SERVER_FEATURE_LEVEL_TCP, | |
36 | DNS_SERVER_FEATURE_LEVEL_UDP, | |
9c5e12a4 | 37 | DNS_SERVER_FEATURE_LEVEL_EDNS0, |
7586f4d1 | 38 | DNS_SERVER_FEATURE_LEVEL_DO, |
be808ea0 TG |
39 | _DNS_SERVER_FEATURE_LEVEL_MAX, |
40 | _DNS_SERVER_FEATURE_LEVEL_INVALID = -1 | |
41 | } DnsServerFeatureLevel; | |
42 | ||
43 | #define DNS_SERVER_FEATURE_LEVEL_WORST 0 | |
44 | #define DNS_SERVER_FEATURE_LEVEL_BEST (_DNS_SERVER_FEATURE_LEVEL_MAX - 1) | |
45 | ||
46 | const char* dns_server_feature_level_to_string(int i) _const_; | |
47 | int dns_server_feature_level_from_string(const char *s) _pure_; | |
48 | ||
3e684349 | 49 | #include "resolved-link.h" |
be808ea0 | 50 | #include "resolved-manager.h" |
3e684349 | 51 | |
74b2466e LP |
52 | struct DnsServer { |
53 | Manager *manager; | |
74b2466e | 54 | |
91b14d6f TG |
55 | unsigned n_ref; |
56 | ||
4e945a6f | 57 | DnsServerType type; |
3c0cf502 LP |
58 | Link *link; |
59 | ||
0dd25fb9 | 60 | int family; |
74b2466e LP |
61 | union in_addr_union address; |
62 | ||
9df3ba6c TG |
63 | usec_t resend_timeout; |
64 | usec_t max_rtt; | |
65 | ||
3c0cf502 | 66 | bool marked:1; |
be808ea0 TG |
67 | DnsServerFeatureLevel verified_features; |
68 | DnsServerFeatureLevel possible_features; | |
69 | unsigned n_failed_attempts; | |
70 | usec_t verified_usec; | |
71 | usec_t features_grace_period_usec; | |
74b2466e | 72 | |
0eac4623 LP |
73 | /* If linked is set, then this server appears in the servers linked list */ |
74 | bool linked:1; | |
74b2466e LP |
75 | LIST_FIELDS(DnsServer, servers); |
76 | }; | |
77 | ||
78 | int dns_server_new( | |
79 | Manager *m, | |
0b58db65 | 80 | DnsServer **ret, |
4e945a6f | 81 | DnsServerType type, |
0b58db65 | 82 | Link *link, |
0dd25fb9 | 83 | int family, |
3c0cf502 | 84 | const union in_addr_union *address); |
74b2466e | 85 | |
91b14d6f TG |
86 | DnsServer* dns_server_ref(DnsServer *s); |
87 | DnsServer* dns_server_unref(DnsServer *s); | |
87f5a193 | 88 | |
0eac4623 | 89 | void dns_server_unlink(DnsServer *s); |
0b58db65 | 90 | void dns_server_move_back_and_unmark(DnsServer *s); |
0eac4623 | 91 | |
be808ea0 TG |
92 | void dns_server_packet_received(DnsServer *s, DnsServerFeatureLevel features, usec_t rtt); |
93 | void dns_server_packet_lost(DnsServer *s, DnsServerFeatureLevel features, usec_t usec); | |
4e0b8b17 | 94 | void dns_server_packet_failed(DnsServer *s, DnsServerFeatureLevel features); |
9df3ba6c | 95 | |
4b95f179 LP |
96 | DnsServer *dns_server_find(DnsServer *first, int family, const union in_addr_union *in_addr); |
97 | ||
98 | void dns_server_unlink_all(DnsServer *first); | |
99 | void dns_server_unlink_marked(DnsServer *first); | |
100 | void dns_server_mark_all(DnsServer *first); | |
f2f1dbe5 | 101 | |
4b95f179 | 102 | DnsServer *manager_get_first_dns_server(Manager *m, DnsServerType t); |
636e813d | 103 | |
0eac4623 | 104 | DnsServer *manager_set_dns_server(Manager *m, DnsServer *s); |
0eac4623 LP |
105 | DnsServer *manager_get_dns_server(Manager *m); |
106 | void manager_next_dns_server(Manager *m); | |
107 | ||
8300ba21 TG |
108 | DEFINE_TRIVIAL_CLEANUP_FUNC(DnsServer*, dns_server_unref); |
109 | ||
be808ea0 TG |
110 | DnsServerFeatureLevel dns_server_possible_features(DnsServer *s); |
111 | ||
d5099efc | 112 | extern const struct hash_ops dns_server_hash_ops; |