]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Include the IP or the master in the shm -- the user might wish to check that it's...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 2 May 2021 13:40:39 +0000 (14:40 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 2 May 2021 13:40:39 +0000 (14:40 +0100)
nqptp-clock-sources.c
nqptp-message-handlers.c
nqptp-shm-structures.h
nqptp.c
nqptp.h

index c32d4240a13663cbac247cba3ee8c6baf0c787b3..009732aff1d5daf98fb21cee5f7824ec56b4d285 100644 (file)
@@ -205,7 +205,7 @@ void update_master() {
     if (old_master != -1) {
       // but there was a master clock, so remove it
       debug(1,"shm interface -- remove master clock designation");
-      update_master_clock_info(0, 0, 0);
+      update_master_clock_info(0, NULL, 0, 0);
     }
     if (timing_peer_count == 0)
       debug(2, "No timing peer list found");
@@ -217,6 +217,7 @@ void update_master() {
     // master_clock_index = best_so_far;
     if (old_master != best_so_far) {
       update_master_clock_info(clocks_private[best_so_far].clock_id,
+                               &clocks_private[best_so_far].ip,
                                clocks_private[best_so_far].local_time,
                                clocks_private[best_so_far].local_to_source_time_offset);
     }
index 21cbaa4fd862b0e0b5c6a848f9166fa7c7547491..448f8602c4d8916cb3de46807e913c4f2b6a26d4 100644 (file)
@@ -494,7 +494,9 @@ void handle_delay_resp(char *buf, __attribute__((unused)) ssize_t recv_len,
       if (old_flags != clock_private_info->flags) {
         update_master();
       } else if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
-        update_master_clock_info(clock_private_info->clock_id, clock_private_info->local_time,
+        update_master_clock_info(clock_private_info->clock_id,
+                                 &clock_private_info->ip,
+                                 clock_private_info->local_time,
                                  clock_private_info->local_to_source_time_offset);
       }
 
index f30f9896ac2bb9e98fc19001d88af6f3cbc36821..50d9e9aacc5544c73528ce4c0106afde9e8a137d 100644 (file)
@@ -22,7 +22,7 @@
 
 #define STORAGE_ID "/nqptp"
 #define MAX_CLOCKS 32
-#define NQPTP_SHM_STRUCTURES_VERSION 3
+#define NQPTP_SHM_STRUCTURES_VERSION 4
 #define NQPTP_CONTROL_PORT 9000
 
 // the control port will accept a UDP packet with the first letter being:
@@ -40,6 +40,7 @@ struct shm_structure {
   uint16_t version;          // check this is equal to NQPTP_SHM_STRUCTURES_VERSION
   uint32_t flags;            // unused
   uint64_t master_clock_id;  // the current master clock
+  char master_clock_ip[64];  // where it's coming from
   uint64_t local_time;       // the time when the offset was calculated
   uint64_t local_to_master_time_offset; // add this to the local time to get master clock time
 };
diff --git a/nqptp.c b/nqptp.c
index 04c5fb6650fe3cb965e41019afccbc878c0d592d..8db0faafd1d9cb6e1290ec64119457f7cb1d36da 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
 #include <signal.h>
 #include <sys/epoll.h>
 
+#ifndef FIELD_SIZEOF
+#define FIELD_SIZEOF(t, f) (sizeof(((t *)0)->f))
+#endif
+
 // 8 samples per second
 
 #define BUFLEN 4096    // Max length of buffer
@@ -71,7 +75,7 @@ int master_clock_index = -1;
 struct shm_structure *shared_memory = NULL; // this is where public clock info is available
 int epoll_fd;
 
-void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time,
+void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t local_time,
                               uint64_t local_to_master_offset) {
   if (shared_memory->master_clock_id != master_clock_id)
     debug(1, "Master clock is: %" PRIx64 ".", master_clock_id);
@@ -79,6 +83,10 @@ void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time,
   if (rc != 0)
     warn("Can't acquire mutex to update master clock!");
   shared_memory->master_clock_id = master_clock_id;
+  if (ip != NULL)
+    strncpy((char *)&shared_memory->master_clock_ip, ip, FIELD_SIZEOF(struct shm_structure, master_clock_ip) - 1);
+  else
+    shared_memory->master_clock_ip[0] = '\0';
   shared_memory->local_time = local_time;
   shared_memory->local_to_master_time_offset = local_to_master_offset;
   rc = pthread_mutex_unlock(&shared_memory->shm_mutex);
diff --git a/nqptp.h b/nqptp.h
index 0e0d1d5dfc6e3f436b94ad926d5ed35d09d6a451..c1da9ebff630a3949aa223623ccc5a5228c0243b 100644 (file)
--- a/nqptp.h
+++ b/nqptp.h
@@ -31,7 +31,7 @@
 extern int master_clock_index;
 extern struct shm_structure *shared_memory;
 
-void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time,
+void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t local_time,
                               uint64_t local_to_master_offset);
 
 #endif
\ No newline at end of file