Browse code

- various resolver/dns related options can now be set from ser.cfg: dns_try-ipv6=yes|no dns_retr_time= time(in s) dns_retr_no = no. dns_use_search_list=yes|no dns_server_no= no. (for more info look in NEWS)

Andrei Pelinescu-Onciul authored on 11/07/2005 17:30:43
Showing 8 changed files
... ...
@@ -58,7 +58,7 @@ MAIN_NAME=ser
58 58
 VERSION = 0
59 59
 PATCHLEVEL = 10
60 60
 SUBLEVEL =   99
61
-EXTRAVERSION = -dev12-tcp
61
+EXTRAVERSION = -dev13-tcp
62 62
 
63 63
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
64 64
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -305,6 +305,9 @@ endif
305 305
 # -DUSE_TLS
306 306
 #		compiles in tls support, requires -DUSE_TCP. Please use
307 307
 #		make TLS=1 instead. (tls support is highly experimental for now)
308
+# -DHAVE_RESOLV_RES
309
+#		support for changing some of the resolver parameters present
310
+#		 (_res structure in <resolv.h>)
308 311
 
309 312
 
310 313
 DEFS+= $(extra_defs) \
... ...
@@ -318,6 +321,7 @@ DEFS+= $(extra_defs) \
318 318
 	 -DUSE_MCAST \
319 319
 	 -DUSE_TCP \
320 320
 	 -DDISABLE_NAGLE \
321
+	 -DHAVE_RESOLV_RES \
321 322
 	 -DDBG_QM_MALLOC \
322 323
 	 #-DF_MALLOC \
323 324
 	 #-DDBG_F_MALLOC \
... ...
@@ -21,13 +21,38 @@ core:
21 21
  - tcp: - improved  performance (io event handling), using OS specific
22 22
            optimizations
23 23
         - 1024 connections limit removed (see tcp_max_connections)
24
+-  resolver: - timeouts, retries a.s.o can no be set from ser.cfg
25
+             (see below dns_* and man resolv.conf(6)).
26
+             The maximum time a dns request can take (before failing) is:
27
+              (dns_retr_time*dns_retr_no)*(search_list_domains)
28
+             If dns_try_ipv6 is yes, mutliply it again by 2.
29
+             The fastest possible dns config (max 1s):
30
+                dns_try_ipv6=no
31
+                dns_retr_time=1
32
+                dns_retr_no=1
33
+                dns_use_search_list=no
24 34
 new config variables:
35
+   dns_try_ipv6 = yes/no - if yes and a dns lookup fails, it will retry it
36
+      for ipv6 (AAAA record). Default: yes
37
+   dns_retr_time = time - time in s before retrying a dns request.
38
+      Default: system specific, depends also on the/etc/resolv.conf content
39
+      (usually 5s).
40
+   dns_retr_no = no. - number of dns retransmissions before giving up.
41
+      Default: see above (usually 4)
42
+   dns_server_no = no. - how many dns servers from the ones defined in 
43
+      /etc/resolv.conf will be used. Default: all of them.
44
+   dns_use_search_list= yes/no - if no, the search list in /etc/resolv.conf
45
+      will be ignored (=> fewer lookups => gives up faster). Default: yes.
46
+      HINT: even if you don't have a search list defined, setting this option
47
+      to "no" will still be "faster", because an empty search list is in 
48
+      fact search "" (so even if the search list is empty/missing there will
49
+      still be 2 dns queries, eg. foo+'.' and foo+""+'.')
25 50
    tcp_connection_lifetime = value (s) - how long the lifetime of a
26 51
       tcp connection will be exteneded after an IO event (accept, connect, 
27 52
       read, write). Default: 120 s.
28 53
    tcp_poll_method = poll|select|epoll_et|epoll-lt|kqueue|devpoll - poll
29 54
       method used (by default the best one for the current OS is selected)
30
-   tcp_max_connections = no - maximum number of tcp connections (if the number
55
+   tcp_max_connections = no. - maximum number of tcp connections (if the number
31 56
       is exceeded no new tcp connections will be accepted). Default: 2048.
32 57
 
33 58
 
... ...
@@ -54,6 +54,8 @@
54 54
  *  2004-11-30  added force_send_socket
55 55
  *  2005-07-08  added tcp_connection_lifetime, tcp_poll_method,
56 56
  *               tcp_max_connections (andrei)
57
+ *  2005-07-11  added dns_retr_{time,no}, dns_servers_no, dns_use_search_list,
58
+ *              dns_try_ipv6 (andrei)
57 59
  */
58 60
 
59 61
 
... ...
@@ -182,6 +184,11 @@ LISTEN		listen
182 182
 ALIAS		alias
183 183
 DNS		 dns
184 184
 REV_DNS	 rev_dns
185
+DNS_TRY_IPV6	dns_try_ipv6
186
+DNS_RETR_TIME	dns_retr_time
187
+DNS_RETR_NO		dns_retr_no
188
+DNS_SERVERS_NO	dns_servers_no
189
+DNS_USE_SEARCH	dns_use_search_list
185 190
 PORT	port
186 191
 STAT	statistics
187 192
 MAXBUFFER maxbuffer
... ...
@@ -356,6 +363,16 @@ EAT_ABLE	[\ \t\b\r]
356 356
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
357 357
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
358 358
 <INITIAL>{REV_DNS}	{ count(); yylval.strval=yytext; return REV_DNS; }
359
+<INITIAL>{DNS_TRY_IPV6}	{ count(); yylval.strval=yytext;
360
+								return DNS_TRY_IPV6; }
361
+<INITIAL>{DNS_RETR_TIME}	{ count(); yylval.strval=yytext;
362
+								return DNS_RETR_TIME; }
363
+<INITIAL>{DNS_RETR_NO}	{ count(); yylval.strval=yytext;
364
+								return DNS_RETR_NO; }
365
+<INITIAL>{DNS_SERVERS_NO}	{ count(); yylval.strval=yytext;
366
+								return DNS_SERVERS_NO; }
367
+<INITIAL>{DNS_USE_SEARCH}	{ count(); yylval.strval=yytext;
368
+								return DNS_USE_SEARCH; }
359 369
 <INITIAL>{PORT}	{ count(); yylval.strval=yytext; return PORT; }
360 370
 <INITIAL>{STAT}	{ count(); yylval.strval=yytext; return STAT; }
361 371
 <INITIAL>{MAXBUFFER}	{ count(); yylval.strval=yytext; return MAXBUFFER; }
... ...
@@ -60,6 +60,8 @@
60 60
  * 2004-11-30  added force_send_socket (andrei)
61 61
  * 2005-07-08  added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
62 62
  *              (andrei)
63
+ * 2005-07-11 added DNS_RETR_TIME, DNS_RETR_NO, DNS_SERVERS_NO, DNS_USE_SEARCH,
64
+ *             DNS_TRY_IPV6 (andrei)
63 65
  */
64 66
 
65 67
 
... ...
@@ -195,6 +197,11 @@ static struct socket_id* mk_listen_id(char*, int, int);
195 195
 %token ALIAS
196 196
 %token DNS
197 197
 %token REV_DNS
198
+%token DNS_TRY_IPV6
199
+%token DNS_RETR_TIME
200
+%token DNS_RETR_NO
201
+%token DNS_SERVERS_NO
202
+%token DNS_USE_SEARCH
198 203
 %token PORT
199 204
 %token STAT
200 205
 %token CHILDREN
... ...
@@ -402,6 +409,16 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
402 402
 		| DNS EQUAL error { yyerror("boolean value expected"); }
403 403
 		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
404 404
 		| REV_DNS EQUAL error { yyerror("boolean value expected"); }
405
+		| DNS_TRY_IPV6 EQUAL NUMBER   { dns_try_ipv6=$3; }
406
+		| DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
407
+		| DNS_RETR_TIME EQUAL NUMBER   { dns_retr_time=$3; }
408
+		| DNS_RETR_TIME error { yyerror("number expected"); }
409
+		| DNS_RETR_NO EQUAL NUMBER   { dns_retr_no=$3; }
410
+		| DNS_RETR_NO error { yyerror("number expected"); }
411
+		| DNS_SERVERS_NO EQUAL NUMBER   { dns_servers_no=$3; }
412
+		| DNS_SERVERS_NO error { yyerror("number expected"); }
413
+		| DNS_USE_SEARCH EQUAL NUMBER   { dns_search_list=$3; }
414
+		| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
405 415
 		| PORT EQUAL NUMBER   { port_no=$3; }
406 416
 		| STAT EQUAL STRING {
407 417
 					#ifdef STATS
... ...
@@ -165,4 +165,10 @@ extern str default_global_port;
165 165
 extern int disable_core_dump;
166 166
 extern int open_files_limit;
167 167
 
168
+/* resolver */
169
+extern int dns_retr_time;
170
+extern int dns_retr_no;
171
+extern int dns_servers_no;
172
+extern int dns_search_list;
173
+
168 174
 #endif
... ...
@@ -1449,6 +1449,8 @@ try_again:
1449 1449
 	
1450 1450
 	print_rl();
1451 1451
 	
1452
+	/* init the resolver, before fixing the config */
1453
+	resolv_init();
1452 1454
 	/* fix parameters */
1453 1455
 	if (port_no<=0) port_no=SIP_PORT;
1454 1456
 #ifdef USE_TLS
... ...
@@ -29,6 +29,7 @@
29 29
  * -------
30 30
  *  2003-02-13  added proto to sip_resolvehost, for SRV lookups (andrei)
31 31
  *  2003-07-03  default port value set according to proto (andrei)
32
+ *  2005-07-11  added resolv_init (timeouts a.s.o) (andrei)
32 33
  */ 
33 34
 
34 35
 
... ...
@@ -49,6 +50,48 @@
49 49
 #define local_malloc pkg_malloc
50 50
 #define local_free   pkg_free
51 51
 
52
+int dns_try_ipv6=1; /* default on */
53
+/* declared in globals.h */
54
+int dns_retr_time=-1;
55
+int dns_retr_no=-1;
56
+int dns_servers_no=-1;
57
+int dns_search_list=-1;
58
+
59
+
60
+/* init. the resolver
61
+ * params: retr_time  - time before retransmitting (must be >0)
62
+ *         retr_no    - retransmissions number
63
+ *         servers_no - how many dns servers will be used
64
+ *                      (from the one listed in /etc/resolv.conf)
65
+ *         search     - if 0 the search list in /etc/resolv.conf will
66
+ *                      be ignored (HINT: even if you don't have a
67
+ *                      search list in resolv.conf, it's still better
68
+ *                      to set search to 0, because an empty seachlist
69
+ *                      means in fact search "" => it takes more time)
70
+ * If any of the parameters <0, the default (system specific) value
71
+ * will be used. See also resolv.conf(5).
72
+ * returns: 0 on success, -1 on error
73
+ */
74
+int resolv_init()
75
+{
76
+	res_init();
77
+#ifdef HAVE_RESOLV_RES
78
+	if (dns_retr_time>0)
79
+		_res.retrans=dns_retr_time;
80
+	if (dns_retr_no>0)
81
+		_res.retry=dns_retr_no;
82
+	if (dns_servers_no>=0)
83
+		_res.nscount=dns_servers_no;
84
+	if (dns_search_list==0)
85
+		_res.options&=~(RES_DEFNAMES|RES_DNSRCH);
86
+#else
87
+#warning "no resolv timeout support"
88
+	LOG(L_WARN, "WARNING: resolv_init: no resolv options support - resolv"
89
+			" options will be ignored\n");
90
+#endif
91
+	return 0;
92
+}
93
+
52 94
 
53 95
 
54 96
  /*  skips over a domain name in a dns message
... ...
@@ -118,6 +118,7 @@ struct rdata* get_record(char* name, int type);
118 118
 void free_rdata_list(struct rdata* head);
119 119
 
120 120
 
121
+extern int dns_try_ipv6;
121 122
 
122 123
 
123 124
 #define rev_resolvehost(ip)\
... ...
@@ -330,7 +331,7 @@ static inline struct hostent* resolvehost(char* name)
330 330
 	/* ipv4 */
331 331
 	he=gethostbyname(name);
332 332
 #ifdef USE_IPV6
333
-	if(he==0){
333
+	if(he==0 && dns_try_ipv6){
334 334
 #ifndef DNS_IP_HACK
335 335
 skip_ipv4:
336 336
 #endif
... ...
@@ -356,4 +357,6 @@ skip_ipv4:
356 356
 
357 357
 
358 358
 
359
+int resolv_init();
360
+
359 361
 #endif