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/4683>
This commit is contained in:
Sebastian Dröge 2023-05-17 10:01:30 +03:00 committed by Tim-Philipp Müller
parent 9994bbbd4c
commit 324f4792ae

View file

@ -346,6 +346,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)
@ -909,7 +914,17 @@ handle_announce_message (PtpMessage * msg, GstClockTime receive_time)
return;
}
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;
@ -1511,7 +1526,17 @@ handle_sync_message (PtpMessage * msg, GstClockTime receive_time)
return;
#endif
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) {
@ -1708,8 +1733,18 @@ handle_delay_resp_message (PtpMessage * msg, GstClockTime receive_time)
requesting_port_identity.port_number != ptp_clock_id.port_number)
return;
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) {