summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-conf.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-24 16:48:13 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-25 21:58:37 +0100
commit636e813dc98ea40c58c6c85bc5e7e3c9f0904ea2 (patch)
tree4ea8f8a918f6efc364944503c25e909c86b8a791 /src/resolve/resolved-conf.c
parente3528a5c46c815974d4d17ea9964278f7ee9caae (diff)
resolved: unify code for parsing dns server information
Let's use the same parser when parsing dns server information from /etc/resolv.conf and our native configuration file. Also, move all code that manages lists of dns servers to a single place. resolved-dns-server.c
Diffstat (limited to 'src/resolve/resolved-conf.c')
-rw-r--r--src/resolve/resolved-conf.c66
1 files changed, 39 insertions, 27 deletions
diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c
index 9207719551..8b49d46a59 100644
--- a/src/resolve/resolved-conf.c
+++ b/src/resolve/resolved-conf.c
@@ -27,53 +27,65 @@
#include "resolved-conf.h"
#include "string-util.h"
-int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) {
- DnsServer *first;
- int r;
+int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char *word) {
+ union in_addr_union address;
+ DnsServer *first, *s;
+ int family, r;
assert(m);
- assert(string);
+ assert(word);
+
+ r = in_addr_from_string_auto(word, &family, &address);
+ if (r < 0)
+ return r;
first = type == DNS_SERVER_FALLBACK ? m->fallback_dns_servers : m->dns_servers;
+ /* Filter out duplicates */
+ LIST_FOREACH(servers, s, first)
+ if (s->family == family && in_addr_equal(family, &s->address, &address))
+ break;
+
+ if (s) {
+ /*
+ * Drop the marker. This is used to find the servers
+ * that ceased to exist, see
+ * manager_mark_dns_servers() and
+ * manager_flush_marked_dns_servers().
+ */
+ s->marked = false;
+ return 0;
+ }
+
+ return dns_server_new(m, NULL, type, NULL, family, &address);
+}
+
+int manager_parse_dns_server_string_and_warn(Manager *m, DnsServerType type, const char *string) {
+ int r;
+
+ assert(m);
+ assert(string);
+
for(;;) {
_cleanup_free_ char *word = NULL;
- union in_addr_union addr;
- bool found = false;
- DnsServer *s;
- int family;
r = extract_first_word(&string, &word, NULL, 0);
if (r < 0)
- return log_error_errno(r, "Failed to parse resolved dns server syntax \"%s\": %m", string);
+ return r;
if (r == 0)
break;
- r = in_addr_from_string_auto(word, &family, &addr);
+ r = manager_add_dns_server_by_string(m, type, word);
if (r < 0) {
- log_warning("Ignoring invalid DNS address '%s'", word);
+ log_warning_errno(r, "Failed to add DNS server address '%s', ignoring.", word);
continue;
}
-
- /* Filter out duplicates */
- LIST_FOREACH(servers, s, first)
- if (s->family == family && in_addr_equal(family, &s->address, &addr)) {
- found = true;
- break;
- }
-
- if (found)
- continue;
-
- r = dns_server_new(m, NULL, type, NULL, family, &addr);
- if (r < 0)
- return r;
}
return 0;
}
-int config_parse_dnsv(
+int config_parse_dns_servers(
const char *unit,
const char *filename,
unsigned line,
@@ -98,7 +110,7 @@ int config_parse_dnsv(
manager_flush_dns_servers(m, ltype);
else {
/* Otherwise, add to the list */
- r = manager_parse_dns_server(m, ltype, rvalue);
+ r = manager_parse_dns_server_string_and_warn(m, ltype, rvalue);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse DNS server string '%s'. Ignoring.", rvalue);
return 0;