]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: add onoffline command
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 24 May 2018 14:56:56 +0000 (16:56 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 25 May 2018 08:53:21 +0000 (10:53 +0200)
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.

candm.h
client.c
cmdmon.c
doc/chronyc.adoc
pktlength.c

diff --git a/candm.h b/candm.h
index 6ffbb39dc9c1565ea40a0552d80cb6f95a783b02..788633827f486e604682124dd62b3689c97982dd 100644 (file)
--- a/candm.h
+++ b/candm.h
 #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 {
index 774343eec58d878caf2fde1e62094d8f14c32eab..8d2c39118aca327dca1b1606d06a315f2fbdb0d3 100644 (file)
--- 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 <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")) {
index 01cf49ec0e944bba888a06deca9696280ad97825..a2dad92a3f3fa1b02a0ee53770a770dd9e4026d7 100644 (file)
--- 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);
index c987907796d4ed4532f35ca122e0b7fac8cbc505..6b6b7ad6ed26d693a336c00f35452523b79488ee 100644 (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
index 14a43f7b6ebda601db41c2f39981be57dac573c2..3fd4a0b3322b409bfa0db4df91ea45f8d38fc34a 100644 (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[] = {