]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
84e51726 LP |
2 | #pragma once |
3 | ||
e8af6973 LP |
4 | /*** |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2014 Kay Sievers, Lennart Poettering | |
e8af6973 LP |
8 | ***/ |
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" |
e8af6973 LP |
18 | |
19 | typedef struct Manager Manager; | |
ae2db4e7 | 20 | |
874ff7bf LP |
21 | #include "timesyncd-server.h" |
22 | ||
a4465d0d YW |
23 | /* |
24 | * "A client MUST NOT under any conditions use a poll interval less | |
25 | * than 15 seconds." | |
26 | */ | |
27 | #define NTP_POLL_INTERVAL_MIN_USEC (32 * USEC_PER_SEC) | |
28 | #define NTP_POLL_INTERVAL_MAX_USEC (2048 * USEC_PER_SEC) | |
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]; | |
77 | unsigned int samples_idx; | |
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; |
e8af6973 LP |
84 | int drift_ppm; |
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; | |
e8af6973 LP |
95 | }; |
96 | ||
84e51726 LP |
97 | int manager_new(Manager **ret); |
98 | void manager_free(Manager *m); | |
99 | ||
100 | DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); | |
e8af6973 | 101 | |
874ff7bf LP |
102 | void manager_set_server_name(Manager *m, ServerName *n); |
103 | void manager_set_server_address(Manager *m, ServerAddress *a); | |
104 | void manager_flush_server_names(Manager *m, ServerType t); | |
105 | ||
84e51726 LP |
106 | int manager_connect(Manager *m); |
107 | void manager_disconnect(Manager *m); |