]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add pre-NTPv5 experimental extension field
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Nov 2021 13:52:04 +0000 (14:52 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 16 Nov 2021 09:23:15 +0000 (10:23 +0100)
Add an experimental extension field for some features that were proposed
for NTPv5. Higher-resolution root delay and dispersion (using 28-bit
fraction) are added. A monotonic receive timestamp will allow a
frequency transfer between the server and client. The client will be
able to separate the server's time corrections from frequency
corrections by tracking the offset between the real-time and monotonic
receive timestamps.

The field has a type of 0xF323 from the new experimental range proposed
by the NTP working group. Include a magic 32-bit value in the field to
avoid interoperability issues if a different implementation choses the
same type for its own experimental field. The value will be changed on
incompatible changes to avoid issues between two different chrony
versions.

ntp.h
ntp_core.c

diff --git a/ntp.h b/ntp.h
index 5ea5ef6540cef0a817ec98956d51a457166b76e3..52b2ab579562a12a586d5d1e5e9d481a7a0e79aa 100644 (file)
--- a/ntp.h
+++ b/ntp.h
@@ -113,6 +113,23 @@ typedef struct {
 #define NTP_REFID_LOCAL 0x7F7F0101UL /* 127.127.1.1 */
 #define NTP_REFID_SMOOTH 0x7F7F01FFUL /* 127.127.1.255 */
 
+/* Non-authentication extension fields and corresponding internal flags */
+
+#define NTP_EF_EXP1                     0xF323
+
+#define NTP_EF_FLAG_EXP1                0x1
+
+/* Pre-NTPv5 experimental extension field */
+typedef struct {
+  uint32_t magic;
+  NTP_int32 root_delay;
+  NTP_int32 root_dispersion;
+  NTP_int64 mono_receive_ts;
+  uint32_t mono_epoch;
+} NTP_ExtFieldExp1;
+
+#define NTP_EF_EXP1_MAGIC 0xF5BEDD9AU
+
 /* Authentication extension fields */
 
 #define NTP_EF_NTS_UNIQUE_IDENTIFIER    0x0104
index 545596472665739da98382eedc9836af9eda7021..9eb67587c3fdf938fe9f6d7bf344c5e1c93a1943 100644 (file)
@@ -1406,6 +1406,11 @@ parse_packet(NTP_Packet *packet, int length, NTP_PacketInfo *info)
       case NTP_EF_NTS_AUTH_AND_EEF:
         info->auth.mode = NTP_AUTH_NTS;
         break;
+      case NTP_EF_EXP1:
+        if (ef_body_length == sizeof (NTP_ExtFieldExp1) &&
+            ntohl(((NTP_ExtFieldExp1 *)ef_body)->magic) == NTP_EF_EXP1_MAGIC)
+          info->ext_field_flags |= NTP_EF_FLAG_EXP1;
+        break;
       default:
         DEBUG_LOG("Unknown extension field type=%x", (unsigned int)ef_type);
     }