]> git.ipfire.org Git - thirdparty/chrony.git/log
thirdparty/chrony.git
7 years agorefclock: split off median filter
Miroslav Lichvar [Fri, 3 Aug 2018 13:15:36 +0000 (15:15 +0200)] 
refclock: split off median filter

Move the implementation of the median filter to a separate file to make
it useful for NTP. Replace some constants with parameters and generalize
the code to work with full NTP samples (including root dispersion/delay,
stratum, and leap).

For refclocks it should give the same results as before.

7 years agouse common structure for NTP samples
Miroslav Lichvar [Wed, 1 Aug 2018 14:28:26 +0000 (16:28 +0200)] 
use common structure for NTP samples

Define a structure for NTP samples and use it to pass samples from
the ntp_core and refclock code to sources and sourcestats.

7 years agosourcestats: don't save stratum for all samples
Miroslav Lichvar [Wed, 1 Aug 2018 14:19:37 +0000 (16:19 +0200)] 
sourcestats: don't save stratum for all samples

Save stratum only from the last accumulated sample as only that is
currently needed.

7 years agosourcestats: track leap status
Miroslav Lichvar [Wed, 1 Aug 2018 14:19:28 +0000 (16:19 +0200)] 
sourcestats: track leap status

This moves the leap status of the last sample from the source instance
to the sourcestats instance in order to make them both accumulate the
same data.

7 years agosys_linux: allow fcntl(F_SETFL) in seccomp filter
Miroslav Lichvar [Fri, 3 Aug 2018 08:39:32 +0000 (10:39 +0200)] 
sys_linux: allow fcntl(F_SETFL) in seccomp filter

This fixes commit 76bed76289575ba1640c02d370ae5304ef8c5fe2.

7 years agoconfigure: fix detection of timepps.h on FreeBSD
Miroslav Lichvar [Fri, 3 Aug 2018 08:08:01 +0000 (10:08 +0200)] 
configure: fix detection of timepps.h on FreeBSD

The header requires inttypes.h to be useful.

7 years agoconfigure: drop detection of stdint.h and inttypes.h
Miroslav Lichvar [Fri, 3 Aug 2018 08:03:07 +0000 (10:03 +0200)] 
configure: drop detection of stdint.h and inttypes.h

The current code uses macros from inttypes.h. There is no point in
detecting and selecting between stdint.h and inttypes.h as the latter is
always needed.

7 years agomemory: add missing include
Miroslav Lichvar [Wed, 1 Aug 2018 16:46:08 +0000 (18:46 +0200)] 
memory: add missing include

7 years agoutil: handle or ignore SIGPIPE signal
Miroslav Lichvar [Wed, 1 Aug 2018 10:20:17 +0000 (12:20 +0200)] 
util: handle or ignore SIGPIPE signal

In chronyc handle SIGPIPE similarly to SIGTERM. In chronyd ignore the
signal to avoid crashing when a TCP socket will be needed (e.g. for
NTS-KE) and will be unexpectedly closed from the other side.

7 years agoutil: handle errors in setting of signal handler as fatal
Miroslav Lichvar [Wed, 1 Aug 2018 09:59:00 +0000 (11:59 +0200)] 
util: handle errors in setting of signal handler as fatal

7 years agosched: allow file handler with multiple events to remove itself
Miroslav Lichvar [Tue, 31 Jul 2018 14:44:43 +0000 (16:44 +0200)] 
sched: allow file handler with multiple events to remove itself

Before dispatching a handler, check if it is still valid. This allows a
handler to remove itself when a descriptor has two different events at
the same time.

7 years agodoc: update chrony.conf man page for recent changes
Miroslav Lichvar [Fri, 22 Jun 2018 10:09:31 +0000 (12:09 +0200)] 
doc: update chrony.conf man page for recent changes

7 years agontp: allow sub-second maxpoll
Miroslav Lichvar [Thu, 21 Jun 2018 15:37:31 +0000 (17:37 +0200)] 
ntp: allow sub-second maxpoll

Remove the maxpoll-specific limit and allow both minpoll and maxpoll to
be set to a negative value.

7 years agontp: restrict use of sub-second polling intervals
Miroslav Lichvar [Thu, 21 Jun 2018 15:29:43 +0000 (17:29 +0200)] 
ntp: restrict use of sub-second polling intervals

When the local polling interval is adjusted between minpoll and maxpoll
to a sub-second value, check if the source is reachable and the minimum
measured delay is 10 milliseconds or less. If it's not, ignore the
maxpoll value and set the interval to 1 second.

This should prevent clients (mis)configured with an extremely short
minpoll/maxpoll from flooding servers on the Internet.

7 years agontp: make burst interval proportional to polling interval
Miroslav Lichvar [Thu, 21 Jun 2018 14:46:30 +0000 (16:46 +0200)] 
ntp: make burst interval proportional to polling interval

If the polling interval is shorter than 8 seconds, set the burst
interval to the 1/4th of the polling interval instead of the 2-second
constant. This should make the burst option and command useful with
very short polling intervals.

7 years agorefclock_sock: downgrade error messages to debug messages
Miroslav Lichvar [Wed, 20 Jun 2018 14:37:57 +0000 (16:37 +0200)] 
refclock_sock: downgrade error messages to debug messages

Turn error messages which are not expected to happen with a correctly
working SOCK client into debug messages.

7 years agofix printf()/scanf() format signedness
Miroslav Lichvar [Wed, 20 Jun 2018 14:28:10 +0000 (16:28 +0200)] 
fix printf()/scanf() format signedness

Fix mismatches between the format and sign of variables passed to
printf() or scanf(), which were found in a Frama-C analysis and gcc
using the -Wformat-signedness option.

7 years agokeys: initialize data used for measuring authentication delay
Miroslav Lichvar [Wed, 20 Jun 2018 12:36:28 +0000 (14:36 +0200)] 
keys: initialize data used for measuring authentication delay

This issue was found in a Frama-C analysis.

7 years agoreference: specify recipient in message when sending email
Miroslav Lichvar [Wed, 20 Jun 2018 11:02:55 +0000 (13:02 +0200)] 
reference: specify recipient in message when sending email

Instead of adding the recipient to the sendmail command line (which is
interpretted by the shell) add a "To" line to the message and run
sendmail with the -t option to read the recipient from the message.

7 years agoreference: terminate string returned by gethostname()
Miroslav Lichvar [Wed, 20 Jun 2018 10:27:59 +0000 (12:27 +0200)] 
reference: terminate string returned by gethostname()

POSIX doesn't require the string to be terminated if it didn't fit in
the buffer.

This issue was found in a Frama-C analysis.

7 years agocheck values returned by gmtime() and localtime()
Miroslav Lichvar [Wed, 20 Jun 2018 10:11:55 +0000 (12:11 +0200)] 
check values returned by gmtime() and localtime()

While it is not expected to happen with any time that can be represented
by the system clock, the functions are allowed to return NULL. Check the
pointer before dereferencing.

This issue was found in a Frama-C analysis.

7 years agoclient: re-work tab-completion to work with libedit 20180525-3.1
Lonnie Abelbeck [Thu, 14 Jun 2018 19:54:42 +0000 (14:54 -0500)] 
client: re-work tab-completion to work with libedit 20180525-3.1

Remove spaces from tab-completion results and now break on a space.
Tested with both readline and editline (libedit)
Incorporated Miroslav's suggestions.

7 years agodoc: fix description of pidfile directive to mention -Q option
Miroslav Lichvar [Thu, 7 Jun 2018 15:53:40 +0000 (17:53 +0200)] 
doc: fix description of pidfile directive to mention -Q option

This fixes commit 778fce4039e1763f9da367a97a53446d28810f1c.

7 years agoexamples: update pidfile in chronyd.service
Miroslav Lichvar [Thu, 7 Jun 2018 15:43:57 +0000 (17:43 +0200)] 
examples: update pidfile in chronyd.service

7 years agoconfigure: move default pidfile to /var/run/chrony
Miroslav Lichvar [Thu, 7 Jun 2018 14:54:59 +0000 (16:54 +0200)] 
configure: move default pidfile to /var/run/chrony

This allows chronyd to remove its pidfile on exit after dropping the
root privileges in order to prevent another chronyd instance from
failing to start, e.g. due to a wrong SELinux label from chronyd -q.

