]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add server support for network correction
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 26 Sep 2023 10:39:25 +0000 (12:39 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 26 Sep 2023 13:14:13 +0000 (15:14 +0200)
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.

ntp_core.c

index 7b0a39999832ae40878116550785ad74a9de3a3d..6cd7879c8fcf4e635b6027c5577b2351cd666586 100644 (file)
@@ -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 {