ntp: split out conf_id allocation
This commit is contained in:
parent
eed0a0de56
commit
33a1fe7a9c
1 changed files with 18 additions and 15 deletions
|
@ -698,21 +698,25 @@ static int get_unused_pool_id(void)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static uint32_t
|
||||||
|
get_next_conf_id(uint32_t *conf_id)
|
||||||
|
{
|
||||||
|
last_conf_id++;
|
||||||
|
|
||||||
|
if (conf_id)
|
||||||
|
*conf_id = last_conf_id;
|
||||||
|
|
||||||
|
return last_conf_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
NSR_Status
|
NSR_Status
|
||||||
NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
|
NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
|
||||||
SourceParameters *params, uint32_t *conf_id)
|
SourceParameters *params, uint32_t *conf_id)
|
||||||
{
|
{
|
||||||
NSR_Status s;
|
return add_source(remote_addr, NULL, type, params, INVALID_POOL,
|
||||||
|
get_next_conf_id(conf_id));
|
||||||
s = add_source(remote_addr, NULL, type, params, INVALID_POOL, last_conf_id + 1);
|
|
||||||
if (s != NSR_Success)
|
|
||||||
return s;
|
|
||||||
|
|
||||||
last_conf_id++;
|
|
||||||
if (conf_id)
|
|
||||||
*conf_id = last_conf_id;
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
@ -725,6 +729,7 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
|
||||||
struct SourcePool *sp;
|
struct SourcePool *sp;
|
||||||
NTP_Remote_Address remote_addr;
|
NTP_Remote_Address remote_addr;
|
||||||
int i, new_sources, pool_id;
|
int i, new_sources, pool_id;
|
||||||
|
uint32_t cid;
|
||||||
|
|
||||||
/* If the name is an IP address, add the source with the address directly */
|
/* If the name is an IP address, add the source with the address directly */
|
||||||
if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
|
if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
|
||||||
|
@ -770,14 +775,12 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
|
||||||
|
|
||||||
append_unresolved_source(us);
|
append_unresolved_source(us);
|
||||||
|
|
||||||
last_conf_id++;
|
cid = get_next_conf_id(conf_id);
|
||||||
if (conf_id)
|
|
||||||
*conf_id = last_conf_id;
|
|
||||||
|
|
||||||
for (i = 0; i < new_sources; i++) {
|
for (i = 0; i < new_sources; i++) {
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
remote_addr.ip_addr.addr.id = ++last_address_id;
|
remote_addr.ip_addr.addr.id = ++last_address_id;
|
||||||
if (add_source(&remote_addr, name, type, params, us->pool_id, last_conf_id) != NSR_Success)
|
if (add_source(&remote_addr, name, type, params, us->pool_id, cid) != NSR_Success)
|
||||||
return NSR_TooManySources;
|
return NSR_TooManySources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue