]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add minstratum command
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 25 Aug 2010 11:50:46 +0000 (13:50 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 25 Aug 2010 15:43:17 +0000 (17:43 +0200)
candm.h
chrony.texi
client.c
cmdmon.c
ntp_core.c
ntp_core.h
ntp_sources.c
ntp_sources.h
pktlength.c

diff --git a/candm.h b/candm.h
index 49c68f41055843989ed15afbfb1a6e3ca698651e..1c7cccffad5827d440aff71e34f6da17f482a38f 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -86,7 +86,8 @@
 #define REQ_MANUAL_DELETE 42
 #define REQ_MAKESTEP 43
 #define REQ_ACTIVITY 44
-#define N_REQUEST_TYPES 45
+#define REQ_MODIFY_MINSTRATUM 45
+#define N_REQUEST_TYPES 46
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
@@ -162,6 +163,12 @@ typedef struct {
   int32_t EOR;
 } REQ_Modify_Maxdelayratio;
 
+typedef struct {
+  IPAddr address;
+  int32_t new_min_stratum;
+  int32_t EOR;
+} REQ_Modify_Minstratum;
+
 typedef struct {
   Float new_max_update_skew;
   int32_t EOR;
@@ -370,6 +377,7 @@ typedef struct {
     REQ_Dump dump;
     REQ_Modify_Maxdelay modify_maxdelay;
     REQ_Modify_Maxdelayratio modify_maxdelayratio;
+    REQ_Modify_Minstratum modify_minstratum;
     REQ_Modify_Maxupdateskew modify_maxupdateskew;
     REQ_Logon logon;
     REQ_Settime settime;
index 9996bb9019461bc0bf521c86309a45c20ce09f7b..b4681ae2ee81bb67923c7b35d2941d41c5a41d35 100644 (file)
@@ -2821,6 +2821,7 @@ interface.
 * maxpoll command::             Set maximum polling interval for a source
 * maxupdateskew command::       Set safety threshold for clock gain/loss rate
 * minpoll command::             Set minimum polling interval for a source
+* minstratum command::          Set minimum stratum for a source
 * offline command::             Warn that connectivity to a source will be lost
 * online command::              Warn that connectivity to a source has been restored
 * password command::            Provide password needed for most commands
@@ -3446,6 +3447,35 @@ to 32 seconds.
 Note that the new minimum polling interval only takes effect after the
 next measurement has been made.
 @c }}}
