1 /* 2 chronyd/chronyc - Programs for keeping computer clocks accurate. 3 4 ********************************************************************** 5 * Copyright (C) Richard P. Curnow 1997-2002 6 * Copyright (C) Miroslav Lichvar 2014 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of version 2 of the GNU General Public License as 10 * published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program; if not, write to the Free Software Foundation, Inc., 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 ********************************************************************** 22 23 ======================================================================= 24 25 This is the header for the module that manages the collection of all 26 sources that we are making measurements from. This include all NTP 27 servers & peers, locally connected reference sources, eye/wristwatch 28 drivers etc */ 29 30 #ifndef GOT_SOURCES_H 31 #define GOT_SOURCES_H 32 33 #include "sysincl.h" 34 35 #include "ntp.h" 36 #include "reports.h" 37 #include "sourcestats.h" 38 39 /* Size of the source reachability register */ 40 #define SOURCE_REACH_BITS 8 41 42 /* This datatype is used to hold information about sources. The 43 instance must be passed when calling many of the interface 44 functions */ 45 46 typedef struct SRC_Instance_Record *SRC_Instance; 47 48 /* Initialisation function */ 49 extern void SRC_Initialise(void); 50 51 /* Finalisation function */ 52 extern void SRC_Finalise(void); 53 54 /* Modes for selecting NTP sources based on their authentication status */ 55 typedef enum { 56 SRC_AUTHSELECT_IGNORE, 57 SRC_AUTHSELECT_MIX, 58 SRC_AUTHSELECT_PREFER, 59 SRC_AUTHSELECT_REQUIRE, 60 } SRC_AuthSelectMode; 61 62 typedef enum { 63 SRC_NTP, /* NTP client/peer */ 64 SRC_REFCLOCK /* Rerefence clock */ 65 } SRC_Type; 66 67 /* Function to create a new instance. This would be called by one of 68 the individual source-type instance creation routines. */ 69 70 extern SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, int authenticated, 71 int sel_options, IPAddr *addr, int min_samples, 72 int max_samples, double min_delay, double asymmetry); 73 74 /* Function to get rid of a source when it is being unconfigured. 75 This may cause the current reference source to be reselected, if this 76 was the reference source or contributed significantly to a 77 falseticker decision. */ 78 79 extern void SRC_DestroyInstance(SRC_Instance instance); 80 81 /* Function to reset a source */ 82 extern void SRC_ResetInstance(SRC_Instance instance); 83 84 /* Function to change the sources's reference ID and IP address */ 85 extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr); 86 87 /* Function to get access to the sourcestats instance */ 88 extern SST_Stats SRC_GetSourcestats(SRC_Instance instance); 89 90 /* Function to update the stratum and leap status of the source */ 91 extern void SRC_UpdateStatus(SRC_Instance instance, int stratum, NTP_Leap leap); 92 93 /* Function to accumulate a new sample from the source */ 94 extern void SRC_AccumulateSample(SRC_Instance instance, NTP_Sample *sample); 95 96 /* This routine sets the source as receiving reachability updates */ 97 extern void SRC_SetActive(SRC_Instance inst); 98 99 /* This routine sets the source as not receiving reachability updates */ 100 extern void SRC_UnsetActive(SRC_Instance inst); 101 102 /* This routine updates the reachability register */ 103 extern void SRC_UpdateReachability(SRC_Instance inst, int reachable); 104 105 /* This routine marks the source unreachable */ 106 extern void SRC_ResetReachability(SRC_Instance inst); 107 108 /* This routine is used to select the best source from amongst those 109 we currently have valid data on, and use it as the tracking base 110 for the local time. Updates are made to the local reference only 111 when the selected source was updated (set as updated_inst) since 112 the last reference update. This avoids updating the frequency 113 tracking for every sample from other sources - only the ones from 114 the selected reference make a difference. */ 115 extern void SRC_SelectSource(SRC_Instance updated_inst); 116 117 /* Force reselecting the best source */ 118 extern void SRC_ReselectSource(void); 119 120 /* Set reselect distance */ 121 extern void SRC_SetReselectDistance(double distance); 122 123 extern void SRC_DumpSources(void); 124 extern void SRC_ReloadSources(void); 125 extern void SRC_RemoveDumpFiles(void); 126 127 extern void SRC_ResetSources(void); 128 129 extern int SRC_IsSyncPeer(SRC_Instance inst); 130 extern int SRC_IsReachable(SRC_Instance inst); 131 extern int SRC_ReadNumberOfSources(void); 132 extern int SRC_ActiveSources(void); 133 134 extern int SRC_ReportSource(int index, RPT_SourceReport *report, struct timespec *now); 135 extern int SRC_ReportSourcestats(int index, RPT_SourcestatsReport *report, struct timespec *now); 136 extern int SRC_GetSelectReport(int index, RPT_SelectReport *report); 137 138 extern SRC_Type SRC_GetType(int index); 139 140 #endif /* GOT_SOURCES_H */ 141