Skip to content

Commit 5c3bc18

Browse files
committed
refclock_acts.c, ntp_peer.c, ChangeLog, ntp_proto.c, ntp_config.c:
Association and other cleanup from Dave Mills ntp.h: NTP_UNREACH changes from Dave Mills. bk: 4716f4b3DzMmmMOZZHXbwPqtpmVKBg
1 parent 04a2d09 commit 5c3bc18

File tree

6 files changed

+82
-125
lines changed

6 files changed

+82
-125
lines changed

ChangeLog

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Association and other cleanup from Dave Mills.
2+
* NTP_UNREACH changes from Dave Mills.
13
* Fix the readline history test.
24
* [Bug 931] Require -lreadline to be asked for explicitly.
35
* [Bug 764] When looking for -lreadline support, also try using -lncurses.

include/ntp.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ typedef char s_char;
103103
/*
104104
* Poll interval parameters
105105
*/
106-
#define NTP_UNREACH 24 /* poll unreach threshold */
106+
#define NTP_UNREACH 10 /* poll unreach threshold */
107107
#define NTP_MINPOLL 4 /* log2 min poll interval (16 s) */
108108
#define NTP_MINDPOLL 6 /* log2 default min poll (64 s) */
109109
#define NTP_MAXDPOLL 10 /* log2 default max poll (~17 m) */
@@ -363,7 +363,7 @@ struct peer {
363363
*/
364364
u_long update; /* receive epoch */
365365
#define end_clear_to_zero update
366-
u_int unreach; /* unreachable count */
366+
u_int unreach; /* watchdog counter */
367367
u_long outdate; /* send time last packet */
368368
u_long nextdate; /* send time next packet */
369369
u_long nextaction; /* peer local activity timeout (refclocks) */

ntpd/ntp_config.c

+20-24
Original file line numberDiff line numberDiff line change
@@ -1768,32 +1768,28 @@ config_peers(void)
17681768
*/
17691769
else {
17701770
res_bak = res;
1771-
/* Loop to configure the desired number of associations
1771+
1772+
/*
1773+
* Loop to configure the desired number of
1774+
* associations
17721775
*/
1773-
for (i = 0; (i < no_needed) && res; res = res->ai_next) {
1776+
for (i = 0; (i < no_needed) && res; res =
1777+
res->ai_next) {
17741778
++i;
1775-
memcpy(&peeraddr, res->ai_addr, res->ai_addrlen);
1776-
#ifdef DEBUG
1777-
if (debug > 1)
1778-
printf("configuring host %s with address %s\n",
1779-
curr_peer->addr->address, stoa(&peeraddr));
1780-
#endif
1781-
if (is_sane_resolved_address(peeraddr, curr_peer->host_mode)) {
1782-
if (peer_config(&peeraddr,
1783-
ANY_INTERFACE_CHOOSE(&peeraddr),
1784-
hmode,
1785-
curr_peer->peerversion,
1786-
curr_peer->minpoll,
1787-
curr_peer->maxpoll,
1788-
curr_peer->peerflags,
1789-
curr_peer->ttl,
1790-
curr_peer->peerkey,
1791-
(u_char *)"*") == 0) {
1792-
msyslog(LOG_ERR,
1793-
"configuration of %s failed",
1794-
stoa(&peeraddr));
1795-
}
1796-
}
1779+
memcpy(&peeraddr, res->ai_addr,
1780+
res->ai_addrlen);
1781+
if (is_sane_resolved_address(peeraddr,
1782+
curr_peer->host_mode))
1783+
peer_config(&peeraddr,
1784+
ANY_INTERFACE_CHOOSE(&peeraddr),
1785+
hmode,
1786+
curr_peer->peerversion,
1787+
curr_peer->minpoll,
1788+
curr_peer->maxpoll,
1789+
curr_peer->peerflags,
1790+
curr_peer->ttl,
1791+
curr_peer->peerkey,
1792+
(u_char *)"*");
17971793
}
17981794
freeaddrinfo(res_bak);
17991795
}

ntpd/ntp_peer.c

+45-65
Original file line numberDiff line numberDiff line change
@@ -426,63 +426,36 @@ peer_config(
426426
u_char *keystr
427427
)
428428
{
429-
register struct peer *peer;
430429
u_char cast_flags;
431430

432-
/*
433-
* First search from the beginning for an association with given
434-
* remote address and mode. If an interface is given, search
435-
* from there to find the association which matches that
436-
* destination. If the given interface is "any", track down
437-
* the actual interface, because that's what gets put into the
438-
* peer structure.
439-
*/
440-
peer = findexistingpeer(srcadr, (struct peer *)0, hmode);
441-
if (dstadr != 0) {
442-
while (peer != 0) {
443-
if (peer->dstadr == dstadr)
444-
break;
445-
446-
if (dstadr == ANY_INTERFACE_CHOOSE(srcadr) &&
447-
peer->dstadr == findinterface(srcadr))
448-
break;
449-
450-
peer = findexistingpeer(srcadr, peer, hmode);
451-
}
452-
}
453-
454431
/*
455432
* We do a dirty little jig to figure the cast flags. This is
456433
* probably not the best place to do this, at least until the
457434
* configure code is rebuilt. Note only one flag can be set.
458435
*/
459436
switch (hmode) {
460-
461437
case MODE_BROADCAST:
462438
if(srcadr->ss_family == AF_INET) {
463439
if (IN_CLASSD(ntohl(((struct sockaddr_in*)srcadr)->sin_addr.s_addr)))
464440
cast_flags = MDF_MCAST;
465441
else
466442
cast_flags = MDF_BCAST;
467443
break;
468-
}
469-
else {
444+
} else {
470445
if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)srcadr)->sin6_addr))
471446
cast_flags = MDF_MCAST;
472447
else
473448
cast_flags = MDF_BCAST;
474449
break;
475450
}
476-
477451
case MODE_CLIENT:
478452
if(srcadr->ss_family == AF_INET) {
479453
if (IN_CLASSD(ntohl(((struct sockaddr_in*)srcadr)->sin_addr.s_addr)))
480454
cast_flags = MDF_ACAST;
481455
else
482456
cast_flags = MDF_UCAST;
483457
break;
484-
}
485-
else {
458+
} else {
486459
if (IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6*)srcadr)->sin6_addr))
487460
cast_flags = MDF_ACAST;
488461
else
@@ -495,34 +468,13 @@ peer_config(
495468
}
496469

