msg->data.ntp_source.asymmetry = UTI_FloatHostToNetwork(data.params.asymmetry);
msg->data.ntp_source.offset = UTI_FloatHostToNetwork(data.params.offset);
msg->data.ntp_source.flags = htonl(
- (data.params.online ? REQ_ADDSRC_ONLINE : 0) |
+ (data.params.connectivity == SRC_ONLINE ? REQ_ADDSRC_ONLINE : 0) |
(data.params.auto_offline ? REQ_ADDSRC_AUTOOFFLINE : 0) |
(data.params.iburst ? REQ_ADDSRC_IBURST : 0) |
(data.params.interleaved ? REQ_ADDSRC_INTERLEAVED : 0) |
UTI_IPNetworkToHost(&rx_message->data.online.mask, &mask);
UTI_IPNetworkToHost(&rx_message->data.online.address, &address);
- if (!NSR_TakeSourcesOnline(&mask, &address))
+ if (!NSR_SetConnectivity(&mask, &address, SRC_ONLINE))
tx_message->status = htons(STT_NOSUCHSOURCE);
}
UTI_IPNetworkToHost(&rx_message->data.offline.mask, &mask);
UTI_IPNetworkToHost(&rx_message->data.offline.address, &address);
- if (!NSR_TakeSourcesOffline(&mask, &address))
+ if (!NSR_SetConnectivity(&mask, &address, SRC_OFFLINE))
tx_message->status = htons(STT_NOSUCHSOURCE);
}
params.asymmetry = UTI_FloatNetworkToHost(rx_message->data.ntp_source.asymmetry);
params.offset = UTI_FloatNetworkToHost(rx_message->data.ntp_source.offset);
- params.online = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_ONLINE ? 1 : 0;
+ params.connectivity = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_ONLINE ?
+ SRC_ONLINE : SRC_OFFLINE;
params.auto_offline = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_AUTOOFFLINE ? 1 : 0;
params.iburst = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_IBURST ? 1 : 0;
params.interleaved = ntohl(rx_message->data.ntp_source.flags) & REQ_ADDSRC_INTERLEAVED ? 1 : 0;
src->port = SRC_DEFAULT_PORT;
src->params.minpoll = SRC_DEFAULT_MINPOLL;
src->params.maxpoll = SRC_DEFAULT_MAXPOLL;
- src->params.online = 1;
+ src->params.connectivity = SRC_ONLINE;
src->params.auto_offline = 0;
src->params.presend_minpoll = SRC_DEFAULT_PRESEND_MINPOLL;
src->params.burst = 0;
} else if (!strcasecmp(cmd, "iburst")) {
src->params.iburst = 1;
} else if (!strcasecmp(cmd, "offline")) {
- src->params.online = 0;
+ src->params.connectivity = SRC_OFFLINE;
} else if (!strcasecmp(cmd, "noselect")) {
src->params.sel_options |= SRC_SELECT_NOSELECT;
} else if (!strcasecmp(cmd, "prefer")) {
ntp_addr.ip_addr = *(IPAddr *)ARR_GetElement(init_sources, i);
ntp_addr.port = cps_source.port;
cps_source.params.iburst = 1;
- cps_source.params.online = 0;
+ cps_source.params.connectivity = SRC_OFFLINE;
NSR_AddSource(&ntp_addr, NTP_SERVER, &cps_source.params);
}
result->rx_timeout_id = 0;
result->tx_timeout_id = 0;
result->tx_suspended = 1;
- result->opmode = params->online ? MD_ONLINE : MD_OFFLINE;
+ result->opmode = params->connectivity == SRC_ONLINE ? MD_ONLINE : MD_OFFLINE;
result->local_poll = result->minpoll;
result->poll_score = 0.0;
zero_local_timestamp(&result->local_tx);
/* With auto_offline take the source offline on 2nd missed reply */
if (inst->auto_offline && inst->tx_count >= 2)
- NCR_TakeSourceOffline(inst);
+ NCR_SetConnectivity(inst, SRC_OFFLINE);
if (inst->opmode == MD_OFFLINE) {
return;
/* ================================================== */
void
-NCR_TakeSourceOnline(NCR_Instance inst)
+NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity)
{
- switch (inst->opmode) {
- case MD_ONLINE:
- /* Nothing to do */
- break;
- case MD_OFFLINE:
- LOG(LOGS_INFO, "Source %s online", UTI_IPToString(&inst->remote_addr.ip_addr));
- inst->opmode = MD_ONLINE;
- NCR_ResetInstance(inst);
- start_initial_timeout(inst);
- break;
- case MD_BURST_WAS_ONLINE:
- /* Will revert */
- break;
- case MD_BURST_WAS_OFFLINE:
- inst->opmode = MD_BURST_WAS_ONLINE;
- LOG(LOGS_INFO, "Source %s online", UTI_IPToString(&inst->remote_addr.ip_addr));
- break;
- }
-}
+ char *s;
-/* ================================================== */
+ s = UTI_IPToString(&inst->remote_addr.ip_addr);
-void
-NCR_TakeSourceOffline(NCR_Instance inst)
-{
- switch (inst->opmode) {
- case MD_ONLINE:
- LOG(LOGS_INFO, "Source %s offline", UTI_IPToString(&inst->remote_addr.ip_addr));
- take_offline(inst);
- break;
- case MD_OFFLINE:
- break;
- case MD_BURST_WAS_ONLINE:
- inst->opmode = MD_BURST_WAS_OFFLINE;
- LOG(LOGS_INFO, "Source %s offline", UTI_IPToString(&inst->remote_addr.ip_addr));
+ switch (connectivity) {
+ case SRC_ONLINE:
+ switch (inst->opmode) {
+ case MD_ONLINE:
+ /* Nothing to do */
+ break;
+ case MD_OFFLINE:
+ LOG(LOGS_INFO, "Source %s online", s);
+ inst->opmode = MD_ONLINE;
+ NCR_ResetInstance(inst);
+ start_initial_timeout(inst);
+ break;
+ case MD_BURST_WAS_ONLINE:
+ /* Will revert */
+ break;
+ case MD_BURST_WAS_OFFLINE:
+ inst->opmode = MD_BURST_WAS_ONLINE;
+ LOG(LOGS_INFO, "Source %s online", s);
+ break;
+ default:
+ assert(0);
+ }
break;
- case MD_BURST_WAS_OFFLINE:
+ case SRC_OFFLINE:
+ switch (inst->opmode) {
+ case MD_ONLINE:
+ LOG(LOGS_INFO, "Source %s offline", s);
+ take_offline(inst);
+ break;
+ case MD_OFFLINE:
+ break;
+ case MD_BURST_WAS_ONLINE:
+ inst->opmode = MD_BURST_WAS_OFFLINE;
+ LOG(LOGS_INFO, "Source %s offline", s);
+ break;
+ case MD_BURST_WAS_OFFLINE:
+ break;
+ default:
+ assert(0);
+ }
break;
+ default:
+ assert(0);
}
-
}
/* ================================================== */
/* Slew receive and transmit times in instance records */
extern void NCR_SlewTimes(NCR_Instance inst, struct timespec *when, double dfreq, double doffset);
-/* Take a particular source online (i.e. start sampling it) */
-extern void NCR_TakeSourceOnline(NCR_Instance inst);
-
-/* Take a particular source offline (i.e. stop sampling it, without
- marking it unreachable in the source selection stuff) */
-extern void NCR_TakeSourceOffline(NCR_Instance inst);
+/* Take a particular source online (i.e. start sampling it) or offline
+ (i.e. stop sampling it) */
+extern void NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity);
extern void NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll);
/* ================================================== */
int
-NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address)
-{
- SourceRecord *record;
- unsigned int i;
- int any;
-
- NSR_ResolveSources();
-
- any = 0;
- for (i = 0; i < ARR_GetSize(records); i++) {
- record = get_record(i);
- if (record->remote_addr) {
- if (address->family == IPADDR_UNSPEC ||
- !UTI_CompareIPs(&record->remote_addr->ip_addr, address, mask)) {
- any = 1;
- NCR_TakeSourceOnline(record->data);
- }
- }
- }
-
- if (address->family == IPADDR_UNSPEC) {
- struct UnresolvedSource *us;
-
- for (us = unresolved_sources; us; us = us->next) {
- if (us->replacement)
- continue;
- any = 1;
- us->new_source.params.online = 1;
- }
- }
-
- return any;
-}
-
-/* ================================================== */
-
-int
-NSR_TakeSourcesOffline(IPAddr *mask, IPAddr *address)
+NSR_SetConnectivity(IPAddr *mask, IPAddr *address, SRC_Connectivity connectivity)
{
SourceRecord *record, *syncpeer;
unsigned int i, any;
+ if (connectivity != SRC_OFFLINE)
+ NSR_ResolveSources();
+
any = 0;
syncpeer = NULL;
for (i = 0; i < ARR_GetSize(records); i++) {
syncpeer = record;
continue;
}
- NCR_TakeSourceOffline(record->data);
+ NCR_SetConnectivity(record->data, connectivity);
}
}
}
- /* Take sync peer offline as last to avoid reference switching */
- if (syncpeer) {
- NCR_TakeSourceOffline(syncpeer->data);
- }
+ /* Set the sync peer last to avoid unnecessary reference switching */
+ if (syncpeer)
+ NCR_SetConnectivity(syncpeer->data, connectivity);
if (address->family == IPADDR_UNSPEC) {
struct UnresolvedSource *us;
if (us->replacement)
continue;
any = 1;
- us->new_source.params.online = 0;
+ us->new_source.params.connectivity = connectivity;
}
}
extern void NSR_Finalise(void);
/* This routine is used to indicate that sources whose IP addresses
- match a particular subnet should be set online again. Returns a
- flag indicating whether any hosts matched the address */
-extern int NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address);
-
-/* This routine is used to indicate that sources whose IP addresses
- match a particular subnet should be set offline. Returns a flag
- indicating whether any hosts matched the address */
-extern int NSR_TakeSourcesOffline(IPAddr *mask, IPAddr *address);
+ match a particular subnet should be set online or offline. It returns
+ a flag indicating whether any hosts matched the address. */
+extern int NSR_SetConnectivity(IPAddr *mask, IPAddr *address, SRC_Connectivity connectivity);
extern int NSR_ModifyMinpoll(IPAddr *address, int new_minpoll);
#include "sources.h"
+typedef enum {
+ SRC_OFFLINE,
+ SRC_ONLINE,
+} SRC_Connectivity;
+
typedef struct {
int minpoll;
int maxpoll;
- int online;
+ SRC_Connectivity connectivity;
int auto_offline;
int presend_minpoll;
int burst;
}
int
-NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address)
-{
- return 0;
-}
-
-int
-NSR_TakeSourcesOffline(IPAddr *mask, IPAddr *address)
+NSR_SetConnectivity(IPAddr *mask, IPAddr *address, SRC_Connectivity connectivity)
{
return 0;
}