+@c {{{ minstratum
+@node minstratum command
+@subsubsection minstratum
+The @code{minstratum} command is used to modify the minimum stratum
+for one of the current set of sources.  It is equivalent to the
+@code{minstratum} option in the @code{server} directive in the
+configuration file (@pxref{server directive}).
+
+The syntax is as follows
+
+@example
+minstratum <host> <new-min-stratum>
+@end example
+
+where the host can be specified as either a machine name or
+IP address.
+
+An example is 
+
+@example
+minpoll foo.bar.com 5
+@end example
+
+which sets the minimum stratum for the host @code{foo.bar.com}
+to 5.
+
+Note that the new minimum stratum only takes effect after the
+next measurement has been made.
+@c }}}
 @c {{{ offline
 @node offline command
 @subsubsection offline
index fcc627b25a80d279e1ab51d658474d25521d8848..cfe518d81dc3817f98a9887876736a6a54f197ae 100644 (file)
--- a/client.c
+++ b/client.c
@@ -458,6 +458,28 @@ process_cmd_maxdelayratio(CMD_Request *msg, char *line)
 
 /* ================================================== */
 
+static int
+process_cmd_minstratum(CMD_Request *msg, char *line)
+{
+  IPAddr address;
+  int min_stratum;
+  int ok;
+  
+  if (read_address_integer(line, &address, &min_stratum)) {
+    UTI_IPHostToNetwork(&address, &msg->data.modify_minstratum.address);
+    msg->data.modify_minstratum.new_min_stratum = htonl(min_stratum);
+    msg->command = htons(REQ_MODIFY_MINSTRATUM);
+    ok = 1;
+  } else {
+    ok = 0;
+  }
+
+  return ok;
+
+}
+
+/* ================================================== */
+
 static int
 process_cmd_maxupdateskew(CMD_Request *msg, char *line)
 {
@@ -1138,9 +1160,10 @@ give_help(void)
   printf("manual list : Show previous settime entries\n");
   printf("maxdelay <address> <new-max-delay> : Modify maximum round-trip valid sample delay for source\n");
   printf("maxdelayratio <address> <new-max-ratio> : Modify max round-trip delay ratio for source\n");
-  printf("maxpoll <address> <new-minpoll> : Modify maximum polling interval of source\n");
+  printf("maxpoll <address> <new-maxpoll> : Modify maximum polling interval of source\n");
   printf("maxupdateskew <new-max-skew> : Modify maximum skew for a clock frequency update to be made\n");
   printf("minpoll <address> <new-minpoll> : Modify minimum polling interval of source\n");
+  printf("minstratum <address> <new-min-stratum> : Modify minimum stratum of source\n");
   printf("offline [<mask>/<masked-address>] : Set sources in subnet to offline status\n");
   printf("online [<mask>/<masked-address>] : Set sources in subnet to online status\n");
   printf("password [<new-password>] : Set command authentication password\n");
@@ -2349,6 +2372,8 @@ process_line(char *line, int *quit)
     do_normal_submit = process_cmd_maxdelay(&tx_message, p+8);
   } else if (!strncmp(p, "maxupdateskew", 13)) {
     do_normal_submit = process_cmd_maxupdateskew(&tx_message, p+13);
+  } else if (!strncmp(p, "minstratum", 10)) {
+    do_normal_submit = process_cmd_minstratum(&tx_message, p+10);
   } else if (!strncmp(p, "settime", 7)) {
     do_normal_submit = 0;
     ret = process_cmd_settime(p+7);
index c39317e14e0b8749862f4ef1646ed7d9ba12f14f..e382e10255801f5d1a526e7ee834caf828c69916 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -158,7 +158,8 @@ static int permissions[] = {
   PERMIT_OPEN, /* MANUAL_LIST */
   PERMIT_AUTH, /* MANUAL_DELETE */
   PERMIT_AUTH, /* MAKESTEP */
-  PERMIT_OPEN  /* ACTIVITY */
+  PERMIT_OPEN, /* ACTIVITY */
+  PERMIT_AUTH  /* MODIFY_MINSTRATUM */
 };
 
 /* ================================================== */
@@ -902,6 +903,24 @@ handle_modify_maxdelayratio(CMD_Request *rx_message, CMD_Reply *tx_message)
 
 /* ================================================== */
 
+static void
+handle_modify_minstratum(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  int status;
+  IPAddr address;
+  UTI_IPNetworkToHost(&rx_message->data.modify_minpoll.address, &address);
+  status = NSR_ModifyMinstratum(&address,
+                             ntohl(rx_message->data.modify_minstratum.new_min_stratum));
+  
+  if (status) {
+    tx_message->status = htons(STT_SUCCESS);
+  } else {
+    tx_message->status = htons(STT_NOSUCHSOURCE);
+  }
+}
+
+/* ================================================== */
+
 static void
 handle_modify_maxupdateskew(CMD_Request *rx_message, CMD_Reply *tx_message)
 {
@@ -2211,6 +2230,10 @@ read_from_cmd_socket(void *anything)
           handle_activity(&rx_message, &tx_message);
           break;
 
+        case REQ_MODIFY_MINSTRATUM:
+          handle_modify_minstratum(&rx_message, &tx_message);
+          break;
+
         default:
           /* Ignore message */
           break;
index e06ea41ef23ae435d2a0ff366a42d3dd1a7132e2..c00c462fa0386822a2c456d67876e7738c2fe775 100644 (file)
@@ -1749,6 +1749,16 @@ NCR_ModifyMaxdelayratio(NCR_Instance inst, double new_max_delay_ratio)
 
 /* ================================================== */
 
+void
+NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum)
+{
+  inst->min_stratum = new_min_stratum;
+  LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new minstratum %d",
+      UTI_IPToString(&inst->remote_addr.ip_addr), new_min_stratum);
+}
+
+/* ================================================== */
+
 void
 NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_samples)
 {
index 5bddc52e9009a575a0edc7e5b21aae1ea91b6730..46e70bb18bb3e926afa24b91db4410d75ee6c7d1 100644 (file)
@@ -91,6 +91,8 @@ extern void NCR_ModifyMaxdelay(NCR_Instance inst, double new_max_delay);
 
 extern void NCR_ModifyMaxdelayratio(NCR_Instance inst, double new_max_delay_ratio);
 
+extern void NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum);
+
 extern void NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_samples);
 
 extern void NCR_ReportSource(NCR_Instance inst, RPT_SourceReport *report, struct timeval *now);
index 3750ef2973887a39ab787f0874bf8b4e23988835..4a75b0760d255538bbfab1e2c8cab06b447ce639 100644 (file)
@@ -555,6 +555,25 @@ NSR_ModifyMaxdelayratio(IPAddr *address, double new_max_delay_ratio)
 
 /* ================================================== */
 
+int
+NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum)
+{
+  int slot, found;
+  NTP_Remote_Address addr;
+  addr.ip_addr = *address;
+  addr.port = 0;
+
+  find_slot(&addr, &slot, &found);
+  if (found == 0) {
+    return 0;
+  } else {
+    NCR_ModifyMinstratum(records[slot].data, new_min_stratum);
+    return 1;
+  }
+}
+
+/* ================================================== */
+
 int
 NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples,
                         IPAddr *mask, IPAddr *address)
index d69ee0dea4c739c2aaed798278aacf54e02bb450..716e38714e4c4ebbf6d5395af56a7afcb70d6ceb 100644 (file)
@@ -91,6 +91,8 @@ extern int NSR_ModifyMaxdelay(IPAddr *address, double new_max_delay);
 
 extern int NSR_ModifyMaxdelayratio(IPAddr *address, double new_max_delay_ratio);
 
+extern int NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum);
+
 extern int NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples, IPAddr *mask, IPAddr *address);
 
 extern void NSR_ReportSource(RPT_SourceReport *report, struct timeval *now);
index 70e16ebd1785c101f9977963cba57391a746d809..1fdbeaf522ed877ce2bda7f21bce05471e27d418 100644 (file)
@@ -147,6 +147,8 @@ PKL_CommandLength(CMD_Request *r)
         return offsetof(CMD_Request, data.make_step.EOR);
       case REQ_ACTIVITY:
         return offsetof(CMD_Request, data.activity.EOR);
+      case REQ_MODIFY_MINSTRATUM:
+        return offsetof(CMD_Request, data.modify_minstratum.EOR);
       default:
         /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
         assert(0);