From c6636533d4bd1ab6c5e0c415194d1bbbb13dad33 Mon Sep 17 00:00:00 2001 From: Jochen Henneberg Date: Wed, 21 Feb 2024 16:56:48 +0100 Subject: [PATCH] ptp-helper: Allow sync to master clock on same host If we drop all messages with the same clock id as ours we will also drop all messages coming from a PTP clock on our host since both clock ids are build from the same MAC address. At least for Linux we do not see our own messages anyway since the network stack can well distinguish between multicast send from our socket or from another socket on the same machine. To make sure that this works for all supported platforms just drop delay requests since this is the only message that is sent from the GStreamer PTP clock. Part-of: --- .../gstreamer/libs/gst/helpers/ptp/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/subprojects/gstreamer/libs/gst/helpers/ptp/main.rs b/subprojects/gstreamer/libs/gst/helpers/ptp/main.rs index f230198418..e550f53106 100644 --- a/subprojects/gstreamer/libs/gst/helpers/ptp/main.rs +++ b/subprojects/gstreamer/libs/gst/helpers/ptp/main.rs @@ -37,7 +37,7 @@ mod rand; mod thread; use error::{Context, Error}; -use parse::{PtpClockIdentity, PtpMessagePayload, ReadBytesBEExt, WriteBytesBEExt}; +use parse::{PtpClockIdentity, PtpMessagePayload, PtpMessageType, ReadBytesBEExt, WriteBytesBEExt}; use rand::rand; /// PTP Multicast group. @@ -240,12 +240,19 @@ fn run() -> Result<(), Error> { trace!("Received PTP message {:#?}", ptp_message); } - if ptp_message.source_port_identity.clock_identity == u64::from_be_bytes(clock_id) { - if args.verbose { - trace!("Ignoring our own PTP message"); + // The delay request is the only message that is sent + // from PTP clock implementation, if others are added + // additional match arms should be added. + match ptp_message.message_type { + PtpMessageType::DELAY_REQ => { + if args.verbose { + trace!("Ignoring our own PTP message"); + } + continue 'next_packet; } - continue 'next_packet; + _ => (), } + if let PtpMessagePayload::DelayResp { requesting_port_identity: PtpClockIdentity { clock_identity, .. }, ..