From 639367f818019a378bcd04a70b9e7fe293ae249a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 17 May 2023 10:01:30 +0300 Subject: [PATCH] ptp: Work around bug in ptpd in default configuration ptpd is defaulting to the hybrid mode, and was sending invalid multicast PTP messages in that configuration until ce96c742a88792a8d92deebaf03927e1b367f4a9. While this commit was made in 2015 there was no release in the meantime. Work around this by detecting this case and defaulting to the default values for the given intervals as given by the PTP standard. Part-of: --- .../gstreamer/libs/gst/net/gstptpclock.c | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/subprojects/gstreamer/libs/gst/net/gstptpclock.c b/subprojects/gstreamer/libs/gst/net/gstptpclock.c index 00a01fa465..ad632d11f8 100644 --- a/subprojects/gstreamer/libs/gst/net/gstptpclock.c +++ b/subprojects/gstreamer/libs/gst/net/gstptpclock.c @@ -382,6 +382,11 @@ static GHookList domain_stats_hooks; static gint domain_stats_n_hooks; static gboolean domain_stats_hooks_initted = FALSE; +/* Only ever accessed from the PTP thread */ +/* PTPD in hybrid mode (default) sends multicast PTP messages with an invalid + * logMessageInterval. We work around this here and warn once */ +static gboolean ptpd_hybrid_workaround_warned_once = FALSE; + /* Converts log2 seconds to GstClockTime */ static GstClockTime log2_to_clock_time (gint l) @@ -945,7 +950,17 @@ handle_announce_message (PtpMessage * msg, GstClockTime receive_time) return; } - sender->announce_interval = log2_to_clock_time (msg->log_message_interval); + if (msg->log_message_interval == 0x7f) { + sender->announce_interval = 2 * GST_SECOND; + + if (!ptpd_hybrid_workaround_warned_once) { + GST_WARNING ("Working around ptpd bug: ptpd sends multicast PTP packets " + "with invalid logMessageInterval"); + ptpd_hybrid_workaround_warned_once = TRUE; + } + } else { + sender->announce_interval = log2_to_clock_time (msg->log_message_interval); + } announce = g_new0 (PtpAnnounceMessage, 1); announce->receive_time = receive_time; @@ -1519,7 +1534,17 @@ handle_sync_message (PtpMessage * msg, GstClockTime receive_time) return; #endif - domain->sync_interval = log2_to_clock_time (msg->log_message_interval); + if (msg->log_message_interval == 0x7f) { + domain->sync_interval = GST_SECOND; + + if (!ptpd_hybrid_workaround_warned_once) { + GST_WARNING ("Working around ptpd bug: ptpd sends multicast PTP packets " + "with invalid logMessageInterval"); + ptpd_hybrid_workaround_warned_once = TRUE; + } + } else { + domain->sync_interval = log2_to_clock_time (msg->log_message_interval); + } /* Check if duplicated */ for (l = domain->pending_syncs.head; l; l = l->next) { @@ -1716,8 +1741,18 @@ handle_delay_resp_message (PtpMessage * msg, GstClockTime receive_time) requesting_port_identity.port_number != ptp_clock_id.port_number) return; - domain->min_delay_req_interval = - log2_to_clock_time (msg->log_message_interval); + if (msg->log_message_interval == 0x7f) { + domain->min_delay_req_interval = GST_SECOND; + + if (!ptpd_hybrid_workaround_warned_once) { + GST_WARNING ("Working around ptpd bug: ptpd sends multicast PTP packets " + "with invalid logMessageInterval"); + ptpd_hybrid_workaround_warned_once = TRUE; + } + } else { + domain->min_delay_req_interval = + log2_to_clock_time (msg->log_message_interval); + } /* Check if we know about this one */ for (l = domain->pending_syncs.head; l; l = l->next) {