diff --git a/candm.h b/candm.h index 6ffbb39..7886338 100644 --- a/candm.h +++ b/candm.h @@ -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 { diff --git a/client.c b/client.c index 774343e..8d2c391 100644 --- a/client.c +++ b/client.c @@ -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
\0Modify minimum stratum\0" "offline [/
]\0Set sources in subnet to offline status\0" "online [/
]\0Set sources in subnet to online status\0" + "onoffline\0Set all sources to online or offline status\0" + "\0according to network configuration\0" "polltarget
\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")) { diff --git a/cmdmon.c b/cmdmon.c index 01cf49e..a2dad92 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -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); diff --git a/doc/chronyc.adoc b/doc/chronyc.adoc index c987907..6b6b7ad 100644 --- a/doc/chronyc.adoc +++ b/doc/chronyc.adoc @@ -722,6 +722,13 @@ particular source or sources has been restored. + The syntax is identical to that of the <> 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 diff --git a/pktlength.c b/pktlength.c index 14a43f7..3fd4a0b 100644 --- a/pktlength.c +++ b/pktlength.c @@ -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[] = {