Always use delayed name resolving for server and peer directives
This significantly reduces initialization time.
This commit is contained in:
parent
919b5b5a7d
commit
7fb50d9a3e
6 changed files with 27 additions and 31 deletions
7
client.c
7
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);
|
||||
|
|
10
cmdparse.c
10
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -47,7 +47,6 @@ typedef enum {
|
|||
} CPS_Status;
|
||||
|
||||
typedef struct {
|
||||
IPAddr ip_addr;
|
||||
char *name;
|
||||
unsigned short port;
|
||||
SourceParameters params;
|
||||
|
|
11
conf.c
11
conf.c
|
@ -1286,21 +1286,14 @@ 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_ResolveSources();
|
||||
|
||||
return;
|
||||
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue