| [chrony-dev] [RFC PATCH 5/9] ntp: print port of NTP sources in logs and dump file names |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [RFC PATCH 5/9] ntp: print port of NTP sources in logs and dump file names
- From: Wojtek Wasko <wwasko@xxxxxxxxxx>
- Date: Thu, 12 Nov 2026 17:22:34 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QubTHggYBThamccTkrOqrSnPr25wFPLs3+JWS7jwuIM=; b=fvN+v9BbZIj/oGUmXE7A1VpAwNqhwURPqCMH6hGL1xFCJ2kjMFmh/A/z2vlw98a/0Zo01HUDw1T1AwWvNxCBtDicppKFtI0lTg1atAQAtSmz9trL3d0ofL/XiBjVAoXwKWkPDaQ7SgnT0oxBvSHp89u3cDbIT9gAE4QF6u16vHAHfnUPKvvxGyKdCR9KSx6OOr6hMm/SYxqEhPzVC1My97z99IA5JwTe1IbQf0ZA5zk1Y6mTUii7quhph2X4KxPa07KFR7KC7jGjgFoWznSkVDfKtq1/+V7YGGzXpjU1rWynQYlD88d8CSEWcIaWP/Ylp009NsMXEXA60l4WEAGVMg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UJyuVg1XxD2MO7eIUDZfBV3Hz/7SIxIer/Gx8YLEj55FmPkFgpQSGy7Op0EbWx9T+4qmAC1YIUqowflFqmUBnqCEkwGoOgC/SY3JQ+mT7zAN4LEO/VNAZce4qZyLf9RgvlY71rjdd8sydCTjNIGbVhmmjLqP+EfnlCTobB/xg747b35F91NLcnKXMkAoQ8gRN1vDtbmqwM5isf1OftSlGmwV2V9OkutOEfmcmbDlNIfxZkIYZ0syRBcSNK53z9K2VR30LmkKWcGa/Jx2huqix6zcKxWOsr16wJgvQTAzvs2IhsicqOs4oE7pv0XcEwaYBnnqd4XI+oplSlEXF84yZQ==
- Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com;
- Cc: Wojtek Wasko <wwasko@xxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QubTHggYBThamccTkrOqrSnPr25wFPLs3+JWS7jwuIM=; b=JBmLqPY7cQ+RQGwSyVEz7CAWIKe8X4BiFaGSALhfLeD9OP8IG6TT2Pjf7pSG9qvcrlAWR2L9MLxpttjE3yLR0XNK2uLXAimlkpRJwEYmrJEPn8mfiO4NGt9lZ3vGNcPQN/u9/U5B+0VHo0PEOIizLgQNBS6CpCcHrH5h4Tm6IOZIkk1ALFs966z6tqjInBDA6NM9IZf5C+TdFLPL6247OufIqThkp/wVUQRp5aELK5EehnPHY9lSj2yCWv+M/LWYqylj1eURCaxc+kE+SbVqwO4IeGXWdhaJ/+++Rqq4oUGCclFha9EWU0+MgQkFArUc81LgJrn9egdFo3ehrZ9xmg==
NTP sources are identified by their IP address in log messages, in the
measurements, statistics, selection, and tracking logs, and in names of
dump files. Sources specified by name are identified by the resolved
address, which some log messages follow with the name in parentheses.
Sources with the same address and different ports, e.g. using NTP and
NTP over PTP, cannot be distinguished in the logs and they would save
their state to the same dump file.
Include the port in the address if it is not the standard NTP port,
e.g. 192.0.2.1:319 or [2001:db8::1]:319. Logs and dump files of sources
using the standard port don't change. Sources using another port get a
new name of the dump file, so their existing dump file is not loaded
after an upgrade. Accept the new names in SRC_RemoveDumpFiles().
---
ntp_core.c | 26 +++++++++++++-------------
ntp_sources.c | 8 ++++----
reference.c | 3 ++-
sources.c | 9 +++++----
sourcestats.c | 4 ++--
test/unit/sources.c | 3 +++
6 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/ntp_core.c b/ntp_core.c
index 81886de..e82e6cf 100644
--- a/ntp_core.c
+++ b/ntp_core.c
@@ -1819,7 +1819,7 @@ check_sync_loop(NCR_Instance inst, NTP_Packet *message, NTP_Local_Address *local
UTI_TimespecToNtp64(&our_ref_time, &ntp_ref_time, NULL);
if (UTI_CompareNtp64(&message->reference_ts, &ntp_ref_time) == 0) {
- DEBUG_LOG("Source %s is me", UTI_IPToString(&inst->remote_addr.ip_addr));
+ DEBUG_LOG("Source %s is me", UTI_NtpAddressToString(&inst->remote_addr));
return 0;
}
}
@@ -1891,7 +1891,7 @@ process_saved_response(NCR_Instance inst)
SCH_RemoveTimeout(inst->saved_response->timeout_id);
inst->saved_response->timeout_id = 0;
- DEBUG_LOG("Processing saved response from %s", UTI_IPToString(&inst->remote_addr.ip_addr));
+ DEBUG_LOG("Processing saved response from %s", UTI_NtpAddressToString(&inst->remote_addr));
process_response(inst, 1, &inst->saved_response->local_addr, &inst->saved_response->rx_ts,
&inst->saved_response->message, &inst->saved_response->info);
}
@@ -2427,7 +2427,7 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
if (kod_rate) {
LOG(LOGS_WARN, "Received KoD RATE from %s",
- UTI_IPToString(&inst->remote_addr.ip_addr));
+ UTI_NtpAddressToString(&inst->remote_addr));
/* Back off for a while and stop ongoing burst */
delay_time += 4 * UTI_Log2ToDouble(inst->local_poll);
@@ -2477,7 +2477,7 @@ process_response(NCR_Instance inst, int saved, NTP_Local_Address *local_addr,
if (logfileid != -1 && (log_raw_measurements || synced_packet)) {
LOG_FileWrite(logfileid, "%s %-15s %1c %2d %1d%1d%1d %1d%1d%1d %1d%1d%1d%d %2d %2d %4.2f %10.3e %10.3e %10.3e %10.3e %10.3e %08"PRIX32" %1d%1c %1c %1c",
UTI_TimeToLogForm(sample.time.tv_sec),
- UTI_IPToString(&inst->remote_addr.ip_addr),
+ UTI_NtpAddressToString(&inst->remote_addr),
leap_chars[pkt_leap],
message->stratum,
test1, test2, test3, test5, test6, test7, testA, testB, testC, testD,
@@ -2962,7 +2962,7 @@ NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity)
is_online = inst->opmode == MD_ONLINE || inst->opmode == MD_BURST_WAS_ONLINE;
if (was_online != is_online)
LOG(LOGS_INFO, "Source %s %s",
- UTI_IPToString(&inst->remote_addr.ip_addr), is_online ? "online" : "offline");
+ UTI_NtpAddressToString(&inst->remote_addr), is_online ? "online" : "offline");
}
/* ================================================== */
@@ -2983,7 +2983,7 @@ NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll)
if (new_minpoll < MIN_POLL || new_minpoll > MAX_POLL)
return;
inst->minpoll = new_minpoll;
- LOG(LOGS_INFO, "Source %s new minpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_minpoll);
+ LOG(LOGS_INFO, "Source %s new minpoll %d", UTI_NtpAddressToString(&inst->remote_addr), new_minpoll);
if (inst->maxpoll < inst->minpoll)
NCR_ModifyMaxpoll(inst, inst->minpoll);
}
@@ -2996,7 +2996,7 @@ NCR_ModifyMaxpoll(NCR_Instance inst, int new_maxpoll)
if (new_maxpoll < MIN_POLL || new_maxpoll > MAX_POLL)
return;
inst->maxpoll = new_maxpoll;
- LOG(LOGS_INFO, "Source %s new maxpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_maxpoll);
+ LOG(LOGS_INFO, "Source %s new maxpoll %d", UTI_NtpAddressToString(&inst->remote_addr), new_maxpoll);
if (inst->minpoll > inst->maxpoll)
NCR_ModifyMinpoll(inst, inst->maxpoll);
}
@@ -3008,7 +3008,7 @@ NCR_ModifyMaxdelay(NCR_Instance inst, double new_max_delay)
{
inst->max_delay = CLAMP(0.0, new_max_delay, MAX_MAXDELAY);
LOG(LOGS_INFO, "Source %s new maxdelay %f",
- UTI_IPToString(&inst->remote_addr.ip_addr), inst->max_delay);
+ UTI_NtpAddressToString(&inst->remote_addr), inst->max_delay);
}
/* ================================================== */
@@ -3018,7 +3018,7 @@ NCR_ModifyMaxdelayratio(NCR_Instance inst, double new_max_delay_ratio)
{
inst->max_delay_ratio = CLAMP(0.0, new_max_delay_ratio, MAX_MAXDELAYRATIO);
LOG(LOGS_INFO, "Source %s new maxdelayratio %f",
- UTI_IPToString(&inst->remote_addr.ip_addr), inst->max_delay_ratio);
+ UTI_NtpAddressToString(&inst->remote_addr), inst->max_delay_ratio);
}
/* ================================================== */
@@ -3028,7 +3028,7 @@ NCR_ModifyMaxdelaydevratio(NCR_Instance inst, double new_max_delay_dev_ratio)
{
inst->max_delay_dev_ratio = CLAMP(0.0, new_max_delay_dev_ratio, MAX_MAXDELAYDEVRATIO);
LOG(LOGS_INFO, "Source %s new maxdelaydevratio %f",
- UTI_IPToString(&inst->remote_addr.ip_addr), inst->max_delay_dev_ratio);
+ UTI_NtpAddressToString(&inst->remote_addr), inst->max_delay_dev_ratio);
}
/* ================================================== */
@@ -3038,7 +3038,7 @@ NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum)
{
inst->min_stratum = new_min_stratum;
LOG(LOGS_INFO, "Source %s new minstratum %d",
- UTI_IPToString(&inst->remote_addr.ip_addr), new_min_stratum);
+ UTI_NtpAddressToString(&inst->remote_addr), new_min_stratum);
}
/* ================================================== */
@@ -3048,7 +3048,7 @@ NCR_ModifyOffset(NCR_Instance inst, double new_offset)
{
inst->offset_correction = new_offset;
LOG(LOGS_INFO, "Source %s new offset %f",
- UTI_IPToString(&inst->remote_addr.ip_addr), new_offset);
+ UTI_NtpAddressToString(&inst->remote_addr), new_offset);
}
/* ================================================== */
@@ -3058,7 +3058,7 @@ NCR_ModifyPolltarget(NCR_Instance inst, int new_poll_target)
{
inst->poll_target = MAX(1, new_poll_target);
LOG(LOGS_INFO, "Source %s new polltarget %d",
- UTI_IPToString(&inst->remote_addr.ip_addr), new_poll_target);
+ UTI_NtpAddressToString(&inst->remote_addr), new_poll_target);
}
/* ================================================== */
diff --git a/ntp_sources.c b/ntp_sources.c
index 2adf63f..1014fb7 100644
--- a/ntp_sources.c
+++ b/ntp_sources.c
@@ -364,7 +364,7 @@ log_source(SourceRecord *record, int addition, int once_per_pool)
pool = 1;
log_addr = 0;
} else {
- ip_str = UTI_IPToString(&record->remote_addr->ip_addr);
+ ip_str = UTI_NtpAddressToString(record->remote_addr);
pool = 0;
log_addr = strcmp(record->name, ip_str) != 0;
}
@@ -496,9 +496,9 @@ change_source_address(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr
rehash_records();
if (UTI_CompareIPs(&old_addr->ip_addr, &new_addr->ip_addr, NULL) != 0) {
- LOG(severity, "Source %s %s %s (%s)", UTI_IPToString(&old_addr->ip_addr),
+ LOG(severity, "Source %s %s %s (%s)", UTI_NtpAddressToString(old_addr),
replacement ? "replaced with" : "changed to",
- UTI_IPToString(&new_addr->ip_addr), name);
+ UTI_NtpAddressToString(new_addr), name);
} else {
LOG(severity, "Source %s (%s) changed port to %d",
UTI_IPToString(&new_addr->ip_addr), name, new_addr->port);
@@ -1255,7 +1255,7 @@ static void remove_pool_sources(int pool_id, int tentative, int unresolved)
continue;
DEBUG_LOG("removing %ssource %s", tentative ? "tentative " : "",
- UTI_IPToString(&record->remote_addr->ip_addr));
+ UTI_NtpAddressToString(record->remote_addr));
clean_source_record(record);
removed++;
diff --git a/reference.c b/reference.c
index e7c3427..1a3e4a9 100644
--- a/reference.c
+++ b/reference.c
@@ -566,7 +566,7 @@ write_log(struct timespec *now, int combined_sources, double freq,
"%s %-15s %2d %10.3f %10.3f %10.3e %1c %2d %10.3e %10.3e %10.3e %10.3e %10.3e",
UTI_TimeToLogForm(now->tv_sec),
our_ref_addr.ip_addr.family != IPADDR_UNSPEC ?
- UTI_IPToString(&our_ref_addr.ip_addr) : UTI_RefidToString(our_ref_id),
+ UTI_NtpAddressToString(&our_ref_addr) : UTI_RefidToString(our_ref_id),
our_stratum, freq, 1.0e6 * our_skew, offset,
are_we_synchronised ? 'N' : '?', combined_sources, offset_sd,
uncorrected_offset, our_root_delay, root_dispersion, max_error);
@@ -893,6 +893,7 @@ REF_SetUnsynchronised(void)
our_ref_addr.ip_addr.family = IPADDR_INET4;
our_ref_addr.ip_addr.addr.in4 = 0;
+ our_ref_addr.port = NTP_PORT;
our_stratum = 0;
if (are_we_synchronised)
diff --git a/sources.c b/sources.c
index f3b5c5f..9c46e1d 100644
--- a/sources.c
+++ b/sources.c
@@ -679,7 +679,7 @@ source_to_string(SRC_Instance inst)
{
switch (inst->type) {
case SRC_NTP:
- return UTI_IPToString(&inst->addr->ip_addr);
+ return UTI_NtpAddressToString(inst->addr);
case SRC_REFCLOCK:
return UTI_RefidToString(inst->ref_id);
default:
@@ -1520,7 +1520,8 @@ add_dispersion(double dispersion, void *anything)
static int
get_dumpfile(SRC_Instance inst, char *filename, size_t len)
{
- /* Use the IP address, or reference ID with reference clocks */
+ /* Use the IP address (with the port if not the NTP port),
+ or reference ID with reference clocks */
switch (inst->type) {
case SRC_NTP:
if (!UTI_IsIPReal(&inst->addr->ip_addr) ||
@@ -1659,7 +1660,7 @@ void
SRC_RemoveDumpFiles(void)
{
char pattern[PATH_MAX], name[64], *dumpdir, *s;
- IPAddr ip_addr;
+ IPSockAddr addr;
glob_t gl;
size_t i;
@@ -1682,7 +1683,7 @@ SRC_RemoveDumpFiles(void)
name[strlen(name) - 4] = '\0';
/* Check if it looks like name of an actual dump file */
- if (strncmp(name, "refid:", 6) && !UTI_StringToIP(name, &ip_addr))
+ if (strncmp(name, "refid:", 6) && !UTI_StringToIPSockAddr(name, &addr))
continue;
if (!UTI_RemoveFile(NULL, gl.gl_pathv[i], NULL))
diff --git a/sourcestats.c b/sourcestats.c
index a65e3b5..86891be 100644
--- a/sourcestats.c
+++ b/sourcestats.c
@@ -301,7 +301,7 @@ SST_AccumulateSample(SST_Stats inst, NTP_Sample *sample)
if (inst->n_samples &&
UTI_CompareTimespecs(&inst->sample_times[inst->last_sample], &sample->time) >= 0) {
LOG(LOGS_WARN, "Out of order sample detected, discarding history for %s",
- inst->addr ? UTI_IPToString(&inst->addr->ip_addr) : UTI_RefidToString(inst->refid));
+ inst->addr ? UTI_NtpAddressToString(inst->addr) : UTI_RefidToString(inst->refid));
SST_ResetInstance(inst);
}
@@ -586,7 +586,7 @@ SST_DoNewRegression(SST_Stats inst)
if (logfileid != -1) {
LOG_FileWrite(logfileid, "%s %-15s %10.3e %10.3e %10.3e %10.3e %10.3e %7.1e %3d %3d %3d %5.2f",
UTI_TimeToLogForm(inst->offset_time.tv_sec),
- inst->addr ? UTI_IPToString(&inst->addr->ip_addr) : UTI_RefidToString(inst->refid),
+ inst->addr ? UTI_NtpAddressToString(inst->addr) : UTI_RefidToString(inst->refid),
inst->std_dev,
inst->estimated_offset, inst->estimated_offset_sd,
inst->estimated_frequency, inst->skew, stress,
diff --git a/test/unit/sources.c b/test/unit/sources.c
index 9701c3b..8e3aadd 100644
--- a/test/unit/sources.c
+++ b/test/unit/sources.c
@@ -292,6 +292,9 @@ test_unit(void)
SRC_DEFAULT_MINSAMPLES, SRC_DEFAULT_MAXSAMPLES, 0.0, 1.0,
SRC_DEFAULT_MAXUNREACH);
+ TEST_CHECK(strcmp(source_to_string(srcs[0]), UTI_IPToString(&addrs[0].ip_addr)) == 0);
+ TEST_CHECK(strcmp(source_to_string(srcs[1]), UTI_IPSockAddrToString(&addrs[1])) == 0);
+
addrs[2] = addrs[0];
addrs[2].port = 319;
TEST_CHECK(SRC_ModifySelectOptions(&addrs[2], 0, SRC_SELECT_PREFER, SRC_SELECT_PREFER));
--
2.43.0
--
To unsubscribe email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "unsubscribe" in the subject.
For help email chrony-dev-request@xxxxxxxxxxxxxxxxxxxx with "help" in the subject.
Trouble? Email listmaster@xxxxxxxxxxxxxxxxxxxx.