ntp: mark all new sources and replacements as tentative
This commit is contained in:
parent
3abaa92926
commit
62e66bda60
1 changed files with 23 additions and 13 deletions
|
@ -53,8 +53,7 @@ typedef struct {
|
||||||
int pool; /* Number of the pool from which was this source
|
int pool; /* Number of the pool from which was this source
|
||||||
added or INVALID_POOL */
|
added or INVALID_POOL */
|
||||||
int tentative; /* Flag indicating there was no valid response
|
int tentative; /* Flag indicating there was no valid response
|
||||||
yet and the source may be removed if other
|
received from the source yet */
|
||||||
sources from the pool respond first */
|
|
||||||
} SourceRecord;
|
} SourceRecord;
|
||||||
|
|
||||||
/* Hash table of SourceRecord, its size is a power of two and it's never
|
/* Hash table of SourceRecord, its size is a power of two and it's never
|
||||||
|
@ -311,7 +310,7 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type, So
|
||||||
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
||||||
record->name = name ? Strdup(name) : NULL;
|
record->name = name ? Strdup(name) : NULL;
|
||||||
record->pool = pool;
|
record->pool = pool;
|
||||||
record->tentative = pool != INVALID_POOL ? 1 : 0;
|
record->tentative = 1;
|
||||||
|
|
||||||
if (auto_start_sources)
|
if (auto_start_sources)
|
||||||
NCR_StartInstance(record->data);
|
NCR_StartInstance(record->data);
|
||||||
|
@ -328,6 +327,7 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
||||||
{
|
{
|
||||||
int slot1, slot2, found;
|
int slot1, slot2, found;
|
||||||
SourceRecord *record;
|
SourceRecord *record;
|
||||||
|
struct SourcePool *pool;
|
||||||
|
|
||||||
find_slot(old_addr, &slot1, &found);
|
find_slot(old_addr, &slot1, &found);
|
||||||
if (!found)
|
if (!found)
|
||||||
|
@ -341,6 +341,15 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
||||||
NCR_ChangeRemoteAddress(record->data, new_addr);
|
NCR_ChangeRemoteAddress(record->data, new_addr);
|
||||||
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
||||||
|
|
||||||
|
if (!record->tentative) {
|
||||||
|
record->tentative = 1;
|
||||||
|
|
||||||
|
if (record->pool != INVALID_POOL) {
|
||||||
|
pool = ARR_GetElement(pools, record->pool);
|
||||||
|
pool->sources--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* The hash table must be rebuilt for the new address */
|
/* The hash table must be rebuilt for the new address */
|
||||||
rehash_records();
|
rehash_records();
|
||||||
|
|
||||||
|
@ -772,20 +781,21 @@ NSR_ProcessReceive(NTP_Packet *message, struct timeval *now, double now_err, NTP
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (record->tentative) {
|
if (record->tentative) {
|
||||||
/* First reply from a pool source */
|
/* This was the first valid reply from the source */
|
||||||
record->tentative = 0;
|
record->tentative = 0;
|
||||||
|
|
||||||
assert(record->pool != INVALID_POOL);
|
if (record->pool != INVALID_POOL) {
|
||||||
pool = (struct SourcePool *)ARR_GetElement(pools, record->pool);
|
pool = ARR_GetElement(pools, record->pool);
|
||||||
pool->sources++;
|
pool->sources++;
|
||||||
|
|
||||||
DEBUG_LOG(LOGF_NtpSources, "pool %s has %d confirmed sources",
|
DEBUG_LOG(LOGF_NtpSources, "pool %s has %d confirmed sources",
|
||||||
record->name, pool->sources);
|
record->name, pool->sources);
|
||||||
|
|
||||||
/* If the number of sources reached the configured maximum, remove
|
/* If the number of sources from the pool reached the configured
|
||||||
the tentative sources added from this pool */
|
maximum, remove the remaining tentative sources */
|
||||||
if (pool->sources >= pool->max_sources)
|
if (pool->sources >= pool->max_sources)
|
||||||
remove_tentative_pool_sources(record->pool);
|
remove_tentative_pool_sources(record->pool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
NCR_ProcessUnknown(message, now, now_err, remote_addr, local_addr, length);
|
NCR_ProcessUnknown(message, now, now_err, remote_addr, local_addr, length);
|
||||||
|
|
Loading…
Reference in a new issue