7 years agomain: create directories before writing pidfile
Miroslav Lichvar [Thu, 7 Jun 2018 14:43:59 +0000 (16:43 +0200)] 
main: create directories before writing pidfile

This makes it possible to save pidfile in /var/run/chrony.

7 years agontp: change auto_offline to trigger on failed transmissions
Miroslav Lichvar [Thu, 24 May 2018 15:29:15 +0000 (17:29 +0200)] 
ntp: change auto_offline to trigger on failed transmissions

Instead of counting missing responses, switch to the offline state
immediately when sendmsg() fails.

This makes the option usable with servers and networks that may drop
packets, and the effect will be consistent with the onoffline command.

7 years agoexamples: update NetworkManager dispatcher script
Miroslav Lichvar [Thu, 24 May 2018 15:03:31 +0000 (17:03 +0200)] 
examples: update NetworkManager dispatcher script

Replace most of the code with the new onoffline command.

7 years agocmdmon: add onoffline command
Miroslav Lichvar [Thu, 24 May 2018 14:56:56 +0000 (16:56 +0200)] 
cmdmon: add onoffline command

The onoffline command tells chronyd to switch all sources to the online
or offline status according to the current network configuration. A
source is considered online if it is possible to send requests to it,
i.e. a route to the network is present.

7 years agontp: allow online/offline state to be selected by connectability
Miroslav Lichvar [Thu, 24 May 2018 13:17:53 +0000 (15:17 +0200)] 
ntp: allow online/offline state to be selected by connectability

Allow SRC_MAYBE_ONLINE to be specified for new NTP sources and
connectivity setting to select between SRC_ONLINE and SRC_OFFLINE
according to the result of the connect() system call, i.e. check whether
the client has a route to send its requests.

7 years agontp: refactor switching between online and offline state
Miroslav Lichvar [Thu, 24 May 2018 11:42:52 +0000 (13:42 +0200)] 
ntp: refactor switching between online and offline state

Use an enum to describe connectivity of a source and merge
the NCR and NSR TakeSourceOnline/Offline() functions into
SetConnectivity() functions.

7 years agontp: check PHC index before opening device
Miroslav Lichvar [Mon, 21 May 2018 14:49:26 +0000 (16:49 +0200)] 
ntp: check PHC index before opening device

Apparently, it is possible for an interface to report all necessary
flags for HW timestamping without having a PHC. Check the PHC index to
avoid an error message in the system log saying that /dev/ptp-1 cannot
be opened.

7 years agontp: enable non-blocking mode on server sockets
Miroslav Lichvar [Mon, 21 May 2018 14:27:43 +0000 (16:27 +0200)] 
ntp: enable non-blocking mode on server sockets

Avoid blocking in sendmsg() due to a full send buffer.

7 years agodoc: add new questions to FAQ
Miroslav Lichvar [Mon, 21 May 2018 12:49:53 +0000 (14:49 +0200)] 
doc: add new questions to FAQ

7 years agoutil: fall back to reading /dev/urandom when getrandom() blocks
Miroslav Lichvar [Thu, 17 May 2018 12:16:58 +0000 (14:16 +0200)] 
util: fall back to reading /dev/urandom when getrandom() blocks

With recent changes in the Linux kernel, the getrandom() system call may
block for a long time after boot on machines that don't have enough
entropy. It blocks the chronyd's initialization before it can detach
from the terminal and may cause a chronyd service to fail to start due
to a timeout.

At least for now, enable the GRND_NONBLOCK flag to make the system call
non-blocking and let the code fall back to reading /dev/urandom (which
never blocks) if the system call failed with EAGAIN or any other error.

This makes the start of chronyd non-deterministic with respect to files
that it needs to open and possibly also makes it slightly easier to
guess the transmit/receive timestamp in client requests until the
urandom source is fully initialized.

7 years agoexamples: make nm-dispatcher script usable for networkd-dispatcher
Christian Ehrhardt [Wed, 18 Apr 2018 13:44:21 +0000 (15:44 +0200)] 
examples: make nm-dispatcher script usable for networkd-dispatcher

