Browse Source

Be more careful setting next and deadline, they should not both be != 0

at the same time.
ok henning@
OPENBSD_3_6
otto 20 years ago
parent
commit
3fa78249ed
1 changed files with 22 additions and 9 deletions
  1. +22
    -9
      src/usr.sbin/ntpd/client.c

+ 22
- 9
src/usr.sbin/ntpd/client.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.31 2004/08/13 12:26:13 otto Exp $ */
/* $OpenBSD: client.c,v 1.32 2004/08/16 11:14:15 otto Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -27,6 +27,22 @@
#include "ntpd.h" #include "ntpd.h"
int client_update(struct ntp_peer *); int client_update(struct ntp_peer *);
void set_next(struct ntp_peer *, time_t);
void set_deadline(struct ntp_peer *, time_t);
void
set_next(struct ntp_peer *p, time_t t)
{
p->next = time(NULL) + t;
p->deadline = 0;
}
void
set_deadline(struct ntp_peer *p, time_t t)
{
p->deadline = time(NULL) + t;
p->next = 0;
}
int int
client_peer_init(struct ntp_peer *p) client_peer_init(struct ntp_peer *p)
@ -71,7 +87,7 @@ client_addr_init(struct ntp_peer *p)
(p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1) (p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0)) == -1)
fatal("client_query socket"); fatal("client_query socket");
p->next = time(NULL);
set_next(p, 0);
return (0); return (0);
} }
@ -102,7 +118,7 @@ int
client_query(struct ntp_peer *p) client_query(struct ntp_peer *p)
{ {
if (p->addr == NULL && client_nextaddr(p) == -1) { if (p->addr == NULL && client_nextaddr(p) == -1) {
p->next = time(NULL) + INTERVAL_QUERY_PATHETIC;
set_next(p, INTERVAL_QUERY_PATHETIC);
return (-1); return (-1);
} }
@ -126,14 +142,12 @@ client_query(struct ntp_peer *p)
if (ntp_sendmsg(p->query->fd, (struct sockaddr *)&p->addr->ss, if (ntp_sendmsg(p->query->fd, (struct sockaddr *)&p->addr->ss,
&p->query->msg, NTP_MSGSIZE_NOAUTH, 0) == -1) { &p->query->msg, NTP_MSGSIZE_NOAUTH, 0) == -1) {
p->next = time(NULL) + INTERVAL_QUERY_PATHETIC;
p->deadline = 0;
set_next(p, INTERVAL_QUERY_PATHETIC);
return (-1); return (-1);
} }
p->state = STATE_QUERY_SENT; p->state = STATE_QUERY_SENT;
p->next = 0;
p->deadline = time(NULL) + QUERYTIME_MAX;
set_deadline(p, QUERYTIME_MAX);
return (0); return (0);
} }
@ -223,8 +237,7 @@ client_dispatch(struct ntp_peer *p)
(QSCALE_OFF_MAX / abs_offset); (QSCALE_OFF_MAX / abs_offset);
} }
p->next = time(NULL) + interval;
p->deadline = 0;
set_next(p, interval);
p->state = STATE_REPLY_RECEIVED; p->state = STATE_REPLY_RECEIVED;
/* every received reply which we do not discard increases trust */ /* every received reply which we do not discard increases trust */


Loading…
Cancel
Save