ptp4l is too silent when receiving, for whatever reason, out of order
messages. If the reordering is persistent (which is either a broken
network, or a broken kernel), the behavior looks like a complete
synchronization stall, since the application is designed to never
attempt to recover from such a condition.
At least save some people some debugging hours and print when the
application reaches this code path. Since it's a debugging tool, we
don't want to create false alarms when the occasional packet gets
reordered in a production system, but have this information readily
available when the program's log level is set to debug, instead of
having users fish for it with code instrumentation.
[ RC - corrected printf format for sequence id. ]
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
After a successful message exchange, the delay measurement values are
processed by the port code. This patch makes the values available to a
monitor by calling the appropriate method.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The monitoring module accepts Sync timing events. This patch hooks up the
port receive path to call into the monitor.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The port_forward_to() method clobbers the specific error code returned
by the transport layer with -1. This patch lets the code preserve the
specific error in question.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
IEEE 1588 v2.1 and ITU G.8275.1/2 call for an optional "synchronization
uncertain" flag passed in Announce messages along with the other flags
from the time properties data set. The value of the flag depends is a
logical OR function of the inputs from the remote master and the local
process. This patch adds background support for handling the flag.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The logic for the Automotive Profile added a message interval update
mechanism that triggers whenever the servo enters the "stable locked"
state. This SERVO_LOCKED_STABLE state is active when the
configuration option servo_offset_threshold is non-zero and
servo_offset_threshold criteria is satisfied.
However, in general, the state of the servo can and should be
independent of any profile specific optional behavior. In particular,
the "stable locked" state will be used in the future to trigger other
kinds useful logic. For example, an upcoming write phase mode feature
would like to take advantage of the SERVO_LOCKED_STABLE state to
trigger its activation.
This patch introduces a proper configuration option to enable
transmission of the message interval request that is specific to the
Automotive Profile.
Signed-off-by: Vincent Cheng <vincent.cheng.xh@renesas.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Don't require each port to have its own master table specified in the
config. Instead of ports claming configured tables, clone the table in
each port, so different ports don't interfere with each other.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
A single, external PTP Hardware Clock device may be wired to one or more
MAC devices, providing the MACs with an input clock. This patch adds
support for such a hardware architecture by letting the command line PHC
override the one discovered via the ethtool ioctl.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
In port_synchronize(), when the clock returned SERVO_UNLOCKED and
port_dispatch() triggered a switch of the PHC, the variable "s" would
point to a servo which was already freed and the following call of
servo_offset_threshold() would read invalid memory.
Don't save the servo before dispatching the port.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 3f5f5653d7 ("port: Add interval update mechanism.")
Add struct PortStats to keep per-port number of messages sent and received,
split by message type. Bump TX counters after messages are sent
successfully, and RX counters after a message is received. To keep things
simple, reserve one counter for each theoretically possible message type,
including the reserved ones.
Signed-off-by: Petr Machata <petrm@mellanox.com>
Add provision to disable delay requests. Designated masters who do not
need to calculate pdelay can use this option. This is required by
Automotive Profile to reduce network load.
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
This commit adds functionality to increase the sync and pdelay request
intervals once gptp synchronization has been achieved. This is useful
while running Automotive Profile where the network is usually static.
Here, we are assuming that the gPTP synchronization is achieved whenever
the last 'n' offsets calculated using the Sync messages are below a
certain threshold. Both, the number of offsets to consider and the offset
threshold are configurable.
In order to support the interval update, a new clock servo state
CLOCK_SERVO_STABLE has been added. The clock will transition to this
state whenever the above condition is satisfied. When this transition
occurs, the slave will send an "interval request" signaling message
asking the master to change the sync interval. It will also update the
pdelay request interval locally.
Four new config options have been added to provide this functionality:
- servo_offset_threshold: All the offset values being considered should
be below this value.
- servo_num_offset_values: number of previously received offset values
to consider.
- operLogSyncInterval: slave will ask the master to switch to this
interval for sending sync messages when the offset stabilizes.
- operLogPdelayReqInterval: the slave will set this interval for pdelay
request messages when the offset stabilizes.
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
This implements transmission and receipt of message interval requests.
Using this mechanism, a time-aware device can request change in sync,
link delay and announce intervals on the device connected on the other
end.
As part of the commit, we are also saving the initial values of Announce
and Sync Interval.
For more information look at sections 10.2.4.4, 10.3.9.5, 10.3.14, 10.4,
10.5.4 and 11.2.17 of 802.1AS standard
Please note that this commit does not implement logic related to
computeNeighborRateRatio and computeNeighborPropDelay flags mentioned in
Section 10.5.4.3.9 of 802.1AS Standard.
[ RC - memset the targetPortIdentity to all ones. ]
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
It will be used to store the current value of Pdelay Request Interval.
It will be represented as power of two in seconds.
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
In logic, when we want to switch phc, we should check if the new phc
index is valid instead of checking the previous one.
In reality, if we use linux team interface with activebackup mode. As
teamd is a userspace tool, it sets the new slave as active port after
receiving link change message. If we set current active port down and
another slave up. There is a race that we receive the new slave's link
up message while active port(ts_index) is still the old one. This means
we may use a link down interface as ts_index and get phc_index with -1.
If we update the p->phc_index to -1, there will be no possibility to
change it back to other value as we swith phc only when p->phc_index >= 0.
With this fix, we will not switch phc_index until receiving the real
active port(p->iface->ts_info.phc_index >= 0) update message.
Reported-by: Miroslav Lichvar <mlichvar@redhat.com>
Fixes: 536a71031d ("ptp4l: use ts label to get ts info")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
The manpage for recvmsg says -1 will be returned on error, Zero indicates an
"orderly shutdown", presumably only in case of stream sockets.
Further, UNIX Network Programming, Vol 1 says ".. a return value of 0 from
recvfrom is acceptable for a datagram protocol"
Such packets have been observed in the wild, aimed at PTP's multicast
address and port, possibly related to malformed management queries.
Patch to properly check return from recvmesg and not trigger the fault
codepath. Instead, such packets are treated as "Bad Message" the same as
non-zero but still too-short UDP payloads.
Signed-off-by: David Mirabito <davidjm@arista.com>
Adjust checks of logMessageInterval in received packet to prevent 1 of
type int being shifted by values >= 31.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When inhibit_announce is set, ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES event is
still sent once every state change. Avoid this by explicitly sending
EV_NONE instead.
[ RC - Simplify and keep all of the timer's state maintenance. ]
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The "inhibit_announce" and "ignore_source_id" options were introduced
in order to support the automotive profile. That profile happens to
specify using the peer to peer delay mechanism, but there is no reason
to restrict them to that mechanism. As it now stands, enabling these
two options prevents E2E slaves from synchronizing. This patch fixes
the issue by checking the "ignore_source_id" option when accepting E2E
delay response messages.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
This config option will skip the source port identity verification in
the Sync and Follow_up messages. This option is needed when the announce
messages are disabled because the slave cannot know the identity of
master without announce messages.
This is required by Automotive Profile as part of skipping the Best
Master Clock Algorithm (BMCA).
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
This option will accomplish 2 things. On the master, it will stop the
announce messages being sent (by disabling FD_MANNO_TIMER timer). On
slave, it will not configure announce message timeouts (by disabling
FD_ANNOUNCE_TIMEOUT timer).
This config option is needed for the Automotive profile as part of
skipping the Best Master Clock Algorithm (BMCA).
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
This adds config option to specify static roles for master and slave
in the Best Master Clock Algorithm. This is the case for Automotive
Profile where networks are mostly static and role for each device is
known in advance.
masterOnly and slaveOnly will be used to determine the roles for the
devices. Since masterOnly is a per-port config and slaveOnly is a global
config option, role assignment will be slightly odd in case of bridges.
If slaveOnly is set to 1, all the ports will be in slave roles except
for the ones where masterOnly is set to 1. These ports will assume the
master role.
Two new FSMs which will be used for master and slave roles for this
config option have also been added.
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
If set to 'true', this unconditionally sets the asCapable variable. The
usual checks will be applied to asCapable if it is set to 'auto'. The
default value is 'auto'.
This config option is needed by the Automotive Profile. The master will
be able to send out Sync Message as soon as the daemon is started.
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
If foreign clock is NULL, both the clocks are obviously not equal. So,
return 0 in that case.
The above condition (fc == NULL) is not currently encountered. It will
be encoutered in the next few patches which implement static roles for
master and slave.
Signed-off-by: Vedang Patel <vedang.patel@intel.com>
Add attribute maxStepsRemoved which is included in IEEE1588-2017 (v2.1)
It is an optional attribute which can decide if an Announce message is
considered in the operation of the BMCA or not.
Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
In port_management_fill_response() the TLV descriptor leaked when
not responding.
In port_open() the port would leak with the unsupported management clock
type.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When using peer to peer one step mode, the normal time stamp handling
of peer delay request messages is bypassed. The hardware subtracts
the ingress time stamp from the correction field and then adds the
egress time into the correction of the response. The configured
latency values are never applied since the hardware has no knowledge
of them. This patch adds in the correction values in this special
case.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
There are two aspects. First, on the receive path, we reply to
unicast peer delay requests in kind. That is, if the peer sends a
unicast delay request, then reply with unicast, too, since this is
obviously what the peer expects.
Second, if configured, we transmit peer delay requests to the
specified unicast peer address.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
All of the callers of transport_peer() use hard coded magic numbers.
This patch fixes them to use the corresponding enumerated values instead.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Consistenly use the pid_eq() and cid_eq() helper functions. Move the
functions into utils.h (making them inline functions) because they are
used in multiple source files.
Signed-off-by: Michael Walle <michael@walle.cc>