timesyncd-manager.h revision 63463bf091949e0178b749016828ec400c106582
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering#pragma once
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering/***
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering This file is part of systemd.
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering Copyright 2014 Kay Sievers, Lennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering systemd is free software; you can redistribute it and/or modify it
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering under the terms of the GNU Lesser General Public License as published by
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering (at your option) any later version.
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering systemd is distributed in the hope that it will be useful, but
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering Lesser General Public License for more details.
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering You should have received a copy of the GNU Lesser General Public License
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering***/
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering#include "sd-event.h"
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering#include "sd-resolve.h"
0dad12c190b7493955cd60d2a1625199b1709f69Lennart Poettering#include "sd-network.h"
0dad12c190b7493955cd60d2a1625199b1709f69Lennart Poettering#include "list.h"
72f1d5a2880d103dc1c1746f5c02e192e054705eLennart Poettering#include "socket-util.h"
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering#include "ratelimit.h"
b070e7f3c9ed680c821bd89d42506695f2438506Lennart Poettering
b070e7f3c9ed680c821bd89d42506695f2438506Lennart Poetteringtypedef struct Manager Manager;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering#include "timesyncd-server.h"
fe6521272ba203ec8f0d5a94f0729960b3f90525Lennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poetteringstruct Manager {
bb99a35a873c35e80b0b47fe045081022660374dLennart Poettering sd_event *event;
bb99a35a873c35e80b0b47fe045081022660374dLennart Poettering sd_resolve *resolve;
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering LIST_HEAD(ServerName, system_servers);
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering LIST_HEAD(ServerName, link_servers);
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering LIST_HEAD(ServerName, fallback_servers);
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering RateLimit ratelimit;
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering bool exhausted_servers;
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering /* network */
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering sd_event_source *network_event_source;
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poettering sd_network_monitor *network_monitor;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering /* peer */
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering sd_resolve_query *resolve_query;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering sd_event_source *event_receive;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering ServerName *current_server_name;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering ServerAddress *current_server_address;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering int server_socket;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering uint64_t packet_count;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering sd_event_source *event_timeout;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering /* last sent packet */
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering struct timespec trans_time_mon;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering struct timespec trans_time;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering usec_t retry_interval;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering bool pending;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering /* poll timer */
bb99a35a873c35e80b0b47fe045081022660374dLennart Poettering sd_event_source *event_timer;
bb99a35a873c35e80b0b47fe045081022660374dLennart Poettering usec_t poll_interval_usec;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering bool poll_resync;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering /* history data */
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering struct {
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering double offset;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering double delay;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering } samples[8];
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering unsigned int samples_idx;
a5344d2c3b0f14e954ce1c0ef905c5b44bc5bf0aLennart Poettering double samples_jitter;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering /* last change */
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering bool jumped;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering bool sync;
d0bbc21caa6e68693a47db60c93e99422bf2a858Lennart Poettering int drift_ppm;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering /* watch for time changes */
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering sd_event_source *event_clock_watch;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering int clock_watch_fd;
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
a5344d2c3b0f14e954ce1c0ef905c5b44bc5bf0aLennart Poettering /* Retry connections */
18c7ed186be28800a2eeb37ad31c9c44480d3d9cLennart Poettering sd_event_source *event_retry;
18c7ed186be28800a2eeb37ad31c9c44480d3d9cLennart Poettering
18c7ed186be28800a2eeb37ad31c9c44480d3d9cLennart Poettering /* RTC runs in local time, leave it alone */
18c7ed186be28800a2eeb37ad31c9c44480d3d9cLennart Poettering bool rtc_local_time;
18c7ed186be28800a2eeb37ad31c9c44480d3d9cLennart Poettering};
d0bbc21caa6e68693a47db60c93e99422bf2a858Lennart Poettering
1ae464e09376853c52075ec4d8a6bfc4b4036d0cThomas Hindoe Paaboel Andersenint manager_new(Manager **ret);
1ae464e09376853c52075ec4d8a6bfc4b4036d0cThomas Hindoe Paaboel Andersenvoid manager_free(Manager *m);
1ae464e09376853c52075ec4d8a6bfc4b4036d0cThomas Hindoe Paaboel Andersen
fe6521272ba203ec8f0d5a94f0729960b3f90525Lennart PoetteringDEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
d0bbc21caa6e68693a47db60c93e99422bf2a858Lennart Poettering
d0bbc21caa6e68693a47db60c93e99422bf2a858Lennart Poetteringvoid manager_set_server_name(Manager *m, ServerName *n);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poetteringvoid manager_set_server_address(Manager *m, ServerAddress *a);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poetteringvoid manager_flush_server_names(Manager *m, ServerType t);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poetteringint manager_connect(Manager *m);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poetteringvoid manager_disconnect(Manager *m);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering