From 33a1fe7a9ce223d6287ab7b11bca3208e9255cdd Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 9 Mar 2022 15:30:16 +0100 Subject: [PATCH] ntp: split out conf_id allocation --- ntp_sources.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/ntp_sources.c b/ntp_sources.c index 3cbb2ae..3077082 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -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_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParameters *params, uint32_t *conf_id) { - NSR_Status s; - - 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; + return add_source(remote_addr, NULL, type, params, INVALID_POOL, + get_next_conf_id(conf_id)); } /* ================================================== */ @@ -725,6 +729,7 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, struct SourcePool *sp; NTP_Remote_Address remote_addr; int i, new_sources, pool_id; + uint32_t cid; /* If the name is an IP address, add the source with the address directly */ 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); - last_conf_id++; - if (conf_id) - *conf_id = last_conf_id; + cid = get_next_conf_id(conf_id); for (i = 0; i < new_sources; i++) { if (i > 0) 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; }