Commit Graph

29 Commits (master)

Author SHA1 Message Date
Vladimir Oltean 5cca24bc07 ptp4l: call recvmsg() with the MSG_DONTWAIT flag
The application's main event loop (clock_poll) is woken up by poll() and
dispatches the socket receive queue events to the corresponding ports as
needed.

So it is a bug if poll() wakes up the process for data availability on a
socket's receive queue, and then recvmsg(), called immediately
afterwards, goes to sleep trying to retrieve it. This patch will
generate an error that will be propagated to the user if this condition
happens.

Can it happen?

As of this patch, ptp4l uses the SO_SELECT_ERR_QUEUE socket option,
which means that poll() will wake the process up, with revents ==
(POLLIN | POLLERR), if data is available in the error queue. But
clock_poll() does not check POLLERR, just POLLIN, and draws the wrong
conclusion that there is data available in the receive queue (when it is
in fact available in the error queue).

When the above condition happens, recvmsg() will sleep typically for a
whole sync interval waiting for data on the event socket, and will be
woken up when the new real frame arrives. It will not dequeue follow-up
messages during this time (which are sent to the general message socket)
and when it does, it will already be late for them (their seqid will be
out of order). So it will drop them and everything that comes after. The
synchronization process will fail.

The above condition shouldn't typically happen, but exceptional kernel
events will trigger it. It helps to be strict in ptp4l in order for
those events to not blow up in even stranger symptoms unrelated to the
root cause of the problem.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
2020-06-24 10:09:13 -07:00
Richard Cochran d95fbcb566 raw: Convey transmit path errors to the caller.
The transport layer's functional interface foresees having error codes
percolate back up to the caller.  However, up until now, the raw module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.  In addition, it removes the gratuitous printing
of the error message, leaving that task up to caller, just like the other
transport modules.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-05-24 12:19:58 -07:00
Richard Cochran e752cac7b1 Convert call sites to the proper method for getting interface labels.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
2020-03-04 09:45:24 -08:00
Khor, Isaac Shi Yan c15e8c7600 ptp4l: Add configuration option for socket priority
Users may need to use different socket priorities for ptp4l traffic for
the purpose of traffic shaping. An example is to route ptp4l traffic
through a specific Linux egress queue using the mqprio qdisc.

 - Update raw.c open_socket() to accept a socket_priority parameter
 - Add the socket_priority option to config.c and the default.cfg config
   file. The option defaults to 0.

CC: "Ong, Boon Leong" <boon.leong.ong@intel.com>
CC: "Wong, Vincent Por Yin" <vincent.por.yin.wong@intel.com>
Signed-off-by: Khor, Isaac Shi Yan <isaac.shi.yan.khor@intel.com>
2019-08-06 21:07:21 -07:00
Richard Cochran e160bad721 transport: Introduce transmit time stamp deferral.
Up until now, the code has always fetched the time stamp immediately
after transmitting a message.  However, a transparent clock will want
to forward a given incoming message out all egress ports with as
little delay as possible, in order to minimize the residence time of
the message within the switch.

This patch adds a new transmit mode for event messages that will be
used to signal the new behavior.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-13 22:29:05 -07:00
Richard Cochran 4247eeb104 transport: Use the proper enumerated event code.
Originally the 'event' parameter to transport_send() was a single
Boolean flag.  Over time, we grew an enumerated list of event
flavors, but the function signatures were never updated.  This patch
changes the methods to use the proper type.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2018-04-13 22:27:03 -07:00
Richard Cochran b01e84af98 raw: Fix valgrind setsockopt warning.
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>
2018-03-06 06:31:46 -08:00
Hangbin Liu 8923bcdf64 transport: pass struct interface to transport_open
Pass struct interface so we can use ts_iface in HW filter.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2017-10-14 05:34:18 -07:00
Petr Kulhavy c7837b9a29 Remove conflicting netinet/ether.h
On some platforms like br-arm-cortex-a9-musl struct ethhdr was defined twice
due to including of both linux/if_ether.h and netinet/ether.h. Which lead
to a compilation error.

Remove netinet/ether.h as the official header for struct ethhdr is
linux/if_ether.h

Signed-off-by: Petr Kulhavy <brain@jikos.cz>
2017-05-15 23:18:19 +02:00
Richard Cochran d0eb73c87b Use the standardized low level socket address format.
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>
2015-08-29 11:32:41 +02:00
Richard Cochran 852c288ebe config: convert 'p2p_dst_mac', letting it be a per-port option.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:46 +02:00
Richard Cochran a31f2d0ddf config: convert 'ptp_dst_mac', letting it be a per-port option.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:46 +02:00
Jiri Benc e804e6f9a0 Common type holding an address
This modifies all transports to use a new common address type, struct
address. This address is stored in a ptp_message for all received messages.

For sending, the "default" address is used with the default sending
functions, transport_send and transport_peer. The default address depends on
the transport; it's supposed to be the multicast address assigned by the
transport specification.

Later, a new transport_sendto function will be implemented that sends to the
address contained in the passed ptp_message.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-25 14:28:14 +02:00
Jiri Benc 3d22154299 raw: separate src and dst addresses
In order to be able to convert to a generic address struct, separate source
and destination address into separate fields.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-17 06:49:37 +02:00
Jiri Benc 8c02ae53f2 raw: replace hard coded constants by MAC_LEN
Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-17 06:49:37 +02:00
Jiri Benc 8bbebdd381 raw: fix reading of uninitialized memory on recv
When less bytes than the header size is read, do not indicate to the caller
that the read was successful, as the caller would read uninitialized memory.
To achieve that, subtract the header size unconditionally (unless an error
was returned by sk_receive).

In addition, do not check for Ethernet type when full Ethernet header was
not read. This again may lead to reading of uninitialized memory.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2014-04-10 12:29:26 +02:00
Stephan Gatzka 110849d422 Make functions and structs dealing with string literals const correct.
This allows the compiler to check if someone writes into string
literals.

Signed-off-by: Stephan Gatzka <stephan.gatzka@gmail.com>
2014-02-07 19:41:47 +01:00
Richard Cochran 7b7e046e91 Add an optional extra check on sync and follow up message ordering.
Because of packet reordering that can occur in the network, in the
hardware, or in the networking stack, a follow up message can appear
to arrive in the application before the matching sync message. As this
is a normal occurrence, and the sequenceID message field ensures
proper matching, the ptp4l program accepts out of order packets.

This patch adds an additional check using the software time stamps
from the networking stack to verify that the sync message did arrive
first. This check is only useful if the sequence IDs generated by
the master might possibly be incorrect.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2013-08-29 11:22:25 +02:00
Geoff Salmon d6779889cc raw: implement getting physical and protocol addrs 2013-01-14 19:12:18 +01:00
Richard Cochran 24385005b8 Enumerate the event codes for the transport layer transmission methods.
We add a new event code that indicates a one step event message.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-11-30 11:34:29 +01:00
Richard Cochran 8dde0d31b6 Pass transport type to time stamping initialization function.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Acked-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Jiri Benc <jbenc@redhat.com>
2012-10-29 20:06:00 +01:00
Richard Cochran 08bee20be2 raw: accept VLAN tagged packets.
The power profile requires using VLAN priority tagged packets. The tags
may or may not reach the application. This commit adds code to handle the
tags in the case that they do appear.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-08-21 16:22:18 +02:00
Richard Cochran 1d1a6acdc1 raw: return the length of the PTP message on receive.
The upper layer code will be confused by the extra fourteen byte length
of the Ethernet header.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-08-10 07:40:21 +02:00
Richard Cochran 7460d2756a Add a configuration option to specify the L2 MAC addresses.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-07-27 22:41:00 +02:00
Richard Cochran 3983406818 raw: Implement the peer transmission option.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-04-05 17:48:59 +02:00
Richard Cochran beb3d5d821 Expand the transport layer interface with a peer transmission method.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-04-05 17:48:59 +02:00
Eliot Blennerhassett 433b6f635e raw: fix filter reject for non 1588 frames
Signed-off-by: Eliot Blennerhassett <eblennerhassett@audioscience.com>
2012-03-31 20:30:59 +02:00
Richard Cochran 0ca8143da5 Remove a useless variable from the file descriptor array data type.
It was a cute idea to have the raw Ethernet layer use just one socket,
but it ended up not working on some specific PTP time stamping hardware.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-03-21 13:55:56 +01:00
Richard Cochran 32d461d4ed Add a transport over raw Ethernet packets.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-03-18 09:31:21 +01:00