]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-conf.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Tom Gundersen <teg@jklm.no>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
23 #include "conf-parser.h"
25 #include "extract-word.h"
26 #include "parse-util.h"
27 #include "resolved-conf.h"
28 #include "string-util.h"
30 int manager_add_dns_server_by_string(Manager
*m
, DnsServerType type
, const char *word
) {
31 union in_addr_union address
;
38 r
= in_addr_from_string_auto(word
, &family
, &address
);
42 /* Filter out duplicates */
43 s
= manager_find_dns_server(m
, type
, family
, &address
);
46 * Drop the marker. This is used to find the servers
47 * that ceased to exist, see
48 * manager_mark_dns_servers() and
49 * manager_flush_marked_dns_servers().
51 dns_server_move_back_and_unmark(s
);
55 return dns_server_new(m
, NULL
, type
, NULL
, family
, &address
);
58 int manager_parse_dns_server_string_and_warn(Manager
*m
, DnsServerType type
, const char *string
) {
65 _cleanup_free_
char *word
= NULL
;
67 r
= extract_first_word(&string
, &word
, NULL
, 0);
73 r
= manager_add_dns_server_by_string(m
, type
, word
);
75 log_warning_errno(r
, "Failed to add DNS server address '%s', ignoring.", word
);
81 int manager_add_search_domain_by_string(Manager
*m
, const char *domain
) {
88 r
= dns_search_domain_find(m
->search_domains
, domain
, &d
);
92 dns_search_domain_move_back_and_unmark(d
);
96 return dns_search_domain_new(m
, NULL
, DNS_SEARCH_DOMAIN_SYSTEM
, NULL
, domain
);
99 int manager_parse_search_domains_and_warn(Manager
*m
, const char *string
) {
106 _cleanup_free_
char *word
= NULL
;
108 r
= extract_first_word(&string
, &word
, NULL
, EXTRACT_QUOTES
);
114 r
= manager_add_search_domain_by_string(m
, word
);
116 log_warning_errno(r
, "Failed to add search domain '%s', ignoring.", word
);
122 int config_parse_dns_servers(
124 const char *filename
,
127 unsigned section_line
,
134 Manager
*m
= userdata
;
143 /* Empty assignment means clear the list */
144 manager_flush_dns_servers(m
, ltype
);
146 /* Otherwise, add to the list */
147 r
= manager_parse_dns_server_string_and_warn(m
, ltype
, rvalue
);
149 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse DNS server string '%s'. Ignoring.", rvalue
);
154 /* If we have a manual setting, then we stop reading
155 * /etc/resolv.conf */
156 if (ltype
== DNS_SERVER_SYSTEM
)
157 m
->read_resolv_conf
= false;
158 if (ltype
== DNS_SERVER_FALLBACK
)
159 m
->need_builtin_fallbacks
= false;
164 int config_parse_search_domains(
166 const char *filename
,
169 unsigned section_line
,
176 Manager
*m
= userdata
;
185 /* Empty assignment means clear the list */
186 dns_search_domain_unlink_all(m
->search_domains
);
188 /* Otherwise, add to the list */
189 r
= manager_parse_search_domains_and_warn(m
, rvalue
);
191 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse search domains string '%s'. Ignoring.", rvalue
);
196 /* If we have a manual setting, then we stop reading
197 * /etc/resolv.conf */
198 m
->read_resolv_conf
= false;
203 int config_parse_support(
205 const char *filename
,
208 unsigned section_line
,
215 Support support
, *v
= data
;
222 support
= support_from_string(rvalue
);
224 r
= parse_boolean(rvalue
);
226 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Failed to parse support level '%s'. Ignoring.", rvalue
);
230 support
= r
? SUPPORT_YES
: SUPPORT_NO
;
237 int manager_parse_config_file(Manager
*m
) {
242 r
= config_parse_many(PKGSYSCONFDIR
"/resolved.conf",
243 CONF_PATHS_NULSTR("systemd/resolved.conf.d"),
245 config_item_perf_lookup
, resolved_gperf_lookup
,
250 if (m
->need_builtin_fallbacks
) {
251 r
= manager_parse_dns_server_string_and_warn(m
, DNS_SERVER_FALLBACK
, DNS_SERVERS
);