]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Always use delayed name resolving for server and peer directives
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 26 Aug 2011 12:22:10 +0000 (14:22 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 26 Aug 2011 12:22:10 +0000 (14:22 +0200)
This significantly reduces initialization time.

client.c
cmdparse.c
cmdparse.h
conf.c
ntp_sources.c
ntp_sources.h

index 99fea838f7111d8cccdd0f243928f8c8a4b70447..788ec965f9d791700fd17d576a5beef3ef9f3245 100644 (file)
--- a/client.c
+++ b/client.c
@@ -960,17 +960,18 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line)
 {
   CPS_NTP_Source data;
   CPS_Status status;
+  IPAddr ip_addr;
   int result = 0;
   
   status = CPS_ParseNTPSourceAdd(line, &data);
   switch (status) {
     case CPS_Success:
-      /* Don't retry name resolving */
-      if (data.ip_addr.family == IPADDR_UNSPEC) {
+      if (DNS_Name2IPAddress(data.name, &ip_addr) != DNS_Success) {
         Free(data.name);
         fprintf(stderr, "Invalid host/IP address\n");
         break;
       }
+      Free(data.name);
 
       if (data.params.min_stratum != SRC_DEFAULT_MINSTRATUM) {
         fprintf(stderr, "Option minstratum not supported\n");
@@ -988,7 +989,7 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line)
       }
 
       msg->data.ntp_source.port = htonl((unsigned long) data.port);
-      UTI_IPHostToNetwork(&data.ip_addr, &msg->data.ntp_source.ip_addr);
+      UTI_IPHostToNetwork(&ip_addr, &msg->data.ntp_source.ip_addr);
       msg->data.ntp_source.minpoll = htonl(data.params.minpoll);
       msg->data.ntp_source.maxpoll = htonl(data.params.maxpoll);
       msg->data.ntp_source.presend_minpoll = htonl(data.params.presend_minpoll);
index 0bf249265b1149f5ded1ff3ca4ebee7b0587f7e7..4b878e8e2e28529a15febdea4b5b33395ee38e1c 100644 (file)
@@ -45,7 +45,6 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
   int ok, n, done;
   char cmd[MAXLEN+1], hostname[MAXLEN+1];
   CPS_Status result;
-  DNS_Status s;
   
   src->port = SRC_DEFAULT_PORT;
   src->params.minpoll = SRC_DEFAULT_MINPOLL;
@@ -66,14 +65,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
   
   ok = 0;
   if (sscanf(line, "%" SMAXLEN "s%n", hostname, &n) == 1) {
-    s = DNS_Name2IPAddress(hostname, &src->ip_addr);
-    if (s == DNS_Success) {
-      ok = 1;
-      src->name = NULL;
-    } else if (s == DNS_TryAgain) {
-      ok = 1;
-      src->ip_addr.family = IPADDR_UNSPEC;
-    }
+    ok = 1;
   }
 
   if (!ok) {
@@ -199,7 +191,7 @@ CPS_ParseNTPSourceAdd(const char *line, CPS_NTP_Source *src)
     } while (!done);
   }
 
-  if (ok && src->ip_addr.family == IPADDR_UNSPEC) {
+  if (ok) {
     n = strlen(hostname);
     src->name = MallocArray(char, n + 1);
     strncpy(src->name, hostname, n);
index e1342d9a337ff70dbcc76ec70eb6fab1e3fe4c8e..4b0b9ceab49490af98d9ea4597b12c65e79d28ff 100644 (file)
@@ -47,7 +47,6 @@ typedef enum {
 } CPS_Status;
 
 typedef struct {
-  IPAddr ip_addr;
   char *name;
   unsigned short port;
   SourceParameters params;
diff --git a/conf.c b/conf.c
index d69855084a07227897d1cf9f16150f6f238e89ba..ced1bb740cb3173cc0f6f3134dabeaab704d0722 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -1286,22 +1286,15 @@ CNF_ProcessInitStepSlew(void (*after_hook)(void *), void *anything)
 
 void
 CNF_AddSources(void) {
-  NTP_Remote_Address server;
   int i;
 
   for (i=0; i<n_ntp_sources; i++) {
-    if (ntp_sources[i].params.ip_addr.family != IPADDR_UNSPEC) {
-      server.ip_addr = ntp_sources[i].params.ip_addr;
-      memset(&server.local_ip_addr, 0, sizeof (server.local_ip_addr));
-      server.port = ntp_sources[i].params.port;
-
-      NSR_AddSource(&server, ntp_sources[i].type, &ntp_sources[i].params.params);
-    } else {
-      NSR_AddUnresolvedSource(ntp_sources[i].params.name, ntp_sources[i].params.port,
-          ntp_sources[i].type, &ntp_sources[i].params.params);
-    }
+    NSR_AddUnresolvedSource(ntp_sources[i].params.name, ntp_sources[i].params.port,
+        ntp_sources[i].type, &ntp_sources[i].params.params);
   }
 
+  NSR_ResolveSources();
+
   return;
 
 }
index 43a5d91d06b794043f2df3110d18c718eefded8b..f7fce83540c8dbb637fcb977ae22ecbdcf5c88aa 100644 (file)
@@ -287,6 +287,19 @@ NSR_AddUnresolvedSource(char *name, int port, NTP_Source_Type type, SourceParame
 
 /* ================================================== */
 
+void
+NSR_ResolveSources(void)
+{
+  /* Try to resolve unresolved sources now */
+  if (resolving_interval) {
+    SCH_RemoveTimeout(resolving_id);
+    resolving_interval--;
+    resolve_sources(NULL);
+  }
+}
+
+/* ================================================== */
+
 /* Procedure to remove a source.  We don't bother whether the port
    address is matched - we're only interested in removing a record for
    the right IP address.  Thus the caller can specify the port number
@@ -406,12 +419,7 @@ NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address)
   int i;
   int any;
 
-  /* Try to resolve unresolved sources now */
-  if (resolving_interval) {
-    SCH_RemoveTimeout(resolving_id);
-    resolving_interval--;
-    resolve_sources(NULL);
-  }
+  NSR_ResolveSources();
 
   any = 0;
   for (i=0; i<N_RECORDS; i++) {
index bf37af21e96001019d0559eb302e192749182b54..654cb0566bb6bfceaaa4543f97023f67343cc1de 100644 (file)
@@ -54,6 +54,9 @@ extern NSR_Status NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type
    until it succeeds or fails with a non-temporary error. */
 extern void NSR_AddUnresolvedSource(char *name, int port, NTP_Source_Type type, SourceParameters *params);
 
+/* Procedure to try resolve unresolved sources immediately. */
+extern void NSR_ResolveSources(void);
+
 /* Procedure to remove a source */
 extern NSR_Status NSR_RemoveSource(NTP_Remote_Address *remote_addr);