xref: /freebsd/contrib/ntp/include/ntp_config.h (revision 148a8da8)
1 #ifndef NTP_CONFIG_H
2 #define NTP_CONFIG_H
3 
4 #ifdef HAVE_SYS_RESOURCE_H
5 # include <sys/resource.h>
6 #endif /* HAVE_SYS_RESOURCE_H */
7 
8 #include "ntp_machine.h"
9 #include "ntpsim.h"
10 
11 
12 /*
13  * Configuration file name
14  */
15 #ifndef CONFIG_FILE
16 # ifndef SYS_WINNT
17 #  define	CONFIG_FILE "/etc/ntp.conf"
18 # else /* SYS_WINNT */
19 #  define	CONFIG_FILE	"%windir%\\system32\\drivers\\etc\\ntp.conf"
20 #  define	ALT_CONFIG_FILE "%windir%\\ntp.conf"
21 #  define	NTP_KEYSDIR	"%windir%\\system32\\drivers\\etc"
22 # endif /* SYS_WINNT */
23 #endif /* not CONFIG_FILE */
24 
25 
26 /*
27  * We keep config trees around for possible saveconfig use.  When
28  * built with configure --disable-saveconfig, and when built with
29  * debugging enabled, include the free_config_*() routines.  In the
30  * DEBUG case, they are used in an atexit() cleanup routine to make
31  * postmortem leak check reports more interesting.
32  */
33 #if !defined(FREE_CFG_T) && (!defined(SAVECONFIG) || defined(DEBUG))
34 #define FREE_CFG_T
35 #endif
36 
37 /* Limits */
38 #define MAXLINE 1024
39 
40 /* Configuration sources */
41 
42 #define CONF_SOURCE_FILE		0
43 #define CONF_SOURCE_NTPQ		1
44 
45 /* list of servers from command line for config_peers() */
46 extern	int	cmdline_server_count;
47 extern	char **	cmdline_servers;
48 
49 /* set to zero if we're not locking memory */
50 extern	int	cur_memlock;
51 
52 typedef struct int_range_tag {
53 	int	first;
54 	int	last;
55 } int_range;
56 
57 /* generic list node */
58 typedef struct any_node_tag any_node;
59 struct any_node_tag {
60 	any_node *	link;
61 };
62 
63 typedef DECL_FIFO_ANCHOR(any_node) any_node_fifo;
64 
65 /* Structure for storing an attribute-value pair */
66 typedef struct attr_val_tag attr_val;
67 struct attr_val_tag {
68 	attr_val *	link;
69 	int		attr;
70 	int		type;	/* T_String, T_Integer, ... */
71 	union val {
72 		int		i;
73 		u_int		u;
74 		int_range	r;
75 		double		d;
76 		char *		s;
77 	} value;
78 };
79 
80 typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo;
81 
82 /* Structure for nodes on the syntax tree */
83 typedef struct address_node_tag address_node;
84 struct address_node_tag {
85 	address_node *	link;
86 	char *		address;
87 	u_short		type;	/* family, AF_UNSPEC (0), AF_INET[6] */
88 };
89 
90 typedef DECL_FIFO_ANCHOR(address_node) address_fifo;
91 
92 typedef struct int_node_tag int_node;
93 struct int_node_tag {
94 	int_node *	link;
95 	int		i;
96 };
97 
98 typedef DECL_FIFO_ANCHOR(int_node) int_fifo;
99 
100 typedef struct string_node_tag string_node;
101 struct string_node_tag {
102 	string_node *	link;
103 	char *		s;
104 };
105 
106 typedef DECL_FIFO_ANCHOR(string_node) string_fifo;
107 
108 typedef struct restrict_node_tag restrict_node;
109 struct restrict_node_tag {
110 	restrict_node *	link;
111 	address_node *	addr;
112 	address_node *	mask;
113 	int_fifo *	flag_tok_fifo;
114 	int		line_no;
115 	short		ippeerlimit;
116 };
117 
118 typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo;
119 
120 typedef struct peer_node_tag peer_node;
121 struct peer_node_tag {
122 	peer_node *	link;
123 	int		host_mode;
124 	address_node *	addr;
125 	attr_val_fifo *	peerflags;
126 	u_char		minpoll;
127 	u_char		maxpoll;
128 	u_int32		ttl;
129 	u_char		peerversion;
130 	keyid_t		peerkey;
131 	char *		group;
132 };
133 
134 typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo;
135 
136 typedef struct unpeer_node_tag unpeer_node;
137 struct unpeer_node_tag {
138 	unpeer_node *	link;
139 	associd_t	assocID;
140 	address_node *	addr;
141 };
142 
143 typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo;
144 
145 typedef struct auth_node_tag auth_node;
146 struct auth_node_tag {
147 	int		control_key;
148 	int		cryptosw;
149 	attr_val_fifo *	crypto_cmd_list;
150 	char *		keys;
151 	char *		keysdir;
152 	int		request_key;
153 	int		revoke;
154 	attr_val_fifo *	trusted_key_list;
155 	char *		ntp_signd_socket;
156 };
157 
158 typedef struct filegen_node_tag filegen_node;
159 struct filegen_node_tag {
160 	filegen_node *	link;
161 	int		filegen_token;
162 	attr_val_fifo *	options;
163 };
164 
165 typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo;
166 
167 typedef struct setvar_node_tag setvar_node;
168 struct setvar_node_tag {
169 	setvar_node *	link;
170 	char *		var;
171 	char *		val;
172 	int		isdefault;
173 };
174 
175 typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo;
176 
177 typedef struct nic_rule_node_tag nic_rule_node;
178 struct nic_rule_node_tag {
179 	nic_rule_node *	link;
180 	int		match_class;
181 	char *		if_name;	/* or numeric address */
182 	int		action;
183 };
184 
185 typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo;
186 
187 typedef struct addr_opts_node_tag addr_opts_node;
188 struct addr_opts_node_tag {
189 	addr_opts_node *link;
190 	address_node *	addr;
191 	attr_val_fifo *	options;
192 };
193 
194 typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo;
195 
196 typedef struct sim_node_tag sim_node;
197 struct sim_node_tag {
198 	sim_node *		link;
199 	attr_val_fifo *		init_opts;
200 	server_info_fifo *	servers;
201 };
202 
203 typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo;
204 
205 /* The syntax tree */
206 typedef struct config_tree_tag config_tree;
207 struct config_tree_tag {
208 	config_tree *	link;
209 
210 	attr_val	source;
211 	time_t		timestamp;
212 
213 	peer_fifo *	peers;
214 	unpeer_fifo *	unpeers;
215 
216 	/* Other Modes */
217 	int		broadcastclient;
218 	address_fifo *	manycastserver;
219 	address_fifo *	multicastclient;
220 
221 	attr_val_fifo *	orphan_cmds;	/* s/b renamed tos_options */
222 
223 	/* Monitoring Configuration */
224 	int_fifo *	stats_list;
225 	char *		stats_dir;
226 	filegen_fifo *	filegen_opts;
227 
228 	/* Access Control Configuration */
229 	attr_val_fifo *	discard_opts;
230 	attr_val_fifo *	mru_opts;
231 	restrict_fifo *	restrict_opts;
232 
233 	addr_opts_fifo *fudge;
234 	attr_val_fifo *	rlimit;
235 	attr_val_fifo *	tinker;
236 	attr_val_fifo *	enable_opts;
237 	attr_val_fifo *	disable_opts;
238 
239 	auth_node	auth;
240 
241 	attr_val_fifo *	logconfig;
242 	string_fifo *	phone;
243 	setvar_fifo *	setvar;
244 	int_fifo *	ttl;
245 	addr_opts_fifo *trap;
246 	attr_val_fifo *	vars;
247 	nic_rule_fifo *	nic_rules;
248 	int_fifo *	reset_counters;
249 
250 	sim_fifo *	sim_details;
251 	int		mdnstries;
252 };
253 
254 
255 /* Structure for holding a remote configuration command */
256 struct REMOTE_CONFIG_INFO {
257 	char buffer[MAXLINE];
258 	char err_msg[MAXLINE];
259 	int pos;
260 	int err_pos;
261 	int no_errors;
262 };
263 
264 
265 /*
266  * context for trap_name_resolved() to call ctlsettrap() once the
267  * name->address resolution completes.
268  */
269 typedef struct settrap_parms_tag {
270 	sockaddr_u	ifaddr;
271 	int		ifaddr_nonnull;
272 } settrap_parms;
273 
274 
275 /* get text from T_ tokens */
276 const char * token_name(int token);
277 
278 /* generic fifo routines for structs linked by 1st member */
279 typedef void (*fifo_deleter)(void*);
280 void *	destroy_gen_fifo(void *fifo, fifo_deleter func);
281 void *	append_gen_fifo(void *fifo, void *entry);
282 void *	concat_gen_fifos(void *first, void *second);
283 #define DESTROY_G_FIFO(pf, func)	\
284 	((pf) = destroy_gen_fifo((pf), (fifo_deleter)(func)))
285 #define APPEND_G_FIFO(pf, pe)		\
286 	((pf) = append_gen_fifo((pf), (pe)))
287 #define CONCAT_G_FIFOS(first, second)	\
288 	((first) = concat_gen_fifos((first), (second)))
289 #define HEAD_PFIFO(pf)			\
290 	(((pf) != NULL)			\
291 	      ? HEAD_FIFO(*(pf))	\
292 	      : NULL)
293 
294 peer_node *create_peer_node(int hmode, address_node *addr,
295 			    attr_val_fifo *options);
296 unpeer_node *create_unpeer_node(address_node *addr);
297 address_node *create_address_node(char *addr, int type);
298 void destroy_address_node(address_node *my_node);
299 attr_val *create_attr_dval(int attr, double value);
300 attr_val *create_attr_ival(int attr, int value);
301 attr_val *create_attr_uval(int attr, u_int value);
302 attr_val *create_attr_rangeval(int attr, int first, int last);
303 attr_val *create_attr_sval(int attr, const char *s);
304 void	  destroy_attr_val(attr_val *node);
305 filegen_node *create_filegen_node(int filegen_token,
306 				  attr_val_fifo *options);
307 string_node *create_string_node(char *str);
308 restrict_node *create_restrict_node(address_node *addr,
309 				    address_node *mask,
310 				    short ippeerlimit,
311 				    int_fifo *flags, int line_no);
312 int_node *create_int_node(int val);
313 addr_opts_node *create_addr_opts_node(address_node *addr,
314 				      attr_val_fifo *options);
315 sim_node *create_sim_node(attr_val_fifo *init_opts,
316 			  server_info_fifo *servers);
317 setvar_node *create_setvar_node(char *var, char *val, int isdefault);
318 nic_rule_node *create_nic_rule_node(int match_class, char *if_name,
319 				    int action);
320 
321 script_info *create_sim_script_info(double duration,
322 				    attr_val_fifo *script_queue);
323 server_info *create_sim_server(address_node *addr, double server_offset,
324 			       script_info_fifo *script);
325 
326 extern struct REMOTE_CONFIG_INFO remote_config;
327 void config_remotely(sockaddr_u *);
328 
329 #ifdef SAVECONFIG
330 int dump_config_tree(config_tree *ptree, FILE *df, int comment);
331 int dump_all_config_trees(FILE *df, int comment);
332 #endif
333 
334 #if defined(HAVE_SETRLIMIT)
335 void ntp_rlimit(int, rlim_t, int, const char *);
336 #endif
337 
338 #endif	/* !defined(NTP_CONFIG_H) */
339