Commit graph

214 commits

Author SHA1 Message Date
Miroslav Lichvar
afff06c88c ntp: add options to set minsamples/maxsamples of hwclock 2018-08-09 14:52:08 +02:00
Miroslav Lichvar
ce6b896948 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.
2018-05-25 10:53:21 +02:00
Chris Perl
f5d1b8fb74 refclock: add tai option
This option is for indicating to chronyd that the reference clock is
kept in TAI and that chrony should attempt to convert from TAI to UTC by
using the timezone configured by the "leapsectz" directive.
2017-10-11 17:28:34 +02:00
Andreas Steinmetz
154b39cf7a refclock: add stratum option 2017-10-09 10:39:20 +02:00
Miroslav Lichvar
6f8fba9a3f conf: check if GLOB_NOMAGIC is defined
This option is not supported by musl and possibly other libc
implementations.
2017-09-01 11:32:16 +02:00
Miroslav Lichvar
aee42fada8 ntp: allow TX-only HW timestamping by default
If no rxfilter is specified in the hwtimestamp directive and the NIC
doesn't support the all or ntp filter, enable TX-only HW timestamping
with the none filter.
2017-08-23 15:01:30 +02:00
Miroslav Lichvar
ea85bc43e0 conf: don't allow slash with hostname in allow/deny directive 2017-07-25 17:40:35 +02:00
Miroslav Lichvar
778fce4039 main: don't require root privileges with -Q option
If the -Q option is specified, disable by default pidfile, ntpport,
cmdport, Unix domain command socket, and clock control, in order to
allow starting chronyd without root privileges and/or when another
chronyd instance is already running.
2017-07-13 16:10:54 +02:00
Miroslav Lichvar
9983185d6d ntp: define NTP port for configuration code 2017-07-13 16:10:54 +02:00
Miroslav Lichvar
cc507bffae conf: abort when include directive fails
When parsing the include directive, call glob() with the GLOB_ERR and
GLOB_NOMAGIC flags, and abort with an error message when matching of the
pattern failed with other error than GLOB_NOMATCH.

This restores the original behavior of the directive when it didn't
allow patterns, but it will still not fail with patterns not matching
any files in an existing directory.
2017-06-27 15:29:01 +02:00
Miroslav Lichvar
f2da253bc3 ntp: add option to select HW RX timestamping filter
Add an rxfilter option to the hwtimestamp directive to select which
received packets should be timestamped. It can be set to "none", "ntp",
or "all". The default value is ntp, which falls back to all when ntp is
not supported.
2017-06-27 15:29:01 +02:00
Miroslav Lichvar
1ca099473f refclock: add option to filter wrong pulse edges
Add width option to the refclock directive to set expected width of
pulses in a PPS signal. The width adds a limit for the maximum offset
and root distance in order to reject PPS samples from wrong events, e.g.
PHCs which cannot be configured to timestamp only rising of falling
edges.
2017-05-26 13:33:53 +02:00
Miroslav Lichvar
f31f68ae8e refclock: add option to treat non-PPS refclocks as PPS
Add pps option to the refclock directive to force chronyd to treat any
refclock as a PPS refclock. This is intended for refclocks that may
provide time off by a whole number of seconds due to missing or wrong
TAI/GPS->UTC conversion.
2017-05-26 13:33:53 +02:00
Miroslav Lichvar
f3a16383b9 main: dump history by default
Always write the measurement history on exit when the dump directory is
specified and silently ignore the dumponexit directive. There doesn't
seem to be a good use case for dumpdir and -r without dumponexit as the
history would be invalidated by adjustments of the clock that happened
between the dump command and chronyd exit.
2017-03-10 16:51:03 +01:00
Miroslav Lichvar
f282856c72 logging: remove facility parameter
It was never used for anything and messages in debug output already
include filenames, which can be easily grepped if there is a need
to see log messages only from a particular file.
2017-03-10 16:51:03 +01:00
Miroslav Lichvar
0a0aff14d8 conf: add rawmeasurements log option
While the measurements log can be useful for debugging problems in NTP
configuration (e.g. authentication failures with symmetric keys), it
seems most users are interested only in valid measurements (e.g. for
producing graphs) and don't expect/handle entries where some of the RFC
5905 tests 1-7 failed. Modify the measurements log option to log only
valid measurements, and for debugging purposes add a new rawmeasurements
option.
2017-01-31 11:22:10 +01:00
Miroslav Lichvar
50f99ec5f4 conf: add nocrossts option to hwtimestamp directive
This option disables the use of the PTP_SYS_OFFSET_PRECISE ioctl.
2017-01-23 15:58:55 +01:00
Miroslav Lichvar
510784077f conf: add minpoll option to hwtimestamp directive 2017-01-23 15:58:55 +01:00
Miroslav Lichvar
1436d9961f conf: add precision option to hwtimestamp directive 2017-01-23 15:58:55 +01:00
Miroslav Lichvar
7a937c7652 conf: return hwtimestamp data in struct 2017-01-23 15:58:55 +01:00
Miroslav Lichvar
b4235abd36 update copyright years 2017-01-12 16:34:28 +01:00
Miroslav Lichvar
cacbe9976f ntp: add options for compensating HW timestamping errors 2017-01-06 13:12:19 +01:00
Miroslav Lichvar
ab99373cfc conf: change default rate limiting parameters
Change the default NTP rate limiting leak to 2 (25%). Change the default
command rate limiting interval to -4 (16 packets per second) and burst
to 8, so the interval is the only difference between NTP and command
rate limiting defaults.
2017-01-06 13:12:19 +01:00
Miroslav Lichvar
dbfb49384b clientlog: disable NTP response rate limiting by default
This reverts commit 50022e9286.

