Browse code

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 authored on 11/02/2008 09:58:29
Showing 18 changed files
... ...
@@ -608,45 +608,45 @@ assign_stm:
608 608
 	| DNS EQUAL error { yyerror("boolean value expected"); }
609 609
 	| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
610 610
 	| REV_DNS EQUAL error { yyerror("boolean value expected"); }
611
-	| DNS_TRY_IPV6 EQUAL NUMBER   { dns_try_ipv6=$3; }
611
+	| DNS_TRY_IPV6 EQUAL NUMBER   { default_core_cfg.dns_try_ipv6=$3; }
612 612
 	| DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
613
-	| DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(dns_try_naptr=$3); }
613
+	| DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
614 614
 	| DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
615
-	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(dns_srv_lb=$3); }
615
+	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
616 616
 	| DNS_SRV_LB error { yyerror("boolean value expected"); }
617
-	| DNS_UDP_PREF EQUAL NUMBER   { IF_NAPTR(dns_udp_pref=$3); }
617
+	| DNS_UDP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_udp_pref=$3); }
618 618
 	| DNS_UDP_PREF error { yyerror("number expected"); }
619
-	| DNS_TCP_PREF EQUAL NUMBER   { IF_NAPTR(dns_tcp_pref=$3); }
619
+	| DNS_TCP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3); }
620 620
 	| DNS_TCP_PREF error { yyerror("number expected"); }
621
-	| DNS_TLS_PREF EQUAL NUMBER   { IF_NAPTR(dns_tls_pref=$3); }
621
+	| DNS_TLS_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tls_pref=$3); }
622 622
 	| DNS_TLS_PREF error { yyerror("number expected"); }
623
-	| DNS_RETR_TIME EQUAL NUMBER   { dns_retr_time=$3; }
623
+	| DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
624 624
 	| DNS_RETR_TIME error { yyerror("number expected"); }
625
-	| DNS_RETR_NO EQUAL NUMBER   { dns_retr_no=$3; }
625
+	| DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
626 626
 	| DNS_RETR_NO error { yyerror("number expected"); }
627
-	| DNS_SERVERS_NO EQUAL NUMBER   { dns_servers_no=$3; }
627
+	| DNS_SERVERS_NO EQUAL NUMBER   { default_core_cfg.dns_servers_no=$3; }
628 628
 	| DNS_SERVERS_NO error { yyerror("number expected"); }
629
-	| DNS_USE_SEARCH EQUAL NUMBER   { dns_search_list=$3; }
629
+	| DNS_USE_SEARCH EQUAL NUMBER   { default_core_cfg.dns_search_list=$3; }
630 630
 	| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
631
-	| DNS_SEARCH_FMATCH EQUAL NUMBER   { dns_search_fmatch=$3; }
631
+	| DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
632 632
 	| DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
633 633
 	| DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(use_dns_cache=$3); }
634 634
 	| DNS_USE_CACHE error { yyerror("boolean value expected"); }
635
-	| DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(use_dns_failover=$3);}
635
+	| DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
636 636
 	| DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
637
-	| DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(dns_flags=$3); }
637
+	| DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
638 638
 	| DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
639
-	| DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(dns_neg_cache_ttl=$3); }
639
+	| DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
640 640
 	| DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
641
-	| DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_max_ttl=$3); }
641
+	| DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
642 642
 	| DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
643
-	| DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_min_ttl=$3); }
643
+	| DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
644 644
 	| DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
645
-	| DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_max_mem=$3); }
645
+	| DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
646 646
 	| DNS_CACHE_MEM error { yyerror("boolean value expected"); }
647 647
 	| DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
648 648
 	| DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
649
-	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_del_nonexp=$3); }
649
+	| DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
650 650
 	| DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
651 651
 	| USE_DST_BLST EQUAL NUMBER   { IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3); }
652 652
 	| USE_DST_BLST error { yyerror("boolean value expected"); }
... ...
@@ -27,20 +27,55 @@
27 27
  * History
28 28
  * -------
29 29
  *  2007-12-03	Initial version (Miklos)
30
+ *  2008-01-31  added DNS resolver parameters (Miklos)
30 31
  */
31 32
 
32 33
 #include "dprint.h"
34
+#ifdef USE_DST_BLACKLIST
33 35
 #include "dst_blacklist.h"
36
+#endif
37
+#include "resolve.h"
38
+#ifdef USE_DNS_CACHE
39
+#include "dns_cache.h"
40
+#endif
34 41
 #include "cfg/cfg.h"
35 42
 #include "cfg_core.h"
36 43
 
37 44
 struct cfg_group_core default_core_cfg = {
38 45
 	L_DEFAULT, /*  print only msg. < L_WARN */
39 46
 #ifdef USE_DST_BLACKLIST
47
+	/* blacklist */
40 48
 	0, /* dst blacklist is disabled by default */
41 49
 	DEFAULT_BLST_TIMEOUT,
42 50
 	DEFAULT_BLST_MAX_MEM,
43 51
 #endif
52
+	/* resolver */
53
+#ifdef USE_IPV6
54
+	1,  /* dns_try_ipv6 -- on by default */
55
+#else
56
+	0,  /* dns_try_ipv6 -- off, if no ipv6 support */
57
+#endif
58
+	0,  /* dns_try_naptr -- off by default */
59
+	3,  /* udp transport preference (for naptr) */
60
+	2,  /* tcp transport preference (for naptr) */
61
+	1,  /* tls transport preference (for naptr) */
62
+	-1, /* dns_retr_time */
63
+	-1, /* dns_retr_no */
64
+	-1, /* dns_servers_no */
65
+	1,  /* dns_search_list */
66
+	1,  /* dns_search_fmatch */
67
+	0,  /* dns_reinit */
68
+	/* DNS cache */
69
+#ifdef USE_DNS_CACHE
70
+	0,  /* dns_cache_flags */
71
+	0,  /* use_dns_failover -- off by default */
72
+	0,  /* dns_srv_lb -- off by default */
73
+	DEFAULT_DNS_NEG_CACHE_TTL, /* neg. cache ttl */
74
+	DEFAULT_DNS_CACHE_MIN_TTL, /* minimum ttl */
75
+	DEFAULT_DNS_CACHE_MAX_TTL, /* maximum ttl */
76
+	DEFAULT_DNS_MAX_MEM, /* dns_cache_max_mem */
77
+	0, /* dns_cache_del_nonexp -- delete only expired entries by default */
78
+#endif
44 79
 };
45 80
 
46 81
 void	*core_cfg = &default_core_cfg;