Historically there were plenty of callback based implementations around
ifupdown via /etc/network/if-up and similar. NetworkManager added the
dispatcher [1] feature for such a kind of functionality.

But so far a systemd-networkd (only) systemd had no means to handle those
cases. This is solved by networkd-dispatcher which is currently available
at least in ArchLinux and Ubuntu.
It takes away the responsibility to listen on netlink events in each
application and provides a more classic script-drop-in interface to respond
to networkd events [3].

This commit makes the NM example compatible to be used by NetworkManager
dispatcher as well as by networkd-dispatcher. That way we avoid too much
code duplication and can from now on handle special cases in the
beginning so that the tail can stay commonly used.

After discussion on IRC the current check differs by checking the
argument count (only in NetworkManager), if ever needed we could extend
that to check for known custom environment vars (NetworkManager =>
CONNECTION_UUID; networkd-dispatcher => OperationalState).

[1]: https://developer.gnome.org/NetworkManager/stable/NetworkManager.html
[2]: https://github.com/craftyguy/networkd-dispatcher
[3]: https://github.com/systemd/systemd/blob/master/src/systemd/sd-network.h#L86

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
7 years agosys_linux: fix building with old libcap versions
Miroslav Lichvar [Thu, 5 Apr 2018 14:18:23 +0000 (16:18 +0200)] 
sys_linux: fix building with old libcap versions

The cap_get_bound() function and CAP_IS_SUPPORTED macro were added in
libcap-2.21. Check if the macro is defined before use.

The sys/capability.h header from libcap-2.16 and earlier disables the
linux/types.h header, which breaks the linux/ptp_clock.h header. Change
the order to include sys/capability.h as the last system header.

7 years agodoc: update NEWS 3.3
Miroslav Lichvar [Wed, 4 Apr 2018 07:17:08 +0000 (09:17 +0200)] 
doc: update NEWS

7 years agoclient: update copyright years
Miroslav Lichvar [Wed, 4 Apr 2018 07:14:16 +0000 (09:14 +0200)] 
client: update copyright years

7 years agontp: fix handling of socket errors with error queue
Miroslav Lichvar [Wed, 4 Apr 2018 07:07:10 +0000 (09:07 +0200)] 
ntp: fix handling of socket errors with error queue

In the next Linux version the recvmmsg() system call will be probably
fixed to not return socket errors (e.g. due to ICMP) when reading from
the error queue.

The NTP I/O code assumed this was the correct behavior. When the system
call is fixed, a socket error on a client socket will cause chronyd to
enter a busy loop consuming the CPU until the receive timeout is reached
(8 seconds by default).

Use getsockopt(SO_ERROR) to clear the socket error when reading from the
error queue failed.

7 years agoprivops: allow binding to acquisition port
Miroslav Lichvar [Tue, 3 Apr 2018 09:05:33 +0000 (11:05 +0200)] 
privops: allow binding to acquisition port

Fix the privileged helper process to allow binding of client sockets to
a non-zero acquisition port which is not equal to the server port.

7 years agodoc: improve FAQ
Miroslav Lichvar [Tue, 27 Mar 2018 15:57:17 +0000 (17:57 +0200)] 
doc: improve FAQ

7 years agodoc: improve description of fallbackdrift directive
Miroslav Lichvar [Tue, 27 Mar 2018 11:08:01 +0000 (13:08 +0200)] 
doc: improve description of fallbackdrift directive

7 years agodoc: improve description of key option in chrony.conf man page
Miroslav Lichvar [Mon, 26 Mar 2018 17:00:50 +0000 (19:00 +0200)] 
doc: improve description of key option in chrony.conf man page

7 years agodoc: update installation document
Miroslav Lichvar [Mon, 26 Mar 2018 11:21:54 +0000 (13:21 +0200)] 
doc: update installation document

7 years agoupdate copyright years
Miroslav Lichvar [Thu, 22 Mar 2018 17:05:00 +0000 (18:05 +0100)] 
update copyright years

7 years agontp: fix compiler warnings
Miroslav Lichvar [Tue, 20 Mar 2018 09:16:39 +0000 (10:16 +0100)] 
ntp: fix compiler warnings

Warnings about using uninitialized variables were seen with gcc-7.3.1
and -O3 in CFLAGS.

