resolved-dns-server.c revision 571370c1555d2aa697733479a50957aff024bbcb
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2014 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
9df3ba6c6cb65eecec06f39dfe85a3596cedac4eTom Gundersen/* After how much time to repeat classic DNS requests */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define DNS_TIMEOUT_MIN_USEC (500 * USEC_PER_MSEC)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define DNS_TIMEOUT_MAX_USEC (5 * USEC_PER_SEC)
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering/* The amount of time to wait before retrying with a full feature set */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define DNS_SERVER_FEATURE_GRACE_PERIOD_MAX_USEC (6 * USEC_PER_HOUR)
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering#define DNS_SERVER_FEATURE_GRACE_PERIOD_MIN_USEC (5 * USEC_PER_MINUTE)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/* The number of times we will attempt a certain feature set before degrading */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#define DNS_SERVER_FEATURE_RETRY_ATTEMPTS 3
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert((type == DNS_SERVER_LINK) == !!l);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (l->n_dns_servers >= LINK_DNS_SERVERS_MAX)
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering if (m->n_dns_servers >= MANAGER_DNS_SERVERS_MAX)
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering s->verified_feature_level = _DNS_SERVER_FEATURE_LEVEL_INVALID;
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering s->possible_feature_level = DNS_SERVER_FEATURE_LEVEL_BEST;
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering s->features_grace_period_usec = DNS_SERVER_FEATURE_GRACE_PERIOD_MIN_USEC;
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering s->received_udp_packet_max = DNS_PACKET_UNICAST_SIZE_MAX;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s->resend_timeout = DNS_TIMEOUT_MIN_USEC;
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen LIST_APPEND(servers, m->fallback_dns_servers, s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* A new DNS server that isn't fallback is added and the one
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * we used so far was a fallback one? Then let's try to pick
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * the new one */
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen m->current_dns_server->type == DNS_SERVER_FALLBACK)
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering /* This removes the specified server from the linked list of
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering * servers, but any server might still stay around if it has
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering * refs, for example from an ongoing transaction. */
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering LIST_REMOVE(servers, s->link->dns_servers, s);
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt LIST_REMOVE(servers, s->manager->dns_servers, s);
case DNS_SERVER_FALLBACK:
s->linked = false;
dns_server_unref(s);
assert(s);
if (!s->marked)
s->marked = false;
switch (s->type) {
case DNS_SERVER_LINK:
case DNS_SERVER_SYSTEM:
case DNS_SERVER_FALLBACK:
void dns_server_packet_received(DnsServer *s, DnsServerFeatureLevel level, usec_t rtt, size_t size) {
assert(s);
s->n_failed_attempts = 0;
assert(s);
s->n_failed_attempts ++;
assert(s);
/* Invoked whenever we get a FORMERR, SERVFAIL or NOTIMP rcode from a server. This is an immediate trigger for
* us to go one feature level down. Except when we are already at TCP or UDP level, in which case there's no
* point in changing, under the assumption that packet failures are caused by packet contents, not by used
assert(s);
log_warning("DNS server %s does not augment replies with RRSIG records, DNSSEC not available.", strna(ip));
s->rrsig_missing = true;
assert(s);
if (s->verified_usec == 0)
s->features_grace_period_usec = MIN(s->features_grace_period_usec * 2, DNS_SERVER_FEATURE_GRACE_PERIOD_MAX_USEC);
assert(s);
s->n_failed_attempts = 0;
s->verified_usec = 0;
s->rrsig_missing = false;
* responds on one of them. Note that we generally prefer UDP over TCP (which is why it is at a higher
s->possible_feature_level --;
s->n_failed_attempts = 0;
s->verified_usec = 0;
return s->possible_feature_level;
bool edns_do;
const DnsServer *s = p;
assert(s);
static int dns_server_compare_func(const void *a, const void *b) {
const DnsServer *x = a, *y = b;
if (!first)
if (!first)
if (!first)
DnsServer *s;
return NULL;
assert(m);
case DNS_SERVER_SYSTEM:
return m->dns_servers;
case DNS_SERVER_FALLBACK:
return m->fallback_dns_servers;
return NULL;
assert(m);
if (m->current_dns_server == s)
if (m->unicast_scope)
Link *l;
assert(m);
/* Try to read updates resolv.conf */
if (!m->current_dns_server)
if (!m->current_dns_server) {
bool found = false;
Iterator i;
if (l->dns_servers) {
found = true;
if (!found)
return m->current_dns_server;
assert(m);
if (!m->current_dns_server)