• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

cfg_core.c

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2007 iptelorg GmbH
00005  *
00006  * This file is part of SIP-router, a free SIP server.
00007  *
00008  * SIP-router is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * SIP-router is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History
00023  * -------
00024  *  2007-12-03  Initial version (Miklos)
00025  *  2008-01-31  added DNS resolver parameters (Miklos)
00026  */
00047 #include "dprint.h"
00048 #ifdef USE_DST_BLACKLIST
00049 #include "dst_blacklist.h"
00050 #endif
00051 #include "resolve.h"
00052 #ifdef USE_DNS_CACHE
00053 #include "dns_cache.h"
00054 #endif
00055 #if defined PKG_MALLOC || defined SHM_MEM
00056 #include "pt.h"
00057 #endif
00058 #include "msg_translator.h" /* fix_global_req_flags() */
00059 #include "globals.h"
00060 #include "sock_ut.h"
00061 #include "cfg/cfg.h"
00062 #include "cfg_core.h"
00063 
00064 struct cfg_group_core default_core_cfg = {
00065         L_WARN,         
00066         LOG_DAEMON,     
00067         L_DBG,  
00068 #ifdef USE_DST_BLACKLIST
00069         /* blacklist */
00070         0, 
00071         DEFAULT_BLST_TIMEOUT,
00072         DEFAULT_BLST_MAX_MEM,
00073         0, /* blst_udp_imask */
00074         0, /* blst_tcp_imask */
00075         0, /* blst_tls_imask */
00076         0, /* blst_sctp_imask */
00077 #endif
00078         /* resolver */
00079 #ifdef USE_IPV6
00080         1,  
00081 #else
00082         0,  
00083 #endif
00084         0,  
00085         30,  
00086         20,  
00087         10,  
00088         20,  
00089         -1, 
00090         -1, 
00091         -1, 
00092         1,  
00093         1,  
00094         0,  
00095         /* DNS cache */
00096 #ifdef USE_DNS_CACHE
00097         1,  
00098         0,  
00099         0,  
00100         0,  
00101         DEFAULT_DNS_NEG_CACHE_TTL, 
00102         DEFAULT_DNS_CACHE_MIN_TTL, 
00103         DEFAULT_DNS_CACHE_MAX_TTL, 
00104         DEFAULT_DNS_MAX_MEM, 
00105         0, 
00106         0, 
00107 #endif
00108 #ifdef PKG_MALLOC
00109         0, 
00110 #endif
00111 #ifdef SHM_MEM
00112         0, 
00113 #endif
00114         DEFAULT_MAX_WHILE_LOOPS, 
00115         0, 
00116         0, 
00117         0, 
00118         1500, 
00119         -1,  
00120         0,  
00121         L_DBG, 
00122         3, 
00124         0, 
00125         0, 
00126         L_ERR, 
00127         L_ERR, 
00128         0, 
00129         0 
00130 };
00131 
00132 void    *core_cfg = &default_core_cfg;
00133 
00134 
00135 static int check_raw_sock_support(void* cfg_h, str* gname, str* name,
00136                                                                         void** v)
00137 {
00138         int val;
00139         
00140         val = (int)(long)(*v);
00141 #ifndef USE_RAW_SOCKS
00142         if (val > 0) {
00143                 ERR("no RAW_SOCKS support, please recompile with it enabled\n");
00144                 return -1;
00145         }
00146         return 0;
00147 #else /* USE_RAW_SOCKS */
00148         if (raw_udp4_send_sock < 0) {
00149                 if (val > 0) {
00150                         ERR("could not intialize raw socket on startup, please "
00151                                         "restart as root or with CAP_NET_RAW\n");
00152                         return -1;
00153                 } else if (val < 0) {
00154                         /* auto and no socket => disable */
00155                         *v = (void*)(long)0;
00156                 }
00157         } else if (val < 0) {
00158                 /* auto and socket => enable */
00159                 *v = (void*)(long)1;
00160         }
00161         return 0;
00162 #endif /* USE_RAW_SOCKS */
00163 }
00164 
00165 
00166 
00167 static int  udp4_raw_ttl_fixup(void* cfg_h, str* gname, str* name, void** val)
00168 {
00169         int v;
00170         v = (int)(long)(*val);
00171         if (v < 0) {
00172                 if (sendipv4)
00173                         v = sock_get_ttl(sendipv4->socket);
00174         }
00175         if (v < 0) {
00176                 /* some error => use a reasonable default */
00177                 v = 63;
00178         }
00179         *val = (void*)(long)v;
00180         return 0;
00181 }
00182 
00183 
00184 
00185 cfg_def_t core_cfg_def[] = {
00186         {"debug",               CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00187                 "debug level"},
00188         {"log_facility",        CFG_VAR_INT|CFG_INPUT_STRING,   0, 0, log_facility_fixup, 0,
00189                 "syslog facility, see \"man 3 syslog\""},
00190         {"memdbg",              CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00191                 "log level for memory debugging messages"},
00192 #ifdef USE_DST_BLACKLIST
00193         /* blacklist */
00194         {"use_dst_blacklist",   CFG_VAR_INT,    0, 1, use_dst_blacklist_fixup, 0,
00195                 "enable/disable destination blacklisting"},
00196         {"dst_blacklist_expire",        CFG_VAR_INT,    0, 0, 0, 0,
00197                 "how much time (in s) a blacklisted destination is kept in the list"},
00198         {"dst_blacklist_mem",   CFG_VAR_INT,    0, 0, blst_max_mem_fixup, 0,
00199                 "maximum shared memory amount (in KB) used for keeping the blacklisted"
00200                         " destinations"},
00201         {"dst_blacklist_udp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
00202                 "blacklist event ignore mask for UDP"},
00203         {"dst_blacklist_tcp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
00204                 "blacklist event ignore mask for TCP"},
00205         {"dst_blacklist_tls_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
00206                 "blacklist event ignore mask for TLS"},
00207         {"dst_blacklist_sctp_imask", CFG_VAR_INT, 0, 0, 0, blst_reinit_ign_masks,
00208                 "blacklist event ignore mask for SCTP"},
00209 #endif
00210         /* resolver */
00211 #ifdef USE_DNS_CACHE
00212         {"dns_try_ipv6",        CFG_VAR_INT,    0, 1, dns_try_ipv6_fixup, fix_dns_flags,
00213 #else
00214         {"dns_try_ipv6",        CFG_VAR_INT,    0, 1, dns_try_ipv6_fixup, 0,
00215 #endif
00216                 "enable/disable IPv6 DNS lookups"},
00217 #ifdef USE_DNS_CACHE
00218         {"dns_try_naptr",       CFG_VAR_INT,    0, 1, 0, fix_dns_flags,
00219 #else
00220         {"dns_try_naptr",       CFG_VAR_INT,    0, 1, 0, 0,
00221 #endif
00222                 "enable/disable NAPTR DNS lookups"},
00223         {"dns_udp_pref",        CFG_VAR_INT,    0, 0, 0, reinit_naptr_proto_prefs,
00224                 "udp protocol preference when doing NAPTR lookups"},
00225         {"dns_tcp_pref",        CFG_VAR_INT,    0, 0, 0, reinit_naptr_proto_prefs,
00226                 "tcp protocol preference when doing NAPTR lookups"},
00227         {"dns_tls_pref",        CFG_VAR_INT,    0, 0, 0, reinit_naptr_proto_prefs,
00228                 "tls protocol preference when doing NAPTR lookups"},
00229         {"dns_sctp_pref",       CFG_VAR_INT,    0, 0, 0, reinit_naptr_proto_prefs,
00230                 "sctp protocol preference when doing NAPTR lookups"},
00231         {"dns_retr_time",       CFG_VAR_INT,    0, 0, 0, resolv_reinit,
00232                 "time in s before retrying a dns request"},
00233         {"dns_retr_no",         CFG_VAR_INT,    0, 0, 0, resolv_reinit,
00234                 "number of dns retransmissions before giving up"},
00235         {"dns_servers_no",      CFG_VAR_INT,    0, 0, 0, resolv_reinit,
00236                 "how many dns servers from the ones defined in "
00237                 "/etc/resolv.conf will be used"},
00238         {"dns_use_search_list", CFG_VAR_INT,    0, 1, 0, resolv_reinit,
00239                 "if set to 0, the search list in /etc/resolv.conf is ignored"},
00240         {"dns_search_full_match",       CFG_VAR_INT,    0, 1, 0, 0,
00241                 "enable/disable domain name checks against the search list "
00242                 "in DNS answers"},
00243         {"dns_reinit",          CFG_VAR_INT|CFG_INPUT_INT,      1, 1, dns_reinit_fixup,
00244                 resolv_reinit,
00245                 "set to 1 in order to reinitialize the DNS resolver"},
00246         /* DNS cache */
00247 #ifdef USE_DNS_CACHE
00248         {"use_dns_cache",       CFG_VAR_INT,    0, 1, use_dns_cache_fixup, 0,
00249                 "enable/disable the dns cache"},
00250         {"dns_cache_flags",     CFG_VAR_INT,    0, 4, 0, fix_dns_flags,
00251                 "dns cache specific resolver flags "
00252                 "(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},
00253         {"use_dns_failover",    CFG_VAR_INT,    0, 1, use_dns_failover_fixup, 0,
00254                 "enable/disable dns failover in case the destination "
00255                 "resolves to multiple ip addresses and/or multiple SRV records "
00256                 "(depends on use_dns_cache)"},
00257         {"dns_srv_lb",          CFG_VAR_INT,    0, 1, 0, fix_dns_flags,
00258                 "enable/disable load balancing to different srv records "
00259                 "of the same priority based on the srv records weights "
00260                 "(depends on dns_failover)"},
00261         {"dns_cache_negative_ttl",      CFG_VAR_INT,    0, 0, 0, 0,
00262                 "time to live for negative results (\"not found\") "
00263                 "in seconds. Use 0 to disable"},
00264         {"dns_cache_min_ttl",   CFG_VAR_INT,    0, 0, 0, 0,
00265                 "minimum accepted time to live for a record, in seconds"},
00266         {"dns_cache_max_ttl",   CFG_VAR_INT,    0, 0, 0, 0,
00267                 "maximum accepted time to live for a record, in seconds"},
00268         {"dns_cache_mem",       CFG_VAR_INT,    0, 0, dns_cache_max_mem_fixup, 0,
00269                 "maximum memory used for the dns cache in Kb"},
00270         {"dns_cache_del_nonexp",        CFG_VAR_INT,    0, 1, 0, 0,
00271                 "allow deletion of non-expired records from the cache when "
00272                 "there is no more space left for new ones"},
00273         {"dns_cache_rec_pref",  CFG_VAR_INT,    0, 3, 0, 0,
00274                 "DNS cache record preference: "
00275                 " 0 - do not check duplicates"
00276                 " 1 - prefer old records"
00277                 " 2 - prefer new records"
00278                 " 3 - prefer records with longer lifetime"},
00279 #endif
00280 #ifdef PKG_MALLOC
00281         {"mem_dump_pkg",        CFG_VAR_INT,    0, 0, 0, mem_dump_pkg_cb,
00282                 "dump process memory status, parameter: pid_number"},
00283 #endif
00284 #ifdef SHM_MEM
00285         {"mem_dump_shm",        CFG_VAR_INT,    0, 0, mem_dump_shm_fixup, 0,
00286                 "dump shared memory status"},
00287 #endif
00288         {"max_while_loops",     CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00289                 "maximum iterations allowed for a while loop" },
00290         {"udp_mtu",     CFG_VAR_INT|CFG_ATOMIC, 0, 65535, 0, 0,
00291                 "fallback to a congestion controlled protocol if send size"
00292                         " exceeds udp_mtu"},
00293         {"udp_mtu_try_proto", CFG_VAR_INT, 1, 4, 0, fix_global_req_flags,
00294                 "if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
00295         {"udp4_raw", CFG_VAR_INT | CFG_ATOMIC, -1, 1, check_raw_sock_support, 0,
00296                 "enable/disable using a raw socket for sending UDP IPV4 packets."
00297                 " Should be  faster on multi-CPU linux running machines."},
00298         {"udp4_raw_mtu", CFG_VAR_INT | CFG_ATOMIC, 28, 65535, 0, 0,
00299                 "set the MTU used when using raw sockets for udp sending."
00300                 " This  value will be used when deciding whether or not to fragment"
00301                 " the packets."},
00302         {"udp4_raw_ttl", CFG_VAR_INT | CFG_ATOMIC, -1, 255, udp4_raw_ttl_fixup, 0,
00303                 "set the IP TTL used when using raw sockets for udp sending."
00304                 " -1 will use the same value as for normal udp sockets."},
00305         {"force_rport",     CFG_VAR_INT, 0, 1,  0, fix_global_req_flags,
00306                 "force rport for all the received messages" },
00307         {"memlog",              CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00308                 "log level for memory status/summary information"},
00309         {"mem_summary", CFG_VAR_INT|CFG_ATOMIC, 0, 31, 0, 0,
00310                 "memory debugging information displayed on exit (flags): "
00311                 " 0 - off,"
00312                 " 1 - dump all the pkg used blocks (status),"
00313                 " 2 - dump all the shm used blocks (status),"
00314                 " 4 - summary of pkg used blocks,"
00315                 " 8 - summary of shm used blocks,"
00316                 " 16 - short status instead of dump" },
00317         {"mem_safety",          CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00318                 "safety level for memory operations"},
00319         {"mem_join",            CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00320                 "join free memory fragments"},
00321         {"corelog",             CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00322                 "log level for non-critical core error messages"},
00323         {"latency_log",         CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00324                 "log level for latency limits alert messages"},
00325         {"latency_limit_db",            CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00326                 "limit is ms for alerting on time consuming db commands"},
00327         {"latency_limit_action",                CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
00328                 "limit is ms for alerting on time consuming config actions"},
00329         {0, 0, 0, 0, 0, 0}
00330 };

Generated on Tue May 22 2012 13:10:03 for SIP Router by  doxygen 1.7.1