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
);
45 if (dns_name_is_root(normalized
))
49 if (l
->n_search_domains
>= LINK_SEARCH_DOMAINS_MAX
)
52 if (m
->n_search_domains
>= MANAGER_SEARCH_DOMAINS_MAX
)
56 d
= new0(DnsSearchDomain
, 1);
68 case DNS_SEARCH_DOMAIN_LINK
:
70 LIST_APPEND(domains
, l
->search_domains
, d
);
71 l
->n_search_domains
++;
74 case DNS_SERVER_SYSTEM
:
75 LIST_APPEND(domains
, m
->search_domains
, d
);
76 m
->n_search_domains
++;
80 assert_not_reached("Unknown search domain type");
91 DnsSearchDomain
* dns_search_domain_ref(DnsSearchDomain
*d
) {
101 DnsSearchDomain
* dns_search_domain_unref(DnsSearchDomain
*d
) {
105 assert(d
->n_ref
> 0);
117 void dns_search_domain_unlink(DnsSearchDomain
*d
) {
126 case DNS_SEARCH_DOMAIN_LINK
:
128 assert(d
->link
->n_search_domains
> 0);
129 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
130 d
->link
->n_search_domains
--;
133 case DNS_SEARCH_DOMAIN_SYSTEM
:
134 assert(d
->manager
->n_search_domains
> 0);
135 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
136 d
->manager
->n_search_domains
--;
142 dns_search_domain_unref(d
);
145 void dns_search_domain_move_back_and_unmark(DnsSearchDomain
*d
) {
146 DnsSearchDomain
*tail
;
155 if (!d
->linked
|| !d
->domains_next
)
160 case DNS_SEARCH_DOMAIN_LINK
:
162 LIST_FIND_TAIL(domains
, d
, tail
);
163 LIST_REMOVE(domains
, d
->link
->search_domains
, d
);
164 LIST_INSERT_AFTER(domains
, d
->link
->search_domains
, tail
, d
);
167 case DNS_SEARCH_DOMAIN_SYSTEM
:
168 LIST_FIND_TAIL(domains
, d
, tail
);
169 LIST_REMOVE(domains
, d
->manager
->search_domains
, d
);
170 LIST_INSERT_AFTER(domains
, d
->manager
->search_domains
, tail
, d
);
174 assert_not_reached("Unknown search domain type");
178 void dns_search_domain_unlink_all(DnsSearchDomain
*first
) {
179 DnsSearchDomain
*next
;
184 next
= first
->domains_next
;
185 dns_search_domain_unlink(first
);
187 dns_search_domain_unlink_all(next
);
190 void dns_search_domain_unlink_marked(DnsSearchDomain
*first
) {
191 DnsSearchDomain
*next
;
196 next
= first
->domains_next
;
199 dns_search_domain_unlink(first
);
201 dns_search_domain_unlink_marked(next
);
204 void dns_search_domain_mark_all(DnsSearchDomain
*first
) {
208 first
->marked
= true;
209 dns_search_domain_mark_all(first
->domains_next
);
212 int dns_search_domain_find(DnsSearchDomain
*first
, const char *name
, DnsSearchDomain
**ret
) {
219 LIST_FOREACH(domains
, d
, first
) {
221 r
= dns_name_equal(name
, d
->name
);