瀏覽代碼

- use_dns_cache can be enabled/disabled runtime
- dns_cache_init is introduced: if set to 0, the dns cache is not
initialized, and cannot be enabled later (default is 1)
- dst_blacklist_init is introduced: if set to 0, the dst blacklist is
not initialized (similar to dns_cache_init) (default is 1)

Miklos Tirpak 17 年之前
父節點
當前提交
7905e2d6ed
共有 13 個文件被更改,包括 118 次插入25 次删除
  1. 7 0
      NEWS
  2. 6 0
      cfg.lex
  3. 7 1
      cfg.y
  4. 4 1
      cfg_core.c
  5. 1 0
      cfg_core.h
  6. 50 16
      dns_cache.c
  7. 1 0
      dns_cache.h
  8. 3 0
      doc/dns.txt
  9. 3 0
      doc/dst_blacklist.txt
  10. 32 0
      dst_blacklist.c
  11. 1 0
      dst_blacklist.h
  12. 2 1
      globals.h
  13. 1 6
      main.c

+ 7 - 0
NEWS

@@ -197,6 +197,13 @@ new config variables:
   tcp_source_ipv6 = IPv6 address
   tcp_source_ipv6 = IPv6 address
     Set the given source IP for all outbound TCP connections.
     Set the given source IP for all outbound TCP connections.
     If setting the IP fails the TCP connection will use the default.
     If setting the IP fails the TCP connection will use the default.
+  dns_cache_init = on | off (default on) - if off, the dns cache is not
+    initialized at startup and cannot be enabled runtime, that saves some
+    memory.
+  dst_blacklist_init = on | off (default on) - if off, the blacklist
+    is not initialized at startup and cannot be enabled runtime,
+    that saves some memory.
+
 
 
 
 
 2.0.0 changes
 2.0.0 changes

+ 6 - 0
cfg.lex

@@ -250,6 +250,7 @@ DNS_SERVERS_NO	dns_servers_no
 DNS_USE_SEARCH	dns_use_search_list
 DNS_USE_SEARCH	dns_use_search_list
 DNS_SEARCH_FMATCH	dns_search_full_match
 DNS_SEARCH_FMATCH	dns_search_full_match
 /* dns cache */
 /* dns cache */
+DNS_CACHE_INIT	dns_cache_init
 DNS_USE_CACHE	use_dns_cache
 DNS_USE_CACHE	use_dns_cache
 DNS_USE_FAILOVER	use_dns_failover
 DNS_USE_FAILOVER	use_dns_failover
 DNS_CACHE_FLAGS		dns_cache_flags
 DNS_CACHE_FLAGS		dns_cache_flags
@@ -260,6 +261,7 @@ DNS_CACHE_MEM		dns_cache_mem
 DNS_CACHE_GC_INT	dns_cache_gc_interval
 DNS_CACHE_GC_INT	dns_cache_gc_interval
 DNS_CACHE_DEL_NONEXP	dns_cache_del_nonexp|dns_cache_delete_nonexpired
 DNS_CACHE_DEL_NONEXP	dns_cache_del_nonexp|dns_cache_delete_nonexpired
 /* blacklist */
 /* blacklist */
+DST_BLST_INIT	dst_blacklist_init
 USE_DST_BLST		use_dst_blacklist
 USE_DST_BLST		use_dst_blacklist
 DST_BLST_MEM		dst_blacklist_mem
 DST_BLST_MEM		dst_blacklist_mem
 DST_BLST_TTL		dst_blacklist_expire|dst_blacklist_ttl
 DST_BLST_TTL		dst_blacklist_expire|dst_blacklist_ttl
@@ -506,6 +508,8 @@ EAT_ABLE	[\ \t\b\r]
 								return DNS_USE_SEARCH; }
 								return DNS_USE_SEARCH; }
 <INITIAL>{DNS_SEARCH_FMATCH}	{ count(); yylval.strval=yytext;
 <INITIAL>{DNS_SEARCH_FMATCH}	{ count(); yylval.strval=yytext;
 								return DNS_SEARCH_FMATCH; }
 								return DNS_SEARCH_FMATCH; }
