Fixes the following build errors seen with musl-libc:
In file included from print.h:25:0,
from linreg.c:24:
util.h:364:32: error: unknown type name 'time_t'
int rate_limited(int interval, time_t *last);
Signed-off-by: Stephen Walker <stephendwalker+github@gmail.com>
[florian: extract patch from OpenWrt, add commit message]
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
If the len is not enought for another tlv process. e.g. one more bytes
padding at the end of message. And we set extra to NULL instead of
msg->last_tlv in tlv_post_recv(). Then the msg->last_tlv will not be
initialised. And program will crash if we read msg->last_tlv. e.g. in
function pmc_show().
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
netdb.h pulls in a large chain of include files:
rpc/netdb.h
rpc/types.h
rpc/types.h re-defines TRUE/FALSE and does it in this way:
#ifndef FALSE
# define FALSE (0)
#endif
#ifndef TRUE
# define TRUE (1)
#endif
And this later causes build problems that appear in this way:
mipsel-linux-gnu-gcc -Wall -DVER=1.8 -D_GNU_SOURCE -DHAVE_CLOCK_ADJTIME
-DHAVE_POSIX_SPAWN -DHAVE_ONESTEP_SYNC -Os -pipe -mno-branch-likely
-mips32r2 -mtune=24kc -fno-caller-saves -Wno-unused-result
-D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro
-I/home/florian/dev/openwrt/trunk/staging_dir/target-mipsel-unknown-linux-gnu_glibc/usr/include
-I/home/florian/dev/openwrt/trunk/staging_dir/target-mipsel-unknown-linux-gnu_glibc/include
-I/home/florian/dev/toolchains/stbgcc-4.8-1.5/usr/include
-I/home/florian/dev/toolchains/stbgcc-4.8-1.5/include
-DHAVE_CLOCK_ADJTIME -DHAVE_POSIX_SPAWN -DHAVE_ONESTEP_SYNC -c -o
udp.o udp.c
In file included from
/home/florian/dev/openwrt/trunk/staging_dir/target-mipsel-unknown-linux-gnu_glibc/usr/include/rpc/netdb.h:45:0,
from
/home/florian/dev/toolchains/stbgcc-4.8-1.5/mipsel-linux-gnu/sys-root/usr/include/netdb.h:32,
from udp.c:23:
pdt.h:25:7: error: expected identifier before '(' token
enum {FALSE, TRUE};
^
<builtin>: recipe for target 'udp.o' failed
Upon inspection, it does not appear that netdb.h is providing any useful
definition or declaration, so let's just remove its inclusion.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
After a servo jump, the call to tsproc_reset() clears tsp->t3. This
causes the next call to tsproc_update_offset() to fail. However the
offset calculation does not necessarily depend on t3, i.e. when
filtered_delay is available and neither raw nor weighting is used.
This patch fixes the issue by allowing the stored filtered delay to be
used when appropriate.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Burkhard Ilsen <burkhardilsen@gmail.com>
The time stamp processor features four modes resulting from the
combination of two independent Boolean options. Even though we have a
proper enumerated type to represent the mode, still the code coverts
the mode into two variables.
The tests on the variables are currently simple enough, but soon we
will want to add some more complexity. In the interest of clarity,
this patch converts the paired Boolean tests into a switch/case
pattern.
No functional change.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We will want to test whether a valid filtered delay value has been
calculated or not. However, we cannot simply test for zero since that is
a legitimate possible delay value. This patch adds a flag that reflects
the state of the filtered delay field.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The sequence of port_nrate_calculate() and tsproc_update_delay()
in port_peer_delay() is mixed up.
The peer delay depends on the nrate ratio so the nrate ratio
shall be updated before peer delay is calculated.
Signed-off-by: Burkhard Ilsen <burkhardilsen@gmail.com>
The servo constructors might return a NULL pointer.
The function servo_create() uses servo without checks.
Signed-off-by: Burkhard Ilsen <burkhardilsen@gmail.com>
When ptp4l is using multiple interfaces sharing the same clock, phc2sys
in the automatic mode should not try to synchronize them to each other.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reported-by: Stefan Lange <s.lange@gateware.de>
Having one fewer port may affect the result of the BMCA. This patch
changes the main loop so that a link down event also causes a state
decision event.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Henry Jesuiter <Henry.Jesuiter@alcnetworx.de>
This global function used to return an error code, but now it always
returns zero. This patch converts the function signature to return void
and simplifies the main clock loop by removing the useless test.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When an interface doesn't support HW time stamping, before falling back
to SW time stamping, check if it's actually supported and exit with an
error message if not.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Use the new options of ptp4l and phc2sys to tag their log messages with
the PTP domain number and name(s) of interface(s) in the domain.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When running multiple instances of ptp4l or phc2sys, it's difficult to
tell which log message belongs to which instance. Add new options to
ptp4l and phc2sys which can specify a tag for all messages printed to
the standard output or system log, so messages from different instances
can have different tags.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Currently UTC offset is defined as a constant - CURRENT_UTC_OFFSET, and if
a leap second is added, that constant is no longer valid. Ptp4l was
updated to read the UTC offset from configuration instead.
Signed-off-by: Viliam Lejcik <viliam.lejcik@kistler.com>
The state machines in 1588 do not specify an event that causes a transition
out of the initializing state. This was left as a local issue. For this
transition, the current code assigns the next state outside of the FSM. But
doing so prevents an alternative FSM to handle this transition differently.
By introducing a new event, this patch places this transition where it
belongs, namely under the control of the FSM code,
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Although leaving the INITIALIZING state and clearing the FAULTY state
ASAP both result in a port entering the LISTENING state, still there
is no benefit from conflating the two. In the FAULTY case, the
current code actually skips the INITIALIZING state altogether.
This patch separates the two cases resulting in two benefits. First,
the check for ASAP fault status is only made when a fault is actually
present, unlike the present unconditional check. Second, this change
will allow us to cleanly support alternative state machines later on.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The code that decides whether a fault qualifies for ASAP treatment is
a tangle of logical operators. This patch replaces the open coded
logic with a helper function whose name makes the intent clear. This
is a cosmetic change only.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Looking at the fault logic in port_dispatch(), you might think that
the function, fault_interval(), checks whether a fault is active, but
you would be wrong, since that function always returns zero.
This patch removes the superfluous input error checking inside of
fault_interval() and changes the return type to void, making the
actual behavior explicit. Dropping the input check is safe because
that function has exactly two callers, both of whom always provide
valid inputs.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
A leap second was applied to UTC on 2016-12-31 and the offset between
TAI and UTC is now 37 seconds.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The recent change allowing every configuration option to appear on the
command line wrongly used bitwise AND to set a flag. This patch fixes
the bug by using the proper bitwise OR idiom.
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
Reported-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 4e8dbd8 ("ptp4l: Accept any configuration option as a command line argument.")
This patch makes the build system less surprising by removing the
executable binaries in the 'clean' target. This behavior is more in
line with the GNU makefile guidelines.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Suggested-by: Manuel Traut <manut@linutronix.de>
This patch provides a way to use the entire table of configuration options
as "long" command line switches.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Poll for link up/down events. When a link goes down, the port becomes
faulty until the link goes up again. We keep the fault timer from the
existing fault detection, but a downed link prevents clear the fault.
The new state machine is depicted in this ascii art diagram:
+--------+ Fault +---------+
| |------------>| |
| UP | | FAULT |
| |<------------| |
+--------+ Timeout +---------+
A | /
| | /
Link-Up | | Link-Down /
| | /
| V /
+--------+ / Link-Down
| | /
| DOWN |<--------/
| |
+--------+
If the fault timer occurs in the DOWN state, we simply ignore it.
After all, without the link the port is useless.
There is one case where the new code changes the existing behavior.
If the link quickly does down and then up again while another fault
(and its timer) are active, then we will enter the UP state without
waiting for the fault timer expiration. However, this behavior is
acceptable because when a link goes up, you are starting with a clean
slate.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
We use a hash table to remember the mapping. Since our existing hash
table is a simply string hash, we convert the integer index into a decimal
string. Although hashing integers in this way is sub-optimal, the table
will not be used in a performance critical path.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
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>