If chronyd is selected as the NTP program, use the SOCK refclock instead
of SHM to improve security and reduce delay in receiving of samples.

Signed-off-by: Miroslav Lichvar <mlich...@redhat.com>
---
 timemaster.8 | 10 ++++-----
 timemaster.c | 57 +++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/timemaster.8 b/timemaster.8
index 2891a97..bc0b5b6 100644
--- a/timemaster.8
+++ b/timemaster.8
@@ -17,9 +17,9 @@ timemaster - run NTP with PTP as reference clocks
 \fBtimemaster\fR is a program that uses \fBptp4l\fR and \fBphc2sys\fR in
 combination with \fBchronyd\fR or \fBntpd\fR to synchronize the system clock to
 NTP and PTP time sources. The PTP time is provided by \fBphc2sys\fR and
-\fBptp4l\fR via SHM reference clocks to \fBchronyd\fR/\fBntpd\fR, which
-can compare all time sources and use the best sources to synchronize the system
-clock.
+\fBptp4l\fR via SOCK reference clock to \fBchronyd\fR or SHM reference clock to
+\fBntpd\fR, which can compare all time sources and use the best sources to
+synchronize the system clock.
 
 On start, \fBtimemaster\fR reads a configuration file that specifies the NTP
 and PTP time sources, checks which network interfaces have and share a PTP
@@ -154,14 +154,14 @@ specified also in other PTP domains and virtual clocks 
are disabled, only the
 
 .TP
 .B ntp_poll
-Specify the polling interval of the NTP SHM reference clock reading samples
+Specify the polling interval of the SOCK/SHM reference clock reading samples
 from \fBptp4l\fR or \fBphc2sys\fR. It's specified as a power of two in seconds.
 The default value is 2 (4 seconds).
 
 .TP
 .B phc2sys_poll
 Specify the polling interval used by \fBphc2sys\fR to read a PTP clock
-synchronized by \fBptp4l\fR and update the SHM sample for
+synchronized by \fBptp4l\fR and update the SOCK/SHM sample for
 \fBchronyd\fR/\fBntpd\fR. It's specified as a power of two in seconds. The
 default value is 0 (1 second).
 
diff --git a/timemaster.c b/timemaster.c
index 9fea011..e3cdbc0 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -674,10 +674,24 @@ static char **get_phc2sys_command(struct program_config 
*config,
                      xstrdup("-z"), xstrdup(uds_path),
                      xstrdup("-t"), xstrdup(message_tag),
                      xstrdup("-n"), string_newf("%d", domain),
-                     xstrdup("-E"), xstrdup("ntpshm"),
-                     xstrdup("-M"), string_newf("%d", refclock_id +
-                                                tconfig->first_shm_segment),
-                     NULL);
+                     xstrdup("-E"), NULL);
+
+       switch (tconfig->ntp_program) {
+       case CHRONYD:
+               parray_extend((void ***)&command,
+                             xstrdup("sock"), xstrdup("--chrony_sock_address"),
+                             string_newf("%s/chrony.SOCK%d",
+                                         tconfig->rundir, refclock_id),
+                             NULL);
+               break;
+       case NTPD:
+               parray_extend((void ***)&command,
+                             xstrdup("ntpshm"), xstrdup("-M"),
+                             string_newf("%d", refclock_id +
+                                         tconfig->first_shm_segment),
+                             NULL);
+               break;
+       }
 
        return command;
 }
@@ -705,21 +719,24 @@ static void add_command(char **command, int command_group,
        parray_append((void ***)&script->command_groups, group);
 }
 
-static void add_refclock_source(int refclock_id, int poll, int dpoll,
+static void add_refclock_source(int refclock_id, int poll, int phc_poll,
                                double delay, char *ntp_options, char *prefix,
                                struct timemaster_config *config,
                                char **ntp_config)
 {
-       int shm_segment = refclock_id + config->first_shm_segment;
+       int filter, shm_segment = refclock_id + config->first_shm_segment;
        char *refid = get_refid(prefix, refclock_id);
 
        switch (config->ntp_program) {
        case CHRONYD:
+               /* set filter to the expected number of samples per poll */
+               filter = (poll >= phc_poll) ? 1 << (poll - phc_poll) : 1;
                string_appendf(ntp_config,
-                              "refclock SHM %d poll %d dpoll %d "
-                              "refid %s precision 1.0e-9 delay %.1e %s\n",
-                              shm_segment, poll, dpoll, refid, delay,
-                              ntp_options);
+                              "refclock SOCK %s/chrony.SOCK%d poll %d "
+                              "filter %d refid %s precision 1.0e-9 "
+                              "delay %.1e %s\n",
+                              config->rundir, refclock_id, poll,
+                              filter, refid, delay, ntp_options);
                break;
        case NTPD:
                string_appendf(ntp_config,
@@ -922,10 +939,22 @@ static int add_ptp_source(struct ptp_domain *source,
                                                    interfaces, NULL, 0);
                        add_command(command, (*command_group)++, script);
 
-                       string_appendf(&config_file->content,
-                                      "clock_servo ntpshm\n"
-                                      "ntpshm_segment %d\n",
-                                      *refclock_id + 
config->first_shm_segment);
+                       switch (config->ntp_program) {
+                       case CHRONYD:
+                               string_appendf(&config_file->content,
+                                              "clock_servo sock\n"
+                                              "chrony_sock_address "
+                                              "%s/chrony.SOCK%d\n",
+                                              config->rundir, *refclock_id);
+                               break;
+                       case NTPD:
+                               string_appendf(&config_file->content,
+                                              "clock_servo ntpshm\n"
+                                              "ntpshm_segment %d\n",
+                                              *refclock_id +
+                                              config->first_shm_segment);
+                               break;
+                       }
                }
 
                parray_append((void ***)&script->configs, config_file);
-- 
2.37.3



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to