]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-server.c
networkd: merge DNS and NTP entries when exporting
[thirdparty/systemd.git] / src / resolve / resolved-dns-server.c
CommitLineData
74b2466e
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2014 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include "resolved-dns-server.h"
23
24int dns_server_new(
25 Manager *m,
26 DnsServer **ret,
27 DnsServerSource source,
28 Link *l,
0dd25fb9 29 int family,
3c0cf502 30 const union in_addr_union *in_addr) {
74b2466e
LP
31
32 DnsServer *s, *tail;
33
34 assert(m);
35 assert(in_addr);
36 assert(source < _DNS_SERVER_SOURCE_MAX);
37
38 s = new0(DnsServer, 1);
39 if (!s)
40 return -ENOMEM;
41
42 s->source = source;
43 s->family = family;
44 s->address = *in_addr;
45
46 if (source == DNS_SERVER_LINK) {
47 assert(l);
48 LIST_FIND_TAIL(servers, l->link_dns_servers, tail);
49 LIST_INSERT_AFTER(servers, l->link_dns_servers, tail, s);
50 s->link = l;
51 } else if (source == DNS_SERVER_DHCP) {
52 assert(l);
53 LIST_FIND_TAIL(servers, l->dhcp_dns_servers, tail);
54 LIST_INSERT_AFTER(servers, l->dhcp_dns_servers, tail, s);
55 s->link = l;
56 } else {
57 assert(!l);
58 LIST_FIND_TAIL(servers, m->dns_servers, tail);
59 LIST_INSERT_AFTER(servers, m->dns_servers, tail, s);
60 }
61
62 s->manager = m;
63
64 if (ret)
65 *ret = s;
66
67 return 0;
68}
69
70DnsServer* dns_server_free(DnsServer *s) {
71 if (!s)
72 return NULL;
73
74 if (s->source == DNS_SERVER_LINK) {
75
76 if (s->link)
77 LIST_REMOVE(servers, s->link->link_dns_servers, s);
78 } else if (s->source == DNS_SERVER_DHCP) {
79
80 if (s->link)
81 LIST_REMOVE(servers, s->link->dhcp_dns_servers, s);
82
83 } else if (s->source == DNS_SERVER_SYSTEM) {
84
85 if (s->manager)
86 LIST_REMOVE(servers, s->manager->dns_servers, s);
87 }
88
89 if (s->link && s->link->current_dns_server == s)
90 s->link->current_dns_server = NULL;
91
92 if (s->manager && s->manager->current_dns_server == s)
93 s->manager->current_dns_server = NULL;
94
95 free(s);
96
97 return NULL;
98}