7 years agoconfigure: include SECHASH in chronyc features
Miroslav Lichvar [Tue, 20 Mar 2018 08:41:53 +0000 (09:41 +0100)] 
configure: include SECHASH in chronyc features

chronyc is linked with the crypto library and the keygen command checks
if the specified hash function is known.

7 years agotest: extend 126-burst
Miroslav Lichvar [Mon, 19 Mar 2018 16:21:32 +0000 (17:21 +0100)] 
test: extend 126-burst

7 years agotest: fix hash unit test for NSS
Miroslav Lichvar [Mon, 19 Mar 2018 12:07:58 +0000 (13:07 +0100)] 
test: fix hash unit test for NSS

Some hash functions in the freebl3 library ignore the length of the
output buffer and always return the length of the digest.

7 years agohash: initialize return value before calling NSS hash functions
Miroslav Lichvar [Mon, 19 Mar 2018 12:02:47 +0000 (13:02 +0100)] 
hash: initialize return value before calling NSS hash functions

Some hash functions in the freebl3 library don't support truncated
digests and either return immediately with no update of the output
length, or ignore the length of the output buffer and always write whole
digest.

Initialize the return value to zero to get correct result with the
former.

This is triggered only in the hash unit test. chronyd always provides a
sufficient buffer for the digest.

7 years agodoc: update NEWS 3.3-pre1
Miroslav Lichvar [Thu, 15 Mar 2018 07:36:38 +0000 (08:36 +0100)] 
doc: update NEWS

7 years agohash: add support for older nettle versions
Miroslav Lichvar [Thu, 15 Mar 2018 07:18:29 +0000 (08:18 +0100)] 
hash: add support for older nettle versions

Use nettle_hashes[] instead of nettle_get_hashes(), which is available
only in nettle >= 3.4. nettle_hashes[] is a symbol available in older
versions and may be renamed in future. In nettle >= 3.4 it is a macro
using nettle_get_hashes() for compatibility.

7 years agodoc: update README
Miroslav Lichvar [Wed, 14 Mar 2018 15:14:38 +0000 (16:14 +0100)] 
doc: update README

7 years agosys_linux: report if CAP_SYS_TIME is not present
Christian Ehrhardt [Wed, 14 Mar 2018 14:05:29 +0000 (15:05 +0100)] 
sys_linux: report if CAP_SYS_TIME is not present

Instead of having adjtimex just fail with a permission issue
improve the error messaging by warning for the lack of
CAP_SYS_TIME on SYS_Linux_Initialise.

Message will look like (instead of only the latter message):
 CAP_SYS_TIME not present
 adjtimex(0x8001) failed : Operation not permitted

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
7 years agodoc: improve description of -x in chronyd man page
Miroslav Lichvar [Wed, 14 Mar 2018 12:27:03 +0000 (13:27 +0100)] 
doc: improve description of -x in chronyd man page

7 years agontp: fix adjustment of init_local_rx timestamp
Miroslav Lichvar [Wed, 14 Mar 2018 13:56:57 +0000 (14:56 +0100)] 
ntp: fix adjustment of init_local_rx timestamp

This fixes commit f0f18a02a7d97a3cfb4cd9977f5ec12c6b1f1028.

7 years agontp: add debug message to update of link speed
Miroslav Lichvar [Wed, 14 Mar 2018 12:25:18 +0000 (13:25 +0100)] 
ntp: add debug message to update of link speed

7 years agotest: update compilation test to disable nettle
Miroslav Lichvar [Tue, 13 Mar 2018 09:19:15 +0000 (10:19 +0100)] 
test: update compilation test to disable nettle

7 years agodoc: update supported hash functions in chrony.conf man apge
Miroslav Lichvar [Tue, 13 Mar 2018 09:01:59 +0000 (10:01 +0100)] 
doc: update supported hash functions in chrony.conf man apge

7 years agohash: add support for nettle
Miroslav Lichvar [Tue, 13 Mar 2018 09:01:44 +0000 (10:01 +0100)] 
hash: add support for nettle

7 years agohash: add support for SHA-3 with libtomcrypt
Miroslav Lichvar [Mon, 12 Mar 2018 18:06:21 +0000 (19:06 +0100)] 
hash: add support for SHA-3 with libtomcrypt

