1 #ifndef GUARD_NTP_CONFIG_H 2 #define GUARD_NTP_CONFIG_H 3 4 #include <sys/resource.h> 5 #include <stdbool.h> 6 #include <stdio.h> 7 #include <math.h> 8 9 #include "ntp_syslog.h" 10 #include "ntp_fp.h" 11 #include "ntp.h" 12 #include "ntp_malloc.h" 13 #include "ntp_refclock.h" 14 #include "ntp_stdlib.h" 15 #include "ntp_machine.h" 16 17 /* 18 * Configuration file name 19 */ 20 #ifndef CONFIG_FILE 21 # define CONFIG_FILE "/etc/ntp.conf" 22 #endif /* not CONFIG_FILE */ 23 #define CONFIG_DIR "ntp.d" 24 25 /* Limits */ 26 #define MAXLINE 1024 27 28 /* Configuration sources */ 29 30 #define CONF_SOURCE_FILE 0 31 #define CONF_SOURCE_NTPQ 1 32 33 /* count of parsing errors - for log file */ 34 extern int parsing_errors; 35 36 /* list of servers from command line for config_peers() */ 37 extern int cmdline_server_count; 38 extern char ** cmdline_servers; 39 40 typedef struct int_range_tag { 41 int first; 42 int last; 43 } int_range; 44 45 /* Structure for storing an attribute-value pair */ 46 typedef struct attr_val_tag attr_val; 47 struct attr_val_tag { 48 attr_val * link; 49 int attr; 50 int type; /* T_String, T_Integer, ... */ 51 union val { 52 int i; 53 unsigned int u; 54 int_range r; 55 double d; 56 char * s; 57 } value; 58 }; 59 60 typedef DECL_FIFO_ANCHOR(attr_val) attr_val_fifo; 61 62 /* Structure for nodes on the syntax tree */ 63 typedef struct address_node_tag address_node; 64 struct address_node_tag { 65 address_node * link; 66 char * address; 67 unsigned short type; /* family, AF_UNSPEC (0), AF_INET[6] */ 68 }; 69 70 typedef DECL_FIFO_ANCHOR(address_node) address_fifo; 71 72 typedef struct int_node_tag int_node; 73 struct int_node_tag { 74 int_node * link; 75 int i; 76 }; 77 78 typedef DECL_FIFO_ANCHOR(int_node) int_fifo; 79 80 typedef struct string_node_tag string_node; 81 struct string_node_tag { 82 string_node * link; 83 char * s; 84 }; 85 86 typedef DECL_FIFO_ANCHOR(string_node) string_fifo; 87 88 typedef struct restrict_node_tag restrict_node; 89 struct restrict_node_tag { 90 restrict_node * link; 91 int mode; /* restrict or unrestrict? */ 92 address_node * addr; 93 address_node * mask; 94 int_fifo * flags; 95 int line_no; 96 }; 97 98 typedef DECL_FIFO_ANCHOR(restrict_node) restrict_fifo; 99 100 typedef struct peer_node_tag peer_node; 101 struct peer_node_tag { 102 peer_node * link; 103 address_node * addr; 104 int host_mode; 105 struct peer_ctl ctl; 106 struct refclockstat clock_stat; 107 char * group; 108 }; 109 110 typedef DECL_FIFO_ANCHOR(peer_node) peer_fifo; 111 112 typedef struct unpeer_node_tag unpeer_node; 113 struct unpeer_node_tag { 114 unpeer_node * link; 115 associd_t assocID; 116 address_node * addr; 117 }; 118 119 typedef DECL_FIFO_ANCHOR(unpeer_node) unpeer_fifo; 120 121 typedef struct auth_node_tag auth_node; 122 struct auth_node_tag { 123 int control_key; 124 char * keys; 125 attr_val_fifo * trusted_key_list; 126 char * ntp_signd_socket; 127 }; 128 129 typedef struct filegen_node_tag filegen_node; 130 struct filegen_node_tag { 131 filegen_node * link; 132 int filegen_token; 133 attr_val_fifo * options; 134 }; 135 136 typedef DECL_FIFO_ANCHOR(filegen_node) filegen_fifo; 137 138 typedef struct setvar_node_tag setvar_node; 139 struct setvar_node_tag { 140 setvar_node * link; 141 char * var; 142 char * val; 143 int isdefault; 144 }; 145 146 typedef DECL_FIFO_ANCHOR(setvar_node) setvar_fifo; 147 148 typedef struct nic_rule_node_tag nic_rule_node; 149 struct nic_rule_node_tag { 150 nic_rule_node * link; 151 int match_class; 152 char * if_name; /* or numeric address */ 153 int action; 154 }; 155 156 typedef DECL_FIFO_ANCHOR(nic_rule_node) nic_rule_fifo; 157 158 typedef struct addr_opts_node_tag addr_opts_node; 159 struct addr_opts_node_tag { 160 addr_opts_node *link; 161 address_node * addr; 162 attr_val_fifo * options; 163 }; 164 165 typedef DECL_FIFO_ANCHOR(addr_opts_node) addr_opts_fifo; 166 167 typedef struct sim_node_tag sim_node; 168 struct sim_node_tag { 169 sim_node * link; 170 attr_val_fifo * init_opts; 171 }; 172 173 typedef DECL_FIFO_ANCHOR(sim_node) sim_fifo; 174 175 /* The syntax tree */ 176 typedef struct config_tree_tag config_tree; 177 struct config_tree_tag { 178 config_tree * link; 179 180 attr_val source; 181 time_t timestamp; 182 183 peer_fifo * peers; 184 unpeer_fifo * unpeers; 185 186 /* Other Modes */ 187 attr_val_fifo * orphan_cmds; /* s/b renamed tos_options */ 188 189 /* Monitoring Configuration */ 190 int_fifo * stats_list; 191 char * stats_dir; 192 filegen_fifo * filegen_opts; 193 194 /* Access Control Configuration */ 195 attr_val_fifo * limit_opts; 196 attr_val_fifo * mru_opts; 197 restrict_fifo * restrict_opts; 198 199 addr_opts_fifo *fudge; 200 attr_val_fifo * rlimit; 201 attr_val_fifo * tinker; 202 attr_val_fifo * nts; 203 attr_val_fifo * enable_opts; 204 attr_val_fifo * disable_opts; 205 206 auth_node auth; 207 208 attr_val_fifo * logconfig; 209 string_fifo * phone; 210 setvar_fifo * setvar; 211 attr_val_fifo * vars; 212 nic_rule_fifo * nic_rules; 213 int_fifo * reset_counters; 214 215 sim_fifo * sim_details; 216 int mdnstries; 217 }; 218 extern void init_readconfig(void); 219 extern void set_keys_file(char*); 220 extern void set_trustedkey(keyid_t); 221 extern int mdnstries; 222 223 224 /* Structure for holding a remote configuration command */ 225 struct REMOTE_CONFIG_INFO { 226 char buffer[MAXLINE]; 227 char err_msg[MAXLINE]; 228 int pos; 229 int err_pos; 230 int no_errors; 231 }; 232 233 234 /* get text from T_ tokens */ 235 const char * token_name(int token); 236 237 /* generic fifo routines for structs linked by 1st member */ 238 void* append_gen_fifo(void *fifo, void *entry); 239 void * concat_gen_fifos(void *first, void *second); 240 #define APPEND_G_FIFO(pf, pe) \ 241 ((pf) = append_gen_fifo((pf), (pe))) 242 #define CONCAT_G_FIFOS(first, second) \ 243 ((first) = concat_gen_fifos((first), (second))) 244 #define HEAD_PFIFO(pf) \ 245 (((pf) != NULL) \ 246 ? HEAD_FIFO(*(pf)) \ 247 : NULL) 248 249 address_node *addr_from_typeunit(char *type, int unit); 250 peer_node *create_peer_node(int hmode, address_node *addr, 251 attr_val_fifo *options); 252 unpeer_node *create_unpeer_node(address_node *addr); 253 address_node *create_address_node(char *addr, int type); 254 void destroy_address_node(address_node *my_node); 255 attr_val *create_attr_dval(int attr, double value); 256 attr_val *create_attr_ival(int attr, int value); 257 attr_val *create_attr_uval(int attr, unsigned int value); 258 attr_val *create_attr_rangeval(int attr, int first, int last); 259 attr_val *create_attr_sval(int attr, const char *s); 260 filegen_node *create_filegen_node(int filegen_token, 261 attr_val_fifo *options); 262 string_node *create_string_node(char *str); 263 restrict_node *create_restrict_node(int mode, address_node *addr, 264 address_node *mask, 265 int_fifo *flags, int line_no); 266 int_node *create_int_node(int val); 267 addr_opts_node *create_addr_opts_node(address_node *addr, 268 attr_val_fifo *options); 269 setvar_node *create_setvar_node(char *var, char *val, int isdefault); 270 nic_rule_node *create_nic_rule_node(int match_class, char *if_name, 271 int action); 272 273 extern struct REMOTE_CONFIG_INFO remote_config; 274 void config_remotely(sockaddr_u *); 275 276 extern bool have_interface_option; 277 extern char *stats_drift_file; /* name of the driftfile */ 278 279 280 void ntp_rlimit(int, rlim_t, int, const char *); 281 282 #endif /* GUARD_NTP_CONFIG_H */ 283