This significantly reduces initialization time.
{
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");
}
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);
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;
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) {
} 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);
} CPS_Status;
typedef struct {
- IPAddr ip_addr;
char *name;
unsigned short port;
SourceParameters params;
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;
}
/* ================================================== */
+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
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++) {
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);