]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-search-domain.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Lennart Poettering
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.
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.
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/>.
22 #include "alloc-util.h"
23 #include "dns-domain.h"
24 #include "resolved-dns-search-domain.h"
26 int dns_search_domain_new(
28 DnsSearchDomain
**ret
,
29 DnsSearchDomainType type
,
33 _cleanup_free_
char *normalized
= NULL
;
34 DnsSearchDomain
*d
, *tail
;
38 assert((type
== DNS_SEARCH_DOMAIN_LINK
) == !!l
);
41 r
= dns_name_normalize(name
, &normalized
);
45 r
= dns_name_root(normalized
);
51 d
= new0(DnsSearchDomain
, 1);
63 case DNS_SEARCH_DOMAIN_LINK
:
65 LIST_FIND_TAIL(domains
, l
->search_domains
, tail
);
66 LIST_INSERT_AFTER(domains
, l
->search_domains
, tail
, d
);
69 case DNS_SERVER_SYSTEM
:
70 LIST_FIND_TAIL(domains
, m
->search_domains
, tail
);
71 LIST_INSERT_AFTER(domains
, m
->search_domains
, tail
, d
);
75 assert_not_reached("Unknown search domain type");
86 DnsSearchDomain
* dns_search_domain_ref(DnsSearchDomain
*d
) {
96 DnsSearchDomain
* dns_search_domain_unref(DnsSearchDomain
*d
) {
100 assert(d
->n_ref
> 0);
112 void dns_search_domain_unlink(DnsSearchDomain
*d
) {
121 case DNS_SEARCH_DOMAIN_LINK
:
123 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
126 case DNS_SEARCH_DOMAIN_SYSTEM
:
127 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
133 dns_search_domain_unref(d
);
136 void dns_search_domain_move_back_and_unmark(DnsSearchDomain
*d
) {
137 DnsSearchDomain
*tail
;
146 if (!d
->linked
|| !d
->domains_next
)
151 case DNS_SEARCH_DOMAIN_LINK
:
153 LIST_FIND_TAIL(domains
, d
, tail
);
154 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
155 LIST_INSERT_AFTER(domains
, d
->link
->search_domains
, tail
, d
);
158 case DNS_SEARCH_DOMAIN_SYSTEM
:
159 LIST_FIND_TAIL(domains
, d
, tail
);
160 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
161 LIST_INSERT_AFTER(domains
, d
->manager
->search_domains
, tail
, d
);
165 assert_not_reached("Unknown search domain type");
169 void dns_search_domain_unlink_all(DnsSearchDomain
*first
) {
170 DnsSearchDomain
*next
;
175 next
= first
->domains_next
;
176 dns_search_domain_unlink(first
);
178 dns_search_domain_unlink_all(next
);
181 void dns_search_domain_unlink_marked(DnsSearchDomain
*first
) {
182 DnsSearchDomain
*next
;
187 next
= first
->domains_next
;
190 dns_search_domain_unlink(first
);
192 dns_search_domain_unlink_marked(next
);
195 void dns_search_domain_mark_all(DnsSearchDomain
*first
) {
199 first
->marked
= true;
200 dns_search_domain_mark_all(first
->domains_next
);
203 int dns_search_domain_find(DnsSearchDomain
*first
, const char *name
, DnsSearchDomain
**ret
) {
210 LIST_FOREACH(domains
, d
, first
) {
212 r
= dns_name_equal(name
, d
->name
);