+<INITIAL>{DNS_CACHE_INIT}	{ count(); yylval.strval=yytext;
+								return DNS_CACHE_INIT; }
 <INITIAL>{DNS_USE_CACHE}	{ count(); yylval.strval=yytext;
 <INITIAL>{DNS_USE_CACHE}	{ count(); yylval.strval=yytext;
 								return DNS_USE_CACHE; }
 								return DNS_USE_CACHE; }
 <INITIAL>{DNS_USE_FAILOVER}	{ count(); yylval.strval=yytext;
 <INITIAL>{DNS_USE_FAILOVER}	{ count(); yylval.strval=yytext;
@@ -524,6 +528,8 @@ EAT_ABLE	[\ \t\b\r]
 								return DNS_CACHE_GC_INT; }
 								return DNS_CACHE_GC_INT; }
 <INITIAL>{DNS_CACHE_DEL_NONEXP}	{ count(); yylval.strval=yytext;
 <INITIAL>{DNS_CACHE_DEL_NONEXP}	{ count(); yylval.strval=yytext;
 								return DNS_CACHE_DEL_NONEXP; }
 								return DNS_CACHE_DEL_NONEXP; }
+<INITIAL>{DST_BLST_INIT}	{ count(); yylval.strval=yytext;
+								return DST_BLST_INIT; }
 <INITIAL>{USE_DST_BLST}	{ count(); yylval.strval=yytext;
 <INITIAL>{USE_DST_BLST}	{ count(); yylval.strval=yytext;
 								return USE_DST_BLST; }
 								return USE_DST_BLST; }
 <INITIAL>{DST_BLST_MEM}	{ count(); yylval.strval=yytext;
 <INITIAL>{DST_BLST_MEM}	{ count(); yylval.strval=yytext;

+ 7 - 1
cfg.y

@@ -292,6 +292,7 @@ static struct socket_id* mk_listen_id(char*, int, int);
 %token DNS_SERVERS_NO
 %token DNS_SERVERS_NO
 %token DNS_USE_SEARCH
 %token DNS_USE_SEARCH
 %token DNS_SEARCH_FMATCH
 %token DNS_SEARCH_FMATCH
+%token DNS_CACHE_INIT
 %token DNS_USE_CACHE
 %token DNS_USE_CACHE
 %token DNS_USE_FAILOVER
 %token DNS_USE_FAILOVER
 %token DNS_CACHE_FLAGS
 %token DNS_CACHE_FLAGS
@@ -302,6 +303,7 @@ static struct socket_id* mk_listen_id(char*, int, int);
 %token DNS_CACHE_GC_INT
 %token DNS_CACHE_GC_INT
 %token DNS_CACHE_DEL_NONEXP
 %token DNS_CACHE_DEL_NONEXP
 /*blacklist*/
 /*blacklist*/
+%token DST_BLST_INIT
 %token USE_DST_BLST
 %token USE_DST_BLST
 %token DST_BLST_MEM
 %token DST_BLST_MEM
 %token DST_BLST_TTL
 %token DST_BLST_TTL
@@ -630,7 +632,9 @@ assign_stm:
 	| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
 	| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
 	| DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
 	| DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
 	| DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
 	| DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
-	| DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(use_dns_cache=$3); }
+	| DNS_CACHE_INIT EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_init=$3); }
+	| DNS_CACHE_INIT error { yyerror("boolean value expected"); }
+	| DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.use_dns_cache=$3); }
 	| DNS_USE_CACHE error { yyerror("boolean value expected"); }
 	| DNS_USE_CACHE error { yyerror("boolean value expected"); }
 	| DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
 	| DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
 	| DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
 	| DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
