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,19 +27,54 @@
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,
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 */
43 78
 #endif
44 79
 };
45 80
 
... ...
@@ -48,12 +83,72 @@ void	*core_cfg = &default_core_cfg;
48 83
 cfg_def_t core_cfg_def[] = {
49 84
 	{"debug",	CFG_VAR_INT,	0, 0, 0, 0, "debug level"},
50 85
 #ifdef USE_DST_BLACKLIST
86
+	/* blacklist */
51 87
 	{"use_dst_blacklist",	CFG_VAR_INT,	0, 0, 0, 0,
52 88
 		"enable/disable destination blacklisting"},
53 89
 	{"dst_blacklist_expire",	CFG_VAR_INT,	0, 0, 0, 0,
54 90
 		"how much time (in s) a blacklisted destination is kept in the list"},
55 91
 	{"dst_blacklist_mem",	CFG_VAR_INT,	0, 0, blst_max_mem_fixup, 0,
56 92
 		"maximum shared memory amount (in KB) used for keeping the blacklisted destinations"},
93
+#endif
94
+	/* resolver */
95
+#ifdef USE_DNS_CACHE
96
+	{"dns_try_ipv6",	CFG_VAR_INT,	0, 1, dns_try_ipv6_fixup, fix_dns_flags,
97
+#else
98
+	{"dns_try_ipv6",	CFG_VAR_INT,	0, 1, dns_try_ipv6_fixup, 0,
99
+#endif
100
+		"enable/disable IPv6 DNS lookups"},
101
+#ifdef USE_DNS_CACHE
102
+	{"dns_try_naptr",	CFG_VAR_INT,	0, 1, 0, fix_dns_flags,
103
+#else
104
+	{"dns_try_naptr",	CFG_VAR_INT,	0, 1, 0, 0,
105
+#endif
106
+		"enable/disable NAPTR DNS lookups"},
107
+	{"dns_udp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
108
+		"udp protocol preference when doing NAPTR lookups"},
109
+	{"dns_tcp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
110
+		"tcp protocol preference when doing NAPTR lookups"},
111
+	{"dns_tls_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
112
+		"tls protocol preference when doing NAPTR lookups"},
113
+	{"dns_retr_time",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
114
+		"time in s before retrying a dns request"},
115
+	{"dns_retr_no",		CFG_VAR_INT,	0, 0, 0, resolv_reinit,
116
+		"number of dns retransmissions before giving up"},
117
+	{"dns_servers_no",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
118
+		"how many dns servers from the ones defined in "
119
+		"/etc/resolv.conf will be used"},
120
+	{"dns_use_search_list",	CFG_VAR_INT,	0, 1, 0, resolv_reinit,
121
+		"if set to 0, the search list in /etc/resolv.conf is ignored"},
122
+	{"dns_search_full_match",	CFG_VAR_INT,	0, 1, 0, 0,
123
+		"enable/disable domain name checks against the search list "
124
+		"in DNS answers"},
125
+	{"dns_reinit",		CFG_VAR_INT|CFG_INPUT_INT,	1, 1, dns_reinit_fixup, resolv_reinit,
126
+		"set to 1 in order to reinitialize the DNS resolver"},
127
+	/* DNS cache */
128
+#ifdef USE_DNS_CACHE
129
+	{"dns_cache_flags",	CFG_VAR_INT,	0, 4, 0, fix_dns_flags,
130
+		"dns cache specific resolver flags "
131
+		"(1=ipv4 only, 2=ipv6 only, 4=prefer ipv6"},
132
+	{"use_dns_failover",	CFG_VAR_INT,	0, 1, use_dns_failover_fixup, 0,
133
+		"enable/disable dns failover in case the destination "
134
+		"resolves to multiple ip addresses and/or multiple SRV records "
135
+		"(depends on use_dns_cache)"},
136
+	{"dns_srv_lb",		CFG_VAR_INT,	0, 1, 0, fix_dns_flags,
137
+		"enable/disable load balancing to different srv records "
138
+		"of the same priority based on the srv records weights "
139
+		"(depends on dns_failover)"},
140
+	{"dns_cache_negative_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
141
+		"time to live for negative results (\"not found\") "
142
+		"in seconds. Use 0 to disable"},
143
+	{"dns_cache_min_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
144
+		"minimum accepted time to live for a record, in seconds"},
145
+	{"dns_cache_max_ttl",	CFG_VAR_INT,	0, 0, 0, 0,
146
+		"maximum accepted time to live for a record, in seconds"},
147
+	{"dns_cache_mem",	CFG_VAR_INT,	0, 0, dns_cache_max_mem_fixup, 0,
148
+		"maximum memory used for the dns cache in Kb"},
149
+	{"dns_cache_del_nonexp",	CFG_VAR_INT,	0, 1, 0, 0,
150
+		"allow deletion of non-expired records from the cache when "
151
+		"there is no more space left for new ones"},
57 152
 #endif
58 153
 	{0, 0, 0, 0, 0, 0}
59 154
 };
... ...
@@ -47,10 +47,34 @@ 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 */
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;
54 78
 #endif
55 79
 };
56 80
 
... ...
@@ -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 50
 #endif
49 51
 
50 52
 #include "globals.h"
53
+#include "cfg_core.h"
51 54
 #include "dns_cache.h"
52 55
 #include "dns_wrappers.h"
53 56
 #include "compiler_opt.h"
... ...
@@ -79,10 +82,6 @@
79 82
 							   dns answer*/
80 83
 
81 84
 #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 85
 #define DEFAULT_DNS_TIMER_INTERVAL 120  /* 2 min. */
87 86
 #define DNS_HE_MAX_ADDR 10  /* maxium addresses returne in a hostent struct */
88 87
 #define MAX_CNAME_CHAIN  10
... ...
@@ -91,16 +90,9 @@
91 90
 
92 91
 static gen_lock_t* dns_hash_lock=0;
93 92
 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 93
 unsigned int dns_timer_interval=DEFAULT_DNS_TIMER_INTERVAL; /* in s */
100 94
 int dns_flags=0; /* default flags used for the  dns_*resolvehost
101 95
                     (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 96
 
105 97
 #ifdef USE_DNS_CACHE_STATS
106 98
 struct t_dns_cache_stats* dns_cache_stats=0;
... ...
@@ -109,8 +101,12 @@ struct t_dns_cache_stats* dns_cache_stats=0;
109 101
 #define LOCK_DNS_HASH()		lock_get(dns_hash_lock)
110 102
 #define UNLOCK_DNS_HASH()	lock_release(dns_hash_lock)
111 103
 
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)))
104
+#define FIX_TTL(t) \
105
+	(((t)<cfg_get(core, core_cfg, dns_cache_min_ttl))? \
106
+		cfg_get(core, core_cfg, dns_cache_min_ttl): \
107
+		(((t)>cfg_get(core, core_cfg, dns_cache_max_ttl))? \
108
+			cfg_get(core, core_cfg, dns_cache_max_ttl): \
109
+			(t)))
114 110
 
115 111
 
116 112
 struct dns_hash_head{
... ...
@@ -216,8 +212,8 @@ static ticks_t dns_timer(ticks_t ticks, struct timer_ln* tl, void* data)
216 212
 	if (atomic_get(dns_servers_up) == 0)
217 213
 		return (ticks_t)(-1);
218 214
 #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);
215
+	if (*dns_cache_mem_used>12*(cfg_get(core, core_cfg, dns_cache_max_mem)/16)){ /* ~ 75% used */
216
+		dns_cache_free_mem(cfg_get(core, core_cfg, dns_cache_max_mem)/2, 1);
221 217
 	}else{
222 218
 		dns_cache_clean(-1, 1); /* all the table, only expired entries */
223 219
 		/* TODO: better strategy? */
... ...
@@ -265,7 +261,62 @@ void destroy_dns_cache()
265 261
 	}
