ntp: add server support for network correction
Provide the network correction (PTP correction + RX duration) of the request in the new extension field if included in the request and NTP-over-PTP is enabled.
This commit is contained in:
parent
d9ae724c60
commit
8eef631009
1 changed files with 34 additions and 0 deletions
34
ntp_core.c
34
ntp_core.c
|
@ -1084,6 +1084,36 @@ add_ef_mono_root(NTP_Packet *message, NTP_PacketInfo *info, struct timespec *rx,
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
static int
|
||||
add_ef_net_correction(NTP_Packet *message, NTP_PacketInfo *info,
|
||||
NTP_Local_Timestamp *local_rx)
|
||||
{
|
||||
NTP_EFExpNetCorrection ef;
|
||||
|
||||
if (CNF_GetPtpPort() == 0) {
|
||||
DEBUG_LOG("ptpport disabled");
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&ef, 0, sizeof (ef));
|
||||
ef.magic = htonl(NTP_EF_EXP_NET_CORRECTION_MAGIC);
|
||||
|
||||
if (info->mode != MODE_CLIENT && local_rx->net_correction > local_rx->rx_duration) {
|
||||
UTI_DoubleToNtp64(local_rx->net_correction, &ef.correction);
|
||||
}
|
||||
|
||||
if (!NEF_AddField(message, info, NTP_EF_EXP_NET_CORRECTION, &ef, sizeof (ef))) {
|
||||
DEBUG_LOG("Could not add EF");
|
||||
return 0;
|
||||
}
|
||||
|
||||
info->ext_field_flags |= NTP_EF_FLAG_EXP_NET_CORRECTION;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static int
|
||||
transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
||||
int interleaved, /* Flag enabling interleaved mode */
|
||||
|
@ -1234,6 +1264,10 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
|
|||
our_root_delay, our_root_dispersion))
|
||||
return 0;
|
||||
}
|
||||
if (ext_field_flags & NTP_EF_FLAG_EXP_NET_CORRECTION) {
|
||||
if (!add_ef_net_correction(&message, &info, local_rx))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
Loading…
Reference in a new issue