@@ -648,6 +652,8 @@ assign_stm:
 	| DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
 	| DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
 	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
 	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
 	| DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
 	| DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
+	| DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
+	| DST_BLST_INIT error { yyerror("boolean value expected"); }
 	| USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3); }
 	| USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3); }
 	| USE_DST_BLST error { yyerror("boolean value expected"); }
 	| USE_DST_BLST error { yyerror("boolean value expected"); }
 	| DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); }
 	| DST_BLST_MEM EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); }

+ 4 - 1
cfg_core.c

@@ -67,6 +67,7 @@ struct cfg_group_core default_core_cfg = {
 	0,  /* dns_reinit */
 	0,  /* dns_reinit */
 	/* DNS cache */
 	/* DNS cache */
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
+	1,  /* use_dns_cache -- on by default */
 	0,  /* dns_cache_flags */
 	0,  /* dns_cache_flags */
 	0,  /* use_dns_failover -- off by default */
 	0,  /* use_dns_failover -- off by default */
 	0,  /* dns_srv_lb -- off by default */
 	0,  /* dns_srv_lb -- off by default */
@@ -84,7 +85,7 @@ cfg_def_t core_cfg_def[] = {
 	{"debug",	CFG_VAR_INT,	0, 0, 0, 0, "debug level"},
 	{"debug",	CFG_VAR_INT,	0, 0, 0, 0, "debug level"},
 #ifdef USE_DST_BLACKLIST
 #ifdef USE_DST_BLACKLIST
 	/* blacklist */
 	/* blacklist */
-	{"use_dst_blacklist",	CFG_VAR_INT,	0, 0, 0, 0,
+	{"use_dst_blacklist",	CFG_VAR_INT,	0, 1, use_dst_blacklist_fixup, 0,
 		"enable/disable destination blacklisting"},
 		"enable/disable destination blacklisting"},
 	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
 	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
 		"how much time (in s) a blacklisted destination is kept in the list"},
 		"how much time (in s) a blacklisted destination is kept in the list"},
