resolved-link.c revision 00f0a16ab4576535021456f8955446d3ae8f0b5f
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier This file is part of systemd.
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier Copyright 2014 Lennart Poettering
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier systemd is free software; you can redistribute it and/or modify it
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier under the terms of the GNU Lesser General Public License as published by
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier the Free Software Foundation; either version 2.1 of the License, or
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier (at your option) any later version.
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier systemd is distributed in the hope that it will be useful, but
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier WITHOUT ANY WARRANTY; without even the implied warranty of
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier Lesser General Public License for more details.
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier You should have received a copy of the GNU Lesser General Public License
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier along with systemd; If not, see <http://www.gnu.org/licenses/>.
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalierint link_new(Manager *m, Link **ret, int ifindex) {
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier r = hashmap_ensure_allocated(&m->links, NULL);
cda134ab1eac84f874aacf8e885a07112a7fd5ceLennart Poettering r = hashmap_put(m->links, INT_TO_PTR(ifindex), l);
cda134ab1eac84f874aacf8e885a07112a7fd5ceLennart Poettering dns_search_domain_unlink_all(l->search_domains);
cda134ab1eac84f874aacf8e885a07112a7fd5ceLennart Poettering hashmap_remove(l->manager->links, INT_TO_PTR(l->ifindex));
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier r = dns_scope_new(l->manager, &l->unicast_scope, l, DNS_PROTOCOL_DNS, AF_UNSPEC);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier log_warning_errno(r, "Failed to allocate DNS scope: %m");
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier l->unicast_scope = dns_scope_free(l->unicast_scope);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier l->manager->llmnr_support != RESOLVE_SUPPORT_NO) {
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier r = dns_scope_new(l->manager, &l->llmnr_ipv4_scope, l, DNS_PROTOCOL_LLMNR, AF_INET);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier log_warning_errno(r, "Failed to allocate LLMNR IPv4 scope: %m");
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier l->llmnr_ipv4_scope = dns_scope_free(l->llmnr_ipv4_scope);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier l->manager->llmnr_support != RESOLVE_SUPPORT_NO &&
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier r = dns_scope_new(l->manager, &l->llmnr_ipv6_scope, l, DNS_PROTOCOL_LLMNR, AF_INET6);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier log_warning_errno(r, "Failed to allocate LLMNR IPv6 scope: %m");
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier l->llmnr_ipv6_scope = dns_scope_free(l->llmnr_ipv6_scope);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier l->manager->mdns_support != RESOLVE_SUPPORT_NO) {
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier r = dns_scope_new(l->manager, &l->mdns_ipv4_scope, l, DNS_PROTOCOL_MDNS, AF_INET);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier log_warning_errno(r, "Failed to allocate mDNS IPv4 scope: %m");
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier l->mdns_ipv4_scope = dns_scope_free(l->mdns_ipv4_scope);
cda134ab1eac84f874aacf8e885a07112a7fd5ceLennart Poettering l->manager->mdns_support != RESOLVE_SUPPORT_NO) {
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier r = dns_scope_new(l->manager, &l->mdns_ipv6_scope, l, DNS_PROTOCOL_MDNS, AF_INET6);
641d1f99b8c4c5427a1fedcb4740586a130ac6cfRonny Chevalier log_warning_errno(r, "Failed to allocate mDNS IPv6 scope: %m");
LinkAddress *a;
const char *n = NULL;
assert(l);
assert(m);
link_add_rrs(l, false);
char **nameserver;
assert(l);
if (r == -ENODATA) {
goto clear;
goto clear;
union in_addr_union a;
DnsServer *s;
int family;
goto clear;
goto clear;
assert(l);
if (r == -ENODATA) {
goto clear;
goto clear;
if (l->llmnr_support < 0) {
r = -EINVAL;
goto clear;
assert(l);
if (r == -ENODATA) {
goto clear;
goto clear;
if (l->mdns_support < 0) {
r = -EINVAL;
goto clear;
assert(l);
if (r == -ENODATA) {
goto clear;
goto clear;
DnsSearchDomain *d;
goto clear;
goto clear;
assert(l);
r = link_update_search_domains(l);
link_add_rrs(l, false);
LinkAddress *a;
assert(l);
LinkAddress *a;
assert(l);
return NULL;
assert(l);
if (l->current_dns_server == s)
if (l->unicast_scope)
assert(l);
if (!l->current_dns_server)
return l->current_dns_server;
assert(l);
if (!l->current_dns_server)
LinkAddress *a;
assert(l);
return -ENOMEM;
a->link = l;
if (ret)
*ret = a;
return NULL;
if (a->link) {
if (a->llmnr_address_rr) {
if (a->llmnr_ptr_rr) {
free(a);
return NULL;
assert(a);
if (!force_remove &&
link_address_relevant(a) &&
a->link->manager->llmnr_host_ipv4_key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, a->link->manager->llmnr_hostname);
r = -ENOMEM;
goto fail;
if (!a->llmnr_address_rr) {
if (!a->llmnr_address_rr) {
r = -ENOMEM;
goto fail;
if (!a->llmnr_ptr_rr) {
r = dns_resource_record_new_reverse(&a->llmnr_ptr_rr, a->family, &a->in_addr, a->link->manager->llmnr_hostname);
goto fail;
r = dns_zone_put(&a->link->llmnr_ipv4_scope->zone, a->link->llmnr_ipv4_scope, a->llmnr_address_rr, true);
r = dns_zone_put(&a->link->llmnr_ipv4_scope->zone, a->link->llmnr_ipv4_scope, a->llmnr_ptr_rr, false);
if (a->llmnr_address_rr) {
if (a->llmnr_ptr_rr) {
if (!force_remove &&
link_address_relevant(a) &&
a->link->manager->llmnr_host_ipv6_key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_AAAA, a->link->manager->llmnr_hostname);
r = -ENOMEM;
goto fail;
if (!a->llmnr_address_rr) {
if (!a->llmnr_address_rr) {
r = -ENOMEM;
goto fail;
if (!a->llmnr_ptr_rr) {
r = dns_resource_record_new_reverse(&a->llmnr_ptr_rr, a->family, &a->in_addr, a->link->manager->llmnr_hostname);
goto fail;
r = dns_zone_put(&a->link->llmnr_ipv6_scope->zone, a->link->llmnr_ipv6_scope, a->llmnr_address_rr, true);
r = dns_zone_put(&a->link->llmnr_ipv6_scope->zone, a->link->llmnr_ipv6_scope, a->llmnr_ptr_rr, false);
if (a->llmnr_address_rr) {
if (a->llmnr_ptr_rr) {
fail:
assert(a);
assert(m);
assert(a);