resolved-link.c revision b26fa1a2fbcfee7d03b0c8fd15ec3aa64ae70b9f
/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-network.h"
#include "alloc-util.h"
#include "missing.h"
#include "parse-util.h"
#include "resolved-link.h"
#include "string-util.h"
#include "strv.h"
int r;
assert(m);
if (r < 0)
return r;
if (!l)
return -ENOMEM;
l->operstate = IF_OPER_UNKNOWN;
if (r < 0)
return r;
l->manager = m;
if (ret)
*ret = l;
l = NULL;
return 0;
}
void link_flush_settings(Link *l) {
assert(l);
}
if (!l)
return NULL;
while (l->addresses)
(void) link_address_free(l->addresses);
if (l->manager)
free(l);
return NULL;
}
void link_allocate_scopes(Link *l) {
int r;
assert(l);
if (link_relevant(l, AF_UNSPEC, false) &&
l->dns_servers) {
if (!l->unicast_scope) {
if (r < 0)
log_warning_errno(r, "Failed to allocate DNS scope: %m");
}
} else
if (link_relevant(l, AF_INET, true) &&
l->llmnr_support != RESOLVE_SUPPORT_NO &&
if (!l->llmnr_ipv4_scope) {
if (r < 0)
log_warning_errno(r, "Failed to allocate LLMNR IPv4 scope: %m");
}
} else
if (link_relevant(l, AF_INET6, true) &&
l->llmnr_support != RESOLVE_SUPPORT_NO &&
if (!l->llmnr_ipv6_scope) {
if (r < 0)
log_warning_errno(r, "Failed to allocate LLMNR IPv6 scope: %m");
}
} else
if (link_relevant(l, AF_INET, true) &&
l->mdns_support != RESOLVE_SUPPORT_NO &&
if (!l->mdns_ipv4_scope) {
if (r < 0)
log_warning_errno(r, "Failed to allocate mDNS IPv4 scope: %m");
}
} else
if (link_relevant(l, AF_INET6, true) &&
l->mdns_support != RESOLVE_SUPPORT_NO &&
if (!l->mdns_ipv6_scope) {
if (r < 0)
log_warning_errno(r, "Failed to allocate mDNS IPv6 scope: %m");
}
} else
}
LinkAddress *a;
}
const char *n = NULL;
int r;
assert(l);
assert(m);
r = sd_rtnl_message_link_get_flags(m, &l->flags);
if (r < 0)
return r;
if (sd_netlink_message_read_string(m, IFLA_IFNAME, &n) >= 0) {
char_array_0(l->name);
}
link_add_rrs(l, false);
return 0;
}
static int link_update_dns_servers(Link *l) {
char **nameserver;
int r;
assert(l);
if (r == -ENODATA) {
r = 0;
goto clear;
}
if (r < 0)
goto clear;
union in_addr_union a;
DnsServer *s;
int family;
if (r < 0)
goto clear;
if (s)
else {
if (r < 0)
goto clear;
}
}
return 0;
return r;
}
static int link_update_llmnr_support(Link *l) {
_cleanup_free_ char *b = NULL;
int r;
assert(l);
r = sd_network_link_get_llmnr(l->ifindex, &b);
if (r == -ENODATA) {
r = 0;
goto clear;
}
if (r < 0)
goto clear;
l->llmnr_support = resolve_support_from_string(b);
if (l->llmnr_support < 0) {
r = -EINVAL;
goto clear;
}
return 0;
return r;
}
static int link_update_mdns_support(Link *l) {
_cleanup_free_ char *b = NULL;
int r;
assert(l);
r = sd_network_link_get_mdns(l->ifindex, &b);
if (r == -ENODATA) {
r = 0;
goto clear;
}
if (r < 0)
goto clear;
l->mdns_support = resolve_support_from_string(b);
if (l->mdns_support < 0) {
r = -EINVAL;
goto clear;
}
return 0;
return r;
}
assert(l);
if (l->dnssec_mode == mode)
return;
if ((l->dnssec_mode == _DNSSEC_MODE_INVALID) ||
/* When switching from non-DNSSEC mode to DNSSEC mode, flush the cache. Also when switching from the
* allow-downgrade mode to full DNSSEC mode, flush it too. */
if (l->unicast_scope)
}
l->dnssec_mode = mode;
}
static int link_update_dnssec_mode(Link *l) {
_cleanup_free_ char *m = NULL;
int r;
assert(l);
r = sd_network_link_get_dnssec(l->ifindex, &m);
if (r == -ENODATA) {
r = 0;
goto clear;
}
if (r < 0)
goto clear;
mode = dnssec_mode_from_string(m);
if (mode < 0) {
r = -EINVAL;
goto clear;
}
link_set_dnssec_mode(l, mode);
return 0;
return r;
}
static int link_update_dnssec_negative_trust_anchors(Link *l) {
char **i;
int r;
assert(l);
if (r == -ENODATA) {
r = 0;
goto clear;
}
if (r < 0)
goto clear;
if (!ns)
return -ENOMEM;
STRV_FOREACH(i, ntas) {
r = set_put_strdup(ns, *i);
if (r < 0)
return r;
}
return 0;
return r;
}
DnsSearchDomain *d;
int r;
if (r < 0)
return r;
if (r > 0)
else {
if (r < 0)
return r;
}
d->route_only = route_only;
return 0;
}
static int link_update_search_domains(Link *l) {
char **i;
int r, q;
assert(l);
if (r < 0 && r != -ENODATA)
goto clear;
if (q < 0 && q != -ENODATA) {
r = q;
goto clear;
}
/* networkd knows nothing about this interface, and that's fine. */
r = 0;
goto clear;
}
STRV_FOREACH(i, sdomains) {
r = link_update_search_domain_one(l, *i, false);
if (r < 0)
goto clear;
}
STRV_FOREACH(i, rdomains) {
r = link_update_search_domain_one(l, *i, true);
if (r < 0)
goto clear;
}
return 0;
return r;
}
static int link_is_unmanaged(Link *l) {
int r;
assert(l);
if (r == -ENODATA)
return 1;
if (r < 0)
return r;
}
static void link_read_settings(Link *l) {
int r;
assert(l);
/* Read settings from networkd, except when networkd is not managing this interface. */
r = link_is_unmanaged(l);
if (r < 0) {
return;
}
if (r > 0) {
/* If this link used to be managed, but is now unmanaged, flush all our settings -- but only once. */
if (l->is_managed)
l->is_managed = false;
return;
}
l->is_managed = true;
r = link_update_dns_servers(l);
if (r < 0)
r = link_update_llmnr_support(l);
if (r < 0)
r = link_update_mdns_support(l);
if (r < 0)
r = link_update_dnssec_mode(l);
if (r < 0)
if (r < 0)
log_warning_errno(r, "Failed to read DNSSEC negative trust anchors for interface %s, ignoring: %m", l->name);
r = link_update_search_domains(l);
if (r < 0)
}
int link_update_monitor(Link *l) {
assert(l);
link_add_rrs(l, false);
return 0;
}
LinkAddress *a;
assert(l);
/* A link is relevant for local multicast traffic if it isn't a loopback or pointopoint device, has a link
* beat, can do multicast and has at least one link-local (or better) IP address.
*
* A link is relevant for non-multicast traffic if it isn't a loopback device, has a link beat, and has at
* least one routable address.*/
return false;
return false;
if (local_multicast) {
if (l->flags & IFF_POINTOPOINT)
return false;
return false;
}
/* Check kernel operstate
return false;
return false;
return true;
return false;
}
LinkAddress *a;
assert(l);
return a;
return NULL;
}
assert(l);
if (l->current_dns_server == s)
return s;
if (s)
l->current_dns_server = dns_server_ref(s);
if (l->unicast_scope)
return s;
}
assert(l);
if (!l->current_dns_server)
link_set_dns_server(l, l->dns_servers);
return l->current_dns_server;
}
void link_next_dns_server(Link *l) {
assert(l);
if (!l->current_dns_server)
return;
/* Change to the next one, but make sure to follow the linked
* list only if this server is actually still linked. */
return;
}
link_set_dns_server(l, l->dns_servers);
}
assert(l);
if (l->dnssec_mode != _DNSSEC_MODE_INVALID)
return l->dnssec_mode;
return manager_get_dnssec_mode(l->manager);
}
bool link_dnssec_supported(Link *l) {
assert(l);
if (link_get_dnssec_mode(l) == DNSSEC_NO)
return false;
server = link_get_dns_server(l);
if (server)
return dns_server_dnssec_supported(server);
return true;
}
LinkAddress *a;
assert(l);
if (!a)
return -ENOMEM;
a->link = l;
if (ret)
*ret = a;
return 0;
}
if (!a)
return NULL;
if (a->link) {
if (a->llmnr_address_rr) {
}
if (a->llmnr_ptr_rr) {
}
}
free(a);
return NULL;
}
int r;
assert(a);
if (!force_remove &&
link_address_relevant(a, true) &&
a->link->llmnr_ipv4_scope &&
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);
if (r < 0)
goto fail;
}
r = dns_zone_put(&a->link->llmnr_ipv4_scope->zone, a->link->llmnr_ipv4_scope, a->llmnr_address_rr, true);
if (r < 0)
log_warning_errno(r, "Failed to add A record to LLMNR zone: %m");
r = dns_zone_put(&a->link->llmnr_ipv4_scope->zone, a->link->llmnr_ipv4_scope, a->llmnr_ptr_rr, false);
if (r < 0)
log_warning_errno(r, "Failed to add IPv6 PTR record to LLMNR zone: %m");
} else {
if (a->llmnr_address_rr) {
if (a->link->llmnr_ipv4_scope)
}
if (a->llmnr_ptr_rr) {
if (a->link->llmnr_ipv4_scope)
}
}
}
if (!force_remove &&
link_address_relevant(a, true) &&
a->link->llmnr_ipv6_scope &&
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);
if (r < 0)
goto fail;
}
r = dns_zone_put(&a->link->llmnr_ipv6_scope->zone, a->link->llmnr_ipv6_scope, a->llmnr_address_rr, true);
if (r < 0)
log_warning_errno(r, "Failed to add AAAA record to LLMNR zone: %m");
r = dns_zone_put(&a->link->llmnr_ipv6_scope->zone, a->link->llmnr_ipv6_scope, a->llmnr_ptr_rr, false);
if (r < 0)
log_warning_errno(r, "Failed to add IPv6 PTR record to LLMNR zone: %m");
} else {
if (a->llmnr_address_rr) {
if (a->link->llmnr_ipv6_scope)
}
if (a->llmnr_ptr_rr) {
if (a->link->llmnr_ipv6_scope)
}
}
}
return;
fail:
log_debug_errno(r, "Failed to update address RRs: %m");
}
int r;
assert(a);
assert(m);
r = sd_rtnl_message_addr_get_flags(m, &a->flags);
if (r < 0)
return r;
sd_rtnl_message_addr_get_scope(m, &a->scope);
link_allocate_scopes(a->link);
link_add_rrs(a->link, false);
return 0;
}
assert(a);
return false;
return false;
return true;
}