]> git.ipfire.org Git - thirdparty/chrony.git/log
thirdparty/chrony.git
11 months agontp: fix finalization for async resolver
Miroslav Lichvar [Thu, 22 Aug 2024 07:26:59 +0000 (09:26 +0200)] 
ntp: fix finalization for async resolver

If an attempt to resolve addresses of an NTP server is made right before
starting the termination sequence, the asynchronous resolver thread
could read the server name when it was already freed.

Leave unresolved sources allocated in NSR_Finalise() if the async
resolver did not finish yet, at least for now. Waiting for the resolving
result or cancelling the thread would complicate the code. The scheduler
is not expected to be running at this point.

11 months agodoc: add new question about accuracy to FAQ
Miroslav Lichvar [Wed, 21 Aug 2024 09:24:24 +0000 (11:24 +0200)] 
doc: add new question about accuracy to FAQ

11 months agodoc: clarify hostname with nts option
Miroslav Lichvar [Tue, 20 Aug 2024 12:13:38 +0000 (14:13 +0200)] 
doc: clarify hostname with nts option

11 months agoconf: don't repeat error message when adding sourcedir source
Miroslav Lichvar [Tue, 6 Aug 2024 11:05:26 +0000 (13:05 +0200)] 
conf: don't repeat error message when adding sourcedir source

When a source from a configured sourcedir cannot be added (e.g. it is a
duplicate of another source), log the error message only on the first
attempt adding the source, until the source is removed and added to a
sourcedir again.

This avoids spamming of the system log with error messages if the
reload sources command is called frequently (e.g. from a DHCP renewal
networking script).

11 months agoconf: save source status in sourcedir reload
Miroslav Lichvar [Tue, 6 Aug 2024 10:56:39 +0000 (12:56 +0200)] 
conf: save source status in sourcedir reload

Save the NSR status when adding a source from a sourcedir and don't
hide sources that failed the addition by clearing their name.

11 months agoconf: merge ntp_source_ids with ntp_sources
Miroslav Lichvar [Tue, 6 Aug 2024 09:28:26 +0000 (11:28 +0200)] 
conf: merge ntp_source_ids with ntp_sources

Keep the configuration IDs of sources loaded from sourcedir in the
NTP_Source structure itself to simplify the code.

11 months agotest: extend 008-confload test
Miroslav Lichvar [Tue, 6 Aug 2024 08:45:55 +0000 (10:45 +0200)] 
test: extend 008-confload test

12 months agodoc: update NEWS 4.6-pre1
Miroslav Lichvar [Tue, 30 Jul 2024 12:05:42 +0000 (14:05 +0200)] 
doc: update NEWS

12 months agodoc: update README
Miroslav Lichvar [Mon, 29 Jul 2024 12:10:46 +0000 (14:10 +0200)] 
doc: update README

12 months agodoc: fix typo in kod option description
Miroslav Lichvar [Thu, 25 Jul 2024 13:37:46 +0000 (15:37 +0200)] 
doc: fix typo in kod option description

12 months agontp: make sure new configuration IDs are unused
Miroslav Lichvar [Mon, 29 Jul 2024 12:33:14 +0000 (14:33 +0200)] 
ntp: make sure new configuration IDs are unused

