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