... ...
@@ -48,6 +83,7 @@ void	*core_cfg = &default_core_cfg;
48 48
 cfg_def_t core_cfg_def[] = {
49 49
 	{"debug",	CFG_VAR_INT,	0, 0, 0, 0, "debug level"},
50 50
 #ifdef USE_DST_BLACKLIST
51
+	/* blacklist */
51 52
 	{"use_dst_blacklist",	CFG_VAR_INT,	0, 0, 0, 0,
52 53
 		"enable/disable destination blacklisting"},
53 54
 	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
... ...
@@ -55,5 +91,64 @@ cfg_def_t core_cfg_def[] = {
55 55
 	{"dst_blacklist_mem",	CFG_VAR_INT,	0, 0, blst_max_mem_fixup, 0,
56 56
 		"maximum shared memory amount (in KB) used for keeping the blacklisted destinations"},
57 57
 #endif
58
+	/* resolver */
59
+#ifdef USE_DNS_CACHE
60
+	{"dns_try_ipv6",	CFG_VAR_INT,	0, 1, dns_try_ipv6_fixup, fix_dns_flags,
61
+#else
62
+	{"dns_try_ipv6",	CFG_VAR_INT,	0, 1, dns_try_ipv6_fixup, 0,
63
+#endif
64
+		"enable/disable IPv6 DNS lookups"},
65
+#ifdef USE_DNS_CACHE
66
+	{"dns_try_naptr",	CFG_VAR_INT,	0, 1, 0, fix_dns_flags,
67
+#else
68
+	{"dns_try_naptr",	CFG_VAR_INT,	0, 1, 0, 0,
69
+#endif
70
+		"enable/disable NAPTR DNS lookups"},
71
+	{"dns_udp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
72
+		"udp protocol preference when doing NAPTR lookups"},
73
+	{"dns_tcp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
74
+		"tcp protocol preference when doing NAPTR lookups"},
75
+	{"dns_tls_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
76
+		"tls protocol preference when doing NAPTR lookups"},
77
+	{"dns_retr_time",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
78
+		"time in s before retrying a dns request"},
79
+	{"dns_retr_no",		CFG_VAR_INT,	0, 0, 0, resolv_reinit,
80
+		"number of dns retransmissions before giving up"},
81
+	{"dns_servers_no",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
82
+		"how many dns servers from the ones defined in "
83
+		"/etc/resolv.conf will be used"},
84
+	{"dns_use_search_list",	CFG_VAR_INT,	0, 1, 0, resolv_reinit,
85
+		"if set to 0, the search list in /etc/resolv.conf is ignored"},
86
+	{"dns_search_full_match",	CFG_VAR_INT,	0, 1, 0, 0,
87
+		"enable/disable domain name checks against the search list "
88
+		"in DNS answers"},
89
+	{"dns_reinit",		CFG_VAR_INT|CFG_INPUT_INT,	1, 1, dns_reinit_fixup, resolv_reinit,
90
+		"set to 1 in order to reinitialize the DNS resolver"},
91
+	/* DNS cache */
92
+#ifdef USE_DNS_CACHE
93
+	{"dns_cache_flags",	CFG_VAR_INT,	0, 4, 0, fix_dns_flags,
94
+		"dns cache specific resolver flags "
95
+		"(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},
96
+	{"use_dns_failover",	CFG_VAR_INT,	0, 1, use_dns_failover_fixup, 0,
97
+		"enable/disable dns failover in case the destination "
98
+		"resolves to multiple ip addresses and/or multiple SRV records "
99
+		"(depends on use_dns_cache)"},
100
+	{"dns_srv_lb",		CFG_VAR_INT,	0, 1, 0, fix_dns_flags,
101
+		"enable/disable load balancing to different srv records "
102
+		"of the same priority based on the srv records weights "
103
+		"(depends on dns_failover)"},
104
+	{"dns_cache_negative_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
105
+		"time to live for negative results (\"not found\") "
106
+		"in seconds. Use 0 to disable"},
107
+	{"dns_cache_min_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
108
+		"minimum accepted time to live for a record, in seconds"},
109
+	{"dns_cache_max_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
110
+		"maximum accepted time to live for a record, in seconds"},
111
+	{"dns_cache_mem",	CFG_VAR_INT,	0, 0, dns_cache_max_mem_fixup, 0,
112
+		"maximum memory used for the dns cache in Kb"},
113
+	{"dns_cache_del_nonexp",	CFG_VAR_INT,	0, 1, 0, 0,
114
+		"allow deletion of non-expired records from the cache when "
115
+		"there is no more space left for new ones"},
116
+#endif
58 117
 	{0, 0, 0, 0, 0, 0}
59 118
 };
... ...
@@ -47,11 +47,35 @@ extern void	*core_cfg;
47 47
 struct cfg_group_core {
48 48
 	int	debug;
49 49
 #ifdef USE_DST_BLACKLIST
50
+	/* blacklist */
50 51
 	int	use_dst_blacklist; /* 1 if blacklist is enabled */
51 52
 	unsigned int	blst_timeout; /* blacklist entry ttl */
52 53
 	unsigned int	blst_max_mem; /* maximum memory used for the
53 54
 					blacklist entries */
54 55
 #endif
56
+	/* resolver */
57
+	int dns_try_ipv6;
58
+	int dns_try_naptr;
59
+	int dns_udp_pref;
60
+	int dns_tcp_pref;
61
+	int dns_tls_pref;
62
+	int dns_retr_time;
63
+	int dns_retr_no;
64
+	int dns_servers_no;
65
+	int dns_search_list;
66
+	int dns_search_fmatch;
67
+	int dns_reinit;
68
+	/* DNS cache */
69
+#ifdef USE_DNS_CACHE
70
+	int dns_cache_flags;
71
+	int use_dns_failover;
72
+	int dns_srv_lb;
73
+	unsigned int dns_neg_cache_ttl;
74
+	unsigned int dns_cache_min_ttl;
75
+	unsigned int dns_cache_max_ttl;
76
+	unsigned int dns_cache_max_mem;
77
+	int dns_cache_del_nonexp;
78
+#endif
55 79
 };
56 80
 
57 81
 extern struct cfg_group_core default_core_cfg;
... ...
@@ -39,6 +39,8 @@
39 39
  *		of the cache (Miklos)
40 40
  *  2007-07-30  DNS cache measurements added (Gergo)
41 41
  *  2007-08-17  dns_cache_del_nonexp config option is introduced (Miklos)
42
+ *  2008-02-04  DNS cache options are adapted for the configuration
43
+ *		framework (Miklos)
42 44
  */
43 45
 
44 46
 #ifdef USE_DNS_CACHE
... ...
@@ -48,6 +50,7 @@
48 48
 #endif
49 49
 
50 50
 #include "globals.h"
51
+#include "cfg_core.h"
51 52
 #include "dns_cache.h"
52 53
 #include "dns_wrappers.h"
53 54
 #include "compiler_opt.h"
... ...
@@ -79,10 +82,6 @@
79 79
 							   dns answer*/
80 80
 
81 81
 #define DNS_HASH_SIZE	1024 /* must be <= 65535 */
82
-#define DEFAULT_DNS_NEG_CACHE_TTL 60 /* 1 min. */
83
-#define DEFAULT_DNS_CACHE_MIN_TTL 0 /* (disabled) */
84
-#define DEFAULT_DNS_CACHE_MAX_TTL ((unsigned int)(-1)) /* (maxint) */
85
-#define DEFAULT_DNS_MAX_MEM 500 /* 500 Kb */
86 82
 #define DEFAULT_DNS_TIMER_INTERVAL 120  /* 2 min. */
87 83
 #define DNS_HE_MAX_ADDR 10  /* maxium addresses returne in a hostent struct */
88 84
 #define MAX_CNAME_CHAIN  10
... ...
@@ -91,16 +90,9 @@
91 91
 
92 92
 static gen_lock_t* dns_hash_lock=0;
93 93
 static volatile unsigned int *dns_cache_mem_used=0; /* current mem. use */
94
-unsigned int dns_cache_max_mem=DEFAULT_DNS_MAX_MEM; /* maximum memory used for
95
-													 the cached entries */
96
-unsigned int dns_neg_cache_ttl=DEFAULT_DNS_NEG_CACHE_TTL; /* neg. cache ttl */
97
-unsigned int dns_cache_max_ttl=DEFAULT_DNS_CACHE_MAX_TTL; /* maximum ttl */
98
-unsigned int dns_cache_min_ttl=DEFAULT_DNS_CACHE_MIN_TTL; /* minimum ttl */
99 94
 unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
100 95
 int dns_flags=0; /* default flags used for the  dns_*resolvehost
101 96
                     (compatibility wrappers) */
102
-int dns_srv_lb=0; /* off by default */
103
-int dns_cache_del_nonexp=0; /* delete only expired entries by default */
104 97
 
105 98
 #ifdef USE_DNS_CACHE_STATS
106 99
 struct t_dns_cache_stats* dns_cache_stats=0;
... ...
@@ -109,8 +101,12 @@ struct t_dns_cache_stats* dns_cache_stats=0;
109 109
 #define LOCK_DNS_HASH()		lock_get(dns_hash_lock)
110 110
 #define UNLOCK_DNS_HASH()	lock_release(dns_hash_lock)
111 111
 
112
-#define FIX_TTL(t)  (((t)<dns_cache_min_ttl)?dns_cache_min_ttl: \
113
-						(((t)>dns_cache_max_ttl)?dns_cache_max_ttl:(t)))
112
+#define FIX_TTL(t) \
113
+	(((t)<cfg_get(core, core_cfg, dns_cache_min_ttl))? \
114
+		cfg_get(core, core_cfg, dns_cache_min_ttl): \
115
+		(((t)>cfg_get(core, core_cfg, dns_cache_max_ttl))? \
116
+			cfg_get(core, core_cfg, dns_cache_max_ttl): \
117
+			(t)))
114 118
 
115 119
 
116 120
 struct dns_hash_head{
... ...
@@ -216,8 +212,8 @@ static ticks_t dns_timer(ticks_t ticks, struct timer_ln* tl, void* data)
216 216
 	if (atomic_get(dns_servers_up) == 0)
217 217
 		return (ticks_t)(-1);
218 218
 #endif
219
-	if (*dns_cache_mem_used>12*(dns_cache_max_mem/16)){ /* ~ 75% used */
220
-		dns_cache_free_mem(dns_cache_max_mem/2, 1);
219
+	if (*dns_cache_mem_used>12*(cfg_get(core, core_cfg, dns_cache_max_mem)/16)){ /* ~ 75% used */
220
+		dns_cache_free_mem(cfg_get(core, core_cfg, dns_cache_max_mem)/2, 1);
221 221
 	}else{
222 222
 		dns_cache_clean(-1, 1); /* all the table, only expired entries */
223 223
 		/* TODO: better strategy? */
... ...
@@ -265,7 +261,62 @@ void destroy_dns_cache()
265 265
 	}
266 266
 }
267 267
 
268
+/* set the value of dns_flags */
269
+void fix_dns_flags(str *name)
270
+{
271
+	/* restore the original value of dns_cache_flags first
272
+	 * (DNS_IPV4_ONLY may have been set only because dns_try_ipv6
273
+	 * was disabled, and the flag must be cleared when
274
+	 * dns_try_ipv6 is enabled) (Miklos)
275
+	 */
276
+	dns_flags = cfg_get(core, core_cfg, dns_cache_flags) & 7;
268 277
 
278
+	if (cfg_get(core, core_cfg, dns_try_ipv6)==0){
279
+		dns_flags|=DNS_IPV4_ONLY;
280
+	}
281
+	if (dns_flags & DNS_IPV4_ONLY){
282
+		dns_flags&=~(DNS_IPV6_ONLY|DNS_IPV6_FIRST);
283
+	}
284
+	if (cfg_get(core, core_cfg, dns_srv_lb)){
285
+#ifdef DNS_SRV_LB
286
+		dns_flags|=DNS_SRV_RR_LB;
287
+#else
288
+		LOG(L_WARN, "WARING: fix_dns_flags: SRV loadbalaning is set, but"
289
+					" support for it is not compiled -- ignoring\n");
290
+#endif
291
+	}
292
+	if (cfg_get(core, core_cfg, dns_try_naptr)) {
293
+#ifndef USE_NAPTR
294
+	LOG(L_WARN, "WARING: fix_dns_flags: NAPTR support is enabled, but"
295
+				" support for it is not compiled -- ignoring\n");
296
+#endif
297
+		dns_flags|=DNS_TRY_NAPTR;
298
+	}
299
+}
300
+
301
+/* fixup function for use_dns_failover
302
+ * verifies that use_dns_cache is set to 1
303
+ */
304
+int use_dns_failover_fixup(void *handle, str *name, void **val)
305
+{
306
+	if ((int)(long)(*val) && !use_dns_cache) {
307
+		LOG(L_ERR, "ERROR: use_dns_failover_fixup(): "
308
+			"DNS cache is turned off, failover cannot be enabled. "
309
+			"(set use_dns_cache to 1)\n");
310
+		return -1;
311
+	}
312
+	return 0;
313
+}
314
+
315
+/* KByte to Byte conversion */
316
+int dns_cache_max_mem_fixup(void *handle, str *name, void **val)
317
+{
318
+	unsigned int    u;
319
+
320
+	u = ((unsigned int)(long)(*val))<<10;
321
+	(*val) = (void *)(long)u;
322
+	return 0;
323
+}
269 324
 
270 325
 int init_dns_cache()
271 326
 {
... ...
@@ -322,29 +373,10 @@ int init_dns_cache()
322 322
 #endif
323 323
 
324 324
 	/* fix options */
325
-	dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
325
+	default_core_cfg.dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
326 326
 	/* fix flags */
327
-	if (dns_try_ipv6==0){
328
-		dns_flags|=DNS_IPV4_ONLY;
329
-	}
330
-	if (dns_flags & DNS_IPV4_ONLY){
331
-		dns_flags&=~(DNS_IPV6_ONLY|DNS_IPV6_FIRST);
332
-	}
333
-	if (dns_srv_lb){
334
-#ifdef DNS_SRV_LB
335
-		dns_flags|=DNS_SRV_RR_LB;
336
-#else
337
-		LOG(L_WARN, "WARING: dns_cache_init: SRV loadbalaning is set, but"
338
-					" support for it is not compiled -- ignoring\n");
339
-#endif
340
-	}
341
-	if (dns_try_naptr){
342
-#ifndef USE_NAPTR
343
-	LOG(L_WARN, "WARING: dns_cache_init: NAPTR support is enabled, but"
344
-				" support for it is not compiled -- ignoring\n");
345
-#endif
346
-		dns_flags|=DNS_TRY_NAPTR;
347
-	}
327
+	fix_dns_flags(NULL);
328
+
348 329
 	dns_timer_h=timer_alloc();
349 330
 	if (dns_timer_h==0){
350 331
 		ret=E_OUT_OF_MEM;
... ...
@@ -599,10 +631,8 @@ inline static int dns_cache_clean(unsigned int no, int expired_only)
599 599
 	if (!expired_only){
600 600
 		for(h=start; h!=(start+DNS_HASH_SIZE); h++){
601 601
 			clist_foreach_safe(&dns_hash[h%DNS_HASH_SIZE], e, t, next){
602
-				if  ((s_ticks_t)(now-e->expire)>=0){
603
-					_dns_hash_remove(e);
604
-					deleted++;
605
-				}
602
+				_dns_hash_remove(e);
603
+				deleted++;
606 604
 				n++;
607 605
 				if (n>=no) goto skip;
608 606
 			}
... ...
@@ -714,14 +744,15 @@ inline static int dns_cache_add(struct dns_hash_entry* e)
714 714
 
715 715
 	/* check space */
716 716
 	/* atomic_add_long(dns_cache_total_used, e->size); */
717
-	if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
717
+	if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
718 718
 #ifdef USE_DNS_CACHE_STATS
719 719
 		dns_cache_stats[process_no].dc_lru_cnt++;
720 720
 #endif
721 721
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
722 722
 		/* free ~ 12% of the cache */
723
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
724
-		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
723
+		dns_cache_free_mem(*dns_cache_mem_used/16*14,
724
+					!cfg_get(core, core_cfg, dns_cache_del_nonexp));
725
+		if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
725 726
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
726 727
 			return -1;
727 728
 		}
... ...
@@ -753,16 +784,17 @@ inline static int dns_cache_add_unsafe(struct dns_hash_entry* e)
753 753
 
754 754
 	/* check space */
755 755
 	/* atomic_add_long(dns_cache_total_used, e->size); */
756
-	if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
756
+	if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
757 757
 #ifdef USE_DNS_CACHE_STATS
758 758
 		dns_cache_stats[process_no].dc_lru_cnt++;
759 759
 #endif
760 760
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
761 761
 		/* free ~ 12% of the cache */
762 762
 		UNLOCK_DNS_HASH();
763
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
763
+		dns_cache_free_mem(*dns_cache_mem_used/16*14,
764
+					!cfg_get(core, core_cfg, dns_cache_del_nonexp));
764 765
 		LOCK_DNS_HASH();
765
-		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
766
+		if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
766 767
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
767 768
 			return -1;
768 769
 		}
... ...
@@ -1672,8 +1704,8 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
1672 1672
 		l=dns_cache_mk_rd_entry2(records);
1673 1673
 #endif
1674 1674
 		free_rdata_list(records);
1675
-	}else if (dns_neg_cache_ttl){
1676
-		e=dns_cache_mk_bad_entry(name, type, dns_neg_cache_ttl, DNS_BAD_NAME);
1675
+	}else if (cfg_get(core, core_cfg, dns_neg_cache_ttl)){
1676
+		e=dns_cache_mk_bad_entry(name, type, cfg_get(core, core_cfg, dns_neg_cache_ttl), DNS_BAD_NAME);
1677 1677
 		atomic_set(&e->refcnt, 1); /* 1 because we return a ref. to it */
1678 1678
 		dns_cache_add(e); /* refcnt++ inside*/
1679 1679
 		goto end;
... ...
@@ -3144,7 +3176,7 @@ void dns_cache_mem_info(rpc_t* rpc, void* ctx)
3144 3144
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
3145 3145
 		return;
3146 3146
 	}
3147
-	rpc->add(ctx, "dd",  *dns_cache_mem_used, dns_cache_max_mem);
3147
+	rpc->add(ctx, "dd",  *dns_cache_mem_used, cfg_get(core, core_cfg, dns_cache_max_mem));
3148 3148
 }
3149 3149
 
3150 3150
 
... ...
@@ -53,6 +53,11 @@
53 53
 #error "DNS WATCHDOG requires DNS CACHE support (define USE_DNS_CACHE)"
54 54
 #endif
55 55
 
56
+#define DEFAULT_DNS_NEG_CACHE_TTL 60 /* 1 min. */
57
+#define DEFAULT_DNS_CACHE_MIN_TTL 0 /* (disabled) */
58
+#define DEFAULT_DNS_CACHE_MAX_TTL ((unsigned int)(-1)) /* (maxint) */
59
+#define DEFAULT_DNS_MAX_MEM 500 /* 500 Kb */
60
+
56 61
 /* uncomment the define below for SRV weight based load balancing */
57 62
 #define DNS_SRV_LB
58 63
 
... ...
@@ -173,6 +178,9 @@ struct dns_srv_handle{
173 173
 
174 174
 const char* dns_strerror(int err);
175 175
 
176
+void fix_dns_flags(str *name);
177
+int use_dns_failover_fixup(void *handle, str *name, void **val);
178
+int dns_cache_max_mem_fixup(void *handle, str *name, void **val);
176 179
 int init_dns_cache();
177 180
 #ifdef USE_DNS_CACHE_STATS
178 181
 int init_dns_cache_stats(int iproc_num);
... ...
@@ -319,7 +319,7 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
319 319
 
320 320
 	if(dst){
321 321
 #ifdef USE_DNS_FAILOVER
322
-		if (use_dns_failover){
322
+		if (cfg_get(core, core_cfg, use_dns_failover)){
323 323
 			dns_srv_handle_init(&dns_srv_h);
324 324
 			err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port,
325 325
 									&send_info->proto, dns_flags);
... ...
@@ -454,7 +454,8 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
454 454
 			goto end;
455 455
 		}
456 456
 #ifdef USE_DNS_FAILOVER
457
-	}while(dst && use_dns_failover && dns_srv_handle_next(&dns_srv_h, err) && 
457
+	}while(dst && cfg_get(core, core_cfg, use_dns_failover) &&
458
+			dns_srv_handle_next(&dns_srv_h, err) && 
458 459
 			((err=dns_sip_resolve2su(&dns_srv_h, &send_info->to, dst, port,
459 460
 								  &send_info->proto, dns_flags))==0));
460 461
 	if ((err!=0) && (err!=-E_DNS_EOR)){
... ...
@@ -471,7 +472,7 @@ error:
471 471
 	STATS_TX_DROPS;
472 472
 end:
473 473
 #ifdef USE_DNS_FAILOVER
474
-	if (dst && use_dns_failover){
474
+	if (dst && cfg_get(core, core_cfg, use_dns_failover)){
475 475
 				dns_srv_handle_put(&dns_srv_h);
476 476
 	}
477 477
 #endif
... ...
@@ -190,26 +190,11 @@ extern int rt_timer1_policy; /* "fast" timer, SCHED_OTHER */
190 190
 extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
191 191
 
192 192
 
193
-
194
-/* resolver */
195
-extern int dns_retr_time;
196
-extern int dns_retr_no;
197
-extern int dns_servers_no;
198
-extern int dns_search_list;
199
-extern int dns_search_fmatch;
200 193
 #ifdef USE_DNS_CACHE
201 194
 extern int use_dns_cache; /* 1 if the cache is enabled, 0 otherwise */
202
-extern int use_dns_failover; /* 1 if failover is enabled, 0 otherwise */
203
-extern unsigned int dns_cache_max_mem; /* maximum memory used for the cached
204
-										  entries*/
205
-extern unsigned int dns_neg_cache_ttl; /* neg. cache ttl */
206
-extern unsigned int dns_cache_max_ttl; /* maximum ttl */
207
-extern unsigned int dns_cache_min_ttl; /* minimum ttl */
208 195
 extern unsigned int dns_timer_interval; /* gc timer interval in s */
209 196
 extern int dns_flags; /* default flags used for the  dns_*resolvehost
210 197
                     (compatibility wrappers) */
211
-extern int dns_srv_lb; /* default SRV LB support value */
212
-extern int dns_cache_del_nonexp; /* delete non-expired values from the cache when it is full */
213 198
 
214 199
 #ifdef USE_DNS_CACHE_STATS
215 200
 struct t_dns_cache_stats{
... ...
@@ -374,7 +374,6 @@ int mcast_ttl = -1; /* if -1, don't touch it, use the default (usually 1) */
374 374
 #endif /* USE_MCAST */
375 375
 #ifdef USE_DNS_CACHE
376 376
 int use_dns_cache=1; /* 1 if the cache is enabled, 0 otherwise */
377
-int use_dns_failover=0; /* 1 if failover is enabled, 0 otherwise */
378 377
 #endif
379 378
 
380 379
 int tos = IPTOS_LOWDELAY;
... ...
@@ -1279,7 +1278,6 @@ int main(int argc, char** argv)
1279 1279
 	int rfd;
1280 1280
 	int debug_save, debug_flag;
1281 1281
 	int dont_fork_cnt;
1282
-	int socket_types;
1283 1282
 
1284 1283
 	/*init*/
1285 1284
 	creator_pid = getpid();
... ...
@@ -1606,14 +1604,14 @@ try_again:
1606 1606
 			goto error;
1607 1607
 		}
1608 1608
 	}
1609
-	if (fix_all_socket_lists(&socket_types)!=0){
1609
+	if (fix_all_socket_lists()!=0){
1610 1610
 		fprintf(stderr,  "failed to initialize list addresses\n");
1611 1611
 		goto error;
1612 1612
 	}
1613
-	if (dns_try_ipv6 && !(socket_types & SOCKET_T_IPV6)){
1613
+	if (default_core_cfg.dns_try_ipv6 && !(socket_types & SOCKET_T_IPV6)){
1614 1614
 		/* if we are not listening on any ipv6 address => no point
1615 1615
 		 * to try to resovle ipv6 addresses */
1616
-		dns_try_ipv6=0;
1616
+		default_core_cfg.dns_try_ipv6=0;
1617 1617
 	}
1618 1618
 	/* print all the listen addresses */
1619 1619
 	printf("Listening on \n");
... ...
@@ -1660,7 +1658,7 @@ try_again:
1660 1660
 		goto error;
1661 1661
 	}
1662 1662
 	if (use_dns_cache==0)
1663
-		use_dns_failover=0; /* cannot work w/o dns_cache support */
1663
+		default_core_cfg.use_dns_failover=0; /* cannot work w/o dns_cache support */
1664 1664
 #ifdef USE_DNS_CACHE_STATS
1665 1665
 	/* preinitializing before the nubmer of processes is determined */
1666 1666
 	if (init_dns_cache_stats(1)<0){
... ...
@@ -102,6 +102,7 @@
102 102
 #include "config.h"
103 103
 #ifdef USE_DNS_FAILOVER
104 104
 #include "../../dns_cache.h"
105
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
105 106
 #endif
106 107
 #ifdef USE_DST_BLACKLIST
107 108
 #include "../../dst_blacklist.h"
... ...
@@ -395,7 +396,7 @@ int add_uac_dns_fallback( struct cell *t, struct sip_msg* msg,
395 395
 	int ret;
396 396
 	
397 397
 	ret=-1;
398
-	if (use_dns_failover && 
398
+	if (cfg_get(core, core_cfg, use_dns_failover) && 
399 399
 			!((t->flags & T_DONT_FORK) || uac_dont_fork(old_uac)) &&
400 400
 			dns_srv_handle_next(&old_uac->dns_h, 0)){
401 401
 			if (lock_replies){
... ...
@@ -674,7 +675,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
674 674
 #ifdef USE_DNS_FAILOVER
675 675
 			/* if the destination resolves to more ips, add another
676 676
 			 *  branch/uac */
677
-			if (use_dns_failover){
677
+			if (cfg_get(core, core_cfg, use_dns_failover)){
678 678
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
679 679
 				if (ret>=0){
680 680
 					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 ,
709 709
 #ifdef USE_DNS_FAILOVER
710 710
 			/* if the destination resolves to more ips, add another
711 711
 			 *  branch/uac */
712
-			if (use_dns_failover){
712
+			if (cfg_get(core, core_cfg, use_dns_failover)){
713 713
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
714 714
 				if (ret>=0){
715 715
 					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 ,
744 744
 #ifdef USE_DNS_FAILOVER
745 745
 		/* if the destination resolves to more ips, add another
746 746
 		 *  branch/uac */
747
-		if (use_dns_failover){
747
+		if (cfg_get(core, core_cfg, use_dns_failover)){
748 748
 			ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
749 749
 			if (ret>=0){
750 750
 				/* success, return new branch */
... ...
@@ -66,6 +66,7 @@
66 66
 #include "uac.h"
67 67
 #ifdef USE_DNS_FAILOVER
68 68
 #include "../../dns_cache.h"
69
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
69 70
 #endif
70 71
 
71 72
 
... ...
@@ -598,7 +599,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans,
598 598
 	
599 599
 	 /* via */
600 600
 #ifdef USE_DNS_FAILOVER
601
-	if (use_dns_failover){
601
+	if (cfg_get(core, core_cfg, use_dns_failover)){
602 602
 		dns_srv_handle_init(&dns_h);
603 603
 		if ((uri2dst(&dns_h , dst, rpl, &next_hop, PROTO_NONE)==0) ||
604 604
 				(dst->send_sock==0)){
... ...
@@ -110,6 +110,10 @@
110 110
 #ifdef USE_DST_BLACKLIST
111 111
 #include "../../dst_blacklist.h"
112 112
 #endif
113
+#ifdef USE_DNS_FAILOVER
114
+#include "../../dns_cache.h"
115
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
116
+#endif
113 117
 
114 118
 #include "defs.h"
115 119
 #include "h_table.h"
... ...
@@ -415,7 +419,7 @@ static int send_local_ack(struct sip_msg* msg, str* next_hop,
415 415
 		return -1;
416 416
 	}
417 417
 #ifdef USE_DNS_FAILOVER
418
-	if (use_dns_failover){
418
+	if (cfg_get(core, core_cfg, use_dns_failover)){
419 419
 		dns_srv_handle_init(&dns_h);
420 420
 		if ((uri2dst(&dns_h, &dst, msg,  next_hop, PROTO_NONE)==0) || 
421 421
 				(dst.send_sock==0)){
... ...
@@ -1837,7 +1841,10 @@ int reply_received( struct sip_msg  *p_msg )
1837 1837
 		 *  This code is out of LOCK_REPLIES() to minimize the time the
1838 1838
 		 *  reply lock is held (the lock won't be held while sending the
1839 1839
 		 *   message)*/
1840
-		if (use_dns_failover && (msg_status==503) && uac->request.t_active){
1840
+		if (cfg_get(core, core_cfg, use_dns_failover) && 
1841
+			(msg_status==503) &&
1842
+			uac->request.t_active
1843
+		) {
1841 1844
 			branch_ret=add_uac_dns_fallback(t, t->uas.request, uac, 1);
1842 1845
 			prev_branch=-1;
1843 1846
 			while((branch_ret>=0) &&(branch_ret!=prev_branch)){
... ...
@@ -138,6 +138,7 @@
138 138
 #include "t_hooks.h"
139 139
 #ifdef USE_DNS_FAILOVER
140 140
 #include "t_fwd.h" /* t_send_branch */
141
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
141 142
 #endif
142 143
 #ifdef USE_DST_BLACKLIST
143 144
 #include "../../dst_blacklist.h"
... ...
@@ -467,7 +468,7 @@ inline static void final_response_handler(	struct retr_buf* r_buf,
467 467
 		/* if this is an invite, the destination resolves to more ips, and
468 468
 		 *  it still hasn't passed more than fr_inv_timeout since we
469 469
 		 *  started, add another branch/uac */
470
-		if (use_dns_failover){
470
+		if (cfg_get(core, core_cfg, use_dns_failover)){
471 471
 			now=get_ticks_raw();
472 472
 			if ((s_ticks_t)(t->end_of_life-now)>0){
473 473
 				branch_ret=add_uac_dns_fallback(t, t->uas.request,
... ...
@@ -77,6 +77,10 @@
77 77
 #include "callid.h"
78 78
 #include "uac.h"
79 79
 #include "t_stats.h"
80
+#ifdef USE_DNS_FAILOVER
81
+#include "../../dns_cache.h"
82
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
83
+#endif
80 84
 
81 85
 
82 86
 #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,
217 217
 			uac_r->dialog->hooks.next_hop->s);
218 218
 	/* it's a new message, so we will take the default socket */
219 219
 #ifdef USE_DNS_FAILOVER
220
-	if (use_dns_failover){
220
+	if (cfg_get(core, core_cfg, use_dns_failover)){
221 221
 		dns_srv_handle_init(&dns_h);
222 222
 		if ((uri2dst(&dns_h, &dst, 0, uac_r->dialog->hooks.next_hop, PROTO_NONE)==0)
223 223
 				|| (dst.send_sock==0)){
... ...
@@ -58,6 +58,7 @@
58 58
 #include "../../resolve.h"
59 59
 #ifdef USE_DNS_FAILOVER
60 60
 #include "../../dns_cache.h"
61
+#include "../../cfg_core.h" /* cfg_get(core, core_cfg, use_dns_failover) */
61 62
 #endif
62 63
 
63 64
 /* a forced_proto takes precedence if != PROTO_NONE */
... ...
@@ -270,7 +271,7 @@ inline static struct dest_info *uri2dst(struct dest_info* dst,
270 270
 #endif
271 271
 		host=&parsed_uri.host;
272 272
 #ifdef USE_DNS_FAILOVER
273
-	if (use_dns_failover && dns_h){
273
+	if (cfg_get(core, core_cfg, use_dns_failover) && dns_h){
274 274
 		ip_found=0;
275 275
 		do{
276 276
 			/* try all the ips until we find a good send socket */
... ...
@@ -41,6 +41,8 @@
41 41
  *              new option dns_search_full_match (default on) controls
42 42
  *              whether rest of the name is matched against search list
43 43
  *              or blindly accepted (better performance but exploitable)
44
+ *  2008-01-31  resolver options use the configuration framework, and the
45
+ *		resolver is reinitialized when the options change (Miklos)
44 46
  */ 
45 47
 
46 48
 
... ...
@@ -57,6 +59,8 @@
57 57
 #include "ip_addr.h"
58 58
 #include "error.h"
59 59
 #include "globals.h" /* tcp_disable, tls_disable a.s.o */
60
+#include "cfg_core.h"
61
+#include "socket_info.h"
60 62
 
61 63
 #ifdef USE_DNS_CACHE
62 64
 #include "dns_cache.h"
... ...
@@ -68,29 +72,11 @@
68 68
 #define local_malloc pkg_malloc
69 69
 #define local_free   pkg_free
70 70
 
71
-#ifdef USE_IPV6
72
-int dns_try_ipv6=1; /* default on */
73
-#else
74
-int dns_try_ipv6=0; /* off, if no ipv6 support */
75
-#endif
76
-int dns_try_naptr=0;  /* off by default */
77
-
78
-int dns_udp_pref=3;  /* udp transport preference (for naptr) */
79
-int dns_tcp_pref=2;  /* tcp transport preference (for naptr) */
80
-int dns_tls_pref=1;  /* tls transport preference (for naptr) */
81
-
82 71
 #ifdef USE_NAPTR
83 72
 #define PROTO_LAST  PROTO_SCTP
84 73
 static int naptr_proto_pref[PROTO_LAST];
85 74
 #endif
86 75
 
87
-/* declared in globals.h */
88
-int dns_retr_time=-1;
89
-int dns_retr_no=-1;
90
-int dns_servers_no=-1;
91
-int dns_search_list=-1;
92
-int dns_search_fmatch=-1;
93
-
94 76
 #ifdef USE_NAPTR
95 77
 void init_naptr_proto_prefs()
96 78
 {
... ...
@@ -99,14 +85,28 @@ void init_naptr_proto_prefs()
99 99
 		BUG("init_naptr_proto_prefs: array too small \n");
100 100
 		return;
101 101
 	}
102
-	naptr_proto_pref[PROTO_UDP]=dns_udp_pref;
103
-	naptr_proto_pref[PROTO_TCP]=dns_tcp_pref;
104
-	naptr_proto_pref[PROTO_TLS]=dns_tls_pref;
102
+	naptr_proto_pref[PROTO_UDP]=cfg_get(core, core_cfg, dns_udp_pref);
103
+	naptr_proto_pref[PROTO_TCP]=cfg_get(core, core_cfg, dns_tcp_pref);
104
+	naptr_proto_pref[PROTO_TLS]=cfg_get(core, core_cfg, dns_tls_pref);
105 105
 }
106 106
 
107 107
 #endif /* USE_NAPTR */
108 108
 
109
+#ifdef DNS_WATCHDOG_SUPPORT
110
+static on_resolv_reinit	on_resolv_reinit_cb = NULL;
109 111
 
112
+/* register the callback function */
113
+int register_resolv_reinit_cb(on_resolv_reinit cb)
114
+{
115
+	if (on_resolv_reinit_cb) {
116
+		LOG(L_ERR, "ERROR: register_resolv_reinit_cb(): "
117
+			"callback function has been already registered\n");
118
+		return -1;
119
+	}
120
+	on_resolv_reinit_cb = cb;
121
+	return 0;
122
+}
123
+#endif
110 124
 
111 125
 /* init. the resolver
112 126
  * params: retr_time  - time before retransmitting (must be >0)
... ...
@@ -122,30 +122,82 @@ void init_naptr_proto_prefs()
122 122
  * will be used. See also resolv.conf(5).
123 123
  * returns: 0 on success, -1 on error
124 124
  */
125
-int resolv_init()
125
+static int _resolv_init()
126 126
 {
127 127
 	res_init();
128 128
 #ifdef HAVE_RESOLV_RES
129
-	if (dns_retr_time>0)
130
-		_res.retrans=dns_retr_time;
131
-	if (dns_retr_no>0)
132
-		_res.retry=dns_retr_no;
133
-	if (dns_servers_no>=0)
134
-		_res.nscount=dns_servers_no;
135
-	if (dns_search_list==0)
129
+	if (cfg_get(core, core_cfg, dns_retr_time)>0)
130
+		_res.retrans=cfg_get(core, core_cfg, dns_retr_time);
131
+	if (cfg_get(core, core_cfg, dns_retr_no)>0)
132
+		_res.retry=cfg_get(core, core_cfg, dns_retr_no);
133
+	if (cfg_get(core, core_cfg, dns_servers_no)>=0)
134
+		_res.nscount=cfg_get(core, core_cfg, dns_servers_no);
135
+	if (cfg_get(core, core_cfg, dns_search_list)==0)
136 136
 		_res.options&=~(RES_DEFNAMES|RES_DNSRCH);
137 137
 #else
138 138
 #warning "no resolv timeout support"
139
-	LOG(L_WARN, "WARNING: resolv_init: no resolv options support - resolv"
139
+	LOG(L_WARN, "WARNING: _resolv_init: no resolv options support - resolv"
140 140
 			" options will be ignored\n");
141 141
 #endif
142
+	return 0;
143
+}
144
+
145
+/* wrapper function to initialize the resolver at startup */
146
+int resolv_init()
147
+{
148
+	_resolv_init();
149
+
142 150
 #ifdef USE_NAPTR
143 151
 	init_naptr_proto_prefs();
144 152
 #endif
145 153
 	return 0;
146 154
 }
147 155
 
156
+/* wrapper function to reinitialize the resolver
157
+ * This function must be called by each child process whenever
158
+ * a resolver option changes
159
+ */
160
+void resolv_reinit(str *name)
161
+{
162
+	_resolv_init();
163
+
164
+#ifdef DNS_WATCHDOG_SUPPORT
165
+	if (on_resolv_reinit_cb) on_resolv_reinit_cb();
166
+#endif
167
+	LOG(L_DBG, "DEBUG: resolv_reinit(): "
168
+		"DNS resolver has been reinitialized\n");
169
+}
170
+
171
+/* fixup function for dns_reinit variable
172
+ * (resets the variable to 0)
173
+ */
174
+int dns_reinit_fixup(void *handle, str *name, void **val)
175
+{
176
+	*val = (void *)(long)0;
177
+	return 0;
178
+}
179
+
180
+/* wrapper function to recalculate the naptr protocol preferences */
181
+void reinit_naptr_proto_prefs(str *name)
182
+{
183
+#ifdef USE_NAPTR
184
+	init_naptr_proto_prefs();
185
+#endif
186
+}
148 187
 
188
+/* fixup function for dns_try_ipv6
189
+ * verifies that SER really listens on an ipv6 interface
190
+ */
191
+int dns_try_ipv6_fixup(void *handle, str *name, void **val)
192
+{
193
+	if ((int)(long)(*val) && !(socket_types & SOCKET_T_IPV6)) {
194
+		LOG(L_ERR, "ERROR: dns_try_ipv6_fixup(): "
195
+			"SER does not listen on any ipv6 interface, "
196
+			"there is no point in resolving ipv6 addresses\n");
197
+		return -1;
198
+	}
199
+	return 0;
200
+}
149 201
 
150 202
  /*  skips over a domain name in a dns message
151 203
  *  (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)
459 459
 	int name_len;
460 460
 	struct rdata* fullname_rd;
461 461
 	
462
-	if (dns_search_list==0) {
462
+	if (cfg_get(core, core_cfg, dns_search_list)==0) {
463 463
 		search_list_used=0;
464 464
 		name_len=0;
465 465
 	} else {
... ...
@@ -574,7 +626,7 @@ again:
574 574
 			/* this is safe.... here was rec_name_len > name_len */
575 575
 			else if (rec_name[name_len]=='.') {
576 576
 #ifdef HAVE_RESOLV_RES
577
-				if ((dns_search_fmatch==0) ||
577
+				if ((cfg_get(core, core_cfg, dns_search_fmatch)==0) ||
578 578
 						(match_search_list(&_res, rec_name+name_len+1)!=0))
579 579
 #endif
580 580
 					fullname_rd=rd;
... ...
@@ -1221,7 +1273,7 @@ end:
1221 1221
 struct hostent* _sip_resolvehost(str* name, unsigned short* port, char* proto)
1222 1222
 {
1223 1223
 #ifdef USE_NAPTR
1224
-	if (dns_try_naptr)
1224
+	if (cfg_get(core, core_cfg, dns_try_naptr))
1225 1225
 		return naptr_sip_resolvehost(name, port, proto);
1226 1226
 #endif
1227 1227
 	return srv_sip_resolvehost(name, 0, port, proto, 0, 0);
... ...
@@ -159,12 +159,6 @@ struct rdata* get_record(char* name, int type, int flags);
159 159
 void free_rdata_list(struct rdata* head);
160 160
 
161 161
 
162
-extern int dns_try_ipv6;
163
-extern int dns_try_naptr;
164
-extern int dns_udp_pref;  /* udp transport preference (for naptr) */
165
-extern int dns_tcp_pref;  /* tcp transport preference (for naptr) */
166
-extern int dns_tls_pref;  /* tls transport preference (for naptr) */
167
-
168 162
 
169 163
 #define rev_resolvehost(ip)\
170 164
 					gethostbyaddr((char*)(ip)->u.addr, (ip)->len, (ip)->af)
... ...
@@ -382,7 +376,7 @@ static inline struct hostent* _resolvehost(char* name)
382 382
 	/* ipv4 */
383 383
 	he=gethostbyname(name);
384 384
 #ifdef USE_IPV6
385
-	if(he==0 && dns_try_ipv6){
385
+	if(he==0 && cfg_get(core, core_cfg, dns_try_ipv6)){
386 386
 #ifndef DNS_IP_HACK
387 387
 skip_ipv4:
388 388
 #endif
... ...
@@ -407,9 +401,27 @@ skip_ipv4:
407 407
 }
408 408
 
409 409
 
410
-
411 410
 int resolv_init();
412 411
 
412
+/* callback/fixup functions executed by the configuration framework */
413
+void resolv_reinit(str *name);
414
+int dns_reinit_fixup(void *handle, str *name, void **val);
415
+int dns_try_ipv6_fixup(void *handle, str *name, void **val);
416
+void reinit_naptr_proto_prefs(str *name);
417
+
418
+#ifdef DNS_WATCHDOG_SUPPORT
419
+/* callback function that is called by the child processes
420
+ * when they reinitialize the resolver
421
+ *
422
+ * Note, that this callback is called by each chiled process separately!!!
423
+ * If the callback is registered after forking, only the child process
424
+ * that installs the hook will call the callback.
425
+ */
426
+typedef void (*on_resolv_reinit)(void);
427
+int register_resolv_reinit_cb(on_resolv_reinit cb);
428
+#endif
429
+
430
+
413 431
 int sip_hostport2su(union sockaddr_union* su, str* host, unsigned short port,
414 432
 						char* proto);
415 433
 
... ...
@@ -715,18 +715,15 @@ error:
715 715
 	return -1;
716 716
 }
717 717
 
718
-
718
+int socket_types = 0;
719 719
 
720 720
 /* fix all 3 socket lists, fills socket_types if non-null
721 721
  * return 0 on success, -1 on error */
722
-int fix_all_socket_lists(int* socket_types)
722
+int fix_all_socket_lists()
723 723
 {
724 724
 	struct utsname myname;
725 725
 	int flags;
726 726
 	
727
-	if (socket_types)
728
-		*socket_types=0;
729
-	
730 727
 	if ((udp_listen==0)
731 728
 #ifdef USE_TCP
732 729
 			&& (tcp_listen==0)
... ...
@@ -771,8 +768,8 @@ int fix_all_socket_lists(int* socket_types)
771 771
 				" udp failed\n");
772 772
 		goto error;
773 773
 	}
774
-	if (flags && socket_types){
775
-		*socket_types|=flags|SOCKET_T_UDP;
774
+	if (flags){
775
+		socket_types|=flags|SOCKET_T_UDP;
776 776
 	}
777 777
 #ifdef USE_TCP
778 778
 	if (!tcp_disable && (fix_socket_list(&tcp_listen, &flags)!=0)){
... ...
@@ -780,8 +777,8 @@ int fix_all_socket_lists(int* socket_types)
780 780
 				" tcp failed\n");
781 781
 		goto error;
782 782
 	}
783
-	if (flags && socket_types){
784
-		*socket_types|=flags|SOCKET_T_TCP;
783
+	if (flags){
784
+		socket_types|=flags|SOCKET_T_TCP;
785 785
 	}
786 786
 #ifdef USE_TLS
787 787
 	if (!tls_disable && (fix_socket_list(&tls_listen, &flags)!=0)){
... ...
@@ -789,8 +786,8 @@ int fix_all_socket_lists(int* socket_types)
789 789
 				" tls failed\n");
790 790
 		goto error;
791 791
 	}
792
-	if (flags && socket_types){
793
-		*socket_types|=flags|SOCKET_T_TLS;
792
+	if (flags){
793
+		socket_types|=flags|SOCKET_T_TLS;
794 794
 	}
795 795
 #endif
796 796
 #endif
... ...
@@ -59,10 +59,11 @@ struct socket_info* tls_listen;
59 59
 #define SOCKET_T_TCP  8
60 60
 #define SOCKET_T_TLS 16
61 61
 
62
+extern int socket_types;
62 63
 
63 64
 int add_listen_iface(char* name, unsigned short port, unsigned short proto,
64 65
 							enum si_flags flags);
65
-int fix_all_socket_lists(int* socket_types);
66
+int fix_all_socket_lists();
66 67
 void print_all_socket_lists();
67 68
 void print_aliases();
68 69