266 262
 }
267 263
 
264
+/* set the value of dns_flags */
265
+void fix_dns_flags(str *name)
266
+{
267
+	/* restore the original value of dns_cache_flags first
268
+	 * (DNS_IPV4_ONLY may have been set only because dns_try_ipv6
269
+	 * was disabled, and the flag must be cleared when
270
+	 * dns_try_ipv6 is enabled) (Miklos)
271
+	 */
272
+	dns_flags = cfg_get(core, core_cfg, dns_cache_flags) & 7;
268 273
 
274
+	if (cfg_get(core, core_cfg, dns_try_ipv6)==0){
275
+		dns_flags|=DNS_IPV4_ONLY;
276
+	}
277
+	if (dns_flags & DNS_IPV4_ONLY){
278
+		dns_flags&=~(DNS_IPV6_ONLY|DNS_IPV6_FIRST);
279
+	}
280
+	if (cfg_get(core, core_cfg, dns_srv_lb)){
281
+#ifdef DNS_SRV_LB
282
+		dns_flags|=DNS_SRV_RR_LB;
283
+#else
284
+		LOG(L_WARN, "WARING: fix_dns_flags: SRV loadbalaning is set, but"
285
+					" support for it is not compiled -- ignoring\n");
286
+#endif
287
+	}
288
+	if (cfg_get(core, core_cfg, dns_try_naptr)) {
289
+#ifndef USE_NAPTR
290
+	LOG(L_WARN, "WARING: fix_dns_flags: NAPTR support is enabled, but"
291
+				" support for it is not compiled -- ignoring\n");
292
+#endif
293
+		dns_flags|=DNS_TRY_NAPTR;
294
+	}
295
+}
296
+
297
+/* fixup function for use_dns_failover
298
+ * verifies that use_dns_cache is set to 1
299
+ */
300
+int use_dns_failover_fixup(void *handle, str *name, void **val)
301
+{
302
+	if ((int)(long)(*val) && !use_dns_cache) {
303
+		LOG(L_ERR, "ERROR: use_dns_failover_fixup(): "
304
+			"DNS cache is turned off, failover cannot be enabled. "
305
+			"(set use_dns_cache to 1)\n");
306
+		return -1;
307
+	}
308
+	return 0;
309
+}
310
+
311
+/* KByte to Byte conversion */
312
+int dns_cache_max_mem_fixup(void *handle, str *name, void **val)
313
+{
314
+	unsigned int    u;
315
+
316
+	u = ((unsigned int)(long)(*val))<<10;
317
+	(*val) = (void *)(long)u;
318
+	return 0;
319
+}
269 320
 
270 321
 int init_dns_cache()
271 322
 {
... ...
@@ -322,29 +373,10 @@ int init_dns_cache()
322 373
 #endif
323 374
 
324 375
 	/* fix options */
325
-	dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
376
+	default_core_cfg.dns_cache_max_mem<<=10; /* Kb */ /* TODO: test with 0 */
326 377
 	/* 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
-	}
378
+	fix_dns_flags(NULL);
379
+
348 380
 	dns_timer_h=timer_alloc();
349 381
 	if (dns_timer_h==0){
350 382
 		ret=E_OUT_OF_MEM;
... ...
@@ -599,10 +631,8 @@ inline static int dns_cache_clean(unsigned int no, int expired_only)
599 631
 	if (!expired_only){
600 632
 		for(h=start; h!=(start+DNS_HASH_SIZE); h++){
601 633
 			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
-				}
634
+				_dns_hash_remove(e);
635
+				deleted++;
606 636
 				n++;
607 637
 				if (n>=no) goto skip;
608 638
 			}
... ...
@@ -714,14 +744,15 @@ inline static int dns_cache_add(struct dns_hash_entry* e)
714 744
 
715 745
 	/* check space */
716 746
 	/* atomic_add_long(dns_cache_total_used, e->size); */
717
-	if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
747
+	if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
718 748
 #ifdef USE_DNS_CACHE_STATS
719 749
 		dns_cache_stats[process_no].dc_lru_cnt++;
720 750
 #endif
721 751
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
722 752
 		/* 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){
753
+		dns_cache_free_mem(*dns_cache_mem_used/16*14,
754
+					!cfg_get(core, core_cfg, dns_cache_del_nonexp));
755
+		if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
725 756
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
726 757
 			return -1;
727 758
 		}
... ...
@@ -753,16 +784,17 @@ inline static int dns_cache_add_unsafe(struct dns_hash_entry* e)
753 784
 
754 785
 	/* check space */
755 786
 	/* atomic_add_long(dns_cache_total_used, e->size); */
756
-	if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
787
+	if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
757 788
 #ifdef USE_DNS_CACHE_STATS
758 789
 		dns_cache_stats[process_no].dc_lru_cnt++;
759 790
 #endif
760 791
 		LOG(L_WARN, "WARNING: dns_cache_add: cache full, trying to free...\n");
761 792
 		/* free ~ 12% of the cache */
762 793
 		UNLOCK_DNS_HASH();
763
-		dns_cache_free_mem(*dns_cache_mem_used/16*14, !dns_cache_del_nonexp);
794
+		dns_cache_free_mem(*dns_cache_mem_used/16*14,
795
+					!cfg_get(core, core_cfg, dns_cache_del_nonexp));
764 796
 		LOCK_DNS_HASH();
765
-		if ((*dns_cache_mem_used+e->total_size)>=dns_cache_max_mem){
797
+		if ((*dns_cache_mem_used+e->total_size)>=cfg_get(core, core_cfg, dns_cache_max_mem)){
766 798
 			LOG(L_ERR, "ERROR: dns_cache_add: max. cache mem size exceeded\n");
767 799
 			return -1;
768 800
 		}
... ...
@@ -1672,8 +1704,8 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
1672 1704
 		l=dns_cache_mk_rd_entry2(records);
1673 1705
 #endif
1674 1706
 		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);
1707
+	}else if (cfg_get(core, core_cfg, dns_neg_cache_ttl)){
1708
+		e=dns_cache_mk_bad_entry(name, type, cfg_get(core, core_cfg, dns_neg_cache_ttl), DNS_BAD_NAME);
1677 1709
 		atomic_set(&e->refcnt, 1); /* 1 because we return a ref. to it */
1678 1710
 		dns_cache_add(e); /* refcnt++ inside*/
1679 1711
 		goto end;
... ...
@@ -3144,7 +3176,7 @@ void dns_cache_mem_info(rpc_t* rpc, void* ctx)
3144 3176
 		rpc->fault(ctx, 500, "dns cache support disabled (see use_dns_cache)");
3145 3177
 		return;
3146 3178
 	}
