diff --git a/ntp_core.c b/ntp_core.c index 833ade6..0f5a49b 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -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) { diff --git a/ntp_core.h b/ntp_core.h index 104a704..4f5fc79 100644 --- a/ntp_core.h +++ b/ntp_core.h @@ -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); diff --git a/sources.c b/sources.c index 01ebdcd..5e5813d 100644 --- a/sources.c +++ b/sources.c @@ -1311,3 +1311,10 @@ SRC_Samples(SRC_Instance inst) } /* ================================================== */ + +SRC_SelectOption SRC_GetSelectOption(SRC_Instance inst) +{ + return inst->sel_option; +} + +/* ================================================== */ diff --git a/sources.h b/sources.h index 34b1e02..d9a0315 100644 --- a/sources.h +++ b/sources.h @@ -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 */