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