]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: allow all parameters to be set for new sources
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 5 Dec 2016 13:47:02 +0000 (14:47 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 6 Dec 2016 15:56:38 +0000 (16:56 +0100)
Add missing fields to the REQ_NTP_Source structure and add new versions
of the ADD_SERVER/ADD_PEER commands.

candm.h
client.c
cmdmon.c
pktlength.c

diff --git a/candm.h b/candm.h
index 5016fdb31875d1ca6c796a0202ae671bf6a2a090..75425b92c30d903b0d92dd854ec4036f9b4d5966 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -95,7 +95,9 @@
 #define REQ_CLIENT_ACCESSES_BY_INDEX2 55
 #define REQ_LOCAL2 56
 #define REQ_NTP_DATA 57
-#define N_REQUEST_TYPES 58
+#define REQ_ADD_SERVER2 58
+#define REQ_ADD_PEER2 59
+#define N_REQUEST_TYPES 60
 
 /* Structure used to exchange timespecs independent of time_t size */
 typedef struct {
@@ -255,9 +257,17 @@ typedef struct {
   int32_t minpoll;
   int32_t maxpoll;
   int32_t presend_minpoll;
+  uint32_t min_stratum;
+  uint32_t poll_target;
+  uint32_t version;
+  uint32_t max_sources;
+  int32_t min_samples;
+  int32_t max_samples;
   uint32_t authkey;
   Float max_delay;
   Float max_delay_ratio;
+  Float max_delay_dev_ratio;
+  Float offset;
   uint32_t flags;
   int32_t EOR;
 } REQ_NTP_Source;
index 7f1a5ffbdd3eea91ac785ad7852150693301e3a9..03e7790629fc5059661513569638fc827a5b12e1 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1073,25 +1073,7 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line)
         break;
       }
 
-      if (data.params.max_delay_dev_ratio != SRC_DEFAULT_MAXDELAYDEVRATIO)
-        opt_name = "maxdelaydevratio";
-      else if (data.params.max_samples != SRC_DEFAULT_MAXSAMPLES)
-        opt_name = "maxsamples";
-      else if (data.params.min_samples != SRC_DEFAULT_MINSAMPLES)
-        opt_name = "minsamples";
-      else if (data.params.max_sources != SRC_DEFAULT_MAXSOURCES)
-        opt_name = "maxsources";
-      else if (data.params.min_stratum != SRC_DEFAULT_MINSTRATUM)
-        opt_name = "minstratum";
-      else if (data.params.offset != 0.0)
-        opt_name = "offset";
-      else if (data.params.poll_target != SRC_DEFAULT_POLLTARGET)
-        opt_name = "polltarget";
-      else if (data.params.version != 0)
-        opt_name = "version";
-      else
-        opt_name = NULL;
-
+      opt_name = NULL;
       if (opt_name) {
         LOG(LOGS_ERR, LOGF_Client, "%s can't be set in chronyc", opt_name);
         break;
@@ -1102,9 +1084,18 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line)
       msg->data.ntp_source.minpoll = htonl(data.params.minpoll);
       msg->data.ntp_source.maxpoll = htonl(data.params.maxpoll);
       msg->data.ntp_source.presend_minpoll = htonl(data.params.presend_minpoll);
+      msg->data.ntp_source.min_stratum = htonl(data.params.min_stratum);
+      msg->data.ntp_source.poll_target = htonl(data.params.poll_target);
+      msg->data.ntp_source.version = htonl(data.params.version);
+      msg->data.ntp_source.max_sources = htonl(data.params.max_sources);
+      msg->data.ntp_source.min_samples = htonl(data.params.min_samples);
+      msg->data.ntp_source.max_samples = htonl(data.params.max_samples);
       msg->data.ntp_source.authkey = htonl(data.params.authkey);
       msg->data.ntp_source.max_delay = UTI_FloatHostToNetwork(data.params.max_delay);
       msg->data.ntp_source.max_delay_ratio = UTI_FloatHostToNetwork(data.params.max_delay_ratio);
+      msg->data.ntp_source.max_delay_dev_ratio =
+        UTI_FloatHostToNetwork(data.params.max_delay_dev_ratio);
+      msg->data.ntp_source.offset = UTI_FloatHostToNetwork(data.params.offset);
       msg->data.ntp_source.flags = htonl(
           (data.params.online ? REQ_ADDSRC_ONLINE : 0) |
           (data.params.auto_offline ? REQ_ADDSRC_AUTOOFFLINE : 0) |
@@ -1127,7 +1118,7 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line)
 static int
 process_cmd_add_server(CMD_Request *msg, char *line)
 {
-  msg->command = htons(REQ_ADD_SERVER);
+  msg->command = htons(REQ_ADD_SERVER2);
   return process_cmd_add_server_or_peer(msg, line);
 }
 
@@ -1136,7 +1127,7 @@ process_cmd_add_server(CMD_Request *msg, char *line)
 static int
 process_cmd_add_peer(CMD_Request *msg, char *line)
 {
-  msg->command = htons(REQ_ADD_PEER);
+  msg->command = htons(REQ_ADD_PEER2);
   return process_cmd_add_server_or_peer(msg, line);
 }
 
