2 chronyd/chronyc - Programs for keeping computer clocks accurate.
4 **********************************************************************
5 * Copyright (C) Richard P. Curnow 1997-2002
6 * Copyright (C) Miroslav Lichvar 2014
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.
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.
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.
21 **********************************************************************
23 =======================================================================
25 Header for the part of the software that deals with the set of
26 current NTP servers and peers, which can resolve an IP address into
27 a source record for further processing.
31 #ifndef GOT_NTP_SOURCES_H
32 #define GOT_NTP_SOURCES_H
35 #include "addressing.h"
36 #include "srcparams.h"
40 /* Status values returned by operations that indirectly result from user
43 NSR_Success
, /* Operation successful */
44 NSR_NoSuchSource
, /* Remove - attempt to remove a source that is not known */
45 NSR_AlreadyInUse
, /* AddSource - attempt to add a source that is already known */
46 NSR_TooManySources
, /* AddSource - too many sources already present */
47 NSR_InvalidAF
, /* AddSource - attempt to add a source with invalid address family */
48 NSR_InvalidName
, /* AddSourceByName - attempt to add a source with invalid name */
49 NSR_UnresolvedName
, /* AddSourceByName - name will be resolved later */
52 /* Procedure to add a new server or peer source. */
53 extern NSR_Status
NSR_AddSource(NTP_Remote_Address
*remote_addr
, NTP_Source_Type type
,
54 SourceParameters
*params
, uint32_t *conf_id
);
56 /* Procedure to add a new server, peer source, or pool of servers specified by
57 name instead of address. The name is resolved in exponentially increasing
58 intervals until it succeeds or fails with a non-temporary error. If the
59 name is an address, it is equivalent to NSR_AddSource(). */
60 extern NSR_Status
NSR_AddSourceByName(char *name
, int port
, int pool
, NTP_Source_Type type
,
61 SourceParameters
*params
, uint32_t *conf_id
);
63 /* Function type for handlers to be called back when an attempt
64 * (possibly unsuccessful) to resolve unresolved sources ends */
65 typedef void (*NSR_SourceResolvingEndHandler
)(void);
67 /* Set the handler, or NULL to disable the notification */
68 extern void NSR_SetSourceResolvingEndHandler(NSR_SourceResolvingEndHandler handler
);
70 /* Procedure to start resolving unresolved sources */
71 extern void NSR_ResolveSources(void);
73 /* Procedure to start all sources */
74 extern void NSR_StartSources(void);
76 /* Start new sources automatically */
77 extern void NSR_AutoStartSources(void);
79 /* Procedure to remove a source */
80 extern NSR_Status
NSR_RemoveSource(IPAddr
*address
);
82 /* Procedure to remove all sources matching a configuration ID */
83 extern void NSR_RemoveSourcesById(uint32_t conf_id
);
85 /* Procedure to remove all sources */
86 extern void NSR_RemoveAllSources(void);
88 /* Procedure to try to find a replacement for a bad source */
89 extern void NSR_HandleBadSource(IPAddr
*address
);
91 /* Procedure to resolve all names again */
92 extern void NSR_RefreshAddresses(void);
94 /* Procedure to update the address of a source. The update may be
96 extern NSR_Status
NSR_UpdateSourceNtpAddress(NTP_Remote_Address
*old_addr
,
97 NTP_Remote_Address
*new_addr
);
99 /* Procedure to get local reference ID corresponding to a source */
100 extern uint32_t NSR_GetLocalRefid(IPAddr
*address
);
102 /* Procedure to get the name of a source as it was specified (it may be
104 extern char *NSR_GetName(IPAddr
*address
);
106 /* This routine is called by ntp_io when a new packet arrives off the network */
107 extern void NSR_ProcessRx(NTP_Remote_Address
*remote_addr
, NTP_Local_Address
*local_addr
,
108 NTP_Local_Timestamp
*rx_ts
, NTP_Packet
*message
, int length
);
110 /* This routine is called by ntp_io when a packet was sent to the network and
111 an accurate transmit timestamp was captured */
112 extern void NSR_ProcessTx(NTP_Remote_Address
*remote_addr
, NTP_Local_Address
*local_addr
,
113 NTP_Local_Timestamp
*tx_ts
, NTP_Packet
*message
, int length
);
115 /* Initialisation function */
116 extern void NSR_Initialise(void);
118 /* Finalisation function */
119 extern void NSR_Finalise(void);
121 /* This routine is used to indicate that sources whose IP addresses
122 match a particular subnet should be set online or offline. It returns
123 a flag indicating whether any hosts matched the address. */
124 extern int NSR_SetConnectivity(IPAddr
*mask
, IPAddr
*address
, SRC_Connectivity connectivity
);
126 extern int NSR_ModifyMinpoll(IPAddr
*address
, int new_minpoll
);
128 extern int NSR_ModifyMaxpoll(IPAddr
*address
, int new_maxpoll
);
130 extern int NSR_ModifyMaxdelay(IPAddr
*address
, double new_max_delay
);
132 extern int NSR_ModifyMaxdelayratio(IPAddr
*address
, double new_max_delay_ratio
);
134 extern int NSR_ModifyMaxdelaydevratio(IPAddr
*address
, double new_max_delay_ratio
);
136 extern int NSR_ModifyMinstratum(IPAddr
*address
, int new_min_stratum
);
138 extern int NSR_ModifyPolltarget(IPAddr
*address
, int new_poll_target
);
140 extern int NSR_InitiateSampleBurst(int n_good_samples
, int n_total_samples
, IPAddr
*mask
, IPAddr
*address
);
142 extern void NSR_ReportSource(RPT_SourceReport
*report
, struct timespec
*now
);
144 extern int NSR_GetAuthReport(IPAddr
*address
, RPT_AuthReport
*report
);
146 extern int NSR_GetNTPReport(RPT_NTPReport
*report
);
148 extern void NSR_GetActivityReport(RPT_ActivityReport
*report
);
150 extern void NSR_DumpAuthData(void);
152 #endif /* GOT_NTP_SOURCES_H */