497470
/*
498-
* If the peer is already configured, some dope has a duplicate
499-
* configureation entry or another dope is wiggling from afar.
500-
*/
501-
if (peer != 0) {
502-
peer->hmode = (u_char)hmode;
503-
peer->version = (u_char) version;
504-
peer->minpoll = (u_char) minpoll;
505-
peer->maxpoll = (u_char) maxpoll;
506-
peer->flags = flags | FLAG_CONFIG |
507-
(peer->flags & FLAG_REFCLOCK);
508-
peer->cast_flags = cast_flags;
509-
peer->ttl = (u_char) ttl;
510-
peer->keyid = key;
511-
peer->precision = sys_precision;
512-
peer_clear(peer, "RMOT");
513-
return (peer);
514-
}
515-
516-
/*
517-
* Here no match has been found, so presumably this is a new
518-
* persistent association. Mobilize the thing and initialize its
519-
* variables. If emulating ntpdate, force iburst.
471+
* Mobilize the association and initialize its variables. If
472+
* emulating ntpdate, force iburst.
520473
*/
521474
if (mode_ntpdate)
522475
flags |= FLAG_IBURST;
523-
peer = newpeer(srcadr, dstadr, hmode, version, minpoll, maxpoll,
524-
flags | FLAG_CONFIG, cast_flags, ttl, key);
525-
return (peer);
476+
return(newpeer(srcadr, dstadr, hmode, version, minpoll, maxpoll,
477+
flags | FLAG_CONFIG, cast_flags, ttl, key));
526478
}
527479

