resolved-dns-server.c revision 91b14d6ff362b938a72db17b095ee9903d07381b
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/>.
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering assert((type == DNS_SERVER_LINK) == !!l);
6073b6f26ab9fc6bf335faa7073ec443eef093fdTom Gundersen LIST_FIND_TAIL(servers, l->dns_servers, tail);
6073b6f26ab9fc6bf335faa7073ec443eef093fdTom Gundersen LIST_INSERT_AFTER(servers, l->dns_servers, tail, s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIND_TAIL(servers, m->dns_servers, tail);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_INSERT_AFTER(servers, m->dns_servers, tail, s);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering } else if (type == DNS_SERVER_FALLBACK) {
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering LIST_FIND_TAIL(servers, m->fallback_dns_servers, tail);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering LIST_INSERT_AFTER(servers, m->fallback_dns_servers, tail, s);
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering assert_not_reached("Unknown server type");
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering /* A new DNS server that isn't fallback is added and the one
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * we used so far was a fallback one? Then let's try to pick
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * the new one */
3e684349c2cead2e6fd2f816c34eb17daba23a49Lennart Poettering m->current_dns_server->type == DNS_SERVER_FALLBACK)
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersenstatic DnsServer* dns_server_free(DnsServer *s) {
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen if (s->link && s->link->current_dns_server == s)
91b14d6ff362b938a72db17b095ee9903d07381bTom Gundersen if (s->manager && s->manager->current_dns_server == s)
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtstatic unsigned long dns_server_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering siphash24((uint8_t*) &u, &s->address, FAMILY_ADDRESS_SIZE(s->family), hash_key);
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidtstatic int dns_server_compare_func(const void *a, const void *b) {
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering const DnsServer *x = a, *y = b;
87f5a19343acf8ba697acc5a62bdb1a2b8c9eda3Lennart Poettering return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family));