ptp-helper: Allow sync to master clock on same host
authorJochen Henneberg <jh@henneberg-systemdesign.com>
Wed, 21 Feb 2024 15:56:48 +0000 (16:56 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 22 Feb 2024 07:52:35 +0000 (07:52 +0000)
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6172>

subprojects/gstreamer/libs/gst/helpers/ptp/main.rs

index f2301984183ef3ae66bf5393e4c893bc39f81834..e550f5310682fbb35b014285bfd0ba2fd59a1fe3 100644 (file)
@@ -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, .. },
                     ..