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