Time values are compared using an inequality test in mmedian.c
Generalise tmv_eq() to tmv_cmp() (by analogy with memcmp()) and
replace existing uses of tmv_eq().
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
Use tmv_dbl() to obtain the floating point value passed to
stats_add_value() rather than relying on the existing implicit cast
from the result of tmv_to_nanoseconds().
Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
We are programming C, not Java, and so opening braces of a function
belong on a line all by themselves.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The code uses a local variable for program flow control in a silly way.
This patch simplifies the logic by using the common switch/case/default
pattern instead.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The code uses a local variable for program flow control in a silly way.
This patch simplifies the logic by using the common switch/case/default
pattern instead.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Valgrind is nagging us, saying we pass uninitialized data through a
setsockopt() call. This patch fixes the issue by clearing the entire
passed structure.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Any code that wants to call one_step() needs to link with the static
global 'assume_two_step'. This patch moves that variable's definition
from ptp4l.c to msg.c. Not only is that file the more natural choice
(since the variable is used on msg.h) but also this allows other
programs to call the one_step() function.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Up until now the transportSpecific field has been treated according to
802.1AS, namely as a field that must match exactly on receive.
However, 1588 mandates ignoring this field for some transports, and
there is equipment in the wild that does in fact set the reserved
bits.
This patch adds an option to ignore the field on receive completely.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reported-by: Petr Kulhavy <brain@jikos.cz>
This option allows the clock to be updated before the path delay is
measured in order to speed up the initial correction of the clock, e.g.
in domains using a very long logMinDelayReqInterval.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When the minimum delay request interval is changed after processing a
delay response, update the current timeout to immediately follow the new
interval.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When a network interface doesn't support the most specific PTP filter
(e.g. it can timestamp either all or no received packets), it is
expected that the driver will report a different filter than was
requested. Turn the warnings into debug messages to avoid confusing
the users.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
The UDS port is not expected to be used by PTP clocks and forwarding of
management messages to the port can be limited to responses.
This prevents ptp4l from printing error messages when a management
request is received from a non-UDS port and the last client which used
the UDS port is no longer listening.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Because our interfaces include UNIX domain sockets, we are using
UNIX_PATH_MAX of 108 bytes for our interface names. Even though
IF_NAMESIZE is much smaller (16 bytes), there is nothing that
guarantees this. This patch adds a compile time sanity check that
tests whether the interface name will fit.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When parsing the argument, the minimum value should be -DBL_MAX instead
of DBL_MIN, which is the smallest positive value.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
When the clock device or phc index changed, the new phc device may have
different maximum adjustment. So we need to create a new clkid and servo
in clock_reinit().
At the same time, we should not only do clock_reinit() when the new state
is PS_MASTER. We also need to reinit clock after a failover in slave mode(
the new state is PS_SLAVE). We can do clock_reinit() even in PS_FAULTY so
we can finish adjust offset before come back to PS_LISTENING. So I removed
the check and let's do clock_reinit() whenever there is a new state.
And for servo reset, as Miroslav suggested, we will do it in these cases:
- the system clock is the new destination (master state)
- a PHC is the new destination (master state)
- a PHC is switched (in any state)
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Now the ts label will be either the bond active slave or the interface
name, which is the exactly interface we need to get ts info.
When the link down/up or there is a fail over and ts_label changed, the
phc index may also changed. So we need to check get new ts info and check
clock_required_modes. We will set the link to LINK_DOWN by force if
the new ts_label's timestamp do not support required mode.
If all good, then we set phc index to new one. Also sync clock interval
after switch phc.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Separate required_modes setting from clock_create so we can obtain the
required time stamping flags from other place.
Add enum timestamping in struct clock to store the time stamping mode.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Besides link up and down, we may also receive other rtnl messages, like
bond slave changed info, which link state keeps the same.
So we should return EV_FAULT_CLEARED only when both LINK_UP and
LINK_STATE_CHANGED.
When the link state keep the same, we should return EV_NONE.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Update function rtnl_link_status to get bond slave info. Pass the slave index
to call back functions. i.e. port_link_status.
Also check the interface index of rtnl message in function rtnl_link_status.
Then we don't need to check it in port_link_status.
Add ifndef IFLA_BOND_MAX in case we build linuxptp on kernel before v3.13-rc1.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
The previous function use general message and will dump all interfaces'
information. Now update with ifinfomsg so we could get specific interface's
information.
We still could get all interfaces' info if set device to NULL.
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
When the master clock changed its state and then changed it back to the
original state before phc2sys could process the first change, e.g. SLAVE
-> UNCALIBRATED -> SLAVE after a clockcheck failure, the second change
was ignored because the new value was the same as the original state,
which wasn't updated for the first change yet. This caused phc2sys to be
stuck with a wrong state.
Fix phc2sys to check both the state and new_state variables of the clock.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Now that we test the UTC flags in clock_update_slave(), the similar
code in clock_utc_correct() is redundant.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
When acting as a slave, we accept the foreign master's advertised
TAI-UTC offset for as long as that master is present. However, when
the master disappears, we fall back to the initial offset value. As a
result of this behavior, when starting with an out of date initial
offset, losing a foreign master causes a sudden UTC offset error (in
phc2sys for example) in the range of whole seconds.
This patch fixes the issue by remembering the UTC offset when assuming
the slave role.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The clock code uses two different variables to store the TAI-UTC
offset. One variable represents the compile time, configuration file,
or command line initial UTC offset, while the other is used when
taking on the GM role and is settable at run time. However, making
this distinction makes no sense. This patch simplifies and clarifies
the code by using a single variable for the offset.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
The current implementation of ptp4l always assumes 6 octets MAC
address, which is correct for Ethernet interfaces but not for IPoIB
interfaces (that have 20 octets MAC), therefore running ptp4l over
IPoIB interface does not function correctly.
In Infiniband, every interface has three identifiers:
GUID, GID, and LID.
The GUID is similar in concept to a MAC address. From RFC4392:
The EUI-64 portion of a GID is referred to as the Global Unique
Identifier (GUID) and is the only persistent identifier of a port.
Therefore, to support IPoIB interfaces, the GUID of the port should
be used instead of the MAC.
This patch checks the interface type before creating the clock identity,
for Infiniband ports, it retrieves the GUID of the port using sysfs
and use it to create the clock identity.
sysfs method was chosen since the GUID is the 6 lsb bytes of
the 20 byte device address, and SIOCGIFHWADDR ioctl call returns
the 14 msb bytes of the device address, so it is not possible to
get the GUID using SIOCGIFHWADDR ioctl call.
[ RC: fixed trivial coding style error, space after switch keyword. ]
Signed-off-by: Feras Daoud <ferasda@mellanox.com>
Reviewed-by: Alex Vesker <valex@mellanox.com>
With rtnl socket we can track link status per port(except UDS port).
We can make sure we get the correct interface and latest status with function
port_link_status().
At the same time we need to set clock sde after link down. But we return
EV_FAULT_DETECTED in port_event(), which will not set clock sde. So we need
to set it in port_link_status().
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>