Testing showed that ntpd as an NTP client performs poorly when it's
getting only 25% of responses. At least for now, disable rate limiting
by default again.
2017-01-06 13:12:18 +01:00
Miroslav Lichvar
50022e9286 clientlog: enable NTP response rate limiting by default
Change the default interval of both NTP and command rate limiting to -10
(1024 packets per second) and the burst to 16. The default NTP leak is 2
(rate limiting is enabled by default) and the default command leak is 0
(rate limiting is disabled by default).
2016-12-15 13:47:41 +01:00
Miroslav Lichvar
9a901e1cb0 refclock: make maximum lock age configurable
The maxlockage option specifies in number of pulses how old can be
samples from the refclock specified by the lock option to be paired with
the pulses. Increasing this value is useful when the samples are
produced at a lower rate than the pulses.
2016-12-08 14:47:38 +01:00
Miroslav Lichvar
8bbb8fa062 sources: add configurable limit for jitter
The maxjitter directive sets the maximum allowed jitter of the sources
to not be rejected by the source selection algorithm. This prevents
synchronisation with sources that have a small root distance, but their
time is too variable. By default, the maximum jitter is 1 second.
2016-12-08 14:20:00 +01:00
Miroslav Lichvar
a049c9e0f8 conf: increase default minsamples and polltarget
Change default minsamples to 6 and polltarget to 8. This should improve
stability with extremely small jitters (e.g. HW timestamping) and not
decrease time accuracy at minimum polling interval too much.
2016-12-02 14:53:03 +01:00
Miroslav Lichvar
d84a706c08 conf: create socket directory before logdir and dumpdir
This allows sharing of the same directory for sockets, logs and dumps as
the socket directory needs to be created first (with mode 0770) in order
to pass the check of the permissions.
2016-11-15 14:55:25 +01:00
Miroslav Lichvar
14a1059e43 ntp: add support for HW timestamping on Linux
Add a new directive to specify interfaces which should be used for HW
timestamping. Extend the Linux ntp_io initialization to enable HW
timestamping, configure the RX filter using the SIOCSHWTSTAMP ioctl,
open their PHC devices, and track them as hwclock instances. When
messages with HW timestamps are received, use the PTP_SYS_OFFSET ioctl
to make PHC samples for hwclock.
2016-11-10 15:26:56 +01:00
Miroslav Lichvar
fb5d4f1da4 conf: disable dumpdir and logdir by default
Use empty string instead of "." (which is normally the root directory)
as the default value of dumpdir and logdir to indicate they are not
specified. Print warnings in syslog when trying to log or dump
measurements without dumpdir or logdir.
2016-09-07 11:16:01 +02:00
Miroslav Lichvar
98ba4ce4d5 configure: add options to set default pidfile and rtcdevice 2016-08-22 15:50:35 +02:00
Miroslav Lichvar
577aed4842 ntp: add support for MS-SNTP authentication in Samba
Add support for authenticating MS-SNTP responses in Samba (ntp_signd).
Supported is currently only the old MS-SNTP authenticator field. It's
disabled by default. It can be enabled with the --enable-ntp-signd
configure option and the ntpsigndsocket directive, which specifies the
location of the Samba ntp_signd socket.
2016-07-29 10:17:33 +02:00
Miroslav Lichvar
223ad0e8aa conf: fix parsing of refclock directive
Don't accept refclock directive which has as the last argument an option
that requires a value.
2016-06-28 13:23:27 +02:00
Miroslav Lichvar
f8bd9ab378 cmdparse: remove CPS_Status
Remove command and option specific error codes. Return zero on any
failure.
2016-06-27 14:52:55 +02:00
Miroslav Lichvar
8fe5e9cf1e reference: add orphan mode to local reference
Add orphan option to the local directive. It will enable an orphan mode
compatible with ntpd.
2016-03-31 16:08:49 +02:00
Miroslav Lichvar
81f440a882 reference: activate local reference with large root distance
Since the update to NTPv4, when the clock is in the synchronised state
and the clock updates stop (e.g. sources become unreachable), it doesn't
switch to the unsynchronised state and the local reference is never
activate. This can be a problem for clients that rely on the server to
always have root distance below some value (e.g. chronyd's maxdistance).

Add a timer that will activate the local reference when the root
distance reaches a specified threshold. It can be configured with the
distance option in the local directive (by default 1.0 second).
2016-03-31 16:08:45 +02:00
Miroslav Lichvar
981f897c96 conf: rework local directive to have default stratum
Allow the local directive to be specified without the stratum field.
It's an option now, with default value 10. Also, move the parsing code
to cmdparse.c to make it available to the client.
2016-03-31 16:01:06 +02:00
Miroslav Lichvar
a12c7c422b local: make maximum frequency offset configurable
Add maxdrift directive to set the maximum assumed drift of the clock,
which sets the maximum frequency offset chronyd is allowed to use to
to correct the drift.
2016-03-22 17:12:27 +01:00
Miroslav Lichvar
008615370a update copyright years 2016-02-02 12:02:16 +01:00
Miroslav Lichvar
8549043a3f conf: set logchange to 1 second by default
logchange is now always enabled, with 1 second threshold by default.
2016-01-29 17:55:58 +01:00
Miroslav Lichvar
e98f76e084 sources: add require option
Require that at least one of the sources specified with this option is
selectable (i.e. recently reachable and not a falseticker) before
updating the clock. Together with the trust option this may be useful to
allow a trusted, but not very precise, reference clock or a trusted
authenticated NTP source to be safely combined with unauthenticated NTP
sources in order to improve the accuracy of the clock. They can be
selected and used for synchronization only if they agree with the
trusted and required source.
2016-01-08 14:30:17 +01:00
Miroslav Lichvar
936f5cb0f1 sources: add trust option
Assume time from a source that is specified with the trust option is
always true.  It can't be rejected as falseticker in the source
selection if sources that are specified without this option don't agree
with it.
2016-01-07 16:20:27 +01:00
Miroslav Lichvar
fa15fb3d53 sources: turn select options into flags
This will allow adding new options for source selection which can be
combined with others.
2015-12-18 16:29:47 +01:00
Miroslav Lichvar
69642dd440 fix undefined shift operations on signed integers 2015-12-17 12:09:45 +01:00
Miroslav Lichvar
e5a593f013 conf: update default ratelimit configuration 2015-12-17 09:44:21 +01:00
Miroslav Lichvar
98947a4e52 conf: inline one-line parse_* functions 2015-12-03 11:43:06 +01:00
Miroslav Lichvar
b506594c2d clientlog: limit response rate
When the measured NTP or command request rate of a client exceeds
a threshold, reply only to a small fraction of the requests to reduce
the network traffic. Clients are allowed to send a burst of requests.
Try to detect broken clients which increase the request rate when not
getting replies and suppress the rate limiting for them.

Add ratelimit and cmdratelimit directives to configure the thresholds,
bursts and leak rates independently for NTP and command response rate
limiting. Both are disabled by default. Commands from localhost are
never limited.
2015-11-30 17:50:55 +01:00
Miroslav Lichvar
f2b82c1e1d conf: don't allow disabling clientloglimit
Don't treat zero as a special value disabling clientloglimit. It's not
useful, the amount of available memory is never unlimited.
2015-11-30 17:34:53 +01:00
Miroslav Lichvar
f660aa9d7a conf: don't allow invalid last refclock option 2015-11-18 12:49:05 +01:00
Miroslav Lichvar
32f8bec92d configure: make default hwclockfile configurable 2015-10-08 15:20:32 +02:00
Miroslav Lichvar
5039f959e0 sources: add option to limit selection by root distance
Add maxdistance directive to set the maximum root distance the sources
are allowed to have to be selected. This is useful to reject NTPv4
sources that are no longer synchronized and report large dispersion.
The default value is 3 seconds.
2015-08-25 17:35:34 +02:00
Miroslav Lichvar
c0867b58f5 conf: allow wildcard patterns in include directive
Use glob() to match and read multiple configuration files with one
include directive.
2015-08-24 15:25:02 +02:00
Miroslav Lichvar
05183748a8 conf: extend logging in CNF_ReadFile() 2015-08-24 14:57:39 +02:00
Miroslav Lichvar
282a9c7d7c keys: remove support for command key
Without the cmdmon authentication, there is no need for command keys.
2015-08-21 13:26:46 +02:00
Miroslav Lichvar
eb5a412bed configure: add option to set default location of Unix domain sockets 2015-08-21 13:26:46 +02:00
Miroslav Lichvar
f1ed08abf0 conf: create directory for Unix domain command socket
Try to create the directory where will be the Unix domain command socket
bound to allow starting with empty /var/run. Check the permissions and
owner/group in case the directory already existed. It MUST NOT be
accessible by others as permissions on Unix domain sockets are ignored
on some systems (e.g. Solaris).
2015-08-12 14:45:23 +02:00
Miroslav Lichvar
6d42dd8603 conf: create directories before dropping root
Create logdir and dumpdir before dropping root. Set their uid/gid to the
user chronyd will switch to. This allows chronyd to create the
directories in a directory where the user won't have write permissions
(e.g. /var/lib).
2015-08-12 14:45:20 +02:00
Miroslav Lichvar
0bcd10560a cmdmon: listen on Unix domain socket
In addition to the IPv4/IPv6 command sockets, create also a Unix domain
socket to process cmdmon requests. For now, there is no difference for
authorized commands, packets from all sockets need to be authenticated.

The default path of the socket is /var/run/chrony/chronyd.sock. It can
be configured with the bindcmdaddress directive with an address starting
with /.
2015-07-28 15:29:30 +02:00
Miroslav Lichvar
0abdc2a350 smooth: add option to smooth out only leap seconds
The leaponly option can be used to enable a mode where only leap seconds
are smoothed out and normal offset/frequency changes are ignored. This
is useful to make the interval in which a leap second is smoothed out
constant and allow an NTP client to use multiple leap smearing servers
safely.
2015-06-02 15:24:01 +02:00
Miroslav Lichvar
61272e7ce8 update copyright years 2015-04-10 11:06:32 +02:00
Miroslav Lichvar
7f45eb7957 ntp: add server time smoothing
Time smoothing determines an offset that needs to be applied to the
cooked time to make it smooth for external observers. Observed offset
and frequency change slowly and there are no discontinuities. This can
be used on an NTP server to make it easier for the clients to track the
time and keep their clocks close together even when large offset or
frequency corrections are applied to the server's clock (e.g. after
being offline for longer time).

