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