]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
General clang format. Quieten a few debug messages.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 31 Jul 2022 12:10:57 +0000 (13:10 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 31 Jul 2022 12:10:57 +0000 (13:10 +0100)
general-utilities.c
nqptp-clock-sources.c
nqptp-clock-sources.h
nqptp-message-handlers.c
nqptp-message-handlers.h
nqptp-shm-structures.h
nqptp-utilities.c
nqptp.c
nqptp.h

index a92a71d5f025a6b3e0b4d92f07f8244c4046cce4..cd9cff339c1347ff1cdf37262fab6576e31f4139 100644 (file)
@@ -83,6 +83,6 @@ uint64_t get_time_now() {
   clock_gettime(CLOCK_MONOTONIC_RAW, &tn);
 #else
   clock_gettime(CLOCK_MONOTONIC, &tn);
-#endif  
+#endif
   return timespec_to_ns(&tn);
 }
index e9aa99828e3fce19f192c919175895a698534831..f0a6ad4917f1ff4acf2f33639f6148d933a60798 100644 (file)
@@ -455,6 +455,7 @@ void update_master(int client_id) {
       }
     }
   }
+//  if ((best_so_far == -1) || (best_so_far != old_master)) {
   if (best_so_far == -1) {
     // no master clock
     // if (old_master != -1) {
@@ -462,6 +463,8 @@ void update_master(int client_id) {
     debug(2, "Remove master clock information from interface %s.", get_client_name(client_id));
     update_master_clock_info(client_id, 0, NULL, 0, 0, 0);
     //}
+  }
+  if (best_so_far == -1) {
     if (timing_peer_count == 0)
       debug(2, "empty timing peer group ");
     else
@@ -476,7 +479,8 @@ void update_master_clock_info(int client_id, uint64_t master_clock_id, const cha
                               uint64_t local_time, uint64_t local_to_master_offset,
                               uint64_t mastership_start_time) {
   if (clients[client_id].shm_interface_name[0] != '\0') {
-    // debug(1,"update_master_clock_info clock: % " PRIx64 ", offset: %" PRIx64 ".", master_clock_id, local_to_master_offset);
+    // debug(1,"update_master_clock_info clock: % " PRIx64 ", offset: %" PRIx64 ".",
+    // master_clock_id, local_to_master_offset);
     int rc = pthread_mutex_lock(&clients[client_id].shared_memory->shm_mutex);
     if (rc != 0)
       warn("Can't acquire mutex to update master clock!");
index 1c81840b82bea26da738095ad3e5c4c25bb8b138..7b806d14d3a86f0f12ea18b2e4f708858bd1b2b7 100644 (file)
@@ -37,7 +37,8 @@ typedef struct {
   int follow_up_number;
   int announcements_without_followups; // add 1 for every announce, reset with a followup
   uint64_t clock_id;
-  uint64_t previous_offset, previous_offset_time, previous_offset_grandmaster, previous_preciseOriginTimestamp;
+  uint64_t previous_offset, previous_offset_time, previous_offset_grandmaster,
+      previous_preciseOriginTimestamp;
   uint64_t mastership_start_time; // set to the time of the first sample used as master
 
   // for garbage collection
index 2b81af6b18faba6171b0fcf420704512f438964d..f874339283ddf7ed6ee3e0bb5ea782bbf0f44fb5 100644 (file)
@@ -238,24 +238,24 @@ void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clo
 }
 
 void handle_sync(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
-                      uint64_t reception_time) {
+                 __attribute__((unused)) uint64_t reception_time) {
   if (clock_private_info->clock_id == 0) {
-    debug(2,"Sync received before announcement -- discarded.");
+    debug(2, "Sync received before announcement -- discarded.");
   } else {
     if ((recv_len >= 0) && ((size_t)recv_len >= sizeof(struct ptp_sync_message))) {
       int is_a_master = 0;
       int temp_client_id;
       for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++)
-        if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0) 
+        if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0)
           is_a_master = 1;
-    
+
       // only process it if it's a master somewhere...
-      
+
       if (is_a_master) {
-      // debug_print_buffer(1, buf, recv_len);
-      struct ptp_sync_message *msg = (struct ptp_sync_message *)buf;
-      
-      // clang-format off
+        // debug_print_buffer(1, buf, recv_len);
+        struct ptp_sync_message *msg = (struct ptp_sync_message *)buf;
+
+        // clang-format off
       
       // actually the precision timestamp needs to be corrected by the Follow_Up Correction_Field contents.
       // According to IEEE Std 802.1AS-2020, paragraph 11.4.4.2.1:
@@ -266,15 +266,15 @@ void handle_sync(char *buf, ssize_t recv_len, clock_source_private_data *clock_p
       is the value of the synchronized time corresponding to the syncEventEgressTimestamp at the PTP Instance that sent the associated Sync message,
       including any fractional nanoseconds.
       */
-      
-      // clang-format on
-      
-      int64_t correction_field = ntoh64(msg->header.correctionField);
-      
-      if (correction_field != 0)
-        debug(1,"Sync correction field is notzero: %" PRId64 " ns.", correction_field);
-      
-      correction_field = correction_field / 65536; //might be signed
+
+        // clang-format on
+
+        int64_t correction_field = ntoh64(msg->header.correctionField);
+
+        if (correction_field != 0)
+          debug(1, "Sync correction field is non-zero: %" PRId64 " ns.", correction_field);
+
+        correction_field = correction_field / 65536; // might be signed
       }
     } else {
       debug(1, "Sync message is too small to be valid.");
@@ -285,63 +285,69 @@ void handle_sync(char *buf, ssize_t recv_len, clock_source_private_data *clock_p
 void handle_follow_up(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
                       uint64_t reception_time) {
   if (clock_private_info->clock_id == 0) {
-    debug(2,"Follow_Up received before announcement -- discarded.");
+    debug(2, "Follow_Up received before announcement -- discarded.");
   } else {
     clock_private_info->announcements_without_followups = 0;
     if ((recv_len >= 0) && ((size_t)recv_len >= sizeof(struct ptp_follow_up_message))) {
       int is_a_master = 0;
       int temp_client_id;
       for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++)
-        if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0) 
+        if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0)
           is_a_master = 1;
-    
+
       // only process it if it's a master somewhere...
-      
+
       if (is_a_master) {
-      // debug_print_buffer(1, buf, recv_len);
-      struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
-      uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]);
-      uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]);
-      uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]);
-      uint64_t preciseOriginTimestamp = seconds_hi;
-      preciseOriginTimestamp = preciseOriginTimestamp << 32;
-      preciseOriginTimestamp = preciseOriginTimestamp + seconds_low;
-      preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L;
-      preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds;
-
-      // update our sample information
-
-
-      if (clock_private_info->previous_preciseOriginTimestamp == preciseOriginTimestamp) {
-        clock_private_info->identical_previous_preciseOriginTimestamp_count++;
-        
-        if (clock_private_info->identical_previous_preciseOriginTimestamp_count == 8 * 60) {
-          int64_t duration_of_mastership = reception_time - clock_private_info->mastership_start_time;
-          if (clock_private_info->mastership_start_time == 0)
-            duration_of_mastership = 0;
-          debug(1,"Clock %" PRIx64 "'s grandmaster clock has stopped after %f seconds of mastership.", clock_private_info->clock_id, 0.000000001 * duration_of_mastership);
-          int64_t wait_limit = 62;
-          wait_limit = wait_limit * 1000000000;
-          if (duration_of_mastership <= wait_limit) {
-            debug(1, "Attempt to start a stopped clock %" PRIx64 ", at follow_up_number %u at IP %s.",
-              clock_private_info->clock_id, clock_private_info->follow_up_number,
-              clock_private_info->ip);
-            send_awakening_announcement_sequence(clock_private_info->clock_id, clock_private_info->ip,
-                                              clock_private_info->family, clock_private_info->grandmasterPriority1,
-                                              clock_private_info->grandmasterPriority2);
+        // debug_print_buffer(1, buf, recv_len);
+        struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
+        uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]);
+        uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]);
+        uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]);
+        uint64_t preciseOriginTimestamp = seconds_hi;
+        preciseOriginTimestamp = preciseOriginTimestamp << 32;
+        preciseOriginTimestamp = preciseOriginTimestamp + seconds_low;
+        preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L;
+        preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds;
+
+        // update our sample information
+
+        if (clock_private_info->previous_preciseOriginTimestamp == preciseOriginTimestamp) {
+          clock_private_info->identical_previous_preciseOriginTimestamp_count++;
+
+          if (clock_private_info->identical_previous_preciseOriginTimestamp_count == 8 * 60) {
+            int64_t duration_of_mastership =
+                reception_time - clock_private_info->mastership_start_time;
+            if (clock_private_info->mastership_start_time == 0)
+              duration_of_mastership = 0;
+            debug(2,
+                  "Clock %" PRIx64
+                  "'s grandmaster clock has stopped after %f seconds of mastership.",
+                  clock_private_info->clock_id, 0.000000001 * duration_of_mastership);
+            int64_t wait_limit = 62;
+            wait_limit = wait_limit * 1000000000;
+            if (duration_of_mastership <= wait_limit) {
+              debug(2,
+                    "Attempt to start a stopped clock %" PRIx64
+                    ", at follow_up_number %u at IP %s.",
+                    clock_private_info->clock_id, clock_private_info->follow_up_number,
+                    clock_private_info->ip);
+              send_awakening_announcement_sequence(
+                  clock_private_info->clock_id, clock_private_info->ip, clock_private_info->family,
+                  clock_private_info->grandmasterPriority1,
+                  clock_private_info->grandmasterPriority2);
+            }
+          }
+        } else {
+          if (clock_private_info->identical_previous_preciseOriginTimestamp_count >= 8 * 60) {
+            debug(2, "Clock %" PRIx64 "'s grandmaster clock has started again...",
+                  clock_private_info->clock_id);
+            clock_private_info->identical_previous_preciseOriginTimestamp_count = 0;
           }
         }
