Compare commits

...

No commits in common. "c8" and "c9-beta" have entirely different histories.
c8 ... c9-beta

13 changed files with 775 additions and 213 deletions

6
.gitignore vendored
View File

@ -1,3 +1,3 @@
SOURCES/clknetsim-5d1dc0.tar.gz
SOURCES/linuxptp-4.2.tgz
SOURCES/linuxptp-testsuite-bf8ead.tar.gz
SOURCES/clknetsim-64df92.tar.gz
SOURCES/linuxptp-4.4.tgz
SOURCES/linuxptp-testsuite-d27dbd.tar.gz

3
.linuxptp.metadata Normal file
View File

@ -0,0 +1,3 @@
acb5ea319dfe96edd43033b35f025b3557b5e8a7 SOURCES/clknetsim-64df92.tar.gz
f35d56a2471359856843f7e703e5e8c681a66f0d SOURCES/linuxptp-4.4.tgz
8db14fbc7bdde436f2e957e77319569614ccf625 SOURCES/linuxptp-testsuite-d27dbd.tar.gz

View File

@ -1,75 +0,0 @@
commit bbfaa1e253b889aeea97702bbbc87e731e0caf87
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Feb 22 13:51:59 2024 +0100
lstab: Limit number of parsed leap seconds.
The lstab structure has a fixed-size array for leap seconds
(currently 28 + 200). Don't read more leap seconds from the leapfile to
avoid corrupting memory.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/lstab.c b/lstab.c
index 24add26..8e35504 100644
--- a/lstab.c
+++ b/lstab.c
@@ -137,7 +137,7 @@ static int lstab_read(struct lstab *lstab, const char *name)
fprintf(stderr, "failed to open '%s' for reading: %m\n", name);
return -1;
}
- while (1) {
+ while (index < N_LEAPS) {
if (!fgets(buf, sizeof(buf), fp)) {
break;
}
commit 90ad2efc74b0f348fb6b417565b3ada7d161641b
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Feb 22 13:56:53 2024 +0100
lstab: Don't free lstab on update.
The modification timestamp of the leapfile is checked with every
call of lstab_utc2tai(). If the file is modified, the provided lstab
structure is freed and a new one is allocated from the updated leapfile.
But the new lstab is not returned to the caller as the function doesn't
accept a pointer to the pointer to lstab. This causes reading from the
freed memory and leak of the newly allocated memory.
Modify update_leapsecond_table() to read the updated leapfile into the
existing lstab structure instead of the reallocation.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/lstab.c b/lstab.c
index 8e35504..357ed27 100644
--- a/lstab.c
+++ b/lstab.c
@@ -195,7 +195,6 @@ struct lstab *lstab_create(const char *filename)
int update_leapsecond_table(struct lstab *lstab)
{
- const char* leapfile;
struct stat statbuf;
int err;
@@ -212,14 +211,14 @@ int update_leapsecond_table(struct lstab *lstab)
return 0;
}
printf("updating leap seconds file\n");
- leapfile = lstab->leapfile;
- lstab_destroy(lstab);
- lstab = lstab_create(leapfile);
- if (!lstab) {
+ if (lstab_read(lstab, lstab->leapfile)) {
+ lstab->length = 0;
return -1;
}
+ lstab->lsfile_mtime = statbuf.st_mtim.tv_sec;
+
return 0;
}

View File

@ -1,29 +0,0 @@
commit 0404c1924254c9162222dd5000a140165d21250c
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Jan 25 15:23:44 2024 +0100
ts2phc: Fix offset for NMEA delays over 0.5 seconds.
The current code of ts2phc assumes that the NMEA RMC message is received
within 0.5 seconds of the pulse the timestamp in the message is refering
to. However, with most receivers NMEA messages are referenced to the
previous pulse. This causes a 1-second error in the measured offset for
receivers with delays over 0.5 seconds.
Add a 0.5 second correction to map the whole interval between pulses to
the preceding pulse.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/ts2phc_nmea_pps_source.c b/ts2phc_nmea_pps_source.c
index 3a4267d..274b70a 100644
--- a/ts2phc_nmea_pps_source.c
+++ b/ts2phc_nmea_pps_source.c
@@ -191,6 +191,7 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
return -1;
}
rmc = tmv_add(rmc, duration_since_rmc);
+ rmc = tmv_add(rmc, nanoseconds_to_tmv(500000000));
utc_time = tmv_to_nanoseconds(rmc);
utc_time /= (int64_t) 1000000000;
*ts = tmv_to_timespec(rmc);

View File

@ -0,0 +1,150 @@
commit a3420abab9eec2dc7b35e0e1e9f37ebeffc87655
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Tue Nov 26 15:10:32 2024 +0100
pmc_agent: Use longer update interval when not subscribed.
When phc2sys is started with the -w option, the pmc agent is not
subscribed to events by the pmc_agent_subscribe() function, which also
sets the update interval. The update interval in this case is zero,
which means the pmc agent is trying to update the currentUtcOffset value
on every call of pmc_agent_update(), i.e. on every clock update in
phc2sys.
Set a default update interval of 60 seconds to reduce the rate of
pmc requests.
Fixes: e3ca7ea90a9e ("pmc_agent: Make update interval configurable.")
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
diff --git a/pmc_agent.c b/pmc_agent.c
index d1a3367..663adc0 100644
--- a/pmc_agent.c
+++ b/pmc_agent.c
@@ -33,6 +33,9 @@
#define UPDATES_PER_SUBSCRIPTION 3
#define MIN_UPDATE_INTERVAL 10
+/* Update interval if the agent not subscribed, just polling the UTC offset */
+#define DEFAULT_UPDATE_INTERVAL 60
+
struct pmc_agent {
struct pmc *pmc;
uint64_t pmc_last_update;
@@ -253,6 +256,7 @@ int init_pmc_node(struct config *cfg, struct pmc_agent *node, const char *uds,
}
node->recv_subscribed = recv_subscribed;
node->recv_context = context;
+ node->update_interval = DEFAULT_UPDATE_INTERVAL * NS_PER_SEC;
return 0;
}
commit 03ab6793abf665039b25319f0f4ad7ce03452874
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Tue Nov 26 15:10:33 2024 +0100
phc2sys: Don't disable pmc agent with -s -d -w options.
When phc2sys is started with -s and -d options to combine a PPS device
and PHC device as a time source, but without an offset specified by
the -O option, the pmc agent is disabled after waiting for ptp4l to have
a port in a synchronized state. This prevents phc2sys from following
changes in the currentUtcOffset value.
Disable the pmc agent only if no PHC device is specified by the -s
option, i.e. there are no PHC readings to which the UTC offset could be
applied.
Fixes: 5f1b419c4102 ("phc2sys: Replace magical test with a proper test.")
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
diff --git a/phc2sys.c b/phc2sys.c
index d09cb53..c98ecec 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1594,7 +1594,7 @@ int main(int argc, char *argv[])
if (domains[0].forced_sync_offset ||
!phc2sys_using_systemclock(&domains[0]) ||
- hardpps_configured(pps_fd)) {
+ (hardpps_configured(pps_fd) && !src_name)) {
pmc_agent_disable(domains[0].agent);
}
}
commit 1e25a62e65e07f2cc9e1c390895f0a940d307a25
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Tue Nov 26 15:10:34 2024 +0100
phc2sys: Don't require -O option without -a and -w.
Allow phc2sys to be started in the static mode without the -O option,
meaning it should fetch the UTC offset from ptp4l, even if the -w option
is not included on the command line to wait for ptp4l to have a port in
the master or slave state.
This is useful when the PHC is synchronized by ts2phc or other
application and the system clock needs to be synchronized to the PHC
even when ptp4l has all ports in the faulty state (e.g. all network
links are down).
It's the responsibility of the user to start phc2sys when ptp4l is
already running. phc2sys will exit with an error message if it cannot
get a response with the 1-second timeout.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/phc2sys.8 b/phc2sys.8
index 762a1b1..3246c8f 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -164,7 +164,10 @@ minimize the error caused by random delays in scheduling and bus utilization.
The default is 5.
.TP
.BI \-O " offset"
-Specify the offset between the sink and source times in seconds. Not
+Specify the offset between the sink and source times in seconds. If not
+specified, the offset will be set according to the currentUtcOffset value
+obtained from ptp4l and the direction of synchronization, assuming the system
+clock is keeping time in UTC and all used PHCs keep time in TAI. Not
compatible with the
.B \-a
option. See
diff --git a/phc2sys.c b/phc2sys.c
index c98ecec..ddd0a6a 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -1452,12 +1452,6 @@ int main(int argc, char *argv[])
goto bad_usage;
}
- if (!autocfg && !wait_sync && !settings.forced_sync_offset) {
- fprintf(stderr,
- "time offset must be specified using -w or -O\n");
- goto bad_usage;
- }
-
if (hardpps_configured(pps_fd) && (dst_cnt != 1 ||
strcmp(dst_names[0], "CLOCK_REALTIME"))) {
fprintf(stderr,
@@ -1559,7 +1553,7 @@ int main(int argc, char *argv[])
r = -1;
- if (wait_sync) {
+ if (wait_sync || !domains[0].forced_sync_offset) {
snprintf(uds_local, sizeof(uds_local),
"/var/run/phc2sys.%d", getpid());
@@ -1574,7 +1568,7 @@ int main(int argc, char *argv[])
phc2sys_recv_subscribed, &domains[0]))
goto end;
- while (is_running()) {
+ while (wait_sync && is_running()) {
r = run_pmc_wait_sync(domains[0].agent, 1000);
if (r < 0)
goto end;

View File

@ -1,4 +1,4 @@
commit 6e480c9572925a4ea8aac45a10a306e0c4e509a9
commit daa82cda8318edd6a8e75ef46d0ed065445c8922
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Jan 11 11:33:54 2024 +0100
@ -7,33 +7,33 @@ Date: Thu Jan 11 11:33:54 2024 +0100
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/config.c b/config.c
index 398b420..d7775c0 100644
index 4a28efb..cbff976 100644
--- a/config.c
+++ b/config.c
@@ -319,7 +319,7 @@ struct config_item config_tab[] = {
GLOB_ITEM_STR("productDescription", ";;"),
@@ -347,7 +347,7 @@ struct config_item config_tab[] = {
PORT_ITEM_STR("ptp_dst_ipv4", "224.0.1.129"),
PORT_ITEM_STR("ptp_dst_ipv6", "FF0E:0:0:0:0:0:0:181"),
PORT_ITEM_STR("ptp_dst_mac", "01:1B:19:00:00:00"),
PORT_ITEM_STR("p2p_dst_mac", "01:80:C2:00:00:0E"),
- GLOB_ITEM_INT("ptp_minor_version", 1, 0, 1),
+ GLOB_ITEM_INT("ptp_minor_version", 0, 0, 1),
GLOB_ITEM_STR("refclock_sock_address", "/var/run/refclock.ptp.sock"),
GLOB_ITEM_STR("revisionData", ";;"),
GLOB_ITEM_INT("sanity_freq_limit", 200000000, 0, INT_MAX),
GLOB_ITEM_STR("sa_file", NULL),
diff --git a/configs/default.cfg b/configs/default.cfg
index 0c7661c..8f94c16 100644
index c3ad618..768eef8 100644
--- a/configs/default.cfg
+++ b/configs/default.cfg
@@ -46,7 +46,7 @@ power_profile.2011.networkTimeInaccuracy -1
@@ -47,7 +47,7 @@ power_profile.2011.networkTimeInaccuracy -1
power_profile.2017.totalTimeInaccuracy -1
power_profile.grandmasterID 0
power_profile.version none
-ptp_minor_version 1
+ptp_minor_version 0
#
# Run time options
-ptp_minor_version 1
+ptp_minor_version 0
spp -1
active_key_id 0
#
diff --git a/msg.h b/msg.h
index 9c80f45..786ddc7 100644
index 58c2287..d2658c9 100644
--- a/msg.h
+++ b/msg.h
@@ -32,7 +32,7 @@
@ -45,16 +45,44 @@ index 9c80f45..786ddc7 100644
#define PTP_VERSION (PTP_MINOR_VERSION << 4 | PTP_MAJOR_VERSION)
#define MAJOR_VERSION_MASK 0x0f
diff --git a/port.c b/port.c
index db35a44..7f945ac 100644
--- a/port.c
+++ b/port.c
@@ -3696,7 +3696,7 @@ struct port *port_open(const char *phc_device,
pr_err("%s: spp not supported on one-step ports", p->log_name);
goto err_uc_service;
}
- if (port_has_security(p) && (config_get_int(cfg, NULL, "ptp_minor_version") < 1)) {
+ if (port_has_security(p) && ptp_hdr_ver >> 4 < 1) {
pr_err("%s: spp needs at least PTPv2.1", p->log_name);
goto err_uc_service;
}
diff --git a/ptp4l.8 b/ptp4l.8
index 4cb9adb..c59b0b4 100644
index 87900e3..28cc4c9 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -813,7 +813,7 @@ The default is 128.
@@ -900,7 +900,8 @@ The default is 128.
.TP
.B ptp_minor_version
This option sets the minorVersionPTP in the common PTP message header.
-The default is 1.
+The default (specific to the installed linuxptp package) is 0.
+The default (specific to the installed linuxptp package) is 0, but setting
+\fBsa_file\fR forces the version to 1.
.TP
.B refclock_sock_address
diff --git a/ptp4l.c b/ptp4l.c
index ac2ef96..0d54d6c 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -194,6 +194,9 @@ int main(int argc, char *argv[])
sk_hwts_filter_mode = config_get_int(cfg, NULL, "hwts_filter");
ptp_hdr_ver = config_get_int(cfg, NULL, "ptp_minor_version");
+ /* Override patched default for spp, which requires PTPv2.1 */
+ if (ptp_hdr_ver < 1 && config_get_string(cfg, NULL, "sa_file"))
+ ptp_hdr_ver = 1;
ptp_hdr_ver = (ptp_hdr_ver << 4) | PTP_MAJOR_VERSION;
if (sad_create(cfg)) {

View File

@ -0,0 +1,302 @@
commit f0ea5436b60494a8c5dac8d39e2b62dd8cab6f53
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Oct 17 15:05:21 2024 +0200
pmc: Avoid race conditions in agent update.
The pmc_agent_update() function updates the subscription to
notifications and also the current UTC offset. It uses a timeout of 0
to avoid blocking. When the pmc client sends the first request, the
response from ptp4l may not come quickly enough to be received in the
same run_pmc() call. It then sends the other request and checks for the
response. If it is the response to the first request, it will be ignored.
The update works correctly only if both responses are quick enough to be
received in the same call, or are both slow enough that they are
received in the next call of the pmc_agent_update() function.
The function needs to be called a random number of times in order to
finish one update. If the mismatch between requests and responses
happened consistently, the agent would never reach the up-to-date state
and phc2sys would not enter the main synchronization loop.
Split the update into two phases, where only one thing is updated at a
time. The function now needs to be called at most 3 times to update both
the subscription and UTC offset, assuming it is not interrupted by
another request outside of the agent's update.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
diff --git a/pmc_agent.c b/pmc_agent.c
index 86b6ee6..d1a3367 100644
--- a/pmc_agent.c
+++ b/pmc_agent.c
@@ -37,6 +37,7 @@ struct pmc_agent {
struct pmc *pmc;
uint64_t pmc_last_update;
uint64_t update_interval;
+ int update_phase;
struct defaultDS dds;
bool dds_valid;
@@ -427,16 +428,27 @@ int pmc_agent_update(struct pmc_agent *node)
ts = tp.tv_sec * NS_PER_SEC + tp.tv_nsec;
if (ts - node->pmc_last_update >= node->update_interval) {
- if (node->stay_subscribed) {
- renew_subscription(node, 0);
- }
- if (!pmc_agent_query_utc_offset(node, 0)) {
+ switch (node->update_phase) {
+ case 0:
+ if (node->stay_subscribed &&
+ renew_subscription(node, 0))
+ break;
+ node->update_phase++;
+ /* Fall through */
+ case 1:
+ if (pmc_agent_query_utc_offset(node, 0))
+ break;
+ node->update_phase++;
+ /* Fall through */
+ default:
node->pmc_last_update = ts;
+ node->update_phase = 0;
+ break;
}
+ } else {
+ run_pmc(node, 0, -1, &msg);
}
- run_pmc(node, 0, -1, &msg);
-
return 0;
}
commit 2ceb8289b26e98f9f2179f021aa153db28c31dcf
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Oct 17 15:05:22 2024 +0200
phc2sys: Wait until pmc agent is subscribed.
When phc2sys is configured with multiple domains, different domains may
have their pmc agent subscribed after different number of calls of the
pmc_agent_update() function depending on how quickly responses from
ptp4l are received. If one domain triggers reconfiguration and the other
domain does not have its agent subscribed yet, it will not have any of
its clocks synchronized until a port changes state and triggers another
reconfiguration of the domain.
To avoid this problem, wait for each domain to have its agent subscribed
before entering the main synchronization loop. Use a 10ms update
interval to speed up the start of phc2sys.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
diff --git a/phc2sys.c b/phc2sys.c
index 6113539..47e896e 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -962,6 +962,12 @@ static int auto_init_ports(struct domain *domain)
return -1;
}
+ while (!pmc_agent_is_subscribed(domain->agent)) {
+ usleep(10000);
+ if (pmc_agent_update(domain->agent) < 0)
+ return -1;
+ }
+
for (i = 1; i <= number_ports; i++) {
err = pmc_agent_query_port_properties(domain->agent, 1000, i,
&state, &timestamping,
commit 5f37c1609d4a21daf7f7c12ae6f3fee327c03c3f
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Oct 24 15:24:07 2024 +0200
phc2sys: Keep clocks in command-line or ptp4l order.
When adding a new clock to the domain, add it to the end of the list to
keep them in the same order as specified on the command line or the port
order of ptp4l.
This will be needed by new code in the domain reconfiguration expecting
the order of reinitialized clocks to be the same as in which they were
added to the domain.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
diff --git a/phc2sys.c b/phc2sys.c
index 47e896e..bf36c38 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -161,7 +161,7 @@ static struct servo *servo_add(struct domain *domain,
static struct clock *clock_add(struct domain *domain, const char *device,
int phc_index)
{
- struct clock *c;
+ struct clock *c, *c2;
clockid_t clkid = CLOCK_INVALID;
char phc_device[19];
@@ -217,7 +217,19 @@ static struct clock *clock_add(struct domain *domain, const char *device,
c->sysoff_method = sysoff_probe(CLOCKID_TO_FD(clkid),
domain->phc_readings);
- LIST_INSERT_HEAD(&domain->clocks, c, list);
+ /* Add the clock to the end of the list to keep them in the
+ command-line or ptp4l order */
+ if (LIST_EMPTY(&domain->clocks)) {
+ LIST_INSERT_HEAD(&domain->clocks, c, list);
+ } else {
+ LIST_FOREACH(c2, &domain->clocks, list) {
+ if (LIST_NEXT(c2, list))
+ continue;
+ LIST_INSERT_AFTER(c2, c, list);
+ break;
+ }
+ }
+
return c;
}
commit 11f06a29e6cb34104785435274e3673dd72970e0
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Oct 24 15:24:08 2024 +0200
phc2sys: Allow static sink clocks in automatic mode.
Allow the -c option to be used together with the -a option. Add the
specified clocks to the first domain, where they will stay in the master
state and be synchronized when a source is available in the same domain
or other domains.
Mark the clocks added by -c as static and skip them in the domain
reconfiguration if they duplicate a clock following a ptp4l port.
A use case is synchronization of clocks of backup interfaces in an
active-backup bond to minimize the observed offset when the active
interface is switched. ptp4l tracks the active interface, which is
followed by the automatic mode of phc2sys. All interfaces included in
the bond are specified by the -c option to keep them all synchronized to
the same source. The interface which duplicates the current active
interface provided by ptp4l is skipped.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/phc2sys.8 b/phc2sys.8
index dd97a70..762a1b1 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -117,10 +117,13 @@ should no longer be used.
.TP
.BI \-c " device"
Specify the time sink by device (e.g. /dev/ptp1) or interface (e.g. eth1) or
-by name. The default is CLOCK_REALTIME (the system clock). Not compatible
-with the
+by name. If used together with the
.B \-a
-option. This option may be given up to 128 times.
+option, it is an additional sink clock added to the clocks provided by the
+first ptp4l instance (if
+.B \-z
+is specified multiple times). Duplicated clocks are allowed. The default is
+CLOCK_REALTIME (the system clock). This option may be given up to 128 times.
.TP
.BI \-E " servo"
Specify which clock servo should be used. Valid values are pi for a PI
diff --git a/phc2sys.c b/phc2sys.c
index bf36c38..d09cb53 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -79,6 +79,7 @@ struct clock {
int dest_only;
int state;
int new_state;
+ int static_state;
int sync_offset;
int leap_set;
int utc_offset_set;
@@ -391,6 +392,18 @@ static struct clock *find_dst_clock(struct domain *domain,
return c;
}
+static struct clock *find_nonstatic_clock(struct domain *domain,
+ int phc_index)
+{
+ struct clock *c = NULL;
+ LIST_FOREACH(c, &domain->clocks, list) {
+ if (!c->static_state && c->phc_index == phc_index) {
+ break;
+ }
+ }
+ return c;
+}
+
static int reconfigure_domain(struct domain *domain)
{
struct clock *c, *src = NULL, *dup = NULL;
@@ -422,6 +435,17 @@ static int reconfigure_domain(struct domain *domain)
c->new_state = 0;
}
+ /* Ignore the clock if its state is not following ptp4l and has
+ the same PHC index as a clock that is following ptp4l */
+ if (c->static_state) {
+ dup = find_nonstatic_clock(domain, c->phc_index);
+ if (dup) {
+ pr_info("skipping static %s: %s has the same clock",
+ c->device, dup->device);
+ continue;
+ }
+ }
+
switch (c->state) {
case PS_FAULTY:
case PS_DISABLED:
@@ -436,6 +460,8 @@ static int reconfigure_domain(struct domain *domain)
dst_cnt++;
LIST_INSERT_HEAD(&domain->dst_clocks,
c, dst_list);
+ if (c->sanity_check)
+ clockcheck_reset(c->sanity_check);
} else {
pr_info("skipping %s: %s has the same clock "
"and is already selected",
@@ -1128,6 +1154,7 @@ static int phc2sys_static_dst_configuration(struct domain *domain,
return -1;
}
dst->state = PS_MASTER;
+ dst->static_state = 1;
LIST_INSERT_HEAD(&domain->dst_clocks, dst, dst_list);
return 0;
@@ -1407,7 +1434,7 @@ int main(int argc, char *argv[])
dst_names[dst_cnt++] = "CLOCK_REALTIME";
}
- if (autocfg && (src_name || dst_cnt > 0 || hardpps_configured(pps_fd) ||
+ if (autocfg && (src_name || hardpps_configured(pps_fd) ||
wait_sync || settings.forced_sync_offset)) {
fprintf(stderr,
"autoconfiguration cannot be mixed with manual config options.\n");
@@ -1506,6 +1533,14 @@ int main(int argc, char *argv[])
if (auto_init_ports(&domains[i]) < 0)
goto end;
}
+
+ for (i = 0; i < dst_cnt; i++) {
+ r = phc2sys_static_dst_configuration(&domains[0],
+ dst_names[i]);
+ if (r)
+ goto end;
+ }
+
r = do_loop(domains, n_domains);
goto end;
}

View File

@ -1,26 +0,0 @@
commit b421a4c66ce636adff150dd1aa8eafa981c2693d
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Wed Jan 3 14:45:51 2024 +0100
pmc: Allow missing values in SUBSCRIBE_EVENTS_NP command.
Don't require all supported notifications to be specified in the command
for compatibility with older scripts.
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/pmc_common.c b/pmc_common.c
index 62e34a6..b88cfc2 100644
--- a/pmc_common.c
+++ b/pmc_common.c
@@ -310,8 +310,8 @@ static void do_set_action(struct pmc *pmc, int action, int index, char *str)
onoff_port_state,
onoff_time_status,
onoff_parent_data_set);
- if (cnt != 4) {
- fprintf(stderr, "%s SET needs 4 values\n",
+ if (cnt < 2) {
+ fprintf(stderr, "%s SET needs at least 2 values\n",
idtab[index].name);
break;
}

View File

@ -0,0 +1,85 @@
commit 77504ea63484dbc0c78b1ef58b29f06ced517223
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Wed Sep 25 14:16:16 2024 +0200
udp: Fix port-specific ptp/p2p_dst_ipv4 configuration.
If different ports are configured with a different ptp_dst_ipv4 or
p2p_dst_ipv4 address, only the last port in the configuration works
correctly. This is caused by a global variable holding the
destination address for all ports using the udp transport.
Move the address to the udp structure to avoid the conflict between
different ports, same as when port-specific scope in udp6 was fixed
in commit a48666bee3dd ("udp6: Make mc6_addr transport-local").
Fixes: 8a26c94cc88e ("udp+udp6: Make IP addresses configurable.")
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
diff --git a/udp.c b/udp.c
index 38d0ec4..c9b5f39 100644
--- a/udp.c
+++ b/udp.c
@@ -44,6 +44,7 @@ struct udp {
struct transport t;
struct address ip;
struct address mac;
+ struct in_addr mcast_addr[2];
};
static int mcast_bind(int fd, int index)
@@ -146,8 +147,6 @@ no_socket:
enum { MC_PRIMARY, MC_PDELAY };
-static struct in_addr mcast_addr[2];
-
static int udp_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type ts_type)
{
@@ -165,22 +164,22 @@ static int udp_open(struct transport *t, struct interface *iface,
sk_interface_addr(name, AF_INET, &udp->ip);
str = config_get_string(t->cfg, name, "ptp_dst_ipv4");
- if (!inet_aton(str, &mcast_addr[MC_PRIMARY])) {
+ if (!inet_aton(str, &udp->mcast_addr[MC_PRIMARY])) {
pr_err("invalid ptp_dst_ipv4 %s", str);
return -1;
}
str = config_get_string(t->cfg, name, "p2p_dst_ipv4");
- if (!inet_aton(str, &mcast_addr[MC_PDELAY])) {
+ if (!inet_aton(str, &udp->mcast_addr[MC_PDELAY])) {
pr_err("invalid p2p_dst_ipv4 %s", str);
return -1;
}
- efd = open_socket(name, mcast_addr, EVENT_PORT, ttl);
+ efd = open_socket(name, udp->mcast_addr, EVENT_PORT, ttl);
if (efd < 0)
goto no_event;
- gfd = open_socket(name, mcast_addr, GENERAL_PORT, ttl);
+ gfd = open_socket(name, udp->mcast_addr, GENERAL_PORT, ttl);
if (gfd < 0)
goto no_general;
@@ -223,6 +222,7 @@ static int udp_send(struct transport *t, struct fdarray *fda,
enum transport_event event, int peer, void *buf, int len,
struct address *addr, struct hw_timestamp *hwts)
{
+ struct udp *udp = container_of(t, struct udp, t);
struct address addr_buf;
unsigned char junk[1600];
ssize_t cnt;
@@ -243,8 +243,8 @@ static int udp_send(struct transport *t, struct fdarray *fda,
if (!addr) {
memset(&addr_buf, 0, sizeof(addr_buf));
addr_buf.sin.sin_family = AF_INET;
- addr_buf.sin.sin_addr = peer ? mcast_addr[MC_PDELAY] :
- mcast_addr[MC_PRIMARY];
+ addr_buf.sin.sin_addr = peer ? udp->mcast_addr[MC_PDELAY] :
+ udp->mcast_addr[MC_PRIMARY];
addr_buf.len = sizeof(addr_buf.sin);
addr = &addr_buf;
}

View File

@ -0,0 +1,57 @@
commit b2ceafdd8e4cde6c0cef67373006049b12f45c4a
Author: Miroslav Lichvar <mlichvar@redhat.com>
Date: Thu Apr 28 14:23:57 2022 +0200
timemaster: Check for RH-specific kernel with vclock support.
diff --git a/timemaster.8 b/timemaster.8
index bc0b5b6..50699d6 100644
--- a/timemaster.8
+++ b/timemaster.8
@@ -104,7 +104,7 @@ Enable or disable synchronization with virtual clocks. If enabled,
needed by configured PTP domains. This enables hardware time stamping for
multiple \fBptp4l\fR instances using the same network interface. The default
value is -1, which enables the virtual clocks if running on Linux 5.18 or
-later.
+later, or the EL9-specific kernel-5.14.0-106 or later release.
.SS [ntp_server address]
diff --git a/timemaster.c b/timemaster.c
index fab71fc..05f0af4 100644
--- a/timemaster.c
+++ b/timemaster.c
@@ -546,6 +546,23 @@ static int check_kernel_version(int version, int patch)
return 0;
}
+static int check_rh_kernel_version(const char *el, int version, int patch,
+ int sub, int release)
+{
+ struct utsname uts;
+ int v, p, sp, r;
+
+ if (uname(&uts) < 0)
+ return 1;
+ if (!strstr(uts.release, el))
+ return 1;
+ if (sscanf(uts.release, "%d.%d.%d-%d", &v, &p, &sp, &r) < 4)
+ return 1;
+ if (version != v || patch != p || sub != sp || release > r)
+ return 1;
+ return 0;
+}
+
static struct timemaster_config *config_parse(char *path)
{
struct timemaster_config *config = xcalloc(1, sizeof(*config));
@@ -621,7 +638,8 @@ static struct timemaster_config *config_parse(char *path)
fclose(f);
if (config->use_vclocks < 0)
- config->use_vclocks = !check_kernel_version(5, 18);
+ config->use_vclocks = !check_kernel_version(5, 18) ||
+ !check_rh_kernel_version(".el9.", 5, 14, 0, 106);
if (section_name)
free(section_name);

14
SOURCES/ptp4l.conf Normal file
View File

@ -0,0 +1,14 @@
# For more information about this file, see the ptp4l(8) man page.
# Examples are available in /usr/share/doc/linuxptp/configs.
[global]
domainNumber 0
slaveOnly 1
time_stamping hardware
tx_timestamp_timeout 1
logging_level 6
summary_interval 0
[eth0]
network_transport UDPv4
hybrid_e2e 0

View File

@ -14,18 +14,11 @@ ntp_program chronyd
[chrony.conf]
include /etc/chrony.conf
[ntp.conf]
includefile /etc/ntp.conf
[ptp4l.conf]
[chronyd]
path /usr/sbin/chronyd
[ntpd]
path /usr/sbin/ntpd
options -u ntp:ntp -g
[phc2sys]
path /usr/sbin/phc2sys

View File

@ -1,41 +1,42 @@
%global _hardened_build 1
%global testsuite_ver bf8ead
%global clknetsim_ver 5d1dc0
%global testsuite_ver d27dbd
%global clknetsim_ver 64df92
Name: linuxptp
Version: 4.2
Version: 4.4
Release: 1%{?dist}
Summary: PTP implementation for Linux
Group: System Environment/Base
License: GPLv2+
URL: http://linuxptp.sourceforge.net/
License: GPL-2.0-or-later
URL: https://www.linuxptp.org/
Source0: https://downloads.sourceforge.net/%{name}/%{name}-%{version}.tgz
Source0: https://downloads.nwtime.org/%{name}/%{name}-%{version}.tgz
Source1: phc2sys.service
Source2: ptp4l.service
Source3: timemaster.service
Source4: timemaster.conf
Source5: ptp4l.conf
# external test suite
Source10: https://github.com/mlichvar/linuxptp-testsuite/archive/%{testsuite_ver}/linuxptp-testsuite-%{testsuite_ver}.tar.gz
# simulator for test suite
Source11: https://github.com/mlichvar/clknetsim/archive/%{clknetsim_ver}/clknetsim-%{clknetsim_ver}.tar.gz
# allow old syntax of SET SUBSCRIBE_EVENTS_NP command
Patch1: linuxptp-subscribe.patch
# disable warning messages about deprecated options
Patch2: linuxptp-deprecated.patch
# revert default PTP version to 2.0 for better compatibility
Patch3: linuxptp-ptpver.patch
# limit unicast message rate per address and grant duration
Patch4: linuxptp-ucastrate.patch
# fix ts2phc to handle large NMEA delay
Patch5: linuxptp-nmeadelay.patch
# fix loading and reloading of leapfile
Patch6: linuxptp-lstab.patch
# fix port-specific ptp/p2p_dst_ipv4 configuration
Patch5: linuxptp-udpaddr.patch
# support static sink clocks in phc2sys automatic mode
Patch6: linuxptp-staticauto.patch
# don't require -O option without -a and -w in phc2sys
Patch7: linuxptp-nowait.patch
# check for EL-specific kernels with vclock support
Patch12: linuxptp-vclock.patch
BuildRequires: kernel-headers > 4.18.0-87
BuildRequires: systemd
BuildRequires: gcc gcc-c++ gnutls-devel make systemd
%{?systemd_requires}
@ -49,11 +50,15 @@ Supporting legacy APIs and other platforms is not a goal.
%prep
%setup -q -a 10 -a 11 -n %{name}-%{!?gitfullver:%{version}}%{?gitfullver}
%autopatch -p1
# disable nettle support in favor of gnutls
sed -i 's|find .*"nettle"|true|' incdefs.sh
mv linuxptp-testsuite-%{testsuite_ver}* testsuite
mv clknetsim-%{clknetsim_ver}* testsuite/clknetsim
%build
make %{?_smp_mflags} \
%{make_build} \
EXTRA_CFLAGS="$RPM_OPT_FLAGS" \
EXTRA_LDFLAGS="$RPM_LD_FLAGS"
@ -61,11 +66,10 @@ make %{?_smp_mflags} \
%makeinstall
mkdir -p $RPM_BUILD_ROOT{%{_sysconfdir}/sysconfig,%{_unitdir},%{_mandir}/man5}
install -m 644 -p configs/default.cfg $RPM_BUILD_ROOT%{_sysconfdir}/ptp4l.conf
install -m 644 -p %{SOURCE1} %{SOURCE2} %{SOURCE3} $RPM_BUILD_ROOT%{_unitdir}
install -m 644 -p %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}
install -m 644 -p %{SOURCE4} %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}
echo 'OPTIONS="-f /etc/ptp4l.conf -i eth0"' > \
echo 'OPTIONS="-f /etc/ptp4l.conf"' > \
$RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ptp4l
echo 'OPTIONS="-a -r"' > $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/phc2sys
@ -79,7 +83,7 @@ find configs -type f ! -name '*.cfg' -delete
cd testsuite
# set random seed to get deterministic results
export CLKNETSIM_RANDOM_SEED=26743
make %{?_smp_mflags} -C clknetsim
%{make_build} -C clknetsim
PATH=..:$PATH ./run
%post
@ -113,58 +117,114 @@ PATH=..:$PATH ./run
%{_mandir}/man8/*.8*
%changelog
* Thu Feb 22 2024 Miroslav Lichvar <mlichvar@redhat.com> 4.2-1
- update to 4.2 (RHEL-21326 RHEL-21328 RHEL-21329)
- fix ts2phc to handle large NMEA delay (RHEL-23278)
* Tue Dec 03 2024 Miroslav Lichvar <mlichvar@redhat.com> 4.4-1
- update to 4.4 (RHEL-58213 RHEL-57040)
- fix port-specific ptp/p2p_dst_ipv4 configuration (RHEL-60027)
- support static sink clocks in phc2sys automatic mode (RHEL-62864)
- don't require -O option without -a and -w in phc2sys (RHEL-69138)
* Thu Jul 25 2024 Miroslav Lichvar <mlichvar@redhat.com> 4.2-3
- rework NMEA delay patch to fix PPS edge rejection (RHEL-39387)
- fix ts2phc to correctly handle leap seconds (RHEL-40216)
- fix ts2phc to reset NMEA parser after RMC message (RHEL-40947)
- add options to configure multicast IP addresses (RHEL-31178)
- add holdover support to ts2phc (RHEL-50216)
* Thu Feb 22 2024 Miroslav Lichvar <mlichvar@redhat.com> 4.2-2
- fix loading and reloading of leapfile
* Wed May 03 2023 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-6
- clear pending errors on sockets (#2192560)
* Tue Jan 30 2024 Miroslav Lichvar <mlichvar@redhat.com> 4.2-1
- update to 4.2 (RHEL-2026 RHEL-2342 RHEL-12182 RHEL-15929)
- fix ts2phc to handle large NMEA delay (RHEL-23208)
* Wed Apr 12 2023 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-5
- handle EINTR when waiting for transmit timestamp (#2123224)
* Wed May 03 2023 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-9
- clear pending errors on sockets (#2192559)
* Mon Mar 20 2023 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-4
- don't re-arm fault clearing timer on unrelated netlink events (#2174900)
* Mon Mar 20 2023 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-8
- don't switch from system clock to PHC with SW timestamping (#2179041)
* Wed Jun 29 2022 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-3
- handle PHC read failing with EBUSY in phc2sys (#2079129)
* Thu Mar 09 2023 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-7
- don't re-arm fault clearing timer on unrelated netlink events (#2172650)
* Mon Nov 01 2021 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-2
- make sanity clock check more reliable (#2007281)
* Thu Jan 05 2023 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-6
- add support for VLAN over bond (#2120521)
- handle EINTR when waiting for transmit timestamp (#2128786)
- check for unexpected changes in frequency offset (#2150815)
* Mon Jul 26 2021 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-1
- update to 3.1.1 (#1895005 CVE-2021-3571)
- add read-only UDS port (#1929797)
- add option to set clockClass threshold (#1980386)
- don't repeat some log messages in multi-port configuration (#1980377)
- increase default TX timestamp timeout to 10 ms (#1977136)
* Thu Jul 28 2022 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-5
- disable PHC switch with vclocks (#2066452)
* Thu Jun 24 2021 Miroslav Lichvar <mlichvar@redhat.com> 2.0-5.el8_4.1
- validate length of forwarded messages (CVE-2021-3570)
* Thu Jun 30 2022 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-4
- handle PHC read failing with EBUSY in phc2sys (#2102568)
* Mon Apr 27 2020 Miroslav Lichvar <mlichvar@redhat.com> 2.0-5
- fix sample timestamps when synchronizing PHC to system clock (#1787376)
- fix handling of zero-length messages (#1827275)
* Thu Jun 09 2022 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-3
- add support for virtual clocks (#2067310)
- make sanity clock check more reliable (#2079893)
* Thu May 16 2019 Miroslav Lichvar <mlichvar@redhat.com> 2.0-4
- rebuild with enabled gating (#1680888)
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 3.1.1-2
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Wed May 15 2019 Miroslav Lichvar <mlichvar@redhat.com> 2.0-3
- add support for active-backup team interface (#1685467)
- add support for more accurate synchronization to phc2sys (#1677217)
- add hwts_filter option to ptp4l (#1708554)
- limit unicast message rate per address and grant duration (#1707395)
- fix comparing of unicast addresses (#1707395)
- fix building with new kernel headers (#1707395)
- update testsuite (#1707395)
- don't leak memory when allocation fails (#1707395)
* Mon Aug 02 2021 Miroslav Lichvar <mlichvar@redhat.com> 3.1.1-1
- update to 3.1.1 (#1979954 CVE-2021-3570 CVE-2021-3571)
- add read-only UDS port
- add option to set clockClass threshold
- don't repeat some log messages in multi-port configuration
- increase default TX timestamp timeout to 10 ms
- limit unicast message rate per address and grant duration
* Tue Jun 22 2021 Mohan Boddu <mboddu@redhat.com> - 3.1-5
- Rebuilt for RHEL 9 BETA for openssl 3.0
Related: rhbz#1971065
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 3.1-4
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
* Thu Feb 25 2021 Miroslav Lichvar <mlichvar@redhat.com> 3.1-3
- fix handling of zero-length messages
- minimize default configuration
- remove obsolete build requirement
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
* Tue Sep 29 2020 Miroslav Lichvar <mlichvar@redhat.com> 3.1-1
- update to 3.1
* Mon Jul 27 2020 Miroslav Lichvar <mlichvar@redhat.com> 3.0-1
- update to 3.0
* Mon Feb 03 2020 Miroslav Lichvar <mlichvar@redhat.com> 2.0-7.20191225gite05809
- update to 20191225gite05809
- fix testing with new glibc
* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-6.20190912git48e605
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
* Wed Sep 25 2019 Miroslav Lichvar <mlichvar@redhat.com> 2.0-5.20190912git48e605
- update to 20190912git48e605
* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 2.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Tue Nov 13 2018 Miroslav Lichvar <mlichvar@redhat.com> 2.0-2
- start ptp4l, timemaster and phc2sys after network-online target (#1632282)
- start ptp4l, timemaster and phc2sys after network-online target
- fix building with new kernel headers
* Mon Aug 13 2018 Miroslav Lichvar <mlichvar@redhat.com> 2.0-1
- update to 2.0 (#1614300)
- update to 2.0
* Thu Aug 09 2018 Miroslav Lichvar <mlichvar@redhat.com> 2.0-0.1.20180805gita27407
- update to 20180805gita27407
* Mon Jul 16 2018 Miroslav Lichvar <mlichvar@redhat.com> 1.9.2-3
- add gcc and gcc-c++ to build requirements
* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.9.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Mon Apr 09 2018 Miroslav Lichvar <mlichvar@redhat.com> 1.9.2-1
- update to 1.9.2