diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-11 11:41:46 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-11 11:41:46 +0200 |
| commit | 4125a6b6306d8d12f1e22239465bce916e168d73 (patch) | |
| tree | 73d31358b100b0bd943578aa3d1cc5a95a9a11ea | |
| parent | 0a393cf7da9003d0d64e1868c13ef206af125451 (diff) | |
| download | busybox-w32-4125a6b6306d8d12f1e22239465bce916e168d73.tar.gz busybox-w32-4125a6b6306d8d12f1e22239465bce916e168d73.tar.bz2 busybox-w32-4125a6b6306d8d12f1e22239465bce916e168d73.zip | |
ntpd: on time step, kill all outstanding replies from other peers
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/ntpd.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 603801ec6..72e9d0be2 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
| @@ -220,14 +220,14 @@ typedef struct { | |||
| 220 | typedef struct { | 220 | typedef struct { |
| 221 | len_and_sockaddr *p_lsa; | 221 | len_and_sockaddr *p_lsa; |
| 222 | char *p_dotted; | 222 | char *p_dotted; |
| 223 | /* when to send new query (if p_fd == -1) | ||
| 224 | * or when receive times out (if p_fd >= 0): */ | ||
| 225 | int p_fd; | 223 | int p_fd; |
| 226 | int datapoint_idx; | 224 | int datapoint_idx; |
| 227 | uint32_t lastpkt_refid; | 225 | uint32_t lastpkt_refid; |
| 228 | uint8_t lastpkt_status; | 226 | uint8_t lastpkt_status; |
| 229 | uint8_t lastpkt_stratum; | 227 | uint8_t lastpkt_stratum; |
| 230 | uint8_t reachable_bits; | 228 | uint8_t reachable_bits; |
| 229 | /* when to send new query (if p_fd == -1) | ||
| 230 | * or when receive times out (if p_fd >= 0): */ | ||
| 231 | double next_action_time; | 231 | double next_action_time; |
| 232 | double p_xmttime; | 232 | double p_xmttime; |
| 233 | double lastpkt_recv_time; | 233 | double lastpkt_recv_time; |
| @@ -895,6 +895,11 @@ step_time(double offset) | |||
| 895 | 895 | ||
| 896 | /* Correct various fields which contain time-relative values: */ | 896 | /* Correct various fields which contain time-relative values: */ |
| 897 | 897 | ||
| 898 | /* Globals: */ | ||
| 899 | G.cur_time += offset; | ||
| 900 | G.last_update_recv_time += offset; | ||
| 901 | G.last_script_run += offset; | ||
| 902 | |||
| 898 | /* p->lastpkt_recv_time, p->next_action_time and such: */ | 903 | /* p->lastpkt_recv_time, p->next_action_time and such: */ |
| 899 | for (item = G.ntp_peers; item != NULL; item = item->link) { | 904 | for (item = G.ntp_peers; item != NULL; item = item->link) { |
| 900 | peer_t *pp = (peer_t *) item->data; | 905 | peer_t *pp = (peer_t *) item->data; |
| @@ -902,11 +907,16 @@ step_time(double offset) | |||
| 902 | //bb_error_msg("offset:%+f pp->next_action_time:%f -> %f", | 907 | //bb_error_msg("offset:%+f pp->next_action_time:%f -> %f", |
| 903 | // offset, pp->next_action_time, pp->next_action_time + offset); | 908 | // offset, pp->next_action_time, pp->next_action_time + offset); |
| 904 | pp->next_action_time += offset; | 909 | pp->next_action_time += offset; |
| 910 | if (pp->p_fd >= 0) { | ||
| 911 | /* We wait for reply from this peer too. | ||
| 912 | * But due to step we are doing, reply's data is no longer | ||
| 913 | * useful (in fact, it'll be bogus). Stop waiting for it. | ||
| 914 | */ | ||
| 915 | close(pp->p_fd); | ||
| 916 | pp->p_fd = -1; | ||
| 917 | set_next(pp, RETRY_INTERVAL); | ||
| 918 | } | ||
| 905 | } | 919 | } |
| 906 | /* Globals: */ | ||
| 907 | G.cur_time += offset; | ||
| 908 | G.last_update_recv_time += offset; | ||
| 909 | G.last_script_run += offset; | ||
| 910 | } | 920 | } |
| 911 | 921 | ||
| 912 | 922 | ||
| @@ -1623,22 +1633,30 @@ recv_and_process_peer_pkt(peer_t *p) | |||
| 1623 | ) { | 1633 | ) { |
| 1624 | //TODO: always do this? | 1634 | //TODO: always do this? |
| 1625 | interval = retry_interval(); | 1635 | interval = retry_interval(); |
| 1626 | goto set_next_and_close_sock; | 1636 | goto set_next_and_ret; |
| 1627 | } | 1637 | } |
| 1628 | xfunc_die(); | 1638 | xfunc_die(); |
| 1629 | } | 1639 | } |
| 1630 | 1640 | ||
| 1631 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE) { | 1641 | if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE) { |
| 1632 | bb_error_msg("malformed packet received from %s", p->p_dotted); | 1642 | bb_error_msg("malformed packet received from %s", p->p_dotted); |
| 1633 | goto bail; | 1643 | return; |
| 1634 | } | 1644 | } |
| 1635 | 1645 | ||
| 1636 | if (msg.m_orgtime.int_partl != p->p_xmt_msg.m_xmttime.int_partl | 1646 | if (msg.m_orgtime.int_partl != p->p_xmt_msg.m_xmttime.int_partl |
| 1637 | || msg.m_orgtime.fractionl != p->p_xmt_msg.m_xmttime.fractionl | 1647 | || msg.m_orgtime.fractionl != p->p_xmt_msg.m_xmttime.fractionl |
| 1638 | ) { | 1648 | ) { |
| 1639 | goto bail; | 1649 | /* Somebody else's packet */ |
| 1650 | return; | ||
| 1640 | } | 1651 | } |
| 1641 | 1652 | ||
| 1653 | /* We do not expect any more packets from this peer for now. | ||
| 1654 | * Closing the socket informs kernel about it. | ||
| 1655 | * We open a new socket when we send a new query. | ||
| 1656 | */ | ||
| 1657 | close(p->p_fd); | ||
| 1658 | p->p_fd = -1; | ||
| 1659 | |||
| 1642 | if ((msg.m_status & LI_ALARM) == LI_ALARM | 1660 | if ((msg.m_status & LI_ALARM) == LI_ALARM |
| 1643 | || msg.m_stratum == 0 | 1661 | || msg.m_stratum == 0 |
| 1644 | || msg.m_stratum > NTP_MAXSTRATUM | 1662 | || msg.m_stratum > NTP_MAXSTRATUM |
| @@ -1647,8 +1665,8 @@ recv_and_process_peer_pkt(peer_t *p) | |||
| 1647 | // "DENY", "RSTR" - peer does not like us at all | 1665 | // "DENY", "RSTR" - peer does not like us at all |
| 1648 | // "RATE" - peer is overloaded, reduce polling freq | 1666 | // "RATE" - peer is overloaded, reduce polling freq |
| 1649 | interval = poll_interval(0); | 1667 | interval = poll_interval(0); |
| 1650 | bb_error_msg("reply from %s: not synced, next query in %us", p->p_dotted, interval); | 1668 | bb_error_msg("reply from %s: peer is unsynced, next query in %us", p->p_dotted, interval); |
| 1651 | goto set_next_and_close_sock; | 1669 | goto set_next_and_ret; |
| 1652 | } | 1670 | } |
| 1653 | 1671 | ||
| 1654 | // /* Verify valid root distance */ | 1672 | // /* Verify valid root distance */ |
| @@ -1794,16 +1812,8 @@ recv_and_process_peer_pkt(peer_t *p) | |||
| 1794 | /* Decide when to send new query for this peer */ | 1812 | /* Decide when to send new query for this peer */ |
| 1795 | interval = poll_interval(0); | 1813 | interval = poll_interval(0); |
| 1796 | 1814 | ||
| 1797 | set_next_and_close_sock: | 1815 | set_next_and_ret: |
| 1798 | set_next(p, interval); | 1816 | set_next(p, interval); |
| 1799 | /* We do not expect any more packets from this peer for now. | ||
| 1800 | * Closing the socket informs kernel about it. | ||
| 1801 | * We open a new socket when we send a new query. | ||
| 1802 | */ | ||
| 1803 | close(p->p_fd); | ||
| 1804 | p->p_fd = -1; | ||
| 1805 | bail: | ||
| 1806 | return; | ||
| 1807 | } | 1817 | } |
| 1808 | 1818 | ||
| 1809 | #if ENABLE_FEATURE_NTPD_SERVER | 1819 | #if ENABLE_FEATURE_NTPD_SERVER |
