xref: /freebsd/contrib/ntp/include/ntp_config.h (revision f5f40dd63bc7acbb5312b26ac1ea1103c12352a6)
12b15cb3dSCy Schubert #ifndef NTP_CONFIG_H
22b15cb3dSCy Schubert #define NTP_CONFIG_H
32b15cb3dSCy Schubert 
42b15cb3dSCy Schubert #ifdef HAVE_SYS_RESOURCE_H
52b15cb3dSCy Schubert # include <sys/resource.h>
62b15cb3dSCy Schubert #endif /* HAVE_SYS_RESOURCE_H */
72b15cb3dSCy Schubert 
82b15cb3dSCy Schubert #include "ntp_machine.h"
92d4e511cSCy Schubert #include "ntp_psl.h"
102b15cb3dSCy Schubert #include "ntpsim.h"
112b15cb3dSCy Schubert 
122b15cb3dSCy Schubert 
13224ba2bdSOllivier Robert /*
14224ba2bdSOllivier Robert  * Configuration file name
15224ba2bdSOllivier Robert  */
16224ba2bdSOllivier Robert #ifndef CONFIG_FILE
17224ba2bdSOllivier Robert # ifndef SYS_WINNT
18224ba2bdSOllivier Robert #  define	CONFIG_FILE "/etc/ntp.conf"
19224ba2bdSOllivier Robert # else /* SYS_WINNT */
20224ba2bdSOllivier Robert #  define	CONFIG_FILE	"%windir%\\system32\\drivers\\etc\\ntp.conf"
21224ba2bdSOllivier Robert #  define	ALT_CONFIG_FILE "%windir%\\ntp.conf"
229c2daa00SOllivier Robert #  define	NTP_KEYSDIR	"%windir%\\system32\\drivers\\etc"
23224ba2bdSOllivier Robert # endif /* SYS_WINNT */
24224ba2bdSOllivier Robert #endif /* not CONFIG_FILE */
25224ba2bdSOllivier Robert 
26224ba2bdSOllivier Robert 
27224ba2bdSOllivier Robert /*
282b15cb3dSCy Schubert  * We keep config trees around for possible saveconfig use.  When
292b15cb3dSCy Schubert  * built with configure --disable-saveconfig, and when built with
302b15cb3dSCy Schubert  * debugging enabled, include the free_config_*() routines.  In the
312b15cb3dSCy Schubert  * DEBUG case, they are used in an atexit() cleanup routine to make
322b15cb3dSCy Schubert  * postmortem leak check reports more interesting.
33224ba2bdSOllivier Robert  */
342b15cb3dSCy Schubert #if !defined(FREE_CFG_T) && (!defined(SAVECONFIG) || defined(DEBUG))
352b15cb3dSCy Schubert #define FREE_CFG_T
362b15cb3dSCy Schubert #endif
372b15cb3dSCy Schubert 
382b15cb3dSCy Schubert /* Limits */
392b15cb3dSCy Schubert #define MAXLINE 1024
402b15cb3dSCy Schubert 
412b15cb3dSCy Schubert /* Configuration sources */
422b15cb3dSCy Schubert 
432b15cb3dSCy Schubert #define CONF_SOURCE_FILE		0
442b15cb3dSCy Schubert #define CONF_SOURCE_NTPQ		1
452b15cb3dSCy Schubert 
462b15cb3dSCy Schubert /* list of servers from command line for config_peers() */
472b15cb3dSCy Schubert extern	int	cmdline_server_count;
482b15cb3dSCy Schubert extern	char **	cmdline_servers;
492b15cb3dSCy Schubert 
509034852cSGleb Smirnoff /* set to zero if we're not locking memory */
519034852cSGleb Smirnoff extern	int	cur_memlock;
522b15cb3dSCy Schubert 
532b15cb3dSCy Schubert typedef struct int_range_tag {
542b15cb3dSCy Schubert 	int	first;
552b15cb3dSCy Schubert 	int	last;
562b15cb3dSCy Schubert } int_range;
572b15cb3dSCy Schubert 
5809100258SXin LI /* generic list node */
5909100258SXin LI typedef struct any_node_tag any_node;
6009100258SXin LI struct any_node_tag {
6109100258SXin LI 	any_node *	link;
6209100258SXin LI };
6309100258SXin LI 
6409100258SXin LI typedef DECL_FIFO_ANCHOR(any_node) any_node_fifo;
6509100258SXin LI 
662b15cb3dSCy Schubert /* Structure for storing an attribute-value pair */
672b15cb3dSCy Schubert typedef struct attr_val_tag attr_val;
682b15cb3dSCy Schubert struct attr_val_tag {
692b15cb3dSCy Schubert 	attr_val *	link;
702b15cb3dSCy Schubert 	int		attr;
712b15cb3dSCy Schubert 	int		type;	/* T_String, T_Integer, ... */
722d4e511cSCy Schubert 	int		flag;	/* auxiliary flags */
732b15cb3dSCy Schubert 	union val {
742d4e511cSCy Schubert 		double		d;	/* T_Double */
752d4e511cSCy Schubert 		int		i;	/* T_Integer */
762d4e511cSCy Schubert 		int_range	r;	/* T_Intrange */
772d4e511cSCy Schubert 		char *		s;	/* T_String */
782d4e511cSCy Schubert 		u_int		u;	/* T_U_int */
792b15cb3dSCy Schubert 	} value;
802b15cb3dSCy Schubert };
812b15cb3dSCy Schubert 
822b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo;
832b15cb3dSCy Schubert 
842b15cb3dSCy Schubert /* Structure for nodes on the syntax tree */
852b15cb3dSCy Schubert typedef struct address_node_tag address_node;
862b15cb3dSCy Schubert struct address_node_tag {
872b15cb3dSCy Schubert 	address_node *	link;
882b15cb3dSCy Schubert 	char *		address;
892b15cb3dSCy Schubert 	u_short		type;	/* family, AF_UNSPEC (0), AF_INET[6] */
902b15cb3dSCy Schubert };
912b15cb3dSCy Schubert 
922b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(address_node) address_fifo;
932b15cb3dSCy Schubert 
942b15cb3dSCy Schubert typedef struct int_node_tag int_node;
952b15cb3dSCy Schubert struct int_node_tag {
962b15cb3dSCy Schubert 	int_node *	link;
972b15cb3dSCy Schubert 	int		i;
982b15cb3dSCy Schubert };
992b15cb3dSCy Schubert 
1002b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(int_node) int_fifo;
1012b15cb3dSCy Schubert 
1022b15cb3dSCy Schubert typedef struct string_node_tag string_node;
1032b15cb3dSCy Schubert struct string_node_tag {
1042b15cb3dSCy Schubert 	string_node *	link;
1052b15cb3dSCy Schubert 	char *		s;
1062b15cb3dSCy Schubert };
1072b15cb3dSCy Schubert 
1082b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(string_node) string_fifo;
1092b15cb3dSCy Schubert 
1102b15cb3dSCy Schubert typedef struct restrict_node_tag restrict_node;
1112b15cb3dSCy Schubert struct restrict_node_tag {
1122b15cb3dSCy Schubert 	restrict_node *	link;
1132b15cb3dSCy Schubert 	address_node *	addr;
1142b15cb3dSCy Schubert 	address_node *	mask;
1152d4e511cSCy Schubert 	attr_val_fifo *	flag_tok_fifo;
116*f5f40dd6SCy Schubert 	int/*BOOL*/	remove;
1172b15cb3dSCy Schubert 	int		line_no;
118*f5f40dd6SCy Schubert 	int		column;
11909100258SXin LI 	short		ippeerlimit;
1202d4e511cSCy Schubert 	short		srvfuzrft;
1212b15cb3dSCy Schubert };
1222b15cb3dSCy Schubert 
1232b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo;
1242b15cb3dSCy Schubert 
1252b15cb3dSCy Schubert typedef struct peer_node_tag peer_node;
1262b15cb3dSCy Schubert struct peer_node_tag {
1272b15cb3dSCy Schubert 	peer_node *	link;
1282b15cb3dSCy Schubert 	int		host_mode;
1292b15cb3dSCy Schubert 	address_node *	addr;
1302b15cb3dSCy Schubert 	attr_val_fifo *	peerflags;
1312b15cb3dSCy Schubert 	u_char		minpoll;
1322b15cb3dSCy Schubert 	u_char		maxpoll;
1332b15cb3dSCy Schubert 	u_int32		ttl;
1342b15cb3dSCy Schubert 	u_char		peerversion;
1352b15cb3dSCy Schubert 	keyid_t		peerkey;
1362b15cb3dSCy Schubert 	char *		group;
1372b15cb3dSCy Schubert };
1382b15cb3dSCy Schubert 
1392b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo;
1402b15cb3dSCy Schubert 
1412b15cb3dSCy Schubert typedef struct unpeer_node_tag unpeer_node;
1422b15cb3dSCy Schubert struct unpeer_node_tag {
1432b15cb3dSCy Schubert 	unpeer_node *	link;
1442b15cb3dSCy Schubert 	associd_t	assocID;
1452b15cb3dSCy Schubert 	address_node *	addr;
1462b15cb3dSCy Schubert };
1472b15cb3dSCy Schubert 
1482b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo;
1492b15cb3dSCy Schubert 
1502b15cb3dSCy Schubert typedef struct auth_node_tag auth_node;
1512b15cb3dSCy Schubert struct auth_node_tag {
1522b15cb3dSCy Schubert 	int		control_key;
1532b15cb3dSCy Schubert 	int		cryptosw;
1542b15cb3dSCy Schubert 	attr_val_fifo *	crypto_cmd_list;
1552b15cb3dSCy Schubert 	char *		keys;
1562b15cb3dSCy Schubert 	char *		keysdir;
1572b15cb3dSCy Schubert 	int		request_key;
1582b15cb3dSCy Schubert 	int		revoke;
1592b15cb3dSCy Schubert 	attr_val_fifo *	trusted_key_list;
1602b15cb3dSCy Schubert 	char *		ntp_signd_socket;
1612b15cb3dSCy Schubert };
1622b15cb3dSCy Schubert 
1632b15cb3dSCy Schubert typedef struct filegen_node_tag filegen_node;
1642b15cb3dSCy Schubert struct filegen_node_tag {
1652b15cb3dSCy Schubert 	filegen_node *	link;
1662b15cb3dSCy Schubert 	int		filegen_token;
1672b15cb3dSCy Schubert 	attr_val_fifo *	options;
1682b15cb3dSCy Schubert };
1692b15cb3dSCy Schubert 
1702b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo;
1712b15cb3dSCy Schubert 
1722b15cb3dSCy Schubert typedef struct setvar_node_tag setvar_node;
1732b15cb3dSCy Schubert struct setvar_node_tag {
1742b15cb3dSCy Schubert 	setvar_node *	link;
1752b15cb3dSCy Schubert 	char *		var;
1762b15cb3dSCy Schubert 	char *		val;
1772b15cb3dSCy Schubert 	int		isdefault;
1782b15cb3dSCy Schubert };
1792b15cb3dSCy Schubert 
1802b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo;
1812b15cb3dSCy Schubert 
1822b15cb3dSCy Schubert typedef struct nic_rule_node_tag nic_rule_node;
1832b15cb3dSCy Schubert struct nic_rule_node_tag {
1842b15cb3dSCy Schubert 	nic_rule_node *	link;
1852b15cb3dSCy Schubert 	int		match_class;
1862b15cb3dSCy Schubert 	char *		if_name;	/* or numeric address */
1872b15cb3dSCy Schubert 	int		action;
1882b15cb3dSCy Schubert };
1892b15cb3dSCy Schubert 
1902b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo;
1912b15cb3dSCy Schubert 
1922b15cb3dSCy Schubert typedef struct addr_opts_node_tag addr_opts_node;
1932b15cb3dSCy Schubert struct addr_opts_node_tag {
1942b15cb3dSCy Schubert 	addr_opts_node *link;
1952b15cb3dSCy Schubert 	address_node *	addr;
1962b15cb3dSCy Schubert 	attr_val_fifo *	options;
1972b15cb3dSCy Schubert };
1982b15cb3dSCy Schubert 
1992b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo;
2002b15cb3dSCy Schubert 
2012b15cb3dSCy Schubert typedef struct sim_node_tag sim_node;
2022b15cb3dSCy Schubert struct sim_node_tag {
2032b15cb3dSCy Schubert 	sim_node *		link;
2042b15cb3dSCy Schubert 	attr_val_fifo *		init_opts;
2052b15cb3dSCy Schubert 	server_info_fifo *	servers;
2062b15cb3dSCy Schubert };
2072b15cb3dSCy Schubert 
2082b15cb3dSCy Schubert typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo;
2092b15cb3dSCy Schubert 
2102b15cb3dSCy Schubert /* The syntax tree */
2112b15cb3dSCy Schubert typedef struct config_tree_tag config_tree;
2122b15cb3dSCy Schubert struct config_tree_tag {
2132b15cb3dSCy Schubert 	config_tree *	link;
2142b15cb3dSCy Schubert 
2152b15cb3dSCy Schubert 	attr_val	source;
2162b15cb3dSCy Schubert 	time_t		timestamp;
2172b15cb3dSCy Schubert 
2182b15cb3dSCy Schubert 	peer_fifo *	peers;
2192b15cb3dSCy Schubert 	unpeer_fifo *	unpeers;
2202b15cb3dSCy Schubert 
2212b15cb3dSCy Schubert 	/* Other Modes */
2222b15cb3dSCy Schubert 	int		broadcastclient;
2232b15cb3dSCy Schubert 	address_fifo *	manycastserver;
2242b15cb3dSCy Schubert 	address_fifo *	multicastclient;
2252b15cb3dSCy Schubert 
2262b15cb3dSCy Schubert 	attr_val_fifo *	orphan_cmds;	/* s/b renamed tos_options */
2272b15cb3dSCy Schubert 
2282b15cb3dSCy Schubert 	/* Monitoring Configuration */
2292b15cb3dSCy Schubert 	int_fifo *	stats_list;
2302b15cb3dSCy Schubert 	char *		stats_dir;
2312b15cb3dSCy Schubert 	filegen_fifo *	filegen_opts;
2322b15cb3dSCy Schubert 
2332b15cb3dSCy Schubert 	/* Access Control Configuration */
2342b15cb3dSCy Schubert 	attr_val_fifo *	discard_opts;
2352b15cb3dSCy Schubert 	attr_val_fifo *	mru_opts;
2362b15cb3dSCy Schubert 	restrict_fifo *	restrict_opts;
2372b15cb3dSCy Schubert 
2382b15cb3dSCy Schubert 	addr_opts_fifo *fudge;
239a466cc55SCy Schubert 	addr_opts_fifo *device;
2402b15cb3dSCy Schubert 	attr_val_fifo *	rlimit;
2412b15cb3dSCy Schubert 	attr_val_fifo *	tinker;
2422b15cb3dSCy Schubert 	attr_val_fifo *	enable_opts;
2432b15cb3dSCy Schubert 	attr_val_fifo *	disable_opts;
2442b15cb3dSCy Schubert 
2452b15cb3dSCy Schubert 	auth_node	auth;
2462b15cb3dSCy Schubert 
2472b15cb3dSCy Schubert 	attr_val_fifo *	logconfig;
2482b15cb3dSCy Schubert 	string_fifo *	phone;
2492b15cb3dSCy Schubert 	setvar_fifo *	setvar;
2502b15cb3dSCy Schubert 	int_fifo *	ttl;
2512b15cb3dSCy Schubert 	addr_opts_fifo *trap;
2522b15cb3dSCy Schubert 	attr_val_fifo *	vars;
2532b15cb3dSCy Schubert 	nic_rule_fifo *	nic_rules;
2542b15cb3dSCy Schubert 	int_fifo *	reset_counters;
2552d4e511cSCy Schubert 	attr_val_fifo *	pollskewlist;
2562b15cb3dSCy Schubert 
2572b15cb3dSCy Schubert 	sim_fifo *	sim_details;
2582b15cb3dSCy Schubert 	int		mdnstries;
2592b15cb3dSCy Schubert };
2602b15cb3dSCy Schubert 
2612b15cb3dSCy Schubert 
2622b15cb3dSCy Schubert /* Structure for holding a remote configuration command */
2632b15cb3dSCy Schubert struct REMOTE_CONFIG_INFO {
2642b15cb3dSCy Schubert 	char buffer[MAXLINE];
2652b15cb3dSCy Schubert 	char err_msg[MAXLINE];
2662b15cb3dSCy Schubert 	int pos;
2672b15cb3dSCy Schubert 	int err_pos;
2682b15cb3dSCy Schubert 	int no_errors;
2692b15cb3dSCy Schubert };
2702b15cb3dSCy Schubert 
271224ba2bdSOllivier Robert 
272224ba2bdSOllivier Robert /*
2732b15cb3dSCy Schubert  * context for trap_name_resolved() to call ctlsettrap() once the
2742b15cb3dSCy Schubert  * name->address resolution completes.
275224ba2bdSOllivier Robert  */
2762b15cb3dSCy Schubert typedef struct settrap_parms_tag {
2772b15cb3dSCy Schubert 	sockaddr_u	ifaddr;
2782b15cb3dSCy Schubert 	int		ifaddr_nonnull;
2792b15cb3dSCy Schubert } settrap_parms;
280224ba2bdSOllivier Robert 
281224ba2bdSOllivier Robert 
2822d4e511cSCy Schubert /*
2832d4e511cSCy Schubert ** Data Minimization Items
2842d4e511cSCy Schubert */
2852d4e511cSCy Schubert 
2862d4e511cSCy Schubert /* Serverresponse fuzz reftime: stored in 'restrict' fifos */
2872d4e511cSCy Schubert 
2882d4e511cSCy Schubert 
2892b15cb3dSCy Schubert /* get text from T_ tokens */
2902b15cb3dSCy Schubert const char * token_name(int token);
291224ba2bdSOllivier Robert 
2922b15cb3dSCy Schubert /* generic fifo routines for structs linked by 1st member */
29309100258SXin LI typedef void (*fifo_deleter)(void*);
29409100258SXin LI void *	destroy_gen_fifo(void *fifo, fifo_deleter func);
2952b15cb3dSCy Schubert void *	append_gen_fifo(void *fifo, void *entry);
2962b15cb3dSCy Schubert void *	concat_gen_fifos(void *first, void *second);
29709100258SXin LI #define DESTROY_G_FIFO(pf, func)	\
29809100258SXin LI 	((pf) = destroy_gen_fifo((pf), (fifo_deleter)(func)))
2992b15cb3dSCy Schubert #define APPEND_G_FIFO(pf, pe)		\
3002b15cb3dSCy Schubert 	((pf) = append_gen_fifo((pf), (pe)))
3012b15cb3dSCy Schubert #define CONCAT_G_FIFOS(first, second)	\
3022b15cb3dSCy Schubert 	((first) = concat_gen_fifos((first), (second)))
3032b15cb3dSCy Schubert #define HEAD_PFIFO(pf)			\
3042b15cb3dSCy Schubert 	(((pf) != NULL)			\
3052b15cb3dSCy Schubert 	      ? HEAD_FIFO(*(pf))	\
3062b15cb3dSCy Schubert 	      : NULL)
307224ba2bdSOllivier Robert 
3082b15cb3dSCy Schubert peer_node *create_peer_node(int hmode, address_node *addr,
3092b15cb3dSCy Schubert 			    attr_val_fifo *options);
3102b15cb3dSCy Schubert unpeer_node *create_unpeer_node(address_node *addr);
3112b15cb3dSCy Schubert address_node *create_address_node(char *addr, int type);
3122b15cb3dSCy Schubert void destroy_address_node(address_node *my_node);
3132b15cb3dSCy Schubert attr_val *create_attr_dval(int attr, double value);
3142b15cb3dSCy Schubert attr_val *create_attr_ival(int attr, int value);
3152d4e511cSCy Schubert attr_val *create_attr_rval(int attr, int first, int last);
3162b15cb3dSCy Schubert attr_val *create_attr_sval(int attr, const char *s);
3172d4e511cSCy Schubert attr_val *create_attr_uval(int attr, u_int value);
31809100258SXin LI void	  destroy_attr_val(attr_val *node);
3192b15cb3dSCy Schubert filegen_node *create_filegen_node(int filegen_token,
3202b15cb3dSCy Schubert 				  attr_val_fifo *options);
3212b15cb3dSCy Schubert string_node *create_string_node(char *str);
3222b15cb3dSCy Schubert restrict_node *create_restrict_node(address_node *	addr,
3232b15cb3dSCy Schubert 				    address_node *	mask,
32409100258SXin LI 				    short		ippeerlimit,
325*f5f40dd6SCy Schubert 				    attr_val_fifo *	flag_tok_fifo,
326*f5f40dd6SCy Schubert 				    int/*BOOL*/		remove,
327*f5f40dd6SCy Schubert 				    int			nline,
328*f5f40dd6SCy Schubert 				    int			ncol);
3292b15cb3dSCy Schubert int_node *create_int_node(int val);
3302b15cb3dSCy Schubert addr_opts_node *create_addr_opts_node(address_node *addr,
3312b15cb3dSCy Schubert 				      attr_val_fifo *options);
3322b15cb3dSCy Schubert sim_node *create_sim_node(attr_val_fifo *init_opts,
3332b15cb3dSCy Schubert 			  server_info_fifo *servers);
3342b15cb3dSCy Schubert setvar_node *create_setvar_node(char *var, char *val, int isdefault);
3352b15cb3dSCy Schubert nic_rule_node *create_nic_rule_node(int match_class, char *if_name,
3362b15cb3dSCy Schubert 				    int action);
337224ba2bdSOllivier Robert 
3382b15cb3dSCy Schubert script_info *create_sim_script_info(double duration,
3392b15cb3dSCy Schubert 				    attr_val_fifo *script_queue);
3402b15cb3dSCy Schubert server_info *create_sim_server(address_node *addr, double server_offset,
3412b15cb3dSCy Schubert 			       script_info_fifo *script);
3429c2daa00SOllivier Robert 
3432b15cb3dSCy Schubert extern struct REMOTE_CONFIG_INFO remote_config;
3442b15cb3dSCy Schubert void config_remotely(sockaddr_u *);
345224ba2bdSOllivier Robert 
3462b15cb3dSCy Schubert #ifdef SAVECONFIG
3472b15cb3dSCy Schubert int dump_config_tree(config_tree *ptree, FILE *df, int comment);
3482b15cb3dSCy Schubert int dump_all_config_trees(FILE *df, int comment);
3492b15cb3dSCy Schubert #endif
3509c2daa00SOllivier Robert 
3512b15cb3dSCy Schubert #if defined(HAVE_SETRLIMIT)
3522b15cb3dSCy Schubert void ntp_rlimit(int, rlim_t, int, const char *);
3532b15cb3dSCy Schubert #endif
3549c2daa00SOllivier Robert 
3552b15cb3dSCy Schubert #endif	/* !defined(NTP_CONFIG_H) */
356