2 This file is part of systemd.
4 Copyright 2015 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
21 #include "dns-domain.h"
22 #include "resolved-dns-search-domain.h"
24 int dns_search_domain_new(
26 DnsSearchDomain
**ret
,
27 DnsSearchDomainType type
,
31 _cleanup_free_
char *normalized
= NULL
;
36 assert((type
== DNS_SEARCH_DOMAIN_LINK
) == !!l
);
39 r
= dns_name_normalize(name
, &normalized
);
44 if (l
->n_search_domains
>= LINK_SEARCH_DOMAINS_MAX
)
47 if (m
->n_search_domains
>= MANAGER_SEARCH_DOMAINS_MAX
)
51 d
= new0(DnsSearchDomain
, 1);
63 case DNS_SEARCH_DOMAIN_LINK
:
65 LIST_APPEND(domains
, l
->search_domains
, d
);
66 l
->n_search_domains
++;
69 case DNS_SERVER_SYSTEM
:
70 LIST_APPEND(domains
, m
->search_domains
, d
);
71 m
->n_search_domains
++;
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);
110 void dns_search_domain_unlink(DnsSearchDomain
*d
) {
119 case DNS_SEARCH_DOMAIN_LINK
:
121 assert(d
->link
->n_search_domains
> 0);
122 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
123 d
->link
->n_search_domains
--;
126 case DNS_SEARCH_DOMAIN_SYSTEM
:
127 assert(d
->manager
->n_search_domains
> 0);
128 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
129 d
->manager
->n_search_domains
--;
135 dns_search_domain_unref(d
);
138 void dns_search_domain_move_back_and_unmark(DnsSearchDomain
*d
) {
139 DnsSearchDomain
*tail
;
148 if (!d
->linked
|| !d
->domains_next
)
153 case DNS_SEARCH_DOMAIN_LINK
:
155 LIST_FIND_TAIL(domains
, d
, tail
);
156 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
157 LIST_INSERT_AFTER(domains
, d
->link
->search_domains
, tail
, d
);
160 case DNS_SEARCH_DOMAIN_SYSTEM
:
161 LIST_FIND_TAIL(domains
, d
, tail
);
162 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
163 LIST_INSERT_AFTER(domains
, d
->manager
->search_domains
, tail
, d
);
167 assert_not_reached("Unknown search domain type");
171 void dns_search_domain_unlink_all(DnsSearchDomain
*first
) {
172 DnsSearchDomain
*next
;
177 next
= first
->domains_next
;
178 dns_search_domain_unlink(first
);
180 dns_search_domain_unlink_all(next
);
183 void dns_search_domain_unlink_marked(DnsSearchDomain
*first
) {
184 DnsSearchDomain
*next
;
189 next
= first
->domains_next
;
192 dns_search_domain_unlink(first
);
194 dns_search_domain_unlink_marked(next
);
197 void dns_search_domain_mark_all(DnsSearchDomain
*first
) {
201 first
->marked
= true;
202 dns_search_domain_mark_all(first
->domains_next
);
205 int dns_search_domain_find(DnsSearchDomain
*first
, const char *name
, DnsSearchDomain
**ret
) {
212 LIST_FOREACH(domains
, d
, first
) {
214 r
= dns_name_equal(name
, d
->name
);