]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
5eef597e MP |
2 | #pragma once |
3 | ||
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2014 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU Lesser General Public License as published by | |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | ||
23 | #include "in-addr-util.h" | |
24 | ||
25 | typedef struct DnsServer DnsServer; | |
5eef597e MP |
26 | |
27 | typedef enum DnsServerType { | |
28 | DNS_SERVER_SYSTEM, | |
29 | DNS_SERVER_FALLBACK, | |
30 | DNS_SERVER_LINK, | |
31 | } DnsServerType; | |
4c89c718 MP |
32 | #define _DNS_SERVER_TYPE_MAX (DNS_SERVER_LINK + 1) |
33 | ||
34 | const char* dns_server_type_to_string(DnsServerType i) _const_; | |
35 | DnsServerType dns_server_type_from_string(const char *s) _pure_; | |
36 | ||
37 | typedef enum DnsServerFeatureLevel { | |
38 | DNS_SERVER_FEATURE_LEVEL_TCP, | |
39 | DNS_SERVER_FEATURE_LEVEL_UDP, | |
40 | DNS_SERVER_FEATURE_LEVEL_EDNS0, | |
41 | DNS_SERVER_FEATURE_LEVEL_DO, | |
42 | DNS_SERVER_FEATURE_LEVEL_LARGE, | |
43 | _DNS_SERVER_FEATURE_LEVEL_MAX, | |
44 | _DNS_SERVER_FEATURE_LEVEL_INVALID = -1 | |
45 | } DnsServerFeatureLevel; | |
46 | ||
47 | #define DNS_SERVER_FEATURE_LEVEL_WORST 0 | |
48 | #define DNS_SERVER_FEATURE_LEVEL_BEST (_DNS_SERVER_FEATURE_LEVEL_MAX - 1) | |
49 | ||
50 | const char* dns_server_feature_level_to_string(int i) _const_; | |
51 | int dns_server_feature_level_from_string(const char *s) _pure_; | |
5eef597e | 52 | |
5eef597e | 53 | #include "resolved-link.h" |
4c89c718 | 54 | #include "resolved-manager.h" |
5eef597e MP |
55 | |
56 | struct DnsServer { | |
57 | Manager *manager; | |
58 | ||
7035cd9e MP |
59 | unsigned n_ref; |
60 | ||
5eef597e | 61 | DnsServerType type; |
5eef597e MP |
62 | Link *link; |
63 | ||
64 | int family; | |
65 | union in_addr_union address; | |
5a920b42 | 66 | int ifindex; /* for IPv6 link-local DNS servers */ |
5eef597e | 67 | |
4c89c718 MP |
68 | char *server_string; |
69 | ||
13d276d0 MP |
70 | usec_t resend_timeout; |
71 | usec_t max_rtt; | |
72 | ||
4c89c718 MP |
73 | DnsServerFeatureLevel verified_feature_level; |
74 | DnsServerFeatureLevel possible_feature_level; | |
75 | ||
76 | size_t received_udp_packet_max; | |
77 | ||
78 | unsigned n_failed_udp; | |
79 | unsigned n_failed_tcp; | |
80 | ||
4c89c718 MP |
81 | bool packet_truncated:1; |
82 | bool packet_bad_opt:1; | |
83 | bool packet_rrsig_missing:1; | |
84 | ||
85 | usec_t verified_usec; | |
86 | usec_t features_grace_period_usec; | |
87 | ||
88 | /* Whether we already warned about downgrading to non-DNSSEC mode for this server */ | |
89 | bool warned_downgrade:1; | |
90 | ||
91 | /* Used when GC'ing old DNS servers when configuration changes. */ | |
5eef597e MP |
92 | bool marked:1; |
93 | ||
4c89c718 MP |
94 | /* If linked is set, then this server appears in the servers linked list */ |
95 | bool linked:1; | |
5eef597e MP |
96 | LIST_FIELDS(DnsServer, servers); |
97 | }; | |
98 | ||
99 | int dns_server_new( | |
100 | Manager *m, | |
4c89c718 | 101 | DnsServer **ret, |
5eef597e | 102 | DnsServerType type, |
4c89c718 | 103 | Link *link, |
5eef597e | 104 | int family, |
5a920b42 MP |
105 | const union in_addr_union *address, |
106 | int ifindex); | |
5eef597e | 107 | |
7035cd9e MP |
108 | DnsServer* dns_server_ref(DnsServer *s); |
109 | DnsServer* dns_server_unref(DnsServer *s); | |
110 | ||
4c89c718 MP |
111 | void dns_server_unlink(DnsServer *s); |
112 | void dns_server_move_back_and_unmark(DnsServer *s); | |
113 | ||
114 | void dns_server_packet_received(DnsServer *s, int protocol, DnsServerFeatureLevel level, usec_t rtt, size_t size); | |
115 | void dns_server_packet_lost(DnsServer *s, int protocol, DnsServerFeatureLevel level, usec_t usec); | |
4c89c718 MP |
116 | void dns_server_packet_truncated(DnsServer *s, DnsServerFeatureLevel level); |
117 | void dns_server_packet_rrsig_missing(DnsServer *s, DnsServerFeatureLevel level); | |
118 | void dns_server_packet_bad_opt(DnsServer *s, DnsServerFeatureLevel level); | |
5a920b42 | 119 | void dns_server_packet_rcode_downgrade(DnsServer *s, DnsServerFeatureLevel level); |
4c89c718 MP |
120 | |
121 | DnsServerFeatureLevel dns_server_possible_feature_level(DnsServer *s); | |
122 | ||
123 | int dns_server_adjust_opt(DnsServer *server, DnsPacket *packet, DnsServerFeatureLevel level); | |
124 | ||
125 | const char *dns_server_string(DnsServer *server); | |
5a920b42 | 126 | int dns_server_ifindex(const DnsServer *s); |
4c89c718 MP |
127 | |
128 | bool dns_server_dnssec_supported(DnsServer *server); | |
129 | ||
130 | void dns_server_warn_downgrade(DnsServer *server); | |
131 | ||
8a584da2 MP |
132 | bool dns_server_limited_domains(DnsServer *server); |
133 | ||
5a920b42 | 134 | DnsServer *dns_server_find(DnsServer *first, int family, const union in_addr_union *in_addr, int ifindex); |
4c89c718 MP |
135 | |
136 | void dns_server_unlink_all(DnsServer *first); | |
137 | void dns_server_unlink_marked(DnsServer *first); | |
138 | void dns_server_mark_all(DnsServer *first); | |
139 | ||
140 | DnsServer *manager_get_first_dns_server(Manager *m, DnsServerType t); | |
141 | ||
142 | DnsServer *manager_set_dns_server(Manager *m, DnsServer *s); | |
143 | DnsServer *manager_get_dns_server(Manager *m); | |
144 | void manager_next_dns_server(Manager *m); | |
13d276d0 | 145 | |
5a920b42 MP |
146 | bool dns_server_address_valid(int family, const union in_addr_union *sa); |
147 | ||
2897b343 MP |
148 | DnssecMode dns_server_get_dnssec_mode(DnsServer *s); |
149 | ||
7035cd9e | 150 | DEFINE_TRIVIAL_CLEANUP_FUNC(DnsServer*, dns_server_unref); |
5eef597e MP |
151 | |
152 | extern const struct hash_ops dns_server_hash_ops; | |
2897b343 MP |
153 | |
154 | void dns_server_flush_cache(DnsServer *s); | |
f5e65279 MB |
155 | |
156 | void dns_server_reset_features(DnsServer *s); | |
157 | void dns_server_reset_features_all(DnsServer *s); | |
158 | ||
159 | void dns_server_dump(DnsServer *s, FILE *f); |