]> git.ipfire.org Git - thirdparty/chrony.git/log
thirdparty/chrony.git
5 months agodoc: mention localhost exception in cmdallow description
Miroslav Lichvar [Tue, 11 Feb 2025 15:25:05 +0000 (16:25 +0100)] 
doc: mention localhost exception in cmdallow description

5 months agocmdmon: make open commands configurable
Miroslav Lichvar [Tue, 11 Feb 2025 11:27:23 +0000 (12:27 +0100)] 
cmdmon: make open commands configurable

Replace the hardcoded list of open commands (accessible over UDP),
with a list that can be configured with a new "opencommands" directive.
The default matches the original list. All read-only commands except
accheck and cmdaccheck can be enabled. The naming follows the chronyc
naming. Enable the N_SOURCES request only when needed.

This makes it possible to have a full monitoring access without access
to the Unix domain socket. It also allows restricting the monitoring
access to a smaller number of commands if some commands from the default
list are not needed.

Mention in the man page that the protocol of the non-default commands is
not consider stable and the information they provide may have security
implications.

5 months agocmdmon: refactor command authorization checks
Miroslav Lichvar [Mon, 10 Feb 2025 14:32:26 +0000 (15:32 +0100)] 
cmdmon: refactor command authorization checks

Try to simplify the code and make it more robust to potential bugs.

Instead of maintaing a table mapping all commands to open/auth
permissions, use a short list of open commands. Split the processing
of the commands into two groups, read-write commands and read-only
(monitoring) commands, where the first group is processed only with full
access. Check both the socket descriptor and address type before giving
full access. While moving the code, reorder the commands alphabetically.

5 months agocmdmon: drop handling of NULL and LOGON requests
Miroslav Lichvar [Mon, 10 Feb 2025 14:08:03 +0000 (15:08 +0100)] 
cmdmon: drop handling of NULL and LOGON requests

Handle the NULL and LOGON requests as unknown (invalid) instead of
returning the success and failed status respectively. They have
been unused for very long time now.

5 months agosocket: rework setting of struct sockaddr_un
Miroslav Lichvar [Wed, 5 Feb 2025 14:20:41 +0000 (15:20 +0100)] 
socket: rework setting of struct sockaddr_un

Add a function to fill the Unix sockaddr for binding, connecting and
sending to avoid code duplication. Use memcpy() instead of snprintf()
and provide the minimum length of the address containing the terminating
null byte. This makes it easier to support abstract sockets if needed in
future (e.g. for systemd support).

5 months agomain: add support for systemd notification
Miroslav Lichvar [Wed, 5 Feb 2025 08:30:46 +0000 (09:30 +0100)] 
main: add support for systemd notification

On Linux, if the NOTIFY_SOCKET variable is set, send a "READY=1"
and "STOPPING=1" message to the Unix domain socket after initialization
and before finalization respectively. This is used with the systemd
"notify" service type as documented in the sd_notity(3) man page. It's
a recommended alternative to the "forking" service type, which does not
need the PID file to determine the main process.

Support pathname Unix sockets only. Abstract sockets don't seem to be
used by systemd for notifications since version 212.

Switch the example services to the notify type, but keep the PID
file. It's still useful to prevent start of other chronyd instances.
systemd doesn't seem to care about the content of the file and should
just remove it in case chronyd didn't terminate cleanly.

Suggested-by: Luca Boccassi <bluca@debian.org>
7 months agorefclock: drop filter length adjustment for polling drivers
Miroslav Lichvar [Wed, 11 Dec 2024 10:16:30 +0000 (11:16 +0100)] 
refclock: drop filter length adjustment for polling drivers