Accumulated offset and frequency are smoothed out in three stages. In
the first stage, the frequency is changed at a constant rate (wander) up
to a maximum, in the second stage the frequency stays at the maximum for
as long as needed and in the third stage the frequency is brought back
to zero.

Time smoothing is configured by the smoothtime directive. It takes two
arguments, maximum frequency offset and maximum wander. It's disabled by
default.
2015-04-07 10:42:26 +02:00
Miroslav Lichvar
f8db832491 reference: add new leap second handling modes
In addition to the system driver handling add new modes to slew or step
the system clock for leap second, or ignore it completely. This can be
configured with leapsecmode directive.
2015-03-27 10:37:48 +01:00
Miroslav Lichvar
5194101c8b cmdmon: bind to loopback interface by default 2015-01-26 10:40:15 +01:00
Miroslav Lichvar
e57abae138 cmdparse: add function to convert error status to string
This is used to avoid duplication of error printing in chronyd and
chronyc.
2014-12-15 18:21:51 +01:00
Miroslav Lichvar
6688f40325 sources: allow setting minsamples and maxsamples for each source
The minsamples and maxsamples directives now set the default value,
which can be overriden for individual sources in the server/peer/pool
and refclock directives.
2014-12-03 16:27:51 +01:00
Miroslav Lichvar
308bcae257 ntp: limit number of pool sources
A new option can be now used in the pool directive: maxsources sets the
maximum number of sources that can be used from the pool, the default
value is 4.

