4 * Copyright (C) 2007 iptelorg GmbH
6 * This file is part of SIP-router, a free SIP server.
8 * SIP-router is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version
13 * SIP-router is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * 2007-12-03 Initial version (Miklos)
25 * 2008-01-31 added DNS resolver parameters (Miklos)
27 /** core runtime config.
33 * - @ref ConfigCoreDoc
38 * \page ConfigCoreDoc Documentation of configuration parser
39 * \section ConfigParser Configuration parser
43 * \verbinclude cfg.txt
48 #ifdef USE_DST_BLACKLIST
49 #include "dst_blacklist.h"
53 #include "dns_cache.h"
55 #if defined PKG_MALLOC || defined SHM_MEM
58 #include "msg_translator.h" /* fix_global_req_flags() */
64 struct cfg_group_core default_core_cfg = {
65 L_WARN, /*!< print only msg. < L_WARN */
66 LOG_DAEMON, /*!< log_facility -- see syslog(3) */
68 #ifdef USE_DST_BLACKLIST
70 0, /*!< dst blacklist is disabled by default */
73 0, /* blst_udp_imask */
74 0, /* blst_tcp_imask */
75 0, /* blst_tls_imask */
76 0, /* blst_sctp_imask */
80 1, /*!< dns_try_ipv6 -- on by default */
82 0, /*!< dns_try_ipv6 -- off, if no ipv6 support */
84 0, /*!< dns_try_naptr -- off by default */
85 30, /*!< udp transport preference (for naptr) */
86 20, /*!< tcp transport preference (for naptr) */
87 10, /*!< tls transport preference (for naptr) */
88 20, /*!< sctp transport preference (for naptr) */
89 -1, /*!< dns_retr_time */
90 -1, /*!< dns_retr_no */
91 -1, /*!< dns_servers_no */
92 1, /*!< dns_search_list */
93 1, /*!< dns_search_fmatch */
97 1, /*!< use_dns_cache -- on by default */
98 0, /*!< dns_cache_flags */
99 0, /*!< use_dns_failover -- off by default */
100 0, /*!< dns_srv_lb -- off by default */
101 DEFAULT_DNS_NEG_CACHE_TTL, /*!< neg. cache ttl */
102 DEFAULT_DNS_CACHE_MIN_TTL, /*!< minimum ttl */
103 DEFAULT_DNS_CACHE_MAX_TTL, /*!< maximum ttl */
104 DEFAULT_DNS_MAX_MEM, /*!< dns_cache_max_mem */
105 0, /*!< dns_cache_del_nonexp -- delete only expired entries by default */
106 0, /*!< dns_cache_rec_pref -- 0 by default, do not check the existing entries. */
109 0, /*!< mem_dump_pkg */
112 0, /*!< mem_dump_shm */
114 DEFAULT_MAX_WHILE_LOOPS, /*!< max_while_loops */
115 0, /*!< udp_mtu (disabled by default) */
116 0, /*!< udp_mtu_try_proto -> default disabled */
117 0, /**< udp4_raw (disabled by default) */
118 1500, /**< udp4_raw_mtu (1500 by default) */
119 -1, /**< udp4_raw_ttl (auto detect by default) */
120 0, /*!< force_rport */
121 L_DBG, /*!< memlog */
122 3, /*!< mem_summary -flags: 0 off, 1 pkg_status, 2 shm_status,
123 4 pkg_sums, 8 shm_sums, 16 short_status */
124 0, /*!< mem_safety - 0 disabled */
125 0, /*!< mem_join - 0 disabled */
126 L_ERR, /*!< corelog */
127 L_ERR, /*!< latency log */
128 0, /*!< latency limit db */
129 0 /*!< latency limit action */
132 void *core_cfg = &default_core_cfg;
135 static int check_raw_sock_support(void* cfg_h, str* gname, str* name,
140 val = (int)(long)(*v);
141 #ifndef USE_RAW_SOCKS
143 ERR("no RAW_SOCKS support, please recompile with it enabled\n");
147 #else /* USE_RAW_SOCKS */
148 if (raw_udp4_send_sock < 0) {
150 ERR("could not intialize raw socket on startup, please "
151 "restart as root or with CAP_NET_RAW\n");
153 } else if (val < 0) {
154 /* auto and no socket => disable */
157 } else if (val < 0) {
158 /* auto and socket => enable */
162 #endif /* USE_RAW_SOCKS */
167 static int udp4_raw_ttl_fixup(void* cfg_h, str* gname, str* name, void** val)
170 v = (int)(long)(*val);
173 v = sock_get_ttl(sendipv4->socket);
176 /* some error => use a reasonable default */
179 *val = (void*)(long)v;
185 cfg_def_t core_cfg_def[] = {
186 {"debug", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
188 {"log_facility", CFG_VAR_INT|CFG_INPUT_STRING, 0, 0, log_facility_fixup, 0,
189 "syslog facility, see \"man 3 syslog\""},
190 {"memdbg", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
191 "log level for memory debugging messages"},
192 #ifdef USE_DST_BLACKLIST
194 {"use_dst_blacklist", CFG_VAR_INT, 0, 1, use_dst_blacklist_fixup, 0,
195 "enable/disable destination blacklisting"},
196 {"dst_blacklist_expire", CFG_VAR_INT, 0, 0, 0, 0,
197 "how much time (in s) a blacklisted destination is kept in the list"},
198 {"dst_blacklist_mem", CFG_VAR_INT, 0, 0, blst_max_mem_fixup, 0,
199 "maximum shared memory amount (in KB) used for keeping the blacklisted"
201 {"dst_blacklist_udp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
202 "blacklist event ignore mask for UDP"},
203 {"dst_blacklist_tcp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
204 "blacklist event ignore mask for TCP"},
205 {"dst_blacklist_tls_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
206 "blacklist event ignore mask for TLS"},
207 {"dst_blacklist_sctp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
208 "blacklist event ignore mask for SCTP"},
212 {"dns_try_ipv6", CFG_VAR_INT, 0, 1, dns_try_ipv6_fixup, fix_dns_flags,
214 {"dns_try_ipv6", CFG_VAR_INT, 0, 1, dns_try_ipv6_fixup, 0,
216 "enable/disable IPv6 DNS lookups"},
218 {"dns_try_naptr", CFG_VAR_INT, 0, 1, 0, fix_dns_flags,
220 {"dns_try_naptr", CFG_VAR_INT, 0, 1, 0, 0,
222 "enable/disable NAPTR DNS lookups"},
223 {"dns_udp_pref", CFG_VAR_INT, 0, 0, 0, reinit_naptr_proto_prefs,
224 "udp protocol preference when doing NAPTR lookups"},
225 {"dns_tcp_pref", CFG_VAR_INT, 0, 0, 0, reinit_naptr_proto_prefs,
226 "tcp protocol preference when doing NAPTR lookups"},
227 {"dns_tls_pref", CFG_VAR_INT, 0, 0, 0, reinit_naptr_proto_prefs,
228 "tls protocol preference when doing NAPTR lookups"},
229 {"dns_sctp_pref", CFG_VAR_INT, 0, 0, 0, reinit_naptr_proto_prefs,
230 "sctp protocol preference when doing NAPTR lookups"},
231 {"dns_retr_time", CFG_VAR_INT, 0, 0, 0, resolv_reinit,
232 "time in s before retrying a dns request"},
233 {"dns_retr_no", CFG_VAR_INT, 0, 0, 0, resolv_reinit,
234 "number of dns retransmissions before giving up"},
235 {"dns_servers_no", CFG_VAR_INT, 0, 0, 0, resolv_reinit,
236 "how many dns servers from the ones defined in "
237 "/etc/resolv.conf will be used"},
238 {"dns_use_search_list", CFG_VAR_INT, 0, 1, 0, resolv_reinit,
239 "if set to 0, the search list in /etc/resolv.conf is ignored"},
240 {"dns_search_full_match", CFG_VAR_INT, 0, 1, 0, 0,
241 "enable/disable domain name checks against the search list "
243 {"dns_reinit", CFG_VAR_INT|CFG_INPUT_INT, 1, 1, dns_reinit_fixup,
245 "set to 1 in order to reinitialize the DNS resolver"},
248 {"use_dns_cache", CFG_VAR_INT, 0, 1, use_dns_cache_fixup, 0,
249 "enable/disable the dns cache"},
250 {"dns_cache_flags", CFG_VAR_INT, 0, 4, 0, fix_dns_flags,
251 "dns cache specific resolver flags "
252 "(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},
253 {"use_dns_failover", CFG_VAR_INT, 0, 1, use_dns_failover_fixup, 0,
254 "enable/disable dns failover in case the destination "
255 "resolves to multiple ip addresses and/or multiple SRV records "
256 "(depends on use_dns_cache)"},
257 {"dns_srv_lb", CFG_VAR_INT, 0, 1, 0, fix_dns_flags,
258 "enable/disable load balancing to different srv records "
259 "of the same priority based on the srv records weights "
260 "(depends on dns_failover)"},
261 {"dns_cache_negative_ttl", CFG_VAR_INT, 0, 0, 0, 0,
262 "time to live for negative results (\"not found\") "
263 "in seconds. Use 0 to disable"},
264 {"dns_cache_min_ttl", CFG_VAR_INT, 0, 0, 0, 0,
265 "minimum accepted time to live for a record, in seconds"},
266 {"dns_cache_max_ttl", CFG_VAR_INT, 0, 0, 0, 0,
267 "maximum accepted time to live for a record, in seconds"},
268 {"dns_cache_mem", CFG_VAR_INT, 0, 0, dns_cache_max_mem_fixup, 0,
269 "maximum memory used for the dns cache in Kb"},
270 {"dns_cache_del_nonexp", CFG_VAR_INT, 0, 1, 0, 0,
271 "allow deletion of non-expired records from the cache when "
272 "there is no more space left for new ones"},
273 {"dns_cache_rec_pref", CFG_VAR_INT, 0, 3, 0, 0,
274 "DNS cache record preference: "
275 " 0 - do not check duplicates"
276 " 1 - prefer old records"
277 " 2 - prefer new records"
278 " 3 - prefer records with longer lifetime"},
281 {"mem_dump_pkg", CFG_VAR_INT, 0, 0, 0, mem_dump_pkg_cb,
282 "dump process memory status, parameter: pid_number"},
285 {"mem_dump_shm", CFG_VAR_INT, 0, 0, mem_dump_shm_fixup, 0,
286 "dump shared memory status"},
288 {"max_while_loops", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
289 "maximum iterations allowed for a while loop" },
290 {"udp_mtu", CFG_VAR_INT|CFG_ATOMIC, 0, 65535, 0, 0,
291 "fallback to a congestion controlled protocol if send size"
293 {"udp_mtu_try_proto", CFG_VAR_INT, 1, 4, 0, fix_global_req_flags,
294 "if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
295 {"udp4_raw", CFG_VAR_INT | CFG_ATOMIC, -1, 1, check_raw_sock_support, 0,
296 "enable/disable using a raw socket for sending UDP IPV4 packets."
297 " Should be faster on multi-CPU linux running machines."},
298 {"udp4_raw_mtu", CFG_VAR_INT | CFG_ATOMIC, 28, 65535, 0, 0,
299 "set the MTU used when using raw sockets for udp sending."
300 " This value will be used when deciding whether or not to fragment"
302 {"udp4_raw_ttl", CFG_VAR_INT | CFG_ATOMIC, -1, 255, udp4_raw_ttl_fixup, 0,
303 "set the IP TTL used when using raw sockets for udp sending."
304 " -1 will use the same value as for normal udp sockets."},
305 {"force_rport", CFG_VAR_INT, 0, 1, 0, fix_global_req_flags,
306 "force rport for all the received messages" },
307 {"memlog", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
308 "log level for memory status/summary information"},
309 {"mem_summary", CFG_VAR_INT|CFG_ATOMIC, 0, 31, 0, 0,
310 "memory debugging information displayed on exit (flags): "
312 " 1 - dump all the pkg used blocks (status),"
313 " 2 - dump all the shm used blocks (status),"
314 " 4 - summary of pkg used blocks,"
315 " 8 - summary of shm used blocks,"
316 " 16 - short status instead of dump" },
317 {"mem_safety", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
318 "safety level for memory operations"},
319 {"mem_join", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
320 "join free memory fragments"},
321 {"corelog", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
322 "log level for non-critical core error messages"},
323 {"latency_log", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
324 "log level for latency limits alert messages"},
325 {"latency_limit_db", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
326 "limit is ms for alerting on time consuming db commands"},
327 {"latency_limit_action", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
328 "limit is ms for alerting on time consuming config actions"},