The clock module will want to know the interface indexes, in order to
implement link monitoring. However, the clock does not open any sockets
directly. This helper function lets us keep the clock module free of
socket level code.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This patch adds a source module that implements RT netlink sockets
for the purpose of link monitoring. Unfortunately the netlink API
offers no possibility for per-port notification. Instead it
forces us to use a de-multiplexing pattern.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The time stamping setup code needlessly queries the configuration data
base over and over, rather than simply using the local variable
already assigned. This patch replaces the extraneous config_get_int()
calls with the local variable.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We activate on-step mode based on the "time_stamping" and
"twoStepFlag" configuration options. If twoStepFlag is false and HW
time stamping is enabled, we upgrade the time stamping mode variable
to one-step.
The code that tests the options and sets the one-step mode moved from
ptp4l.c into clock.c in commit 9b27664c ("clock: simplify the create
method."). However, that commit inadvertently moved the test after
the place where the time stamping mode is latched in a local variable.
As a result, one-step mode is not activated when configured.
This patch fixes the issue by keeping the local time stamping mode
variable up to date during the one-step test.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
If a non-slave port on a boundary clock see an announce message, then it
must decide whether it should take on the MASTER or the PASSIVE role. When
the GM fields from the local clock are identical to those in the announce,
then the sender/receiver ports are used as a tie breaker.
Following a typographical error in 1588, the code wrongly uses the port
identity of the upstream parent as the "receiver" id. As a result, a port
that should be PASSIVE may choose MASTER instead. This patch fixes the
code to use local port id.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Assume only the chronyd or ntpd process is essential for synchronization
of the system clock and ignore SIGCHLD from other processes. This should
provide resiliency against possible bugs in ptp4l or phc2sys that can
terminate the processes.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
This allows using a sequence of SHM segments that starts with a number
larger than zero, which can be useful to avoid conflicts with time
sources that are not started by timemaster, e.g. gpsd using segments
number 0 and 1.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Instead of trying to support all options of the server and refclock
directives in both NTP implementations, add an "ntp_options" option
which specifies a string that is added directly to the lines in the
chronyd/ntpd configuration file.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
In the last years there are several media streaming standards
evolving that are relying on PTP. These standards make requirements
about the DSCP priority of PTP messages. This patch introduces two
new configuration options 'dscp_event' and 'dscp_general' to address
that issue and to be able to set the DSCP priority separately for
PTP event messages and PTP general messages.
Signed-off-by: Henry Jesuiter <henry.jesuiter@alcnetworx.de>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Since size_t is an unsigned data type, it won't evaluate correctly on errors
of vasprintf(). This patch makes 'len2' a signed integer, as expected by
vasprintf().
'len2' is of type 'size_t' in util.c:451, but vasprintf in line
457 returns '-1' on error which is checked in line 460. Currently
this check will always fail (regardless of the return value of
vasprintf()), according to its declaration as unsigned int.
[ RC: Added more explanation taken from another list message. ]
Signed-off-by: Henry Jesuiter <henry.jesuiter@alcnetworx.de>
During the configuration rework, the announce span was wrongly converted
into a hard coded macro. In addition, the announceReceiptTimeout option
inadvertently became non-zero for the UDS port. As a result, the UDS port
sets a useless announce message timer, causing the code to close and reopen
the UDS port every few seconds.
This bug has an interesting history. It was first reported and fixed in
commit f36af8e0 ("uds: disable the accidentally enabled announce timer.").
That very fix was wrongly removed in commit 54f45063 ("port: change
'announce_span' into a macro."). Because of various code changes, this
bad commit cannot be simply reverted now.
This patch re-introduces the 'announce_span' variable and clears both it
and 'announceReceiptTimeout' for the UDS port, effectively disabling the
announce message timer.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The -p option for ptp4l, which specifies the PHC device, was added
before the ethtool get_ts_info ioctl had been invented. Today it does
not "force" the given device as the man page says. Instead this is a
legacy option only useful when running on older kernels.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The code that determines the index of the PHC device is useful to all
kinds of clock devices.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This function will allow the TC code to iterate over the ports without
calling into the clock logic.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The port code is not interested in the number of ports but rather the
clock type. Since the polymorphic clock object will be able to report
its own type, this patch changes the clock interface accordingly.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
There is no need for the 'ifaces' parameter since the list of network
interfaces is already present in the configuration.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
With the new configuration API, there is no need to pass the default data
set. Instead, the clock code can read the configuration directly. This
patch simplifies the clock create method by removing the 'dds' parameter
and moving the code that initialized the data set into the clock module.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
There is no need to have a function to get this information as
we can easily obtain it when the interface is first created.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The message lists are implemented using a TAILQ from queue(3). The heads
of the list must be initialized using the provided macros, since the field
called 'tqh_last' is non-zero in the initial state. This patch fixes a
potential null pointer dereference by properly initializing the queues.
Note that there is no actual bug in the current code, because it uses the
lists in such a way as to initialize 'tqh_last' before any dereference.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When the P2P link partner is using one shot mode, the residence time
in the peer (t3 - t2) is reflected in the correction field of the
peer delay response message, and t2 and t3 are both zero.
The function port_peer_delay() calls clock_peer_delay(), passing in
the zero valued 't2' to the 'rx' argument. The latter function then
stores the zero value in the 't4' field of the clock's tsproc
instance.
As a result, tsproc_update_offset() returns an error to
clock_synchronize(), and so a slave clock will never leave the
"uncalibrated" state.
This patch fixes the issue by removing the test for a non-zero 't4'
field within the tsproc.
Acked-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When remote timestamps from P2P delay measurement are not known (the
remote processing time is saved in the correction field), they are set
to zero. Fix tsproc to not require non-zero t1 and t4.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The difference between Coordinated Universal Time UTC and the International
Atomic Time TAI is :
from 2015 July 1, 0h UTC, until further notice : UTC-TAI = -36 s
https://hpiers.obspm.fr/iers/bul/bulc/bulletinc.dat
Signed-off-by: Libor Pechacek <lpechacek@suse.com>
Upgrade the message level to info so the user can see it, but print it
at most once per 5 minutes to not spam the syslog too much.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The new configuration code inadvertently causes the UDS port to use P2P
messaging when P2P is set as a global option. This results in a never
ending series of "missing timestamp" error messages from the UDS port as
it vainly tries to send peer delay requests.
This patch fixes the bug by changing the UDS delay mechanism back to zero
as it was before. This is the appropriate setting for the UDS port,
because it never leaves the listening state and thus never sends an E2E
delay request.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The draft Enterprise Profile [1] specifies a hybrid E2E delay mechanism,
where the delay response message is sent "in kind". That is, if the
request is unicast, then the response is also unicast. Apparently this
scheme is already in widespread use in some industries. Also, it makes
sense, because those messages are of no interest to the other slaves in
the PTP network.
Because of the address work already in place, in turns out that adding
this mode is almost trivial. This patch introduces an "hybrid_e2e" option
that enabled the new mode.
1. https://datatracker.ietf.org/doc/draft-ietf-tictoc-ptp-enterprise-profile
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The raw Ethernet transport code invented its own way of storing the MAC
address into our "struct address" data structure. However, this private
format is incompatible with the sockaddr_ll returned from the networking
stack. This patch converts the code to use the proper format.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Even if the caller provides the destination address, still the port must
depend on the passed 'event' value for correct delivery.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Even if the caller provides the destination address, still the port must
depend on the passed 'event' value for correct delivery.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Add wrappers for malloc(), calloc(), realloc() and strdup() that check
if the allocation failed, print an error message and call exit(1). This
allows the caller to use the returned value without checking for errors.
Buggy or mis-configured masters can place bogus logMessageInterval values
in their delay response messages. This patch places reasonable limits on
the range of values that we will accept.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The logMessageInterval field has an improbable range from 2^-128 to 2^127
seconds. The extreme ends cause an integer overflow in the calculation
of the "foreign master time window". Buggy or mis-configured foreign
masters advertising extreme values will cause incorrect announce message
aging.
This patch fixes the issue by adding thresholds for the bogus extremes.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Now that all of the legacy, open coded configuration fields are gone,
we can follow a normal create/destroy pattern for the configuration.
This patch add the new method and converts the programs to use it.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Now that all of the legacy parsing code is gone, there remain two
identical parsing functions. This patch removes them both and places
the common code at the original call site.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This patch rearranges the guts of the main parsing loop to keep it
more within the 80th column. The logic has not been changed.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>