Commit Graph

28 Commits (703c3c7bc70ff2aa267c0f35289719b4f364d306)

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 b2bf55aebd udp6: 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 udp6 module
simply returned -1 for any error.  This patch lets the code return the
specific error instead.

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
Richard Cochran 34945679fe Convert call sites to the proper method for getting interface names.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2020-03-04 09:45:10 -08:00
Petr Machata a48666bee3 udp6: Make mc6_addr transport-local
mc6_addr holds the parsed multicast address to which messages should be sent.
But since each port can have a different scope, and the primary MC address
depends on the scope, it really can't be stored in a global variable. Move both
to struct udp6.

Additionally, document the fact that the primary multicast address is changed at
runtime.

Reported-by: Alex Veber <alexve@mellanox.com>
Signed-off-by: Petr Machata <petrm@mellanox.com>
2019-09-10 20:56:30 -07:00
Anders Selhammer 80b1d25dfd sk: Added address family as inargument in sk_set_priority
Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>
2018-11-01 20:17:50 -07:00
Rafaël Carré 5219b6417f udp*: multicast join work with specific addresses
Remove unused sockaddr size argument, and pass address using specific struct

Signed-off-by: Rafaël Carré <funman@videolan.org>
2018-06-25 07:24:17 -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
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
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
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
Richard Cochran 776f772c36 Merge the hybrid E2E work.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-09-05 21:40:48 +02:00
Miroslav Lichvar d8bfa0fa69 udp6: set hop limit with udp_ttl option.
Use the udp_ttl option to configure both IPv4 and IPv6 transports.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
2015-08-31 15:39:41 +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 1e35b91c6a udp6: set the destination port unconditionally.
Even if the caller provides the destination address, still the port must
depend on the passed 'event' value for correct delivery.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-29 11:32:29 +02:00
Richard Cochran 6fa42d3491 config: convert 'udp6_scope' to the new scheme.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2015-08-23 21:09:45 +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
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 d4db76d64c udp6: 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 d83cd7283c udp6: add an option to set the multicast scope.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-11-25 20:30:14 +01:00
Richard Cochran f92f09f563 udp6: set the scope id when sending to link local addresses.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-11-25 19:24:27 +01:00
Richard Cochran 8e7a6da80c udp6: remember the interface index.
In order to set the scope id, we will need to know the interface index
before sending, in some cases.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-11-25 18:01:12 +01:00
Richard Cochran 87313fd05d Initialize the socket address structure to zero.
It is safer and more correct to clear the addresses before use. The IPv6
fields flowinfo and scope_id in particular should not be set to random
values from the stack.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-11-25 17:45:37 +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 aea4cfcd50 Add transport over UDP IPv6.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
2012-04-20 16:30:01 +02:00