]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/timesync/timesyncd-manager.h
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / timesync / timesyncd-manager.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
84e51726
LP
2#pragma once
3
e8af6973 4/***
96b2fb93 5 Copyright © 2014 Kay Sievers
e8af6973
LP
6***/
7
66086a40
YW
8#include <sys/timex.h>
9
e7dd3947 10#include "sd-bus.h"
e8af6973 11#include "sd-event.h"
e0e5ce23 12#include "sd-network.h"
71d35b6b
TA
13#include "sd-resolve.h"
14
84e51726 15#include "list.h"
84e51726 16#include "ratelimit.h"
a4465d0d 17#include "time-util.h"
66086a40 18#include "timesyncd-ntp-message.h"
e8af6973
LP
19
20typedef struct Manager Manager;
ae2db4e7 21
874ff7bf
LP
22#include "timesyncd-server.h"
23
a4465d0d
YW
24/*
25 * "A client MUST NOT under any conditions use a poll interval less
26 * than 15 seconds."
27 */
28#define NTP_POLL_INTERVAL_MIN_USEC (32 * USEC_PER_SEC)
29#define NTP_POLL_INTERVAL_MAX_USEC (2048 * USEC_PER_SEC)
30
e8af6973 31struct Manager {
e7dd3947 32 sd_bus *bus;
e8af6973
LP
33 sd_event *event;
34 sd_resolve *resolve;
35
874ff7bf 36 LIST_HEAD(ServerName, system_servers);
84e51726 37 LIST_HEAD(ServerName, link_servers);
84e51726 38 LIST_HEAD(ServerName, fallback_servers);
e8af6973 39
3745770a
MB
40 bool have_fallbacks:1;
41
e8af6973 42 RateLimit ratelimit;
63463bf0 43 bool exhausted_servers;
e8af6973 44
e0e5ce23
TG
45 /* network */
46 sd_event_source *network_event_source;
47 sd_network_monitor *network_monitor;
48
e8af6973
LP
49 /* peer */
50 sd_resolve_query *resolve_query;
51 sd_event_source *event_receive;
52 ServerName *current_server_name;
53 ServerAddress *current_server_address;
54 int server_socket;
e8206972 55 int missed_replies;
e8af6973
LP
56 uint64_t packet_count;
57 sd_event_source *event_timeout;
481b3f9e 58 bool good;
e8af6973
LP
59
60 /* last sent packet */
61 struct timespec trans_time_mon;
62 struct timespec trans_time;
ab4df227 63 usec_t retry_interval;
e8af6973
LP
64 bool pending;
65
66 /* poll timer */
67 sd_event_source *event_timer;
68 usec_t poll_interval_usec;
a4465d0d
YW
69 usec_t poll_interval_min_usec;
70 usec_t poll_interval_max_usec;
e8af6973
LP
71 bool poll_resync;
72
73 /* history data */
74 struct {
75 double offset;
76 double delay;
77 } samples[8];
78 unsigned int samples_idx;
79 double samples_jitter;
f907cc16 80 usec_t max_root_distance_usec;
e8af6973
LP
81
82 /* last change */
83 bool jumped;
d636d376 84 bool sync;
66086a40 85 long drift_freq;
e8af6973
LP
86
87 /* watch for time changes */
88 sd_event_source *event_clock_watch;
89 int clock_watch_fd;
90
91 /* Retry connections */
92 sd_event_source *event_retry;
c264aeab
KS
93
94 /* RTC runs in local time, leave it alone */
95 bool rtc_local_time;
66086a40
YW
96
97 /* NTP response */
98 struct ntp_msg ntpmsg;
99 struct timespec origin_time, dest_time;
100 bool spike;
e8af6973
LP
101};
102
84e51726
LP
103int manager_new(Manager **ret);
104void manager_free(Manager *m);
105
106DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
e8af6973 107
874ff7bf
LP
108void manager_set_server_name(Manager *m, ServerName *n);
109void manager_set_server_address(Manager *m, ServerAddress *a);
110void manager_flush_server_names(Manager *m, ServerType t);
111
84e51726
LP
112int manager_connect(Manager *m);
113void manager_disconnect(Manager *m);