ntp: allow online/offline state to be selected by connectability

Allow SRC_MAYBE_ONLINE to be specified for new NTP sources and
connectivity setting to select between SRC_ONLINE and SRC_OFFLINE
according to the result of the connect() system call, i.e. check whether
the client has a route to send its requests.
This commit is contained in:
Miroslav Lichvar
2018-05-24 15:17:53 +02:00
parent ce6b896948
commit 8b9021bf34
4 changed files with 27 additions and 1 deletions

View File

@@ -603,7 +603,9 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar
result->rx_timeout_id = 0;
result->tx_timeout_id = 0;
result->tx_suspended = 1;
result->opmode = params->connectivity == SRC_ONLINE ? MD_ONLINE : MD_OFFLINE;
result->opmode = params->connectivity == SRC_ONLINE ||
(params->connectivity == SRC_MAYBE_ONLINE &&
NIO_IsServerConnectable(remote_addr)) ? MD_ONLINE : MD_OFFLINE;
result->local_poll = result->minpoll;
result->poll_score = 0.0;
zero_local_timestamp(&result->local_tx);
@@ -2281,6 +2283,9 @@ NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity)
s = UTI_IPToString(&inst->remote_addr.ip_addr);
if (connectivity == SRC_MAYBE_ONLINE)
connectivity = NIO_IsServerConnectable(&inst->remote_addr) ? SRC_ONLINE : SRC_OFFLINE;
switch (connectivity) {
case SRC_ONLINE:
switch (inst->opmode) {