From f3aea33ad43045098d2af3379ae420f24bb67cac Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 7 Oct 2020 09:37:41 +0200 Subject: [PATCH] ntp: avoid unnecessary replacement attempts In the initial resolving of pool sources try to assign each address only once. If it fails, it means the address is already used (DNS provided the same address) or the address is not connectable. The same result can be expected for other unresolved sources of the pool as they don't have a real address yet. --- ntp_sources.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ntp_sources.c b/ntp_sources.c index 122f5e4..850f471 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -444,8 +444,8 @@ process_resolved_name(struct UnresolvedSource *us, IPAddr *ip_addrs, int n_addrs DEBUG_LOG("(%d) %s", i + 1, UTI_IPToString(&new_addr.ip_addr)); if (us->pool_id != INVALID_POOL) { - /* In the pool resolving mode, try to replace all sources from - the pool which don't have a real address yet */ + /* In the pool resolving mode, try to replace a source from + the pool which does not have a real address yet */ for (j = 0; j < ARR_GetSize(records); j++) { record = get_record(j); if (!record->remote_addr || record->pool_id != us->pool_id || @@ -454,7 +454,8 @@ process_resolved_name(struct UnresolvedSource *us, IPAddr *ip_addrs, int n_addrs old_addr = *record->remote_addr; new_addr.port = old_addr.port; if (replace_source_connectable(&old_addr, &new_addr)) - break; + ; + break; } } else { new_addr.port = us->address.port;