The configuration IDs assigned to individual sources (used when they
don't have a resolved IP address) and pools of sources are 32-bit. The
ID could overflow if some sources were very frequently removed and added
again. Two unrelated sources could end up with the same ID, causing some
operations to unexpectedly impact only one or both sources.

Make sure the ID is currently unused before assigning it to a new source.

12 months agoleapdb: add explicit cast to int64_t
Miroslav Lichvar [Thu, 25 Jul 2024 13:32:44 +0000 (15:32 +0200)] 
leapdb: add explicit cast to int64_t

Add an explicit cast to int64_t to not rely on LEAP_SEC_LIST_OFFSET
not fitting in 32-bit time_t.

13 months agomain: check for killed foreground process
Miroslav Lichvar [Thu, 4 Jul 2024 14:11:19 +0000 (16:11 +0200)] 
main: check for killed foreground process

On start, if the foreground process waiting for the daemon process to
close the pipe (after finishing the RTC initialization, initstepslew,
etc) is killed, terminate the daemon too assuming that whatever killed
the foreground process it wanted all chronyd processes to stop.

In the daemon, before closing the pipe file descriptor, send an empty
message to check if the pipe isn't already closed on the other end.

13 months agologging: add function to send message to foreground process
Miroslav Lichvar [Thu, 4 Jul 2024 14:08:46 +0000 (16:08 +0200)] 
logging: add function to send message to foreground process

13 months agotest: fix 142-ntpoverptp
Miroslav Lichvar [Thu, 20 Jun 2024 13:10:14 +0000 (15:10 +0200)] 
test: fix 142-ntpoverptp

13 months agontp: make NTP-over-PTP domain configurable
Miroslav Lichvar [Thu, 20 Jun 2024 12:31:04 +0000 (14:31 +0200)] 
ntp: make NTP-over-PTP domain configurable

Add ptpdomain directive to set the domain number of transmitted and
accepted NTP-over-PTP messages. It might need to be changed in networks
using a PTP profile with the same domain number. The default domain
number of 123 follows the current NTP-over-PTP specification.

13 months agontp: update NTP-over-PTP support
Miroslav Lichvar [Thu, 20 Jun 2024 07:31:31 +0000 (09:31 +0200)] 
ntp: update NTP-over-PTP support

Following the latest version of the draft, accept NTP messages in both
PTPv2 and PTPv2.1 messages, accept sync messages in addition to delay
request messages, and check the minorSdoId field in PTPv2.1 messages.

Transmitted messages are still PTPv2 delay requests.

Don't switch to the organization-specific TLV yet. Wait for the NTP TLV
subtype and Network Correction extension field to be assigned by IANA to
avoid an additional break in compatibility.

14 months agotest: make 124-tai more reliable
Miroslav Lichvar [Tue, 4 Jun 2024 14:23:41 +0000 (16:23 +0200)] 
test: make 124-tai more reliable

Reported-by: Reinhard Max <max@suse.de>
14 months agodoc: clarify prefer source option
Miroslav Lichvar [Tue, 14 May 2024 09:11:56 +0000 (11:11 +0200)] 
doc: clarify prefer source option

15 months agontp: limit offset correction to supported NTP interval
Miroslav Lichvar [Thu, 2 May 2024 12:23:08 +0000 (14:23 +0200)] 
ntp: limit offset correction to supported NTP interval

When an NTP source is specified with the offset option, the corrected
offset may get outside of the supported NTP interval (by default -50..86
years around the build date). If the source passed the source selection,
the offset would be rejected only later in the adjustment of the local
clock.

Check the offset validity as part of the NTP test A to make the source
unselectable and make it visible in the measurements log and ntpdata
report.

15 months agoreference: switch is_leap_close() from time_t to double
Miroslav Lichvar [Thu, 2 May 2024 11:20:54 +0000 (13:20 +0200)] 
reference: switch is_leap_close() from time_t to double

Avoid undefined behavior in the timestamp conversion from double to
time_t in REF_IsLeapSecondClose() with NTP sources configured with a
large offset correction.

15 months agosources: allow logging one selection failure on start
Miroslav Lichvar [Mon, 29 Apr 2024 14:00:58 +0000 (16:00 +0200)] 
sources: allow logging one selection failure on start

Allow one message about failed selection (e.g. no selectable sources)
to be logged before first successful selection when a source has
full-size reachability register (8 polls with a received or missed
response).

This should make it more obvious that chronyd has a wrong configuration
or there is a firewall/networking issue.

15 months agosources: update source selection with unreachable sources
Miroslav Lichvar [Mon, 29 Apr 2024 13:42:16 +0000 (15:42 +0200)] 
sources: update source selection with unreachable sources

When updating the reachability register of a source with zero, call the
source selection even if the source is not the currently selected as the
best source. But do that only if all reachability bits are zero, i.e.
there was no synchronized response for last 8 polls.

This will enable the source selection to log a message when only
unreachable sources are updating reachability and it decreases the
number of unnecessary source selections.

15 months agosources: reorder unsynchronised source status
Miroslav Lichvar [Mon, 29 Apr 2024 12:45:23 +0000 (14:45 +0200)] 
sources: reorder unsynchronised source status

In the source selection, check for the unsynchronized leap status after
getting sourcestats data. The unsynchronized source status is supposed
to indicate an unsynchronized source that is providing samples, not a
source which doesn't have any samples.

Also, fix the comment describing the status.

Fixes: 4c29f8888c76 ("sources: handle unsynchronized sources in selection")
15 months agontp: improve copying of server status
Miroslav Lichvar [Mon, 29 Apr 2024 09:21:45 +0000 (11:21 +0200)] 
ntp: improve copying of server status

When a server specified with the copy option responds with an
unsynchronized status (e.g. due to selection failure), reset the
source instance to immediately switch the local reference status
instead of waiting for the source to become unreachable after 8 polls.

15 months agodoc: fix typo in README
Rob Gill [Tue, 16 Apr 2024 01:00:30 +0000 (11:00 +1000)] 
doc: fix typo in README

Typo correction only - no change to content

Signed-off-by: Rob Gill <rrobgill@protonmail.com>
15 months agodoc: fix typo in chronyc docs
Rob Gill [Tue, 16 Apr 2024 00:52:22 +0000 (10:52 +1000)] 
doc: fix typo in chronyc docs

Typo fix only - no change to content

Signed-off-by: Rob Gill <rrobgill@protonmail.com>
15 months agontp: log failed connection to Samba signd socket
Miroslav Lichvar [Mon, 15 Apr 2024 14:19:06 +0000 (16:19 +0200)] 
ntp: log failed connection to Samba signd socket

Log an error message (in addition to the socket-specific debug message)
when the connection to signd socket fails, but only once before a
successful signd exchange to avoid flooding the system log.

15 months agodoc: add contributing.adoc
Miroslav Lichvar [Thu, 11 Apr 2024 10:54:26 +0000 (12:54 +0200)] 
doc: add contributing.adoc

15 months agotest: add --enable-debug option to 002-scanbuild
Miroslav Lichvar [Thu, 11 Apr 2024 10:53:01 +0000 (12:53 +0200)] 
test: add --enable-debug option to 002-scanbuild

15 months agoavoid some static analysis errors
Miroslav Lichvar [Thu, 11 Apr 2024 07:20:44 +0000 (09:20 +0200)] 
avoid some static analysis errors

Modify the code to avoid some false positives reported by the clang and
gcc static analyzers.

15 months agosys_linux: disable other external timestamping channels
Miroslav Lichvar [Wed, 10 Apr 2024 10:05:57 +0000 (12:05 +0200)] 
sys_linux: disable other external timestamping channels

Use new ioctls added in Linux 6.7 to disable receiving events from other
channels when enabling external timestamping on a PHC. This should save
some CPU time when other applications or chronyd instances are using
other channels of the same PHC.

15 months agorefclock: update comment in PHC driver
Miroslav Lichvar [Wed, 10 Apr 2024 10:02:50 +0000 (12:02 +0200)] 
refclock: update comment in PHC driver

Since Linux 6.7 external timestamping events are no longer shared among
all descriptors of a PHC. Each descriptor gets its own copy of each
timestamp.

16 months agocmdmon: add reserved fields to local command
Miroslav Lichvar [Thu, 4 Apr 2024 13:17:43 +0000 (15:17 +0200)] 
cmdmon: add reserved fields to local command

Add two reserved fields initialized to zero to the new REQ_LOCAL3
command to allow adding more options (e.g. delay in activation) without
changing the command number again.

16 months agotest: add tests of local directive options
Miroslav Lichvar [Thu, 4 Apr 2024 13:00:20 +0000 (15:00 +0200)] 
test: add tests of local directive options

16 months agoreference: add "local activate" option
Andy Fiddaman [Mon, 25 Mar 2024 19:05:52 +0000 (19:05 +0000)] 
reference: add "local activate" option

This option sets an activating root distance for the local reference. The
local reference will not be used until the root distance drops below the
configured value for the first time. This can be used to prevent the local
reference from being activated on a server which has never been synchronised
with an upstream server. The default value of 0.0 causes no activating
distance to be used, such that the local reference is always eligible for
activation.

16 months agoleapdb: fix leapsec list processing with 32-bit time_t
Miroslav Lichvar [Wed, 3 Apr 2024 09:01:44 +0000 (11:01 +0200)] 
leapdb: fix leapsec list processing with 32-bit time_t

A 32-bit time_t value overflows when converted to the Y1900 epoch used
in the leapsec list. Use a 64-bit variable in get_list_leap() to fix the
comparisons on systems using 32-bit time_t.

Fixes: 53823b9f1c07 ("leapdb: support leap-seconds.list as second source")
16 months agontp: add server support for KoD RATE
Miroslav Lichvar [Tue, 2 Apr 2024 13:25:51 +0000 (15:25 +0200)] 
ntp: add server support for KoD RATE

Add "kod" option to the ratelimit directive to respond with the KoD
RATE code to randomly selected requests exceeding the configured limit.
This complements the client support of KoD RATE. It's disabled by
default.

There can be only one KoD code in one response. If both NTS NAK and RATE
codes are triggered, drop the response. The KoD RATE code can be set in
an NTS-authenticated response.

16 months agoclientlog: add support for KoD rate limiting
Miroslav Lichvar [Tue, 2 Apr 2024 13:05:19 +0000 (15:05 +0200)] 
clientlog: add support for KoD rate limiting

Add a third return value to CLG_LimitServiceRate() to indicate the
server should send a response requesting the client to reduce its
polling rate. It randomly selects from a fraction (configurable to 1/2,
1/4, 1/8, 1/16, or disabled) of responses which would be dropped
(after selecting responses for the leak option).

16 months agoclientlog: return enum from CLG_LimitServiceRate()
Miroslav Lichvar [Tue, 2 Apr 2024 09:37:39 +0000 (11:37 +0200)] 
clientlog: return enum from CLG_LimitServiceRate()

Change CLG_LimitServiceRate() to return an enum in preparation for
adding KoD RATE support.

16 months agonts: check for NTS NAK specifically when responding
Miroslav Lichvar [Tue, 2 Apr 2024 09:33:04 +0000 (11:33 +0200)] 
nts: check for NTS NAK specifically when responding

Ignore other KoD codes than NTS NAK when deciding if the server response
should not be authenticated.

16 months agontp: avoid unnecessary restart of resolving round on refresh
Miroslav Lichvar [Thu, 14 Mar 2024 14:37:15 +0000 (15:37 +0100)] 
ntp: avoid unnecessary restart of resolving round on refresh

Don't call NSR_ResolveSources() when a resolving round is already
started. This cuts the number of calls of the system resolver made due
to the refresh command to half.

16 months agontp: don't keep refresh requests in list of unresolved sources
Miroslav Lichvar [Thu, 14 Mar 2024 14:32:28 +0000 (15:32 +0100)] 
ntp: don't keep refresh requests in list of unresolved sources

The refresh command adds requests to reresolve addresses of all sources.
If some sources didn't have an IP address resolved yet, the
corresponding requests were not removed after failed resolving. Repeated
refresh commands increased the number of requests and number of calls of
the system resolver, which might not be caching DNS responses.

Remove all refresh requests from the list after resolving attempt to fix
that.

Reported-by: t.barnewski@avm.de
Fixes: d7e3ad17ff7a ("ntp: create sources for unresolved addresses")
16 months agontp: add more debug messages for resolving
Miroslav Lichvar [Thu, 14 Mar 2024 14:09:09 +0000 (15:09 +0100)] 
ntp: add more debug messages for resolving

16 months agoconf: don't load sourcedir during initstepslew and RTC init
Miroslav Lichvar [Tue, 12 Mar 2024 13:30:27 +0000 (14:30 +0100)] 
conf: don't load sourcedir during initstepslew and RTC init

If the reload sources command was received in the chronyd start-up
sequence with initstepslew and/or RTC init (-s option), the sources
loaded from sourcedirs caused a crash due to failed assertion after
adding sources specified in the config.

Ignore the reload sources command until chronyd enters the normal
operation mode.

Fixes: 519796de3756 ("conf: add sourcedirs directive")
16 months agotest: replace another C99-style declaration in for loop
Miroslav Lichvar [Mon, 11 Mar 2024 10:59:11 +0000 (11:59 +0100)] 
test: replace another C99-style declaration in for loop

16 months agocmdmon: add offset command
Miroslav Lichvar [Thu, 7 Mar 2024 15:20:27 +0000 (16:20 +0100)] 
cmdmon: add offset command

Add a new command to modify the offset option of NTP sources and
reference clocks.

16 months agontp+refclock: add functions to modify offset option
Miroslav Lichvar [Thu, 7 Mar 2024 15:19:04 +0000 (16:19 +0100)] 
ntp+refclock: add functions to modify offset option

17 months agortc+getdate: initialize tm_wday for mktime()
Miroslav Lichvar [Mon, 4 Mar 2024 10:34:22 +0000 (11:34 +0100)] 
rtc+getdate: initialize tm_wday for mktime()

Even though mktime() is documented as ignoring the tm_wday field, the
coverity static analyzer complains about passing an uninitialized value.
Set the field to zero to make it happy.

17 months agotest: avoid C99-style declaration in for loop
Miroslav Lichvar [Mon, 12 Feb 2024 13:42:03 +0000 (14:42 +0100)] 
test: avoid C99-style declaration in for loop

This fixes compilation without the -std=c99 option with an older gcc.

17 months agoexamples: switch chrony.conf examples to leapseclist
Miroslav Lichvar [Thu, 8 Feb 2024 15:18:57 +0000 (16:18 +0100)] 
examples: switch chrony.conf examples to leapseclist

17 months agotest: improve 113-leapsecond and 124-tai tests
Miroslav Lichvar [Wed, 7 Feb 2024 14:48:43 +0000 (15:48 +0100)] 
test: improve 113-leapsecond and 124-tai tests

Use leapseclist instead of leapsectz and test also negative leap
seconds. Add a test for leapsectz when the date command indicates
right/UTC is available on the system and mktime() works as expected.
Check TAI offset in the server's log.

17 months agotest: add leapdb unit test
Patrick Oppenlander [Thu, 8 Feb 2024 03:36:29 +0000 (14:36 +1100)] 
test: add leapdb unit test

17 months agoleapdb: support leap-seconds.list as second source
Patrick Oppenlander [Thu, 8 Feb 2024 03:36:28 +0000 (14:36 +1100)] 
leapdb: support leap-seconds.list as second source

The existing implementation of getting leap second information from a
timezone in get_tz_leap() relies on non-portable C library behaviour.

Specifically, mktime is not required to return '60' in the tm_sec field
when a leap second is inserted leading to "Timezone right/UTC failed
leap second check, ignoring" errors on musl based systems.

This patch adds support for getting leap second information from the
leap-seconds.list file included with tzdata and adds a new configuration
directive leapseclist to switch on the feature.

17 months agoleapdb: move source check into separate function
Patrick Oppenlander [Thu, 8 Feb 2024 03:36:27 +0000 (14:36 +1100)] 
leapdb: move source check into separate function

The sanity checks are valid for all possible sources of leap second
information, so move them into a separate function check_leap_source().

17 months agoleapdb: make twice per day check logic common
Patrick Oppenlander [Thu, 8 Feb 2024 03:36:26 +0000 (14:36 +1100)] 
leapdb: make twice per day check logic common

We want to do the twice per day check regardless of the data source.
Move the check up one level from get_tz_leap() into LDB_GetLeap().

17 months agoreference: move leap second source into leapdb
Patrick Oppenlander [Thu, 8 Feb 2024 03:36:25 +0000 (14:36 +1100)] 
reference: move leap second source into leapdb

Separate out source of leap second data into a new module in preparation
for supporting more sources such as leap-seconds.list.

17 months agocmdmon: add timestamp counters to ntpdata report
Miroslav Lichvar [Tue, 6 Feb 2024 13:56:30 +0000 (14:56 +0100)] 
cmdmon: add timestamp counters to ntpdata report

17 months agontp: add per-source counters of kernel and hardware timestamps
Miroslav Lichvar [Tue, 6 Feb 2024 13:27:14 +0000 (14:27 +0100)] 
ntp: add per-source counters of kernel and hardware timestamps

17 months agocmdmon: add ipv4/ipv6 options to add source command
Miroslav Lichvar [Mon, 5 Feb 2024 13:43:03 +0000 (14:43 +0100)] 
cmdmon: add ipv4/ipv6 options to add source command

17 months agocmdmon: simplify flag checking in handle_add_source()
Miroslav Lichvar [Mon, 5 Feb 2024 13:38:51 +0000 (14:38 +0100)] 
cmdmon: simplify flag checking in handle_add_source()

17 months agoconf: add ipv4 and ipv6 options to server/pool/peer directive
Miroslav Lichvar [Mon, 5 Feb 2024 13:20:19 +0000 (14:20 +0100)] 
conf: add ipv4 and ipv6 options to server/pool/peer directive

Accept "ipv4" and "ipv6" options in the server/pool/peer directive to
use only IPv4 or IPv6 addresses respectively.

The configuration is different from the "server [-4|-6] hostname" syntax
supported by ntpd to avoid breaking existing scripts which expect the
hostname to always be the first argument of the directives.

17 months agontp: support per-source IP family restriction
Miroslav Lichvar [Mon, 5 Feb 2024 13:06:52 +0000 (14:06 +0100)] 
ntp: support per-source IP family restriction

Add a new parameter to the NSR_AddSourceByName() function to allow
individual sources to be limited to IPv4 or IPv6 addresses. This doesn't
change the options passed to the resolver. It's just an additional
filter in the processing of resolved addresses following the -4/-6
command-line option of chronyd.

18 months agontp: fix authenticated requests in serverstats
Miroslav Lichvar [Mon, 8 Jan 2024 10:35:56 +0000 (11:35 +0100)] 
ntp: fix authenticated requests in serverstats

Fix the CLG_UpdateNtpStats() call to count requests passing the
authentication check instead of requests triggering a KoD response
(i.e. NTS NAK).

20 months agoupdate copyright years 4.5
Miroslav Lichvar [Tue, 5 Dec 2023 13:14:00 +0000 (14:14 +0100)] 
update copyright years

20 months agodoc: update FAQ on improving accuracy
Miroslav Lichvar [Tue, 5 Dec 2023 12:54:44 +0000 (13:54 +0100)] 
doc: update FAQ on improving accuracy

20 months agodoc: mention dependency of net corrections on HW timestamping
Miroslav Lichvar [Tue, 5 Dec 2023 12:03:27 +0000 (13:03 +0100)] 
doc: mention dependency of net corrections on HW timestamping

20 months agodoc: improve description of reload sources command
Miroslav Lichvar [Mon, 4 Dec 2023 11:38:03 +0000 (12:38 +0100)] 
doc: improve description of reload sources command

20 months agosources: rework logging of selection loss
Miroslav Lichvar [Tue, 28 Nov 2023 10:28:03 +0000 (11:28 +0100)] 
sources: rework logging of selection loss

The commit 5dd288dc0cbd ("sources: reselect earlier when removing
selected source") didn't cover all paths that can lead to a missing log
message when all sources are removed.

Add a flag to track the loss of selection and postpone the log message
in transient states where no message is logged to avoid spamming in
normal operation. Call SRC_SelectSource() after removing the source
to get a log message if there are no (selectable) sources left.

Reported-by: Thomas Lange <thomas@corelatus.se>
20 months agodoc: update NEWS 4.5-pre1
Miroslav Lichvar [Wed, 22 Nov 2023 09:46:33 +0000 (10:46 +0100)] 
doc: update NEWS

20 months agodoc: update README
Miroslav Lichvar [Wed, 22 Nov 2023 09:34:59 +0000 (10:34 +0100)] 
doc: update README

20 months agodoc: replace foobar naming in examples
Miroslav Lichvar [Wed, 22 Nov 2023 09:29:01 +0000 (10:29 +0100)] 
doc: replace foobar naming in examples

20 months agodoc: update description of NTP over PTP in FAQ
Miroslav Lichvar [Wed, 22 Nov 2023 08:51:14 +0000 (09:51 +0100)] 
doc: update description of NTP over PTP in FAQ

20 months agodoc: mention version supporting socket activation in FAQ
Miroslav Lichvar [Wed, 22 Nov 2023 08:50:44 +0000 (09:50 +0100)] 
doc: mention version supporting socket activation in FAQ

20 months agodoc: improve ntstrustedcerts description
Miroslav Lichvar [Wed, 22 Nov 2023 09:19:53 +0000 (10:19 +0100)] 
doc: improve ntstrustedcerts description

20 months agodoc: improve cmdport description
Miroslav Lichvar [Wed, 22 Nov 2023 08:48:36 +0000 (09:48 +0100)] 
doc: improve cmdport description

20 months agosources: drop unreachable log message
Miroslav Lichvar [Tue, 21 Nov 2023 10:25:10 +0000 (11:25 +0100)] 
sources: drop unreachable log message

With forced reselection during source removal selected_source_index
can only be INVALID_SOURCE if there are no sources. The "Can't
synchronise: no sources" message couldn't be logged even before that as
SRC_ReselectSource() resets the index before calling SRC_SelectSource().

Replace the message with an assertion.

20 months agosources: reselect earlier when removing selected source
Miroslav Lichvar [Tue, 21 Nov 2023 10:10:23 +0000 (11:10 +0100)] 
sources: reselect earlier when removing selected source

When a selected source is being removed, reset the instance and rerun
the selection while the source is still marked as selected. This forces
a "Can't synchronise" message to be logged when all sources are removed.

Reported-by: Thomas Lange <thomas@corelatus.se>
20 months agosources: reselect after resetting selected source
Miroslav Lichvar [Tue, 21 Nov 2023 10:05:41 +0000 (11:05 +0100)] 
sources: reselect after resetting selected source

Avoid showing in the sources report a selected source which has no
samples (e.g. after replacement).

20 months agontp: allow reusing timestamps of unused samples
Miroslav Lichvar [Tue, 21 Nov 2023 08:28:40 +0000 (09:28 +0100)] 
ntp: allow reusing timestamps of unused samples

When switching from basic mode to interleaved mode following a response
which wasn't accumulated due to failed test A, B, C, or D, allow
timestamps of the failed sample to be reused in interleaved mode, i.e.
replacing the server's less accurate transmit timestamp with a more
accurate timestamp server can turn a failed sample into acceptable one.

Move the presend check into test A to simplify the code.

20 months agontp: fix presend in interleaved mode
Miroslav Lichvar [Tue, 21 Nov 2023 06:51:37 +0000 (07:51 +0100)] 
ntp: fix presend in interleaved mode

The presend option in interleaved mode uses two presend requests instead
of one to get an interleaved response from servers like chrony which
delay the first interleaved response due to an optimization saving
timestamps only for clients actually using the interleaved mode.

After commit 0ae6f2485b97 ("ntp: don't use first response in interleaved
mode") the first interleaved response following the two presend
responses in basic mode is dropped as the preferred set of timestamps
minimizing error in delay was already used by the second sample in
basic mode. There are only three responses in the burst and no sample is
accumulated.

Increasing the number of presend requests to three to get a fourth
sample would be wasteful. Instead, allow reusing timestamps of the
second presend sample in basic mode, which is never accumulated.

Reported-by: Aaron Thompson
Fixes: 0ae6f2485b97 ("ntp: don't use first response in interleaved mode")
20 months agonts: close reusable sockets in helper process
Miroslav Lichvar [Mon, 20 Nov 2023 12:34:59 +0000 (13:34 +0100)] 
nts: close reusable sockets in helper process

Close all reusable sockets when the NTS-KE server helper is forked. It
is not supposed to have access to any of the server sockets, just the
socket for getting requests from the main process and the syslog socket.

20 months agosocket: provide function for closing reusable sockets
Miroslav Lichvar [Mon, 20 Nov 2023 12:34:38 +0000 (13:34 +0100)] 
socket: provide function for closing reusable sockets

20 months agosocket: set close-on-exec on all reusable sockets
Miroslav Lichvar [Mon, 20 Nov 2023 12:25:27 +0000 (13:25 +0100)] 
socket: set close-on-exec on all reusable sockets

Set the CLOEXEC flag on all reusable sockets in the initialization to
avoid leaking them to sendmail (mailonchange directive) in case the
chrony configuration doesn't use all sockets provided by systemd.

20 months agodoc: add FAQ section on minimizing service downtime
Luke Valenta [Wed, 1 Nov 2023 20:40:35 +0000 (16:40 -0400)] 
doc: add FAQ section on minimizing service downtime

20 months agosocket: add support for systemd sockets
Luke Valenta [Thu, 26 Oct 2023 16:48:56 +0000 (12:48 -0400)] 
socket: add support for systemd sockets

Before opening new IPv4/IPv6 server sockets, chronyd will check for
matching reusable sockets passed from the service manager (for example,
passed via systemd socket activation:
https://www.freedesktop.org/software/systemd/man/latest/sd_listen_fds.html)
and use those instead.

Aside from IPV6_V6ONLY (which cannot be set on already-bound sockets),
the daemon sets the same socket options on reusable sockets as it would
on sockets it opens itself.

Unit tests test the correct parsing of the LISTEN_FDS environment
variable.

Add 011-systemd system test to test socket activation for DGRAM and
STREAM sockets (both IPv4 and IPv6).  The tests use the
systemd-socket-activate test tool, which has some limitations requiring
workarounds discussed in inline comments.

20 months agologging: move severity_chars to fix compiler warning
Luke Valenta [Tue, 7 Nov 2023 19:39:40 +0000 (14:39 -0500)] 
logging: move severity_chars to fix compiler warning

20 months agologging: add log severity to file log prefix when debug is enabled
Luke Valenta [Wed, 1 Nov 2023 20:32:45 +0000 (16:32 -0400)] 
logging: add log severity to file log prefix when debug is enabled

21 months agontp: initialize network correction of transmitted packets
Miroslav Lichvar [Thu, 2 Nov 2023 11:41:55 +0000 (12:41 +0100)] 
ntp: initialize network correction of transmitted packets

Initialize the unused value of network correction parsed from
own transmitted packets to avoid a use-of-uninitialized-value error
in NIO_UnwrapMessage() reported by clang.

Fixes: 6372a9f93f59 ("ntp: save PTP correction from NTP-over-PTP messages")
21 months agodoc: document '-L -1' option for debug logging output
Luke Valenta [Fri, 20 Oct 2023 15:54:41 +0000 (11:54 -0400)] 
doc: document '-L -1' option for debug logging output

22 months agontp: add client support for network correction
Miroslav Lichvar [Tue, 26 Sep 2023 10:52:39 +0000 (12:52 +0200)] 
ntp: add client support for network correction

If the network correction is known for both the request and response,
and their sum is not larger that the measured peer delay, allowing the
transparent clocks to be running up to 100 ppm faster than the client's
clock, apply the corrections to the NTP offset and peer delay. Don't
correct the root delay to not change the estimated maximum error.

22 months agontp: add server support for network correction
Miroslav Lichvar [Tue, 26 Sep 2023 10:39:25 +0000 (12:39 +0200)] 
ntp: add server support for network correction

Provide the network correction (PTP correction + RX duration) of the
request in the new extension field if included in the request and
NTP-over-PTP is enabled.

22 months agontp: add extension field to provide network correction
Miroslav Lichvar [Tue, 26 Sep 2023 10:30:10 +0000 (12:30 +0200)] 
ntp: add extension field to provide network correction

To be able to verify PTP corrections, the client will need to know both
the correction of the request received by the server and the correction
of the response. Add a new experimental NTP extension field that the
clients will use to request the correction and servers return the
value.

22 months agontp: save PTP correction from NTP-over-PTP messages
Miroslav Lichvar [Tue, 26 Sep 2023 10:22:47 +0000 (12:22 +0200)] 
ntp: save PTP correction from NTP-over-PTP messages

When the RX duration is known (HW timestamping), save the PTP correction
from received PTP messages in the local RX timestamp.

22 months agontp: extend local timestamp for PTP correction
Miroslav Lichvar [Tue, 26 Sep 2023 10:14:56 +0000 (12:14 +0200)] 
ntp: extend local timestamp for PTP correction

Add two new fields to the NTP_Local_Timestamp structure:
- receive duration as the time it takes to receive the ethernet frame,
  currently known only with HW timestamping
- network correction as a generalized PTP correction

The PTP correction is provided by transparent clocks in the correction
field of PTP messages to remove the receive, processing and queueing
delays of network switches and routers. Only one-step end-to-end unicast
transparent clocks are useful for NTP-over-PTP. Two-step transparent
clocks use follow-up messages and peer-to-peer transparent clocks don't
handle delay requests.

The RX duration will be included in the network correction to compensate
for asymmetric link speeds of the server and client as the NTP RX
timestamp corresponds to the end of the reception (in order to
compensate for the asymmetry in the normal case when no corrections
are applied).

22 months agontp: add function for detection of experimental fields
Miroslav Lichvar [Thu, 21 Sep 2023 09:02:24 +0000 (11:02 +0200)] 
ntp: add function for detection of experimental fields

22 months agontp: assert size of exp_mono_root field
Miroslav Lichvar [Tue, 12 Sep 2023 12:03:50 +0000 (14:03 +0200)] 
ntp: assert size of exp_mono_root field

22 months agontp: rename exp1 extension field
Miroslav Lichvar [Tue, 12 Sep 2023 10:19:03 +0000 (12:19 +0200)] 
ntp: rename exp1 extension field

Rename the exp1 extension field to exp_mono_root (monotonic timestamp +
root delay/dispersion) to better distinguish it from future experimental
extension fields.

22 months agoutil: add conversion between intervals and NTP 64-bit format
Miroslav Lichvar [Thu, 21 Sep 2023 12:02:11 +0000 (14:02 +0200)] 
util: add conversion between intervals and NTP 64-bit format

This will be needed to save PTP correction in NTP timestamp format.

22 months agodoc: don't require same version for experimental features
Miroslav Lichvar [Tue, 26 Sep 2023 10:12:14 +0000 (12:12 +0200)] 
doc: don't require same version for experimental features