528480
/*
@@ -724,12 +676,42 @@ newpeer(
724676
keyid_t key
725677
)
726678
{
727-
register struct peer *peer;
728-
register int i;
679+
struct peer *peer;
680+
int i;
729681
#ifdef OPENSSL
730682
char statstr[NTP_MAXSTRLEN]; /* statistics for filegen */
731683
#endif /* OPENSSL */
732684

685+
/*
686+
* First search from the beginning for an association with given
687+
* remote address and mode. If an interface is given, search
688+
* from there to find the association which matches that
689+
* destination. If the given interface is "any", track down the
690+
* actual interface, because that's what gets put into the peer
691+
* structure.
692+
*/
693+
peer = findexistingpeer(srcadr, (struct peer *)0, hmode);
694+
if (dstadr != 0) {
695+
while (peer != 0) {
696+
if (peer->dstadr == dstadr)
697+
break;
698+
699+
if (dstadr == ANY_INTERFACE_CHOOSE(srcadr) &&
700+
peer->dstadr == findinterface(srcadr))
701+
break;
702+
703+
peer = findexistingpeer(srcadr, peer, hmode);
704+
}
705+
}
706+
707+
/*
708+
* If a peer is found, this would be a duplicate and we don't
709+
* allow that. This is mostly to avoid duplicate pool
710+
* associations.
711+
*/
712+
if (peer != NULL)
713+
return (NULL);
714+
733715
/*
734716
* Allocate a new peer structure. Some dirt here, since some of
735717
* the initialization requires knowlege of our system state.
@@ -857,12 +839,10 @@ newpeer(
857839
#endif /* OPENSSL */
858840

859841
DPRINTF(1, ("newpeer: %s->%s mode %d vers %d poll %d %d flags 0x%x 0x%x ttl %d key %08x\n",
860-
peer->dstadr == NULL ? "<null>" : stoa(&peer->dstadr->sin),
861-
stoa(&peer->srcadr),
862-
peer->hmode, peer->version, peer->minpoll,
863-
peer->maxpoll, peer->flags, peer->cast_flags,
864-
peer->ttl, peer->keyid));
865-
842+
peer->dstadr == NULL ? "<null>" : stoa(&peer->dstadr->sin),
843+
stoa(&peer->srcadr), peer->hmode, peer->version,
844+
peer->minpoll, peer->maxpoll, peer->flags, peer->cast_flags,
845+
peer->ttl, peer->keyid));
866846
return (peer);
867847
}
868848