3147
-	rpc->add(ctx, "dd",  *dns_cache_mem_used, dns_cache_max_mem);
3179
+	rpc->add(ctx, "dd",  *dns_cache_mem_used, cfg_get(core, core_cfg, dns_cache_max_mem));
3148 3180
 }
3149 3181
 
3150 3182
 
... ...
@@ -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 178
 
174 179
 const char* dns_strerror(int err);
175 180
 
181
+void fix_dns_flags(str *name);
182
+int use_dns_failover_fixup(void *handle, str *name, void **val);
183
+int dns_cache_max_mem_fixup(void *handle, str *name, void **val);
176 184
 int init_dns_cache();
177 185
 #ifdef USE_DNS_CACHE_STATS
178 186
 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 472
 	STATS_TX_DROPS;
472 473
 end:
473 474
 #ifdef USE_DNS_FAILOVER
474
-	if (dst && use_dns_failover){
475
+	if (dst && cfg_get(core, core_cfg, use_dns_failover)){
475 476
 				dns_srv_handle_put(&dns_srv_h);
476 477
 	}
477 478
 #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 1278
 	int rfd;
1280 1279
 	int debug_save, debug_flag;
1281 1280
 	int dont_fork_cnt;
1282
-	int socket_types;
1283 1281
 
1284 1282
 	/*init*/
1285 1283
 	creator_pid = getpid();
... ...
@@ -1606,14 +1604,14 @@ try_again:
1606 1604
 			goto error;
1607 1605
 		}
1608 1606
 	}