7 years agotest: add hash unit test
Miroslav Lichvar [Mon, 12 Mar 2018 11:42:07 +0000 (12:42 +0100)] 
test: add hash unit test

7 years agodoc: fix typo in chrony.conf man page
Miroslav Lichvar [Mon, 12 Mar 2018 11:30:05 +0000 (12:30 +0100)] 
doc: fix typo in chrony.conf man page

7 years agontp: add missing breaks in switch statement
Miroslav Lichvar [Mon, 12 Mar 2018 08:58:40 +0000 (09:58 +0100)] 
ntp: add missing breaks in switch statement

Fortunately, they didn't change the behavior of the code.

7 years agotest: use random version in ntp_core unit test
Miroslav Lichvar [Wed, 7 Mar 2018 12:17:29 +0000 (13:17 +0100)] 
test: use random version in ntp_core unit test

7 years agontp: respond to NTPv1 client requests with zero mode
Miroslav Lichvar [Wed, 7 Mar 2018 10:12:52 +0000 (11:12 +0100)] 
ntp: respond to NTPv1 client requests with zero mode

NTPv1 packets have a reserved field instead of the mode field and the
actual mode is determined from the port numbers. It seems there is still
a large number of clients sending NTPv1 requests with a zero value in
the field (per RFC 1059).

Follow ntpd and respond to the requests with server mode packets.

7 years agoclient: improve handling of unknown responses
Miroslav Lichvar [Tue, 6 Mar 2018 10:48:44 +0000 (11:48 +0100)] 
client: improve handling of unknown responses

Rework the code to not ignore valid packets with unknown or obsolete
responses and return immediately with "bad reply from daemon" instead of
timing out with "cannot talk to daemon".

7 years agocmdmon: initialize all bytes of reply buffer
Miroslav Lichvar [Tue, 6 Mar 2018 10:30:34 +0000 (11:30 +0100)] 
cmdmon: initialize all bytes of reply buffer

Instead of zeroing individual fields, zero all bytes of the buffer
before the reply is formed.

This may have a small impact on performance, but it simplifies the code
and minimizes the risk of leaking uninitialized memory.

7 years agocmdmon: update protocol changelog
Miroslav Lichvar [Mon, 5 Mar 2018 17:42:16 +0000 (18:42 +0100)] 
cmdmon: update protocol changelog

7 years agocmdmon: make length of manual list constant
Miroslav Lichvar [Mon, 5 Mar 2018 17:37:20 +0000 (18:37 +0100)] 
cmdmon: make length of manual list constant

Make the length of responses containing manual samples constant to
simplify the protocol. It was the only type of response that had a
variable length.

This reverts commit 2343e7a89c0bacdfccf892f881c4b89b2990c512.

7 years agontp: check RX and TX timestamp in interleaved client requests
Miroslav Lichvar [Mon, 5 Mar 2018 09:15:42 +0000 (10:15 +0100)] 
ntp: check RX and TX timestamp in interleaved client requests

Clients sending packets in the interleaved mode are supposed to use
a different receive and transmit timestamp in order to reliably detect
the mode of the response. If an interleaved request with the receive
timestamp equal to the transmit timestamp is detected, respond in the
basic mode.

7 years agodoc: update README
Miroslav Lichvar [Fri, 2 Mar 2018 13:46:08 +0000 (14:46 +0100)] 
doc: update README

7 years agocmdmon: add shutdown command
Miroslav Lichvar [Fri, 2 Mar 2018 11:51:52 +0000 (12:51 +0100)] 
cmdmon: add shutdown command

The command is functionally equivalent to sending the process the
SIGTERM signal.

7 years agontp: delay enabling permanent kernel RX timestamping on Linux
Miroslav Lichvar [Fri, 2 Mar 2018 10:49:53 +0000 (11:49 +0100)] 
ntp: delay enabling permanent kernel RX timestamping on Linux

Wait until a kernel RX timestamp is actually missing before opening the
dummy socket in order to avoid a small performance impact in case the
servers are so slow/distant that the kernel can constantly win the race.

