ntp: allow changing address of core instance

This commit is contained in:
Miroslav Lichvar 2014-10-31 16:38:39 +01:00
parent 40f8591257
commit 29c1df4610
4 changed files with 35 additions and 0 deletions

View file

@ -538,6 +538,29 @@ NCR_ResetInstance(NCR_Instance instance)
/* ================================================== */
void
NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr)
{
SRC_SelectOption sel_option;
inst->remote_addr = *remote_addr;
inst->tx_count = 0;
inst->presend_done = 0;
if (inst->mode == MODE_CLIENT)
close_client_socket(inst);
else
inst->local_addr.sock_fd = NIO_GetServerSocket(remote_addr);
/* Replace sources and sourcestats instances */
sel_option = SRC_GetSelectOption(inst->source);
SRC_DestroyInstance(inst->source);
inst->source = SRC_CreateNewInstance(UTI_IPToRefid(&remote_addr->ip_addr), SRC_NTP,
sel_option, &inst->remote_addr.ip_addr);
}
/* ================================================== */
static void
adjust_poll(NCR_Instance inst, double adj)
{

View file

@ -58,6 +58,9 @@ extern void NCR_StartInstance(NCR_Instance instance);
/* Reset an instance */
extern void NCR_ResetInstance(NCR_Instance inst);
/* Change the remote address of an instance */
extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr);
/* 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 */
extern void NCR_ProcessKnown(NTP_Packet *message, struct timeval *now, double now_err, NCR_Instance data, NTP_Local_Address *local_addr, int length);

View file

@ -1311,3 +1311,10 @@ SRC_Samples(SRC_Instance inst)
}
/* ================================================== */
SRC_SelectOption SRC_GetSelectOption(SRC_Instance inst)
{
return inst->sel_option;
}
/* ================================================== */

View file

@ -174,5 +174,7 @@ extern SRC_Type SRC_GetType(int index);
extern int SRC_Samples(SRC_Instance inst);
extern SRC_SelectOption SRC_GetSelectOption(SRC_Instance inst);
#endif /* GOT_SOURCES_H */