In preparation of adding OpenBSD support:
OpenBSD doesn't support timex but adjusting frequency using the
adjfreq(2) system call. Add a privops method PRV_AdjustFreq() to allow
unprivileged processes to set the time.
In preparation of OpenBSD support, add SYS_EnableSystemCallFilter() call
to PRV_StartHelper().
In OpenBSD the privops helper will use a system call filter (pledge(2)),
whereas in Linux the privops helper doesn't use any system call filter
at the moment.
Modify Unit test ntp_sources call to PRV_Initialise() with parameter
scfilter_level set to 0.
`DEFAULT_OPEN_COMMANDS` is defined as `activity manual rtcdata smoothing
sourcename sources sourcestats tracking`, so it looks like `sourcestats`
and `serverstats` were swapped in the documentation.
The macOS driver was using the old settimeofday() variables. Now uses
timespec as required by updated PRV_SetTime().
Fixes: e313f5abf7 ("privops: switch from settimeofday() to clock_settime()")
Following the removal of gettimeofday() calls, change PRV_SetTime() to
use clock_settime() instead of settimeofday(). Only CLOCK_REALTIME is
supported for now.
Make clock_gettime() a hard requirement of chrony. It should be
available on all reasonably recent versions of the supported systems.
This enables adoption of the clockid_t type (CLOCK_* identifiers).
Update the support for NTP over PTP to the latest specification
(currently in the RFC editor queue). Switch the NTP TLV to the
organization-specific TLV using the IANA OUI and assigned TLV
subtype 0x1. The Network Correction extension field has been
assigned type 0x10A. The extfield option accepts F324 as an alias
for 10A to not break existing configurations. Drop the experimental
status.
Drop the old workaround avoiding small changes in ticks needed to avoid
frequency steps due to inexact scaling of frequency vs ticks in kernels
before 2.6.18. chrony doesn't support such old kernels anymore.
The NSR_ReportSource() and RCL_ReportSource() functions assume that the
provided report already has some data prefilled by SRC_ReportSource()
and it's assumed these functions cannot fail.
Change them to accept the required data (refid and IP address) as
a parameter, remove unneeded parameters, and return an error status
(if the refid/address doesn't exist) to be handled in cmdmon
handle_source_data(). Also, catch unexpected values of the source state
and mode to make chronyc report an error instead of incorrect data.
When chronyd gets a kernel or hardware transmit timestamp after sending
an NTP message to a server, peer, or client (using interleaved mode), it
needs the address and content of the message to be able to correctly
assign the timestamp to the server, peer, or client. The timestamps are
processed asynchronously. The kernel provides with each timestamp the
data-link frame that was timestamped, but chronyd can extract the
necessary data only from plain IPv4 and IPv6 packets in Ethernet frames,
possibly including VLAN tags. If the NTP packets are transmitted by a
non-Ethernet device, or they are encapsulated in another layer (e.g. a
WireGuard tunnel), chronyd is not able to extract the data and use the
kernel or hardware transmit timestamps, having to fall back to less
accurate daemon timestamps.
Add an alternative method using transmit IDs assigned to each message
(supported since Linux 6.13), which are provided by the kernel with the
timestamp in the error queue, and map them to messages, addresses and
ports saved in a ring buffer, whose size can be configured by the new
maxtxbuffers directive.
Fow now, set the default maxtxbuffers to 0 (disabled). If set to a
non-zero value, allocate the ring buffer to the maximum size on start.
As a future improvement, it could be allocated only when the extraction
of the UDP payload fails, or the extracted message is not the expected
NTP message. The size could grow dynamically when a transmit ID is
missed.
Add a new field to the SCK_Message structure to enable setting and
getting of the Linux timestamping transmit IDs enabled by the
SOF_TIMESTAMPING_OPT_ID socket option. The ID can be set for each packet
individually by the SCM_TS_OPT_ID control message (supported on Linux
6.13 and newer).
This will allow procesing of transmit timestamps without extracting data
from the data-link frames.
Add minstratum and maxstratum directives to specify the minimum and
maximum allowed stratum of sources to be selected. The default values
are 0 and 15 respectively, allowing all NTP sources and refclocks.
Sources that are rejected due to having too large or too small stratum
are marked with 'r' in the selection log and selectdata report.
This is similar to the "tos floor" and "tos ceiling" settings of ntpd,
except that maxstratum is interpreted as one below the ceiling.
There is no need to save the SST_GetSelectionData() "select_ok" status
as the source is immediately marked as SRC_BAD_STATS if it is not ok.
Nothing else is using this information.
The recent replacement of <termios.h> with <linux/termios.h> to get
TCGETS2 seems to work only with compilers (or C standards) that allow
the same structure to be defined multiple times. There is a conflict
between <sys/ioctl.h> and <linux/termios.h>.
Another problem is that TCGETS2 is not used on some archs like ppc64.
Switch back to <termios.h> and move TCGETS2 to a list in a separate
file where it can be compiled without <sys/ioctl.h>.
Fixes: 03875f1ea5 ("sys_linux: allow ioctl(TCGETS2) in seccomp filter")
Add TCGETS2 to the list of allowed ioctls. It seems to be called by the
latest glibc version from isatty(), which is called from libpcsclite
used by gnutls in an NTS-KE session.
Include the linux termios header instead of glibc header to get a usable
definition of TCGETS2.
By default, the clock precision is set to the minimum measured time
needed to read the clock. This value is typically larger than the actual
resolution, which causes the NTP server to add more noise to NTP
timestamps than necessary. With HW timestamping and PTP corrections
enabled by the NTP-over-PTP transport that can be the limiting factor in
the stability of NTP measurements.
Try to determine the actual resolution of the clock. On non-Linux
systems use the clock_getres() function. On FreeBSD and NetBSD it seems
to provide expected values. On illumos it returns a large value (kernel
tick length?). On Linux it seems to be the internal timer resolution,
which is 1 ns with hrtimers, even when using a lower-resolution
clocksource like hpet or acpi_pm.
On Linux, try to measure the resolution as the minimum observed change
in differences between consecutive readings of the CLOCK_MONOTONIC_RAW
clock with a varying amount of busy work. Ignore 1ns changes due to
the kernel converting readings to timespec. This seems to work reliably.
In a test with the acpi_pm clocksource, differences of 3073, 3352, and
3631 ns were measured, which gives a resolution of 279 ns, matching the
clocksource frequency of ~3.58 MHz. With a tsc clocksource it gives
the minimum accepted resolution of 2 ns and with kvm-clock 10 ns.
As the final value of the precision, use the minimum value from the
measured or clock_getres() resolution and the original minimum time
needed to read the clock.
SCK_AcceptConnection() always returns a non-blocking socket. Clear the
O_NONBLOCK flag in the socket unit test, which relies on blocking, to
avoid failures.
Reported-by: Matthias Andree <matthias.andree@gmx.de>
If the specified PHC device cannot be opened directly, an attempt is
made to open it as a network interface. When that fails, the error
"Could not open PHC of iface" is misleading the user that it was handled
only as an interface. Change the message to "Could not open PHC (of)" to
better cover both possibilities. Also remove the errno as it's not set
in all code paths.
Use lchown(), the safer variant of chown() that does not follow
symlinks, when changing the ownership of a created directory (logdir,
dumpdir, ntsdumpdir, and the directory of bindcmdaddress) to the chrony
user.
Fix one of the sizeofs in open_unix_socket() to correctly specify
sock_dir2 instead of sock_dir1. They have the same size, but don't rely
on that.
Fixes: 90d808ed28 ("client: mitigate unsafe permissions change on chronyc socket")
The recent rework of refclock reachability to better work with
driver-specific filtering (PHC driver dropping samples with unexpected
delay) introduced an issue that a PPS refclock is indicated as reachable
even when its "lock" refclock is permanently unreachable, or its samples
constistently fail in other sample checks, and no actual samples can be
accumulated. This breaks the new maxunreach option.
Rework the refclock code to provide samples from drivers together with
their quality level (all drivers except PHC provide samples with
constant quality of 1) and drop samples with quality 0 after passing
all checks, right before the actual accumulation in the median sample
filter. Increment the reachability counter only for samples that would
be accumulated.
This fixes the problem with refclocks indicated as reachable when their
samples would be dropped for other reasons than the PHC-specific delay
filter, and the maxunreach option can work as expected.
Fixes: b9b338a8df ("refclock: rework update of reachability")
Modify the HCL_ProcessReadings() function to try to always provide
a valid sample. Instead of dropping a sample outside of the expected
delay, provide its assumed quality level as a small integer (relative to
already accumulated samples), and let the caller decide what quality is
acceptable.
In version 6.15 the Linux kernel started checking write access on the
PHC file descriptor in the PTP_PIN_SETFUNC and PTP_EXTTS_REQUEST ioctls.
chronyd opened the PHC device as readonly, which caused the PHC refclock
driver configured with the extpps option to fail with the
"Could not enable external PHC timestamping" error message.
To ensure compatibility with new kernel versions, add flags to the
SYS_Linux_OpenPHC() function and open the device with the O_RDWR flag
when the extpps option is enabled.
The TLS_CreateInstance() function handles a NULL alpn_name, but the
other session functions would crash if it was NULL. Change the function
to not handle the NULL for consistency and avoid potential confusion.
Fixes: 3e32e7e694 ("tls: move gnutls code into tls_gnutls.c")
Add an additional parameter to TLS_CreateInstance() to save the label of
the connection (server name on the client side and client IP
address:port on the server side) instead of the server name (which is
NULL on the server side) to fix the log messages.
Fixes: 3e32e7e694 ("tls: move gnutls code into tls_gnutls.c")