@@ -126,6 +127,8 @@ cfg_def_t core_cfg_def[] = {
 		"set to 1 in order to reinitialize the DNS resolver"},
 		"set to 1 in order to reinitialize the DNS resolver"},
 	/* DNS cache */
 	/* DNS cache */
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
+	{"use_dns_cache",	CFG_VAR_INT,	0, 1, use_dns_cache_fixup, 0,
+		"enable/disable the dns cache"},
 	{"dns_cache_flags",	CFG_VAR_INT,	0, 4, 0, fix_dns_flags,
 	{"dns_cache_flags",	CFG_VAR_INT,	0, 4, 0, fix_dns_flags,
 		"dns cache specific resolver flags "
 		"dns cache specific resolver flags "
 		"(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},
 		"(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},

+ 1 - 0
cfg_core.h

@@ -67,6 +67,7 @@ struct cfg_group_core {
 	int dns_reinit;
 	int dns_reinit;
 	/* DNS cache */
 	/* DNS cache */
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
+	int use_dns_cache;
 	int dns_cache_flags;
 	int dns_cache_flags;
 	int use_dns_failover;
 	int use_dns_failover;
 	int dns_srv_lb;
 	int dns_srv_lb;

+ 50 - 16
dns_cache.c

@@ -41,6 +41,7 @@
  *  2007-08-17  dns_cache_del_nonexp config option is introduced (Miklos)
  *  2007-08-17  dns_cache_del_nonexp config option is introduced (Miklos)
  *  2008-02-04  DNS cache options are adapted for the configuration
  *  2008-02-04  DNS cache options are adapted for the configuration
  *		framework (Miklos)
  *		framework (Miklos)
+ *  2008-02-11  dns_cache_init cfg parameter is introduced (Miklos)
  */
  */
 
 
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
@@ -87,7 +88,7 @@
 #define MAX_CNAME_CHAIN  10
 #define MAX_CNAME_CHAIN  10
 #define SPACE_FORMAT "    " /* format of view output */
 #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 gen_lock_t* dns_hash_lock=0;
 static volatile unsigned int *dns_cache_mem_used=0; /* current mem. use */
 static volatile unsigned int *dns_cache_mem_used=0; /* current mem. use */
 unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
 unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
@@ -299,7 +300,7 @@ void fix_dns_flags(str *name)
  */
  */
 int use_dns_failover_fixup(void *handle, str *name, void **val)
 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(): "
 		LOG(L_ERR, "ERROR: use_dns_failover_fixup(): "
 			"DNS cache is turned off, failover cannot be enabled. "
 			"DNS cache is turned off, failover cannot be enabled. "
 			"(set use_dns_cache to 1)\n");
 			"(set use_dns_cache to 1)\n");
@@ -308,6 +309,26 @@ int use_dns_failover_fixup(void *handle, str *name, void **val)
 	return 0;
 	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 */
 /* KByte to Byte conversion */
 int dns_cache_max_mem_fixup(void *handle, str *name, void **val)
 int dns_cache_max_mem_fixup(void *handle, str *name, void **val)
 {
 {
@@ -323,6 +344,13 @@ int init_dns_cache()
 	int r;
 	int r;
 	int ret;
 	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;
 	ret=0;
 	/* sanity check */
 	/* sanity check */
 	if (E_DNS_CRITICAL>=sizeof(dns_str_errors)/sizeof(char*)){
 	if (E_DNS_CRITICAL>=sizeof(dns_str_errors)/sizeof(char*)){
@@ -374,6 +402,8 @@ int init_dns_cache()
 
 
 	/* fix options */
 	/* fix options */
 	default_core_cfg.dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
 	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 flags */
 	fix_dns_flags(NULL);
 	fix_dns_flags(NULL);
 
 
@@ -399,7 +429,11 @@ error:
 }
 }
 
 
 #ifdef USE_DNS_CACHE_STATS
 #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 it is already initialized */
 	if (dns_cache_stats)
 	if (dns_cache_stats)
 		shm_free(dns_cache_stats);
 		shm_free(dns_cache_stats);
@@ -2225,7 +2259,7 @@ struct hostent* dns_resolvehost(char* name)
 {
 {
 	str host;
 	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);
 		return _resolvehost(name);
 	}
 	}
 	host.s=name;
 	host.s=name;
@@ -2250,7 +2284,7 @@ struct hostent* dns_sip_resolvehost(str* name, unsigned short* port,
 	struct ip_addr ip;
 	struct ip_addr ip;
 	int ret;
 	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 */
 		/* not init or off => use normal, non-cached version */
 		return _sip_resolvehost(name, port, proto);
 		return _sip_resolvehost(name, port, proto);
 	}
 	}
@@ -2282,7 +2316,7 @@ struct hostent* dns_srv_sip_resolvehost(str* name, unsigned short* port,
 	str srv_name;
 	str srv_name;
 	char srv_proto;
 	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 */
 		/* not init or off => use normal, non-cached version */
 		return _sip_resolvehost(name, port, proto);
 		return _sip_resolvehost(name, port, proto);
 	}
 	}
@@ -3172,7 +3206,7 @@ int dns_get_server_state(void)
 /* rpc functions */
 /* rpc functions */
 void dns_cache_mem_info(rpc_t* rpc, void* ctx)
 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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3186,7 +3220,7 @@ void dns_cache_debug(rpc_t* rpc, void* ctx)
 	struct dns_hash_entry* e;
 	struct dns_hash_entry* e;
 	ticks_t now;
 	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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3255,7 +3289,7 @@ void dns_cache_stats_get(rpc_t* rpc, void* c)
 	};
 	};
 
 
 
 
-	if (!use_dns_cache) {
+	if (!cfg_get(core, core_cfg, use_dns_cache)) {
 		rpc->fault(c, 500, "dns cache support disabled");
 		rpc->fault(c, 500, "dns cache support disabled");
 		return;
 		return;
 	}
 	}