On start, when the pool name is resolved, chronyd will add up to 16
sources, one for each resolved address. When the number of sources from
which at least one valid reply was received reaches maxsources, the
other sources will be removed.
2014-11-26 17:56:36 +01:00
Miroslav Lichvar
ed862c8d08 tempcomp: allow configuration with list of points
In addition to the quadratic function, allow configuration of the
compensation with a file containing list of (temperature, compensation)
points used for linear interpolation and extrapolation.
2014-11-21 13:11:16 +01:00
Miroslav Lichvar
df63790bb3 conf: change default stratumweight to 0.001 2014-11-03 15:13:52 +01:00
Miroslav Lichvar
c743ecbf50 ntp: support pools
The pool directive can be used to configure chronyd for a pool of NTP
servers (e.g. pool.ntp.org). The name is expected to resolve to multiple
addresses which change over time.

On start, a source will be added for each resolved address. When a
source from the pool is unreachable or marked as falseticker, chronyd
will try to replace the source with a newly resolved address of the
pool.

The minimum interval between replacements is currently set to 244
seconds to avoid frequent DNS requests.
2014-11-03 11:18:04 +01:00
Miroslav Lichvar
4d1a754ec6 nameserv: add support for returning multiple addresses 2014-10-23 16:48:13 +02:00
Miroslav Lichvar
1bb2732056 sources: add minsources option
This sets the minimum number of selectable sources needed to update the
local clock.
2014-10-20 18:04:37 +02:00
Miroslav Lichvar
1aecc51c70 ntp: add version option to server/peer directive 2014-10-20 16:14:17 +02:00
Miroslav Lichvar
c9571e55f5 conf: use array for broadcast destinations 2014-10-20 13:05:55 +02:00
Miroslav Lichvar
aba4596ba9 conf: use arrays for NTP and cmdmon restrictions 2014-10-20 12:54:16 +02:00
Miroslav Lichvar
a78bf0c34e ntp: merge broadcast code with ntp_core 2014-10-15 12:27:46 +02:00
Miroslav Lichvar
361726b3ae keys: store IDs in uint32_t 2014-09-26 14:14:54 +02:00
Miroslav Lichvar
75fd327222 conf: allocate sources dynamically
This removes the limits on maximum number of sources specified by the
initstepslew, server and refclock directives in the config file.
2014-09-25 10:58:57 +02:00
Miroslav Lichvar
f6ed7844e1 Free allocated memory on exit
This should reduce the number of possible memory leaks reported by
valgrind. The remaining reported leaks are sched tqe allocation, async
DNS instance allocation, cmdmon response/timestamp cell allocation, and
clientlog subnet allocation.
2014-09-25 10:57:55 +02:00
Miroslav Lichvar
d466390233 cmdparse: don't duplicate hostname in CPS_ParseNTPSourceAdd()
Let the caller duplicate the string if needed.
2014-09-24 12:43:11 +02:00
Miroslav Lichvar
336473398a Check for memory allocation errors 2014-09-23 15:47:02 +02:00
Miroslav Lichvar
d18c071849 ntp: use one socket with random port when acquisitionport is 0 2014-08-15 10:58:44 +02:00
Miroslav Lichvar
61b629fdad conf: return port numbers as int 2014-08-15 10:58:44 +02:00
Miroslav Lichvar
cb74f3e7ad Update copyright years 2014-06-05 18:06:56 +02:00
Miroslav Lichvar
b745b6d546 refclock: add maxdispersion option
This can be used to prevent accumulation of samples with estimated
dispersion above given limit. By default, this limit is disabled.
2014-05-23 16:15:28 +02:00
Miroslav Lichvar
e147f2f11e sys: drop frequency scaling in Linux driver
Since the kernel USER_HZ constant was introduced and the internal HZ
can't be reliably detected in user-space, the frequency scaling constant
used with older kernels is just a random guess.

