ntp_proto.c (ntp-4.2.8p14) | : | ntp_proto.c (ntp-4.2.8p15) | ||
---|---|---|---|---|
skipping to change at line 1328 | skipping to change at line 1328 | |||
return; | return; | |||
} | } | |||
#endif /* AUTOKEY */ | #endif /* AUTOKEY */ | |||
/* | /* | |||
* Do not respond if we are not synchronized or our | * Do not respond if we are not synchronized or our | |||
* stratum is greater than the manycaster or the | * stratum is greater than the manycaster or the | |||
* manycaster has already synchronized to us. | * manycaster has already synchronized to us. | |||
*/ | */ | |||
if ( sys_leap == LEAP_NOTINSYNC | if ( sys_leap == LEAP_NOTINSYNC | |||
|| sys_stratum >= hisstratum | || sys_stratum > hisstratum + 1 | |||
|| (!sys_cohort && sys_stratum == hisstratum + 1) | || (!sys_cohort && sys_stratum == hisstratum + 1) | |||
|| rbufp->dstadr->addr_refid == pkt->refid) { | || rbufp->dstadr->addr_refid == pkt->refid) { | |||
DPRINTF(2, ("receive: sys leap: %0x, sys_stratum %d > his stratum+1 %d, !sys_cohort %d && sys_stratum == hisstratum+1, loop refid %#x == p kt refid %#x\n", sys_leap, sys_stratum, hisstratum + 1, !sys_cohort, rbufp->dsta dr->addr_refid, pkt->refid)); | ||||
DPRINTF(2, ("receive: AM_FXMIT drop: LEAP_NOTINSYNC || st ratum || loop\n")); | DPRINTF(2, ("receive: AM_FXMIT drop: LEAP_NOTINSYNC || st ratum || loop\n")); | |||
sys_declined++; | sys_declined++; | |||
return; /* no help */ | return; /* no help */ | |||
} | } | |||
/* | /* | |||
* Respond only if authentication succeeds. Don't do a | * Respond only if authentication succeeds. Don't do a | |||
* crypto-NAK, as that would not be useful. | * crypto-NAK, as that would not be useful. | |||
*/ | */ | |||
if (AUTH(restrict_mask & RES_DONTTRUST, is_authentic)) { | if (AUTH(restrict_mask & RES_DONTTRUST, is_authentic)) { | |||
skipping to change at line 1676 | skipping to change at line 1677 | |||
* Do not respond if synchronized and if stratum is | * Do not respond if synchronized and if stratum is | |||
* below the floor or at or above the ceiling. Note, | * below the floor or at or above the ceiling. Note, | |||
* this allows an unsynchronized peer to synchronize to | * this allows an unsynchronized peer to synchronize to | |||
* us. It would be very strange if he did and then was | * us. It would be very strange if he did and then was | |||
* nipped, but that could only happen if we were | * nipped, but that could only happen if we were | |||
* operating at the top end of the range. It also means | * operating at the top end of the range. It also means | |||
* we will spin an ephemeral association in response to | * we will spin an ephemeral association in response to | |||
* MODE_ACTIVE KoDs, which will time out eventually. | * MODE_ACTIVE KoDs, which will time out eventually. | |||
*/ | */ | |||
if ( hisleap != LEAP_NOTINSYNC | if ( hisleap != LEAP_NOTINSYNC | |||
&& (hisstratum < sys_floor || hisstratum >= sys_ceiling)) { | && (hisstratum < sys_floor || hisstratum >= sys_ceiling)) | |||
DPRINTF(2, ("receive: AM_NEWPASS drop: Autokey group mism | { | |||
atch\n")); | DPRINTF(2, ("receive: AM_NEWPASS drop: Remote stratum (%d | |||
) out of range\n", | ||||
hisstratum)); | ||||
sys_declined++; | sys_declined++; | |||
return; /* no help */ | return; /* no help */ | |||
} | } | |||
/* | /* | |||
* The message is correctly authenticated and allowed. | * The message is correctly authenticated and allowed. | |||
* Mobilize a symmetric passive association, if we won't | * Mobilize a symmetric passive association, if we won't | |||
* exceed the ippeerlimit. | * exceed the ippeerlimit. | |||
*/ | */ | |||
if ((peer = newpeer(&rbufp->recv_srcadr, NULL, rbufp->dstadr, | if ((peer = newpeer(&rbufp->recv_srcadr, NULL, rbufp->dstadr, | |||
skipping to change at line 2474 | skipping to change at line 2476 | |||
double t34, t21; | double t34, t21; | |||
double p_offset, p_del, p_disp; | double p_offset, p_del, p_disp; | |||
l_fp p_rec, p_xmt, p_org, p_reftime, ci; | l_fp p_rec, p_xmt, p_org, p_reftime, ci; | |||
u_char pmode, pleap, pversion, pstratum; | u_char pmode, pleap, pversion, pstratum; | |||
char statstr[NTP_MAXSTRLEN]; | char statstr[NTP_MAXSTRLEN]; | |||
#ifdef ASSYM | #ifdef ASSYM | |||
int itemp; | int itemp; | |||
double etemp, ftemp, td; | double etemp, ftemp, td; | |||
#endif /* ASSYM */ | #endif /* ASSYM */ | |||
#if 0 | ||||
sys_processed++; | ||||
peer->processed++; | ||||
#endif | ||||
p_del = FPTOD(NTOHS_FP(pkt->rootdelay)); | p_del = FPTOD(NTOHS_FP(pkt->rootdelay)); | |||
p_offset = 0; | p_offset = 0; | |||
p_disp = FPTOD(NTOHS_FP(pkt->rootdisp)); | p_disp = FPTOD(NTOHS_FP(pkt->rootdisp)); | |||
NTOHL_FP(&pkt->reftime, &p_reftime); | NTOHL_FP(&pkt->reftime, &p_reftime); | |||
NTOHL_FP(&pkt->org, &p_org); | NTOHL_FP(&pkt->org, &p_org); | |||
NTOHL_FP(&pkt->rec, &p_rec); | NTOHL_FP(&pkt->rec, &p_rec); | |||
NTOHL_FP(&pkt->xmt, &p_xmt); | NTOHL_FP(&pkt->xmt, &p_xmt); | |||
pmode = PKT_MODE(pkt->li_vn_mode); | pmode = PKT_MODE(pkt->li_vn_mode); | |||
pleap = PKT_LEAP(pkt->li_vn_mode); | pleap = PKT_LEAP(pkt->li_vn_mode); | |||
pversion = PKT_VERSION(pkt->li_vn_mode); | pversion = PKT_VERSION(pkt->li_vn_mode); | |||
pstratum = PKT_TO_STRATUM(pkt->stratum); | pstratum = PKT_TO_STRATUM(pkt->stratum); | |||
/**/ | ||||
/**/ | ||||
/* | /* | |||
* Verify the server is synchronized; that is, the leap bits, | * Verify the server is synchronized; that is, the leap bits, | |||
* stratum and root distance are valid. | * stratum and root distance are valid. | |||
*/ | */ | |||
if ( pleap == LEAP_NOTINSYNC /* test 6 */ | if ( pleap == LEAP_NOTINSYNC /* test 6 */ | |||
|| pstratum < sys_floor || pstratum >= sys_ceiling) | || pstratum < sys_floor || pstratum >= sys_ceiling) | |||
peer->flash |= TEST6; /* bad synch or strat */ | peer->flash |= TEST6; /* bad synch or strat */ | |||
if (p_del / 2 + p_disp >= MAXDISPERSE) /* test 7 */ | if (p_del / 2 + p_disp >= MAXDISPERSE) /* test 7 */ | |||
peer->flash |= TEST7; /* bad header */ | peer->flash |= TEST7; /* bad header */ | |||
/* | /* | |||
* If any tests fail at this point, the packet is discarded. | * If any tests fail at this point, the packet is discarded. | |||
* Note that some flashers may have already been set in the | * Note that some flashers may have already been set in the | |||
* receive() routine. | * receive() routine. | |||
*/ | */ | |||
if (peer->flash & PKT_TEST_MASK) { | if (peer->flash & PKT_TEST_MASK) { | |||
peer->seldisptoolarge++; | peer->seldisptoolarge++; | |||
DPRINTF(1, ("packet: flash header %04x\n", | DPRINTF(1, ("packet: flash header %04x\n", | |||
peer->flash)); | peer->flash)); | |||
/* [Bug 3592] do *not* update poll on bad packets! */ | ||||
/* ppoll updated? */ | ||||
/* XXX: Fuzz the poll? */ | ||||
poll_update(peer, peer->hpoll, (peer->hmode == MODE_CLIENT)); | ||||
return; | return; | |||
} | } | |||
/**/ | /* | |||
* update stats, now that we really handle this packet: | ||||
#if 1 | */ | |||
sys_processed++; | sys_processed++; | |||
peer->processed++; | peer->processed++; | |||
#endif | ||||
/* | /* | |||
* Capture the header values in the client/peer association.. | * Capture the header values in the client/peer association.. | |||
*/ | */ | |||
record_raw_stats(&peer->srcadr, | record_raw_stats(&peer->srcadr, | |||
peer->dstadr ? &peer->dstadr->sin : NULL, | peer->dstadr ? &peer->dstadr->sin : NULL, | |||
&p_org, &p_rec, &p_xmt, &peer->dst, | &p_org, &p_rec, &p_xmt, &peer->dst, | |||
pleap, pversion, pmode, pstratum, pkt->ppoll, pkt->precision, | pleap, pversion, pmode, pstratum, pkt->ppoll, pkt->precision, | |||
p_del, p_disp, pkt->refid, | p_del, p_disp, pkt->refid, | |||
len - MIN_V4_PKT_LEN, (u_char *)&pkt->exten); | len - MIN_V4_PKT_LEN, (u_char *)&pkt->exten); | |||
skipping to change at line 2560 | skipping to change at line 2550 | |||
if (peer->retry > 0) { | if (peer->retry > 0) { | |||
peer->retry = 0; | peer->retry = 0; | |||
if (peer->reach) | if (peer->reach) | |||
peer->burst = min(1 << (peer->hpoll - | peer->burst = min(1 << (peer->hpoll - | |||
peer->minpoll), NTP_SHIFT) - 1; | peer->minpoll), NTP_SHIFT) - 1; | |||
else | else | |||
peer->burst = NTP_IBURST - 1; | peer->burst = NTP_IBURST - 1; | |||
if (peer->burst > 0) | if (peer->burst > 0) | |||
peer->nextdate = current_time; | peer->nextdate = current_time; | |||
} | } | |||
poll_update(peer, peer->hpoll, (peer->hmode == MODE_CLIENT)); | ||||
/**/ | ||||
/* | /* | |||
* If the peer was previously unreachable, raise a trap. In any | * If the peer was previously unreachable, raise a trap. In any | |||
* case, mark it reachable. | * case, mark it reachable. | |||
*/ | */ | |||
if (!peer->reach) { | if (!peer->reach) { | |||
report_event(PEVNT_REACH, peer, NULL); | report_event(PEVNT_REACH, peer, NULL); | |||
peer->timereachable = current_time; | peer->timereachable = current_time; | |||
} | } | |||
peer->reach |= 1; | peer->reach |= 1; | |||
skipping to change at line 3438 | skipping to change at line 3425 | |||
clock_select(void) | clock_select(void) | |||
{ | { | |||
struct peer *peer; | struct peer *peer; | |||
int i, j, k, n; | int i, j, k, n; | |||
int nlist, nl2; | int nlist, nl2; | |||
int allow; | int allow; | |||
int speer; | int speer; | |||
double d, e, f, g; | double d, e, f, g; | |||
double high, low; | double high, low; | |||
double speermet; | double speermet; | |||
double lastresort_dist = MAXDISPERSE; | ||||
double orphmet = 2.0 * U_INT32_MAX; /* 2x is greater than */ | double orphmet = 2.0 * U_INT32_MAX; /* 2x is greater than */ | |||
struct endpoint endp; | struct endpoint endp; | |||
struct peer *osys_peer; | struct peer *osys_peer; | |||
struct peer *sys_prefer = NULL; /* prefer peer */ | struct peer *sys_prefer = NULL; /* prefer peer */ | |||
struct peer *typesystem = NULL; | struct peer *typesystem = NULL; | |||
struct peer *typelastresort = NULL; | ||||
struct peer *typeorphan = NULL; | struct peer *typeorphan = NULL; | |||
#ifdef REFCLOCK | #ifdef REFCLOCK | |||
struct peer *typeacts = NULL; | struct peer *typeacts = NULL; | |||
struct peer *typelocal = NULL; | struct peer *typelocal = NULL; | |||
struct peer *typepps = NULL; | struct peer *typepps = NULL; | |||
#endif /* REFCLOCK */ | #endif /* REFCLOCK */ | |||
static struct endpoint *endpoint = NULL; | static struct endpoint *endpoint = NULL; | |||
static int *indx = NULL; | static int *indx = NULL; | |||
static peer_select *peers = NULL; | static peer_select *peers = NULL; | |||
static u_int endpoint_size = 0; | static u_int endpoint_size = 0; | |||
skipping to change at line 3507 | skipping to change at line 3496 | |||
/* | /* | |||
* Leave the island immediately if the peer is | * Leave the island immediately if the peer is | |||
* unfit to synchronize. | * unfit to synchronize. | |||
*/ | */ | |||
if (peer_unfit(peer)) { | if (peer_unfit(peer)) { | |||
continue; | continue; | |||
} | } | |||
/* | /* | |||
* If we have never been synchronised, look for any peer | ||||
* which has ever been synchronised and pick the one which | ||||
* has the lowest root distance. This can be used as a last | ||||
* resort if all else fails. Once we get an initial sync | ||||
* with this peer, sys_reftime gets set and so this | ||||
* function becomes disabled. | ||||
*/ | ||||
if (L_ISZERO(&sys_reftime)) { | ||||
d = root_distance(peer); | ||||
if (!L_ISZERO(&peer->reftime) && d < lastresort_dist) { | ||||
typelastresort = peer; | ||||
lastresort_dist = d; | ||||
} | ||||
} | ||||
/* | ||||
* If this peer is an orphan parent, elect the | * If this peer is an orphan parent, elect the | |||
* one with the lowest metric defined as the | * one with the lowest metric defined as the | |||
* IPv4 address or the first 64 bits of the | * IPv4 address or the first 64 bits of the | |||
* hashed IPv6 address. To ensure convergence | * hashed IPv6 address. To ensure convergence | |||
* on the same selected orphan, consider as | * on the same selected orphan, consider as | |||
* well that this system may have the lowest | * well that this system may have the lowest | |||
* metric and be the orphan parent. If this | * metric and be the orphan parent. If this | |||
* system wins, sys_peer will be NULL to trigger | * system wins, sys_peer will be NULL to trigger | |||
* orphan mode in timer(). | * orphan mode in timer(). | |||
*/ | */ | |||
skipping to change at line 3739 | skipping to change at line 3744 | |||
peers[0].peer = typeacts; | peers[0].peer = typeacts; | |||
nlist = 1; | nlist = 1; | |||
} else if (typelocal != NULL) { | } else if (typelocal != NULL) { | |||
peers[0].peer = typelocal; | peers[0].peer = typelocal; | |||
nlist = 1; | nlist = 1; | |||
} else | } else | |||
#endif /* REFCLOCK */ | #endif /* REFCLOCK */ | |||
if (typeorphan != NULL) { | if (typeorphan != NULL) { | |||
peers[0].peer = typeorphan; | peers[0].peer = typeorphan; | |||
nlist = 1; | nlist = 1; | |||
} else if (typelastresort != NULL) { | ||||
peers[0].peer = typelastresort; | ||||
nlist = 1; | ||||
} | } | |||
} | } | |||
/* | /* | |||
* Mark the candidates at this point as truechimers. | * Mark the candidates at this point as truechimers. | |||
*/ | */ | |||
for (i = 0; i < nlist; i++) { | for (i = 0; i < nlist; i++) { | |||
peers[i].peer->new_status = CTL_PST_SEL_SELCAND; | peers[i].peer->new_status = CTL_PST_SEL_SELCAND; | |||
DPRINTF(2, ("select: survivor %s %f\n", | DPRINTF(2, ("select: survivor %s %f\n", | |||
stoa(&peers[i].peer->srcadr), peers[i].synch)); | stoa(&peers[i].peer->srcadr), peers[i].synch)); | |||
skipping to change at line 3932 | skipping to change at line 3940 | |||
} | } | |||
#endif /* REFCLOCK */ | #endif /* REFCLOCK */ | |||
/* | /* | |||
* If there are no survivors at this point, there is no | * If there are no survivors at this point, there is no | |||
* system peer. If so and this is an old update, keep the | * system peer. If so and this is an old update, keep the | |||
* current statistics, but do not update the clock. | * current statistics, but do not update the clock. | |||
*/ | */ | |||
if (typesystem == NULL) { | if (typesystem == NULL) { | |||
if (osys_peer != NULL) { | if (osys_peer != NULL) { | |||
if (sys_orphwait > 0) | orphwait = current_time + sys_orphwait; | |||
orphwait = current_time + sys_orphwait; | ||||
report_event(EVNT_NOPEER, NULL, NULL); | report_event(EVNT_NOPEER, NULL, NULL); | |||
} | } | |||
sys_peer = NULL; | sys_peer = NULL; | |||
for (peer = peer_list; peer != NULL; peer = peer->p_link) | for (peer = peer_list; peer != NULL; peer = peer->p_link) | |||
peer->status = peer->new_status; | peer->status = peer->new_status; | |||
return; | return; | |||
} | } | |||
/* | /* | |||
* Do not use old data, as this may mess up the clock discipline | * Do not use old data, as this may mess up the clock discipline | |||
skipping to change at line 5311 | skipping to change at line 5318 | |||
case PROTO_MINSANE: /* minimum survivors (minsane) */ | case PROTO_MINSANE: /* minimum survivors (minsane) */ | |||
sys_minsane = (int)dvalue; | sys_minsane = (int)dvalue; | |||
break; | break; | |||
case PROTO_ORPHAN: /* orphan stratum (orphan) */ | case PROTO_ORPHAN: /* orphan stratum (orphan) */ | |||
sys_orphan = (int)dvalue; | sys_orphan = (int)dvalue; | |||
break; | break; | |||
case PROTO_ORPHWAIT: /* orphan wait (orphwait) */ | case PROTO_ORPHWAIT: /* orphan wait (orphwait) */ | |||
orphwait -= sys_orphwait; | orphwait -= sys_orphwait; | |||
sys_orphwait = (int)dvalue; | sys_orphwait = (dvalue >= 1) ? (int)dvalue : NTP_ORPHWAIT; | |||
orphwait += sys_orphwait; | orphwait += sys_orphwait; | |||
break; | break; | |||
/* | /* | |||
* Miscellaneous commands | * Miscellaneous commands | |||
*/ | */ | |||
case PROTO_MULTICAST_ADD: /* add group address */ | case PROTO_MULTICAST_ADD: /* add group address */ | |||
if (svalue != NULL) | if (svalue != NULL) | |||
io_multicast_add(svalue); | io_multicast_add(svalue); | |||
sys_bclient = 1; | sys_bclient = 1; | |||
End of changes. 15 change blocks. | ||||
26 lines changed or deleted | 34 lines changed or added |