* 2007-08-17 dns_cache_del_nonexp config option is introduced (Miklos)
* 2008-02-04 DNS cache options are adapted for the configuration
* framework (Miklos)
+ * 2008-02-11 dns_cache_init cfg parameter is introduced (Miklos)
*/
#ifdef USE_DNS_CACHE
#define MAX_CNAME_CHAIN 10
#define SPACE_FORMAT " " /* format of view output */
-
+int dns_cache_init=1; /* if 0, the DNS cache is not initialized at startup */
static gen_lock_t* dns_hash_lock=0;
static volatile unsigned int *dns_cache_mem_used=0; /* current mem. use */
unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
*/
int use_dns_failover_fixup(void *handle, str *name, void **val)
{
- if ((int)(long)(*val) && !use_dns_cache) {
+ if ((int)(long)(*val) && !cfg_get(core, handle, use_dns_cache)) {
LOG(L_ERR, "ERROR: use_dns_failover_fixup(): "
"DNS cache is turned off, failover cannot be enabled. "
"(set use_dns_cache to 1)\n");
return 0;
}
+/* fixup function for use_dns_cache
+ * verifies that dns_cache_init is set to 1
+ */
+int use_dns_cache_fixup(void *handle, str *name, void **val)
+{
+ if ((int)(long)(*val) && !dns_cache_init) {
+ LOG(L_ERR, "ERROR: use_dns_cache_fixup(): "
+ "DNS cache is turned off by dns_cache_init=0, "
+ "it cannot be enabled runtime.\n");
+ return -1;
+ }
+ if (((int)(long)(*val)==0) && cfg_get(core, handle, use_dns_failover)) {
+ LOG(L_ERR, "ERROR: use_dns_failover_fixup(): "
+ "DNS failover depends on use_dns_cache, set use_dns_failover "
+ "to 0 before disabling the DNS cache\n");
+ return -1;
+ }
+ return 0;
+}
+
/* KByte to Byte conversion */
int dns_cache_max_mem_fixup(void *handle, str *name, void **val)
{
int r;
int ret;
+ if (dns_cache_init==0) {
+ /* the DNS cache is turned off */
+ default_core_cfg.use_dns_cache=0;
+ default_core_cfg.use_dns_failover=0;
+ return 0;
+ }
+
ret=0;
/* sanity check */
if (E_DNS_CRITICAL>=sizeof(dns_str_errors)/sizeof(char*)){
/* fix options */
default_core_cfg.dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
+ if (default_core_cfg.use_dns_cache==0)
+ default_core_cfg.use_dns_failover=0; /* cannot work w/o dns_cache support */
/* fix flags */
fix_dns_flags(NULL);
}
#ifdef USE_DNS_CACHE_STATS
-int init_dns_cache_stats(int iproc_num) {
+int init_dns_cache_stats(int iproc_num)
+{
+ /* do not initialize the stats array if the DNS cache will not be used */
+ if (dns_cache_init==0) return 0;
+
/* if it is already initialized */
if (dns_cache_stats)
shm_free(dns_cache_stats);
{
str host;
- if ((use_dns_cache==0) || (dns_hash==0)){ /* not init yet */
+ if ((cfg_get(core, core_cfg, use_dns_cache)==0) || (dns_hash==0)){ /* not init yet */
return _resolvehost(name);
}
host.s=name;
struct ip_addr ip;
int ret;
- if ((use_dns_cache==0) || (dns_hash==0)){
+ if ((cfg_get(core, core_cfg, use_dns_cache==0)) || (dns_hash==0)){
/* not init or off => use normal, non-cached version */
return _sip_resolvehost(name, port, proto);
}
str srv_name;
char srv_proto;
- if ((use_dns_cache==0) || (dns_hash==0)){
+ if ((cfg_get(core, core_cfg, use_dns_cache)==0) || (dns_hash==0)){
/* not init or off => use normal, non-cached version */
return _sip_resolvehost(name, port, proto);
}
/* rpc functions */
void dns_cache_mem_info(rpc_t* rpc, void* ctx)
{
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
struct dns_hash_entry* e;
ticks_t now;
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
};
- if (!use_dns_cache) {
+ if (!cfg_get(core, core_cfg, use_dns_cache)) {
rpc->fault(c, 500, "dns cache support disabled");
return;
}
int i;
ticks_t now;
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
ticks_t now;
str s;
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
/* deletes all the entries from the cache */
void dns_cache_delete_all(rpc_t* rpc, void* ctx)
{
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
ip_addr = 0;
size = 0;
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
str name;
int err, h, found=0;
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
{
int state;
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}
/* prints the DNS server state */
void dns_get_server_state_rpc(rpc_t* rpc, void* ctx)
{
- if (!use_dns_cache){
+ if (!cfg_get(core, core_cfg, use_dns_cache)){
rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
return;
}