diff --git a/candm.h b/candm.h index 49822b0..5154946 100644 --- a/candm.h +++ b/candm.h @@ -86,7 +86,8 @@ #define REQ_MODIFY_POLLTARGET 46 #define REQ_MODIFY_MAXDELAYDEVRATIO 47 #define REQ_RESELECT 48 -#define N_REQUEST_TYPES 49 +#define REQ_RESELECTDISTANCE 49 +#define N_REQUEST_TYPES 50 /* Special utoken value used to log on with first exchange being the password. (This time value has long since gone by) */ @@ -339,6 +340,11 @@ typedef struct { int32_t EOR; } REQ_Reselect; +typedef struct { + Float distance; + int32_t EOR; +} REQ_ReselectDistance; + /* ================================================== */ #define PKT_TYPE_CMD_REQUEST 1 @@ -425,6 +431,7 @@ typedef struct { REQ_MakeStep make_step; REQ_Activity activity; REQ_Reselect reselect; + REQ_ReselectDistance reselect_distance; } data; /* Command specific parameters */ } CMD_Request; diff --git a/chrony.texi b/chrony.texi index ec755a1..f0931b8 100644 --- a/chrony.texi +++ b/chrony.texi @@ -2934,6 +2934,7 @@ interface. * polltarget command:: Set poll target for a source * quit command:: Exit from chronyc * reselect command:: Reselect synchronisation source +* reselectdist command:: Set improvement in distance needed to reselect a source * retries command:: Set maximum number of retries * rtcdata command:: Display RTC parameters * settime command:: Provide a manual input of the current time @@ -3756,6 +3757,13 @@ available sources. The @code{reselect} command can be used to force @code{chronyd} to reselect the best synchronisation source. @c }}} +@c {{{ reselectdist command +@node reselectdist command +@subsubsection reselectdist +The @code{reselectdist} command sets the reselect distance. It is equivalent +to the @code{reselectdist} directive in the configuration file +(@pxref{reselectdist directive}). +@c }}} @c {{{ retries @node retries command @subsubsection retries diff --git a/client.c b/client.c index 43a9b7c..b8d93bf 100644 --- a/client.c +++ b/client.c @@ -2377,6 +2377,23 @@ process_cmd_activity(const char *line) /* ================================================== */ +static int +process_cmd_reselectdist(CMD_Request *msg, char *line) +{ + double dist; + int ok; + msg->command = htons(REQ_RESELECTDISTANCE); + if (sscanf(line, "%lf", &dist) == 1) { + msg->data.reselect_distance.distance = UTI_FloatHostToNetwork(dist); + ok = 1; + } else { + ok = 0; + } + return ok; +} + +/* ================================================== */ + static void process_cmd_reselect(CMD_Request *msg, char *line) { @@ -2558,6 +2575,8 @@ process_line(char *line, int *quit) } else if (!strncmp(p, "activity", 8)) { ret = process_cmd_activity(p+8); do_normal_submit = 0; + } else if (!strncmp(p, "reselectdist", 12)) { + do_normal_submit = process_cmd_reselectdist(&tx_message, p+12); } else if (!strncmp(p, "reselect", 8)) { process_cmd_reselect(&tx_message, p+8); } else if (!strncmp(p, "dns ", 4)) { diff --git a/cmdmon.c b/cmdmon.c index 561cb40..4aea031 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -158,7 +158,8 @@ static int permissions[] = { PERMIT_AUTH, /* MODIFY_MINSTRATUM */ PERMIT_AUTH, /* MODIFY_POLLTARGET */ PERMIT_AUTH, /* MODIFY_MAXDELAYDEVRATIO */ - PERMIT_AUTH /* RESELECT */ + PERMIT_AUTH, /* RESELECT */ + PERMIT_AUTH /* RESELECTDISTANCE */ }; /* ================================================== */ @@ -1711,6 +1712,18 @@ handle_activity(CMD_Request *rx_message, CMD_Reply *tx_message) /* ================================================== */ +static void +handle_reselect_distance(CMD_Request *rx_message, CMD_Reply *tx_message) +{ + double dist; + dist = UTI_FloatNetworkToHost(rx_message->data.reselect_distance.distance); + SRC_SetReselectDistance(dist); + tx_message->status = htons(STT_SUCCESS); + return; +} + +/* ================================================== */ + static void handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message) { @@ -2258,6 +2271,10 @@ read_from_cmd_socket(void *anything) handle_activity(&rx_message, &tx_message); break; + case REQ_RESELECTDISTANCE: + handle_reselect_distance(&rx_message, &tx_message); + break; + case REQ_RESELECT: handle_reselect(&rx_message, &tx_message); break; diff --git a/pktlength.c b/pktlength.c index 7bde64c..74f35db 100644 --- a/pktlength.c +++ b/pktlength.c @@ -147,6 +147,8 @@ PKL_CommandLength(CMD_Request *r) return offsetof(CMD_Request, data.activity.EOR); case REQ_RESELECT: return offsetof(CMD_Request, data.reselect.EOR); + case REQ_RESELECTDISTANCE: + return offsetof(CMD_Request, data.reselect_distance.EOR); case REQ_MODIFY_MINSTRATUM: return offsetof(CMD_Request, data.modify_minstratum.EOR); case REQ_MODIFY_POLLTARGET: diff --git a/sources.c b/sources.c index 01b0f46..b596ed9 100644 --- a/sources.c +++ b/sources.c @@ -901,6 +901,17 @@ SRC_ReselectSource(void) /* ================================================== */ +void +SRC_SetReselectDistance(double distance) +{ + if (reselect_distance != distance) { + reselect_distance = distance; + LOG(LOGS_INFO, LOGF_Sources, "New reselect distance %f", distance); + } +} + +/* ================================================== */ + double SRC_PredictOffset(SRC_Instance inst, struct timeval *when) { diff --git a/sources.h b/sources.h index 8aeee02..ec98338 100644 --- a/sources.h +++ b/sources.h @@ -140,6 +140,9 @@ extern void SRC_SelectSource(unsigned long match_addr); /* Force reselecting the best source */ extern void SRC_ReselectSource(void); +/* Set reselect distance */ +extern void SRC_SetReselectDistance(double distance); + /* Predict the offset of the local clock relative to a given source at a given local cooked time. Positive indicates local clock is FAST relative to reference. */