client: add option to print all sources

Add -a option to the sources and sourcestats commands to print all
sources, including those that don't have a resolved address yet. By
default, only sources that have a real address are printed for
compatibility. Remove the "210 Number of sources" messages to avoid
confusion. Also, modify the ntpdata command to always print only sources
with a resolved address.
This commit is contained in:
Miroslav Lichvar 2020-02-18 10:51:41 +01:00
parent a5110d3ed9
commit a24d2713cd
3 changed files with 47 additions and 26 deletions

View file

@ -1205,8 +1205,8 @@ give_help(void)
"Wait until synchronised in specified limits\0" "Wait until synchronised in specified limits\0"
"\0\0" "\0\0"
"Time sources:\0\0" "Time sources:\0\0"
"sources [-v]\0Display information about current sources\0" "sources [-a] [-v]\0Display information about current sources\0"
"sourcestats [-v]\0Display statistics about collected measurements\0" "sourcestats [-a] [-v]\0Display statistics about collected measurements\0"
"reselect\0Force reselecting synchronisation source\0" "reselect\0Force reselecting synchronisation source\0"
"reselectdist <dist>\0Modify reselection distance\0" "reselectdist <dist>\0Modify reselection distance\0"
"\0\0" "\0\0"
@ -1321,8 +1321,8 @@ command_name_generator(const char *text, int state)
}; };
const char *add_options[] = { "peer", "pool", "server", NULL }; const char *add_options[] = { "peer", "pool", "server", NULL };
const char *manual_options[] = { "on", "off", "delete", "list", "reset", NULL }; const char *manual_options[] = { "on", "off", "delete", "list", "reset", NULL };
const char *sources_options[] = { "-v", NULL }; const char *sources_options[] = { "-a", "-v", NULL };
const char *sourcestats_options[] = { "-v", NULL }; const char *sourcestats_options[] = { "-a", "-v", NULL };
static int list_index, len; static int list_index, len;
names[TAB_COMPLETE_BASE_CMDS] = base_commands; names[TAB_COMPLETE_BASE_CMDS] = base_commands;
@ -2089,12 +2089,21 @@ format_name(char *buf, int size, int trunc_dns, int ref, uint32_t ref_id,
/* ================================================== */ /* ================================================== */
static int static void
check_for_verbose_flag(char *line) parse_sources_options(char *line, int *all, int *verbose)
{ {
if (!csv_mode && !strcmp(line, "-v")) char *opt;
return 1;
return 0; *all = *verbose = 0;
while (*line) {
opt = line;
line = CPS_SplitWord(line);
if (!strcmp(opt, "-a"))
*all = 1;
else if (!strcmp(opt, "-v"))
*verbose = !csv_mode;
}
} }
/* ================================================== */ /* ================================================== */
@ -2128,17 +2137,15 @@ process_cmd_sources(char *line)
IPAddr ip_addr; IPAddr ip_addr;
uint32_t i, mode, n_sources; uint32_t i, mode, n_sources;
char name[256], mode_ch, state_ch; char name[256], mode_ch, state_ch;
int verbose; int all, verbose;
/* Check whether to output verbose headers */ parse_sources_options(line, &all, &verbose);
verbose = check_for_verbose_flag(line);
request.command = htons(REQ_N_SOURCES); request.command = htons(REQ_N_SOURCES);
if (!request_reply(&request, &reply, RPY_N_SOURCES, 0)) if (!request_reply(&request, &reply, RPY_N_SOURCES, 0))
return 0; return 0;
n_sources = ntohl(reply.data.n_sources.n_sources); n_sources = ntohl(reply.data.n_sources.n_sources);
print_info_field("210 Number of sources = %lu\n", (unsigned long)n_sources);
if (verbose) { if (verbose) {
printf("\n"); printf("\n");
@ -2164,6 +2171,9 @@ process_cmd_sources(char *line)
mode = ntohs(reply.data.source_data.mode); mode = ntohs(reply.data.source_data.mode);
UTI_IPNetworkToHost(&reply.data.source_data.ip_addr, &ip_addr); UTI_IPNetworkToHost(&reply.data.source_data.ip_addr, &ip_addr);
if (!all && ip_addr.family == IPADDR_ID)
continue;
format_name(name, sizeof (name), 25, format_name(name, sizeof (name), 25,
mode == RPY_SD_MD_REF && ip_addr.family == IPADDR_INET4, mode == RPY_SD_MD_REF && ip_addr.family == IPADDR_INET4,
ip_addr.addr.in4, 1, &ip_addr); ip_addr.addr.in4, 1, &ip_addr);
@ -2233,18 +2243,17 @@ process_cmd_sourcestats(char *line)
CMD_Request request; CMD_Request request;
CMD_Reply reply; CMD_Reply reply;
uint32_t i, n_sources; uint32_t i, n_sources;
int verbose = 0; int all, verbose;
char name[256]; char name[256];
IPAddr ip_addr; IPAddr ip_addr;
verbose = check_for_verbose_flag(line); parse_sources_options(line, &all, &verbose);
request.command = htons(REQ_N_SOURCES); request.command = htons(REQ_N_SOURCES);
if (!request_reply(&request, &reply, RPY_N_SOURCES, 0)) if (!request_reply(&request, &reply, RPY_N_SOURCES, 0))
return 0; return 0;
n_sources = ntohl(reply.data.n_sources.n_sources); n_sources = ntohl(reply.data.n_sources.n_sources);
print_info_field("210 Number of sources = %lu\n", (unsigned long)n_sources);
if (verbose) { if (verbose) {
printf(" .- Number of sample points in measurement set.\n"); printf(" .- Number of sample points in measurement set.\n");
@ -2269,6 +2278,9 @@ process_cmd_sourcestats(char *line)
return 0; return 0;
UTI_IPNetworkToHost(&reply.data.sourcestats.ip_addr, &ip_addr); UTI_IPNetworkToHost(&reply.data.sourcestats.ip_addr, &ip_addr);
if (!all && ip_addr.family == IPADDR_ID)
continue;
format_name(name, sizeof (name), 25, ip_addr.family == IPADDR_UNSPEC, format_name(name, sizeof (name), 25, ip_addr.family == IPADDR_UNSPEC,
ntohl(reply.data.sourcestats.ref_id), 1, &ip_addr); ntohl(reply.data.sourcestats.ref_id), 1, &ip_addr);
@ -2382,6 +2394,8 @@ process_cmd_ntpdata(char *line)
continue; continue;
UTI_IPNetworkToHost(&reply.data.source_data.ip_addr, &remote_addr); UTI_IPNetworkToHost(&reply.data.source_data.ip_addr, &remote_addr);
if (!UTI_IsIPReal(&remote_addr))
continue;
} }
request.command = htons(REQ_NTP_DATA); request.command = htons(REQ_NTP_DATA);

View file

@ -291,15 +291,18 @@ milliseconds.
=== Time sources === Time sources
[[sources]]*sources* [*-v*]:: [[sources]]*sources* [*-a*] [*-v*]::
This command displays information about the current time sources that *chronyd* This command displays information about the current time sources that *chronyd*
is accessing. is accessing.
+ +
The optional argument *-v* can be specified, meaning _verbose_. In this case, If the *-a* option is specified, all sources are displayed, including those that
do not have a known address yet. Such sources have an identifier in the format
_ID#XXXXXXXXXX_, which can be used in other commands expecting a source address.
+
The *-v* option enables a verbose output. In this case,
extra caption lines are shown as a reminder of the meanings of the columns. extra caption lines are shown as a reminder of the meanings of the columns.
+ +
---- ----
210 Number of sources = 3
MS Name/IP address Stratum Poll Reach LastRx Last sample MS Name/IP address Stratum Poll Reach LastRx Last sample
=============================================================================== ===============================================================================
#* GPS0 0 4 377 11 -479ns[ -621ns] +/- 134ns #* GPS0 0 4 377 11 -479ns[ -621ns] +/- 134ns
@ -360,18 +363,21 @@ since. The number following the _+/-_ indicator shows the margin of error in
the measurement. Positive offsets indicate that the local clock is ahead of the measurement. Positive offsets indicate that the local clock is ahead of
the source. the source.
[[sourcestats]]*sourcestats* [*-v*]:: [[sourcestats]]*sourcestats* [*-a*] [*-v*]::
The *sourcestats* command displays information about the drift rate and offset The *sourcestats* command displays information about the drift rate and offset
estimation process for each of the sources currently being examined by estimation process for each of the sources currently being examined by
*chronyd*. *chronyd*.
+ +
The optional argument *-v* can be specified, meaning _verbose_. In this case, If the *-a* option is specified, all sources are displayed, including those that
do not have a known address yet. Such sources have an identifier in the format
_ID#XXXXXXXXXX_, which can be used in other commands expecting a source address.
+
The *-v* option enables a verbose output. In this case,
extra caption lines are shown as a reminder of the meanings of the columns. extra caption lines are shown as a reminder of the meanings of the columns.
+ +
An example report is: An example report is:
+ +
---- ----
210 Number of sources = 1
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
=============================================================================== ===============================================================================
foo.example.net 11 5 46m -0.001 0.045 1us 25us foo.example.net 11 5 46m -0.001 0.045 1us 25us
@ -449,8 +455,9 @@ not visible in the *sources* and *sourcestats* reports.
[[ntpdata]]*ntpdata* [_address_]:: [[ntpdata]]*ntpdata* [_address_]::
The *ntpdata* command displays the last valid measurement and other The *ntpdata* command displays the last valid measurement and other
NTP-specific information about the specified NTP source, or all NTP sources if NTP-specific information about the specified NTP source, or all NTP sources
no address was specified. An example of the output is shown below. (with a known address) if no address was specified. An example of the output is
shown below.
+ +
---- ----
Remote address : 203.0.113.15 (CB00710F) Remote address : 203.0.113.15 (CB00710F)

View file

@ -43,12 +43,10 @@ Root delay : 0\.000...... seconds
Root dispersion : 0\.000...... seconds Root dispersion : 0\.000...... seconds
Update interval : [0-9]+\.. seconds Update interval : [0-9]+\.. seconds
Leap status : Normal Leap status : Normal
210 Number of sources = 2
MS Name/IP address Stratum Poll Reach LastRx Last sample MS Name/IP address Stratum Poll Reach LastRx Last sample
=============================================================================== ===============================================================================
#\? SHM0 0 4 377 [0-9]+ [0-9 +-]+[un]s\[[0-9 +-]+[un]s\] \+/-[ 0-9]+[un]s #\? SHM0 0 4 377 [0-9]+ [0-9 +-]+[un]s\[[0-9 +-]+[un]s\] \+/-[ 0-9]+[un]s
\^\* 192\.168\.123\.1 1 [67] 377 [0-9]+ [0-9 +-]+[un]s\[[0-9 +-]+[un]s\] \+/-[ 0-9]+[un]s \^\* 192\.168\.123\.1 1 [67] 377 [0-9]+ [0-9 +-]+[un]s\[[0-9 +-]+[un]s\] \+/-[ 0-9]+[un]s
210 Number of sources = 2
Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev
============================================================================== ==============================================================================
SHM0 [0-9 ]+ [0-9 ]+ [0-9 ]+ [ +-][01]\.... [0-9 ]+\.... [0-9 +-]+[un]s [0-9 ]+[un]s SHM0 [0-9 ]+ [0-9 ]+ [0-9 ]+ [ +-][01]\.... [0-9 ]+\.... [0-9 +-]+[un]s [0-9 ]+[un]s
@ -106,6 +104,7 @@ for chronyc_conf in \
"cmddeny all 1.2.3.0/24" \ "cmddeny all 1.2.3.0/24" \
"cyclelogs" \ "cyclelogs" \
"delete 10.0.0.0" \ "delete 10.0.0.0" \
"delete ID#0000000001" \
"deny 1.2.3.4" \ "deny 1.2.3.4" \
"deny all 1.2.3.0/24" \ "deny all 1.2.3.0/24" \
"dfreq 1.0e-3" \ "dfreq 1.0e-3" \
@ -126,6 +125,7 @@ for chronyc_conf in \
"maxupdateskew 1.2.3.4 10.0" \ "maxupdateskew 1.2.3.4 10.0" \
"minpoll 1.2.3.4 3" \ "minpoll 1.2.3.4 3" \
"minstratum 1.2.3.4 1" \ "minstratum 1.2.3.4 1" \
"minstratum ID#0000000001 1" \
"ntpdata 1.2.3.4" \ "ntpdata 1.2.3.4" \
"offline" \ "offline" \
"offline 255.255.255.0/1.2.3.0" \ "offline 255.255.255.0/1.2.3.0" \