]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Add polltarget command
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 Oct 2010 13:08:35 +0000 (15:08 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 Oct 2010 13:08:35 +0000 (15:08 +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 b0f0a3e30eb19a8fe62adb2ef95397fab7e24797..25e17378ffa48c9b62038c9cdf5a9f7e0ba2dd88 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -87,7 +87,8 @@
 #define REQ_MAKESTEP 43
 #define REQ_ACTIVITY 44
 #define REQ_MODIFY_MINSTRATUM 45
-#define N_REQUEST_TYPES 46
+#define REQ_MODIFY_POLLTARGET 46
+#define N_REQUEST_TYPES 47
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
@@ -169,6 +170,12 @@ typedef struct {
   int32_t EOR;
 } REQ_Modify_Minstratum;
 
+typedef struct {
+  IPAddr address;
+  int32_t new_poll_target;
+  int32_t EOR;
+} REQ_Modify_Polltarget;
+
 typedef struct {
   Float new_max_update_skew;
   int32_t EOR;
@@ -380,6 +387,7 @@ typedef struct {
     REQ_Modify_Maxdelay modify_maxdelay;
     REQ_Modify_Maxdelayratio modify_maxdelayratio;
     REQ_Modify_Minstratum modify_minstratum;
+    REQ_Modify_Polltarget modify_polltarget;
     REQ_Modify_Maxupdateskew modify_maxupdateskew;
     REQ_Logon logon;
     REQ_Settime settime;
index 26320ceeb46212fe5a9d5b01ad16b6017e0d2f6b..47086aa5386adcc0de0ae9ccbfbae1c8ca150b64 100644 (file)
@@ -2855,6 +2855,7 @@ interface.
 * 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
+* polltarget command::          Set poll target for a source
 * quit command::                Exit from chronyc
 * retries command::             Set maximum number of retries
 * rtcdata command::             Display RTC parameters
@@ -3620,6 +3621,32 @@ The password is any string of characters not containing whitespace.  It
 has to match @code{chronyd's} currently defined command key (@pxref{commandkey
 directive}).
 @c }}}
