xref: /netbsd-src/external/bsd/ntp/dist/include/ntp_config.h (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1*eabc0478Schristos /*	$NetBSD: ntp_config.h,v 1.15 2024/08/18 20:46:50 christos Exp $	*/
2abb0f93cSkardel 
3abb0f93cSkardel #ifndef NTP_CONFIG_H
4abb0f93cSkardel #define NTP_CONFIG_H
5abb0f93cSkardel 
62950cc38Schristos #ifdef HAVE_SYS_RESOURCE_H
72950cc38Schristos # include <sys/resource.h>
82950cc38Schristos #endif /* HAVE_SYS_RESOURCE_H */
92950cc38Schristos 
10abb0f93cSkardel #include "ntp_machine.h"
11cdfa2a7eSchristos #include "ntp_psl.h"
12abb0f93cSkardel #include "ntpsim.h"
13abb0f93cSkardel 
14abb0f93cSkardel 
15abb0f93cSkardel /*
16abb0f93cSkardel  * Configuration file name
17abb0f93cSkardel  */
18abb0f93cSkardel #ifndef CONFIG_FILE
19abb0f93cSkardel # ifndef SYS_WINNT
20abb0f93cSkardel #  define	CONFIG_FILE "/etc/ntp.conf"
21abb0f93cSkardel # else /* SYS_WINNT */
22abb0f93cSkardel #  define	CONFIG_FILE	"%windir%\\system32\\drivers\\etc\\ntp.conf"
23abb0f93cSkardel #  define	ALT_CONFIG_FILE "%windir%\\ntp.conf"
24abb0f93cSkardel #  define	NTP_KEYSDIR	"%windir%\\system32\\drivers\\etc"
25abb0f93cSkardel # endif /* SYS_WINNT */
26abb0f93cSkardel #endif /* not CONFIG_FILE */
27abb0f93cSkardel 
28abb0f93cSkardel 
29abb0f93cSkardel /*
30abb0f93cSkardel  * We keep config trees around for possible saveconfig use.  When
31abb0f93cSkardel  * built with configure --disable-saveconfig, and when built with
32abb0f93cSkardel  * debugging enabled, include the free_config_*() routines.  In the
33abb0f93cSkardel  * DEBUG case, they are used in an atexit() cleanup routine to make
34abb0f93cSkardel  * postmortem leak check reports more interesting.
35abb0f93cSkardel  */
36abb0f93cSkardel #if !defined(FREE_CFG_T) && (!defined(SAVECONFIG) || defined(DEBUG))
37abb0f93cSkardel #define FREE_CFG_T
38abb0f93cSkardel #endif
39abb0f93cSkardel 
40abb0f93cSkardel /* Limits */
41abb0f93cSkardel #define MAXLINE 1024
42abb0f93cSkardel 
43abb0f93cSkardel /* Configuration sources */
44abb0f93cSkardel 
45abb0f93cSkardel #define CONF_SOURCE_FILE		0
46abb0f93cSkardel #define CONF_SOURCE_NTPQ		1
47abb0f93cSkardel 
482950cc38Schristos /* list of servers from command line for config_peers() */
492950cc38Schristos extern	int	cmdline_server_count;
502950cc38Schristos extern	char **	cmdline_servers;
512950cc38Schristos 
52af12ab5eSchristos /* set to zero if we're not locking memory */
53af12ab5eSchristos extern	int	cur_memlock;
542950cc38Schristos 
552950cc38Schristos typedef struct int_range_tag {
562950cc38Schristos 	int	first;
572950cc38Schristos 	int	last;
582950cc38Schristos } int_range;
59abb0f93cSkardel 
604eea345dSchristos /* generic list node */
614eea345dSchristos typedef struct any_node_tag any_node;
624eea345dSchristos struct any_node_tag {
634eea345dSchristos 	any_node *	link;
644eea345dSchristos };
654eea345dSchristos 
664eea345dSchristos typedef DECL_FIFO_ANCHOR(any_node) any_node_fifo;
674eea345dSchristos 
68abb0f93cSkardel /* Structure for storing an attribute-value pair */
692950cc38Schristos typedef struct attr_val_tag attr_val;
702950cc38Schristos struct attr_val_tag {
712950cc38Schristos 	attr_val *	link;
72abb0f93cSkardel 	int		attr;
732950cc38Schristos 	int		type;	/* T_String, T_Integer, ... */
74cdfa2a7eSchristos 	int		flag;	/* auxiliary flags */
75abb0f93cSkardel 	union val {
76cdfa2a7eSchristos 		double		d;	/* T_Double */
77cdfa2a7eSchristos 		int		i;	/* T_Integer */
78cdfa2a7eSchristos 		int_range	r;	/* T_Intrange */
79cdfa2a7eSchristos 		char *		s;	/* T_String */
80cdfa2a7eSchristos 		u_int		u;	/* T_U_int */
81abb0f93cSkardel 	} value;
82abb0f93cSkardel };
83abb0f93cSkardel 
842950cc38Schristos typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo;
852950cc38Schristos 
86abb0f93cSkardel /* Structure for nodes on the syntax tree */
872950cc38Schristos typedef struct address_node_tag address_node;
882950cc38Schristos struct address_node_tag {
892950cc38Schristos 	address_node *	link;
90abb0f93cSkardel 	char *		address;
912950cc38Schristos 	u_short		type;	/* family, AF_UNSPEC (0), AF_INET[6] */
92abb0f93cSkardel };
93abb0f93cSkardel 
942950cc38Schristos typedef DECL_FIFO_ANCHOR(address_node) address_fifo;
952950cc38Schristos 
962950cc38Schristos typedef struct int_node_tag int_node;
972950cc38Schristos struct int_node_tag {
982950cc38Schristos 	int_node *	link;
992950cc38Schristos 	int		i;
1002950cc38Schristos };
1012950cc38Schristos 
1022950cc38Schristos typedef DECL_FIFO_ANCHOR(int_node) int_fifo;
1032950cc38Schristos 
1042950cc38Schristos typedef struct string_node_tag string_node;
1052950cc38Schristos struct string_node_tag {
1062950cc38Schristos 	string_node *	link;
1072950cc38Schristos 	char *		s;
1082950cc38Schristos };
1092950cc38Schristos 
1102950cc38Schristos typedef DECL_FIFO_ANCHOR(string_node) string_fifo;
1112950cc38Schristos 
1122950cc38Schristos typedef struct restrict_node_tag restrict_node;
1132950cc38Schristos struct restrict_node_tag {
1142950cc38Schristos 	restrict_node *	link;
1152950cc38Schristos 	address_node *	addr;
1162950cc38Schristos 	address_node *	mask;
117cdfa2a7eSchristos 	attr_val_fifo *	flag_tok_fifo;
118*eabc0478Schristos 	int/*BOOL*/	remove;
119abb0f93cSkardel 	int		line_no;
120*eabc0478Schristos 	int		column;
1214eea345dSchristos 	short		ippeerlimit;
122cdfa2a7eSchristos 	short		srvfuzrft;
123abb0f93cSkardel };
124abb0f93cSkardel 
1252950cc38Schristos typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo;
1262950cc38Schristos 
1272950cc38Schristos typedef struct peer_node_tag peer_node;
1282950cc38Schristos struct peer_node_tag {
1292950cc38Schristos 	peer_node *	link;
130abb0f93cSkardel 	int		host_mode;
1312950cc38Schristos 	address_node *	addr;
1322950cc38Schristos 	attr_val_fifo *	peerflags;
1332950cc38Schristos 	u_char		minpoll;
1342950cc38Schristos 	u_char		maxpoll;
1352950cc38Schristos 	u_int32		ttl;
1362950cc38Schristos 	u_char		peerversion;
1372950cc38Schristos 	keyid_t		peerkey;
1382950cc38Schristos 	char *		group;
139abb0f93cSkardel };
140abb0f93cSkardel 
1412950cc38Schristos typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo;
1422950cc38Schristos 
1432950cc38Schristos typedef struct unpeer_node_tag unpeer_node;
1442950cc38Schristos struct unpeer_node_tag {
1452950cc38Schristos 	unpeer_node *	link;
1462950cc38Schristos 	associd_t	assocID;
1472950cc38Schristos 	address_node *	addr;
148abb0f93cSkardel };
149abb0f93cSkardel 
1502950cc38Schristos typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo;
1512950cc38Schristos 
1522950cc38Schristos typedef struct auth_node_tag auth_node;
1532950cc38Schristos struct auth_node_tag {
154abb0f93cSkardel 	int		control_key;
155abb0f93cSkardel 	int		cryptosw;
1562950cc38Schristos 	attr_val_fifo *	crypto_cmd_list;
157abb0f93cSkardel 	char *		keys;
158abb0f93cSkardel 	char *		keysdir;
159abb0f93cSkardel 	int		request_key;
160abb0f93cSkardel 	int		revoke;
1612950cc38Schristos 	attr_val_fifo *	trusted_key_list;
162abb0f93cSkardel 	char *		ntp_signd_socket;
163abb0f93cSkardel };
164abb0f93cSkardel 
1652950cc38Schristos typedef struct filegen_node_tag filegen_node;
1662950cc38Schristos struct filegen_node_tag {
1672950cc38Schristos 	filegen_node *	link;
168abb0f93cSkardel 	int		filegen_token;
1692950cc38Schristos 	attr_val_fifo *	options;
170abb0f93cSkardel };
171abb0f93cSkardel 
1722950cc38Schristos typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo;
1732950cc38Schristos 
1742950cc38Schristos typedef struct setvar_node_tag setvar_node;
1752950cc38Schristos struct setvar_node_tag {
1762950cc38Schristos 	setvar_node *	link;
177abb0f93cSkardel 	char *		var;
178abb0f93cSkardel 	char *		val;
179abb0f93cSkardel 	int		isdefault;
180abb0f93cSkardel };
181abb0f93cSkardel 
1822950cc38Schristos typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo;
1832950cc38Schristos 
1842950cc38Schristos typedef struct nic_rule_node_tag nic_rule_node;
1852950cc38Schristos struct nic_rule_node_tag {
1862950cc38Schristos 	nic_rule_node *	link;
187abb0f93cSkardel 	int		match_class;
1882950cc38Schristos 	char *		if_name;	/* or numeric address */
189abb0f93cSkardel 	int		action;
190abb0f93cSkardel };
191abb0f93cSkardel 
1922950cc38Schristos typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo;
1932950cc38Schristos 
1942950cc38Schristos typedef struct addr_opts_node_tag addr_opts_node;
1952950cc38Schristos struct addr_opts_node_tag {
1962950cc38Schristos 	addr_opts_node *link;
1972950cc38Schristos 	address_node *	addr;
1982950cc38Schristos 	attr_val_fifo *	options;
199abb0f93cSkardel };
200abb0f93cSkardel 
2012950cc38Schristos typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo;
2022950cc38Schristos 
2032950cc38Schristos typedef struct sim_node_tag sim_node;
2042950cc38Schristos struct sim_node_tag {
2052950cc38Schristos 	sim_node *		link;
2062950cc38Schristos 	attr_val_fifo *		init_opts;
2072950cc38Schristos 	server_info_fifo *	servers;
2082950cc38Schristos };
2092950cc38Schristos 
2102950cc38Schristos typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo;
211abb0f93cSkardel 
212abb0f93cSkardel /* The syntax tree */
2132950cc38Schristos typedef struct config_tree_tag config_tree;
2142950cc38Schristos struct config_tree_tag {
2152950cc38Schristos 	config_tree *	link;
216abb0f93cSkardel 
2172950cc38Schristos 	attr_val	source;
218abb0f93cSkardel 	time_t		timestamp;
219abb0f93cSkardel 
2202950cc38Schristos 	peer_fifo *	peers;
2212950cc38Schristos 	unpeer_fifo *	unpeers;
222abb0f93cSkardel 
223abb0f93cSkardel 	/* Other Modes */
224abb0f93cSkardel 	int		broadcastclient;
2252950cc38Schristos 	address_fifo *	manycastserver;
2262950cc38Schristos 	address_fifo *	multicastclient;
227abb0f93cSkardel 
2282950cc38Schristos 	attr_val_fifo *	orphan_cmds;	/* s/b renamed tos_options */
229abb0f93cSkardel 
230abb0f93cSkardel 	/* Monitoring Configuration */
2312950cc38Schristos 	int_fifo *	stats_list;
232abb0f93cSkardel 	char *		stats_dir;
2332950cc38Schristos 	filegen_fifo *	filegen_opts;
234abb0f93cSkardel 
235abb0f93cSkardel 	/* Access Control Configuration */
2362950cc38Schristos 	attr_val_fifo *	discard_opts;
2372950cc38Schristos 	attr_val_fifo *	mru_opts;
2382950cc38Schristos 	restrict_fifo *	restrict_opts;
239abb0f93cSkardel 
2402950cc38Schristos 	addr_opts_fifo *fudge;
241*eabc0478Schristos 	addr_opts_fifo *device;
2422950cc38Schristos 	attr_val_fifo *	rlimit;
2432950cc38Schristos 	attr_val_fifo *	tinker;
2442950cc38Schristos 	attr_val_fifo *	enable_opts;
2452950cc38Schristos 	attr_val_fifo *	disable_opts;
246abb0f93cSkardel 
2472950cc38Schristos 	auth_node	auth;
248abb0f93cSkardel 
2492950cc38Schristos 	attr_val_fifo *	logconfig;
2502950cc38Schristos 	string_fifo *	phone;
2512950cc38Schristos 	setvar_fifo *	setvar;
2522950cc38Schristos 	int_fifo *	ttl;
2532950cc38Schristos 	addr_opts_fifo *trap;
2542950cc38Schristos 	attr_val_fifo *	vars;
2552950cc38Schristos 	nic_rule_fifo *	nic_rules;
2562950cc38Schristos 	int_fifo *	reset_counters;
257cdfa2a7eSchristos 	attr_val_fifo *	pollskewlist;
25896061387Schristos 
2592950cc38Schristos 	sim_fifo *	sim_details;
260a04a202dSchristos 	int		mdnstries;
261abb0f93cSkardel };
262abb0f93cSkardel 
263abb0f93cSkardel 
264abb0f93cSkardel /* Structure for holding a remote configuration command */
265abb0f93cSkardel struct REMOTE_CONFIG_INFO {
266abb0f93cSkardel 	char buffer[MAXLINE];
267abb0f93cSkardel 	char err_msg[MAXLINE];
268abb0f93cSkardel 	int pos;
269abb0f93cSkardel 	int err_pos;
270abb0f93cSkardel 	int no_errors;
271abb0f93cSkardel };
272abb0f93cSkardel 
2732950cc38Schristos 
2742950cc38Schristos /*
2752950cc38Schristos  * context for trap_name_resolved() to call ctlsettrap() once the
2762950cc38Schristos  * name->address resolution completes.
2772950cc38Schristos  */
2782950cc38Schristos typedef struct settrap_parms_tag {
2792950cc38Schristos 	sockaddr_u	ifaddr;
2802950cc38Schristos 	int		ifaddr_nonnull;
2812950cc38Schristos } settrap_parms;
2822950cc38Schristos 
28350c1baceSchristos 
284cdfa2a7eSchristos /*
285cdfa2a7eSchristos ** Data Minimization Items
286cdfa2a7eSchristos */
287cdfa2a7eSchristos 
288cdfa2a7eSchristos /* Serverresponse fuzz reftime: stored in 'restrict' fifos */
289cdfa2a7eSchristos 
290cdfa2a7eSchristos 
291abb0f93cSkardel /* get text from T_ tokens */
292abb0f93cSkardel const char * token_name(int token);
293abb0f93cSkardel 
2942950cc38Schristos /* generic fifo routines for structs linked by 1st member */
2954eea345dSchristos typedef void (*fifo_deleter)(void*);
2964eea345dSchristos void *	destroy_gen_fifo(void *fifo, fifo_deleter func);
2972950cc38Schristos void *	append_gen_fifo(void *fifo, void *entry);
2982950cc38Schristos void *	concat_gen_fifos(void *first, void *second);
2994eea345dSchristos #define DESTROY_G_FIFO(pf, func)	\
3004eea345dSchristos 	((pf) = destroy_gen_fifo((pf), (fifo_deleter)(func)))
3012950cc38Schristos #define APPEND_G_FIFO(pf, pe)		\
3022950cc38Schristos 	((pf) = append_gen_fifo((pf), (pe)))
3032950cc38Schristos #define CONCAT_G_FIFOS(first, second)	\
3042950cc38Schristos 	((first) = concat_gen_fifos((first), (second)))
3052950cc38Schristos #define HEAD_PFIFO(pf)			\
3062950cc38Schristos 	(((pf) != NULL)			\
3072950cc38Schristos 	      ? HEAD_FIFO(*(pf))	\
3082950cc38Schristos 	      : NULL)
3092950cc38Schristos 
3102950cc38Schristos peer_node *create_peer_node(int hmode, address_node *addr,
3112950cc38Schristos 			    attr_val_fifo *options);
3122950cc38Schristos unpeer_node *create_unpeer_node(address_node *addr);
3132950cc38Schristos address_node *create_address_node(char *addr, int type);
3142950cc38Schristos void destroy_address_node(address_node *my_node);
3152950cc38Schristos attr_val *create_attr_dval(int attr, double value);
3162950cc38Schristos attr_val *create_attr_ival(int attr, int value);
317cdfa2a7eSchristos attr_val *create_attr_rval(int attr, int first, int last);
3182950cc38Schristos attr_val *create_attr_sval(int attr, const char *s);
319cdfa2a7eSchristos attr_val *create_attr_uval(int attr, u_int value);
3204eea345dSchristos void	  destroy_attr_val(attr_val *node);
3212950cc38Schristos filegen_node *create_filegen_node(int filegen_token,
3222950cc38Schristos 				  attr_val_fifo *options);
3232950cc38Schristos string_node *create_string_node(char *str);
3242950cc38Schristos restrict_node *create_restrict_node(address_node *	addr,
3252950cc38Schristos 				    address_node *	mask,
3264eea345dSchristos 				    short		ippeerlimit,
327*eabc0478Schristos 				    attr_val_fifo *	flag_tok_fifo,
328*eabc0478Schristos 				    int/*BOOL*/		remove,
329*eabc0478Schristos 				    int			nline,
330*eabc0478Schristos 				    int			ncol);
3312950cc38Schristos int_node *create_int_node(int val);
3322950cc38Schristos addr_opts_node *create_addr_opts_node(address_node *addr,
3332950cc38Schristos 				      attr_val_fifo *options);
3342950cc38Schristos sim_node *create_sim_node(attr_val_fifo *init_opts,
3352950cc38Schristos 			  server_info_fifo *servers);
3362950cc38Schristos setvar_node *create_setvar_node(char *var, char *val, int isdefault);
337abb0f93cSkardel nic_rule_node *create_nic_rule_node(int match_class, char *if_name,
338abb0f93cSkardel 				    int action);
339abb0f93cSkardel 
340abb0f93cSkardel script_info *create_sim_script_info(double duration,
3412950cc38Schristos 				    attr_val_fifo *script_queue);
3422950cc38Schristos server_info *create_sim_server(address_node *addr, double server_offset,
3432950cc38Schristos 			       script_info_fifo *script);
344abb0f93cSkardel 
345abb0f93cSkardel extern struct REMOTE_CONFIG_INFO remote_config;
346abb0f93cSkardel void config_remotely(sockaddr_u *);
347abb0f93cSkardel 
348abb0f93cSkardel #ifdef SAVECONFIG
3492950cc38Schristos int dump_config_tree(config_tree *ptree, FILE *df, int comment);
350abb0f93cSkardel int dump_all_config_trees(FILE *df, int comment);
351abb0f93cSkardel #endif
352abb0f93cSkardel 
3532950cc38Schristos #if defined(HAVE_SETRLIMIT)
3542950cc38Schristos void ntp_rlimit(int, rlim_t, int, const char *);
3552950cc38Schristos #endif
356abb0f93cSkardel 
357abb0f93cSkardel #endif	/* !defined(NTP_CONFIG_H) */
358