Browse Source

DNS resolver and cache parameters use the configuration framework
that makes the config variables changeable on-the-fly.

- The resolver is reinitialized by each child process separately
when dns_retr_time, dns_retr_no, dns_servers_no, or dns_use_search_list
is changed.

- dns_reinit is introduced: the resolver is reinitialized when the
variable is set to 1, and the variable is reseted to 0 again.
It can be set via RPC for example, when /etc/resolv.conf changes,
but none of the SER config parameters are affected.

- A callback function is called by each child process after the resolver
has been reinitialized, if DNS_WATCHDOG_SUPPORT is enabled.

- socket_types is changed to be a global variable, and set by
fix_all_socket_lists(), because we have to remember for
the socket types, and do not allow dns_try_ipv6 to be enabled if there
is no ipv6 interface.

- minor bug is corrected: the expiration check is removed from
dns_cache_clean() function, when non-expired entries are deleted.

Miklos Tirpak 17 years ago
parent
commit
2cfcc6bb1b
18 changed files with 375 additions and 155 deletions
  1. 18 18
      cfg.y
  2. 95 0
      cfg_core.c
  3. 24 0
      cfg_core.h
  4. 82 50
      dns_cache.c
  5. 8 0
      dns_cache.h
  6. 4 3
      forward.c
  7. 0 15
      globals.h
  8. 4 6
      main.c
  9. 5 4
      modules/tm/t_fwd.c
  10. 2 1
      modules/tm/t_msgbuilder.c
  11. 9 2
      modules/tm/t_reply.c
  12. 2 1
      modules/tm/timer.c
  13. 5 1
      modules/tm/uac.c
  14. 2 1
      modules/tm/ut.h
  15. 85 33
      resolve.c
  16. 20 8
      resolve.h
  17. 8 11
      socket_info.c
  18. 2 1
      socket_info.h

+ 18 - 18
cfg.y

@@ -608,45 +608,45 @@ assign_stm:
 	| DNS EQUAL error { yyerror("boolean value expected"); }
 	| DNS EQUAL error { yyerror("boolean value expected"); }
 	| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
 	| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
 	| REV_DNS EQUAL error { yyerror("boolean value expected"); }
 	| REV_DNS EQUAL error { yyerror("boolean value expected"); }
-	| DNS_TRY_IPV6 EQUAL NUMBER   { dns_try_ipv6=$3; }
+	| DNS_TRY_IPV6 EQUAL NUMBER   { default_core_cfg.dns_try_ipv6=$3; }
 	| DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
 	| DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
-	| DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(dns_try_naptr=$3); }
+	| DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
 	| DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
 	| DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
-	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(dns_srv_lb=$3); }
+	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
 	| DNS_SRV_LB error { yyerror("boolean value expected"); }
 	| DNS_SRV_LB error { yyerror("boolean value expected"); }
-	| DNS_UDP_PREF EQUAL NUMBER   { IF_NAPTR(dns_udp_pref=$3); }
+	| DNS_UDP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_udp_pref=$3); }
 	| DNS_UDP_PREF error { yyerror("number expected"); }
 	| DNS_UDP_PREF error { yyerror("number expected"); }
-	| DNS_TCP_PREF EQUAL NUMBER   { IF_NAPTR(dns_tcp_pref=$3); }
+	| DNS_TCP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3); }
 	| DNS_TCP_PREF error { yyerror("number expected"); }
 	| DNS_TCP_PREF error { yyerror("number expected"); }
-	| DNS_TLS_PREF EQUAL NUMBER   { IF_NAPTR(dns_tls_pref=$3); }
+	| DNS_TLS_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tls_pref=$3); }
 	| DNS_TLS_PREF error { yyerror("number expected"); }
 	| DNS_TLS_PREF error { yyerror("number expected"); }
-	| DNS_RETR_TIME EQUAL NUMBER   { dns_retr_time=$3; }
+	| DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
 	| DNS_RETR_TIME error { yyerror("number expected"); }
 	| DNS_RETR_TIME error { yyerror("number expected"); }
-	| DNS_RETR_NO EQUAL NUMBER   { dns_retr_no=$3; }
+	| DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
 	| DNS_RETR_NO error { yyerror("number expected"); }
 	| DNS_RETR_NO error { yyerror("number expected"); }
-	| DNS_SERVERS_NO EQUAL NUMBER   { dns_servers_no=$3; }
+	| DNS_SERVERS_NO EQUAL NUMBER   { default_core_cfg.dns_servers_no=$3; }
 	| DNS_SERVERS_NO error { yyerror("number expected"); }
 	| DNS_SERVERS_NO error { yyerror("number expected"); }
-	| DNS_USE_SEARCH EQUAL NUMBER   { dns_search_list=$3; }
+	| DNS_USE_SEARCH EQUAL NUMBER   { default_core_cfg.dns_search_list=$3; }
 	| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
 	| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
-	| DNS_SEARCH_FMATCH EQUAL NUMBER   { 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_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(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(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"); }
-	| DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(dns_flags=$3); }
+	| DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
 	| DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
 	| DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
-	| DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(dns_neg_cache_ttl=$3); }
+	| DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
 	| DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
 	| DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
-	| DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_max_ttl=$3); }
+	| DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
 	| DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
 	| DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
-	| DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_min_ttl=$3); }
+	| DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
 	| DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
 	| DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
-	| DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_max_mem=$3); }
+	| DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
 	| DNS_CACHE_MEM error { yyerror("boolean value expected"); }
 	| DNS_CACHE_MEM error { yyerror("boolean value expected"); }
 	| DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
 	| DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
 	| 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(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"); }
 	| 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"); }

+ 95 - 0
cfg_core.c

@@ -27,19 +27,54 @@
  * History
  * History
  * -------
  * -------
  *  2007-12-03	Initial version (Miklos)
  *  2007-12-03	Initial version (Miklos)
+ *  2008-01-31  added DNS resolver parameters (Miklos)
  */
  */
 
 
 #include "dprint.h"
 #include "dprint.h"
+#ifdef USE_DST_BLACKLIST
 #include "dst_blacklist.h"
 #include "dst_blacklist.h"
+#endif
+#include "resolve.h"
+#ifdef USE_DNS_CACHE
+#include "dns_cache.h"
+#endif
 #include "cfg/cfg.h"
 #include "cfg/cfg.h"
 #include "cfg_core.h"
 #include "cfg_core.h"
 
 
 struct cfg_group_core default_core_cfg = {
 struct cfg_group_core default_core_cfg = {
 	L_DEFAULT, /*  print only msg. < L_WARN */
 	L_DEFAULT, /*  print only msg. < L_WARN */
 #ifdef USE_DST_BLACKLIST
 #ifdef USE_DST_BLACKLIST
+	/* blacklist */
 	0, /* dst blacklist is disabled by default */
 	0, /* dst blacklist is disabled by default */
 	DEFAULT_BLST_TIMEOUT,
 	DEFAULT_BLST_TIMEOUT,
 	DEFAULT_BLST_MAX_MEM,
 	DEFAULT_BLST_MAX_MEM,
+#endif
+	/* resolver */
+#ifdef USE_IPV6
+	1,  /* dns_try_ipv6 -- on by default */
+#else
+	0,  /* dns_try_ipv6 -- off, if no ipv6 support */
+#endif
+	0,  /* dns_try_naptr -- off by default */
+	3,  /* udp transport preference (for naptr) */
+	2,  /* tcp transport preference (for naptr) */
+	1,  /* tls transport preference (for naptr) */
+	-1, /* dns_retr_time */
+	-1, /* dns_retr_no */
+	-1, /* dns_servers_no */
+	1,  /* dns_search_list */
+	1,  /* dns_search_fmatch */
+	0,  /* dns_reinit */
+	/* DNS cache */
+#ifdef USE_DNS_CACHE
+	0,  /* dns_cache_flags */
+	0,  /* use_dns_failover -- off by default */
+	0,  /* dns_srv_lb -- off by default */
+	DEFAULT_DNS_NEG_CACHE_TTL, /* neg. cache ttl */
+	DEFAULT_DNS_CACHE_MIN_TTL, /* minimum ttl */
+	DEFAULT_DNS_CACHE_MAX_TTL, /* maximum ttl */
+	DEFAULT_DNS_MAX_MEM, /* dns_cache_max_mem */
+	0, /* dns_cache_del_nonexp -- delete only expired entries by default */
 #endif
 #endif
 };
 };
 
 
@@ -48,12 +83,72 @@ void	*core_cfg = &default_core_cfg;
 cfg_def_t core_cfg_def[] = {
 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 */
 	{"use_dst_blacklist",	CFG_VAR_INT,	0, 0, 0, 0,
 	{"use_dst_blacklist",	CFG_VAR_INT,	0, 0, 0, 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"},
 	{"dst_blacklist_mem",	CFG_VAR_INT,	0, 0, blst_max_mem_fixup, 0,
 	{"dst_blacklist_mem",	CFG_VAR_INT,	0, 0, blst_max_mem_fixup, 0,
 		"maximum shared memory amount (in KB) used for keeping the blacklisted destinations"},
 		"maximum shared memory amount (in KB) used for keeping the blacklisted destinations"},
+#endif
+	/* resolver */
+#ifdef USE_DNS_CACHE
+	{"dns_try_ipv6",	CFG_VAR_INT,	0, 1, dns_try_ipv6_fixup, fix_dns_flags,
+#else
+	{"dns_try_ipv6",	CFG_VAR_INT,	0, 1, dns_try_ipv6_fixup, 0,
+#endif
+		"enable/disable IPv6 DNS lookups"},
+#ifdef USE_DNS_CACHE
+	{"dns_try_naptr",	CFG_VAR_INT,	0, 1, 0, fix_dns_flags,
+#else
+	{"dns_try_naptr",	CFG_VAR_INT,	0, 1, 0, 0,
+#endif
+		"enable/disable NAPTR DNS lookups"},
+	{"dns_udp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
+		"udp protocol preference when doing NAPTR lookups"},
+	{"dns_tcp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
+		"tcp protocol preference when doing NAPTR lookups"},
+	{"dns_tls_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
+		"tls protocol preference when doing NAPTR lookups"},
+	{"dns_retr_time",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
+		"time in s before retrying a dns request"},
+	{"dns_retr_no",		CFG_VAR_INT,	0, 0, 0, resolv_reinit,
+		"number of dns retransmissions before giving up"},
+	{"dns_servers_no",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
+		"how many dns servers from the ones defined in "
+		"/etc/resolv.conf will be used"},
+	{"dns_use_search_list",	CFG_VAR_INT,	0, 1, 0, resolv_reinit,
+		"if set to 0, the search list in /etc/resolv.conf is ignored"},
+	{"dns_search_full_match",	CFG_VAR_INT,	0, 1, 0, 0,
+		"enable/disable domain name checks against the search list "
+		"in DNS answers"},
+	{"dns_reinit",		CFG_VAR_INT|CFG_INPUT_INT,	1, 1, dns_reinit_fixup, resolv_reinit,
+		"set to 1 in order to reinitialize the DNS resolver"},
+	/* DNS cache */
+#ifdef USE_DNS_CACHE
+	{"dns_cache_flags",	CFG_VAR_INT,	0, 4, 0, fix_dns_flags,
+		"dns cache specific resolver flags "
+		"(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},
+	{"use_dns_failover",	CFG_VAR_INT,	0, 1, use_dns_failover_fixup, 0,
+		"enable/disable dns failover in case the destination "
+		"resolves to multiple ip addresses and/or multiple SRV records "
+		"(depends on use_dns_cache)"},
+	{"dns_srv_lb",		CFG_VAR_INT,	0, 1, 0, fix_dns_flags,
+		"enable/disable load balancing to different srv records "
+		"of the same priority based on the srv records weights "
+		"(depends on dns_failover)"},
+	{"dns_cache_negative_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
+		"time to live for negative results (\"not found\") "
+		"in seconds. Use 0 to disable"},
+	{"dns_cache_min_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
+		"minimum accepted time to live for a record, in seconds"},
+	{"dns_cache_max_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
+		"maximum accepted time to live for a record, in seconds"},
+	{"dns_cache_mem",	CFG_VAR_INT,	0, 0, dns_cache_max_mem_fixup, 0,
+		"maximum memory used for the dns cache in Kb"},
+	{"dns_cache_del_nonexp",	CFG_VAR_INT,	0, 1, 0, 0,
+		"allow deletion of non-expired records from the cache when "
+		"there is no more space left for new ones"},
 #endif
 #endif
 	{0, 0, 0, 0, 0, 0}
 	{0, 0, 0, 0, 0, 0}
 };
 };

+ 24 - 0
cfg_core.h

@@ -47,10 +47,34 @@ extern void	*core_cfg;
 struct cfg_group_core {
 struct cfg_group_core {
 	int	debug;
 	int	debug;
 #ifdef USE_DST_BLACKLIST
 #ifdef USE_DST_BLACKLIST
+	/* blacklist */
 	int	use_dst_blacklist; /* 1 if blacklist is enabled */
 	int	use_dst_blacklist; /* 1 if blacklist is enabled */
 	unsigned int	blst_timeout; /* blacklist entry ttl */
 	unsigned int	blst_timeout; /* blacklist entry ttl */
 	unsigned int	blst_max_mem; /* maximum memory used for the
 	unsigned int	blst_max_mem; /* maximum memory used for the
 					blacklist entries */
 					blacklist entries */
+#endif
+	/* resolver */
+	int dns_try_ipv6;
+	int dns_try_naptr;
+	int dns_udp_pref;
+	int dns_tcp_pref;
+	int dns_tls_pref;
+	int dns_retr_time;
+	int dns_retr_no;
+	int dns_servers_no;
+	int dns_search_list;
+	int dns_search_fmatch;
+	int dns_reinit;
+	/* DNS cache */
+#ifdef USE_DNS_CACHE
+	int dns_cache_flags;
+	int use_dns_failover;
+	int dns_srv_lb;
+	unsigned int dns_neg_cache_ttl;
+	unsigned int dns_cache_min_ttl;
+	unsigned int dns_cache_max_ttl;
+	unsigned int dns_cache_max_mem;
+	int dns_cache_del_nonexp;
 #endif
 #endif
 };
 };
 
 

+ 82 - 50
dns_cache.c

@@ -39,6 +39,8 @@
  *		of the cache (Miklos)
  *		of the cache (Miklos)
  *  2007-07-30  DNS cache measurements added (Gergo)
  *  2007-07-30  DNS cache measurements added (Gergo)
  *  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
+ *		framework (Miklos)
  */
  */
 
 
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
@@ -48,6 +50,7 @@
 #endif
 #endif
 
 
 #include "globals.h"
 #include "globals.h"
+#include "cfg_core.h"
 #include "dns_cache.h"
 #include "dns_cache.h"
 #include "dns_wrappers.h"
 #include "dns_wrappers.h"
 #include "compiler_opt.h"
 #include "compiler_opt.h"
@@ -79,10 +82,6 @@
 							   dns answer*/
 							   dns answer*/
 
 
 #define DNS_HASH_SIZE	1024 /* must be <= 65535 */
 #define DNS_HASH_SIZE	1024 /* must be <= 65535 */
-#define DEFAULT_DNS_NEG_CACHE_TTL 60 /* 1 min. */
-#define DEFAULT_DNS_CACHE_MIN_TTL 0 /* (disabled) */
-#define DEFAULT_DNS_CACHE_MAX_TTL ((unsigned int)(-1)) /* (maxint) */
-#define DEFAULT_DNS_MAX_MEM 500 /* 500 Kb */
 #define DEFAULT_DNS_TIMER_INTERVAL 120  /* 2 min. */
 #define DEFAULT_DNS_TIMER_INTERVAL 120  /* 2 min. */
 #define DNS_HE_MAX_ADDR 10  /* maxium addresses returne in a hostent struct */
 #define DNS_HE_MAX_ADDR 10  /* maxium addresses returne in a hostent struct */
 #define MAX_CNAME_CHAIN  10
 #define MAX_CNAME_CHAIN  10
@@ -91,16 +90,9 @@
 
 
 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_cache_max_mem=DEFAULT_DNS_MAX_MEM; /* maximum memory used for
-													 the cached entries */
-unsigned int dns_neg_cache_ttl=DEFAULT_DNS_NEG_CACHE_TTL; /* neg. cache ttl */
-unsigned int dns_cache_max_ttl=DEFAULT_DNS_CACHE_MAX_TTL; /* maximum ttl */
-unsigned int dns_cache_min_ttl=DEFAULT_DNS_CACHE_MIN_TTL; /* minimum ttl */
 unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
 unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
 int dns_flags=0; /* default flags used for the  dns_*resolvehost
 int dns_flags=0; /* default flags used for the  dns_*resolvehost
                     (compatibility wrappers) */
                     (compatibility wrappers) */
-int dns_srv_lb=0; /* off by default */
-int dns_cache_del_nonexp=0; /* delete only expired entries by default */
 
 
 #ifdef USE_DNS_CACHE_STATS
 #ifdef USE_DNS_CACHE_STATS
 struct t_dns_cache_stats* dns_cache_stats=0;
 struct t_dns_cache_stats* dns_cache_stats=0;
@@ -109,8 +101,12 @@ struct t_dns_cache_stats* dns_cache_stats=0;
 #define LOCK_DNS_HASH()		lock_get(dns_hash_lock)
 #define LOCK_DNS_HASH()		lock_get(dns_hash_lock)
 #define UNLOCK_DNS_HASH()	lock_release(dns_hash_lock)
 #define UNLOCK_DNS_HASH()	lock_release(dns_hash_lock)
 
 
-#define FIX_TTL(t)  (((t)<dns_cache_min_ttl)?dns_cache_min_ttl: \
-						(((t)>dns_cache_max_ttl)?dns_cache_max_ttl:(t)))
+#define FIX_TTL(t) \
+	(((t)<cfg_get(core, core_cfg, dns_cache_min_ttl))? \
+		cfg_get(core, core_cfg, dns_cache_min_ttl): \
+		(((t)>cfg_get(core, core_cfg, dns_cache_max_ttl))? \
+			cfg_get(core, core_cfg, dns_cache_max_ttl): \
+			(t)))
 
 
 
 
 struct dns_hash_head{
 struct dns_hash_head{
@@ -216,8 +212,8 @@ static ticks_t dns_timer(ticks_t ticks, struct timer_ln* tl, void* data)
 	if (atomic_get(dns_servers_up) == 0)
 	if (atomic_get(dns_servers_up) == 0)
 		return (ticks_t)(-1);
 		return (ticks_t)(-1);
 #endif
 #endif
-	if (*dns_cache_mem_used>12*(dns_cache_max_mem/16)){ /* ~ 75% used */
-		dns_cache_free_mem(dns_cache_max_mem/2, 1);
+	if (*dns_cache_mem_used>12*(cfg_get(core, core_cfg, dns_cache_max_mem)/16)){ /* ~ 75% used */
+		dns_cache_free_mem(cfg_get(core, core_cfg, dns_cache_max_mem)/2, 1);
 	}else{
 	}else{
 		dns_cache_clean(-1, 1); /* all the table, only expired entries */
 		dns_cache_clean(-1, 1); /* all the table, only expired entries */
 		/* TODO: better strategy? */
 		/* TODO: better strategy? */
@@ -265,7 +261,62 @@ void destroy_dns_cache()
 	}
 	}
 }
 }
 
 
+/* set the value of dns_flags */
+void fix_dns_flags(str *name)
+{
+	/* restore the original value of dns_cache_flags first
+	 * (DNS_IPV4_ONLY may have been set only because dns_try_ipv6
+	 * was disabled, and the flag must be cleared when
+	 * dns_try_ipv6 is enabled) (Miklos)
+	 */
+	dns_flags = cfg_get(core, core_cfg, dns_cache_flags) & 7;
 
 
+	if (cfg_get(core, core_cfg, dns_try_ipv6)==0){
+		dns_flags|=DNS_IPV4_ONLY;
+	}
+	if (dns_flags & DNS_IPV4_ONLY){
+		dns_flags&=~(DNS_IPV6_ONLY|DNS_IPV6_FIRST);
+	}
+	if (cfg_get(core, core_cfg, dns_srv_lb)){
+#ifdef DNS_SRV_LB
+		dns_flags|=DNS_SRV_RR_LB;
+#else
+		LOG(L_WARN, "WARING: fix_dns_flags: SRV loadbalaning is set, but"
+					" support for it is not compiled -- ignoring\n");
+#endif
+	}
+	if (cfg_get(core, core_cfg, dns_try_naptr)) {
+#ifndef USE_NAPTR
+	LOG(L_WARN, "WARING: fix_dns_flags: NAPTR support is enabled, but"
+				" support for it is not compiled -- ignoring\n");
+#endif
+		dns_flags|=DNS_TRY_NAPTR;
+	}
+}
+
+/* fixup function for use_dns_failover
+ * verifies that use_dns_cache is set to 1
+ */
+int use_dns_failover_fixup(void *handle, str *name, void **val)
+{
+	if ((int)(long)(*val) && !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 -1;
+	}
+	return 0;
+}
+
+/* KByte to Byte conversion */
+int dns_cache_max_mem_fixup(void *handle, str *name, void **val)
+{
+	unsigned int    u;
+
+	u = ((unsigned int)(long)(*val))<<10;
+	(*val) = (void *)(long)u;
+	return 0;
+}
 
 
 int init_dns_cache()
 int init_dns_cache()
 {
 {
@@ -322,29 +373,10 @@ int init_dns_cache()
 #endif
 #endif
 
 
 	/* fix options */
 	/* fix options */
-	dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
+	default_core_cfg.dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
 	/* fix flags */
 	/* fix flags */
-	if (dns_try_ipv6==0){
-		dns_flags|=DNS_IPV4_ONLY;
-	}
-	if (dns_flags & DNS_IPV4_ONLY){
-		dns_flags&=~(DNS_IPV6_ONLY|DNS_IPV6_FIRST);
-	}
-	if (dns_srv_lb){
-#ifdef DNS_SRV_LB
-		dns_flags|=DNS_SRV_RR_LB;
-#else
-		LOG(L_WARN, "WARING: dns_cache_init: SRV loadbalaning is set, but"
-					" support for it is not compiled -- ignoring\n");
-#endif
-	}
-	if (dns_try_naptr){
-#ifndef USE_NAPTR
-	LOG(L_WARN, "WARING: dns_cache_init: NAPTR support is enabled, but"
-				" support for it is not compiled -- ignoring\n");
-#endif
-		dns_flags|=DNS_TRY_NAPTR;
-	}
+	fix_dns_flags(NULL);
+
 	dns_timer_h=timer_alloc();
 	dns_timer_h=timer_alloc();
 	if (dns_timer_h==0){
 	if (dns_timer_h==0){
 		ret=E_OUT_OF_MEM;
 		ret=E_OUT_OF_MEM;
@@ -599,10 +631,8 @@ inline static int dns_cache_clean(unsigned int no, int expired_only)
 	if (!expired_only){
 	if (!expired_only){
 		for(h=start; h!=(start+DNS_HASH_SIZE); h++){
 		for(h=start; h!=(start+DNS_HASH_SIZE); h++){
 			clist_foreach_safe(&dns_hash[h%DNS_HASH_SIZE], e, t, next){
 			clist_foreach_safe(&dns_hash[h%DNS_HASH_SIZE], e, t, next){
-				if  ((s_ticks_t)(now-e->expire)>=0){
-					_dns_hash_remove(e);
-					deleted++;
-				}
+				_dns_hash_remove(e);
+				deleted++;
 				n++;
 				n++;
 				if (n>=no) goto skip;
 				if (n>=no) goto skip;
 			}
 			}
@@ -714,14 +744,15 @@ inline static int dns_cache_add(struct dns_hash_entry* e)
 
 
 	/* check space */
 	/* check space */
 	/* atomic_add_long(dns_cache_total_used, e->size); */
 	/* atomic_add_long(dns_cache_total_used, e->size); */
-	if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
+	if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
 #ifdef USE_DNS_CACHE_STATS
 #ifdef USE_DNS_CACHE_STATS
 		dns_cache_stats[process_no].dc_lru_cnt++;
 		dns_cache_stats[process_no].dc_lru_cnt++;
 #endif
 #endif
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
 		/* free ~ 12% of the cache */
 		/* free ~ 12% of the cache */
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
-		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
+		dns_cache_free_mem(*dns_cache_mem_used/16*14,
+					!cfg_get(core, core_cfg, dns_cache_del_nonexp));
+		if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
 			return -1;
 			return -1;
 		}
 		}
@@ -753,16 +784,17 @@ inline static int dns_cache_add_unsafe(struct dns_hash_entry* e)
 
 
 	/* check space */
 	/* check space */
 	/* atomic_add_long(dns_cache_total_used, e->size); */
 	/* atomic_add_long(dns_cache_total_used, e->size); */
-	if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
+	if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
 #ifdef USE_DNS_CACHE_STATS
 #ifdef USE_DNS_CACHE_STATS
 		dns_cache_stats[process_no].dc_lru_cnt++;
 		dns_cache_stats[process_no].dc_lru_cnt++;
 #endif
 #endif
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
 		/* free ~ 12% of the cache */
 		/* free ~ 12% of the cache */
 		UNLOCK_DNS_HASH();
 		UNLOCK_DNS_HASH();
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
+		dns_cache_free_mem(*dns_cache_mem_used/16*14,
+					!cfg_get(core, core_cfg, dns_cache_del_nonexp));
 		LOCK_DNS_HASH();
 		LOCK_DNS_HASH();
-		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
+		if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
 			return -1;
 			return -1;
 		}
 		}
@@ -1672,8 +1704,8 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
 		l=dns_cache_mk_rd_entry2(records);
 		l=dns_cache_mk_rd_entry2(records);
 #endif
 #endif
 		free_rdata_list(records);
 		free_rdata_list(records);
-	}else if (dns_neg_cache_ttl){
-		e=dns_cache_mk_bad_entry(name, type, dns_neg_cache_ttl, DNS_BAD_NAME);
+	}else if (cfg_get(core, core_cfg, dns_neg_cache_ttl)){
+		e=dns_cache_mk_bad_entry(name, type, cfg_get(core, core_cfg, dns_neg_cache_ttl), DNS_BAD_NAME);
 		atomic_set(&e->refcnt, 1); /* 1 because we return a ref. to it */
 		atomic_set(&e->refcnt, 1); /* 1 because we return a ref. to it */
 		dns_cache_add(e); /* refcnt++ inside*/
 		dns_cache_add(e); /* refcnt++ inside*/
 		goto end;
 		goto end;
@@ -3144,7 +3176,7 @@ void dns_cache_mem_info(rpc_t* rpc, void* ctx)
 		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;
 	}
 	}
-	rpc->add(ctx, "dd",  *dns_cache_mem_used, dns_cache_max_mem);
+	rpc->add(ctx, "dd",  *dns_cache_mem_used, cfg_get(core, core_cfg, dns_cache_max_mem));
 }
 }
 
 
 
 

+ 8 - 0
dns_cache.h

@@ -53,6 +53,11 @@
 #error "DNS WATCHDOG requires DNS CACHE support (define USE_DNS_CACHE)"
 #error "DNS WATCHDOG requires DNS CACHE support (define USE_DNS_CACHE)"
 #endif
 #endif
 
 
+#define DEFAULT_DNS_NEG_CACHE_TTL 60 /* 1 min. */
+#define DEFAULT_DNS_CACHE_MIN_TTL 0 /* (disabled) */
+#define DEFAULT_DNS_CACHE_MAX_TTL ((unsigned int)(-1)) /* (maxint) */
+#define DEFAULT_DNS_MAX_MEM 500 /* 500 Kb */
+
 /* uncomment the define below for SRV weight based load balancing */
 /* uncomment the define below for SRV weight based load balancing */
 #define DNS_SRV_LB
 #define DNS_SRV_LB
 
 
@@ -173,6 +178,9 @@ struct dns_srv_handle{
 
 
 const char* dns_strerror(int err);
 const char* dns_strerror(int err);
 
 
+void fix_dns_flags(str *name);
+int use_dns_failover_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
 int init_dns_cache_stats(int iproc_num);
 int init_dns_cache_stats(int iproc_num);

+ 4 - 3
forward.c

@@ -319,7 +319,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
 
 
 	if(dst){
 	if(dst){
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
-		if (use_dns_failover){
+		if (cfg_get(core, core_cfg, use_dns_failover)){
 			dns_srv_handle_init(&dns_srv_h);
 			dns_srv_handle_init(&dns_srv_h);
 			err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port,
 			err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port,
 									&send_info->proto, dns_flags);
 									&send_info->proto, dns_flags);
@@ -454,7 +454,8 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
 			goto end;
 			goto end;
 		}
 		}
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
-	}while(dst && use_dns_failover && dns_srv_handle_next(&dns_srv_h, err) && 
+	}while(dst && cfg_get(core, core_cfg, use_dns_failover) &&
+			dns_srv_handle_next(&dns_srv_h, err) && 
 			((err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port,
 			((err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port,
 								  &send_info->proto, dns_flags))==0));
 								  &send_info->proto, dns_flags))==0));
 	if ((err!=0) && (err!=-E_DNS_EOR)){
 	if ((err!=0) && (err!=-E_DNS_EOR)){
@@ -471,7 +472,7 @@ error:
 	STATS_TX_DROPS;
 	STATS_TX_DROPS;
 end:
 end:
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
-	if (dst && use_dns_failover){
+	if (dst && cfg_get(core, core_cfg, use_dns_failover)){
 				dns_srv_handle_put(&dns_srv_h);
 				dns_srv_handle_put(&dns_srv_h);
 	}
 	}
 #endif
 #endif

+ 0 - 15
globals.h

@@ -190,26 +190,11 @@ extern int rt_timer1_policy; /* "fast" timer, SCHED_OTHER */
 extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
 extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
 
 
 
 
-
-/* resolver */
-extern int dns_retr_time;
-extern int dns_retr_no;
-extern int dns_servers_no;
-extern int dns_search_list;
-extern int dns_search_fmatch;
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
 extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
 extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
-extern int use_dns_failover; /* 1 if failover is enabled, 0 otherwise */
-extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached
-										  entries*/
-extern unsigned int dns_neg_cache_ttl; /* neg. cache ttl */
-extern unsigned int dns_cache_max_ttl; /* maximum ttl */
-extern unsigned int dns_cache_min_ttl; /* minimum ttl */
 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) */
-extern int dns_srv_lb; /* default SRV LB support value */
-extern int dns_cache_del_nonexp; /* delete non-expired values from the cache when it is full */
 
 
 #ifdef USE_DNS_CACHE_STATS
 #ifdef USE_DNS_CACHE_STATS
 struct t_dns_cache_stats{
 struct t_dns_cache_stats{

+ 4 - 6
main.c

@@ -374,7 +374,6 @@ 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
 #ifdef USE_DNS_CACHE
 int use_dns_cache=1; /* 1 if the cache is enabled, 0 otherwise */
 int use_dns_cache=1; /* 1 if the cache is enabled, 0 otherwise */
-int use_dns_failover=0; /* 1 if failover is enabled, 0 otherwise */
 #endif
 #endif
 
 
 int tos = IPTOS_LOWDELAY;
 int tos = IPTOS_LOWDELAY;
@@ -1279,7 +1278,6 @@ int main(int argc, char** argv)
 	int rfd;
 	int rfd;
 	int debug_save, debug_flag;
 	int debug_save, debug_flag;
 	int dont_fork_cnt;
 	int dont_fork_cnt;
-	int socket_types;
 
 
 	/*init*/
 	/*init*/
 	creator_pid = getpid();
 	creator_pid = getpid();
@@ -1606,14 +1604,14 @@ try_again:
 			goto error;
 			goto error;
 		}
 		}
 	}
 	}
