]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-conf.c
2 This file is part of systemd.
4 Copyright 2014 Tom Gundersen <teg@jklm.no>
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
21 #include "conf-parser.h"
23 #include "extract-word.h"
24 #include "parse-util.h"
25 #include "resolved-conf.h"
26 #include "string-util.h"
28 int manager_add_dns_server_by_string(Manager
*m
, DnsServerType type
, const char *word
) {
29 union in_addr_union address
;
36 r
= in_addr_from_string_auto(word
, &family
, &address
);
40 /* Filter out duplicates */
41 s
= dns_server_find(manager_get_first_dns_server(m
, type
), family
, &address
);
44 * Drop the marker. This is used to find the servers
45 * that ceased to exist, see
46 * manager_mark_dns_servers() and
47 * manager_flush_marked_dns_servers().
49 dns_server_move_back_and_unmark(s
);
53 return dns_server_new(m
, NULL
, type
, NULL
, family
, &address
);
56 int manager_parse_dns_server_string_and_warn(Manager
*m
, DnsServerType type
, const char *string
) {
63 _cleanup_free_
char *word
= NULL
;
65 r
= extract_first_word(&string
, &word
, NULL
, 0);
71 r
= manager_add_dns_server_by_string(m
, type
, word
);
73 log_warning_errno(r
, "Failed to add DNS server address '%s', ignoring.", word
);
79 int manager_add_search_domain_by_string(Manager
*m
, const char *domain
) {
87 route_only
= *domain
== '~';
91 if (dns_name_is_root(domain
) || streq(domain
, "*")) {
96 r
= dns_search_domain_find(m
->search_domains
, domain
, &d
);
100 dns_search_domain_move_back_and_unmark(d
);
102 r
= dns_search_domain_new(m
, &d
, DNS_SEARCH_DOMAIN_SYSTEM
, NULL
, domain
);
107 d
->route_only
= route_only
;
111 int manager_parse_search_domains_and_warn(Manager
*m
, const char *string
) {
118 _cleanup_free_
char *word
= NULL
;
120 r
= extract_first_word(&string
, &word
, NULL
, EXTRACT_QUOTES
);
126 r
= manager_add_search_domain_by_string(m
, word
);
128 log_warning_errno(r
, "Failed to add search domain '%s', ignoring.", word
);
134 int config_parse_dns_servers(
136 const char *filename
,
139 unsigned section_line
,
146 Manager
*m
= userdata
;
155 /* Empty assignment means clear the list */
156 dns_server_unlink_all(manager_get_first_dns_server(m
, ltype
));
158 /* Otherwise, add to the list */
159 r
= manager_parse_dns_server_string_and_warn(m
, ltype
, rvalue
);
161 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse DNS server string '%s'. Ignoring.", rvalue
);
166 /* If we have a manual setting, then we stop reading
167 * /etc/resolv.conf */
168 if (ltype
== DNS_SERVER_SYSTEM
)
169 m
->read_resolv_conf
= false;
170 if (ltype
== DNS_SERVER_FALLBACK
)
171 m
->need_builtin_fallbacks
= false;
176 int config_parse_search_domains(
178 const char *filename
,
181 unsigned section_line
,
188 Manager
*m
= userdata
;
197 /* Empty assignment means clear the list */
198 dns_search_domain_unlink_all(m
->search_domains
);
200 /* Otherwise, add to the list */
201 r
= manager_parse_search_domains_and_warn(m
, rvalue
);
203 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse search domains string '%s'. Ignoring.", rvalue
);
208 /* If we have a manual setting, then we stop reading
209 * /etc/resolv.conf */
210 m
->read_resolv_conf
= false;
215 int manager_parse_config_file(Manager
*m
) {
220 r
= config_parse_many(PKGSYSCONFDIR
"/resolved.conf",
221 CONF_PATHS_NULSTR("systemd/resolved.conf.d"),
223 config_item_perf_lookup
, resolved_gperf_lookup
,
228 if (m
->need_builtin_fallbacks
) {
229 r
= manager_parse_dns_server_string_and_warn(m
, DNS_SERVER_FALLBACK
, DNS_SERVERS
);