summaryrefslogtreecommitdiff
path: root/usr.sbin/ntpd
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-10-05 11:23:29 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-10-05 11:23:29 +0000
commit1ba2fc776609851cbade609a580b57f03fcea59d (patch)
tree9d3b915f6a3629910f239f61260593c0e19e5659 /usr.sbin/ntpd
parent417ece82c5cb68e9191f4e2ab6d635d89be92d7a (diff)
in client_addr_init() and client_nextaddr(), do not set up the socket and
connect it, instead leave it at -1. in client_query, set up and connect the socket if it is -1. and, the real reason for this change: handle connect failures gracefully ok otto
Diffstat (limited to 'usr.sbin/ntpd')
-rw-r--r--usr.sbin/ntpd/client.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index 4b0e9c2e2ed..ca81029be0f 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.36 2004/09/30 10:19:43 henning Exp $ */
+/* $OpenBSD: client.c,v 1.37 2004/10/05 11:23:28 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -83,15 +83,7 @@ client_addr_init(struct ntp_peer *p)
}
}
- if (p->addr != NULL) {
- if ((p->query->fd = socket(p->addr->ss.ss_family,
- SOCK_DGRAM, 0)) == -1)
- fatal("client_query socket");
- if (connect(p->query->fd, (struct sockaddr *)&p->addr->ss,
- p->addr->ss.ss_len) == -1)
- fatal("client_query connect");
- }
-
+ p->query->fd = -1;
set_next(p, 0);
return (0);
@@ -111,12 +103,6 @@ client_nextaddr(struct ntp_peer *p)
if ((p->addr = p->addr->next) == NULL)
p->addr = p->addr_head.a;
- if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1)
- fatal("client_query socket");
- if (connect(p->query->fd, (struct sockaddr *)&p->addr->ss,
- p->addr->ss.ss_len) == -1)
- fatal("client_query connect");
-
p->shift = 0;
p->trustlevel = TRUSTLEVEL_PATHETIC;
@@ -131,6 +117,22 @@ client_query(struct ntp_peer *p)
return (-1);
}
+ if (p->query->fd == -1) {
+ if ((p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM,
+ 0)) == -1)
+ fatal("client_query socket");
+ if (connect(p->query->fd, (struct sockaddr *)&p->addr->ss,
+ p->addr->ss.ss_len) == -1) {
+ if (errno == ECONNREFUSED || errno == ENETUNREACH ||
+ errno == EHOSTUNREACH) {
+ client_nextaddr(p);
+ set_next(p, INTERVAL_QUERY_PATHETIC);
+ return (-1);
+ } else
+ fatal("client_query connect");
+ }
+ }
+
/*
* Send out a random 64-bit number as our transmit time. The NTP
* server will copy said number into the originate field on the