+@c {{{ polltarget
+@node polltarget command
+@subsubsection polltarget
+The @code{polltarget} command is used to modify the poll target for
+one of the current set of sources.  It is equivalent to the
+@code{polltarget} option in the @code{server} directive in the
+configuration file (@pxref{server directive}).
+
+The syntax is as follows
+
+@example
+polltarget <host> <new-poll-target>
+@end example
+
+where the host can be specified as either a machine name or
+IP address.
+
+An example is 
+
+@example
+polltarget foo.bar.com 12
+@end example
+
+which sets the poll target for the host @code{foo.bar.com}
+to 12.
+@c }}}
 @c {{{ quit
 @node quit command
 @subsubsection quit
index c31564d2afc161bcf0b149b3c42da0a87eef4a6f..5379ca863bc75cc08e3a684fc336930253b9dba3 100644 (file)
--- a/client.c
+++ b/client.c
@@ -480,6 +480,28 @@ process_cmd_minstratum(CMD_Request *msg, char *line)
 
 /* ================================================== */
 
+static int
+process_cmd_polltarget(CMD_Request *msg, char *line)
+{
+  IPAddr address;
+  int poll_target;
+  int ok;
+  
+  if (read_address_integer(line, &address, &poll_target)) {
+    UTI_IPHostToNetwork(&address, &msg->data.modify_polltarget.address);
+    msg->data.modify_polltarget.new_poll_target = htonl(poll_target);
+    msg->command = htons(REQ_MODIFY_POLLTARGET);
+    ok = 1;
+  } else {
+    ok = 0;
+  }
+
+  return ok;
+
+}
+
+/* ================================================== */
+
 static int
 process_cmd_maxupdateskew(CMD_Request *msg, char *line)
 {
@@ -2417,6 +2439,8 @@ process_line(char *line, int *quit)
     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, "polltarget", 10)) {
+    do_normal_submit = process_cmd_polltarget(&tx_message, p+10);
   } else if (!strncmp(p, "settime", 7)) {
     do_normal_submit = 0;
     ret = process_cmd_settime(p+7);
index 3b9fe193b31999532352cb54aaa3ed34fa1c3503..884c62328b3819d8f1b579bc286e70a090be1e6e 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -159,7 +159,8 @@ static int permissions[] = {
   PERMIT_AUTH, /* MANUAL_DELETE */
   PERMIT_AUTH, /* MAKESTEP */
   PERMIT_OPEN, /* ACTIVITY */
-  PERMIT_AUTH  /* MODIFY_MINSTRATUM */
+  PERMIT_AUTH, /* MODIFY_MINSTRATUM */
+  PERMIT_AUTH  /* MODIFY_POLLTARGET */
 };
 
 /* ================================================== */
@@ -921,6 +922,24 @@ handle_modify_minstratum(CMD_Request *rx_message, CMD_Reply *tx_message)
 
 /* ================================================== */
 
+static void
+handle_modify_polltarget(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  int status;
+  IPAddr address;
+  UTI_IPNetworkToHost(&rx_message->data.modify_polltarget.address, &address);
+  status = NSR_ModifyPolltarget(&address,
+                             ntohl(rx_message->data.modify_polltarget.new_poll_target));
+  
+  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)
 {
@@ -2198,6 +2217,10 @@ read_from_cmd_socket(void *anything)
           handle_modify_minstratum(&rx_message, &tx_message);
           break;
 
+        case REQ_MODIFY_POLLTARGET:
+          handle_modify_polltarget(&rx_message, &tx_message);
+          break;
+
         default:
           /* Ignore message */
           break;
index 62148cb845b26d9027a6c0f6598e47cd92ed6849..8306ad2f3c85afb4de027799715b066730689d17 100644 (file)
@@ -1746,6 +1746,16 @@ NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum)
 
 /* ================================================== */
 
+void
+NCR_ModifyPolltarget(NCR_Instance inst, int new_poll_target)
+{
+  inst->poll_target = new_poll_target;
+  LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new polltarget %d",
+      UTI_IPToString(&inst->remote_addr.ip_addr), new_poll_target);
+}
+
+/* ================================================== */
+
 void
 NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_samples)
 {
index 46e70bb18bb3e926afa24b91db4410d75ee6c7d1..76449c68699ea9b3e36264f8607ceb5269cbfa5b 100644 (file)
@@ -93,6 +93,8 @@ extern void NCR_ModifyMaxdelayratio(NCR_Instance inst, double new_max_delay_rati
 
 extern void NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum);
 
+extern void NCR_ModifyPolltarget(NCR_Instance inst, int new_poll_target);
+
 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 4a75b0760d255538bbfab1e2c8cab06b447ce639..2f5bb8fc4055354f1a4137899e449604fd3c7356 100644 (file)
@@ -574,6 +574,25 @@ NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum)
 
 /* ================================================== */
 
+int
+NSR_ModifyPolltarget(IPAddr *address, int new_poll_target)
+{
+  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_ModifyPolltarget(records[slot].data, new_poll_target);
+    return 1;
+  }
+}
+
+/* ================================================== */
+
 int
 NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples,
                         IPAddr *mask, IPAddr *address)
index 716e38714e4c4ebbf6d5395af56a7afcb70d6ceb..de5b3fb6defddd98918a174e7d7d93b365dabadf 100644 (file)
@@ -93,6 +93,8 @@ extern int NSR_ModifyMaxdelayratio(IPAddr *address, double new_max_delay_ratio);
 
 extern int NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum);
 
+extern int NSR_ModifyPolltarget(IPAddr *address, int new_poll_target);
+
 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 1fdbeaf522ed877ce2bda7f21bce05471e27d418..8b735af06971c1fdc8e0914e8d2fddb124e1b646 100644 (file)
@@ -149,6 +149,8 @@ PKL_CommandLength(CMD_Request *r)
         return offsetof(CMD_Request, data.activity.EOR);
       case REQ_MODIFY_MINSTRATUM:
         return offsetof(CMD_Request, data.modify_minstratum.EOR);
+      case REQ_MODIFY_POLLTARGET:
+        return offsetof(CMD_Request, data.modify_polltarget.EOR);
       default:
         /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
         assert(0);