From 1219f99935ca9597eb0e4f4c6039e536462cf1a6 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 9 Mar 2022 15:34:16 +0100 Subject: [PATCH] ntp: keep original source IP address When an added source is specified by IP address, save the original string instead of formatting a new string from the parsed address, which can be different (e.g. compressed vs expanded IPv6 address). This fixes the chronyc sourcename command and -N option to print the IP address exactly as it was specified in the configuration file or chronyc add command. --- ntp_sources.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntp_sources.c b/ntp_sources.c index 3077082..d46c211 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -353,7 +353,6 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type, record_lock = 1; record = get_record(slot); - assert(!name || !UTI_IsStringIP(name)); record->name = Strdup(name ? name : UTI_IPToString(&remote_addr->ip_addr)); record->data = NCR_CreateInstance(remote_addr, type, params, record->name); record->remote_addr = NCR_GetRemoteAddress(record->data); @@ -734,7 +733,8 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, /* If the name is an IP address, add the source with the address directly */ if (UTI_StringToIP(name, &remote_addr.ip_addr)) { remote_addr.port = port; - return NSR_AddSource(&remote_addr, type, params, conf_id); + return add_source(&remote_addr, name, type, params, INVALID_POOL, + get_next_conf_id(conf_id)); } /* Make sure the name is at least printable and has no spaces */