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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4654>
This commit is contained in:
Sebastian Dröge 2023-05-17 10:01:30 +03:00 committed by GStreamer Marge Bot
parent d55492add4
commit 639367f818

View file

@ -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) {