cmdmon: add onoffline command

The onoffline command tells chronyd to switch all sources to the online
or offline status according to the current network configuration. A
source is considered online if it is possible to send requests to it,
i.e. a route to the network is present.
This commit is contained in:
Miroslav Lichvar 2018-05-24 16:56:56 +02:00
parent 8b9021bf34
commit 34db671b57
5 changed files with 40 additions and 2 deletions

View file

@ -100,7 +100,8 @@
#define REQ_ADD_SERVER3 60
#define REQ_ADD_PEER3 61
#define REQ_SHUTDOWN 62
#define N_REQUEST_TYPES 63
#define REQ_ONOFFLINE 63
#define N_REQUEST_TYPES 64
/* Structure used to exchange timespecs independent of time_t size */
typedef struct {

View file

@ -426,6 +426,14 @@ process_cmd_online(CMD_Request *msg, char *line)
/* ================================================== */
static void
process_cmd_onoffline(CMD_Request *msg, char *line)
{
msg->command = htons(REQ_ONOFFLINE);
}
/* ================================================== */
static int
read_address_integer(char *line, IPAddr *address, int *value)
{
@ -1208,6 +1216,8 @@ give_help(void)
"minstratum <address> <stratum>\0Modify minimum stratum\0"
"offline [<mask>/<address>]\0Set sources in subnet to offline status\0"
"online [<mask>/<address>]\0Set sources in subnet to online status\0"
"onoffline\0Set all sources to online or offline status\0"
"\0according to network configuration\0"
"polltarget <address> <target>\0Modify poll target\0"
"refresh\0Refresh IP addresses\0"
"\0\0"
@ -1279,7 +1289,7 @@ command_name_generator(const char *text, int state)
"deny", "dns", "dump", "exit", "help", "keygen", "local", "makestep",
"manual on", "manual off", "manual delete", "manual list", "manual reset",
"maxdelay", "maxdelaydevratio", "maxdelayratio", "maxpoll",
"maxupdateskew", "minpoll", "minstratum", "ntpdata", "offline", "online",
"maxupdateskew", "minpoll", "minstratum", "ntpdata", "offline", "online", "onoffline",
"polltarget", "quit", "refresh", "rekey", "reselect", "reselectdist",
"retries", "rtcdata", "serverstats", "settime", "shutdown", "smoothing",
"smoothtime", "sources", "sources -v", "sourcestats", "sourcestats -v",
@ -2984,6 +2994,8 @@ process_line(char *line)
do_normal_submit = process_cmd_offline(&tx_message, line);
} else if (!strcmp(command, "online")) {
do_normal_submit = process_cmd_online(&tx_message, line);
} else if (!strcmp(command, "onoffline")) {
process_cmd_onoffline(&tx_message, line);
} else if (!strcmp(command, "polltarget")) {
do_normal_submit = process_cmd_polltarget(&tx_message, line);
} else if (!strcmp(command, "quit")) {

View file

@ -139,6 +139,7 @@ static const char permissions[] = {
PERMIT_AUTH, /* ADD_SERVER3 */
PERMIT_AUTH, /* ADD_PEER3 */
PERMIT_AUTH, /* SHUTDOWN */
PERMIT_AUTH, /* ONOFFLINE */
};
/* ================================================== */
@ -443,6 +444,18 @@ handle_offline(CMD_Request *rx_message, CMD_Reply *tx_message)
/* ================================================== */
static void
handle_onoffline(CMD_Request *rx_message, CMD_Reply *tx_message)
{
IPAddr address, mask;
address.family = mask.family = IPADDR_UNSPEC;
if (!NSR_SetConnectivity(&mask, &address, SRC_MAYBE_ONLINE))
;
}
/* ================================================== */
static void
handle_burst(CMD_Request *rx_message, CMD_Reply *tx_message)
{
@ -1637,6 +1650,10 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
handle_shutdown(&rx_message, &tx_message);
break;
case REQ_ONOFFLINE:
handle_onoffline(&rx_message, &tx_message);
break;
default:
DEBUG_LOG("Unhandled command %d", rx_command);
tx_message.status = htons(STT_FAILED);

View file

@ -722,6 +722,13 @@ particular source or sources has been restored.
+
The syntax is identical to that of the <<offline,*offline*>> command.
[[onoffline]]
*onoffline*::
The *onoffline* command tells *chronyd* to switch all sources to the online or
offline status according to the current network configuration. A source is
considered online if it is possible to send requests to it, i.e. a route to the
network is present.
[[polltarget]]*polltarget* _address_ _polltarget_::
The *polltarget* command is used to modify the poll target for one of the
current set of sources. It is equivalent to the *polltarget* option in the

View file

@ -119,6 +119,7 @@ static const struct request_length request_lengths[] = {
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SERVER3 */
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_PEER3 */
REQ_LENGTH_ENTRY(null, null), /* SHUTDOWN */
REQ_LENGTH_ENTRY(null, null), /* ONOFFLINE */
};
static const uint16_t reply_lengths[] = {