Merge NSR/NCR server and peer functions
This commit is contained in:
parent
ab68a9d1d3
commit
2458325c09
6 changed files with 31 additions and 91 deletions
4
cmdmon.c
4
cmdmon.c
|
@ -1233,7 +1233,7 @@ handle_add_server(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||
params.iburst = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_IBURST ? 1 : 0;
|
||||
params.max_delay = UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay);
|
||||
params.max_delay_ratio = UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_ratio);
|
||||
status = NSR_AddServer(&rem_addr, ¶ms);
|
||||
status = NSR_AddSource(&rem_addr, NTP_SERVER, ¶ms);
|
||||
switch (status) {
|
||||
case NSR_Success:
|
||||
tx_message->status = htons(STT_SUCCESS);
|
||||
|
@ -1274,7 +1274,7 @@ handle_add_peer(CMD_Request *rx_message, CMD_Reply *tx_message)
|
|||
params.iburst = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_IBURST ? 1 : 0;
|
||||
params.max_delay = UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay);
|
||||
params.max_delay_ratio = UTI_FloatNetworkToHost(rx_message->data.ntp_source.max_delay_ratio);
|
||||
status = NSR_AddPeer(&rem_addr, ¶ms);
|
||||
status = NSR_AddSource(&rem_addr, NTP_PEER, ¶ms);
|
||||
switch (status) {
|
||||
case NSR_Success:
|
||||
tx_message->status = htons(STT_SUCCESS);
|
||||
|
|
19
conf.c
19
conf.c
|
@ -260,10 +260,6 @@ static int line_number;
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
typedef enum {
|
||||
SERVER, PEER
|
||||
} NTP_Source_Type;
|
||||
|
||||
typedef struct {
|
||||
NTP_Source_Type type;
|
||||
IPAddr ip_addr;
|
||||
|
@ -433,7 +429,7 @@ parse_lockall(const char *line)
|
|||
static void
|
||||
parse_server(const char *line)
|
||||
{
|
||||
parse_source(line, SERVER);
|
||||
parse_source(line, NTP_SERVER);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
@ -441,7 +437,7 @@ parse_server(const char *line)
|
|||
static void
|
||||
parse_peer(const char *line)
|
||||
{
|
||||
parse_source(line, PEER);
|
||||
parse_source(line, NTP_PEER);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
@ -1199,16 +1195,7 @@ CNF_AddSources(void) {
|
|||
memset(&server.local_ip_addr, 0, sizeof (server.local_ip_addr));
|
||||
server.port = ntp_sources[i].port;
|
||||
|
||||
switch (ntp_sources[i].type) {
|
||||
case SERVER:
|
||||
NSR_AddServer(&server, &ntp_sources[i].params);
|
||||
break;
|
||||
|
||||
case PEER:
|
||||
NSR_AddPeer(&server, &ntp_sources[i].params);
|
||||
break;
|
||||
}
|
||||
|
||||
NSR_AddSource(&server, ntp_sources[i].type, &ntp_sources[i].params);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
33
ntp_core.c
33
ntp_core.c
|
@ -247,15 +247,24 @@ start_initial_timeout(NCR_Instance inst)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
static NCR_Instance
|
||||
create_instance(NTP_Remote_Address *remote_addr, NTP_Mode mode, SourceParameters *params)
|
||||
NCR_Instance
|
||||
NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParameters *params)
|
||||
{
|
||||
NCR_Instance result;
|
||||
|
||||
result = MallocNew(struct NCR_Instance_Record);
|
||||
|
||||
result->remote_addr = *remote_addr;
|
||||
result->mode = mode;
|
||||
switch (type) {
|
||||
case NTP_SERVER:
|
||||
result->mode = MODE_CLIENT;
|
||||
break;
|
||||
case NTP_PEER:
|
||||
result->mode = MODE_ACTIVE;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
result->minpoll = params->minpoll;
|
||||
result->maxpoll = params->maxpoll;
|
||||
|
@ -314,24 +323,6 @@ create_instance(NTP_Remote_Address *remote_addr, NTP_Mode mode, SourceParameters
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
/* Get a new instance for a server */
|
||||
NCR_Instance
|
||||
NCR_GetServerInstance(NTP_Remote_Address *remote_addr, SourceParameters *params)
|
||||
{
|
||||
return create_instance(remote_addr, MODE_CLIENT, params);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
/* Get a new instance for a peer */
|
||||
NCR_Instance
|
||||
NCR_GetPeerInstance(NTP_Remote_Address *remote_addr, SourceParameters *params)
|
||||
{
|
||||
return create_instance(remote_addr, MODE_ACTIVE, params);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
/* Destroy an instance */
|
||||
void
|
||||
NCR_DestroyInstance(NCR_Instance instance)
|
||||
|
|
11
ntp_core.h
11
ntp_core.h
|
@ -38,6 +38,10 @@
|
|||
#include "ntp.h"
|
||||
#include "reports.h"
|
||||
|
||||
typedef enum {
|
||||
NTP_SERVER, NTP_PEER
|
||||
} NTP_Source_Type;
|
||||
|
||||
/* This is a private data type used for storing the instance record for
|
||||
each source that we are chiming with */
|
||||
typedef struct NCR_Instance_Record *NCR_Instance;
|
||||
|
@ -46,11 +50,8 @@ typedef struct NCR_Instance_Record *NCR_Instance;
|
|||
extern void NCR_Initialise(void);
|
||||
extern void NCR_Finalise(void);
|
||||
|
||||
/* Get a new instance for a server */
|
||||
extern NCR_Instance NCR_GetServerInstance(NTP_Remote_Address *remote_addr, SourceParameters *params);
|
||||
|
||||
/* Get a new instance for a peer */
|
||||
extern NCR_Instance NCR_GetPeerInstance(NTP_Remote_Address *remote_addr, SourceParameters *params);
|
||||
/* Get a new instance for a server or peer */
|
||||
extern NCR_Instance NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParameters *params);
|
||||
|
||||
/* Destroy an instance */
|
||||
extern void NCR_DestroyInstance(NCR_Instance instance);
|
||||
|
|
|
@ -170,10 +170,9 @@ find_slot(NTP_Remote_Address *remote_addr, int *slot, int *found)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
/* Procedure to add a new server source (to which this machine will be
|
||||
a client) */
|
||||
/* Procedure to add a new source */
|
||||
NSR_Status
|
||||
NSR_AddServer(NTP_Remote_Address *remote_addr, SourceParameters *params)
|
||||
NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParameters *params)
|
||||
{
|
||||
int slot, found;
|
||||
|
||||
|
@ -195,40 +194,7 @@ NSR_AddServer(NTP_Remote_Address *remote_addr, SourceParameters *params)
|
|||
return NSR_InvalidAF;
|
||||
} else {
|
||||
n_sources++;
|
||||
records[slot].data = NCR_GetServerInstance(remote_addr, params); /* Will need params passing through */
|
||||
records[slot].remote_addr = NCR_GetRemoteAddress(records[slot].data);
|
||||
return NSR_Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
/* Procedure to add a new peer. */
|
||||
NSR_Status
|
||||
NSR_AddPeer(NTP_Remote_Address *remote_addr, SourceParameters *params)
|
||||
{
|
||||
int slot, found;
|
||||
|
||||
assert(initialised);
|
||||
|
||||
#if 0
|
||||
LOG(LOGS_INFO, LOGF_NtpSources, "IP=%s port=%d", UTI_IPToString(&remote_addr->ip_addr), remote_addr->port);
|
||||
#endif
|
||||
|
||||
/* Find empty bin & check that we don't have the address already */
|
||||
find_slot(remote_addr, &slot, &found);
|
||||
if (found) {
|
||||
return NSR_AlreadyInUse;
|
||||
} else {
|
||||
if (n_sources == MAX_SOURCES) {
|
||||
return NSR_TooManySources;
|
||||
} else if (remote_addr->ip_addr.family != IPADDR_INET4 &&
|
||||
remote_addr->ip_addr.family != IPADDR_INET6) {
|
||||
return NSR_InvalidAF;
|
||||
} else {
|
||||
n_sources++;
|
||||
records[slot].data = NCR_GetPeerInstance(remote_addr, params); /* Will need params passing through */
|
||||
records[slot].data = NCR_GetInstance(remote_addr, type, params); /* Will need params passing through */
|
||||
records[slot].remote_addr = NCR_GetRemoteAddress(records[slot].data);
|
||||
return NSR_Success;
|
||||
}
|
||||
|
|
|
@ -45,18 +45,13 @@
|
|||
typedef enum {
|
||||
NSR_Success, /* Operation successful */
|
||||
NSR_NoSuchSource, /* Remove - attempt to remove a source that is not known */
|
||||
NSR_AlreadyInUse, /* AddServer, AddPeer - attempt to add a source that is already known */
|
||||
NSR_TooManySources, /* AddServer, AddPeer - too many sources already present */
|
||||
NSR_InvalidAF /* AddServer, AddPeer - attempt to add a source with invalid address family */
|
||||
NSR_AlreadyInUse, /* AddSource - attempt to add a source that is already known */
|
||||
NSR_TooManySources, /* AddSource - too many sources already present */
|
||||
NSR_InvalidAF /* AddSource - attempt to add a source with invalid address family */
|
||||
} NSR_Status;
|
||||
|
||||
/* Procedure to add a new server source (to which this machine will be
|
||||
a client) */
|
||||
extern NSR_Status NSR_AddServer(NTP_Remote_Address *remote_addr, SourceParameters *params);
|
||||
|
||||
/* Procedure to add a new peer source. We will use symmetric active
|
||||
mode packets when communicating with this source */
|
||||
extern NSR_Status NSR_AddPeer(NTP_Remote_Address *remote_addr, SourceParameters *params);
|
||||
/* Procedure to add a new server or peer source. */
|
||||
extern NSR_Status NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourceParameters *params);
|
||||
|
||||
/* Procedure to remove a source */
|
||||
extern NSR_Status NSR_RemoveSource(NTP_Remote_Address *remote_addr);
|
||||
|
|
Loading…
Reference in a new issue