summaryrefslogtreecommitdiff
path: root/usr.sbin/ntpd/client.c
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-07-09 10:53:34 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-07-09 10:53:34 +0000
commit0264908561a9c56a148e053b0464128aa89d627a (patch)
tree73c76a62a551ba9de494792fd6ded471164dec4e /usr.sbin/ntpd/client.c
parent9d2a564965b2248467a5330aff3bcc4700d44f0d (diff)
rework dns handling with all its cosequences...
we know have both a "server" and "servers" keyword. they differ when the hostname resolves to more than one IP, server picks one and servers expands to all. that means no longer stuffing a sockaddr_storage into ntp_peer but a pointer to a linked list of ntp_addr structs. in the "servers" case the list of n addresses returned by host() is expanded into n ntp_peer structs and thus n individual peers. in the "server" case the whole list is attached to ntp_peer, and whenever we do not receive a reply in time we traverse the list one further, so that hosts with both AAAA and A records are first tried with the AAAA one but we gracefully fall back to the A one. semantics with theo; hacked up on the Montreal->Frankfurt flight. again Air Canada surprised me, that older 767 hat pretty decent seats.
Diffstat (limited to 'usr.sbin/ntpd/client.c')
-rw-r--r--usr.sbin/ntpd/client.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index 660559bf88d..873056c5806 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.17 2004/07/08 01:20:21 henning Exp $ */
+/* $OpenBSD: client.c,v 1.18 2004/07/09 10:53:33 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -31,27 +31,30 @@ client_peer_init(struct ntp_peer *p)
{
struct sockaddr_in *sa_in;
struct sockaddr_in6 *sa_in6;
+ struct ntp_addr *h;
if ((p->query = calloc(1, sizeof(struct ntp_query))) == NULL)
fatal("client_query calloc");
- switch (p->ss.ss_family) {
- case AF_INET:
- sa_in = (struct sockaddr_in *)&p->ss;
- if (ntohs(sa_in->sin_port) == 0)
- sa_in->sin_port = htons(123);
- break;
- case AF_INET6:
- sa_in6 = (struct sockaddr_in6 *)&p->ss;
- if (ntohs(sa_in6->sin6_port) == 0)
- sa_in6->sin6_port = htons(123);
- break;
- default:
- fatal("king bula sez: wrong AF in client_peer_init");
- /* not reached */
+ for (h = p->addr; h != NULL; h = h->next) {
+ switch (h->ss.ss_family) {
+ case AF_INET:
+ sa_in = (struct sockaddr_in *)&h->ss;
+ if (ntohs(sa_in->sin_port) == 0)
+ sa_in->sin_port = htons(123);
+ break;
+ case AF_INET6:
+ sa_in6 = (struct sockaddr_in6 *)&h->ss;
+ if (ntohs(sa_in6->sin6_port) == 0)
+ sa_in6->sin6_port = htons(123);
+ break;
+ default:
+ fatal("king bula sez: wrong AF in client_peer_init");
+ /* not reached */
+ }
}
- if ((p->query->fd = socket(p->ss.ss_family, SOCK_DGRAM, 0)) == -1)
+ if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1)
fatal("client_query socket");
p->query->msg.status = MODE_CLIENT | (NTP_VERSION << 3);
@@ -64,6 +67,23 @@ client_peer_init(struct ntp_peer *p)
}
int
+client_nextaddr(struct ntp_peer *p)
+{
+ close(p->query->fd);
+
+ if ((p->addr = p->addr->next) == NULL)
+ p->addr = p->addr_head;
+
+ if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1)
+ fatal("client_query socket");
+
+ p->shift = 0;
+ p->trustlevel = TRUSTLEVEL_PATHETIC;
+
+ return (0);
+}
+
+int
client_query(struct ntp_peer *p)
{
/*
@@ -84,8 +104,8 @@ client_query(struct ntp_peer *p)
p->query->msg.xmttime.fraction = arc4random();
p->query->xmttime = gettime();
- ntp_sendmsg(p->query->fd, (struct sockaddr *)&p->ss, &p->query->msg,
- NTP_MSGSIZE_NOAUTH, 0);
+ ntp_sendmsg(p->query->fd, (struct sockaddr *)&p->addr->ss,
+ &p->query->msg, NTP_MSGSIZE_NOAUTH, 0);
p->state = STATE_QUERY_SENT;
p->next = 0;
p->deadline = time(NULL) + QUERYTIME_MAX;