From 7fb50d9a3ebcb9c6c46b59731176840a6e38eee5 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 26 Aug 2011 14:22:10 +0200 Subject: [PATCH] Always use delayed name resolving for server and peer directives This significantly reduces initialization time. --- client.c | 7 ++++--- cmdparse.c | 12 ++---------- cmdparse.h | 1 - conf.c | 15 ++++----------- ntp_sources.c | 20 ++++++++++++++------ ntp_sources.h | 3 +++ 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/client.c b/client.c index 99fea83..788ec96 100644 --- 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); diff --git a/cmdparse.c b/cmdparse.c index 0bf2492..4b878e8 100644 --- a/cmdparse.c +++ b/cmdparse.c @@ -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); diff --git a/cmdparse.h b/cmdparse.h index e1342d9..4b0b9ce 100644 --- a/cmdparse.h +++ b/cmdparse.h @@ -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 d698550..ced1bb7 100644 --- 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