In the refclock initialization, if the driver provides a poll()
function and 2^(poll-dpoll) is smaller than the configured length of the
median filter (64 by default), the filter is shortened to 2^(poll-dpoll)
samples, assuming the driver provides samples only in the poll()
function and at most one per call, to avoid wasting memory and before
commit 12237bf28393 ("refclock: stop requiring 4 samples in median
filter") also simplify configuration (for polling drivers only)

But this assumption is not always correct. The PHC driver can read
external PPS timestamps independently from the driver polling and the
RTC driver can timestamp interrupts. If the dpoll was too large to cover
the sample rate, some samples would be lost.

Drop the adjustment of the filter length to avoid this unexpected impact
on filtering and make it work as documented.

7 months agorefclock: fix build on non-Linux systems
Bryan Christianson [Tue, 10 Dec 2024 09:14:43 +0000 (10:14 +0100)] 
refclock: fix build on non-Linux systems

Fixes: 5fd71e27831f ("refclock: add new refclock for RTCs")
7 months agorefclock: add new refclock for RTCs
Uwe Kleine-König [Wed, 30 Jun 2021 14:47:21 +0000 (16:47 +0200)] 
refclock: add new refclock for RTCs

This refclock uses an RTC as reference source. If the RTC doesn't
support reporting an update event this source is quite coarse as it
usually needs a slow bus access to be read and has a precision of only
one second. If reporting an update event is available, the time is read
just after such an event which improves precision.

Depending on hardware capabilities you might want to combine it with a
PPS reference clock sourced from the same chip.

Note that you can enable UIE emulation in the Linux kernel to make a RTC
without interrupt support look like one with irqs in return for some
system and bus overhead.

Co-authored-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
7 months agortc: optionally return raw time from RTC_Linux_ReadTime*
Ahmad Fatoum [Mon, 22 Jul 2024 15:41:47 +0000 (17:41 +0200)] 
rtc: optionally return raw time from RTC_Linux_ReadTime*

For use with RCL_AddSample in the incoming RTC reference clock driver,
we'll want access not to the cooked timestamps, but to the raw ones.

Otherwise, the core reference clock code complains:

  (valid_sample_time) RTC0 refclock sample time 1721242673.092211891
    not valid age=-3.092007

Support both use cases by have the RTC_Linux_ReadTime_* functions take
two nullable pointers, one for cooked and the other for raw time.

7 months agortc: factor out RTC_Linux_ReadTimeNow
Ahmad Fatoum [Mon, 22 Jul 2024 15:46:44 +0000 (17:46 +0200)] 
rtc: factor out RTC_Linux_ReadTimeNow

We have code to read RTC time and handle the error associated with
having no UIE interrupt, which we currently use as part of maintaining
the correction file.

In a later commit, we will need the same functionality for using the RTC
as reference clock, so export the function and give it a descriptive
name appropriate for a globally visible function.

7 months agortc: factor out RTC_Linux_ReadTimeAfterInterrupt
Ahmad Fatoum [Wed, 17 Jul 2024 11:00:39 +0000 (13:00 +0200)] 
rtc: factor out RTC_Linux_ReadTimeAfterInterrupt

We have code to read time after an RTC's UIE interrupt, which we
currently use as part of maintaining the correction file.

In a later commit, we will need the same functionality for using the RTC
as reference clock, so export the function and give it a descriptive
name appropriate for a globally visible function.

7 months agortc: export RTC_Linux_{SwitchInterrupt,CheckInterrupt}
Ahmad Fatoum [Mon, 15 Jul 2024 20:23:09 +0000 (22:23 +0200)] 
rtc: export RTC_Linux_{SwitchInterrupt,CheckInterrupt}

We have code to enable and disable the RTC's UIE interrupt, as well as
check whether it occurred and skip the first interrupt as it may be
bogus.
This is currently used as part of maintaining the correction file.

In a later commit, we will need the same functionality for using the RTC
as reference clock, so export the functions and give them descriptive
names appropriate for globally visible functions.

7 months agortc: pass info whether RTC is on UTC as a function parameter
Ahmad Fatoum [Mon, 22 Jul 2024 11:40:59 +0000 (13:40 +0200)] 
rtc: pass info whether RTC is on UTC as a function parameter

rtc_from_t() and t_from_rtc() call either gmtime or localtime depending
on the value of a global rtc_on_utc variable.

This will not be appropriate anymore when we start exporting functions
that call rtc_from_t() and t_from_rtc() for use outside of rtc_linux.c
as the rtc_on_utc variable may not have been initialized yet or at all.

Therefore make whether the RTC is on UTC a function parameter of these
functions, so the value can be propagated from the callers.

7 months agortc: let t_from_rtc/rtc_from_t operate on struct rtc_time directly
Ahmad Fatoum [Fri, 12 Jul 2024 14:12:44 +0000 (16:12 +0200)] 
rtc: let t_from_rtc/rtc_from_t operate on struct rtc_time directly

Both functions operate on struct tm even though the struct tm is only
used as intermediary format from struct rtc_time.

In the case of rtc_from_t, the code to convert from struct tm to struct
rtc is even duplicated.

Let's simplify code a bit by moving the struct translation code into
these conversion functions.

7 months agotest: pass make options in features compilation test
Miroslav Lichvar [Wed, 4 Dec 2024 11:03:57 +0000 (12:03 +0100)] 
test: pass make options in features compilation test

7 months agotest: extend socket unit test
Miroslav Lichvar [Mon, 2 Dec 2024 13:43:29 +0000 (14:43 +0100)] 
test: extend socket unit test

8 months agotest: add valgrind support to system tests
Miroslav Lichvar [Thu, 28 Nov 2024 15:05:48 +0000 (16:05 +0100)] 
test: add valgrind support to system tests

8 months agonts: close socket in helper process on exit
Miroslav Lichvar [Thu, 28 Nov 2024 13:45:23 +0000 (14:45 +0100)] 
nts: close socket in helper process on exit

Close the socket used for receiving helper requests before exit to avoid
another valgrind error.

8 months agomain: close pipe in grandparent process
Miroslav Lichvar [Thu, 28 Nov 2024 13:35:58 +0000 (14:35 +0100)] 
main: close pipe in grandparent process

Close the other end of the pipe in the grandparent process before exit
to avoid valgrind error.

Also, in the daemon process avoid closing the pipe for second time in
the 0-1024 close() loop to avoid another error.

8 months agoclient: close /dev/urandom on exit
Miroslav Lichvar [Thu, 28 Nov 2024 13:35:01 +0000 (14:35 +0100)] 
client: close /dev/urandom on exit

8 months agotest: enable valgrind fd tracking
Miroslav Lichvar [Thu, 28 Nov 2024 10:16:20 +0000 (11:16 +0100)] 
test: enable valgrind fd tracking

8 months agotest: update 106-refclock
Miroslav Lichvar [Wed, 27 Nov 2024 15:08:33 +0000 (16:08 +0100)] 
test: update 106-refclock

With the latest clknetsim all PHC readings should be valid (no
timestamps from future).

Also don't forget to remove refclock.log between tests.

8 months agoquantiles: add parameter to limit negative step
Miroslav Lichvar [Thu, 21 Nov 2024 13:30:14 +0000 (14:30 +0100)] 
quantiles: add parameter to limit negative step

Add a new parameter to limit the negative value of the step state
variable. It's set as a maximum delay in number of updates before the
actual step applied to the quantile estimate starts growing from the
minimum step when the input value is consistently larger or smaller than
the estimate.

This prevents the algorithm from effectively becoming the slower 1U
variant if the quantile estimate is stable most of the time.

Set it to 100 updates for the NTP delay and 1000 updates for the hwclock
delay. An option could be added later to make it configurable.

8 months agoquantiles: force step update with stable input values
Miroslav Lichvar [Thu, 21 Nov 2024 09:11:48 +0000 (10:11 +0100)] 
quantiles: force step update with stable input values

The algorithm was designed for estimating quantiles in streams of
integer values. When the estimate is equal to the input value, the
step state variable does not change. This causes problems for the
floating-point adaptation used for measurents of delay in chrony.

One problem is numerical instability due to the strict comparison of
the input value and the current estimate.

Another problem is with signals that are so stable that the nanosecond
resolution of the system functions becomes the limitation. There is a
large difference in the value of the step state variable, which
determines how quickly the estimate will adapt to a new distribution,
between signals that are constant in the nanosecond resolution and
signals that can move in two nanoseconds.

Change the estimate update to never consider the input value equal to
the current estimate and don't set the estimate exactly to the input
value. Keep it off by a quarter of the minimum step to force jumping
around the input value if it's constant and decreasing the step variable
to negative values. Also fix the initial adjustment to step at least by
the minimum step (the original algorithm is described with ceil(), not
fabs()).

8 months agontp+hwclock: add margin to estimated delay quantiles
Miroslav Lichvar [Mon, 18 Nov 2024 15:18:40 +0000 (16:18 +0100)] 
ntp+hwclock: add margin to estimated delay quantiles

Extend the interval of accepted delays by half of the quantile minimum
step in both directions to make room for floating-point errors in the
quantile calculation and an error that will be intentionally added in
the next commit.

8 months agoquantiles: add functions to get max k and min step
Miroslav Lichvar [Mon, 18 Nov 2024 14:54:17 +0000 (15:54 +0100)] 
quantiles: add functions to get max k and min step

8 months agoquantiles: fix assertion for requested k
Miroslav Lichvar [Mon, 18 Nov 2024 14:51:42 +0000 (15:51 +0100)] 
quantiles: fix assertion for requested k

8 months agotest: improve nts_ntp_auth test
Miroslav Lichvar [Thu, 14 Nov 2024 12:43:22 +0000 (13:43 +0100)] 
test: improve nts_ntp_auth test

8 months agotest: add 014-intermittent test
Miroslav Lichvar [Thu, 14 Nov 2024 12:41:41 +0000 (13:41 +0100)] 
test: add 014-intermittent test

8 months agotest: indicate failed sync stats
Miroslav Lichvar [Thu, 14 Nov 2024 12:40:43 +0000 (13:40 +0100)] 
test: indicate failed sync stats

8 months agotest: make system test users configurable
Miroslav Lichvar [Thu, 14 Nov 2024 09:53:35 +0000 (10:53 +0100)] 
test: make system test users configurable

8 months agosiv: drop internal implementation
Miroslav Lichvar [Tue, 12 Nov 2024 15:34:40 +0000 (16:34 +0100)] 
siv: drop internal implementation

Nettle (>=3.6) and GnuTLS (>=3.6.14) with the AES-SIV-CMAC support
required for NTS are now widely available in operating systems. Drop
the internal Nettle-based implementation.

8 months agoreference: make driftfile update interval configurable
Miroslav Lichvar [Tue, 12 Nov 2024 15:01:03 +0000 (16:01 +0100)] 
reference: make driftfile update interval configurable

Add interval option to the driftfile directive to specify the minimum
interval between updates of the recorded frequency offset and skew.

8 months agoclientlog: simplify code
lvgenggeng [Tue, 13 Aug 2024 08:33:27 +0000 (16:33 +0800)] 
clientlog: simplify code

8 months agorefclock: stop requiring 4 samples in median filter
Miroslav Lichvar [Tue, 5 Nov 2024 15:03:40 +0000 (16:03 +0100)] 
refclock: stop requiring 4 samples in median filter

Reduce the minimum number of samples required by the filter from
min(4, length) to 1.

This makes the filtering less confusing. The sample lifetime is limited
to one poll and the default filtering of the SOCK refclock (where the
maximum number of samples per poll is unknown) is identical to the other
refclocks.

A concern with potential variability in number of samples per poll below
4 is switching between different calculations of dispersion in
combine_selected_samples() in samplefilt.c.

The 106-refclock test shows how the order of refclocks in the config can
impact the first filtered sample and selection. If the PPS refclock
follows SHM, a single low-quality PPS sample is accepted in the same
poll where SHM is selected and the initial clock correction started,
which causes larger skew later and delays the first selection of the PPS
refclock.

8 months agorefclock: rework update of reachability
Miroslav Lichvar [Thu, 31 Oct 2024 13:41:19 +0000 (14:41 +0100)] 
refclock: rework update of reachability

Update the reachability register of a refclock source by 1 if a valid
measurement is received by the drivers between source polls, and not
only when it is accumulated to sourcestats, similarly to how
reachability works with NTP sources.

This avoids drops in the reported reachability when a PHC refclock is
dropping samples due to significant changes in the measured delay (e.g.
due to high PCIe load), or a PPS refclock dropping samples due to failed
lock.

9 months agodoc: fix typo in chrony.conf man page
Vincent Blut [Tue, 8 Oct 2024 21:01:20 +0000 (23:01 +0200)] 
doc: fix typo in chrony.conf man page

9 months agodoc: update NEWS 4.6.1
Miroslav Lichvar [Tue, 8 Oct 2024 11:49:14 +0000 (13:49 +0200)] 
doc: update NEWS

9 months agodoc: warn about MD5 keys not protecting extension fields
Miroslav Lichvar [Tue, 8 Oct 2024 12:13:13 +0000 (14:13 +0200)] 
doc: warn about MD5 keys not protecting extension fields

Add a warning to the chrony.conf man page that MD5 keys cannot protect
NTP extension fields due to the length extension attack.

9 months agoupdate copyright years
Miroslav Lichvar [Mon, 7 Oct 2024 14:17:07 +0000 (16:17 +0200)] 
update copyright years

9 months agonts: don't include compliant-128gcm record for other AEADs
Miroslav Lichvar [Tue, 8 Oct 2024 09:49:55 +0000 (11:49 +0200)] 
nts: don't include compliant-128gcm record for other AEADs

If the client included the NTS-KE record requesting compliant key
exporter context for AES-128-GCM-SIV, but the server doesn't select this
AEAD algorithm (it's not supported by the crypto library or it is
disabled by the ntsaeads directive), don't include the NTS-KE record in
the response. It's not relevant to the other AEAD algorithms.

9 months agonts: make server and client AEAD algorithms configurable
Miroslav Lichvar [Thu, 3 Oct 2024 12:25:53 +0000 (14:25 +0200)] 
nts: make server and client AEAD algorithms configurable

Add ntsaeads directive to specify a list of AEAD algorithms enabled for
NTS. The list is shared between the server and client. For the client it
also specifies the order of priority. The default is "30 15", matching
the previously hardcoded preference of AES-128-GCM-SIV (30) over
AES-SIV-CMAC-256 (15).

9 months agotest: improve nts_ke_client unit test
Miroslav Lichvar [Tue, 1 Oct 2024 09:44:16 +0000 (11:44 +0200)] 
test: improve nts_ke_client unit test

9 months agonts: check TLS session in NKSN_GetKeys()
Miroslav Lichvar [Mon, 30 Sep 2024 13:27:18 +0000 (15:27 +0200)] 
nts: check TLS session in NKSN_GetKeys()

Make sure the TLS session is not NULL in NKSN_GetKeys() before trying to
export the keys in case some future code tried to call the function
outside of the NTS-KE message handler.

9 months agonts: switch client to compliant key exporter on NTS NAK
Miroslav Lichvar [Thu, 19 Sep 2024 12:19:12 +0000 (14:19 +0200)] 
nts: switch client to compliant key exporter on NTS NAK

Implement a fallback for the NTS-NTP client to switch to the compliant
AES-128-GCM-SIV exporter context when the server is using the compliant
context, but does not support the new NTS-KE record negotiating its use,
assuming it can respond with an NTS NAK to the request authenticated
with the incorrect key.

Export both sets of keys when processing the NTS-KE response. If an NTS
NAK is the only valid response from the server after the last NTS-KE
session, switch to the keys exported with the compliant context for the
following requests instead of dropping all cookies and restarting
NTS-KE. Don't switch back to the original keys if an NTS NAK is received
again.

10 months agonts: negotiate compliant export of AES-128-GCM-SIV keys
Miroslav Lichvar [Thu, 19 Sep 2024 10:08:36 +0000 (12:08 +0200)] 
nts: negotiate compliant export of AES-128-GCM-SIV keys

Add client and server support for a new NTS-KE record to negotiate use
of the compliant key exporter context with the AES-128-GCM-SIV AEAD as
specified here:

https://chrony-project.org/doc/spec/nts-compliant-128gcm.html

10 months agonts: construct key exporter context
Miroslav Lichvar [Mon, 16 Sep 2024 12:15:38 +0000 (14:15 +0200)] 
nts: construct key exporter context

When the NTS client and server negotiated use of AES-128-GCM-SIV keys,
the keys exported from the TLS session and used for authentication and
encryption of NTP messages do not comply to RFC8915. The exporter
context value specified in the section 5.1 of RFC8915 function is
incorrect. It is a hardcoded string which contains 15 (AES-SIV-CMAC-256)
instead of 30 (AES-128-GCM-SIV). This causes chrony to not interoperate
with NTS implementations that follow RFC8915 correctly. (At this time,
there doesn't seem to be another implementation with AES-128-GCM-SIV
support yet.)

Replace the string with a proper construction of the exporter context
from a specified AEAD ID and next protocol.

Keep using the incorrect AEAD ID for AES-128-GCM-SIV to not break
compatibility with existing chrony servers and clients. A new NTS-KE
record will be added to negotiate the compliant exporter context.

Reported-by: Martin Mayer <martin.mayer@m2-it-solutions.de>
11 months agodoc: update NEWS 4.6
Miroslav Lichvar [Thu, 29 Aug 2024 08:27:52 +0000 (10:27 +0200)] 
doc: update NEWS

11 months agodoc: update README
Miroslav Lichvar [Thu, 29 Aug 2024 07:36:50 +0000 (09:36 +0200)] 
doc: update README

11 months agoupdate copyright years
Miroslav Lichvar [Thu, 29 Aug 2024 07:36:23 +0000 (09:36 +0200)] 
update copyright years

11 months agotest: make 110-chronyc more reliable
Miroslav Lichvar [Thu, 29 Aug 2024 07:25:16 +0000 (09:25 +0200)] 
test: make 110-chronyc more reliable

11 months agotest: make 106-refclock more reliable
Miroslav Lichvar [Thu, 29 Aug 2024 07:24:59 +0000 (09:24 +0200)] 
test: make 106-refclock more reliable

11 months agotest: make 108-peer more reliable
Miroslav Lichvar [Wed, 28 Aug 2024 14:49:25 +0000 (16:49 +0200)] 
test: make 108-peer more reliable

11 months agosources: replace unreachable sources before selection
Miroslav Lichvar [Wed, 28 Aug 2024 08:49:52 +0000 (10:49 +0200)] 
sources: replace unreachable sources before selection

The commit c43efccf0273 ("sources: update source selection with
unreachable sources") caused a high rate of failures in the
148-replacement test (1 falseticker vs 2 unreachable sources). This was
due to a larger fraction of the replacement attempts being made for the
source incorrectly marked as a falseticker instead of the second
unreachable source and the random process needed more time to get to the
expected state with both unreachable sources replaced.

When updating reachability of an unreachable source, try to request the
replacement of the source before calling the source selection, where
other sources may be replaced, to better balance the different
replacement attempts.

11 months agoconf: do not check, write and delete PID file if set to '/'
Luca Boccassi [Wed, 21 Aug 2024 19:21:47 +0000 (20:21 +0100)] 
conf: do not check, write and delete PID file if set to '/'

If the pid file path is specified as '/', skip handling it,
as it is not only unnecessary but complicates managing the
service. A systemd unit can manage the program without any
need for this functionality, and it makes process tracking
simpler and more robust.
The implementation matches the bindcmdaddress directive.

11 months agodoc: explain how to disable DNSSEC validation with sd-resolved in FAQ
Luca Boccassi [Wed, 21 Aug 2024 18:54:47 +0000 (19:54 +0100)] 
doc: explain how to disable DNSSEC validation with sd-resolved in FAQ

DNSSEC requires the system time to be synced in order to work,
as the signature date and expiration need to be checked by
resolvers. But it is possible that syncing the times requires
doing DNS queries. Add a paragraph to the FAQ explaining how
to break this cycle by asking nss-resolved to always avoid
DNSSEC when chronyd tries to resolve hostnames.

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.

12 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.

12 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.

13 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>
13 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.

15 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.

15 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

15 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.

15 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")
15 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.

15 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).

15 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.

15 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")