]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add extension field to provide network correction
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 26 Sep 2023 10:30:10 +0000 (12:30 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 26 Sep 2023 13:14:13 +0000 (15:14 +0200)
To be able to verify PTP corrections, the client will need to know both
the correction of the request received by the server and the correction
of the response. Add a new experimental NTP extension field that the
clients will use to request the correction and servers return the
value.

ntp.h
ntp_core.c

diff --git a/ntp.h b/ntp.h
index 1ef36834504aa40b206ea147c076ac4f81e16a3b..165adbc210eda1168083dcc9f820b67bc87a6cff 100644 (file)
--- a/ntp.h
+++ b/ntp.h
@@ -116,8 +116,10 @@ typedef struct {
 /* Non-authentication extension fields and corresponding internal flags */
 
 #define NTP_EF_EXP_MONO_ROOT            0xF323
+#define NTP_EF_EXP_NET_CORRECTION       0xF324
 
 #define NTP_EF_FLAG_EXP_MONO_ROOT       0x1
+#define NTP_EF_FLAG_EXP_NET_CORRECTION  0x2
 
 /* Pre-NTPv5 experimental extension field */
 typedef struct {
@@ -130,6 +132,15 @@ typedef struct {
 
 #define NTP_EF_EXP_MONO_ROOT_MAGIC      0xF5BEDD9AU
 
+/* Experimental extension field to provide PTP corrections */
+typedef struct {
+  uint32_t magic;
+  NTP_int64 correction;
+  uint32_t reserved[3];
+} NTP_EFExpNetCorrection;
+
+#define NTP_EF_EXP_NET_CORRECTION_MAGIC 0x07AC2CEBU
+
 /* Authentication extension fields */
 
 #define NTP_EF_NTS_UNIQUE_IDENTIFIER    0x0104
index fae5e7b19be77efe763b8b31fc12341e2ee7fba8..7b0a39999832ae40878116550785ad74a9de3a3d 100644 (file)
@@ -375,6 +375,7 @@ do_size_checks(void)
   assert(offsetof(NTP_Packet, transmit_ts)     == 40);
 
   assert(sizeof (NTP_EFExpMonoRoot) == 24);
+  assert(sizeof (NTP_EFExpNetCorrection) == 24);
 }
 
 /* ================================================== */
@@ -1595,6 +1596,11 @@ parse_packet(NTP_Packet *packet, int length, NTP_PacketInfo *info)
                       NTP_EF_EXP_MONO_ROOT_MAGIC))
           info->ext_field_flags |= NTP_EF_FLAG_EXP_MONO_ROOT;
         break;
+      case NTP_EF_EXP_NET_CORRECTION:
+        if (is_exp_ef(ef_body, ef_body_length, sizeof (NTP_EFExpNetCorrection),
+                      NTP_EF_EXP_NET_CORRECTION_MAGIC))
+          info->ext_field_flags |= NTP_EF_FLAG_EXP_NET_CORRECTION;
+        break;
       default:
         DEBUG_LOG("Unknown extension field type=%x", (unsigned int)ef_type);
     }