-	if (fix_all_socket_lists(&socket_types)!=0){
+	if (fix_all_socket_lists()!=0){
 		fprintf(stderr,  "failed to initialize list addresses\n");
 		fprintf(stderr,  "failed to initialize list addresses\n");
 		goto error;
 		goto error;
 	}
 	}
-	if (dns_try_ipv6 && !(socket_types & SOCKET_T_IPV6)){
+	if (default_core_cfg.dns_try_ipv6 && !(socket_types & SOCKET_T_IPV6)){
 		/* if we are not listening on any ipv6 address => no point
 		/* if we are not listening on any ipv6 address => no point
 		 * to try to resovle ipv6 addresses */
 		 * to try to resovle ipv6 addresses */
-		dns_try_ipv6=0;
+		default_core_cfg.dns_try_ipv6=0;
 	}
 	}
 	/* print all the listen addresses */
 	/* print all the listen addresses */
 	printf("Listening on \n");
 	printf("Listening on \n");
@@ -1660,7 +1658,7 @@ try_again:
 		goto error;
 		goto error;
 	}
 	}
 	if (use_dns_cache==0)
 	if (use_dns_cache==0)
-		use_dns_failover=0; /* cannot work w/o dns_cache support */
+		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){

+ 5 - 4
modules/tm/t_fwd.c

@@ -102,6 +102,7 @@
 #include "config.h"
 #include "config.h"
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
 #include "../../dns_cache.h"
 #include "../../dns_cache.h"
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
 #endif
 #endif
 #ifdef USE_DST_BLACKLIST
 #ifdef USE_DST_BLACKLIST
 #include "../../dst_blacklist.h"
 #include "../../dst_blacklist.h"
@@ -395,7 +396,7 @@ int add_uac_dns_fallback( struct cell *t, struct sip_msg* msg,
 	int ret;
 	int ret;
 	
 	
 	ret=-1;
 	ret=-1;
-	if (use_dns_failover && 
+	if (cfg_get(core, core_cfg, use_dns_failover) && 
 			!((t->flags & T_DONT_FORK) || uac_dont_fork(old_uac)) &&
 			!((t->flags & T_DONT_FORK) || uac_dont_fork(old_uac)) &&
 			dns_srv_handle_next(&old_uac->dns_h, 0)){
 			dns_srv_handle_next(&old_uac->dns_h, 0)){
 			if (lock_replies){
 			if (lock_replies){
@@ -674,7 +675,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
 			/* if the destination resolves to more ips, add another
 			/* if the destination resolves to more ips, add another
 			 *  branch/uac */
 			 *  branch/uac */
-			if (use_dns_failover){
+			if (cfg_get(core, core_cfg, use_dns_failover)){
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
 				if (ret>=0){
 				if (ret>=0){
 					su2ip_addr(&ip, &uac->request.dst.to);
 					su2ip_addr(&ip, &uac->request.dst.to);
@@ -709,7 +710,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
 			/* if the destination resolves to more ips, add another
 			/* if the destination resolves to more ips, add another
 			 *  branch/uac */
 			 *  branch/uac */
-			if (use_dns_failover){
+			if (cfg_get(core, core_cfg, use_dns_failover)){
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
 				if (ret>=0){
 				if (ret>=0){
 					su2ip_addr(&ip, &uac->request.dst.to);
 					su2ip_addr(&ip, &uac->request.dst.to);
@@ -744,7 +745,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
 		/* if the destination resolves to more ips, add another
 		/* if the destination resolves to more ips, add another
 		 *  branch/uac */
 		 *  branch/uac */
-		if (use_dns_failover){
+		if (cfg_get(core, core_cfg, use_dns_failover)){
 			ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
 			ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
 			if (ret>=0){
 			if (ret>=0){
 				/* success, return new branch */
 				/* success, return new branch */

+ 2 - 1
modules/tm/t_msgbuilder.c

@@ -66,6 +66,7 @@
 #include "uac.h"
 #include "uac.h"
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
 #include "../../dns_cache.h"
 #include "../../dns_cache.h"
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
 #endif
 #endif
 
 
 
 
@@ -598,7 +599,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans,
 	
 	
 	 /* via */
 	 /* via */
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
-	if (use_dns_failover){
+	if (cfg_get(core, core_cfg, use_dns_failover)){
 		dns_srv_handle_init(&dns_h);
 		dns_srv_handle_init(&dns_h);
 		if ((uri2dst(&dns_h , dst, rpl, &next_hop, PROTO_NONE)==0) ||
 		if ((uri2dst(&dns_h , dst, rpl, &next_hop, PROTO_NONE)==0) ||
 				(dst->send_sock==0)){
 				(dst->send_sock==0)){

+ 9 - 2
modules/tm/t_reply.c

@@ -110,6 +110,10 @@
 #ifdef USE_DST_BLACKLIST
 #ifdef USE_DST_BLACKLIST
 #include "../../dst_blacklist.h"
 #include "../../dst_blacklist.h"
 #endif
 #endif
+#ifdef USE_DNS_FAILOVER
+#include "../../dns_cache.h"
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
+#endif
 
 
 #include "defs.h"
 #include "defs.h"
 #include "h_table.h"
 #include "h_table.h"
@@ -415,7 +419,7 @@ static int send_local_ack(struct sip_msg* msg, str* next_hop,
 		return -1;
 		return -1;
 	}
 	}
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
-	if (use_dns_failover){
+	if (cfg_get(core, core_cfg, use_dns_failover)){
 		dns_srv_handle_init(&dns_h);
 		dns_srv_handle_init(&dns_h);
 		if ((uri2dst(&dns_h, &dst, msg,  next_hop, PROTO_NONE)==0) || 
 		if ((uri2dst(&dns_h, &dst, msg,  next_hop, PROTO_NONE)==0) || 
 				(dst.send_sock==0)){
 				(dst.send_sock==0)){
@@ -1837,7 +1841,10 @@ int reply_received( struct sip_msg  *p_msg )
 		 *  This code is out of LOCK_REPLIES() to minimize the time the
 		 *  This code is out of LOCK_REPLIES() to minimize the time the
 		 *  reply lock is held (the lock won't be held while sending the
 		 *  reply lock is held (the lock won't be held while sending the
 		 *   message)*/
 		 *   message)*/
-		if (use_dns_failover && (msg_status==503) && uac->request.t_active){
+		if (cfg_get(core, core_cfg, use_dns_failover) && 
+			(msg_status==503) &&
+			uac->request.t_active
+		) {
 			branch_ret=add_uac_dns_fallback(t, t->uas.request, uac, 1);
 			branch_ret=add_uac_dns_fallback(t, t->uas.request, uac, 1);
 			prev_branch=-1;
 			prev_branch=-1;
 			while((branch_ret>=0) &&(branch_ret!=prev_branch)){
 			while((branch_ret>=0) &&(branch_ret!=prev_branch)){

+ 2 - 1
modules/tm/timer.c

@@ -138,6 +138,7 @@
 #include "t_hooks.h"
 #include "t_hooks.h"
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
 #include "t_fwd.h" /* t_send_branch */
 #include "t_fwd.h" /* t_send_branch */
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
 #endif
 #endif
 #ifdef USE_DST_BLACKLIST
 #ifdef USE_DST_BLACKLIST
 #include "../../dst_blacklist.h"
 #include "../../dst_blacklist.h"
@@ -467,7 +468,7 @@ inline static void final_response_handler(	struct retr_buf* r_buf,
 		/* if this is an invite, the destination resolves to more ips, and
 		/* if this is an invite, the destination resolves to more ips, and
 		 *  it still hasn't passed more than fr_inv_timeout since we
 		 *  it still hasn't passed more than fr_inv_timeout since we
 		 *  started, add another branch/uac */
 		 *  started, add another branch/uac */
-		if (use_dns_failover){
+		if (cfg_get(core, core_cfg, use_dns_failover)){
 			now=get_ticks_raw();
 			now=get_ticks_raw();
 			if ((s_ticks_t)(t->end_of_life-now)>0){
 			if ((s_ticks_t)(t->end_of_life-now)>0){
 				branch_ret=add_uac_dns_fallback(t, t->uas.request,
 				branch_ret=add_uac_dns_fallback(t, t->uas.request,

+ 5 - 1
modules/tm/uac.c

@@ -77,6 +77,10 @@
 #include "callid.h"
 #include "callid.h"
 #include "uac.h"
 #include "uac.h"
 #include "t_stats.h"
 #include "t_stats.h"
+#ifdef USE_DNS_FAILOVER
+#include "../../dns_cache.h"
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
+#endif
 
 
 
 
 #define FROM_TAG_LEN (MD5_LEN + 1 /* - */ + CRC16_LEN) /* length of FROM tags */
 #define FROM_TAG_LEN (MD5_LEN + 1 /* - */ + CRC16_LEN) /* length of FROM tags */
@@ -217,7 +221,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
 			uac_r->dialog->hooks.next_hop->s);
 			uac_r->dialog->hooks.next_hop->s);
 	/* it's a new message, so we will take the default socket */
 	/* it's a new message, so we will take the default socket */
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
-	if (use_dns_failover){
+	if (cfg_get(core, core_cfg, use_dns_failover)){
 		dns_srv_handle_init(&dns_h);
 		dns_srv_handle_init(&dns_h);
 		if ((uri2dst(&dns_h, &dst, 0, uac_r->dialog->hooks.next_hop, PROTO_NONE)==0)
 		if ((uri2dst(&dns_h, &dst, 0, uac_r->dialog->hooks.next_hop, PROTO_NONE)==0)
 				|| (dst.send_sock==0)){
 				|| (dst.send_sock==0)){

+ 2 - 1
modules/tm/ut.h

@@ -58,6 +58,7 @@
 #include "../../resolve.h"
 #include "../../resolve.h"
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
 #include "../../dns_cache.h"
 #include "../../dns_cache.h"
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
 #endif
 #endif
 
 
 /* a forced_proto takes precedence if != PROTO_NONE */
 /* a forced_proto takes precedence if != PROTO_NONE */
@@ -270,7 +271,7 @@ inline static struct dest_info *uri2dst(struct dest_info* dst,
 #endif
 #endif
 		host=&parsed_uri.host;
 		host=&parsed_uri.host;
 #ifdef USE_DNS_FAILOVER
 #ifdef USE_DNS_FAILOVER
-	if (use_dns_failover && dns_h){
+	if (cfg_get(core, core_cfg, use_dns_failover) && dns_h){
 		ip_found=0;
 		ip_found=0;
 		do{
 		do{
 			/* try all the ips until we find a good send socket */
 			/* try all the ips until we find a good send socket */

+ 85 - 33
resolve.c

@@ -41,6 +41,8 @@
  *              new option dns_search_full_match (default on) controls
  *              new option dns_search_full_match (default on) controls
  *              whether rest of the name is matched against search list
  *              whether rest of the name is matched against search list
  *              or blindly accepted (better performance but exploitable)
  *              or blindly accepted (better performance but exploitable)
+ *  2008-01-31  resolver options use the configuration framework, and the
+ *		resolver is reinitialized when the options change (Miklos)
  */ 
  */ 
 
 
 
 
@@ -57,6 +59,8 @@
 #include "ip_addr.h"
 #include "ip_addr.h"
 #include "error.h"
 #include "error.h"
 #include "globals.h" /* tcp_disable, tls_disable a.s.o */
 #include "globals.h" /* tcp_disable, tls_disable a.s.o */
+#include "cfg_core.h"
+#include "socket_info.h"
 
 
 #ifdef USE_DNS_CACHE
 #ifdef USE_DNS_CACHE
 #include "dns_cache.h"
 #include "dns_cache.h"
@@ -68,29 +72,11 @@
 #define local_malloc pkg_malloc
 #define local_malloc pkg_malloc
 #define local_free   pkg_free
 #define local_free   pkg_free
 
 
-#ifdef USE_IPV6
-int dns_try_ipv6=1; /* default on */
-#else
-int dns_try_ipv6=0; /* off, if no ipv6 support */
-#endif
-int dns_try_naptr=0;  /* off by default */
-
-int dns_udp_pref=3;  /* udp transport preference (for naptr) */
-int dns_tcp_pref=2;  /* tcp transport preference (for naptr) */
-int dns_tls_pref=1;  /* tls transport preference (for naptr) */
-
 #ifdef USE_NAPTR
 #ifdef USE_NAPTR
 #define PROTO_LAST  PROTO_SCTP
 #define PROTO_LAST  PROTO_SCTP
 static int naptr_proto_pref[PROTO_LAST];
 static int naptr_proto_pref[PROTO_LAST];
 #endif
 #endif
 
 
-/* declared in globals.h */
-int dns_retr_time=-1;
-int dns_retr_no=-1;
-int dns_servers_no=-1;
-int dns_search_list=-1;
-int dns_search_fmatch=-1;
-
 #ifdef USE_NAPTR
 #ifdef USE_NAPTR
 void init_naptr_proto_prefs()
 void init_naptr_proto_prefs()
 {
 {
@@ -99,14 +85,28 @@ void init_naptr_proto_prefs()
 		BUG("init_naptr_proto_prefs: array too small \n");
 		BUG("init_naptr_proto_prefs: array too small \n");
 		return;
 		return;
 	}
 	}
-	naptr_proto_pref[PROTO_UDP]=dns_udp_pref;
-	naptr_proto_pref[PROTO_TCP]=dns_tcp_pref;
-	naptr_proto_pref[PROTO_TLS]=dns_tls_pref;
+	naptr_proto_pref[PROTO_UDP]=cfg_get(core, core_cfg, dns_udp_pref);
+	naptr_proto_pref[PROTO_TCP]=cfg_get(core, core_cfg, dns_tcp_pref);
+	naptr_proto_pref[PROTO_TLS]=cfg_get(core, core_cfg, dns_tls_pref);
 }
 }
 
 
 #endif /* USE_NAPTR */
 #endif /* USE_NAPTR */
 
 
+#ifdef DNS_WATCHDOG_SUPPORT
+static on_resolv_reinit	on_resolv_reinit_cb = NULL;
 
 
+/* register the callback function */
+int register_resolv_reinit_cb(on_resolv_reinit cb)
+{
+	if (on_resolv_reinit_cb) {
+		LOG(L_ERR, "ERROR: register_resolv_reinit_cb(): "
+			"callback function has been already registered\n");
+		return -1;
+	}
+	on_resolv_reinit_cb = cb;
+	return 0;
+}
+#endif
 
 
 /* init. the resolver
 /* init. the resolver
  * params: retr_time  - time before retransmitting (must be >0)
  * params: retr_time  - time before retransmitting (must be >0)
@@ -122,30 +122,82 @@ void init_naptr_proto_prefs()
  * will be used. See also resolv.conf(5).
  * will be used. See also resolv.conf(5).
  * returns: 0 on success, -1 on error
  * returns: 0 on success, -1 on error
  */
  */
-int resolv_init()
+static int _resolv_init()
 {
 {
 	res_init();
 	res_init();
 #ifdef HAVE_RESOLV_RES
 #ifdef HAVE_RESOLV_RES
-	if (dns_retr_time>0)
-		_res.retrans=dns_retr_time;
-	if (dns_retr_no>0)
-		_res.retry=dns_retr_no;
-	if (dns_servers_no>=0)
-		_res.nscount=dns_servers_no;
-	if (dns_search_list==0)
+	if (cfg_get(core, core_cfg, dns_retr_time)>0)
+		_res.retrans=cfg_get(core, core_cfg, dns_retr_time);
+	if (cfg_get(core, core_cfg, dns_retr_no)>0)
+		_res.retry=cfg_get(core, core_cfg, dns_retr_no);
+	if (cfg_get(core, core_cfg, dns_servers_no)>=0)
+		_res.nscount=cfg_get(core, core_cfg, dns_servers_no);
+	if (cfg_get(core, core_cfg, dns_search_list)==0)
 		_res.options&=~(RES_DEFNAMES|RES_DNSRCH);
 		_res.options&=~(RES_DEFNAMES|RES_DNSRCH);
 #else
 #else
 #warning "no resolv timeout support"
 #warning "no resolv timeout support"
-	LOG(L_WARN, "WARNING: resolv_init: no resolv options support - resolv"
+	LOG(L_WARN, "WARNING: _resolv_init: no resolv options support - resolv"
 			" options will be ignored\n");
 			" options will be ignored\n");
 #endif
 #endif
+	return 0;
+}
+
+/* wrapper function to initialize the resolver at startup */
+int resolv_init()
+{
+	_resolv_init();
+
 #ifdef USE_NAPTR
 #ifdef USE_NAPTR
 	init_naptr_proto_prefs();
 	init_naptr_proto_prefs();
 #endif
 #endif
 	return 0;
 	return 0;
 }
 }
 
 
+/* wrapper function to reinitialize the resolver
+ * This function must be called by each child process whenever
+ * a resolver option changes
+ */
+void resolv_reinit(str *name)
+{
+	_resolv_init();
+
+#ifdef DNS_WATCHDOG_SUPPORT
+	if (on_resolv_reinit_cb) on_resolv_reinit_cb();
+#endif
+	LOG(L_DBG, "DEBUG: resolv_reinit(): "
+		"DNS resolver has been reinitialized\n");
+}
+
+/* fixup function for dns_reinit variable
+ * (resets the variable to 0)
+ */
+int dns_reinit_fixup(void *handle, str *name, void **val)
+{
+	*val = (void *)(long)0;
+	return 0;
+}
+
+/* wrapper function to recalculate the naptr protocol preferences */
+void reinit_naptr_proto_prefs(str *name)
+{
+#ifdef USE_NAPTR
+	init_naptr_proto_prefs();
+#endif
+}
 
 
+/* fixup function for dns_try_ipv6
+ * verifies that SER really listens on an ipv6 interface
+ */
+int dns_try_ipv6_fixup(void *handle, str *name, void **val)
+{
+	if ((int)(long)(*val) && !(socket_types & SOCKET_T_IPV6)) {
+		LOG(L_ERR, "ERROR: dns_try_ipv6_fixup(): "
+			"SER does not listen on any ipv6 interface, "
+			"there is no point in resolving ipv6 addresses\n");
+		return -1;
+	}
+	return 0;
+}
 
 
  /*  skips over a domain name in a dns message
  /*  skips over a domain name in a dns message
  *  (it can be  a sequence of labels ending in \0, a pointer or
  *  (it can be  a sequence of labels ending in \0, a pointer or
@@ -459,7 +511,7 @@ struct rdata* get_record(char* name, int type, int flags)
 	int name_len;
 	int name_len;
 	struct rdata* fullname_rd;
 	struct rdata* fullname_rd;
 	
 	
-	if (dns_search_list==0) {
+	if (cfg_get(core, core_cfg, dns_search_list)==0) {
 		search_list_used=0;
 		search_list_used=0;
 		name_len=0;
 		name_len=0;
 	} else {
 	} else {
@@ -574,7 +626,7 @@ again:
 			/* this is safe.... here was rec_name_len > name_len */
 			/* this is safe.... here was rec_name_len > name_len */
 			else if (rec_name[name_len]=='.') {
 			else if (rec_name[name_len]=='.') {
 #ifdef HAVE_RESOLV_RES
 #ifdef HAVE_RESOLV_RES
-				if ((dns_search_fmatch==0) ||
+				if ((cfg_get(core, core_cfg, dns_search_fmatch)==0) ||
 						(match_search_list(&_res, rec_name+name_len+1)!=0))
 						(match_search_list(&_res, rec_name+name_len+1)!=0))
 #endif
 #endif
 					fullname_rd=rd;
 					fullname_rd=rd;
@@ -1221,7 +1273,7 @@ end:
 struct hostent* _sip_resolvehost(str* name, unsigned short* port, char* proto)
 struct hostent* _sip_resolvehost(str* name, unsigned short* port, char* proto)
 {
 {
 #ifdef USE_NAPTR
 #ifdef USE_NAPTR
-	if (dns_try_naptr)
+	if (cfg_get(core, core_cfg, dns_try_naptr))
 		return naptr_sip_resolvehost(name, port, proto);
 		return naptr_sip_resolvehost(name, port, proto);
 #endif
 #endif
 	return srv_sip_resolvehost(name, 0, port, proto, 0, 0);
 	return srv_sip_resolvehost(name, 0, port, proto, 0, 0);

+ 20 - 8
resolve.h

@@ -159,12 +159,6 @@ struct rdata* get_record(char* name, int type, int flags);
 void free_rdata_list(struct rdata* head);
 void free_rdata_list(struct rdata* head);
 
 
 
 
-extern int dns_try_ipv6;
-extern int dns_try_naptr;
-extern int dns_udp_pref;  /* udp transport preference (for naptr) */
-extern int dns_tcp_pref;  /* tcp transport preference (for naptr) */
-extern int dns_tls_pref;  /* tls transport preference (for naptr) */
-
 
 
 #define rev_resolvehost(ip)\
 #define rev_resolvehost(ip)\
 					gethostbyaddr((char*)(ip)->u.addr, (ip)->len, (ip)->af)
 					gethostbyaddr((char*)(ip)->u.addr, (ip)->len, (ip)->af)
@@ -382,7 +376,7 @@ static inline struct hostent* _resolvehost(char* name)
 	/* ipv4 */
 	/* ipv4 */
 	he=gethostbyname(name);
 	he=gethostbyname(name);
 #ifdef USE_IPV6
 #ifdef USE_IPV6
-	if(he==0 && dns_try_ipv6){
+	if(he==0 && cfg_get(core, core_cfg, dns_try_ipv6)){
 #ifndef DNS_IP_HACK
 #ifndef DNS_IP_HACK
 skip_ipv4:
 skip_ipv4:
 #endif
 #endif
@@ -407,9 +401,27 @@ skip_ipv4:
 }
 }
 
 
 
 
-
 int resolv_init();
 int resolv_init();
 
 
+/* callback/fixup functions executed by the configuration framework */
+void resolv_reinit(str *name);
+int dns_reinit_fixup(void *handle, str *name, void **val);
+int dns_try_ipv6_fixup(void *handle, str *name, void **val);
+void reinit_naptr_proto_prefs(str *name);
+
+#ifdef DNS_WATCHDOG_SUPPORT
+/* callback function that is called by the child processes
+ * when they reinitialize the resolver
+ *
+ * Note, that this callback is called by each chiled process separately!!!
+ * If the callback is registered after forking, only the child process
+ * that installs the hook will call the callback.
+ */
+typedef void (*on_resolv_reinit)(void);
+int register_resolv_reinit_cb(on_resolv_reinit cb);
+#endif
+
+
 int sip_hostport2su(union sockaddr_union* su, str* host, unsigned short port,
 int sip_hostport2su(union sockaddr_union* su, str* host, unsigned short port,
 						char* proto);
 						char* proto);
 
 

+ 8 - 11
socket_info.c

@@ -715,18 +715,15 @@ error:
 	return -1;
 	return -1;
 }
 }
 
 
-
+int socket_types = 0;
 
 
 /* fix all 3 socket lists, fills socket_types if non-null
 /* fix all 3 socket lists, fills socket_types if non-null
  * return 0 on success, -1 on error */
  * return 0 on success, -1 on error */
-int fix_all_socket_lists(int* socket_types)
+int fix_all_socket_lists()
 {
 {
 	struct utsname myname;
 	struct utsname myname;
 	int flags;
 	int flags;
 	
 	
-	if (socket_types)
-		*socket_types=0;
-	
 	if ((udp_listen==0)
 	if ((udp_listen==0)
 #ifdef USE_TCP
 #ifdef USE_TCP
 			&& (tcp_listen==0)
 			&& (tcp_listen==0)
@@ -771,8 +768,8 @@ int fix_all_socket_lists(int* socket_types)
 				" udp failed\n");
 				" udp failed\n");
 		goto error;
 		goto error;
 	}
 	}
-	if (flags && socket_types){
-		*socket_types|=flags|SOCKET_T_UDP;
+	if (flags){
+		socket_types|=flags|SOCKET_T_UDP;
 	}
 	}
 #ifdef USE_TCP
 #ifdef USE_TCP
 	if (!tcp_disable && (fix_socket_list(&tcp_listen, &flags)!=0)){
 	if (!tcp_disable && (fix_socket_list(&tcp_listen, &flags)!=0)){
@@ -780,8 +777,8 @@ int fix_all_socket_lists(int* socket_types)
 				" tcp failed\n");
 				" tcp failed\n");
 		goto error;
 		goto error;
 	}
 	}
-	if (flags && socket_types){
-		*socket_types|=flags|SOCKET_T_TCP;
+	if (flags){
+		socket_types|=flags|SOCKET_T_TCP;
 	}
 	}
 #ifdef USE_TLS
 #ifdef USE_TLS
 	if (!tls_disable && (fix_socket_list(&tls_listen, &flags)!=0)){
 	if (!tls_disable && (fix_socket_list(&tls_listen, &flags)!=0)){
@@ -789,8 +786,8 @@ int fix_all_socket_lists(int* socket_types)
 				" tls failed\n");
 				" tls failed\n");
 		goto error;
 		goto error;
 	}
 	}
-	if (flags && socket_types){
-		*socket_types|=flags|SOCKET_T_TLS;
+	if (flags){
+		socket_types|=flags|SOCKET_T_TLS;
 	}
 	}
 #endif
 #endif
 #endif
 #endif

+ 2 - 1
socket_info.h

@@ -59,10 +59,11 @@ struct socket_info* tls_listen;
 #define SOCKET_T_TCP  8
 #define SOCKET_T_TCP  8
 #define SOCKET_T_TLS 16
 #define SOCKET_T_TLS 16
 
 
+extern int socket_types;
 
 
 int add_listen_iface(char* name, unsigned short port, unsigned short proto,
 int add_listen_iface(char* name, unsigned short port, unsigned short proto,
 							enum si_flags flags);
 							enum si_flags flags);
-int fix_all_socket_lists(int* socket_types);
+int fix_all_socket_lists();
 void print_all_socket_lists();
 void print_all_socket_lists();
 void print_aliases();
 void print_aliases();