resolved-manager.c revision b18b8662154b46f03ddeac00e52d157c87d474e3
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering This file is part of systemd.
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering Copyright 2014 Tom Gundersen <teg@jklm.no>
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering (at your option) any later version.
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering systemd is distributed in the hope that it will be useful, but
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering Lesser General Public License for more details.
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskog#define SEND_TIMEOUT_USEC (200 * USEC_PER_MSEC)
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskogstatic int manager_process_link(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek r = sd_netlink_message_get_type(mm, &type);
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering r = sd_rtnl_message_link_get_ifindex(mm, &ifindex);
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering l = hashmap_get(m->links, INT_TO_PTR(ifindex));
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering log_debug("Found new link %i/%s", ifindex, l->name);
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering log_debug("Removing link %i/%s", l->ifindex, l->name);
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt log_warning_errno(r, "Failed to process RTNL link message: %m");
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poetteringstatic int manager_process_address(sd_netlink *rtnl, sd_netlink_message *mm, void *userdata) {
LinkAddress *a;
Link *l;
assert(m);
goto fail;
goto fail;
goto fail;
switch (family) {
case AF_INET:
goto fail;
case AF_INET6:
goto fail;
switch (type) {
case RTM_NEWADDR:
case RTM_DELADDR:
fail:
assert(m);
Iterator i;
Link *l;
assert(m);
r = link_update_monitor(l);
r = manager_write_resolv_conf(m);
assert(m);
if (fd < 0)
return fd;
if (events < 0)
return events;
h = gethostname_malloc();
return log_oom();
return -EINVAL;
return -EINVAL;
if (is_localhost(n)) {
return -EINVAL;
*llmnr_hostname = n;
n = NULL;
assert(m);
assert(m);
if (m->hostname_fd < 0) {
if (r == -EPERM)
if (!m->llmnr_hostname)
return log_oom();
if (!m->mdns_hostname)
return log_oom();
assert(s);
assert(m);
return log_oom();
if (fflush_and_check(f) < 0)
return log_oom();
return -ENOMEM;
m->read_resolv_conf = true;
m->need_builtin_fallbacks = true;
r = manager_watch_hostname(m);
r = manager_network_monitor_listen(m);
r = manager_rtnl_listen(m);
r = manager_connect_bus(m);
*ret = m;
m = NULL;
assert(m);
r = manager_llmnr_start(m);
r = manager_mdns_start(m);
Link *l;
return NULL;
link_free(l);
while (m->dns_queries)
free(m);
return NULL;
} control;
int ms = 0, r;
ssize_t l;
assert(m);
return -errno;
if (ms < 0)
return -EIO;
return -errno;
return -EIO;
return -EAFNOSUPPORT;
case IPV6_PKTINFO: {
if (p->ifindex <= 0)
case IPV6_HOPLIMIT:
case IP_PKTINFO: {
if (p->ifindex <= 0)
case IP_TTL:
p->ifindex = 0;
if (p->ifindex <= 0)
*ret = p;
p = NULL;
return -errno;
return -ETIMEDOUT;
return -errno;
return -ETIMEDOUT;
log_debug("Sending %s packet with id %" PRIu16 ".", DNS_PACKET_QR(p) ? "response" : "query", DNS_PACKET_ID(p));
static int manager_ipv4_send(Manager *m, int fd, int ifindex, const struct in_addr *addr, uint16_t port, DnsPacket *p) {
} control;
assert(m);
assert(p);
if (ifindex > 0) {
static int manager_ipv6_send(Manager *m, int fd, int ifindex, const struct in6_addr *addr, uint16_t port, DnsPacket *p) {
} control;
assert(m);
assert(p);
if (ifindex > 0) {
int manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *addr, uint16_t port, DnsPacket *p) {
assert(m);
assert(p);
log_debug("Sending %s packet with id %" PRIu16 " on interface %i/%s.", DNS_PACKET_QR(p) ? "response" : "query", DNS_PACKET_ID(p), ifindex, af_to_name(family));
return -EAFNOSUPPORT;
Link *l;
Iterator i;
if (l->mtu <= 0)
return mtu;
LinkAddress *a;
assert(m);
Iterator i;
Link *l;
assert(m);
link_add_rrs(l, true);
link_add_rrs(l, false);
uint64_t u, a;
assert(m);
assert(p);
while (p > m->llmnr_hostname) {
if (*p == 0 || safe_atou64(p, &u) < 0 || u <= 0)
random_bytes(&a, sizeof(a));
return -ENOMEM;
free(h);
log_info("Hostname conflict, changing published hostname from '%s' to '%s'.", m->llmnr_hostname, h);
m->llmnr_hostname = h;
m->mdns_hostname = k;
LinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr) {
Iterator i;
Link *l;
assert(m);
LinkAddress *a;
return NULL;
assert(m);
assert(p);
Link *l;
assert(m);
assert(p);
return NULL;
switch (p->protocol) {
case DNS_PROTOCOL_LLMNR:
return l->llmnr_ipv4_scope;
return l->llmnr_ipv6_scope;
case DNS_PROTOCOL_MDNS:
return l->mdns_ipv4_scope;
return l->mdns_ipv6_scope;
return NULL;
DnsScope *s;
assert(m);
assert(m);
if (m->llmnr_hostname) {
if (m->mdns_hostname)
DnsServer *s;
Iterator i;
Link *l;
assert(m);
if (r == -EEXIST)
if (r == -EEXIST)
if (r == -EEXIST)
DnsSearchDomain *d;
Iterator i;
Link *l;
assert(m);
if (r == -EEXIST)
if (r == -EEXIST)