@@ -3300,7 +3334,7 @@ void dns_cache_debug_all(rpc_t* rpc, void* ctx)
 	int i;
 	int i;
 	ticks_t now;
 	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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3380,7 +3414,7 @@ void dns_cache_view(rpc_t* rpc, void* ctx)
 	ticks_t now;
 	ticks_t now;
 	str s;
 	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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3488,7 +3522,7 @@ void dns_cache_flush(void)
 /* deletes all the entries from the cache */
 /* deletes all the entries from the cache */
 void dns_cache_delete_all(rpc_t* rpc, void* ctx)
 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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3637,7 +3671,7 @@ static void dns_cache_add_record(rpc_t* rpc, void* ctx, unsigned short type)
 	ip_addr = 0;
 	ip_addr = 0;
 	size = 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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3844,7 +3878,7 @@ static void dns_cache_delete_record(rpc_t* rpc, void* ctx, unsigned short type)
 	str name;
 	str name;
 	int err, h, found=0;
 	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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3911,7 +3945,7 @@ void dns_set_server_state_rpc(rpc_t* rpc, void* ctx)
 {
 {
 	int	state;
 	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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}
@@ -3923,7 +3957,7 @@ void dns_set_server_state_rpc(rpc_t* rpc, void* ctx)
 /* prints the DNS server state */
 /* prints the DNS server state */
 void dns_get_server_state_rpc(rpc_t* rpc, void* ctx)
 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)");
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
 		return;
 		return;
 	}
 	}

+ 1 - 0
dns_cache.h

@@ -180,6 +180,7 @@ const char* dns_strerror(int err);
 
 
 void fix_dns_flags(str *name);
 void fix_dns_flags(str *name);
 int use_dns_failover_fixup(void *handle, str *name, void **val);
 int use_dns_failover_fixup(void *handle, str *name, void **val);
+int use_dns_cache_fixup(void *handle, str *name, void **val);
 int dns_cache_max_mem_fixup(void *handle, str *name, void **val);
 int dns_cache_max_mem_fixup(void *handle, str *name, void **val);
 int init_dns_cache();
 int init_dns_cache();
 #ifdef USE_DNS_CACHE_STATS
 #ifdef USE_DNS_CACHE_STATS

+ 3 - 0
doc/dns.txt

@@ -258,6 +258,9 @@ DNS Cache and Failover Config Variables
       ones. The last-recently used entries are deleted first.
       ones. The last-recently used entries are deleted first.
       Default: no
       Default: no
 
 
+   dns_cache_init = on | off - if off, the dns cache is not initialized
+      at startup and cannot be enabled runtime, that saves some memory.
+      Default: on
 
 
 DNS Cache Compile Options
 DNS Cache Compile Options
 
 

+ 3 - 0
doc/dst_blacklist.txt

@@ -55,6 +55,9 @@ Config Variables
  dst_blacklist_gc_interval = time in s (default 60 s) - how often the 
  dst_blacklist_gc_interval = time in s (default 60 s) - how often the 
   garbage collection will run (eliminating old, expired entries).
   garbage collection will run (eliminating old, expired entries).
 
 
+ dst_blacklist_init = on | off (default on) - if off, the blacklist
+  is not initialized at startup and cannot be enabled runtime,
+  that saves some memory.
 
 
 Compile Options
 Compile Options
 
 

+ 32 - 0
dst_blacklist.c

@@ -33,6 +33,7 @@
  *  2007-06-26  added hooks for search (andrei)
  *  2007-06-26  added hooks for search (andrei)
  *  2007-07-30  added dst_blacklist_del() and dst_blacklist_add_to()  (andrei)
  *  2007-07-30  added dst_blacklist_del() and dst_blacklist_add_to()  (andrei)
  *  2007-07-30  dst blacklist measurements added (Gergo)
  *  2007-07-30  dst blacklist measurements added (Gergo)
