ntp: add function to update source NTP address
This will allow a source to have its address changed due to NTS-KE server negotiation, which allows the NTS-KE server to have a different address than the NTP server.
This commit is contained in:
parent
9468fd4aa6
commit
e8062b7ff1
4 changed files with 24 additions and 6 deletions
|
@ -691,7 +691,7 @@ NCR_ResetPoll(NCR_Instance instance)
|
|||
/* ================================================== */
|
||||
|
||||
void
|
||||
NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr)
|
||||
NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr, int ntp_only)
|
||||
{
|
||||
memset(&inst->report, 0, sizeof (inst->report));
|
||||
NCR_ResetInstance(inst);
|
||||
|
|
|
@ -74,7 +74,8 @@ extern void NCR_ResetInstance(NCR_Instance inst);
|
|||
extern void NCR_ResetPoll(NCR_Instance instance);
|
||||
|
||||
/* Change the remote address of an instance */
|
||||
extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr);
|
||||
extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr,
|
||||
int ntp_only);
|
||||
|
||||
/* This routine is called when a new packet arrives off the network,
|
||||
and it relates to a source we have an ongoing protocol exchange with */
|
||||
|
|
|
@ -343,7 +343,8 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type, So
|
|||
/* ================================================== */
|
||||
|
||||
static NSR_Status
|
||||
replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
||||
change_source_address(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr,
|
||||
int replacement)
|
||||
{
|
||||
int slot1, slot2, found;
|
||||
SourceRecord *record;
|
||||
|
@ -361,7 +362,7 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
|||
return NSR_AlreadyInUse;
|
||||
|
||||
record = get_record(slot1);
|
||||
NCR_ChangeRemoteAddress(record->data, new_addr);
|
||||
NCR_ChangeRemoteAddress(record->data, new_addr, !replacement);
|
||||
record->remote_addr = NCR_GetRemoteAddress(record->data);
|
||||
if (!UTI_IsIPReal(&old_addr->ip_addr) && UTI_IsIPReal(&new_addr->ip_addr)) {
|
||||
if (auto_start_sources)
|
||||
|
@ -384,7 +385,8 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
|||
/* The hash table must be rebuilt for the changed address */
|
||||
rehash_records();
|
||||
|
||||
LOG(severity, "Source %s replaced with %s (%s)", UTI_IPToString(&old_addr->ip_addr),
|
||||
LOG(severity, "Source %s %s %s (%s)", UTI_IPToString(&old_addr->ip_addr),
|
||||
replacement ? "replaced with" : "changed to",
|
||||
UTI_IPToString(&new_addr->ip_addr), name ? name : "");
|
||||
} else {
|
||||
LOG(severity, "Source %s (%s) changed port to %d",
|
||||
|
@ -404,7 +406,7 @@ replace_source_connectable(NTP_Remote_Address *old_addr, NTP_Remote_Address *new
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (replace_source(old_addr, new_addr) == NSR_AlreadyInUse)
|
||||
if (change_source_address(old_addr, new_addr, 1) == NSR_AlreadyInUse)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
@ -864,6 +866,17 @@ NSR_RefreshAddresses(void)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
NSR_Status
|
||||
NSR_UpdateSourceNtpAddress(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
|
||||
{
|
||||
if (new_addr->ip_addr.family == IPADDR_UNSPEC)
|
||||
return NSR_InvalidAF;
|
||||
|
||||
return change_source_address(old_addr, new_addr, 0);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static void remove_pool_sources(int pool, int tentative, int unresolved)
|
||||
{
|
||||
SourceRecord *record;
|
||||
|
|
|
@ -87,6 +87,10 @@ extern void NSR_HandleBadSource(IPAddr *address);
|
|||
/* Procedure to resolve all names again */
|
||||
extern void NSR_RefreshAddresses(void);
|
||||
|
||||
/* Procedure to update the address of a source */
|
||||
extern NSR_Status NSR_UpdateSourceNtpAddress(NTP_Remote_Address *old_addr,
|
||||
NTP_Remote_Address *new_addr);
|
||||
|
||||
/* Procedure to get local reference ID corresponding to a source */
|
||||
extern uint32_t NSR_GetLocalRefid(IPAddr *address);
|
||||
|
||||
|
|
Loading…
Reference in a new issue