]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
clientlog: count RX and TX timestamps for each source
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 16 Mar 2023 15:56:28 +0000 (16:56 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 22 Mar 2023 08:42:35 +0000 (09:42 +0100)
Count served timestamps in all combinations of RX/TX and
daemon/kernel/hardware. Repurpose CLG_LogAuthNtpRequest() to update all
NTP-specific stats in one call per accepted request and response.

clientlog.c
clientlog.h
ntp_core.c
reports.h

index a6b199e72783b2527749d37084f73e39b78b702c..611e75339e3d4dd2065c47491bf73589947a5c7b 100644 (file)
@@ -165,6 +165,8 @@ 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;
+static uint32_t total_ntp_rx_timestamps[MAX_NTP_TS + 1];
+static uint32_t total_ntp_tx_timestamps[MAX_NTP_TS + 1];
 
 #define NSEC_PER_SEC 1000000000U
 
@@ -643,9 +645,14 @@ CLG_LimitServiceRate(CLG_Service service, int index)
 /* ================================================== */
 
 void
-CLG_LogAuthNtpRequest(void)
+CLG_UpdateNtpStats(int auth, NTP_Timestamp_Source rx_ts_src, NTP_Timestamp_Source tx_ts_src)
 {
-  total_ntp_auth_hits++;
+  if (auth)
+    total_ntp_auth_hits++;
+  if (rx_ts_src >= 0 && rx_ts_src <= MAX_NTP_TS)
+    total_ntp_rx_timestamps[rx_ts_src]++;
+  if (tx_ts_src >= 0 && tx_ts_src <= MAX_NTP_TS)
+    total_ntp_tx_timestamps[tx_ts_src]++;
 }
 
 /* ================================================== */
@@ -1095,4 +1102,10 @@ CLG_GetServerStatsReport(RPT_ServerStatsReport *report)
   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;
+  report->ntp_daemon_rx_timestamps = total_ntp_rx_timestamps[NTP_TS_DAEMON];
+  report->ntp_daemon_tx_timestamps = total_ntp_tx_timestamps[NTP_TS_DAEMON];
+  report->ntp_kernel_rx_timestamps = total_ntp_rx_timestamps[NTP_TS_KERNEL];
+  report->ntp_kernel_tx_timestamps = total_ntp_tx_timestamps[NTP_TS_KERNEL];
+  report->ntp_hw_rx_timestamps = total_ntp_rx_timestamps[NTP_TS_HARDWARE];
+  report->ntp_hw_tx_timestamps = total_ntp_tx_timestamps[NTP_TS_HARDWARE];
 }
index f7d8a4827beb5f61a471ae1e2ea667717353f2b4..9ea0a3fbb670c1b6c67502957db45d9603217871 100644 (file)
@@ -42,7 +42,8 @@ extern void CLG_Finalise(void);
 extern int CLG_GetClientIndex(IPAddr *client);
 extern int CLG_LogServiceAccess(CLG_Service service, IPAddr *client, struct timespec *now);
 extern int CLG_LimitServiceRate(CLG_Service service, int index);
-extern void CLG_LogAuthNtpRequest(void);
+extern void CLG_UpdateNtpStats(int auth, NTP_Timestamp_Source rx_ts_src,
+                               NTP_Timestamp_Source tx_ts_src);
 extern int CLG_GetNtpMinPoll(void);
 
 /* Functions to save and retrieve timestamps for server interleaved mode */
index 05eab948a02ee680a72ab8c3651cc2a69af414e0..a6e47acab0d2355b6d1d04acb680286fb5bfabf1 100644 (file)
@@ -2455,8 +2455,6 @@ NCR_ProcessRxUnknown(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_a
     /* Don't respond unless a non-zero KoD was returned */
     if (kod == 0)
       return;
-  } else if (info.auth.mode != NTP_AUTH_NONE && info.auth.mode != NTP_AUTH_MSSNTP) {
-    CLG_LogAuthNtpRequest();
   }
 
   local_ntp_rx = NULL;
@@ -2485,6 +2483,10 @@ NCR_ProcessRxUnknown(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_a
       CLG_DisableNtpTimestamps(&ntp_rx);
   }
 
+  CLG_UpdateNtpStats(kod != 0 && info.auth.mode != NTP_AUTH_NONE &&
+                     info.auth.mode != NTP_AUTH_MSSNTP,
+                     rx_ts->source, interleaved ? tx_ts->source : NTP_TS_DAEMON);
+
   /* Suggest the client to increase its polling interval if it indicates
      the interval is shorter than the rate limiting interval */
   poll = CLG_GetNtpMinPoll();
index 6674dd9143f614bf09ff076114afe3c5e587451e..68164a67d6d7186d58febf2df2e0e5d959935adb 100644 (file)
--- a/reports.h
+++ b/reports.h
@@ -120,6 +120,12 @@ typedef struct {
   uint32_t ntp_interleaved_hits;
   uint32_t ntp_timestamps;
   uint32_t ntp_span_seconds;
+  uint32_t ntp_daemon_rx_timestamps;
+  uint32_t ntp_daemon_tx_timestamps;
+  uint32_t ntp_kernel_rx_timestamps;
+  uint32_t ntp_kernel_tx_timestamps;
+  uint32_t ntp_hw_rx_timestamps;
+  uint32_t ntp_hw_tx_timestamps;
 } RPT_ServerStatsReport;
 
 typedef struct {