index 3a284aa29222bc48731f212c05edc8145dd93157..cbfcdea45c94977db689c5460ce91a9c09c32802 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -134,6 +134,8 @@ static const char permissions[] = {
   PERMIT_AUTH, /* CLIENT_ACCESSES_BY_INDEX2 */
   PERMIT_AUTH, /* LOCAL2 */
   PERMIT_AUTH, /* NTP_DATA */
+  PERMIT_AUTH, /* ADD_SERVER2 */
+  PERMIT_AUTH, /* ADD_PEER2 */
 };
 
 /* ================================================== */
@@ -778,7 +780,20 @@ handle_add_source(NTP_Source_Type type, CMD_Request *rx_message, CMD_Reply *tx_m
   params.minpoll = ntohl(rx_message->data.ntp_source.minpoll);
   params.maxpoll = ntohl(rx_message->data.ntp_source.maxpoll);
   params.presend_minpoll = ntohl(rx_message->data.ntp_source.presend_minpoll);
+  params.min_stratum = ntohl(rx_message->data.ntp_source.min_stratum);
+  params.poll_target = ntohl(rx_message->data.ntp_source.poll_target);
+  params.version = ntohl(rx_message->data.ntp_source.version);
+  params.max_sources = ntohl(rx_message->data.ntp_source.max_sources);
+  params.min_samples = ntohl(rx_message->data.ntp_source.min_samples);
+  params.max_samples = ntohl(rx_message->data.ntp_source.max_samples);
   params.authkey = ntohl(rx_message->data.ntp_source.authkey);
+  params.max_delay = UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay);
+  params.max_delay_ratio =
+    UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_ratio);
+  params.max_delay_dev_ratio =
+    UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_dev_ratio);
+  params.offset = UTI_FloatNetworkToHost(rx_message->data.ntp_source.offset);
+
   params.online  = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_ONLINE ? 1 : 0;
   params.auto_offline = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_AUTOOFFLINE ? 1 : 0;
   params.iburst = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_IBURST ? 1 : 0;
@@ -788,17 +803,6 @@ handle_add_source(NTP_Source_Type type, CMD_Request *rx_message, CMD_Reply *tx_m
     (ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_NOSELECT ? SRC_SELECT_NOSELECT : 0) |
     (ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_TRUST ? SRC_SELECT_TRUST : 0) |
     (ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_REQUIRE ? SRC_SELECT_REQUIRE : 0);
-  params.max_delay = UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay);
-  params.max_delay_ratio = UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_ratio);
-
- /* not transmitted in cmdmon protocol yet */
-  params.min_stratum = SRC_DEFAULT_MINSTRATUM;       
-  params.poll_target = SRC_DEFAULT_POLLTARGET;
-  params.max_delay_dev_ratio = SRC_DEFAULT_MAXDELAYDEVRATIO;
-  params.version = NTP_VERSION;
-  params.max_sources = SRC_DEFAULT_MAXSOURCES;
-  params.min_samples = SRC_DEFAULT_MINSAMPLES;
-  params.max_samples = SRC_DEFAULT_MAXSAMPLES;
 
   status = NSR_AddSource(&rem_addr, type, &params);
   switch (status) {
@@ -1521,11 +1525,11 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
           handle_cmdaccheck(&rx_message, &tx_message);
           break;
 
-        case REQ_ADD_SERVER:
+        case REQ_ADD_SERVER2:
           handle_add_source(NTP_SERVER, &rx_message, &tx_message);
           break;
 
-        case REQ_ADD_PEER:
+        case REQ_ADD_PEER2:
           handle_add_source(NTP_PEER, &rx_message, &tx_message);
           break;
 
index 459b79c37268ca9df35f6e9f1aadf752c20720e9..84facb60d64fe0057d05c8e658439ef3ee880bfb 100644 (file)
@@ -82,8 +82,8 @@ static const struct request_length request_lengths[] = {
   REQ_LENGTH_ENTRY(allow_deny, null),           /* CMDDENYALL */
   REQ_LENGTH_ENTRY(ac_check, null),             /* ACCHECK */
   REQ_LENGTH_ENTRY(ac_check, null),             /* CMDACCHECK */
-  REQ_LENGTH_ENTRY(ntp_source, null),           /* ADD_SERVER */
-  REQ_LENGTH_ENTRY(ntp_source, null),           /* ADD_PEER */
+  { 0, 0 },                                     /* ADD_SERVER */
+  { 0, 0 },                                     /* ADD_PEER */
   REQ_LENGTH_ENTRY(del_source, null),           /* DEL_SOURCE */
   REQ_LENGTH_ENTRY(null, null),                 /* WRITERTC */
   REQ_LENGTH_ENTRY(dfreq, null),                /* DFREQ */
@@ -114,6 +114,8 @@ static const struct request_length request_lengths[] = {
                    client_accesses_by_index),   /* CLIENT_ACCESSES_BY_INDEX2 */
   REQ_LENGTH_ENTRY(local, null),                /* LOCAL2 */
   REQ_LENGTH_ENTRY(ntp_data, ntp_data),         /* NTP_DATA */
+  REQ_LENGTH_ENTRY(ntp_source, null),           /* ADD_SERVER2 */
+  REQ_LENGTH_ENTRY(ntp_source, null),           /* ADD_PEER2 */
 };
 
 static const uint16_t reply_lengths[] = {