]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: rename exp1 extension field
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 12 Sep 2023 10:19:03 +0000 (12:19 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 26 Sep 2023 13:01:24 +0000 (15:01 +0200)
Rename the exp1 extension field to exp_mono_root (monotonic timestamp +
root delay/dispersion) to better distinguish it from future experimental
extension fields.

candm.h
client.c
cmdmon.c
cmdparse.c
ntp.h
ntp_core.c
test/simulation/144-monoroot [moved from test/simulation/144-exp1 with 96% similarity]

diff --git a/candm.h b/candm.h
index b5b1b7f5c749e0eb1502033010d76bfee96e1c23..909252f15eb14015d24f325e34d62a7ac52b134f 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -277,7 +277,7 @@ typedef struct {
 #define REQ_ADDSRC_BURST 0x100
 #define REQ_ADDSRC_NTS 0x200
 #define REQ_ADDSRC_COPY 0x400
-#define REQ_ADDSRC_EF_EXP1 0x800
+#define REQ_ADDSRC_EF_EXP_MONO_ROOT 0x800
 
 typedef struct {
   uint32_t type;
index 5c056bc2f6c562ad34960e75d43e81658000c544..ee606ab6e15c020592ff4c645d548f7699b7f4b7 100644 (file)
--- a/client.c
+++ b/client.c
@@ -958,7 +958,7 @@ process_cmd_add_source(CMD_Request *msg, char *line)
           (data.params.burst ? REQ_ADDSRC_BURST : 0) |
           (data.params.nts ? REQ_ADDSRC_NTS : 0) |
           (data.params.copy ? REQ_ADDSRC_COPY : 0) |
-          (data.params.ext_fields & NTP_EF_FLAG_EXP1 ? REQ_ADDSRC_EF_EXP1 : 0) |
+          (data.params.ext_fields & NTP_EF_FLAG_EXP_MONO_ROOT ? REQ_ADDSRC_EF_EXP_MONO_ROOT : 0) |
           convert_addsrc_sel_options(data.params.sel_options));
       msg->data.ntp_source.filter_length = htonl(data.params.filter_length);
       msg->data.ntp_source.cert_set = htonl(data.params.cert_set);
index c2c5bf05c87142369d07abb9876adfe681fbd110..988bb427c006337f7257db54fa0bc22e8aadad29 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -783,8 +783,8 @@ handle_add_source(CMD_Request *rx_message, CMD_Reply *tx_message)
   params.burst = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_BURST ? 1 : 0;
   params.nts = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_NTS ? 1 : 0;
   params.copy = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_COPY ? 1 : 0;
-  params.ext_fields =
-    ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_EF_EXP1 ? NTP_EF_FLAG_EXP1 : 0;
+  params.ext_fields = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_EF_EXP_MONO_ROOT ?
+                      NTP_EF_FLAG_EXP_MONO_ROOT : 0;
   params.sel_options = convert_addsrc_select_options(ntohl(rx_message->data.ntp_source.flags));
 
   status = NSR_AddSourceByName(name, port, pool, type, &params, NULL);
index c20e8a34c0b4b5c0505b477800a2cd5d37a7585c..57fea1ca92267a46976bd4c300bd29a6f018ff43 100644 (file)
@@ -115,8 +115,8 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
       if (sscanf(line, "%"SCNx32"%n", &ef_type, &n) != 1)
         return 0;
       switch (ef_type) {
-        case NTP_EF_EXP1:
-          src->params.ext_fields |= NTP_EF_FLAG_EXP1;
+        case NTP_EF_EXP_MONO_ROOT:
+          src->params.ext_fields |= NTP_EF_FLAG_EXP_MONO_ROOT;
           break;
         default:
           return 0;
diff --git a/ntp.h b/ntp.h
index 906adc387e9ace83bdbf3ac9ab9a962c76470208..1ef36834504aa40b206ea147c076ac4f81e16a3b 100644 (file)
--- a/ntp.h
+++ b/ntp.h
@@ -115,9 +115,9 @@ typedef struct {
 
 /* Non-authentication extension fields and corresponding internal flags */
 
-#define NTP_EF_EXP1                     0xF323
+#define NTP_EF_EXP_MONO_ROOT            0xF323
 
-#define NTP_EF_FLAG_EXP1                0x1
+#define NTP_EF_FLAG_EXP_MONO_ROOT       0x1
 
 /* Pre-NTPv5 experimental extension field */
 typedef struct {
@@ -126,9 +126,9 @@ typedef struct {
   NTP_int32 root_dispersion;
   NTP_int64 mono_receive_ts;
   uint32_t mono_epoch;
-} NTP_ExtFieldExp1;
+} NTP_EFExpMonoRoot;
 
-#define NTP_EF_EXP1_MAGIC 0xF5BEDD9AU
+#define NTP_EF_EXP_MONO_ROOT_MAGIC      0xF5BEDD9AU
 
 /* Authentication extension fields */
 
index 22cab439bf55ad66f73b48dc5b372151843542b0..847932b3424e91737c86b0914e82a9279f64ab4c 100644 (file)
@@ -1045,34 +1045,34 @@ receive_timeout(void *arg)
 /* ================================================== */
 
 static int
-add_ext_exp1(NTP_Packet *message, NTP_PacketInfo *info, struct timespec *rx,
-             double root_delay, double root_dispersion)
+add_ef_mono_root(NTP_Packet *message, NTP_PacketInfo *info, struct timespec *rx,
+                 double root_delay, double root_dispersion)
 {
   struct timespec mono_rx;
-  NTP_ExtFieldExp1 exp1;
+  NTP_EFExpMonoRoot ef;
   NTP_int64 ts_fuzz;
 
-  memset(&exp1, 0, sizeof (exp1));
-  exp1.magic = htonl(NTP_EF_EXP1_MAGIC);
+  memset(&ef, 0, sizeof (ef));
+  ef.magic = htonl(NTP_EF_EXP_MONO_ROOT_MAGIC);
 
   if (info->mode != MODE_CLIENT) {
-    exp1.root_delay = UTI_DoubleToNtp32f28(root_delay);
-    exp1.root_dispersion = UTI_DoubleToNtp32f28(root_dispersion);
+    ef.root_delay = UTI_DoubleToNtp32f28(root_delay);
+    ef.root_dispersion = UTI_DoubleToNtp32f28(root_dispersion);
     if (rx)
       UTI_AddDoubleToTimespec(rx, server_mono_offset, &mono_rx);
     else
       UTI_ZeroTimespec(&mono_rx);
     UTI_GetNtp64Fuzz(&ts_fuzz, message->precision);
-    UTI_TimespecToNtp64(&mono_rx, &exp1.mono_receive_ts, &ts_fuzz);
-    exp1.mono_epoch = htonl(server_mono_epoch);
+    UTI_TimespecToNtp64(&mono_rx, &ef.mono_receive_ts, &ts_fuzz);
+    ef.mono_epoch = htonl(server_mono_epoch);
   }
 
-  if (!NEF_AddField(message, info, NTP_EF_EXP1, &exp1, sizeof (exp1))) {
+  if (!NEF_AddField(message, info, NTP_EF_EXP_MONO_ROOT, &ef, sizeof (ef))) {
     DEBUG_LOG("Could not add EF");
     return 0;
   }
 
-  info->ext_field_flags |= NTP_EF_FLAG_EXP1;
+  info->ext_field_flags |= NTP_EF_FLAG_EXP_MONO_ROOT;
 
   return 1;
 }
@@ -1224,9 +1224,9 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
     return 0;
 
   if (ext_field_flags) {
-    if (ext_field_flags & NTP_EF_FLAG_EXP1) {
-      if (!add_ext_exp1(&message, &info, smooth_time ? NULL : &local_receive,
-                        our_root_delay, our_root_dispersion))
+    if (ext_field_flags & NTP_EF_FLAG_EXP_MONO_ROOT) {
+      if (!add_ef_mono_root(&message, &info, smooth_time ? NULL : &local_receive,
+                            our_root_delay, our_root_dispersion))
         return 0;
     }
   }
@@ -1576,10 +1576,10 @@ 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;
+      case NTP_EF_EXP_MONO_ROOT:
+        if (ef_body_length == sizeof (NTP_EFExpMonoRoot) &&
+            ntohl(((NTP_EFExpMonoRoot *)ef_body)->magic) == NTP_EF_EXP_MONO_ROOT_MAGIC)
+          info->ext_field_flags |= NTP_EF_FLAG_EXP_MONO_ROOT;
         break;
       default:
         DEBUG_LOG("Unknown extension field type=%x", (unsigned int)ef_type);
@@ -1868,7 +1868,7 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
   /* Extension fields */
   int parsed, ef_length, ef_type, ef_body_length;
   void *ef_body;
-  NTP_ExtFieldExp1 *ef_exp1;
+  NTP_EFExpMonoRoot *ef_mono_root;
 
   NTP_Local_Timestamp local_receive, local_transmit;
   double remote_interval, local_interval, response_time;
@@ -1879,7 +1879,7 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
 
   stats = SRC_GetSourcestats(inst->source);
 
-  ef_exp1 = NULL;
+  ef_mono_root = NULL;
 
   /* Find requested non-authentication extension fields */
   if (inst->ext_field_flags & info->ext_field_flags) {
@@ -1889,11 +1889,11 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
         break;
 
       switch (ef_type) {
-        case NTP_EF_EXP1:
-          if (inst->ext_field_flags & NTP_EF_FLAG_EXP1 &&
-              ef_body_length == sizeof (*ef_exp1) &&
-              ntohl(((NTP_ExtFieldExp1 *)ef_body)->magic) == NTP_EF_EXP1_MAGIC)
-            ef_exp1 = ef_body;
+        case NTP_EF_EXP_MONO_ROOT:
+          if (inst->ext_field_flags & NTP_EF_FLAG_EXP_MONO_ROOT &&
+              ef_body_length == sizeof (*ef_mono_root) &&
+              ntohl(((NTP_EFExpMonoRoot *)ef_body)->magic) == NTP_EF_EXP_MONO_ROOT_MAGIC)
+            ef_mono_root = ef_body;
           break;
       }
     }
@@ -1902,9 +1902,9 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
   pkt_leap = NTP_LVM_TO_LEAP(message->lvm);
   pkt_version = NTP_LVM_TO_VERSION(message->lvm);
   pkt_refid = ntohl(message->reference_id);
-  if (ef_exp1) {
-    pkt_root_delay = UTI_Ntp32f28ToDouble(ef_exp1->root_delay);
-    pkt_root_dispersion = UTI_Ntp32f28ToDouble(ef_exp1->root_dispersion);
+  if (ef_mono_root) {
+    pkt_root_delay = UTI_Ntp32f28ToDouble(ef_mono_root->root_delay);
+    pkt_root_dispersion = UTI_Ntp32f28ToDouble(ef_mono_root->root_dispersion);
   } else {
     pkt_root_delay = UTI_Ntp32ToDouble(message->root_delay);
     pkt_root_dispersion = UTI_Ntp32ToDouble(message->root_dispersion);
@@ -1989,11 +1989,11 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
        the new sample.  In the interleaved mode, cancel the correction out in
        remote timestamps of the previous request and response, which were
        captured before the source accumulated the new time corrections. */
-    if (ef_exp1 && inst->remote_mono_epoch == ntohl(ef_exp1->mono_epoch) &&
-        !UTI_IsZeroNtp64(&ef_exp1->mono_receive_ts) &&
+    if (ef_mono_root && inst->remote_mono_epoch == ntohl(ef_mono_root->mono_epoch) &&
+        !UTI_IsZeroNtp64(&ef_mono_root->mono_receive_ts) &&
         !UTI_IsZeroNtp64(&inst->remote_ntp_monorx)) {
       mono_doffset =
-          UTI_DiffNtp64ToDouble(&ef_exp1->mono_receive_ts, &inst->remote_ntp_monorx) -
+          UTI_DiffNtp64ToDouble(&ef_mono_root->mono_receive_ts, &inst->remote_ntp_monorx) -
           UTI_DiffNtp64ToDouble(&message->receive_ts, &inst->remote_ntp_rx);
       if (fabs(mono_doffset) > MAX_MONO_DOFFSET)
         mono_doffset = 0.0;
@@ -2165,9 +2165,9 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
     /* If available, update the monotonic timestamp and accumulate the offset.
        This needs to be done here to not lose changes in remote_ntp_rx in
        symmetric mode when there are multiple responses per request. */
-    if (ef_exp1 && !UTI_IsZeroNtp64(&ef_exp1->mono_receive_ts)) {
-      inst->remote_mono_epoch = ntohl(ef_exp1->mono_epoch);
-      inst->remote_ntp_monorx = ef_exp1->mono_receive_ts;
+    if (ef_mono_root && !UTI_IsZeroNtp64(&ef_mono_root->mono_receive_ts)) {
+      inst->remote_mono_epoch = ntohl(ef_mono_root->mono_epoch);
+      inst->remote_ntp_monorx = ef_mono_root->mono_receive_ts;
       inst->mono_doffset += mono_doffset;
     } else {
       inst->remote_mono_epoch = 0;
similarity index 96%
rename from test/simulation/144-exp1
rename to test/simulation/144-monoroot
index 4a2042d2e8b78ecb0bd101a8e033fc0271c28409..20fae12b0cd7055a389109b10ed7fb3ab95a79e7 100755 (executable)
@@ -2,7 +2,7 @@
 
 . ./test.common
 
-test_start "experimental extension field"
+test_start "mono+root extension field"
 
 check_config_h 'FEAT_CMDMON 1' || test_skip