aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-04-19 19:00:16 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-04-19 19:00:16 +0200
commitd531f93f646f4347b464730b80dfb34b8744a984 (patch)
treea125e1044d33cec06fac84dc9970067c79c9d839
parent6116cb23cc2074f232397b406fabab1606b28fb6 (diff)
downloadbusybox-w32-d531f93f646f4347b464730b80dfb34b8744a984.tar.gz
busybox-w32-d531f93f646f4347b464730b80dfb34b8744a984.tar.bz2
busybox-w32-d531f93f646f4347b464730b80dfb34b8744a984.zip
ntpd: truly ignore high delay packet
Before this cahnge, sometimes they were used after the next packet from another peer was received, because we did updare some peer stats from high delay packet before dropping it. function old new delta recv_and_process_peer_pkt 922 966 +44 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/ntpd.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index adda6e5b0..2eec99f99 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -252,6 +252,9 @@ typedef struct {
252 * or when receive times out (if p_fd >= 0): */ 252 * or when receive times out (if p_fd >= 0): */
253 double next_action_time; 253 double next_action_time;
254 double p_xmttime; 254 double p_xmttime;
255 double p_raw_delay;
256 /* p_raw_delay is set even by "high delay" packets */
257 /* lastpkt_delay isn't */
255 double lastpkt_recv_time; 258 double lastpkt_recv_time;
256 double lastpkt_delay; 259 double lastpkt_delay;
257 double lastpkt_rootdelay; 260 double lastpkt_rootdelay;
@@ -1685,7 +1688,8 @@ recv_and_process_peer_pkt(peer_t *p)
1685 ssize_t size; 1688 ssize_t size;
1686 msg_t msg; 1689 msg_t msg;
1687 double T1, T2, T3, T4; 1690 double T1, T2, T3, T4;
1688 double dv, offset; 1691 double offset;
1692 double prev_delay, delay;
1689 unsigned interval; 1693 unsigned interval;
1690 datapoint_t *datapoint; 1694 datapoint_t *datapoint;
1691 peer_t *q; 1695 peer_t *q;
@@ -1745,12 +1749,6 @@ recv_and_process_peer_pkt(peer_t *p)
1745// if (msg.m_rootdelay / 2 + msg.m_rootdisp >= MAXDISP || p->lastpkt_reftime > msg.m_xmt) 1749// if (msg.m_rootdelay / 2 + msg.m_rootdisp >= MAXDISP || p->lastpkt_reftime > msg.m_xmt)
1746// return; /* invalid header values */ 1750// return; /* invalid header values */
1747 1751
1748 p->lastpkt_status = msg.m_status;
1749 p->lastpkt_stratum = msg.m_stratum;
1750 p->lastpkt_rootdelay = sfp_to_d(msg.m_rootdelay);
1751 p->lastpkt_rootdisp = sfp_to_d(msg.m_rootdisp);
1752 p->lastpkt_refid = msg.m_refid;
1753
1754 /* 1752 /*
1755 * From RFC 2030 (with a correction to the delay math): 1753 * From RFC 2030 (with a correction to the delay math):
1756 * 1754 *
@@ -1770,28 +1768,35 @@ recv_and_process_peer_pkt(peer_t *p)
1770 T3 = lfp_to_d(msg.m_xmttime); 1768 T3 = lfp_to_d(msg.m_xmttime);
1771 T4 = G.cur_time; 1769 T4 = G.cur_time;
1772 1770
1773 p->lastpkt_recv_time = T4;
1774 VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time);
1775
1776 /* The delay calculation is a special case. In cases where the 1771 /* The delay calculation is a special case. In cases where the
1777 * server and client clocks are running at different rates and 1772 * server and client clocks are running at different rates and
1778 * with very fast networks, the delay can appear negative. In 1773 * with very fast networks, the delay can appear negative. In
1779 * order to avoid violating the Principle of Least Astonishment, 1774 * order to avoid violating the Principle of Least Astonishment,
1780 * the delay is clamped not less than the system precision. 1775 * the delay is clamped not less than the system precision.
1781 */ 1776 */
1782 dv = p->lastpkt_delay; 1777 delay = (T4 - T1) - (T3 - T2);
1783 p->lastpkt_delay = (T4 - T1) - (T3 - T2); 1778 if (delay < G_precision_sec)
1784 if (p->lastpkt_delay < G_precision_sec) 1779 delay = G_precision_sec;
1785 p->lastpkt_delay = G_precision_sec;
1786 /* 1780 /*
1787 * If this packet's delay is much bigger than the last one, 1781 * If this packet's delay is much bigger than the last one,
1788 * it's better to just ignore it than use its much less precise value. 1782 * it's better to just ignore it than use its much less precise value.
1789 */ 1783 */
1790 if (p->reachable_bits && p->lastpkt_delay > dv * BAD_DELAY_GROWTH) { 1784 prev_delay = p->p_raw_delay;
1785 p->p_raw_delay = delay;
1786 if (p->reachable_bits && delay > prev_delay * BAD_DELAY_GROWTH) {
1791 bb_error_msg("reply from %s: delay %f is too high, ignoring", p->p_dotted, p->lastpkt_delay); 1787 bb_error_msg("reply from %s: delay %f is too high, ignoring", p->p_dotted, p->lastpkt_delay);
1792 goto pick_normal_interval; 1788 goto pick_normal_interval;
1793 } 1789 }
1794 1790
1791 p->lastpkt_delay = delay;
1792 p->lastpkt_recv_time = T4;
1793 VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time);
1794 p->lastpkt_status = msg.m_status;
1795 p->lastpkt_stratum = msg.m_stratum;
1796 p->lastpkt_rootdelay = sfp_to_d(msg.m_rootdelay);
1797 p->lastpkt_rootdisp = sfp_to_d(msg.m_rootdisp);
1798 p->lastpkt_refid = msg.m_refid;
1799
1795 p->datapoint_idx = p->reachable_bits ? (p->datapoint_idx + 1) % NUM_DATAPOINTS : 0; 1800 p->datapoint_idx = p->reachable_bits ? (p->datapoint_idx + 1) % NUM_DATAPOINTS : 0;
1796 datapoint = &p->filter_datapoint[p->datapoint_idx]; 1801 datapoint = &p->filter_datapoint[p->datapoint_idx];
1797 datapoint->d_recv_time = T4; 1802 datapoint->d_recv_time = T4;