-      } else {
-        if (clock_private_info->identical_previous_preciseOriginTimestamp_count >= 8 * 60) {
-          debug(1,"Clock %" PRIx64 "'s grandmaster clock has started again...", clock_private_info->clock_id);
-          clock_private_info->identical_previous_preciseOriginTimestamp_count = 0;
-        }
-      }
 
+        clock_private_info->previous_preciseOriginTimestamp = preciseOriginTimestamp;
 
-      clock_private_info->previous_preciseOriginTimestamp = preciseOriginTimestamp;
-      
-      // clang-format off
+        // clang-format off
       
       // actually the precision timestamp needs to be corrected by the Follow_Up Correction_Field contents.
       // According to IEEE Std 802.1AS-2020, paragraph 11.4.4.2.1:
@@ -352,141 +358,146 @@ void handle_follow_up(char *buf, ssize_t recv_len, clock_source_private_data *cl
       is the value of the synchronized time corresponding to the syncEventEgressTimestamp at the PTP Instance that sent the associated Sync message,
       including any fractional nanoseconds.
       */
-      
-      // clang-format on
-      
-      int64_t correction_field = ntoh64(msg->header.correctionField);
-      
-      // debug(1," Check ntoh64: in: %" PRIx64 ", out: %" PRIx64 ".", msg->header.correctionField, correction_field);
-      
-      correction_field = correction_field / 65536; //might be signed
-      uint64_t correctedPreciseOriginTimestamp = preciseOriginTimestamp + correction_field;
-      
 
-      if (clock_private_info->follow_up_number < 100)
-        clock_private_info->follow_up_number++;
+        // clang-format on
 
-      // if (clock_private_info->announcements_without_followups < 4) // if we haven't signalled already
-        clock_private_info->announcements_without_followups = 0;   // we've seen a followup
+        int64_t correction_field = ntoh64(msg->header.correctionField);
 
-      debug(2, "FOLLOWUP from %" PRIx64 ", %s.", clock_private_info->clock_id,
-            &clock_private_info->ip);
-      uint64_t offset = correctedPreciseOriginTimestamp - reception_time;
+        // debug(1," Check ntoh64: in: %" PRIx64 ", out: %" PRIx64 ".", msg->header.correctionField,
+        // correction_field);
 
-      int64_t jitter = 0;
+        correction_field = correction_field / 65536; // might be signed
+        uint64_t correctedPreciseOriginTimestamp = preciseOriginTimestamp + correction_field;
 
-      int64_t time_since_previous_offset = 0;
-      uint64_t smoothed_offset = offset;
+        if (clock_private_info->follow_up_number < 100)
+          clock_private_info->follow_up_number++;
 
-      // This is a bit hacky.
-      // Basically, the idea is that if the grandmaster has changed, then acceptance checking and
-      // smoothing should start as it it's a new clock. This is because the correctedPreciseOriginTimestamp,
-      // which is part of the data that is being smoothed, refers to the grandmaster, so when the
-      // grandmaster changes any previous calculations are no longer valid. The hacky bit is to signal
-      // this condition by zeroing the previous_offset_time.
-      if (clock_private_info->previous_offset_grandmaster != clock_private_info->grandmasterIdentity)
-        clock_private_info->previous_offset_time =
-            0;
+        // if (clock_private_info->announcements_without_followups < 4) // if we haven't signalled
+        // already
+        clock_private_info->announcements_without_followups = 0; // we've seen a followup
 
-      if (clock_private_info->previous_offset_time != 0) {
-        time_since_previous_offset = reception_time - clock_private_info->previous_offset_time;
-      }
+        debug(2, "FOLLOWUP from %" PRIx64 ", %s.", clock_private_info->clock_id,
+              &clock_private_info->ip);
+        uint64_t offset = correctedPreciseOriginTimestamp - reception_time;
+
+        int64_t jitter = 0;
+
+        int64_t time_since_previous_offset = 0;
+        uint64_t smoothed_offset = offset;
+
+        // This is a bit hacky.
+        // Basically, the idea is that if the grandmaster has changed, then acceptance checking and
+        // smoothing should start as it it's a new clock. This is because the
+        // correctedPreciseOriginTimestamp, which is part of the data that is being smoothed, refers
+        // to the grandmaster, so when the grandmaster changes any previous calculations are no
+        // longer valid. The hacky bit is to signal this condition by zeroing the
+        // previous_offset_time.
+        if (clock_private_info->previous_offset_grandmaster !=
+            clock_private_info->grandmasterIdentity)
+          clock_private_info->previous_offset_time = 0;
 
-      // Do acceptance checking and smoothing.
-
-      // Positive changes in the offset are much more likely to be
-      // legitimate, since they could only occur due to a shorter
-      // propagation time or less of a delay sending or receiving the packet.
-      // (Actually, this is not quite true --
-      // it is possible that the remote clock could be adjusted forward
-      // and this would increase the offset too.)
-      // Anyway, when the clock is new, we give extra preferential weighting to
-      // positive changes in the offset.
-
-      // If the new offset is greater, by any amount, than the old offset,
-      // or if it is less by up to 10 mS, accept it.
-      // Otherwise, drop it if the last sample was fairly recent
-      // If the last sample was long ago, take this as a discontinuity and
-      // accept it as the start of a new period of mastership.
-
-      // This seems to be quite stable
-
-      if (clock_private_info->previous_offset_time != 0)
-        jitter = offset - clock_private_info->previous_offset;
-
-      // We take any positive or a limited negative jitter as a sync event in
-      // a continuous synchronisation sequence.
-      // This works well with PTP sources that sleep, as when they sleep
-      // their clock stops. When they awaken, the offset from
-      // the local clock to them must be smaller than before, triggering the
-      // timing discontinuity below and allowing an immediate readjustment.
-
-      // The full value of a positive offset jitter is accepted for a
-      // number of follow_ups at the start.
-      // After that, the weight of the jitter is reduced.
-      // Follow-ups don't always come in at 125 ms intervals, especially after a discontinuity
-      // Delays makes the offsets smaller than they should be, which is quickly
-      // allowed for.
-
-      if ((clock_private_info->previous_offset_time != 0) && (jitter > -10000000)) {
-
-        if (jitter < 0) {
-          if (clock_private_info->follow_up_number <
-              (5 * 8)) // at the beginning (8 samples per second)
-            smoothed_offset = clock_private_info->previous_offset + jitter / 16;
+        if (clock_private_info->previous_offset_time != 0) {
+          time_since_previous_offset = reception_time - clock_private_info->previous_offset_time;
+        }
+
+        // Do acceptance checking and smoothing.
+
+        // Positive changes in the offset are much more likely to be
+        // legitimate, since they could only occur due to a shorter
+        // propagation time or less of a delay sending or receiving the packet.
+        // (Actually, this is not quite true --
+        // it is possible that the remote clock could be adjusted forward
+        // and this would increase the offset too.)
+        // Anyway, when the clock is new, we give extra preferential weighting to
+        // positive changes in the offset.
+
+        // If the new offset is greater, by any amount, than the old offset,
+        // or if it is less by up to 10 mS, accept it.
+        // Otherwise, drop it if the last sample was fairly recent
+        // If the last sample was long ago, take this as a discontinuity and
+        // accept it as the start of a new period of mastership.
+
+        // This seems to be quite stable
+
+        if (clock_private_info->previous_offset_time != 0)
+          jitter = offset - clock_private_info->previous_offset;
+
+        // We take any positive or a limited negative jitter as a sync event in
+        // a continuous synchronisation sequence.
+        // This works well with PTP sources that sleep, as when they sleep
+        // their clock stops. When they awaken, the offset from
+        // the local clock to them must be smaller than before, triggering the
+        // timing discontinuity below and allowing an immediate readjustment.
+
+        // The full value of a positive offset jitter is accepted for a
+        // number of follow_ups at the start.
+        // After that, the weight of the jitter is reduced.
+        // Follow-ups don't always come in at 125 ms intervals, especially after a discontinuity
+        // Delays makes the offsets smaller than they should be, which is quickly
+        // allowed for.
+
+        if ((clock_private_info->previous_offset_time != 0) && (jitter > -10000000)) {
+
+          if (jitter < 0) {
+            if (clock_private_info->follow_up_number <
+                (5 * 8)) // at the beginning (8 samples per second)
+              smoothed_offset = clock_private_info->previous_offset + jitter / 16;
+            else
+              smoothed_offset = clock_private_info->previous_offset + jitter / 64;
+          } else if (clock_private_info->follow_up_number <
+                     (5 * 8)) // at the beginning (8 samples per second)
+            smoothed_offset =
+                clock_private_info->previous_offset + jitter / 1; // accept positive changes quickly
           else
             smoothed_offset = clock_private_info->previous_offset + jitter / 64;
-        } else if (clock_private_info->follow_up_number <
-                   (5 * 8)) // at the beginning (8 samples per second)
-          smoothed_offset =
-              clock_private_info->previous_offset + jitter / 1; // accept positive changes quickly
-        else
-          smoothed_offset = clock_private_info->previous_offset + jitter / 64;
-      } else {
-        // allow samples to disappear for up to a second
-        if ((time_since_previous_offset != 0) && (time_since_previous_offset < 1000000000) && (jitter > -4000000000L)) {
-          smoothed_offset = clock_private_info->previous_offset +
-                            1; // if we have recent samples, forget the present sample...
         } else {
-          if (clock_private_info->previous_offset_time == 0)
-            debug(2, "Clock %" PRIx64 " record (re)starting at %s.", clock_private_info->clock_id,
-                  clock_private_info->ip);
-          else
-            debug(2,
-                  "Timing discontinuity on clock %" PRIx64
-                  " at %s: time_since_previous_offset: %.3f seconds.",
-                  clock_private_info->clock_id, clock_private_info->ip,
-                  0.000000001 * time_since_previous_offset);
-          smoothed_offset = offset;
-          // clock_private_info->follow_up_number = 0;
-          clock_private_info->mastership_start_time =
-              reception_time; // mastership is reset to this time...
+          // allow samples to disappear for up to a second
+          if ((time_since_previous_offset != 0) && (time_since_previous_offset < 1000000000) &&
+              (jitter > -4000000000L)) {
+            smoothed_offset = clock_private_info->previous_offset +
+                              1; // if we have recent samples, forget the present sample...
+          } else {
+            if (clock_private_info->previous_offset_time == 0)
+              debug(2, "Clock %" PRIx64 " record (re)starting at %s.", clock_private_info->clock_id,
+                    clock_private_info->ip);
+            else
+              debug(2,
+                    "Timing discontinuity on clock %" PRIx64
+                    " at %s: time_since_previous_offset: %.3f seconds.",
+                    clock_private_info->clock_id, clock_private_info->ip,
+                    0.000000001 * time_since_previous_offset);
+            smoothed_offset = offset;
+            // clock_private_info->follow_up_number = 0;
+            clock_private_info->mastership_start_time =
+                reception_time; // mastership is reset to this time...
+          }
         }
-      }
 
-      clock_private_info->previous_offset_grandmaster = clock_private_info->grandmasterIdentity;
-      clock_private_info->previous_offset = smoothed_offset;
-      clock_private_info->previous_offset_time = reception_time;
+        clock_private_info->previous_offset_grandmaster = clock_private_info->grandmasterIdentity;
+        clock_private_info->previous_offset = smoothed_offset;
+        clock_private_info->previous_offset_time = reception_time;
 
-      int temp_client_id;
-      for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
-        if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0) {
-        debug(1,
-              "Clock %" PRIx64 ", grandmaster %" PRIx64 ". Offset: %" PRIx64
-              ", smoothed offset: %" PRIx64 ". Raw Precise Origin Timestamp: %" PRIx64
-              ". Time since previous offset: %8.3f milliseconds. ID: %5u, Follow_Up Number: %u. Source: %s",
-              clock_private_info->clock_id, clock_private_info->grandmasterIdentity, offset,
-              smoothed_offset, preciseOriginTimestamp, 0.000001 * time_since_previous_offset,
-              ntohs(msg->header.sequenceId), clock_private_info->follow_up_number, clock_private_info->ip);
-
-          debug(2, "clock_is_master -- updating master clock info for client \"%s\"",
-                get_client_name(temp_client_id));
-          update_master_clock_info(temp_client_id, clock_private_info->clock_id,
-                                   (const char *)&clock_private_info->ip, reception_time,
-                                   smoothed_offset, clock_private_info->mastership_start_time);
+        int temp_client_id;
+        for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
+          if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0) {
+            debug(2,
+                  "Clock %" PRIx64 ", grandmaster %" PRIx64 ". Offset: %" PRIx64
+                  ", smoothed offset: %" PRIx64 ". Raw Precise Origin Timestamp: %" PRIx64
+                  ". Time since previous offset: %8.3f milliseconds. ID: %5u, Follow_Up Number: "
+                  "%u. Source: %s",
+                  clock_private_info->clock_id, clock_private_info->grandmasterIdentity, offset,
+                  smoothed_offset, preciseOriginTimestamp, 0.000001 * time_since_previous_offset,
+                  ntohs(msg->header.sequenceId), clock_private_info->follow_up_number,
+                  clock_private_info->ip);
+
+            debug(2, "clock_is_master -- updating master clock info for client \"%s\"",
+                  get_client_name(temp_client_id));
+            update_master_clock_info(temp_client_id, clock_private_info->clock_id,
+                                     (const char *)&clock_private_info->ip, reception_time,
+                                     smoothed_offset, clock_private_info->mastership_start_time);
+          }
         }
       }
