From a97ca73704c3add23e52fafe0fa87aca7aaa254e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 10 Nov 2021 14:52:04 +0100 Subject: [PATCH] ntp: add pre-NTPv5 experimental extension field 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 | 17 +++++++++++++++++ ntp_core.c | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/ntp.h b/ntp.h index 5ea5ef6..52b2ab5 100644 --- 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 diff --git a/ntp_core.c b/ntp_core.c index 5455964..9eb6758 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -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); }