]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/timesync/timesyncd-manager.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / timesync / timesyncd-manager.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2014 Kay Sievers, Lennart Poettering
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include "sd-event.h"
24 #include "sd-network.h"
25 #include "sd-resolve.h"
26
27 #include "list.h"
28 #include "ratelimit.h"
29 #include "time-util.h"
30
31 typedef struct Manager Manager;
32
33 #include "timesyncd-server.h"
34
35 /*
36 * "A client MUST NOT under any conditions use a poll interval less
37 * than 15 seconds."
38 */
39 #define NTP_POLL_INTERVAL_MIN_USEC (32 * USEC_PER_SEC)
40 #define NTP_POLL_INTERVAL_MAX_USEC (2048 * USEC_PER_SEC)
41
42 struct Manager {
43 sd_event *event;
44 sd_resolve *resolve;
45
46 LIST_HEAD(ServerName, system_servers);
47 LIST_HEAD(ServerName, link_servers);
48 LIST_HEAD(ServerName, fallback_servers);
49
50 bool have_fallbacks:1;
51
52 RateLimit ratelimit;
53 bool exhausted_servers;
54
55 /* network */
56 sd_event_source *network_event_source;
57 sd_network_monitor *network_monitor;
58
59 /* peer */
60 sd_resolve_query *resolve_query;
61 sd_event_source *event_receive;
62 ServerName *current_server_name;
63 ServerAddress *current_server_address;
64 int server_socket;
65 int missed_replies;
66 uint64_t packet_count;
67 sd_event_source *event_timeout;
68 bool good;
69
70 /* last sent packet */
71 struct timespec trans_time_mon;
72 struct timespec trans_time;
73 usec_t retry_interval;
74 bool pending;
75
76 /* poll timer */
77 sd_event_source *event_timer;
78 usec_t poll_interval_usec;
79 usec_t poll_interval_min_usec;
80 usec_t poll_interval_max_usec;
81 bool poll_resync;
82
83 /* history data */
84 struct {
85 double offset;
86 double delay;
87 } samples[8];
88 unsigned int samples_idx;
89 double samples_jitter;
90 usec_t max_root_distance_usec;
91
92 /* last change */
93 bool jumped;
94 bool sync;
95 int drift_ppm;
96
97 /* watch for time changes */
98 sd_event_source *event_clock_watch;
99 int clock_watch_fd;
100
101 /* Retry connections */
102 sd_event_source *event_retry;
103
104 /* RTC runs in local time, leave it alone */
105 bool rtc_local_time;
106 };
107
108 int manager_new(Manager **ret);
109 void manager_free(Manager *m);
110
111 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
112
113 void manager_set_server_name(Manager *m, ServerName *n);
114 void manager_set_server_address(Manager *m, ServerAddress *a);
115 void manager_flush_server_names(Manager *m, ServerType t);
116
117 int manager_connect(Manager *m);
118 void manager_disconnect(Manager *m);