conf: use array for broadcast destinations
This commit is contained in:
parent
aba4596ba9
commit
c9571e55f5
1 changed files with 18 additions and 22 deletions
40
conf.c
40
conf.c
|
@ -217,15 +217,13 @@ static ARR_Instance ntp_restrictions;
|
||||||
static ARR_Instance cmd_restrictions;
|
static ARR_Instance cmd_restrictions;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Both in host (not necessarily network) order */
|
|
||||||
IPAddr addr;
|
IPAddr addr;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
int interval;
|
int interval;
|
||||||
} NTP_Broadcast_Destination;
|
} NTP_Broadcast_Destination;
|
||||||
|
|
||||||
static NTP_Broadcast_Destination *broadcasts = NULL;
|
/* Array of NTP_Broadcast_Destination */
|
||||||
static int max_broadcasts = 0;
|
static ARR_Instance broadcasts;
|
||||||
static int n_broadcasts = 0;
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
@ -286,6 +284,7 @@ CNF_Initialise(int r)
|
||||||
init_sources = ARR_CreateInstance(sizeof (IPAddr));
|
init_sources = ARR_CreateInstance(sizeof (IPAddr));
|
||||||
ntp_sources = ARR_CreateInstance(sizeof (NTP_Source));
|
ntp_sources = ARR_CreateInstance(sizeof (NTP_Source));
|
||||||
refclock_sources = ARR_CreateInstance(sizeof (RefclockParameters));
|
refclock_sources = ARR_CreateInstance(sizeof (RefclockParameters));
|
||||||
|
broadcasts = ARR_CreateInstance(sizeof (NTP_Broadcast_Destination));
|
||||||
|
|
||||||
ntp_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
ntp_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
||||||
cmd_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
cmd_restrictions = ARR_CreateInstance(sizeof (AllowDeny));
|
||||||
|
@ -310,6 +309,7 @@ CNF_Finalise(void)
|
||||||
ARR_DestroyInstance(init_sources);
|
ARR_DestroyInstance(init_sources);
|
||||||
ARR_DestroyInstance(ntp_sources);
|
ARR_DestroyInstance(ntp_sources);
|
||||||
ARR_DestroyInstance(refclock_sources);
|
ARR_DestroyInstance(refclock_sources);
|
||||||
|
ARR_DestroyInstance(broadcasts);
|
||||||
|
|
||||||
ARR_DestroyInstance(ntp_restrictions);
|
ARR_DestroyInstance(ntp_restrictions);
|
||||||
ARR_DestroyInstance(cmd_restrictions);
|
ARR_DestroyInstance(cmd_restrictions);
|
||||||
|
@ -1088,6 +1088,7 @@ static void
|
||||||
parse_broadcast(char *line)
|
parse_broadcast(char *line)
|
||||||
{
|
{
|
||||||
/* Syntax : broadcast <interval> <broadcast-IP-addr> [<port>] */
|
/* Syntax : broadcast <interval> <broadcast-IP-addr> [<port>] */
|
||||||
|
NTP_Broadcast_Destination *destination;
|
||||||
int port;
|
int port;
|
||||||
int interval;
|
int interval;
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -1122,20 +1123,10 @@ parse_broadcast(char *line)
|
||||||
port = 123;
|
port = 123;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_broadcasts == n_broadcasts) {
|
destination = (NTP_Broadcast_Destination *)ARR_GetNewElement(broadcasts);
|
||||||
/* Expand array */
|
destination->addr = ip;
|
||||||
max_broadcasts += 8;
|
destination->port = port;
|
||||||
if (broadcasts) {
|
destination->interval = interval;
|
||||||
broadcasts = ReallocArray(NTP_Broadcast_Destination, max_broadcasts, broadcasts);
|
|
||||||
} else {
|
|
||||||
broadcasts = MallocArray(NTP_Broadcast_Destination, max_broadcasts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
broadcasts[n_broadcasts].addr = ip;
|
|
||||||
broadcasts[n_broadcasts].port = port;
|
|
||||||
broadcasts[n_broadcasts].interval = interval;
|
|
||||||
++n_broadcasts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
@ -1234,11 +1225,16 @@ CNF_AddRefclocks(void)
|
||||||
void
|
void
|
||||||
CNF_AddBroadcasts(void)
|
CNF_AddBroadcasts(void)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int i;
|
||||||
for (i=0; i<n_broadcasts; i++) {
|
NTP_Broadcast_Destination *destination;
|
||||||
NCR_AddBroadcastDestination(&broadcasts[i].addr, broadcasts[i].port,
|
|
||||||
broadcasts[i].interval);
|
for (i = 0; i < ARR_GetSize(broadcasts); i++) {
|
||||||
|
destination = (NTP_Broadcast_Destination *)ARR_GetElement(broadcasts, i);
|
||||||
|
NCR_AddBroadcastDestination(&destination->addr, destination->port,
|
||||||
|
destination->interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ARR_SetSize(broadcasts, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
Loading…
Reference in a new issue