]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: make NTP-over-PTP domain configurable
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 20 Jun 2024 12:31:04 +0000 (14:31 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 20 Jun 2024 13:00:17 +0000 (15:00 +0200)
Add ptpdomain directive to set the domain number of transmitted and
accepted NTP-over-PTP messages. It might need to be changed in networks
using a PTP profile with the same domain number. The default domain
number of 123 follows the current NTP-over-PTP specification.

conf.c
conf.h
doc/chrony.conf.adoc
ntp_io.c
ptp.h
test/simulation/142-ntpoverptp

diff --git a/conf.c b/conf.c
index 01ace0df4edcc91cd665877d1a1282f94140911e..774dc672ccae73db8b07661865be75d30d52938b 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -287,6 +287,8 @@ static double hwts_timeout = 0.001;
 
 /* PTP event port (disabled by default) */
 static int ptp_port = 0;
+/* PTP domain number of NTP-over-PTP messages */
+static int ptp_domain = 123;
 
 typedef struct {
   NTP_Source_Type type;
@@ -708,6 +710,8 @@ CNF_ParseLine(const char *filename, int number, char *line)
     parse_source(p, command, 1);
   } else if (!strcasecmp(command, "port")) {
     parse_int(p, &ntp_port);
+  } else if (!strcasecmp(command, "ptpdomain")) {
+    parse_int(p, &ptp_domain);
   } else if (!strcasecmp(command, "ptpport")) {
     parse_int(p, &ptp_port);
   } else if (!strcasecmp(command, "ratelimit")) {
@@ -2572,6 +2576,14 @@ CNF_GetPtpPort(void)
 
 /* ================================================== */
 
+int
+CNF_GetPtpDomain(void)
+{
+  return ptp_domain;
+}
+
+/* ================================================== */
+
 int
 CNF_GetRefresh(void)
 {
diff --git a/conf.h b/conf.h
index fb45fb770ea85b2d6f0668bac780d0dd2f2b0da4..cc0f17ea3370d24ce4e2e20a6a40d85a1779f6bb 100644 (file)
--- a/conf.h
+++ b/conf.h
@@ -159,6 +159,7 @@ extern int CNF_GetHwTsInterface(unsigned int index, CNF_HwTsInterface **iface);
 extern double CNF_GetHwTsTimeout(void);
 
 extern int CNF_GetPtpPort(void);
+extern int CNF_GetPtpDomain(void);
 
 extern int CNF_GetRefresh(void);
 
index 56ed8427f10c6947013ab44117a75bcf53b62bc4..15684a861d6352370a30c32581a9f11dc063b264 100644 (file)
@@ -2802,6 +2802,11 @@ hwtimestamp * rxfilter ptp
 ptpport 319
 ----
 
+[[ptpdomain]]*ptpdomain* _domain_::
+The *ptpdomain* directive sets the PTP domain number of transmitted and
+accepted NTP-over-PTP messages. Messages from other domains are ignored.
+The default is 123, the minimum is 0, and the maximum is 255.
+
 [[sched_priority]]*sched_priority* _priority_::
 On Linux, FreeBSD, NetBSD, and illumos, the *sched_priority* directive will
 select the SCHED_FIFO real-time scheduler at the specified priority (which must
index fc80aca21cb57de68286b3cae5abec3df39cef90..7a034f72e8d6a13c6f9f4fa917de28dfd5e2dca2 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -517,7 +517,7 @@ NIO_UnwrapMessage(SCK_Message *message, int sock_fd, double *net_correction)
       (msg->header.version != PTP_VERSION_2 &&
        (msg->header.version != PTP_VERSION_2_1 || msg->header.min_sdoid != 0)) ||
       ntohs(msg->header.length) != message->length ||
-      msg->header.domain != PTP_DOMAIN_NTP ||
+      msg->header.domain != CNF_GetPtpDomain() ||
       ntohs(msg->header.flags) != PTP_FLAG_UNICAST ||
       ntohs(msg->tlv_header.type) != PTP_TLV_NTP ||
       ntohs(msg->tlv_header.length) != message->length - PTP_NTP_PREFIX_LENGTH) {
@@ -565,7 +565,7 @@ wrap_message(SCK_Message *message, int sock_fd)
   ptp_message->header.type = PTP_TYPE_DELAY_REQ;
   ptp_message->header.version = PTP_VERSION_2;
   ptp_message->header.length = htons(PTP_NTP_PREFIX_LENGTH + message->length);
-  ptp_message->header.domain = PTP_DOMAIN_NTP;
+  ptp_message->header.domain = CNF_GetPtpDomain();
   ptp_message->header.flags = htons(PTP_FLAG_UNICAST);
   ptp_message->header.sequence_id = htons(sequence_id++);
   ptp_message->tlv_header.type = htons(PTP_TLV_NTP);
diff --git a/ptp.h b/ptp.h
index 4330f4b359c37fb509a517fbe1ae7448338f52f2..8bf639a594db0a835fd4dccb99892a41ea6ce9bb 100644 (file)
--- a/ptp.h
+++ b/ptp.h
@@ -35,7 +35,6 @@
 #define PTP_VERSION_2_1 (2 | 1 << 4)
 #define PTP_TYPE_SYNC 0
 #define PTP_TYPE_DELAY_REQ 1
-#define PTP_DOMAIN_NTP 123
 #define PTP_FLAG_UNICAST (1 << (2 + 8))
 #define PTP_TLV_NTP 0x2023
 
index 2996dc0e8daa5f311a32c5844f9b494c36b4e77e..8f966af57487e02ede2aadd3fa9a8b1347d38405 100755 (executable)
@@ -16,6 +16,7 @@ peers=2
 max_sync_time=420
 
 server_conf="
+ptpdomain 123
 ptpport 319"
 client_conf="
 ptpport 319
@@ -103,4 +104,20 @@ if check_config_h 'FEAT_DEBUG 1'; then
        check_log_messages "apply_net_correction.*Applied" 0 0 || test_fail
 fi
 
+freq_offset=-1e-4
+delay_correction=""
+server_conf="ptpport 319"
+client_conf="ptpport 319
+ptpdomain 124
+authselectmode ignore
+keyfile tmp/peer.keys"
+time_max_limit=$default_time_max_limit
+time_rms_limit=$default_time_rms_limit
+freq_max_limit=$default_freq_max_limit
+freq_rms_limit=$default_freq_rms_limit
+
+run_test || test_fail
+check_chronyd_exit || test_fail
+check_sync || test_fail
+
 test_pass