int pool; /* Number of the pool from which was this source
added or INVALID_POOL */
int tentative; /* Flag indicating there was no valid response
- yet and the source may be removed if other
- sources from the pool respond first */
+ received from the source yet */
} SourceRecord;
/* Hash table of SourceRecord, its size is a power of two and it's never
record->remote_addr = NCR_GetRemoteAddress(record->data);
record->name = name ? Strdup(name) : NULL;
record->pool = pool;
- record->tentative = pool != INVALID_POOL ? 1 : 0;
+ record->tentative = 1;
if (auto_start_sources)
NCR_StartInstance(record->data);
{
int slot1, slot2, found;
SourceRecord *record;
+ struct SourcePool *pool;
find_slot(old_addr, &slot1, &found);
if (!found)
NCR_ChangeRemoteAddress(record->data, new_addr);
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 */
rehash_records();
return;
if (record->tentative) {
- /* First reply from a pool source */
+ /* This was the first valid reply from the source */
record->tentative = 0;
- assert(record->pool != INVALID_POOL);
- pool = (struct SourcePool *)ARR_GetElement(pools, record->pool);
- pool->sources++;
+ if (record->pool != INVALID_POOL) {
+ pool = ARR_GetElement(pools, record->pool);
+ pool->sources++;
- DEBUG_LOG(LOGF_NtpSources, "pool %s has %d confirmed sources",
- record->name, pool->sources);
+ DEBUG_LOG(LOGF_NtpSources, "pool %s has %d confirmed sources",
+ record->name, pool->sources);
- /* If the number of sources reached the configured maximum, remove
- the tentative sources added from this pool */
- if (pool->sources >= pool->max_sources)
- remove_tentative_pool_sources(record->pool);
+ /* If the number of sources from the pool reached the configured
+ maximum, remove the remaining tentative sources */
+ if (pool->sources >= pool->max_sources)
+ remove_tentative_pool_sources(record->pool);
+ }
}
} else {
NCR_ProcessUnknown(message, now, now_err, remote_addr, local_addr, length);