if (r < 0)
return r;
- /* Silently filter out 0.0.0.0, 127.0.0.53, 127.0.0.54 (our own stub DNS listener) */
- if (!dns_server_address_valid(family, &address))
- return 0;
-
- /* By default, the port number is determined with the transaction feature level.
+ /* By default, the port number is determined by the transaction feature level.
* See dns_transaction_port() and dns_server_port(). */
if (IN_SET(port, 53, 853))
port = 0;
+ /* Refuse 0.0.0.0, 127.0.0.53, 127.0.0.54 and the rest of our own stub DNS listeners. */
+ if (!dns_server_address_valid(family, &address) ||
+ manager_server_address_is_stub(m, family, &address, port ?: 53))
+ return -ELOOP;
+
/* Filter out duplicates */
s = dns_server_find(manager_get_first_dns_server(m, type), family, &address, port, ifindex, server_name);
if (s) {
return dns_server_new(m, NULL, type, NULL, family, &address, port, ifindex, server_name);
}
-int manager_parse_dns_server_string_and_warn(Manager *m, DnsServerType type, const char *string) {
+int manager_parse_dns_server_string_and_warn(Manager *m, DnsServerType type, const char *string, bool ignore_self_quietly) {
int r;
assert(m);
return r;
r = manager_add_dns_server_by_string(m, type, word);
- if (r < 0)
+ if (r == -ELOOP)
+ log_full(ignore_self_quietly ? LOG_DEBUG : LOG_INFO,
+ "DNS server string '%s' points to our own listener, ignoring.", word);
+ else if (r < 0)
log_warning_errno(r, "Failed to add DNS server address '%s', ignoring: %m", word);
}
}
dns_server_unlink_all(manager_get_first_dns_server(m, ltype));
else {
/* Otherwise, add to the list */
- r = manager_parse_dns_server_string_and_warn(m, ltype, rvalue);
+ r = manager_parse_dns_server_string_and_warn(m, ltype, rvalue, false);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse DNS server string '%s', ignoring.", rvalue);
}
}
- /* If we have a manual setting, then we stop reading
- * /etc/resolv.conf */
+ /* If we have a manual setting, then we stop reading /etc/resolv.conf */
if (ltype == DNS_SERVER_SYSTEM)
m->read_resolv_conf = false;
if (ltype == DNS_SERVER_FALLBACK)
}
}
- /* If we have a manual setting, then we stop reading
- * /etc/resolv.conf */
+ /* If we have a manual setting, then we stop reading /etc/resolv.conf */
m->read_resolv_conf = false;
return 0;
return r;
if (m->need_builtin_fallbacks) {
- r = manager_parse_dns_server_string_and_warn(m, DNS_SERVER_FALLBACK, DNS_SERVERS);
+ r = manager_parse_dns_server_string_and_warn(m, DNS_SERVER_FALLBACK, DNS_SERVERS, false);
if (r < 0)
return r;
}
return tried;
}
-bool manager_server_is_stub(Manager *m, DnsServer *s) {
+bool manager_server_address_is_stub(Manager *m, int family, const union in_addr_union *address, uint16_t port) {
DnsStubListenerExtra *l;
assert(m);
- assert(s);
+ assert(address);
/* Safety check: we generally already skip the main stub when parsing configuration. But let's be
* extra careful, and check here again */
- if (s->family == AF_INET &&
- s->address.in.s_addr == htobe32(INADDR_DNS_STUB) &&
- dns_server_port(s) == 53)
+ if (family == AF_INET &&
+ address->in.s_addr == htobe32(INADDR_DNS_STUB) &&
+ port == 53)
return true;
/* Main reason to call this is to check server data against the extra listeners, and filter things
* out. */
ORDERED_SET_FOREACH(l, m->dns_extra_stub_listeners)
- if (s->family == l->family &&
- in_addr_equal(s->family, &s->address, &l->address) &&
- dns_server_port(s) == dns_stub_listener_extra_port(l))
+ if (family == l->family &&
+ in_addr_equal(family, address, &l->address) &&
+ port == dns_stub_listener_extra_port(l))
return true;
return false;
}
+bool manager_server_is_stub(Manager *m, DnsServer *s) {
+ assert(m);
+ assert(s);
+
+ return manager_server_address_is_stub(m, s->family, &s->address, dns_server_port(s));
+}
+
int socket_disable_pmtud(int fd, int af) {
int r;