mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 05:25:08 -05:00
client: add ntpdata command
This commit is contained in:
81
client.c
81
client.c
@@ -1193,6 +1193,7 @@ give_help(void)
|
||||
"\0\0"
|
||||
"NTP sources:\0\0"
|
||||
"activity\0Check how many NTP sources are online/offline\0"
|
||||
"ntpdata <address>\0Display information about last valid measurement\0"
|
||||
"add server <address> [options]\0Add new NTP server\0"
|
||||
"add peer <address> [options]\0Add new NTP peer\0"
|
||||
"delete <address>\0Remove server or peer\0"
|
||||
@@ -2193,6 +2194,83 @@ process_cmd_tracking(char *line)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static int
|
||||
process_cmd_ntpdata(char *line)
|
||||
{
|
||||
CMD_Request request;
|
||||
CMD_Reply reply;
|
||||
IPAddr remote_addr, local_addr;
|
||||
struct timespec ref_time;
|
||||
|
||||
if (DNS_Name2IPAddress(line, &remote_addr, 1) != DNS_Success) {
|
||||
LOG(LOGS_ERR, LOGF_Client, "Could not get address for hostname");
|
||||
return 0;
|
||||
}
|
||||
|
||||
request.command = htons(REQ_NTP_DATA);
|
||||
UTI_IPHostToNetwork(&remote_addr, &request.data.ntp_data.ip_addr);
|
||||
if (!request_reply(&request, &reply, RPY_NTP_DATA, 0))
|
||||
return 0;
|
||||
|
||||
UTI_IPNetworkToHost(&reply.data.ntp_data.remote_addr, &remote_addr);
|
||||
UTI_IPNetworkToHost(&reply.data.ntp_data.local_addr, &local_addr);
|
||||
UTI_TimespecNetworkToHost(&reply.data.ntp_data.ref_time, &ref_time);
|
||||
|
||||
print_report("Remote address : %s\n"
|
||||
"Remote port : %u\n"
|
||||
"Local address : %s\n"
|
||||
"Leap status : %L\n"
|
||||
"Version : %u\n"
|
||||
"Mode : %M\n"
|
||||
"Stratum : %u\n"
|
||||
"Poll : %u\n"
|
||||
"Precision : %.9f seconds\n"
|
||||
"Root delay : %.6f seconds\n"
|
||||
"Root dispersion : %.6f seconds\n"
|
||||
"Reference ID : %R\n"
|
||||
"Reference time : %T\n"
|
||||
"Offset : %+.9f seconds\n"
|
||||
"Peer delay : %.9f seconds\n"
|
||||
"Peer dispersion : %.9f seconds\n"
|
||||
"Response time : %.9f seconds\n"
|
||||
"Jitter asymmetry: %+.2f\n"
|
||||
"NTP tests : %.3b %.3b %.4b\n"
|
||||
"Interleaved : %B\n"
|
||||
"Authenticated : %B\n"
|
||||
"TX timestamping : %N\n"
|
||||
"RX timestamping : %N\n"
|
||||
"Total TX : %U\n"
|
||||
"Total RX : %U\n"
|
||||
"Total valid RX : %U\n",
|
||||
UTI_IPToString(&remote_addr), ntohs(reply.data.ntp_data.remote_port),
|
||||
UTI_IPToString(&local_addr),
|
||||
reply.data.ntp_data.leap, reply.data.ntp_data.version,
|
||||
reply.data.ntp_data.mode, reply.data.ntp_data.stratum,
|
||||
reply.data.ntp_data.poll, UTI_Log2ToDouble(reply.data.ntp_data.precision),
|
||||
UTI_FloatNetworkToHost(reply.data.ntp_data.root_delay),
|
||||
UTI_FloatNetworkToHost(reply.data.ntp_data.root_dispersion),
|
||||
(unsigned long)ntohl(reply.data.ntp_data.ref_id), &ref_time,
|
||||
UTI_FloatNetworkToHost(reply.data.ntp_data.offset),
|
||||
UTI_FloatNetworkToHost(reply.data.ntp_data.peer_delay),
|
||||
UTI_FloatNetworkToHost(reply.data.ntp_data.peer_dispersion),
|
||||
UTI_FloatNetworkToHost(reply.data.ntp_data.response_time),
|
||||
UTI_FloatNetworkToHost(reply.data.ntp_data.jitter_asymmetry),
|
||||
ntohs(reply.data.ntp_data.flags) >> 7,
|
||||
ntohs(reply.data.ntp_data.flags) >> 4,
|
||||
ntohs(reply.data.ntp_data.flags),
|
||||
ntohs(reply.data.ntp_data.flags) & RPY_NTP_FLAG_INTERLEAVED,
|
||||
ntohs(reply.data.ntp_data.flags) & RPY_NTP_FLAG_AUTHENTICATED,
|
||||
reply.data.ntp_data.tx_tss_char, reply.data.ntp_data.rx_tss_char,
|
||||
(unsigned long)ntohl(reply.data.ntp_data.total_tx_count),
|
||||
(unsigned long)ntohl(reply.data.ntp_data.total_rx_count),
|
||||
(unsigned long)ntohl(reply.data.ntp_data.total_valid_count),
|
||||
REPORT_END);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static int
|
||||
process_cmd_serverstats(char *line)
|
||||
{
|
||||
@@ -2809,6 +2887,9 @@ process_line(char *line)
|
||||
do_normal_submit = process_cmd_minpoll(&tx_message, line);
|
||||
} else if (!strcmp(command, "minstratum")) {
|
||||
do_normal_submit = process_cmd_minstratum(&tx_message, line);
|
||||
} else if (!strcmp(command, "ntpdata")) {
|
||||
do_normal_submit = 0;
|
||||
ret = process_cmd_ntpdata(line);
|
||||
} else if (!strcmp(command, "offline")) {
|
||||
do_normal_submit = process_cmd_offline(&tx_message, line);
|
||||
} else if (!strcmp(command, "online")) {
|
||||
|
||||
Reference in New Issue
Block a user