+ *  2008-02-11  dns_blacklist_init cfg parameter is introduced (Miklos)
  */
  */
 
 
 
 
@@ -123,6 +124,7 @@ struct dst_blst_lst_head{
 #endif
 #endif
 };
 };
 
 
+int dst_blacklist_init=1; /* if 0, the dst blacklist is not initialized at startup */
 static struct timer_ln* blst_timer_h=0;
 static struct timer_ln* blst_timer_h=0;
 
 
 static volatile unsigned int* blst_mem_used=0;
 static volatile unsigned int* blst_mem_used=0;
@@ -226,6 +228,12 @@ int register_blacklist_hook(struct blacklist_hook *h, int type)
 	struct blacklist_hook* tmp;
 	struct blacklist_hook* tmp;
 	int new_max_hooks;
 	int new_max_hooks;
 
 
+	if (dst_blacklist_init==0) {
+		LOG(L_ERR, "register_blacklist_hook: blacklist is turned off, "
+			"the hook cannot be registered\n");
+		goto error;
+	}
+
 	switch(type){
 	switch(type){
 		case DST_BLACKLIST_ADD_CB:
 		case DST_BLACKLIST_ADD_CB:
 			cb_lst=&blst_add_cb;
 			cb_lst=&blst_add_cb;
@@ -339,6 +347,7 @@ void destroy_dst_blacklist()
 		blst_timer_h=0;
 		blst_timer_h=0;
 	}
 	}
 #ifdef BLST_LOCK_PER_BUCKET
 #ifdef BLST_LOCK_PER_BUCKET
+	if (dst_blst_hash)
 		for(r=0; r<DST_BLST_HASH_SIZE; r++)
 		for(r=0; r<DST_BLST_HASH_SIZE; r++)
 			lock_destroy(&dst_blst_hash[r].lock);
 			lock_destroy(&dst_blst_hash[r].lock);
 #elif defined BLST_LOCK_SET
 #elif defined BLST_LOCK_SET
@@ -390,6 +399,12 @@ int init_dst_blacklist()
 	int r;
 	int r;
 #endif
 #endif
 
 
