cfg_core.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Copyright (C) 2007 iptelorg GmbH
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. /** Kamailio core :: core runtime config.
  22. * @file cfg_core.c
  23. * @ingroup core
  24. * Module: @ref core
  25. *
  26. * See
  27. * - @ref ConfigCoreDoc
  28. * - @ref ConfigEngine
  29. * - @ref cfg_core.h
  30. */
  31. /*!
  32. * \page ConfigCoreDoc Documentation of configuration parser
  33. * \section ConfigParser Configuration parser
  34. * Further information
  35. * - \ref ConfigEngine
  36. * - \ref cfg_core.h
  37. * \verbinclude cfg.txt
  38. *
  39. */
  40. #include "dprint.h"
  41. #ifdef USE_DST_BLACKLIST
  42. #include "dst_blacklist.h"
  43. #endif
  44. #include "resolve.h"
  45. #ifdef USE_DNS_CACHE
  46. #include "dns_cache.h"
  47. #endif
  48. #if defined PKG_MALLOC || defined SHM_MEM
  49. #include "pt.h"
  50. #endif
  51. #include "msg_translator.h" /* fix_global_req_flags() */
  52. #include "globals.h"
  53. #include "sock_ut.h"
  54. #include "cfg/cfg.h"
  55. #include "cfg_core.h"
  56. struct cfg_group_core default_core_cfg = {
  57. L_WARN, /*!< print only msg. < L_WARN */
  58. LOG_DAEMON, /*!< log_facility -- see syslog(3) */
  59. L_DBG+1, /*!< memdbg */
  60. #ifdef USE_DST_BLACKLIST
  61. /* blacklist */
  62. 0, /*!< dst blacklist is disabled by default */
  63. DEFAULT_BLST_TIMEOUT,
  64. DEFAULT_BLST_MAX_MEM,
  65. 0, /* blst_udp_imask */
  66. 0, /* blst_tcp_imask */
  67. 0, /* blst_tls_imask */
  68. 0, /* blst_sctp_imask */
  69. #endif
  70. /* resolver */
  71. 1, /*!< dns_try_ipv6 -- on by default */
  72. 0, /*!< dns_try_naptr -- off by default */
  73. 30, /*!< udp transport preference (for naptr) */
  74. 20, /*!< tcp transport preference (for naptr) */
  75. 10, /*!< tls transport preference (for naptr) */
  76. 20, /*!< sctp transport preference (for naptr) */
  77. -1, /*!< dns_retr_time */
  78. -1, /*!< dns_retr_no */
  79. -1, /*!< dns_servers_no */
  80. 1, /*!< dns_search_list */
  81. 1, /*!< dns_search_fmatch */
  82. 0, /*!< dns_reinit */
  83. 1, /*!< dns_naptr_ignore_rfc */
  84. /* DNS cache */
  85. #ifdef USE_DNS_CACHE
  86. 1, /*!< use_dns_cache -- on by default */
  87. 0, /*!< dns_cache_flags */
  88. 0, /*!< use_dns_failover -- off by default */
  89. 0, /*!< dns_srv_lb -- off by default */
  90. DEFAULT_DNS_NEG_CACHE_TTL, /*!< neg. cache ttl */
  91. DEFAULT_DNS_CACHE_MIN_TTL, /*!< minimum ttl */
  92. DEFAULT_DNS_CACHE_MAX_TTL, /*!< maximum ttl */
  93. DEFAULT_DNS_MAX_MEM, /*!< dns_cache_max_mem */
  94. 0, /*!< dns_cache_del_nonexp -- delete only expired entries by default */
  95. 0, /*!< dns_cache_rec_pref -- 0 by default, do not check the existing entries. */
  96. #endif
  97. #ifdef PKG_MALLOC
  98. 0, /*!< mem_dump_pkg */
  99. #endif
  100. #ifdef SHM_MEM
  101. 0, /*!< mem_dump_shm */
  102. #endif
  103. DEFAULT_MAX_WHILE_LOOPS, /*!< max_while_loops */
  104. 0, /*!< udp_mtu (disabled by default) */
  105. 0, /*!< udp_mtu_try_proto -> default disabled */
  106. 0, /**< udp4_raw (disabled by default) */
  107. 1500, /**< udp4_raw_mtu (1500 by default) */
  108. -1, /**< udp4_raw_ttl (auto detect by default) */
  109. 0, /*!< force_rport */
  110. L_DBG+1, /*!< memlog */
  111. 3, /*!< mem_summary -flags: 0 off, 1 pkg_status, 2 shm_status,
  112. 4 pkg_sums, 8 shm_sums, 16 short_status */
  113. 0, /*!< mem_safety - 0 disabled */
  114. 0, /*!< mem_join - 0 disabled */
  115. L_ERR, /*!< corelog */
  116. L_ERR, /*!< latency log */
  117. 0, /*!< latency limit db */
  118. 0 /*!< latency limit action */
  119. };
  120. void *core_cfg = &default_core_cfg;
  121. static int check_raw_sock_support(void* cfg_h, str* gname, str* name,
  122. void** v)
  123. {
  124. int val;
  125. val = (int)(long)(*v);
  126. #ifndef USE_RAW_SOCKS
  127. if (val > 0) {
  128. ERR("no RAW_SOCKS support, please recompile with it enabled\n");
  129. return -1;
  130. }
  131. return 0;
  132. #else /* USE_RAW_SOCKS */
  133. if (raw_udp4_send_sock < 0) {
  134. if (val > 0) {
  135. ERR("could not intialize raw socket on startup, please "
  136. "restart as root or with CAP_NET_RAW\n");
  137. return -1;
  138. } else if (val < 0) {
  139. /* auto and no socket => disable */
  140. *v = (void*)(long)0;
  141. }
  142. } else if (val < 0) {
  143. /* auto and socket => enable */
  144. *v = (void*)(long)1;
  145. }
  146. return 0;
  147. #endif /* USE_RAW_SOCKS */
  148. }
  149. static int udp4_raw_ttl_fixup(void* cfg_h, str* gname, str* name, void** val)
  150. {
  151. int v;
  152. v = (int)(long)(*val);
  153. if (v < 0) {
  154. if (sendipv4)
  155. v = sock_get_ttl(sendipv4->socket);
  156. }
  157. if (v < 0) {
  158. /* some error => use a reasonable default */
  159. v = 63;
  160. }
  161. *val = (void*)(long)v;
  162. return 0;
  163. }
  164. cfg_def_t core_cfg_def[] = {
  165. {"debug", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  166. "debug level"},
  167. {"log_facility", CFG_VAR_INT|CFG_INPUT_STRING, 0, 0, log_facility_fixup, 0,
  168. "syslog facility, see \"man 3 syslog\""},
  169. {"memdbg", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  170. "log level for memory debugging messages"},
  171. #ifdef USE_DST_BLACKLIST
  172. /* blacklist */
  173. {"use_dst_blacklist", CFG_VAR_INT, 0, 1, use_dst_blacklist_fixup, 0,
  174. "enable/disable destination blacklisting"},
  175. {"dst_blacklist_expire", CFG_VAR_INT, 0, 0, 0, 0,
  176. "how much time (in s) a blacklisted destination is kept in the list"},
  177. {"dst_blacklist_mem", CFG_VAR_INT, 0, 0, blst_max_mem_fixup, 0,
  178. "maximum shared memory amount (in KB) used for keeping the blacklisted"
  179. " destinations"},
  180. {"dst_blacklist_udp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
  181. "blacklist event ignore mask for UDP"},
  182. {"dst_blacklist_tcp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
  183. "blacklist event ignore mask for TCP"},
  184. {"dst_blacklist_tls_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
  185. "blacklist event ignore mask for TLS"},
  186. {"dst_blacklist_sctp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
  187. "blacklist event ignore mask for SCTP"},
  188. #endif
  189. /* resolver */
  190. #ifdef USE_DNS_CACHE
  191. {"dns_try_ipv6", CFG_VAR_INT, 0, 1, dns_try_ipv6_fixup, fix_dns_flags,
  192. #else
  193. {"dns_try_ipv6", CFG_VAR_INT, 0, 1, dns_try_ipv6_fixup, 0,
  194. #endif
  195. "enable/disable IPv6 DNS lookups"},
  196. #ifdef USE_DNS_CACHE
  197. {"dns_try_naptr", CFG_VAR_INT, 0, 1, 0, fix_dns_flags,
  198. #else
  199. {"dns_try_naptr", CFG_VAR_INT, 0, 1, 0, 0,
  200. #endif
  201. "enable/disable NAPTR DNS lookups"},
  202. {"dns_udp_pref", CFG_VAR_INT, 0, 0, 0, reinit_proto_prefs,
  203. "udp protocol preference when doing NAPTR lookups"},
  204. {"dns_tcp_pref", CFG_VAR_INT, 0, 0, 0, reinit_proto_prefs,
  205. "tcp protocol preference when doing NAPTR lookups"},
  206. {"dns_tls_pref", CFG_VAR_INT, 0, 0, 0, reinit_proto_prefs,
  207. "tls protocol preference when doing NAPTR lookups"},
  208. {"dns_sctp_pref", CFG_VAR_INT, 0, 0, 0, reinit_proto_prefs,
  209. "sctp protocol preference when doing NAPTR lookups"},
  210. {"dns_retr_time", CFG_VAR_INT, 0, 0, 0, resolv_reinit,
  211. "time in s before retrying a dns request"},
  212. {"dns_retr_no", CFG_VAR_INT, 0, 0, 0, resolv_reinit,
  213. "number of dns retransmissions before giving up"},
  214. {"dns_servers_no", CFG_VAR_INT, 0, 0, 0, resolv_reinit,
  215. "how many dns servers from the ones defined in "
  216. "/etc/resolv.conf will be used"},
  217. {"dns_use_search_list", CFG_VAR_INT, 0, 1, 0, resolv_reinit,
  218. "if set to 0, the search list in /etc/resolv.conf is ignored"},
  219. {"dns_search_full_match", CFG_VAR_INT, 0, 1, 0, 0,
  220. "enable/disable domain name checks against the search list "
  221. "in DNS answers"},
  222. {"dns_reinit", CFG_VAR_INT|CFG_INPUT_INT, 1, 1, dns_reinit_fixup,
  223. resolv_reinit,
  224. "set to 1 in order to reinitialize the DNS resolver"},
  225. {"dns_naptr_ignore_rfc", CFG_VAR_INT, 0, 0, 0, reinit_proto_prefs,
  226. "ignore the Order field required by RFC 2915"},
  227. /* DNS cache */
  228. #ifdef USE_DNS_CACHE
  229. {"use_dns_cache", CFG_VAR_INT, 0, 1, use_dns_cache_fixup, 0,
  230. "enable/disable the dns cache"},
  231. {"dns_cache_flags", CFG_VAR_INT, 0, 4, 0, fix_dns_flags,
  232. "dns cache specific resolver flags "
  233. "(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},
  234. {"use_dns_failover", CFG_VAR_INT, 0, 1, use_dns_failover_fixup, 0,
  235. "enable/disable dns failover in case the destination "
  236. "resolves to multiple ip addresses and/or multiple SRV records "
  237. "(depends on use_dns_cache)"},
  238. {"dns_srv_lb", CFG_VAR_INT, 0, 1, 0, fix_dns_flags,
  239. "enable/disable load balancing to different srv records "
  240. "of the same priority based on the srv records weights "
  241. "(depends on dns_failover)"},
  242. {"dns_cache_negative_ttl", CFG_VAR_INT, 0, 0, 0, 0,
  243. "time to live for negative results (\"not found\") "
  244. "in seconds. Use 0 to disable"},
  245. {"dns_cache_min_ttl", CFG_VAR_INT, 0, 0, 0, 0,
  246. "minimum accepted time to live for a record, in seconds"},
  247. {"dns_cache_max_ttl", CFG_VAR_INT, 0, 0, 0, 0,
  248. "maximum accepted time to live for a record, in seconds"},
  249. {"dns_cache_mem", CFG_VAR_INT, 0, 0, dns_cache_max_mem_fixup, 0,
  250. "maximum memory used for the dns cache in Kb"},
  251. {"dns_cache_del_nonexp", CFG_VAR_INT, 0, 1, 0, 0,
  252. "allow deletion of non-expired records from the cache when "
  253. "there is no more space left for new ones"},
  254. {"dns_cache_rec_pref", CFG_VAR_INT, 0, 3, 0, 0,
  255. "DNS cache record preference: "
  256. " 0 - do not check duplicates"
  257. " 1 - prefer old records"
  258. " 2 - prefer new records"
  259. " 3 - prefer records with longer lifetime"},
  260. #endif
  261. #ifdef PKG_MALLOC
  262. {"mem_dump_pkg", CFG_VAR_INT, 0, 0, 0, mem_dump_pkg_cb,
  263. "dump process memory status, parameter: pid_number"},
  264. #endif
  265. #ifdef SHM_MEM
  266. {"mem_dump_shm", CFG_VAR_INT, 0, 0, mem_dump_shm_fixup, 0,
  267. "dump shared memory status"},
  268. #endif
  269. {"max_while_loops", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  270. "maximum iterations allowed for a while loop" },
  271. {"udp_mtu", CFG_VAR_INT|CFG_ATOMIC, 0, 65535, 0, 0,
  272. "fallback to a congestion controlled protocol if send size"
  273. " exceeds udp_mtu"},
  274. {"udp_mtu_try_proto", CFG_VAR_INT, 1, 4, 0, fix_global_req_flags,
  275. "if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
  276. {"udp4_raw", CFG_VAR_INT | CFG_ATOMIC, -1, 1, check_raw_sock_support, 0,
  277. "enable/disable using a raw socket for sending UDP IPV4 packets."
  278. " Should be faster on multi-CPU linux running machines."},
  279. {"udp4_raw_mtu", CFG_VAR_INT | CFG_ATOMIC, 28, 65535, 0, 0,
  280. "set the MTU used when using raw sockets for udp sending."
  281. " This value will be used when deciding whether or not to fragment"
  282. " the packets."},
  283. {"udp4_raw_ttl", CFG_VAR_INT | CFG_ATOMIC, -1, 255, udp4_raw_ttl_fixup, 0,
  284. "set the IP TTL used when using raw sockets for udp sending."
  285. " -1 will use the same value as for normal udp sockets."},
  286. {"force_rport", CFG_VAR_INT, 0, 1, 0, fix_global_req_flags,
  287. "force rport for all the received messages" },
  288. {"memlog", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  289. "log level for memory status/summary information"},
  290. {"mem_summary", CFG_VAR_INT|CFG_ATOMIC, 0, 31, 0, 0,
  291. "memory debugging information displayed on exit (flags): "
  292. " 0 - off,"
  293. " 1 - dump all the pkg used blocks (status),"
  294. " 2 - dump all the shm used blocks (status),"
  295. " 4 - summary of pkg used blocks,"
  296. " 8 - summary of shm used blocks,"
  297. " 16 - short status instead of dump" },
  298. {"mem_safety", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  299. "safety level for memory operations"},
  300. {"mem_join", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  301. "join free memory fragments"},
  302. {"corelog", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  303. "log level for non-critical core error messages"},
  304. {"latency_log", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  305. "log level for latency limits alert messages"},
  306. {"latency_limit_db", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  307. "limit is ms for alerting on time consuming db commands"},
  308. {"latency_limit_action", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
  309. "limit is ms for alerting on time consuming config actions"},
  310. {0, 0, 0, 0, 0, 0}
  311. };