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