diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c index 157e06c1..0eae0c5b 100644 --- a/src/usr.sbin/ntpd/client.c +++ b/src/usr.sbin/ntpd/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.78 2007/12/27 01:46:50 stevesk Exp $ */ +/* $OpenBSD: client.c,v 1.79 2008/01/28 11:45:59 mpf Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -54,6 +54,7 @@ client_peer_init(struct ntp_peer *p) p->shift = 0; p->trustlevel = TRUSTLEVEL_PATHETIC; p->lasterror = 0; + p->senderrors = 0; return (client_addr_init(p)); } @@ -172,11 +173,13 @@ client_query(struct ntp_peer *p) if (ntp_sendmsg(p->query->fd, NULL, &p->query->msg, NTP_MSGSIZE_NOAUTH, 0) == -1) { + p->senderrors++; set_next(p, INTERVAL_QUERY_PATHETIC); p->trustlevel = TRUSTLEVEL_PATHETIC; return (-1); } + p->senderrors = 0; p->state = STATE_QUERY_SENT; set_deadline(p, QUERYTIME_MAX); diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c index 1da3eef6..28234875 100644 --- a/src/usr.sbin/ntpd/ntp.c +++ b/src/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.102 2007/12/27 01:46:50 stevesk Exp $ */ +/* $OpenBSD: ntp.c,v 1.103 2008/01/28 11:45:59 mpf Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -229,11 +229,6 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf, struct passwd *pw) 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; if (p->deadline > 0 && p->deadline <= getmonotime()) { timeout = error_interval(); log_debug("no reply from %s received in time, " @@ -247,6 +242,19 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf, struct passwd *pw) client_nextaddr(p); set_next(p, timeout); } + if (p->senderrors > MAX_SEND_ERRORS) { + log_debug("failed to send query to %s, " + "next query %ds", log_sockaddr( + (struct sockaddr *)&p->addr->ss), + INTERVAL_QUERY_PATHETIC); + p->senderrors = 0; + client_nextaddr(p); + set_next(p, INTERVAL_QUERY_PATHETIC); + } + if (p->next > 0 && p->next < nextaction) + nextaction = p->next; + if (p->deadline > 0 && p->deadline < nextaction) + nextaction = p->deadline; if (p->state == STATE_QUERY_SENT && p->query->fd != -1) { diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h index efbb286e..323ca05e 100644 --- a/src/usr.sbin/ntpd/ntpd.h +++ b/src/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.90 2007/12/23 18:39:50 stevesk Exp $ */ +/* $OpenBSD: ntpd.h,v 1.91 2008/01/28 11:45:59 mpf Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -60,6 +60,7 @@ #define FREQUENCY_SAMPLES 8 /* samples for est. of permanent drift */ #define MAX_FREQUENCY_ADJUST 128e-5 /* max correction per iteration */ #define REPORT_INTERVAL (24*60*60) /* interval between status reports */ +#define MAX_SEND_ERRORS 3 /* max send errors before reconnect */ #define SENSOR_DATA_MAXAGE (15*60) @@ -130,6 +131,7 @@ struct ntp_peer { u_int8_t trustlevel; u_int8_t weight; int lasterror; + int senderrors; }; struct ntp_sensor {