resolved-manager.h revision 72290734be81e83e6ef9520c07692f68095eb5b2
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#pragma once
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering/***
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering This file is part of systemd.
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering Copyright 2014 Tom Gundersen <teg@jklm.no>
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering systemd is free software; you can redistribute it and/or modify it
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering under the terms of the GNU Lesser General Public License as published by
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering (at your option) any later version.
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering systemd is distributed in the hope that it will be useful, but
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering Lesser General Public License for more details.
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering You should have received a copy of the GNU Lesser General Public License
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering***/
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "sd-event.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "sd-network.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "sd-netlink.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "list.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "hashmap.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringtypedef struct Manager Manager;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringtypedef enum Support Support;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringenum Support {
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering SUPPORT_NO,
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering SUPPORT_YES,
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering SUPPORT_RESOLVE,
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering _SUPPORT_MAX,
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering _SUPPORT_INVALID = -1
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering};
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "resolved-dns-query.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "resolved-dns-stream.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#include "resolved-link.h"
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringstruct Manager {
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event *event;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering Support llmnr_support;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering /* Network */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering Hashmap *links;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_netlink *rtnl;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *rtnl_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_network_monitor *network_monitor;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *network_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering /* DNS query management */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering Hashmap *dns_transactions;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering LIST_HEAD(DnsQuery, dns_queries);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering unsigned n_dns_queries;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering LIST_HEAD(DnsStream, dns_streams);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering unsigned n_dns_streams;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering /* Unicast dns */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering LIST_HEAD(DnsServer, dns_servers);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering LIST_HEAD(DnsServer, fallback_dns_servers);
a71fe8b8aee1cb78c4d8c56eeb234743f64e4b4dLennart Poettering DnsServer *current_dns_server;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering bool read_resolv_conf;
a71fe8b8aee1cb78c4d8c56eeb234743f64e4b4dLennart Poettering usec_t resolv_conf_mtime;
a71fe8b8aee1cb78c4d8c56eeb234743f64e4b4dLennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering LIST_HEAD(DnsScope, dns_scopes);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering DnsScope *unicast_scope;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
c9fe4af70d2c884c1f95714a81ad6d1de31d5186Michal Schmidt /* LLMNR */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering int llmnr_ipv4_udp_fd;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering int llmnr_ipv6_udp_fd;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering int llmnr_ipv4_tcp_fd;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering int llmnr_ipv6_tcp_fd;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *llmnr_ipv4_udp_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *llmnr_ipv6_udp_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *llmnr_ipv4_tcp_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *llmnr_ipv6_tcp_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering /* dbus */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_bus *bus;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *bus_retry_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering /* The hostname we publish on LLMNR and mDNS */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering char *hostname;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering DnsResourceKey *host_ipv4_key;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering DnsResourceKey *host_ipv6_key;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering /* Watch the system hostname */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering int hostname_fd;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_event_source *hostname_event_source;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering /* Watch for system suspends */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering sd_bus_slot *prepare_for_sleep_slot;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering};
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering/* Manager */
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_new(Manager **ret);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart PoetteringManager* manager_free(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_start(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_read_resolv_conf(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_write_resolv_conf(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart PoetteringDnsServer *manager_set_dns_server(Manager *m, DnsServer *s);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart PoetteringDnsServer *manager_find_dns_server(Manager *m, int family, const union in_addr_union *in_addr);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart PoetteringDnsServer *manager_get_dns_server(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringvoid manager_next_dns_server(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringuint32_t manager_find_mtu(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_write(Manager *m, int fd, DnsPacket *p);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_send(Manager *m, int fd, int ifindex, int family, const union in_addr_union *addr, uint16_t port, DnsPacket *p);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_find_ifindex(Manager *m, int family, const union in_addr_union *in_addr);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart PoetteringLinkAddress* manager_find_link_address(Manager *m, int family, const union in_addr_union *in_addr);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringvoid manager_refresh_rrs(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint manager_next_hostname(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringbool manager_our_packet(Manager *m, DnsPacket *p);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart PoetteringDnsScope* manager_find_scope(Manager *m, DnsPacket *p);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringvoid manager_verify_all(Manager *m);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringvoid manager_flush_dns_servers(Manager *m, DnsServerType t);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering#define EXTRA_CMSG_SPACE 1024
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringconst char* support_to_string(Support p) _const_;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poetteringint support_from_string(const char *s) _pure_;
19befb2d5fc087f96e40ddc432b2cc9385666209Lennart Poettering