resolved-dns-server.c revision 3c0cf502796be355431d4a64d738e75f543aa51d
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/***
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2014 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart 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
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
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/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering***/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "resolved-dns-server.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringint dns_server_new(
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering Manager *m,
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering DnsServer **ret,
ec2c5e4398f9d65e5dfe61530f2556224733d1e6Lennart Poettering DnsServerSource source,
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering Link *l,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering unsigned char family,
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering const union in_addr_union *in_addr) {
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering DnsServer *s, *tail;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(in_addr);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(source < _DNS_SERVER_SOURCE_MAX);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s = new0(DnsServer, 1);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!s)
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt return -ENOMEM;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s->source = source;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s->family = family;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s->address = *in_addr;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (source == DNS_SERVER_LINK) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(l);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIND_TAIL(servers, l->link_dns_servers, tail);
af49ca27ffd790d78dbbb465b978266dfd5c93daLennart Poettering LIST_INSERT_AFTER(servers, l->link_dns_servers, tail, s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s->link = l;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (source == DNS_SERVER_DHCP) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(l);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIND_TAIL(servers, l->dhcp_dns_servers, tail);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_INSERT_AFTER(servers, l->dhcp_dns_servers, tail, s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s->link = l;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering assert(!l);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_FIND_TAIL(servers, m->dns_servers, tail);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_INSERT_AFTER(servers, m->dns_servers, tail, s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering }
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering s->manager = m;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (ret)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering *ret = s;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return 0;
00f0a16ab4576535021456f8955446d3ae8f0b5fLennart Poettering}
a51c10485af349eb15faa4d1a63b9818bcf3e589Lennart Poettering
0eac462399c8e87bcce252cf058eba9f2678f2bdLennart PoetteringDnsServer* dns_server_free(DnsServer *s) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!s)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering return NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (s->source == DNS_SERVER_LINK) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (s->link)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering LIST_REMOVE(servers, s->link->link_dns_servers, s);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering } else if (s->source == DNS_SERVER_DHCP) {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
b4f1862df2e45aba90386887d685b8bf3c840e10Daniel Mack if (s->link)
b4f1862df2e45aba90386887d685b8bf3c840e10Daniel Mack LIST_REMOVE(servers, s->link->dhcp_dns_servers, s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (s->source == DNS_SERVER_SYSTEM) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (s->manager)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering LIST_REMOVE(servers, s->manager->dns_servers, s);
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering }
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering if (s->link && s->link->current_dns_server == s)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering s->link->current_dns_server = NULL;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
6073b6f26ab9fc6bf335faa7073ec443eef093fdTom Gundersen if (s->manager && s->manager->current_dns_server == s)
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering s->manager->current_dns_server = NULL;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering free(s);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering return NULL;
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering}
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering