Commit Graph

1177 Commits (47982fb8c8c2c0861583ffc6b62ad0af6ee967d6)

Author SHA1 Message Date
Stephen Walker 159eb5ff11 util: Fix unknown time_t types with musl-libc builds
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>
2017-05-15 23:05:57 +02:00
Hangbin Liu 43b2f5d120 msg: use last_tlv if there is not enough room for another tlv
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>
2017-05-12 16:18:45 +02:00
Florian Fainelli 8b61aa2c3f udp: Avoid including netdb.h
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>
2017-05-07 23:22:50 +02:00
Richard Cochran 2d5d8a0395 tsproc: Allow clock synchronization immediately after jump.
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>
2017-04-08 21:17:01 +02:00
Richard Cochran a0cbeb7367 tsproc: Clarify the internal mode handling.
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>
2017-04-08 21:17:01 +02:00
Richard Cochran 74ab3b3728 tsproc: Track the validity of the filtered delay explicitly.
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>
2017-04-08 21:13:36 +02:00
Burkhard Ilsen d1bb9ecbd5 port: sequence of nrate and peer_delay calculation
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>
2017-04-08 21:04:50 +02:00
Burkhard Ilsen 7e1ccac8f8 servo: NULL pointer check for servo constructors
The servo constructors might return a NULL pointer.
The function servo_create() uses servo without checks.

Signed-off-by: Burkhard Ilsen <burkhardilsen@gmail.com>
2017-04-06 06:25:34 +02:00
Miroslav Lichvar ac92a71161 phc2sys: don't synchronize clock to itself.
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>
2017-03-29 13:10:52 +02:00
Miroslav Lichvar 8deb52a849 Fix leaks of sockets on errors.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2017-02-14 09:05:04 +01:00
Richard Cochran 73318c5b99 clock: Force a BMC election when a port link goes down.
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>
2017-02-05 18:31:27 +01:00
Richard Cochran 6b471d45ed port: Change port_dispatch() into a void function.
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>
2017-02-05 18:25:18 +01:00
Miroslav Lichvar 117ed5c2d0 timemaster: check support for SW time stamping.
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>
2017-02-05 16:44:48 +01:00
Miroslav Lichvar e54158195b timemaster: tag ptp4l and phc2sys messages.
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>
2017-02-05 16:44:48 +01:00
Miroslav Lichvar 0f6c6972c7 Add options to tag ptp4l and phc2sys log messages.
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>
2017-02-05 16:44:48 +01:00
Viliam Lejcik 33e62f9925 ptp4l: Make UTC offset configurable.
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>
2017-02-05 16:41:58 +01:00
Richard Cochran b738afb604 fsm: Make the transition out of INITIALIZING part of the FSM code.
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>
2017-01-08 21:34:54 +01:00
Richard Cochran 01ee947457 Disentangle initialization from fault clearing.
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>
2017-01-08 21:34:53 +01:00
Richard Cochran 1f66948d38 Make the fault handling code more readable.
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>
2017-01-08 21:34:53 +01:00
Richard Cochran 80a28a9dc3 Change a misleading fault handling function signature.
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>
2017-01-08 21:34:53 +01:00
Richard Cochran 10d4e7f8b0 port: Make the finite state machine into a function variable.
This allows adding new FSM flavors in the future.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2017-01-08 21:34:53 +01:00
Miroslav Lichvar 0309a880fb Update TAI-UTC offset
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>
2017-01-08 21:28:40 +01:00
Richard Cochran 4e966536c6 ptp4l: Document the "long" command line options in the man page.
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
2016-12-13 20:52:45 +01:00
Richard Cochran e658982624 config: Fix bitwise copy-and-pasto for command line items.
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.")
2016-12-13 19:57:07 +01:00
Richard Cochran 81d97657bf Add an acknowledgment in the readme for Exablaze.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-12-09 19:41:08 +01:00
Richard Cochran 356eb81d4d makefile: Make the 'clean' target conform to standard practice.
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>
2016-12-06 19:48:39 +01:00
Richard Cochran 4e8dbd8492 ptp4l: Accept any configuration option as a command line argument.
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>
2016-12-06 19:40:36 +01:00
Richard Cochran 891d56e429 Version 1.8
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-11-04 19:38:56 +01:00
Richard Cochran 3b82f227ce clock: Monitor the link status using a RT netlink socket.
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>
2016-10-19 21:48:07 +02:00
Richard Cochran 5e3156da15 port: Provide methods to set and get the link status.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran e995cf7f52 clock: Remember each port's interface index.
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>
2016-10-16 12:42:56 +02:00
Richard Cochran 6b99df29e0 clock: Fix coding style within a helper function.
No functional changes.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran c8b525755b clock: Remove stray semicolon.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-10-16 12:42:56 +02:00
Richard Cochran 44a469597a sk: Add a method to obtain a socket for utility purposes.
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>
2016-10-16 12:42:56 +02:00
Richard Cochran 0b3c045a42 rtnl: Introduce RT netlink sockets.
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>
2016-10-16 12:42:56 +02:00
Richard Cochran 1de59d6226 clock: Remove cruft from the creation method.
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>
2016-10-16 12:14:16 +02:00
Richard Cochran 86ed2432f0 Fix regression in one-step configuration.
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>
2016-10-16 11:55:14 +02:00
Richard Cochran 5e5c98b3da port: Fix input to the BMC for forming the spanning tree.
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>
2016-08-03 14:00:04 +02:00
Richard Cochran 159f4a265d Version 1.7
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-07-21 16:49:14 +02:00
Miroslav Lichvar 914ca86b37 timemaster: ignore failures of non-essential processes.
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>
2016-07-16 21:03:59 +02:00
Miroslav Lichvar 395544d117 timemaster: add option to specify first SHM segment.
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>
2016-07-16 21:03:59 +02:00
Miroslav Lichvar ac77099493 timemaster: allow arbitrary options in server/refclock directives.
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>
2016-07-16 21:03:59 +02:00
Jesuiter, Henry (ALC NetworX GmbH) 1e667ff7fb Introduce options to set DSCP values in PTP messages.
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>
2016-07-12 15:11:56 +02:00
Jesuiter, Henry (ALC NetworX GmbH) dc09312ce7 Fix data type for return value of vasprintf()
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>
2016-07-12 14:55:46 +02:00
Richard Cochran 3938cbc101 uds: Prevent unintentional announce message timeouts.
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>
2016-07-07 18:41:57 +02:00
Richard Cochran 0d61027fd3 Fix the man page regarding the '-p' option.
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>
2016-07-03 20:45:41 +02:00
Richard Cochran d825b1d549 Let the clock code figure the PHC index.
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>
2016-04-03 14:45:41 +02:00
Richard Cochran 9c8fe6a94e clock: specify type at creation time.
Store the type in the clock object explicitly.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 63e530e297 config: count the interfaces as they are added.
This information is useful to the various clock types.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00
Richard Cochran 8f7fb11fbc Perform the time stamping mode check in the clock module.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2016-04-03 14:45:41 +02:00