7 years agotest: add 126-burst test
Miroslav Lichvar [Tue, 27 Feb 2018 17:41:24 +0000 (18:41 +0100)] 
test: add 126-burst test

7 years agontp: add burst option
Miroslav Lichvar [Tue, 27 Feb 2018 16:35:16 +0000 (17:35 +0100)] 
ntp: add burst option

When the burst option is specified in the server/pool directive and the
current poll is longer than the minimum poll, initiate on each poll a
burst with 1 good sample and 2 or 4 total samples according to the
difference between the current and minimum poll.

7 years agodoc: improve description of server options
Miroslav Lichvar [Tue, 27 Feb 2018 15:25:31 +0000 (16:25 +0100)] 
doc: improve description of server options

7 years agotest: make 119-smoothtime more reliable
Miroslav Lichvar [Mon, 26 Feb 2018 16:23:06 +0000 (17:23 +0100)] 
test: make 119-smoothtime more reliable

7 years agosources: include maxclockerror in source selection
Miroslav Lichvar [Thu, 22 Feb 2018 16:30:23 +0000 (17:30 +0100)] 
sources: include maxclockerror in source selection

In the source selection algorithm, include extra dispersion due to
maxclockerror in the root distance of sources that don't have new
samples (the last sample is older than span of all samples) to not
prefer unreachable sources with a short distance and small skew over
reachable sources for too long, and also to decrease their chances of
becoming falsetickers.

7 years agomain: open /dev/null as stdin/out/err in daemonization
Miroslav Lichvar [Wed, 21 Feb 2018 11:50:14 +0000 (12:50 +0100)] 
main: open /dev/null as stdin/out/err in daemonization

chronyd doesn't normally write anything to stdout or stderr when running
as a daemon, but it is a good practice to replace them with descriptors
of /dev/null to prevent accidental writes to other files or sockets that
would otherwise take their place.

7 years agologging: don't write fatal messages to invalid descriptor
Miroslav Lichvar [Wed, 21 Feb 2018 11:40:53 +0000 (12:40 +0100)] 
logging: don't write fatal messages to invalid descriptor

If opening the log file specified with the -l option failed (after
closing all descriptors), the error message is written to an invalid
descriptor as no log file or syslog is opened yet. Fix the code to track
when the output is usable.

7 years agoutil: replace assert for missing MD5 with fatal log message
Miroslav Lichvar [Wed, 21 Feb 2018 10:10:26 +0000 (11:10 +0100)] 
util: replace assert for missing MD5 with fatal log message

Apparently, on some systems the MD5 function is missing with the NSS
support (freebl3). Instead of failing an assertion, exit with a log
message.

7 years agotest: update util unit test
Miroslav Lichvar [Fri, 23 Feb 2018 15:33:42 +0000 (16:33 +0100)] 
test: update util unit test

7 years agotest: improve and extend ntp_core unit test
Miroslav Lichvar [Tue, 20 Feb 2018 16:35:16 +0000 (17:35 +0100)] 
test: improve and extend ntp_core unit test

7 years agosourcestats: limit minimum value of std_dev
Miroslav Lichvar [Fri, 23 Feb 2018 11:30:20 +0000 (12:30 +0100)] 
sourcestats: limit minimum value of std_dev

7 years agontp: compare receive timestamp when checking for duplicate
Miroslav Lichvar [Fri, 23 Feb 2018 13:17:07 +0000 (14:17 +0100)] 
ntp: compare receive timestamp when checking for duplicate

Compare both receive and transmit timestamps in the NTP test number 1.

This prevents a client from dropping a valid response in the interleaved
mode if it follows a response in the basic mode and the server did not
have a kernel/hardware transmit timestamp, and the random bits of the
two timestamps happen to be the same (chance of 1 in 2^(32-precision)).

7 years agontp: don't send packets with RX/TX timestamp equal to another timestamp
Miroslav Lichvar [Tue, 20 Feb 2018 08:46:08 +0000 (09:46 +0100)] 
ntp: don't send packets with RX/TX timestamp equal to another timestamp

Before sending a new packet, check if the receive/transmit timestamp
is not equal to the origin timestamp or the previous receive/transmit
timestamp in order to prevent the packet from being its own valid
response (in the symmetric mode) and invalidate responses to the
previous packet.

This improves protection against replay attacks in the symmetric mode.

7 years agontp: separate timestamps for restarting symmetric protocol
Miroslav Lichvar [Fri, 16 Feb 2018 16:07:56 +0000 (17:07 +0100)] 
ntp: separate timestamps for restarting symmetric protocol

Save the local receive and remote transmit timestamp needed for
(re)starting the symmetric protocol when no valid reply was received
separately from the timestamps that are used for synchronization of the
local clock.

This extends the interval in which the local NTP state is (partially)
protected against replay attacks in order to complete a measurement
in the interleaved symmetric mode from [last valid RX, next TX] to
[last TX, next TX], i.e. it should be the same as in the basic mode.

7 years agomain: create directories before refclock initialization
Miroslav Lichvar [Fri, 16 Feb 2018 09:36:41 +0000 (10:36 +0100)] 
main: create directories before refclock initialization

This allows the SOCK refclock to open sockets in the /var/run/chrony
directory.

7 years agomain: improve error message for failed getpwnam()
Miroslav Lichvar [Fri, 16 Feb 2018 09:33:04 +0000 (10:33 +0100)] 
main: improve error message for failed getpwnam()

7 years agoconfigure: improve check for timestamping options
Miroslav Lichvar [Fri, 16 Feb 2018 08:41:22 +0000 (09:41 +0100)] 
configure: improve check for timestamping options

The socket.h header provided by musl doesn't seem to include the kernel
headers and is missing SCM_TIMESTAMPING_PKTINFO, which causes the
Linux-specific code in chrony to fail to build.

7 years agopktlength: handle truncated MANUAL_LIST reply
Miroslav Lichvar [Thu, 15 Feb 2018 16:29:40 +0000 (17:29 +0100)] 
pktlength: handle truncated MANUAL_LIST reply

Before reading the n_samples field of the MANUAL_LIST reply, check if it
is actually contained in the received message. This does not change the
outcome of the client's length check as the returned length was always
larger than the length of the truncated reply and it was dropped anyway,
but it prevents the client from reading uninitialized memory.

7 years agosourcestats: reset instance before loading dump file
Miroslav Lichvar [Thu, 15 Feb 2018 16:10:45 +0000 (17:10 +0100)] 
sourcestats: reset instance before loading dump file

Don't rely on the caller to reset the instance and always reset it
before loading data to make sure it can't get to an unexpected state.

7 years agodoc: improve description of refclock tai option
Miroslav Lichvar [Thu, 15 Feb 2018 15:47:41 +0000 (16:47 +0100)] 
doc: improve description of refclock tai option

Emphasize that tzdata must be kept up to date in order for the
correction to work as expected.

7 years agotest: add 125-packetloss test
Miroslav Lichvar [Thu, 15 Feb 2018 15:47:01 +0000 (16:47 +0100)] 
test: add 125-packetloss test

7 years agotest: extend 106-refclock
Miroslav Lichvar [Thu, 15 Feb 2018 13:05:26 +0000 (14:05 +0100)] 
test: extend 106-refclock

7 years agotest: extend 110-chronyc
Miroslav Lichvar [Thu, 15 Feb 2018 12:35:06 +0000 (13:35 +0100)] 
test: extend 110-chronyc

7 years agontp: keep kernel RX timestamping permanently enabled on Linux
Miroslav Lichvar [Wed, 14 Feb 2018 09:11:19 +0000 (10:11 +0100)] 
ntp: keep kernel RX timestamping permanently enabled on Linux

The Linux kernel has a counter for sockets using kernel RX timestamping
and timestamps (all) received packets only when it is not zero. However,
this counter is updated asynchronously from setsockopt(). If there are
currently no other sockets using the timestamping, it is possible that a
fast server response is received before the kernel timestamping is
actually enabled after setting the socket option and sending a request.

Open a dummy socket on start to make sure there is always at least one
timestamping socket to avoid the race condition.

7 years agoexamples: ignore non-up/down events in nm-dispatcher script
Miroslav Lichvar [Tue, 13 Feb 2018 10:44:24 +0000 (11:44 +0100)] 
examples: ignore non-up/down events in nm-dispatcher script