-      }
     } else {
       debug(1, "Follow_Up message is too small to be valid.");
     }
index 72a4cda076cd5a1bdef8a131cdb4c437dbf888e6..6d2e3428e7f30b2e5298ad071f06ae3cbed83d9d 100644 (file)
@@ -28,7 +28,7 @@ void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clo
                      uint64_t reception_time);
 
 void handle_sync(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
-                      uint64_t reception_time);
+                 uint64_t reception_time);
 
 void handle_follow_up(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
                       uint64_t reception_time);
index 0791197d0cc6a22df76ade5b4c29f497225113c0..f3861b44a7b8fddd57a06c066d4cb70a7fc33ac3 100644 (file)
@@ -41,7 +41,6 @@
 // (In future version of NQPTP the SMI interface may also be deleted at this point.)
 // SMI interfaces are not currently deleted or garbage collected.
 
-
 #include <inttypes.h>
 #include <pthread.h>
 
index d371aa296898a57e6492ecf6e9ee90c042c6b0d8..6a132f8366a6dd30b7909d877d8208dc3501040e 100644 (file)
 #endif
 
 #ifdef CONFIG_FOR_FREEBSD
-#include <sys/types.h>
-#include <net/if_types.h>
 #include <net/if_dl.h>
+#include <net/if_types.h>
 #include <sys/socket.h>
