resolved-manager.h revision edc501d4674dadc304d45a7e1c5b69e207eb8cd4
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#pragma once
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering/***
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering This file is part of systemd.
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Copyright 2014 Tom Gundersen <teg@jklm.no>
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is free software; you can redistribute it and/or modify it
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering under the terms of the GNU Lesser General Public License as published by
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering (at your option) any later version.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering systemd is distributed in the hope that it will be useful, but
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Lesser General Public License for more details.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering You should have received a copy of the GNU Lesser General Public License
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering***/
a9cdc94f7ff40f22a3cf9472f612a80730a1b010Dave Reisner
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "sd-event.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "sd-network.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "sd-rtnl.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "util.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "list.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "in-addr-util.h"
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers#include "hashmap.h"
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sieverstypedef struct Manager Manager;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-dns-query.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-dns-server.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-dns-scope.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-dns-stream.h"
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#include "resolved-link.h"
0732ef7acf37473847992888bcb6446726d9d877Zbigniew Jędrzejewski-Szmek
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletartypedef enum Support {
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar SUPPORT_NO,
7568345034f2890af745747783c5abfbf6eccf0fLennart Poettering SUPPORT_YES,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering SUPPORT_RESOLVE,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _SUPPORT_MAX,
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering _SUPPORT_INVALID = -1
4d7859d173282e16bb75254c2b4ec14a915ef30bKay Sievers} Support;
7085053a437456ab87d726f3697002dd811fdf7aDaniel Wallace
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringstruct Manager {
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event *event;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Support llmnr_support;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Network */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *links;
1b12a7b5896f94bdf33b3a6661ebabd761ea6adcHarald Hoyer
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_rtnl *rtnl;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event_source *rtnl_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_network_monitor *network_monitor;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering sd_event_source *network_event_source;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* DNS query management */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering Hashmap *dns_transactions;
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering LIST_HEAD(DnsQuery, dns_queries);
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering unsigned n_dns_queries;
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(DnsStream, dns_streams);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering unsigned n_dns_streams;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering /* Unicast dns */
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering int dns_ipv4_fd;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann int dns_ipv6_fd;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann sd_event_source *dns_ipv4_event_source;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann sd_event_source *dns_ipv6_event_source;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann LIST_HEAD(DnsServer, dns_servers);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering LIST_HEAD(DnsServer, fallback_dns_servers);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering DnsServer *current_dns_server;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann bool read_resolv_conf;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann usec_t resolv_conf_mtime;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann LIST_HEAD(DnsScope, dns_scopes);
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann DnsScope *unicast_scope;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann /* LLMNR */
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann int llmnr_ipv4_udp_fd;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann int llmnr_ipv6_udp_fd;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann int llmnr_ipv4_tcp_fd;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann int llmnr_ipv6_tcp_fd;
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann
ff9b60f38bf68eba4a47cabff14547d92e083214Torstein Husebø sd_event_source *llmnr_ipv4_udp_event_source;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar sd_event_source *llmnr_ipv6_udp_event_source;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar sd_event_source *llmnr_ipv4_tcp_event_source;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar sd_event_source *llmnr_ipv6_tcp_event_source;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar /* dbus */
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar sd_bus *bus;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar sd_event_source *bus_retry_event_source;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar /* The hostname we publish on LLMNR and mDNS */
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar char *hostname;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar DnsResourceKey *host_ipv4_key;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar DnsResourceKey *host_ipv6_key;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar /* Watch the system hostname */
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar int hostname_fd;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar sd_event_source *hostname_event_source;
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar};
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar/* Manager */
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_new(Manager **ret);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal SekletarManager* manager_free(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_start(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_read_resolv_conf(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_write_resolv_conf(Manager *m);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal SekletarDnsServer *manager_set_dns_server(Manager *m, DnsServer *s);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal SekletarDnsServer *manager_find_dns_server(Manager *m, int family, const union in_addr_union *in_addr);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal SekletarDnsServer *manager_get_dns_server(Manager *m);
63229aa1abdb98aa69fda9819ed2f40c8082762bLennart Poetteringvoid manager_next_dns_server(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletaruint32_t manager_find_mtu(Manager *m);
b344bcbbfda8fbe14dadc5aa4b5dfb3ced6d76e2Lennart Poettering
ff49bc3212cb07d850dcfd59940539773a0be26fMichal Schmidtint manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *addr, uint16_t port, DnsPacket *p);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
b344bcbbfda8fbe14dadc5aa4b5dfb3ced6d76e2Lennart Poetteringint manager_dns_ipv4_fd(Manager *m);
ff49bc3212cb07d850dcfd59940539773a0be26fMichal Schmidtint manager_dns_ipv6_fd(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_llmnr_ipv4_udp_fd(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_llmnr_ipv6_udp_fd(Manager *m);
63229aa1abdb98aa69fda9819ed2f40c8082762bLennart Poetteringint manager_llmnr_ipv4_tcp_fd(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_llmnr_ipv6_tcp_fd(Manager *m);
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletar
a34286684ebb78dd3db0d7f34feb2c121c9d00ccMichal Sekletarint manager_ifindex_is_loopback(Manager *m, int ifindex);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringLinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringvoid manager_refresh_rrs(Manager *m);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint manager_next_hostname(Manager *m);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint manager_our_packet(Manager *m, DnsPacket *p);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering#define EXTRA_CMSG_SPACE 1024
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringconst char* support_to_string(Support p) _const_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poetteringint support_from_string(const char *s) _pure_;
2087a7aff26ea5d1bc2c7c29add3275328f36baaLennart Poettering