ntp: don't replace sources with unroutable addresses
When changing an address of a source (both known and unknown), make sure the new address is connectable. This should avoid useless replacements, e.g. polling an IPv6 address on IPv4-only systems.
This commit is contained in:
parent
8c0ee9c175
commit
5a09adebfd
1 changed files with 19 additions and 2 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
#include "ntp_sources.h"
|
#include "ntp_sources.h"
|
||||||
#include "ntp_core.h"
|
#include "ntp_core.h"
|
||||||
|
#include "ntp_io.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
@ -389,6 +390,22 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
replace_source_connectable(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
||||||
|
{
|
||||||
|
if (!NIO_IsServerConnectable(new_addr)) {
|
||||||
|
DEBUG_LOG("%s not connectable", UTI_IPToString(&new_addr->ip_addr));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (replace_source(old_addr, new_addr) == NSR_AlreadyInUse)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
process_resolved_name(struct UnresolvedSource *us, IPAddr *ip_addrs, int n_addrs)
|
process_resolved_name(struct UnresolvedSource *us, IPAddr *ip_addrs, int n_addrs)
|
||||||
{
|
{
|
||||||
|
@ -415,12 +432,12 @@ process_resolved_name(struct UnresolvedSource *us, IPAddr *ip_addrs, int n_addrs
|
||||||
continue;
|
continue;
|
||||||
old_addr = *record->remote_addr;
|
old_addr = *record->remote_addr;
|
||||||
new_addr.port = old_addr.port;
|
new_addr.port = old_addr.port;
|
||||||
if (replace_source(&old_addr, &new_addr) != NSR_AlreadyInUse)
|
if (replace_source_connectable(&old_addr, &new_addr))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new_addr.port = us->address.port;
|
new_addr.port = us->address.port;
|
||||||
if (replace_source(&us->address, &new_addr) != NSR_AlreadyInUse)
|
if (replace_source_connectable(&us->address, &new_addr))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue