From 2ea87490f454c88e91874f140937996c99d4bfef Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 2 Apr 2010 15:55:58 +0200 Subject: [PATCH] Mark offline sources unreachable --- ntp_core.c | 9 +++++++++ ntp_core.h | 2 ++ ntp_sources.c | 13 +++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index c0eada3..6e3abf7 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1709,6 +1709,8 @@ NCR_TakeSourceOffline(NCR_Instance inst) SCH_RemoveTimeout(inst->timeout_id); inst->timer_running = 0; inst->opmode = MD_OFFLINE; + /* Mark source unreachable */ + SRC_UnsetReachable(inst->source); } break; case MD_OFFLINE: @@ -1923,3 +1925,10 @@ NCR_GetRemoteAddress(NCR_Instance inst) } /* ================================================== */ + +int NCR_IsSyncPeer(NCR_Instance inst) +{ + return SRC_IsSyncPeer(inst->source); +} + +/* ================================================== */ diff --git a/ntp_core.h b/ntp_core.h index ee22e46..1a8efcc 100644 --- a/ntp_core.h +++ b/ntp_core.h @@ -104,4 +104,6 @@ extern void NCR_IncrementActivityCounters(NCR_Instance inst, int *online, int *o extern NTP_Remote_Address *NCR_GetRemoteAddress(NCR_Instance instance); +extern int NCR_IsSyncPeer(NCR_Instance instance); + #endif /* GOT_NTP_CORE_H */ diff --git a/ntp_sources.c b/ntp_sources.c index 9a058f3..eeca7ce 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -355,20 +355,29 @@ NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address) int NSR_TakeSourcesOffline(IPAddr *mask, IPAddr *address) { - int i; - int any; + int i, any, syncpeer; any = 0; + syncpeer = -1; for (i=0; ifamily == IPADDR_UNSPEC || !UTI_CompareIPs(&records[i].remote_addr->ip_addr, address, mask)) { any = 1; + if (NCR_IsSyncPeer(records[i].data)) { + syncpeer = i; + continue; + } NCR_TakeSourceOffline(records[i].data); } } } + /* Take sync peer offline as last to avoid reference switching */ + if (syncpeer >= 0) { + NCR_TakeSourceOffline(records[syncpeer].data); + } + return any; }