Browse Source

Reconnect a client socket after three consecutive send failures.

This allows recovery after an IP address change (e.g. on dialup links).
Also move the update of "nextaction" timeout below the deadline check.
OK henning@
OPENBSD_4_3
mpf 17 years ago
parent
commit
18c1f831f0
3 changed files with 21 additions and 8 deletions
  1. +4
    -1
      src/usr.sbin/ntpd/client.c
  2. +14
    -6
      src/usr.sbin/ntpd/ntp.c
  3. +3
    -1
      src/usr.sbin/ntpd/ntpd.h

+ 4
- 1
src/usr.sbin/ntpd/client.c View File

@ -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 <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -54,6 +54,7 @@ client_peer_init(struct ntp_peer *p)
p->shift = 0; p->shift = 0;
p->trustlevel = TRUSTLEVEL_PATHETIC; p->trustlevel = TRUSTLEVEL_PATHETIC;
p->lasterror = 0; p->lasterror = 0;
p->senderrors = 0;
return (client_addr_init(p)); 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, if (ntp_sendmsg(p->query->fd, NULL, &p->query->msg,
NTP_MSGSIZE_NOAUTH, 0) == -1) { NTP_MSGSIZE_NOAUTH, 0) == -1) {
p->senderrors++;
set_next(p, INTERVAL_QUERY_PATHETIC); set_next(p, INTERVAL_QUERY_PATHETIC);
p->trustlevel = TRUSTLEVEL_PATHETIC; p->trustlevel = TRUSTLEVEL_PATHETIC;
return (-1); return (-1);
} }
p->senderrors = 0;
p->state = STATE_QUERY_SENT; p->state = STATE_QUERY_SENT;
set_deadline(p, QUERYTIME_MAX); set_deadline(p, QUERYTIME_MAX);


+ 14
- 6
src/usr.sbin/ntpd/ntp.c View File

@ -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 <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -229,11 +229,6 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf, struct passwd *pw)
if (client_query(p) == 0) if (client_query(p) == 0)
sent_cnt++; 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()) { if (p->deadline > 0 && p->deadline <= getmonotime()) {
timeout = error_interval(); timeout = error_interval();
log_debug("no reply from %s received in time, " 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); client_nextaddr(p);
set_next(p, timeout); 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 && if (p->state == STATE_QUERY_SENT &&
p->query->fd != -1) { p->query->fd != -1) {


+ 3
- 1
src/usr.sbin/ntpd/ntpd.h View File

@ -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 <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -60,6 +60,7 @@
#define FREQUENCY_SAMPLES 8 /* samples for est. of permanent drift */ #define FREQUENCY_SAMPLES 8 /* samples for est. of permanent drift */
#define MAX_FREQUENCY_ADJUST 128e-5 /* max correction per iteration */ #define MAX_FREQUENCY_ADJUST 128e-5 /* max correction per iteration */
#define REPORT_INTERVAL (24*60*60) /* interval between status reports */ #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) #define SENSOR_DATA_MAXAGE (15*60)
@ -130,6 +131,7 @@ struct ntp_peer {
u_int8_t trustlevel; u_int8_t trustlevel;
u_int8_t weight; u_int8_t weight;
int lasterror; int lasterror;
int senderrors;
}; };
struct ntp_sensor { struct ntp_sensor {


Loading…
Cancel
Save