diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-03-04 07:06:53 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-03-04 07:06:53 +0100 |
commit | f37f28199f508f5fee44753d320f044a91e76e39 (patch) | |
tree | e2e06a1faa1617dda7d14ed3b43a2ab826dc7a9f | |
parent | 4c48a6474701d8b396a14213ebcc979a49187faf (diff) | |
download | busybox-w32-f37f28199f508f5fee44753d320f044a91e76e39.tar.gz busybox-w32-f37f28199f508f5fee44753d320f044a91e76e39.tar.bz2 busybox-w32-f37f28199f508f5fee44753d320f044a91e76e39.zip |
ntpd: do not use a peer more than once (say, if two peers resolve to the same IP)
function old new delta
add_peers 98 166 +68
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ntpd.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 4695c3366..517806e75 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -727,7 +727,7 @@ reset_peer_stats(peer_t *p, double offset) | |||
727 | 727 | ||
728 | /* Used to set p->filter_datapoint[i].d_dispersion = MAXDISP | 728 | /* Used to set p->filter_datapoint[i].d_dispersion = MAXDISP |
729 | * and clear reachable bits, but this proved to be too agressive: | 729 | * and clear reachable bits, but this proved to be too agressive: |
730 | * after step (tested with suspinding laptop for ~30 secs), | 730 | * after step (tested with suspending laptop for ~30 secs), |
731 | * this caused all previous data to be considered invalid, | 731 | * this caused all previous data to be considered invalid, |
732 | * making us needing to collect full ~8 datapoins per peer | 732 | * making us needing to collect full ~8 datapoins per peer |
733 | * after step in order to start trusting them. | 733 | * after step in order to start trusting them. |
@@ -766,11 +766,26 @@ reset_peer_stats(peer_t *p, double offset) | |||
766 | static void | 766 | static void |
767 | add_peers(const char *s) | 767 | add_peers(const char *s) |
768 | { | 768 | { |
769 | llist_t *item; | ||
769 | peer_t *p; | 770 | peer_t *p; |
770 | 771 | ||
771 | p = xzalloc(sizeof(*p)); | 772 | p = xzalloc(sizeof(*p)); |
772 | p->p_lsa = xhost2sockaddr(s, 123); | 773 | p->p_lsa = xhost2sockaddr(s, 123); |
773 | p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa); | 774 | p->p_dotted = xmalloc_sockaddr2dotted_noport(&p->p_lsa->u.sa); |
775 | |||
776 | /* Names like N.<country2chars>.pool.ntp.org are randomly resolved | ||
777 | * to a pool of machines. Sometimes different N's resolve to the same IP. | ||
778 | * It is not useful to have two peers with same IP. We skip duplicates. | ||
779 | */ | ||
780 | for (item = G.ntp_peers; item != NULL; item = item->link) { | ||
781 | peer_t *pp = (peer_t *) item->data; | ||
782 | if (strcmp(p->p_dotted, pp->p_dotted) == 0) { | ||
783 | bb_error_msg("duplicate peer %s (%s)", s, p->p_dotted); | ||
784 | free(p); | ||
785 | return; | ||
786 | } | ||
787 | } | ||
788 | |||
774 | p->p_fd = -1; | 789 | p->p_fd = -1; |
775 | p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); | 790 | p->p_xmt_msg.m_status = MODE_CLIENT | (NTP_VERSION << 3); |
776 | p->next_action_time = G.cur_time; /* = set_next(p, 0); */ | 791 | p->next_action_time = G.cur_time; /* = set_next(p, 0); */ |