summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2005-06-19 16:42:58 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2005-06-19 16:42:58 +0000
commit9880d1789b0653058775cee62ef862098c07cca6 (patch)
tree5d184f82d0c27f91b4d7bf0b55b3a29413deb411
parentd6d80e3d1a87695b6afdb77f389ff41b3c33230e (diff)
use a little state engine to keep track of delayed dns lookups and such,
eases things tested by Jason Ackley <jason@ackley.net> Matthias Kilian <kili@outback.escape.de> Stephen Marley <stephen@marley.org.uk> sturm@ theo ok
-rw-r--r--usr.sbin/ntpd/client.c8
-rw-r--r--usr.sbin/ntpd/ntp.c17
-rw-r--r--usr.sbin/ntpd/ntpd.c22
-rw-r--r--usr.sbin/ntpd/ntpd.h5
-rw-r--r--usr.sbin/ntpd/parse.y6
5 files changed, 40 insertions, 18 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index e03d5a3670a..9e1cf68db19 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.60 2005/04/19 11:08:41 henning Exp $ */
+/* $OpenBSD: client.c,v 1.61 2005/06/19 16:42:57 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -71,11 +71,13 @@ client_addr_init(struct ntp_peer *p)
sa_in = (struct sockaddr_in *)&h->ss;
if (ntohs(sa_in->sin_port) == 0)
sa_in->sin_port = htons(123);
+ p->state = STATE_DNS_DONE;
break;
case AF_INET6:
sa_in6 = (struct sockaddr_in6 *)&h->ss;
if (ntohs(sa_in6->sin6_port) == 0)
sa_in6->sin6_port = htons(123);
+ p->state = STATE_DNS_DONE;
break;
default:
fatal("king bula sez: wrong AF in client_addr_init");
@@ -97,6 +99,7 @@ client_nextaddr(struct ntp_peer *p)
if (p->addr_head.a == NULL) {
priv_host_dns(p->addr_head.name, p->id);
+ p->state = STATE_DNS_INPROGRESS;
return (-1);
}
@@ -119,6 +122,9 @@ client_query(struct ntp_peer *p)
return (0);
}
+ if (p->state < STATE_DNS_DONE || p->addr == NULL)
+ return (-1);
+
if (p->query->fd == -1) {
struct sockaddr *sa = (struct sockaddr *)&p->addr->ss;
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c
index 2cf725a4b76..59f3284b97a 100644
--- a/usr.sbin/ntpd/ntp.c
+++ b/usr.sbin/ntpd/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.60 2005/05/26 09:13:06 dtucker Exp $ */
+/* $OpenBSD: ntp.c,v 1.61 2005/06/19 16:42:57 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -194,13 +194,14 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
idx_peers = i;
sent_cnt = trial_cnt = 0;
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
- if (p->next > 0 && p->next < nextaction)
- nextaction = p->next;
if (p->next > 0 && p->next <= time(NULL)) {
- trial_cnt++;
+ if (p->state > STATE_DNS_INPROGRESS)
+ trial_cnt++;
if (client_query(p) == 0)
sent_cnt++;
}
+ if (p->next > 0 && p->next < nextaction)
+ nextaction = p->next;
if (p->deadline > 0 && p->deadline < nextaction)
nextaction = p->deadline;
@@ -326,7 +327,13 @@ ntp_dispatch_imsg(void)
log_warnx("IMSG_HOST_DNS but addr != NULL!");
break;
}
+
dlen = imsg.hdr.len - IMSG_HEADER_SIZE;
+ if (dlen == 0) { /* no data -> temp error */
+ peer->state = STATE_DNS_TEMPFAIL;
+ break;
+ }
+
p = (u_char *)imsg.data;
while (dlen >= sizeof(struct sockaddr_storage)) {
if ((h = calloc(1, sizeof(struct ntp_addr))) ==
@@ -341,11 +348,13 @@ ntp_dispatch_imsg(void)
npeer->addr = h;
npeer->addr_head.a = h;
client_peer_init(npeer);
+ npeer->state = STATE_DNS_DONE;
peer_add(npeer);
} else {
h->next = peer->addr;
peer->addr = h;
peer->addr_head.a = peer->addr;
+ peer->state = STATE_DNS_DONE;
}
}
if (dlen != 0)
diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c
index 6c635953bec..8cbf68c1c2a 100644
--- a/usr.sbin/ntpd/ntpd.c
+++ b/usr.sbin/ntpd/ntpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.c,v 1.36 2005/05/26 09:13:06 dtucker Exp $ */
+/* $OpenBSD: ntpd.c,v 1.37 2005/06/19 16:42:57 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -289,17 +289,17 @@ dispatch_imsg(struct ntpd_conf *conf)
if (name[imsg.hdr.len] != '\0' ||
strlen(name) != imsg.hdr.len)
fatalx("invalid IMSG_HOST_DNS received");
- if ((cnt = host_dns(name, &hn)) > 0) {
- buf = imsg_create(ibuf, IMSG_HOST_DNS,
- imsg.hdr.peerid, 0,
- cnt * sizeof(struct sockaddr_storage));
- if (buf == NULL)
- break;
- for (h = hn; h != NULL; h = h->next) {
+ cnt = host_dns(name, &hn);
+ buf = imsg_create(ibuf, IMSG_HOST_DNS,
+ imsg.hdr.peerid, 0,
+ cnt * sizeof(struct sockaddr_storage));
+ if (buf == NULL)
+ break;
+ if (cnt > 0)
+ for (h = hn; h != NULL; h = h->next)
imsg_add(buf, &h->ss, sizeof(h->ss));
- }
- imsg_close(ibuf, buf);
- }
+
+ imsg_close(ibuf, buf);
break;
default:
break;
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index 7387c3751f9..2952415de90 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.55 2005/04/26 15:18:22 henning Exp $ */
+/* $OpenBSD: ntpd.h,v 1.56 2005/06/19 16:42:57 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -59,6 +59,9 @@
enum client_state {
STATE_NONE,
+ STATE_DNS_INPROGRESS,
+ STATE_DNS_TEMPFAIL,
+ STATE_DNS_DONE,
STATE_QUERY_SENT,
STATE_REPLY_RECEIVED
};
diff --git a/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y
index 05ed002f5cd..981e03f5103 100644
--- a/usr.sbin/ntpd/parse.y
+++ b/usr.sbin/ntpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.24 2004/11/25 06:27:41 henning Exp $ */
+/* $OpenBSD: parse.y,v 1.25 2005/06/19 16:42:57 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -134,6 +134,8 @@ conf_main : LISTEN ON address {
p->addr_head.name = strdup($2->name);
if (p->addr_head.name == NULL)
fatal(NULL);
+ if (p->addr != NULL)
+ p->state = STATE_DNS_DONE;
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
h = next;
@@ -168,6 +170,8 @@ conf_main : LISTEN ON address {
p->addr_head.name = strdup($2->name);
if (p->addr_head.name == NULL)
fatal(NULL);
+ if (p->addr != NULL)
+ p->state = STATE_DNS_DONE;
TAILQ_INSERT_TAIL(&conf->ntp_peers, p, entry);
free($2->name);
free($2);