Remove the scaling completely and let the closed loop compensate for the
error. To prevent thrashing between two states when the system's
frequency error is close to a multiple of USER_HZ, stick to the current
tick value if it's next to the new required tick. This is used only on
archs where USER_HZ is 100 as the frequency adjustment is limited to 500
ppm.

The linux_hz and linux_freq_scale directives are no longer supported,
but allowed by the config parser.
2014-05-23 16:15:28 +02:00
Miroslav Lichvar
9cf78b974a conf: add option to set maximum slew rate
With the generic driver, the maxslewrate directive sets the maximum
frequency offset that the driver is allowed to use to slew the time. By
default, it's set to 83333.333 (1/12). This is identical to what Linux
fast slewing used to use.
2014-05-22 13:28:46 +02:00
Miroslav Lichvar
3e1dc801b0 conf: change default corrtimeratio to 3.0
This improves the overall frequency accuracy of the clock at a slight
cost in the time accuracy.
2014-05-21 12:08:10 +02:00
Miroslav Lichvar
6ee357d230 ntp: use async name resolving for NTP sources
Use the new asynchronous call to resolve addresses of NTP servers
configured by the server/peer directives. Introduce a callback to be
notified when the first resolving attempt ends to correctly finish
chronyd initialization (dumpfile reload and reference mode end).
2014-04-29 12:43:03 +02:00
Miroslav Lichvar
ff31702f74 configure: add option to set default user
The default user is root by default, which disables root dropping by
default. The user directive or the -u option can still be used to set
the user.
2014-04-09 16:30:06 +02:00
Miroslav Lichvar
4f3fb95981 conf: allow NULL as filename 2014-04-09 12:56:11 +02:00
Miroslav Lichvar
7c7ab95e2e conf: split line parsing from CNF_ReadFile 2014-04-09 12:36:13 +02:00
Miroslav Lichvar
7fda9c6723 ntp: drop initstepslew NTP implementation
The initstepslew code has its own minimal NTP implementation. Drop the
code, add a new initstepslew mode to the reference updating code and
use regular NTP sources with iburst flag for initstepslew addresses
instead. When an update is made or a source is found unreachable, log a
message, remove the initstepslew sources and switch to normal mode.

This reduces code duplication and makes initstepslew use features
implemented only in the main code like source combining or SO_TIMESTAMP
support.
2014-04-09 09:54:40 +02:00
Miroslav Lichvar
05c5445fe2 conf: add bindacqaddress directive for client sockets 2014-04-03 15:47:32 +02:00
Miroslav Lichvar
e77b0070af Add option to read RTC LOCAL/UTC setting from hwclock's adjtime file 2013-12-11 11:22:04 +01:00
Miroslav Lichvar
be14dbffef Make naming of RTC config functions consistent 2013-12-10 17:54:05 +01:00
Miroslav Lichvar
0e8b27556d Merge config parsing functions for common data types 2013-11-28 17:33:20 +01:00
Miroslav Lichvar
162c6a49b5 Add option to trim RTC automatically 2013-11-27 17:35:00 +01:00
Miroslav Lichvar
0731cd6950 Fix log messages 2013-11-26 18:41:51 +01:00
Miroslav Lichvar
d5b737cce8 Update copyright years 2013-06-19 12:50:26 +02:00