]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: add refresh command
authorGautier PHILIPPON <gautier.philippon@ensimag.grenoble-inp.fr>
Tue, 29 Sep 2015 14:08:43 +0000 (16:08 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 29 Sep 2015 14:42:18 +0000 (16:42 +0200)
This command can be used to resolve the names of configured sources to
IP addresses again.

candm.h
client.c
cmdmon.c
ntp_sources.c
ntp_sources.h
pktlength.c

diff --git a/candm.h b/candm.h
index e21d4945ad71c9946c2563fdd3f0cbd2e48a8678..e4eafb73365983a8df92aa232b5398f593442ec3 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -90,7 +90,8 @@
 #define REQ_MODIFY_MAKESTEP 50
 #define REQ_SMOOTHING 51
 #define REQ_SMOOTHTIME 52
-#define N_REQUEST_TYPES 53
+#define REQ_REFRESH 53
+#define N_REQUEST_TYPES 54
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
index cb8e6bb101d5519f99dc0541b74bf9b14e245163..28a5fc262520c5b34e80f1531a31c1d838dde360 100644 (file)
--- a/client.c
+++ b/client.c
@@ -2293,6 +2293,14 @@ process_cmd_reselect(CMD_Request *msg, char *line)
 
 /* ================================================== */
 
+static void
+process_cmd_refresh(CMD_Request *msg, char *line)
+{
+  msg->command = htons(REQ_REFRESH);
+}
+
+/* ================================================== */
+
 static int
 process_cmd_waitsync(char *line)
 {
@@ -2520,6 +2528,8 @@ process_line(char *line)
     do_normal_submit = 0;
     quit = 1;
     ret = 1;
+  } else if (!strcmp(command, "refresh")) {
+    process_cmd_refresh(&tx_message, line);
   } else if (!strcmp(command, "rekey")) {
     process_cmd_rekey(&tx_message, line);
   } else if (!strcmp(command, "reselect")) {
index 8eaa0a20a11d0a54d969aaee158074cd167f2db4..a5b223d58bde1bb3412e2115d0ea9b842d6019db 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -129,6 +129,7 @@ static const char permissions[] = {
   PERMIT_AUTH, /* MODIFY_MAKESTEP */
   PERMIT_OPEN, /* SMOOTHING */
   PERMIT_AUTH, /* SMOOTHTIME */
+  PERMIT_AUTH, /* REFRESH */
 };
 
 /* ================================================== */
@@ -1140,6 +1141,14 @@ handle_reselect(CMD_Request *rx_message, CMD_Reply *tx_message)
   SRC_ReselectSource();
 }
 
+/* ================================================== */
+
+static void
+handle_refresh(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  NSR_RefreshAddresses();
+}
+
 /* ================================================== */
 /* Read a packet and process it */
 
@@ -1534,6 +1543,10 @@ read_from_cmd_socket(void *anything)
           handle_modify_polltarget(&rx_message, &tx_message);
           break;
 
+        case REQ_REFRESH:
+          handle_refresh(&rx_message, &tx_message);
+          break;
+
         default:
           assert(0);
           break;
index 9c56255199ba1313e77ad4b842bccfaad7d47f35..eca681ccaeec7c632c54feb8ee1b01e24dc4ceb6 100644 (file)
@@ -703,6 +703,23 @@ NSR_HandleBadSource(IPAddr *address)
 
 /* ================================================== */
 
+void
+NSR_RefreshAddresses(void)
+{
+  SourceRecord *record;
+  unsigned int i;
+
+  for (i = 0; i < ARR_GetSize(records); i++) {
+    record = get_record(i);
+    if (!record->remote_addr || !record->name)
+      continue;
+
+    resolve_source_replacement(record);
+  }
+}
+
+/* ================================================== */
+
 static void remove_tentative_pool_sources(int pool)
 {
   SourceRecord *record;
index 828a446e5b19b8a041f6915007085b31a40a917f..9bd2d3bdd39d757cde79377c0121da22e04a2a37 100644 (file)
@@ -80,6 +80,9 @@ extern void NSR_RemoveAllSources(void);
 /* Procedure to try to find a replacement for a bad source */
 extern void NSR_HandleBadSource(IPAddr *address);
 
+/* Procedure to resolve all names again */
+extern void NSR_RefreshAddresses(void);
+
 /* This routine is called by ntp_io when a new packet arrives off the network */
 extern void NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr, int length);
 
index be773c273021c8f9ad277e7da8c5bf969bcaed64..e123ef452fb0f378eae7ed537f23616b459ded60 100644 (file)
@@ -150,6 +150,8 @@ command_unpadded_length(CMD_Request *r)
         return offsetof(CMD_Request, data.null.EOR);
       case REQ_SMOOTHTIME:
         return offsetof(CMD_Request, data.smoothtime.EOR);
+      case REQ_REFRESH:
+        return offsetof(CMD_Request, data.null.EOR);
       default:
         /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
         assert(0);
@@ -304,6 +306,8 @@ PKL_CommandPaddingLength(CMD_Request *r)
       return PADDING_LENGTH(data.null.EOR, data.smoothing.EOR);
     case REQ_SMOOTHTIME:
       return PADDING_LENGTH(data.smoothtime.EOR, data.null.EOR);
+    case REQ_REFRESH:
+      return PADDING_LENGTH(data.null.EOR, data.null.EOR);
     default:
       /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
       assert(0);