]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/resolve/resolved-dns-server.c
resolved: set LLMNR TCP and UDP TTLs to the values suggested by the RFC
[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,
74b2466e 27 Link *l,
0dd25fb9 28 int family,
3c0cf502 29 const union in_addr_union *in_addr) {
74b2466e
LP
30
31 DnsServer *s, *tail;
32
33 assert(m);
34 assert(in_addr);
74b2466e
LP
35
36 s = new0(DnsServer, 1);
37 if (!s)
38 return -ENOMEM;
39
74b2466e
LP
40 s->family = family;
41 s->address = *in_addr;
42
6073b6f2
TG
43 if (l) {
44 LIST_FIND_TAIL(servers, l->dns_servers, tail);
45 LIST_INSERT_AFTER(servers, l->dns_servers, tail, s);
74b2466e
LP
46 s->link = l;
47 } else {
74b2466e
LP
48 LIST_FIND_TAIL(servers, m->dns_servers, tail);
49 LIST_INSERT_AFTER(servers, m->dns_servers, tail, s);
50 }
51
52 s->manager = m;
53
54 if (ret)
55 *ret = s;
56
57 return 0;
58}
59
60DnsServer* dns_server_free(DnsServer *s) {
61 if (!s)
62 return NULL;
63
2f82f5ea 64 if (s->manager) {
74b2466e 65 if (s->link)
6073b6f2 66 LIST_REMOVE(servers, s->link->dns_servers, s);
2f82f5ea 67 else
74b2466e
LP
68 LIST_REMOVE(servers, s->manager->dns_servers, s);
69 }
70
71 if (s->link && s->link->current_dns_server == s)
72 s->link->current_dns_server = NULL;
73
74 if (s->manager && s->manager->current_dns_server == s)
75 s->manager->current_dns_server = NULL;
76
77 free(s);
78
79 return NULL;
80}