From 65fd30a5473f0a13a216e2d481236ebe54058b41 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 5 Dec 2016 14:47:02 +0100 Subject: [PATCH] cmdmon: allow all parameters to be set for new sources Add missing fields to the REQ_NTP_Source structure and add new versions of the ADD_SERVER/ADD_PEER commands. --- candm.h | 12 +++++++++++- client.c | 33 ++++++++++++--------------------- cmdmon.c | 30 +++++++++++++++++------------- pktlength.c | 6 ++++-- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/candm.h b/candm.h index 5016fdb..75425b9 100644 --- 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; diff --git a/client.c b/client.c index 7f1a5ff..03e7790 100644 --- 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); } diff --git a/cmdmon.c b/cmdmon.c index 3a284aa..cbfcdea 100644 --- 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, ¶ms); 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; diff --git a/pktlength.c b/pktlength.c index 459b79c..84facb6 100644 --- a/pktlength.c +++ b/pktlength.c @@ -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[] = {