1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 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/>.
23 #include "resolved-dns-domain.h"
24 #include "resolved-dns-scope.h"
26 #define SEND_TIMEOUT_USEC (2*USEC_PER_SEC)
28 int dns_scope_new(Manager *m, DnsScope **ret, DnsScopeType t) {
34 s = new0(DnsScope, 1);
41 LIST_PREPEND(scopes, m->dns_scopes, s);
47 DnsScope* dns_scope_free(DnsScope *s) {
51 while (s->transactions) {
54 q = s->transactions->query;
55 dns_query_transaction_free(s->transactions);
60 LIST_REMOVE(scopes, s->manager->dns_scopes, s);
61 strv_free(s->domains);
67 DnsServer *dns_scope_get_server(DnsScope *s) {
71 return link_get_dns_server(s->link);
73 return manager_get_dns_server(s->manager);
76 void dns_scope_next_dns_server(DnsScope *s) {
80 link_next_dns_server(s->link);
82 manager_next_dns_server(s->manager);
85 int dns_scope_send(DnsScope *s, DnsPacket *p) {
93 srv = dns_scope_get_server(s);
98 ifindex = s->link->ifindex;
100 if (srv->family == AF_INET)
101 r = manager_dns_ipv4_send(s->manager, srv, ifindex, p);
102 else if (srv->family == AF_INET6)
103 r = manager_dns_ipv6_send(s->manager, srv, ifindex, p);
105 return -EAFNOSUPPORT;
113 DnsScopeMatch dns_scope_test(DnsScope *s, const char *domain) {
119 STRV_FOREACH(i, s->domains)
120 if (dns_name_endswith(domain, *i))
121 return DNS_SCOPE_YES;
123 if (dns_name_root(domain))
126 if (s->type == DNS_SCOPE_MDNS) {
127 if (dns_name_endswith(domain, "254.169.in-addr.arpa") ||
128 dns_name_endswith(domain, "0.8.e.f.ip6.arpa"))
129 return DNS_SCOPE_YES;
130 else if (dns_name_endswith(domain, "local") ||
131 !dns_name_single_label(domain))
132 return DNS_SCOPE_MAYBE;
137 if (s->type == DNS_SCOPE_DNS) {
138 if (dns_name_endswith(domain, "254.169.in-addr.arpa") ||
139 dns_name_endswith(domain, "0.8.e.f.ip6.arpa") ||
140 dns_name_single_label(domain))
143 return DNS_SCOPE_MAYBE;
146 assert_not_reached("Unknown scope type");