]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: add smoothtime command
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 9 Jun 2015 10:51:49 +0000 (12:51 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 9 Jun 2015 14:15:30 +0000 (16:15 +0200)
This adds a command to reset or activate the time smoothing process.

candm.h
cmdmon.c
pktlength.c
smooth.c
smooth.h

diff --git a/candm.h b/candm.h
index 956db9e0023a0a1994965bce5eab99aba8c55361..f3bea3a40b68fd4cbf8058b04a6ca4a11063b367 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -90,7 +90,8 @@
 #define REQ_RESELECTDISTANCE 49
 #define REQ_MODIFY_MAKESTEP 50
 #define REQ_SMOOTHING 51
-#define N_REQUEST_TYPES 52
+#define REQ_SMOOTHTIME 52
+#define N_REQUEST_TYPES 53
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
@@ -297,6 +298,14 @@ typedef struct {
   int32_t EOR;
 } REQ_ReselectDistance;
 
+#define REQ_SMOOTHTIME_RESET 0
+#define REQ_SMOOTHTIME_ACTIVATE 1
+
+typedef struct {
+  int32_t option;
+  int32_t EOR;
+} REQ_SmoothTime;
+
 /* ================================================== */
 
 #define PKT_TYPE_CMD_REQUEST 1
@@ -326,7 +335,7 @@ typedef struct {
 
    Version 6 : added padding to requests to prevent amplification attack,
    changed maximum number of samples in manual list to 16, new commands: modify
-   makestep
+   makestep, smoothing report, smoothtime command
  */
 
 #define PROTO_VERSION_NUMBER 6
@@ -388,6 +397,7 @@ typedef struct {
     REQ_ClientAccessesByIndex client_accesses_by_index;
     REQ_ManualDelete manual_delete;
     REQ_ReselectDistance reselect_distance;
+    REQ_SmoothTime smoothtime;
   } data; /* Command specific parameters */
 
   /* The following fields only set the maximum size of the packet.
index 2d71b8d31ff4d417e534d6db752f9f0d428e6aae..82e6f4ae34c69c51591447d1f93c7acd2d752508 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -164,6 +164,7 @@ static const char permissions[] = {
   PERMIT_AUTH, /* RESELECTDISTANCE */
   PERMIT_AUTH, /* MODIFY_MAKESTEP */
   PERMIT_OPEN, /* SMOOTHING */
+  PERMIT_AUTH, /* SMOOTHTIME */
 };
 
 /* ================================================== */
@@ -1250,6 +1251,35 @@ handle_smoothing(CMD_Request *rx_message, CMD_Reply *tx_message)
 
 /* ================================================== */
 
+static void
+handle_smoothtime(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  struct timeval now;
+  int option;
+
+  if (!SMT_IsEnabled()) {
+    tx_message->status = htons(STT_NOTENABLED);
+    return;
+  }
+
+  option = ntohl(rx_message->data.smoothtime.option);
+  SCH_GetLastEventTime(&now, NULL, NULL);
+
+  switch (option) {
+    case REQ_SMOOTHTIME_RESET:
+      SMT_Reset(&now);
+      break;
+    case REQ_SMOOTHTIME_ACTIVATE:
+      SMT_Activate(&now);
+      break;
+    default:
+      tx_message->status = htons(STT_INVALID);
+      break;
+  }
+}
+
+/* ================================================== */
+
 static void
 handle_sourcestats(CMD_Request *rx_message, CMD_Reply *tx_message)
 {
@@ -1920,6 +1950,10 @@ read_from_cmd_socket(void *anything)
           handle_smoothing(&rx_message, &tx_message);
           break;
 
+        case REQ_SMOOTHTIME:
+          handle_smoothtime(&rx_message, &tx_message);
+          break;
+
         case REQ_SOURCESTATS:
           handle_sourcestats(&rx_message, &tx_message);
           break;
index 72c31714fcc339a21c42c3e0a6a4116f0cb5c0d4..be773c273021c8f9ad277e7da8c5bf969bcaed64 100644 (file)
@@ -148,6 +148,8 @@ command_unpadded_length(CMD_Request *r)
         return offsetof(CMD_Request, data.modify_polltarget.EOR);
       case REQ_SMOOTHING:
         return offsetof(CMD_Request, data.null.EOR);
+      case REQ_SMOOTHTIME:
+        return offsetof(CMD_Request, data.smoothtime.EOR);
       default:
         /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
         assert(0);
@@ -300,6 +302,8 @@ PKL_CommandPaddingLength(CMD_Request *r)
       return PADDING_LENGTH(data.modify_polltarget.EOR, data.null.EOR);
     case REQ_SMOOTHING:
       return PADDING_LENGTH(data.null.EOR, data.smoothing.EOR);
+    case REQ_SMOOTHTIME:
+      return PADDING_LENGTH(data.smoothtime.EOR, data.null.EOR);
     default:
       /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
       assert(0);
index bfd7529fc6762d71a6bc0ca6d15eda2b4437cf7a..ae64ca34ed6c126b6184c745077796ab13788e6a 100644 (file)
--- a/smooth.c
+++ b/smooth.c
@@ -199,12 +199,8 @@ update_smoothing(struct timeval *now, double offset, double freq)
 {
   /* Don't accept offset/frequency until the clock has stabilized */
   if (locked) {
-    if (REF_GetSkew() / max_wander < UNLOCK_SKEW_WANDER_RATIO || leap_only_mode) {
-      LOG(LOGS_INFO, LOGF_Smooth, "Time smoothing activated%s", leap_only_mode ?
-          " (leap seconds only)" : "");
-      locked = 0;
-      last_update = *now;
-    }
+    if (REF_GetSkew() / max_wander < UNLOCK_SKEW_WANDER_RATIO || leap_only_mode)
+      SMT_Activate(now);
     return;
   }
 
@@ -274,6 +270,18 @@ SMT_GetOffset(struct timeval *now)
   return offset;
 }
 
+void
+SMT_Activate(struct timeval *now)
+{
+  if (!enabled || !locked)
+    return;
+
+  LOG(LOGS_INFO, LOGF_Smooth, "Time smoothing activated%s", leap_only_mode ?
+      " (leap seconds only)" : "");
+  locked = 0;
+  last_update = *now;
+}
+
 void
 SMT_Reset(struct timeval *now)
 {
index 1cf6814bc7b7a7fdb021d559b9a8b17a0d6a489c..72e67af680640f02c490c39a3bef11eb5e07628a 100644 (file)
--- a/smooth.h
+++ b/smooth.h
@@ -37,6 +37,8 @@ extern int SMT_IsEnabled(void);
 
 extern double SMT_GetOffset(struct timeval *now);
 
+extern void SMT_Activate(struct timeval *now);
+
 extern void SMT_Reset(struct timeval *now);
 
 extern void SMT_Leap(struct timeval *now, int leap);