xref: /netbsd-src/external/bsd/ntp/dist/include/ntp_config.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: ntp_config.h,v 1.5 2013/12/30 17:42:19 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 admin doesn't want memory locked */
52 extern	int	do_memlock;
53 
54 typedef struct int_range_tag {
55 	int	first;
56 	int	last;
57 } int_range;
58 
59 /* Structure for storing an attribute-value pair  */
60 typedef struct attr_val_tag attr_val;
61 struct attr_val_tag {
62 	attr_val *	link;
63 	int		attr;
64 	int		type;	/* T_String, T_Integer, ... */
65 	union val {
66 		int		i;
67 		u_int		u;
68 		int_range	r;
69 		double		d;
70 		char *		s;
71 	} value;
72 };
73 
74 typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo;
75 
76 /* Structure for nodes on the syntax tree */
77 typedef struct address_node_tag address_node;
78 struct address_node_tag {
79 	address_node *	link;
80 	char *		address;
81 	u_short		type;	/* family, AF_UNSPEC (0), AF_INET[6] */
82 };
83 
84 typedef DECL_FIFO_ANCHOR(address_node) address_fifo;
85 
86 typedef struct int_node_tag int_node;
87 struct int_node_tag {
88 	int_node *	link;
89 	int		i;
90 };
91 
92 typedef DECL_FIFO_ANCHOR(int_node) int_fifo;
93 
94 typedef struct string_node_tag string_node;
95 struct string_node_tag {
96 	string_node *	link;
97 	char *		s;
98 };
99 
100 typedef DECL_FIFO_ANCHOR(string_node) string_fifo;
101 
102 typedef struct restrict_node_tag restrict_node;
103 struct restrict_node_tag {
104 	restrict_node *	link;
105 	address_node *	addr;
106 	address_node *	mask;
107 	int_fifo *	flags;
108 	int		line_no;
109 };
110 
111 typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo;
112 
113 typedef struct peer_node_tag peer_node;
114 struct peer_node_tag {
115 	peer_node *	link;
116 	int		host_mode;
117 	address_node *	addr;
118 	attr_val_fifo *	peerflags;
119 	u_char		minpoll;
120 	u_char		maxpoll;
121 	u_int32		ttl;
122 	u_char		peerversion;
123 	keyid_t		peerkey;
124 	char *		group;
125 };
126 
127 typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo;
128 
129 typedef struct unpeer_node_tag unpeer_node;
130 struct unpeer_node_tag {
131 	unpeer_node *	link;
132 	associd_t	assocID;
133 	address_node *	addr;
134 };
135 
136 typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo;
137 
138 typedef struct auth_node_tag auth_node;
139 struct auth_node_tag {
140 	int		control_key;
141 	int		cryptosw;
142 	attr_val_fifo *	crypto_cmd_list;
143 	char *		keys;
144 	char *		keysdir;
145 	int		request_key;
146 	int		revoke;
147 	attr_val_fifo *	trusted_key_list;
148 	char *		ntp_signd_socket;
149 };
150 
151 typedef struct filegen_node_tag filegen_node;
152 struct filegen_node_tag {
153 	filegen_node *	link;
154 	int		filegen_token;
155 	attr_val_fifo *	options;
156 };
157 
158 typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo;
159 
160 typedef struct setvar_node_tag setvar_node;
161 struct setvar_node_tag {
162 	setvar_node *	link;
163 	char *		var;
164 	char *		val;
165 	int		isdefault;
166 };
167 
168 typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo;
169 
170 typedef struct nic_rule_node_tag nic_rule_node;
171 struct nic_rule_node_tag {
172 	nic_rule_node *	link;
173 	int		match_class;
174 	char *		if_name;	/* or numeric address */
175 	int		action;
176 };
177 
178 typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo;
179 
180 typedef struct addr_opts_node_tag addr_opts_node;
181 struct addr_opts_node_tag {
182 	addr_opts_node *link;
183 	address_node *	addr;
184 	attr_val_fifo *	options;
185 };
186 
187 typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo;
188 
189 typedef struct sim_node_tag sim_node;
190 struct sim_node_tag {
191 	sim_node *		link;
192 	attr_val_fifo *		init_opts;
193 	server_info_fifo *	servers;
194 };
195 
196 typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo;
197 
198 /* The syntax tree */
199 typedef struct config_tree_tag config_tree;
200 struct config_tree_tag {
201 	config_tree *	link;
202 
203 	attr_val	source;
204 	time_t		timestamp;
205 
206 	peer_fifo *	peers;
207 	unpeer_fifo *	unpeers;
208 
209 	/* Other Modes */
210 	int		broadcastclient;
211 	address_fifo *	manycastserver;
212 	address_fifo *	multicastclient;
213 
214 	attr_val_fifo *	orphan_cmds;	/* s/b renamed tos_options */
215 
216 	/* Monitoring Configuration */
217 	int_fifo *	stats_list;
218 	char *		stats_dir;
219 	filegen_fifo *	filegen_opts;
220 
221 	/* Access Control Configuration */
222 	attr_val_fifo *	discard_opts;
223 	attr_val_fifo *	mru_opts;
224 	restrict_fifo *	restrict_opts;
225 
226 	addr_opts_fifo *fudge;
227 	attr_val_fifo *	rlimit;
228 	attr_val_fifo *	tinker;
229 	attr_val_fifo *	enable_opts;
230 	attr_val_fifo *	disable_opts;
231 
232 	auth_node	auth;
233 
234 	attr_val_fifo *	logconfig;
235 	string_fifo *	phone;
236 	setvar_fifo *	setvar;
237 	int_fifo *	ttl;
238 	addr_opts_fifo *trap;
239 	attr_val_fifo *	vars;
240 	nic_rule_fifo *	nic_rules;
241 	int_fifo *	reset_counters;
242 
243 	sim_fifo *	sim_details;
244 	int		mdnstries;
245 };
246 
247 
248 /* Structure for holding a remote configuration command */
249 struct REMOTE_CONFIG_INFO {
250 	char buffer[MAXLINE];
251 	char err_msg[MAXLINE];
252 	int pos;
253 	int err_pos;
254 	int no_errors;
255 };
256 
257 
258 /*
259  * context for trap_name_resolved() to call ctlsettrap() once the
260  * name->address resolution completes.
261  */
262 typedef struct settrap_parms_tag {
263 	sockaddr_u	ifaddr;
264 	int		ifaddr_nonnull;
265 } settrap_parms;
266 
267 
268 /* get text from T_ tokens */
269 const char * token_name(int token);
270 
271 /* generic fifo routines for structs linked by 1st member */
272 void*	append_gen_fifo(void *fifo, void *entry);
273 void *	concat_gen_fifos(void *first, void *second);
274 #define APPEND_G_FIFO(pf, pe)		\
275 	((pf) = append_gen_fifo((pf), (pe)))
276 #define CONCAT_G_FIFOS(first, second)	\
277 	((first) = concat_gen_fifos((first), (second)))
278 #define HEAD_PFIFO(pf)			\
279 	(((pf) != NULL)			\
280 	      ? HEAD_FIFO(*(pf))	\
281 	      : NULL)
282 
283 peer_node *create_peer_node(int hmode, address_node *addr,
284 			    attr_val_fifo *options);
285 unpeer_node *create_unpeer_node(address_node *addr);
286 address_node *create_address_node(char *addr, int type);
287 void destroy_address_node(address_node *my_node);
288 attr_val *create_attr_dval(int attr, double value);
289 attr_val *create_attr_ival(int attr, int value);
290 attr_val *create_attr_uval(int attr, u_int value);
291 attr_val *create_attr_rangeval(int attr, int first, int last);
292 attr_val *create_attr_sval(int attr, const char *s);
293 filegen_node *create_filegen_node(int filegen_token,
294 				  attr_val_fifo *options);
295 string_node *create_string_node(char *str);
296 restrict_node *create_restrict_node(address_node *addr,
297 				    address_node *mask,
298 				    int_fifo *flags, int line_no);
299 int_node *create_int_node(int val);
300 addr_opts_node *create_addr_opts_node(address_node *addr,
301 				      attr_val_fifo *options);
302 sim_node *create_sim_node(attr_val_fifo *init_opts,
303 			  server_info_fifo *servers);
304 setvar_node *create_setvar_node(char *var, char *val, int isdefault);
305 nic_rule_node *create_nic_rule_node(int match_class, char *if_name,
306 				    int action);
307 
308 script_info *create_sim_script_info(double duration,
309 				    attr_val_fifo *script_queue);
310 server_info *create_sim_server(address_node *addr, double server_offset,
311 			       script_info_fifo *script);
312 
313 extern struct REMOTE_CONFIG_INFO remote_config;
314 void config_remotely(sockaddr_u *);
315 
316 #ifdef SAVECONFIG
317 int dump_config_tree(config_tree *ptree, FILE *df, int comment);
318 int dump_all_config_trees(FILE *df, int comment);
319 #endif
320 
321 #if defined(HAVE_SETRLIMIT)
322 void ntp_rlimit(int, rlim_t, int, const char *);
323 #endif
324 
325 #endif	/* !defined(NTP_CONFIG_H) */
326