+#include <sys/types.h>
 #include <unistd.h>
 #endif
-  
+
 #include <netdb.h>  // getaddrinfo etc.
 #include <stdio.h>  // snprintf
 #include <stdlib.h> // malloc, free
diff --git a/nqptp.c b/nqptp.c
index 017e3a2950277daf12382ef721700154b2a5bec5..e6f3d6cb7a2d7a9803b97e1e36ce3dbb4a838c50 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -410,8 +410,8 @@ void send_awakening_announcement_sequence(const uint64_t clock_id, const char *c
       int ret = sendto(s, msg, msg_length, 0, res->ai_addr, res->ai_addrlen);
       if (ret == -1)
         debug(1, "result of sendto is %d.", ret);
-      debug(2, "Send awaken Announce message to clock \"%" PRIx64 "\" at %s on %s.", clock_id, clock_ip,
-            ip_family == AF_INET6 ? "IPv6" : "IPv4");
+      debug(2, "Send awaken Announce message to clock \"%" PRIx64 "\" at %s on %s.", clock_id,
+            clock_ip, ip_family == AF_INET6 ? "IPv6" : "IPv4");
 
       if (priority1 < 254) {
         msg->announce.grandmasterPriority1 =
@@ -437,20 +437,21 @@ uint64_t broadcasting_task(uint64_t call_time, __attribute__((unused)) void *pri
   clock_source_private_data *clocks_private = (clock_source_private_data *)private_data;
   int i;
   for (i = 0; i < MAX_CLOCKS; i++) {
-  
+
     int is_a_master = 0;
     int temp_client_id;
-  
+
     for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++)
-      if ((clocks_private->client_flags[temp_client_id] & (1 << clock_is_master)) != 0) 
+      if ((clocks_private->client_flags[temp_client_id] & (1 << clock_is_master)) != 0)
         is_a_master = 1;
-    
+
     // only process it if it's a master somewhere...
-    if ((is_a_master != 0) && 
-        (clocks_private[i].announcements_without_followups == 3) &&
+    if ((is_a_master != 0) && (clocks_private[i].announcements_without_followups == 3) &&
         // (clocks_private[i].follow_up_number == 0) && // only check at the start
         ((clocks_private[i].flags & (1 << clock_is_one_of_ours)) == 0)) {
-      debug(1, "Attempt to awaken a silent clock %" PRIx64 ", index %u, at follow_up_number %u at IP %s.",
+      debug(2,
+            "Attempt to awaken a silent clock %" PRIx64
+            ", index %u, at follow_up_number %u at IP %s.",
             clocks_private[i].clock_id, i, clocks_private[i].follow_up_number,
             clocks_private[i].ip);
 
diff --git a/nqptp.h b/nqptp.h
index 3f04e1d0bbc0575888dd30955cd8772ae301145f..1070b9115db42090e45ee52c770d7e86bc8416b0 100644 (file)
--- a/nqptp.h
+++ b/nqptp.h
 // Instances" -- of a "PTP Network" it wishes to monitor. This is a "timing group" in AirPlay 2
 // parlance, it seems.
 
-
 void send_awakening_announcement_sequence(const uint64_t clock_id, const char *clock_ip,
                                           const int ip_family, const uint8_t priority1,
                                           const uint8_t priority2);
 
-
 #endif