diff --git a/candm.h b/candm.h index b560614..86d8107 100644 --- a/candm.h +++ b/candm.h @@ -516,7 +516,8 @@ typedef struct { #define RPY_CLIENT_ACCESSES_BY_INDEX3 21 #define RPY_SERVER_STATS2 22 #define RPY_SELECT_DATA 23 -#define N_REPLY_TYPES 24 +#define RPY_SERVER_STATS3 24 +#define N_REPLY_TYPES 25 /* Status codes */ #define STT_SUCCESS 0 @@ -659,6 +660,9 @@ typedef struct { uint32_t cmd_drops; uint32_t log_drops; uint32_t ntp_auth_hits; + uint32_t ntp_interleaved_hits; + uint32_t ntp_timestamps; + uint32_t ntp_span_seconds; int32_t EOR; } RPY_ServerStats; diff --git a/client.c b/client.c index 4180ac5..a9aa6b5 100644 --- a/client.c +++ b/client.c @@ -2459,7 +2459,7 @@ process_cmd_serverstats(char *line) CMD_Reply reply; request.command = htons(REQ_SERVER_STATS); - if (!request_reply(&request, &reply, RPY_SERVER_STATS2, 0)) + if (!request_reply(&request, &reply, RPY_SERVER_STATS3, 0)) return 0; print_report("NTP packets received : %U\n" @@ -2469,7 +2469,10 @@ process_cmd_serverstats(char *line) "Client log records dropped : %U\n" "NTS-KE connections accepted: %U\n" "NTS-KE connections dropped : %U\n" - "Authenticated NTP packets : %U\n", + "Authenticated NTP packets : %U\n" + "Interleaved NTP packets : %U\n" + "NTP timestamps held : %U\n" + "NTP timestamp span : %U\n", (unsigned long)ntohl(reply.data.server_stats.ntp_hits), (unsigned long)ntohl(reply.data.server_stats.ntp_drops), (unsigned long)ntohl(reply.data.server_stats.cmd_hits), @@ -2478,6 +2481,9 @@ process_cmd_serverstats(char *line) (unsigned long)ntohl(reply.data.server_stats.nke_hits), (unsigned long)ntohl(reply.data.server_stats.nke_drops), (unsigned long)ntohl(reply.data.server_stats.ntp_auth_hits), + (unsigned long)ntohl(reply.data.server_stats.ntp_interleaved_hits), + (unsigned long)ntohl(reply.data.server_stats.ntp_timestamps), + (unsigned long)ntohl(reply.data.server_stats.ntp_span_seconds), REPORT_END); return 1; diff --git a/clientlog.c b/clientlog.c index 09af04b..2a18a97 100644 --- a/clientlog.c +++ b/clientlog.c @@ -155,6 +155,7 @@ static NtpTimestampMap ntp_ts_map; static uint32_t total_hits[MAX_SERVICES]; static uint32_t total_drops[MAX_SERVICES]; static uint32_t total_ntp_auth_hits; +static uint32_t total_ntp_interleaved_hits; static uint32_t total_record_drops; #define NSEC_PER_SEC 1000000000U @@ -921,6 +922,10 @@ CLG_DisableNtpTimestamps(NTP_int64 *rx_ts) if (find_ntp_rx_ts(ntp64_to_int64(rx_ts), &index)) get_ntp_tss(index)->flags |= NTPTS_DISABLED; + + /* This assumes the function is called only to prevent multiple + interleaved responses to the same timestamp */ + total_ntp_interleaved_hits++; } /* ================================================== */ @@ -1027,4 +1032,9 @@ CLG_GetServerStatsReport(RPT_ServerStatsReport *report) report->cmd_drops = total_drops[CLG_CMDMON]; report->log_drops = total_record_drops; report->ntp_auth_hits = total_ntp_auth_hits; + report->ntp_interleaved_hits = total_ntp_interleaved_hits; + report->ntp_timestamps = ntp_ts_map.size; + report->ntp_span_seconds = ntp_ts_map.size > 1 ? + (get_ntp_tss(ntp_ts_map.size - 1)->rx_ts - + get_ntp_tss(0)->rx_ts) >> 32 : 0; } diff --git a/cmdmon.c b/cmdmon.c index 8cbcd80..fee398b 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -1164,7 +1164,7 @@ handle_server_stats(CMD_Request *rx_message, CMD_Reply *tx_message) RPT_ServerStatsReport report; CLG_GetServerStatsReport(&report); - tx_message->reply = htons(RPY_SERVER_STATS2); + tx_message->reply = htons(RPY_SERVER_STATS3); tx_message->data.server_stats.ntp_hits = htonl(report.ntp_hits); tx_message->data.server_stats.nke_hits = htonl(report.nke_hits); tx_message->data.server_stats.cmd_hits = htonl(report.cmd_hits); @@ -1173,6 +1173,9 @@ handle_server_stats(CMD_Request *rx_message, CMD_Reply *tx_message) tx_message->data.server_stats.cmd_drops = htonl(report.cmd_drops); tx_message->data.server_stats.log_drops = htonl(report.log_drops); tx_message->data.server_stats.ntp_auth_hits = htonl(report.ntp_auth_hits); + tx_message->data.server_stats.ntp_interleaved_hits = htonl(report.ntp_interleaved_hits); + tx_message->data.server_stats.ntp_timestamps = htonl(report.ntp_timestamps); + tx_message->data.server_stats.ntp_span_seconds = htonl(report.ntp_span_seconds); } /* ================================================== */ diff --git a/doc/chronyc.adoc b/doc/chronyc.adoc index fbfea41..cfb5eb8 100644 --- a/doc/chronyc.adoc +++ b/doc/chronyc.adoc @@ -1107,13 +1107,9 @@ The columns are as follows: received/accepted. [[serverstats]]*serverstats*:: -The *serverstats* command displays how many valid NTP and command requests, and -NTS-KE connections, *chronyd* operating as a server received from clients, and -how many of them were dropped due to rate limiting. It also displays how many -client log records were dropped due to the memory limit configured by the -<> directive and how many of -the NTP requests (from those which were not dropped) were authenticated. An -example of the output is shown below. +The *serverstats* command displays NTP and command server statistics. ++ +An example of the output is shown below. + ---- NTP packets received : 1598 @@ -1124,7 +1120,47 @@ Client log records dropped : 0 NTS-KE connections accepted: 3 NTS-KE connections dropped : 0 Authenticated NTP packets : 189 +Interleaved NTP packets : 43 +NTP timestamps held : 44 +NTP timestamp span : 120 ---- ++ +The fields have the following meaning: ++ +*NTP packets received*::: +The number of valid NTP requests received by the server. +*NTP packets dropped*::: +The number of NTP requests dropped by the server due to rate limiting +(configured by the <> directive). +*Command packets received*::: +The number of command requests received by the server. +*Command packets dropped*::: +The number of command requests dropped by the server due to rate limiting +(configured by the <> directive). +*Client log records dropped*::: +The number of client log records dropped by the server to limit the memory use +(configured by the <> +directive). +*NTS-KE connections accepted*::: +The number of NTS-KE connections accepted by the server. +*NTS-KE connections dropped*::: +The number of NTS-KE connections dropped by the server due to rate limiting +(configured by the <> directive). +*Authenticated NTP packets*::: +The number of received NTP requests that were authenticated (with a symmetric +key or NTS). +*Interleaved NTP packets*::: +The number of received NTP requests that were detected to be in the interleaved +mode. +*NTP timestamps held*::: +The number of pairs of receive and transmit timestamps that the server is +currently holding in memory for clients using the interleaved mode. +*NTP timestamp span*::: +The interval (in seconds) covered by the currently held NTP timestamps. +{blank}:: ++ +Note that the numbers reported by this overflow to zero after 4294967295 +(32-bit values). [[allow]]*allow* [*all*] [_subnet_]:: The effect of the allow command is identical to the diff --git a/pktlength.c b/pktlength.c index 1e318d6..642e477 100644 --- a/pktlength.c +++ b/pktlength.c @@ -154,8 +154,9 @@ static const uint16_t reply_lengths[] = { RPY_LENGTH_ENTRY(ntp_source_name), /* NTP_SOURCE_NAME */ RPY_LENGTH_ENTRY(auth_data), /* AUTH_DATA */ RPY_LENGTH_ENTRY(client_accesses_by_index), /* CLIENT_ACCESSES_BY_INDEX3 */ - RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS2 */ + 0, /* SERVER_STATS2 - not supported */ RPY_LENGTH_ENTRY(select_data), /* SELECT_DATA */ + RPY_LENGTH_ENTRY(server_stats), /* SERVER_STATS3 */ }; /* ================================================== */ diff --git a/reports.h b/reports.h index 4508e8f..c403c23 100644 --- a/reports.h +++ b/reports.h @@ -117,6 +117,9 @@ typedef struct { uint32_t cmd_drops; uint32_t log_drops; uint32_t ntp_auth_hits; + uint32_t ntp_interleaved_hits; + uint32_t ntp_timestamps; + uint32_t ntp_span_seconds; } RPT_ServerStatsReport; typedef struct { diff --git a/test/simulation/110-chronyc b/test/simulation/110-chronyc index e95dfa0..7e4d327 100755 --- a/test/simulation/110-chronyc +++ b/test/simulation/110-chronyc @@ -241,7 +241,10 @@ Command packets dropped : 0 Client log records dropped : 0 NTS-KE connections accepted: 0 NTS-KE connections dropped : 0 -Authenticated NTP packets : 0$" || test_fail +Authenticated NTP packets : 0 +Interleaved NTP packets : 0 +NTP timestamps held : 0 +NTP timestamp span : 0$" || test_fail chronyc_conf=" deny all diff --git a/test/system/007-cmdmon b/test/system/007-cmdmon index fe2b006..bbcc12f 100755 --- a/test/system/007-cmdmon +++ b/test/system/007-cmdmon @@ -110,7 +110,10 @@ Command packets dropped : 0 Client log records dropped : 0 NTS-KE connections accepted: 0 NTS-KE connections dropped : 0 -Authenticated NTP packets : 0$" || test_fail +Authenticated NTP packets : 0 +Interleaved NTP packets : 0 +NTP timestamps held : 0 +NTP timestamp span : 0$"|| test_fail run_chronyc "manual on" || test_fail check_chronyc_output "^200 OK$" || test_fail