2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2014-08-12 16:58:56 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-04-30 15:37:02 +02:00
|
|
|
#include <sys/timex.h>
|
|
|
|
|
2018-04-30 16:02:09 +02:00
|
|
|
#include "sd-bus.h"
|
2014-05-06 17:02:11 +02:00
|
|
|
#include "sd-event.h"
|
2014-05-07 15:26:47 +02:00
|
|
|
#include "sd-network.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "sd-resolve.h"
|
|
|
|
|
2014-08-12 16:58:56 +02:00
|
|
|
#include "list.h"
|
|
|
|
#include "ratelimit.h"
|
2017-11-07 17:47:38 +01:00
|
|
|
#include "time-util.h"
|
2018-04-30 15:37:02 +02:00
|
|
|
#include "timesyncd-ntp-message.h"
|
2014-05-06 17:02:11 +02:00
|
|
|
|
|
|
|
typedef struct Manager Manager;
|
2014-07-15 00:29:27 +02:00
|
|
|
|
2014-08-12 19:48:24 +02:00
|
|
|
#include "timesyncd-server.h"
|
|
|
|
|
2017-11-07 17:47:38 +01:00
|
|
|
/*
|
|
|
|
* "A client MUST NOT under any conditions use a poll interval less
|
|
|
|
* than 15 seconds."
|
|
|
|
*/
|
|
|
|
#define NTP_POLL_INTERVAL_MIN_USEC (32 * USEC_PER_SEC)
|
|
|
|
#define NTP_POLL_INTERVAL_MAX_USEC (2048 * USEC_PER_SEC)
|
|
|
|
|
timesync: increase retry interval more slowly
The new retry intervals are [15, 20, 26, 34, 45, 60, 80, 106, 141, 188, 250,
333, 360, ...]. This should allow graceful response if a transient network
failure is encountered. Growth is exponential, but with a small power and
capped to a non-too-large value so that we resynchronize within a few minutes
after network is restored. I made the minimum 15 s to make sure that we never
send packets more often than that.
Fixes #16492.
2020-07-30 15:15:11 +02:00
|
|
|
#define NTP_RETRY_INTERVAL_MIN_USEC (15 * USEC_PER_SEC)
|
|
|
|
#define NTP_RETRY_INTERVAL_MAX_USEC (6 * 60 * USEC_PER_SEC) /* 6 minutes */
|
|
|
|
|
2020-12-10 19:54:19 +01:00
|
|
|
#define DEFAULT_CONNECTION_RETRY_USEC (30*USEC_PER_SEC)
|
|
|
|
|
2014-05-06 17:02:11 +02:00
|
|
|
struct Manager {
|
2018-04-30 16:02:09 +02:00
|
|
|
sd_bus *bus;
|
2014-05-06 17:02:11 +02:00
|
|
|
sd_event *event;
|
|
|
|
sd_resolve *resolve;
|
|
|
|
|
2014-08-12 19:48:24 +02:00
|
|
|
LIST_HEAD(ServerName, system_servers);
|
2014-08-12 16:58:56 +02:00
|
|
|
LIST_HEAD(ServerName, link_servers);
|
|
|
|
LIST_HEAD(ServerName, fallback_servers);
|
2014-05-06 17:02:11 +02:00
|
|
|
|
2017-05-21 03:22:43 +02:00
|
|
|
bool have_fallbacks:1;
|
|
|
|
|
2014-05-06 17:02:11 +02:00
|
|
|
RateLimit ratelimit;
|
2014-08-27 16:47:24 +02:00
|
|
|
bool exhausted_servers;
|
2014-05-06 17:02:11 +02:00
|
|
|
|
2014-05-07 15:26:47 +02:00
|
|
|
/* network */
|
|
|
|
sd_event_source *network_event_source;
|
|
|
|
sd_network_monitor *network_monitor;
|
|
|
|
|
2014-05-06 17:02:11 +02:00
|
|
|
/* peer */
|
|
|
|
sd_resolve_query *resolve_query;
|
|
|
|
sd_event_source *event_receive;
|
|
|
|
ServerName *current_server_name;
|
|
|
|
ServerAddress *current_server_address;
|
|
|
|
int server_socket;
|
2014-09-02 14:29:51 +02:00
|
|
|
int missed_replies;
|
2014-05-06 17:02:11 +02:00
|
|
|
uint64_t packet_count;
|
|
|
|
sd_event_source *event_timeout;
|
2015-04-08 20:14:04 +02:00
|
|
|
bool good;
|
2014-05-06 17:02:11 +02:00
|
|
|
|
|
|
|
/* last sent packet */
|
|
|
|
struct timespec trans_time_mon;
|
|
|
|
struct timespec trans_time;
|
2014-09-02 15:28:56 +02:00
|
|
|
usec_t retry_interval;
|
2020-12-10 19:54:19 +01:00
|
|
|
usec_t connection_retry_usec;
|
2014-05-06 17:02:11 +02:00
|
|
|
bool pending;
|
|
|
|
|
|
|
|
/* poll timer */
|
|
|
|
sd_event_source *event_timer;
|
|
|
|
usec_t poll_interval_usec;
|
2017-11-07 17:47:38 +01:00
|
|
|
usec_t poll_interval_min_usec;
|
|
|
|
usec_t poll_interval_max_usec;
|
2014-05-06 17:02:11 +02:00
|
|
|
bool poll_resync;
|
|
|
|
|
|
|
|
/* history data */
|
|
|
|
struct {
|
|
|
|
double offset;
|
|
|
|
double delay;
|
|
|
|
} samples[8];
|
2018-10-19 20:00:46 +02:00
|
|
|
unsigned samples_idx;
|
2014-05-06 17:02:11 +02:00
|
|
|
double samples_jitter;
|
2017-11-05 07:39:34 +01:00
|
|
|
usec_t max_root_distance_usec;
|
2014-05-06 17:02:11 +02:00
|
|
|
|
|
|
|
/* last change */
|
|
|
|
bool jumped;
|
2014-05-22 14:31:46 +02:00
|
|
|
bool sync;
|
2018-06-23 02:41:55 +02:00
|
|
|
int64_t drift_freq;
|
2014-05-06 17:02:11 +02:00
|
|
|
|
|
|
|
/* watch for time changes */
|
|
|
|
sd_event_source *event_clock_watch;
|
|
|
|
int clock_watch_fd;
|
|
|
|
|
|
|
|
/* Retry connections */
|
|
|
|
sd_event_source *event_retry;
|
2014-07-27 00:11:08 +02:00
|
|
|
|
|
|
|
/* RTC runs in local time, leave it alone */
|
|
|
|
bool rtc_local_time;
|
2018-04-30 15:37:02 +02:00
|
|
|
|
|
|
|
/* NTP response */
|
|
|
|
struct ntp_msg ntpmsg;
|
|
|
|
struct timespec origin_time, dest_time;
|
|
|
|
bool spike;
|
2014-05-06 17:02:11 +02:00
|
|
|
};
|
|
|
|
|
2014-08-12 16:58:56 +02:00
|
|
|
int manager_new(Manager **ret);
|
|
|
|
void manager_free(Manager *m);
|
|
|
|
|
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
|
2014-05-06 17:02:11 +02:00
|
|
|
|
2014-08-12 19:48:24 +02:00
|
|
|
void manager_set_server_name(Manager *m, ServerName *n);
|
|
|
|
void manager_set_server_address(Manager *m, ServerAddress *a);
|
|
|
|
void manager_flush_server_names(Manager *m, ServerType t);
|
|
|
|
|
2014-08-12 16:58:56 +02:00
|
|
|
int manager_connect(Manager *m);
|
|
|
|
void manager_disconnect(Manager *m);
|