@@ -896,13 +876,13 @@ peer_unconfig(
896876
* mode. The protocol will eventually terminate
897877
* undesirables on its own.
898878
*/
899-
if (peer->hmode == MODE_ACTIVE
900-
&& peer->pmode == MODE_ACTIVE) {
879+
if (peer->hmode == MODE_ACTIVE && peer->pmode ==
880+
MODE_ACTIVE) {
901881
peer->hmode = MODE_PASSIVE;
902882
peer->flags &= ~FLAG_CONFIG;
903883
} else {
904884
unpeer(peer);
905-
peer = 0;
885+
peer = NULL;
906886
}
907887
}
908888
peer = findexistingpeer(srcadr, peer, mode);

ntpd/ntp_proto.c

+11-34
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,19 @@ transmit(
210210
*/
211211
oreach = peer->reach & 0xfe;
212212
peer->outdate = current_time;
213+
peer->unreach++;
213214
peer->reach <<= 1;
214215
if (!(peer->reach & 0x0f))
215216
clock_filter(peer, 0., 0., MAXDISPERSE);
216217
if (!peer->reach) {
217218

218219
/*
219220
* Here the peer is unreachable. If it was
220-
* previously reachable raise a trap. Bump the
221-
* unreach counter such that the association
222-
* times out in a reasonable time after becoming
223-
* unreachable.
224-
*/
221+
* previously reachable raise a trap. */
225222
if (oreach) {
226223
report_event(EVNT_UNREACH, peer);
227224
peer->timereachable = current_time;
228225
}
229-
peer->unreach += 2;
230226
} else {
231227

232228
/*
@@ -236,29 +232,11 @@ transmit(
236232
* only if enabled and the peer is fit.
237233
*/
238234
hpoll = sys_poll;
235+
if (!oreach)
236+
peer->unreach = 0;
239237
if (peer->flags & FLAG_BURST &&
240238
!peer_unfit(peer))
241239
peer->burst = NTP_BURST;
242-
243-
/*
244-
* Respond to the peer evaluation produced by
245-
* the selection algorithm. If less than the
246-
* outlyer level, up the unreach by three. If
247-
* there are excess associations, up the unreach
248-
* by two if not a candidate and by one if so.
249-
*/
250-
if (!(peer->flags & FLAG_PREEMPT)) {
251-
peer->unreach = 0;
252-
} else if (peer->status < CTL_PST_SEL_SELCAND) {
253-
peer->unreach += 3;
254-
} else if (peer_preempt > sys_maxclock) {
255-
if (peer->status < CTL_PST_SEL_SYNCCAND)
256-
peer->unreach += 2;
257-
else
258-
peer->unreach++;
259-
} else {
260-
peer->unreach = 0;
261-
}
262240
}
263241

264242
/*
@@ -781,7 +759,7 @@ receive(
781759
hisversion, NTP_MINDPOLL, NTP_MAXDPOLL,
782760
FLAG_IBURST | FLAG_PREEMPT, MDF_UCAST | MDF_ACLNT,
783761
0, skeyid)) == NULL)
784-
return; /* system error */
762+
return; /* ignore duplicate */
785763

786764
/*
787765
* We don't need these, but it warms the billboards.
@@ -832,7 +810,7 @@ receive(
832810
pkt->ppoll, max(pkt->ppoll, allan_xpt - 5),
833811
FLAG_MCAST | FLAG_IBURST, MDF_BCLNT, 0,
834812
skeyid)) == NULL)
835-
return; /* system error */
813+
return; /* ignore duplicate */
836814
#ifdef OPENSSL
837815
/*
838816
* Ordinarily this will be an association reply
@@ -867,7 +845,7 @@ receive(
867845
rbufp->dstadr, MODE_BCLIENT, hisversion,
868846
pkt->ppoll, max(pkt->ppoll, allan_xpt - 5),
869847
0, MDF_BCLNT, 0, skeyid)) == NULL)
870-
return; /* system error */
848+
return; /* ignore duplicate */
871849
}
872850
break;
873851

@@ -912,7 +890,7 @@ receive(
912890
rbufp->dstadr, MODE_PASSIVE, hisversion,
913891
NTP_MINDPOLL, NTP_MAXDPOLL, 0, MDF_UCAST, 0,
914892
skeyid)) == NULL)
915-
return; /* system error */
893+
return; /* ignore duplicate */
916894
break;
917895

918896
/*
@@ -1044,9 +1022,6 @@ receive(
10441022
if (rval != XEVNT_OK) {
10451023
peer_clear(peer, "CRYP");
10461024
peer->flash |= TEST9; /* crypto error */
1047-
if (peer->flags & FLAG_PREEMPT ||
1048-
!(peer->flags & FLAG_CONFIG))
1049-
unpeer(peer);
10501025
return;
10511026

10521027
} else if (hismode == MODE_SERVER) {
@@ -2327,8 +2302,10 @@ clock_select(void)
23272302
*/
23282303
leap_next = 0;
23292304
for (i = 0; i < nlist; i++) {
2330-
peer = peer_list[i];
23312305
sys_survivors++;
2306+
peer = peer_list[i];
2307+
if (i < sys_maxclock)
2308+
peer->unreach = 0;
23322309
if (peer->leap == LEAP_ADDSECOND) {
23332310
if (peer->flags & FLAG_REFCLOCK)
23342311
leap_next = nlist;

ntpd/refclock_acts.c

+2
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ acts_timeout(
770770
fd = refclock_open(device, SPEED232,
771771
LDISC_ACTS | LDISC_RAW | LDISC_REMOTE);
772772
if (fd == 0) {
773+
msyslog(LOG_ERR,
774+
"acts: open fails");
773775
return;
774776
}
775777
pp->io.fd = fd;

0 commit comments

Comments
 (0)