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
;
38 assert((type
== DNS_SEARCH_DOMAIN_LINK
) == !!l
);
41 r
= dns_name_normalize(name
, &normalized
);
46 if (l
->n_search_domains
>= LINK_SEARCH_DOMAINS_MAX
)
49 if (m
->n_search_domains
>= MANAGER_SEARCH_DOMAINS_MAX
)
53 d
= new0(DnsSearchDomain
, 1);
65 case DNS_SEARCH_DOMAIN_LINK
:
67 LIST_APPEND(domains
, l
->search_domains
, d
);
68 l
->n_search_domains
++;
71 case DNS_SERVER_SYSTEM
:
72 LIST_APPEND(domains
, m
->search_domains
, d
);
73 m
->n_search_domains
++;
77 assert_not_reached("Unknown search domain type");
88 DnsSearchDomain
* dns_search_domain_ref(DnsSearchDomain
*d
) {
98 DnsSearchDomain
* dns_search_domain_unref(DnsSearchDomain
*d
) {
102 assert(d
->n_ref
> 0);
114 void dns_search_domain_unlink(DnsSearchDomain
*d
) {
123 case DNS_SEARCH_DOMAIN_LINK
:
125 assert(d
->link
->n_search_domains
> 0);
126 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
127 d
->link
->n_search_domains
--;
130 case DNS_SEARCH_DOMAIN_SYSTEM
:
131 assert(d
->manager
->n_search_domains
> 0);
132 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
133 d
->manager
->n_search_domains
--;
139 dns_search_domain_unref(d
);
142 void dns_search_domain_move_back_and_unmark(DnsSearchDomain
*d
) {
143 DnsSearchDomain
*tail
;
152 if (!d
->linked
|| !d
->domains_next
)
157 case DNS_SEARCH_DOMAIN_LINK
:
159 LIST_FIND_TAIL(domains
, d
, tail
);
160 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
161 LIST_INSERT_AFTER(domains
, d
->link
->search_domains
, tail
, d
);
164 case DNS_SEARCH_DOMAIN_SYSTEM
:
165 LIST_FIND_TAIL(domains
, d
, tail
);
166 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
167 LIST_INSERT_AFTER(domains
, d
->manager
->search_domains
, tail
, d
);
171 assert_not_reached("Unknown search domain type");
175 void dns_search_domain_unlink_all(DnsSearchDomain
*first
) {
176 DnsSearchDomain
*next
;
181 next
= first
->domains_next
;
182 dns_search_domain_unlink(first
);
184 dns_search_domain_unlink_all(next
);
187 void dns_search_domain_unlink_marked(DnsSearchDomain
*first
) {
188 DnsSearchDomain
*next
;
193 next
= first
->domains_next
;
196 dns_search_domain_unlink(first
);
198 dns_search_domain_unlink_marked(next
);
201 void dns_search_domain_mark_all(DnsSearchDomain
*first
) {
205 first
->marked
= true;
206 dns_search_domain_mark_all(first
->domains_next
);
209 int dns_search_domain_find(DnsSearchDomain
*first
, const char *name
, DnsSearchDomain
**ret
) {
216 LIST_FOREACH(domains
, d
, first
) {
218 r
= dns_name_equal(name
, d
->name
);