1609
-	if (fix_all_socket_lists(&socket_types)!=0){
1607
+	if (fix_all_socket_lists()!=0){
1610 1608
 		fprintf(stderr,  "failed to initialize list addresses\n");
1611 1609
 		goto error;
1612 1610
 	}
1613
-	if (dns_try_ipv6 && !(socket_types & SOCKET_T_IPV6)){
1611
+	if (default_core_cfg.dns_try_ipv6 && !(socket_types & SOCKET_T_IPV6)){
1614 1612
 		/* if we are not listening on any ipv6 address => no point
1615 1613
 		 * to try to resovle ipv6 addresses */
1616
-		dns_try_ipv6=0;
1614
+		default_core_cfg.dns_try_ipv6=0;
1617 1615
 	}
1618 1616
 	/* print all the listen addresses */
1619 1617
 	printf("Listening on \n");
... ...
@@ -1660,7 +1658,7 @@ try_again:
1660 1658
 		goto error;
1661 1659
 	}
1662 1660
 	if (use_dns_cache==0)
1663
-		use_dns_failover=0; /* cannot work w/o dns_cache support */
1661
+		default_core_cfg.use_dns_failover=0; /* cannot work w/o dns_cache support */
1664 1662
 #ifdef USE_DNS_CACHE_STATS
1665 1663
 	/* preinitializing before the nubmer of processes is determined */
1666 1664
 	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 396
 	int ret;
396 397
 	
397 398
 	ret=-1;
398
-	if (use_dns_failover && 
399
+	if (cfg_get(core, core_cfg, use_dns_failover) && 
399 400
 			!((t->flags & T_DONT_FORK) || uac_dont_fork(old_uac)) &&
400 401
 			dns_srv_handle_next(&old_uac->dns_h, 0)){
401 402
 			if (lock_replies){
... ...
@@ -674,7 +675,7 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
674 675
 #ifdef USE_DNS_FAILOVER
675 676
 			/* if the destination resolves to more ips, add another
676 677
 			 *  branch/uac */
677
-			if (use_dns_failover){
678
+			if (cfg_get(core, core_cfg, use_dns_failover)){
678 679
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
679 680
 				if (ret>=0){
680 681
 					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 710
 #ifdef USE_DNS_FAILOVER
710 711
 			/* if the destination resolves to more ips, add another
711 712
 			 *  branch/uac */
712
-			if (use_dns_failover){
713
+			if (cfg_get(core, core_cfg, use_dns_failover)){
713 714
 				ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
714 715
 				if (ret>=0){
715 716
 					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 745
 #ifdef USE_DNS_FAILOVER
745 746
 		/* if the destination resolves to more ips, add another
746 747
 		 *  branch/uac */
747
-		if (use_dns_failover){
748
+		if (cfg_get(core, core_cfg, use_dns_failover)){
748 749
 			ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies);
749 750
 			if (ret>=0){
750 751
 				/* 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 599
 	
599 600
 	 /* via */
600 601
 #ifdef USE_DNS_FAILOVER
601
-	if (use_dns_failover){
602
+	if (cfg_get(core, core_cfg, use_dns_failover)){
602 603
 		dns_srv_handle_init(&dns_h);
603 604
 		if ((uri2dst(&dns_h , dst, rpl, &next_hop, PROTO_NONE)==0) ||
604 605
 				(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 419
 		return -1;
416 420
 	}
417 421
 #ifdef USE_DNS_FAILOVER
418
-	if (use_dns_failover){
422
+	if (cfg_get(core, core_cfg, use_dns_failover)){
419 423
 		dns_srv_handle_init(&dns_h);
420 424
 		if ((uri2dst(&dns_h, &dst, msg,  next_hop, PROTO_NONE)==0) || 
421 425
 				(dst.send_sock==0)){
... ...
@@ -1837,7 +1841,10 @@ int reply_received( struct sip_msg  *p_msg )
1837 1841
 		 *  This code is out of LOCK_REPLIES() to minimize the time the
1838 1842
 		 *  reply lock is held (the lock won't be held while sending the
1839 1843
 		 *   message)*/
1840
-		if (use_dns_failover && (msg_status==503) && uac->request.t_active){
1844
+		if (cfg_get(core, core_cfg, use_dns_failover) && 
1845
+			(msg_status==503) &&
1846
+			uac->request.t_active
1847
+		) {
1841 1848
 			branch_ret=add_uac_dns_fallback(t, t->uas.request, uac, 1);
1842 1849
 			prev_branch=-1;
1843 1850
 			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 468
 		/* if this is an invite, the destination resolves to more ips, and
468 469
 		 *  it still hasn't passed more than fr_inv_timeout since we
469 470
 		 *  started, add another branch/uac */
470
-		if (use_dns_failover){
471
+		if (cfg_get(core, core_cfg, use_dns_failover)){
471 472
 			now=get_ticks_raw();
472 473
 			if ((s_ticks_t)(t->end_of_life-now)>0){
473 474
 				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 221
 			uac_r->dialog->hooks.next_hop->s);
218 222
 	/* it's a new message, so we will take the default socket */
219 223
 #ifdef USE_DNS_FAILOVER
220
-	if (use_dns_failover){
224
+	if (cfg_get(core, core_cfg, use_dns_failover)){
221 225
 		dns_srv_handle_init(&dns_h);
222 226
 		if ((uri2dst(&dns_h, &dst, 0, uac_r->dialog->hooks.next_hop, PROTO_NONE)==0)
223 227
 				|| (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 271
 #endif
271 272
 		host=&parsed_uri.host;
272 273
 #ifdef USE_DNS_FAILOVER
273
-	if (use_dns_failover && dns_h){
274
+	if (cfg_get(core, core_cfg, use_dns_failover) && dns_h){
274 275
 		ip_found=0;
275 276
 		do{
276 277
 			/* 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 59
 #include "ip_addr.h"
58 60
 #include "error.h"
59 61
 #include "globals.h" /* tcp_disable, tls_disable a.s.o */
62
+#include "cfg_core.h"
63
+#include "socket_info.h"
60 64
 
61 65
 #ifdef USE_DNS_CACHE
62 66
 #include "dns_cache.h"
... ...
@@ -68,29 +72,11 @@
68 72
 #define local_malloc pkg_malloc
69 73
 #define local_free   pkg_free
70 74
 
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 75
 #ifdef USE_NAPTR
83 76
 #define PROTO_LAST  PROTO_SCTP
84 77
 static int naptr_proto_pref[PROTO_LAST];
85 78
 #endif
86 79
 
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 80
 #ifdef USE_NAPTR
95 81
 void init_naptr_proto_prefs()
96 82
 {
... ...
@@ -99,14 +85,28 @@ void init_naptr_proto_prefs()
99 85
 		BUG("init_naptr_proto_prefs: array too small \n");
100 86
 		return;
101 87
 	}
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;
88
+	naptr_proto_pref[PROTO_UDP]=cfg_get(core, core_cfg, dns_udp_pref);
89
+	naptr_proto_pref[PROTO_TCP]=cfg_get(core, core_cfg, dns_tcp_pref);
90
+	naptr_proto_pref[PROTO_TLS]=cfg_get(core, core_cfg, dns_tls_pref);
105 91
 }
106 92
 
107 93
 #endif /* USE_NAPTR */
108 94
 
95
+#ifdef DNS_WATCHDOG_SUPPORT
96
+static on_resolv_reinit	on_resolv_reinit_cb = NULL;
109 97
 
98
+/* register the callback function */
99
+int register_resolv_reinit_cb(on_resolv_reinit cb)
100
+{
101
+	if (on_resolv_reinit_cb) {
102
+		LOG(L_ERR, "ERROR: register_resolv_reinit_cb(): "
103
+			"callback function has been already registered\n");
104
+		return -1;
105
+	}
106
+	on_resolv_reinit_cb = cb;
107
+	return 0;
108
+}
109
+#endif
110 110
 
111 111
 /* init. the resolver
112 112
  * 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 511
 	int name_len;
460 512
 	struct rdata* fullname_rd;
461 513
 	
462
-	if (dns_search_list==0) {
514
+	if (cfg_get(core, core_cfg, dns_search_list)==0) {
463 515
 		search_list_used=0;
464 516
 		name_len=0;
465 517
 	} else {
... ...
@@ -574,7 +626,7 @@ again:
574 626
 			/* this is safe.... here was rec_name_len > name_len */
575 627
 			else if (rec_name[name_len]=='.') {
576 628
 #ifdef HAVE_RESOLV_RES
577
-				if ((dns_search_fmatch==0) ||
629
+				if ((cfg_get(core, core_cfg, dns_search_fmatch)==0) ||
578 630
 						(match_search_list(&_res, rec_name+name_len+1)!=0))
579 631
 #endif
580 632
 					fullname_rd=rd;
... ...
@@ -1221,7 +1273,7 @@ end:
1221 1273
 struct hostent* _sip_resolvehost(str* name, unsigned short* port, char* proto)
1222 1274
 {
1223 1275
 #ifdef USE_NAPTR
1224
-	if (dns_try_naptr)
1276
+	if (cfg_get(core, core_cfg, dns_try_naptr))
1225 1277
 		return naptr_sip_resolvehost(name, port, proto);
1226 1278
 #endif
1227 1279
 	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 376
 	/* ipv4 */
383 377
 	he=gethostbyname(name);
384 378
 #ifdef USE_IPV6
385
-	if(he==0 && dns_try_ipv6){
379
+	if(he==0 && cfg_get(core, core_cfg, dns_try_ipv6)){
386 380
 #ifndef DNS_IP_HACK
387 381
 skip_ipv4:
388 382
 #endif
... ...
@@ -407,9 +401,27 @@ skip_ipv4:
407 401
 }
408 402
 
409 403
 
410
-
411 404
 int resolv_init();
412 405
 
406
+/* callback/fixup functions executed by the configuration framework */
407
+void resolv_reinit(str *name);
408
+int dns_reinit_fixup(void *handle, str *name, void **val);
409
+int dns_try_ipv6_fixup(void *handle, str *name, void **val);
410
+void reinit_naptr_proto_prefs(str *name);
411
+
412
+#ifdef DNS_WATCHDOG_SUPPORT
413
+/* callback function that is called by the child processes
414
+ * when they reinitialize the resolver
415
+ *
416
+ * Note, that this callback is called by each chiled process separately!!!
417
+ * If the callback is registered after forking, only the child process
418
+ * that installs the hook will call the callback.
419
+ */
420
+typedef void (*on_resolv_reinit)(void);
421
+int register_resolv_reinit_cb(on_resolv_reinit cb);
422
+#endif
423
+
424
+
413 425
 int sip_hostport2su(union sockaddr_union* su, str* host, unsigned short port,
414 426
 						char* proto);
415 427
 
... ...
@@ -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 768
 				" udp failed\n");
772 769
 		goto error;
773 770
 	}
774
-	if (flags && socket_types){
775
-		*socket_types|=flags|SOCKET_T_UDP;
771
+	if (flags){
772
+		socket_types|=flags|SOCKET_T_UDP;
776 773
 	}
777 774
 #ifdef USE_TCP
778 775
 	if (!tcp_disable && (fix_socket_list(&tcp_listen, &flags)!=0)){
... ...
@@ -780,8 +777,8 @@ int fix_all_socket_lists(int* socket_types)
780 777
 				" tcp failed\n");
781 778
 		goto error;
782 779
 	}
783
-	if (flags && socket_types){
784
-		*socket_types|=flags|SOCKET_T_TCP;
780
+	if (flags){
781
+		socket_types|=flags|SOCKET_T_TCP;
785 782
 	}
786 783
 #ifdef USE_TLS
787 784
 	if (!tls_disable && (fix_socket_list(&tls_listen, &flags)!=0)){
... ...
@@ -789,8 +786,8 @@ int fix_all_socket_lists(int* socket_types)
789 786
 				" tls failed\n");
790 787
 		goto error;
791 788
 	}
792
-	if (flags && socket_types){
793
-		*socket_types|=flags|SOCKET_T_TLS;
789
+	if (flags){
790
+		socket_types|=flags|SOCKET_T_TLS;
794 791
 	}
795 792
 #endif
796 793
 #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