+	if (dst_blacklist_init==0) {
+		/* the dst blacklist is turned off */
+		default_core_cfg.use_dst_blacklist=0;
+		return 0;
+	}
+
 	ret=-1;
 	ret=-1;
 #ifdef DST_BLACKLIST_HOOKS
 #ifdef DST_BLACKLIST_HOOKS
 	if (init_blacklist_hooks()!=0){
 	if (init_blacklist_hooks()!=0){
@@ -468,6 +483,9 @@ error:
 #ifdef USE_DST_BLACKLIST_STATS
 #ifdef USE_DST_BLACKLIST_STATS
 int init_dst_blacklist_stats(int iproc_num)
 int init_dst_blacklist_stats(int iproc_num)
 {
 {
+	/* do not initialize the stats array if the dst blacklist will not be used */
+	if (dst_blacklist_init==0) return 0;
+
 	/* if it is already initialized */
 	/* if it is already initialized */
 	if (dst_blacklist_stats)
 	if (dst_blacklist_stats)
 		shm_free(dst_blacklist_stats);
 		shm_free(dst_blacklist_stats);
@@ -1095,6 +1113,20 @@ void dst_blst_add(rpc_t* rpc, void* ctx)
 		rpc->fault(ctx, 400, "Failed to add the entry to the blacklist");
 		rpc->fault(ctx, 400, "Failed to add the entry to the blacklist");
 }
 }
 
 
+/* fixup function for use_dst_blacklist
+ * verifies that dst_blacklist_init is set to 1
+ */
+int use_dst_blacklist_fixup(void *handle, str *name, void **val)
+{
+	if ((int)(long)(*val) && !dst_blacklist_init) {
+		LOG(L_ERR, "ERROR: use_dst_blacklist_fixup(): "
+			"dst blacklist is turned off by dst_blacklist_init=0, "
+			"it cannot be enabled runtime.\n");
+		return -1;
+	}
+	return 0;
+}
+
 /* KByte to Byte conversion */
 /* KByte to Byte conversion */
 int blst_max_mem_fixup(void *handle, str *name, void **val)
 int blst_max_mem_fixup(void *handle, str *name, void **val)
 {
 {

+ 1 - 0
dst_blacklist.h

@@ -103,6 +103,7 @@ int dst_blacklist_del(struct dest_info* si, struct sip_msg* msg);
  */
  */
 void dst_blst_flush(void);
 void dst_blst_flush(void);
 
 
+int use_dst_blacklist_fixup(void *handle, str *name, void **val);
 /* KByte to Byte conversion */
 /* KByte to Byte conversion */
 int blst_max_mem_fixup(void *handle, str *name, void **val);
 int blst_max_mem_fixup(void *handle, str *name, void **val);
 
 

+ 2 - 1
globals.h

@@ -191,7 +191,7 @@ extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
 
 
 
 
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
-extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
+extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
 extern unsigned int dns_timer_interval; /* gc timer interval in s */
 extern unsigned int dns_timer_interval; /* gc timer interval in s */
 extern int dns_flags; /* default flags used for the  dns_*resolvehost
 extern int dns_flags; /* default flags used for the  dns_*resolvehost
                     (compatibility wrappers) */
                     (compatibility wrappers) */
@@ -207,6 +207,7 @@ extern struct t_dns_cache_stats* dns_cache_stats;
 #endif /* USE_DNS_CACHE_STATS */
 #endif /* USE_DNS_CACHE_STATS */
 #endif
 #endif
 #ifdef USE_DST_BLACKLIST
 #ifdef USE_DST_BLACKLIST
+extern int dst_blacklist_init; /* if 0, the dst blacklist is not initialized at startup */
 extern unsigned int blst_timer_interval; /*blacklist gc timer interval (in s)*/
 extern unsigned int blst_timer_interval; /*blacklist gc timer interval (in s)*/
 
 
 #ifdef USE_DST_BLACKLIST_STATS
 #ifdef USE_DST_BLACKLIST_STATS

+ 1 - 6
main.c

@@ -371,9 +371,6 @@ int reply_to_via=0;
 int mcast_loopback = 0;
 int mcast_loopback = 0;
 int mcast_ttl = -1; /* if -1, don't touch it, use the default (usually 1) */
 int mcast_ttl = -1; /* if -1, don't touch it, use the default (usually 1) */
 #endif /* USE_MCAST */
 #endif /* USE_MCAST */
-#ifdef USE_DNS_CACHE
-int use_dns_cache=1; /* 1 if the cache is enabled, 0 otherwise */
-#endif
 
 
 int tos = IPTOS_LOWDELAY;
 int tos = IPTOS_LOWDELAY;
 int pmtu_discovery = 0;
 int pmtu_discovery = 0;
@@ -1652,12 +1649,10 @@ try_again:
 		goto error;
 		goto error;
 	}
 	}
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
-	if (use_dns_cache && init_dns_cache()<0){
+	if (init_dns_cache()<0){
 		LOG(L_CRIT, "could not initialize the dns cache, exiting...\n");
 		LOG(L_CRIT, "could not initialize the dns cache, exiting...\n");
 		goto error;
 		goto error;
 	}
 	}
-	if (use_dns_cache==0)
-		default_core_cfg.use_dns_failover=0; /* cannot work w/o dns_cache support */
 #ifdef USE_DNS_CACHE_STATS
 #ifdef USE_DNS_CACHE_STATS
 	/* preinitializing before the nubmer of processes is determined */
 	/* preinitializing before the nubmer of processes is determined */
 	if (init_dns_cache_stats(1)<0){
 	if (init_dns_cache_stats(1)<0){