Kaynağa Gözat

- 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 20 yıl önce
ebeveyn
işleme
878fc1940b
8 değiştirilmiş dosya ile 120 ekleme ve 3 silme
  1. 5 1
      Makefile.defs
  2. 26 1
      NEWS
  3. 17 0
      cfg.lex
  4. 17 0
      cfg.y
  5. 6 0
      globals.h
  6. 2 0
      main.c
  7. 43 0
      resolve.c
  8. 4 1
      resolve.h

+ 5 - 1
Makefile.defs

@@ -58,7 +58,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 10
 SUBLEVEL =   99
-EXTRAVERSION = -dev12-tcp
+EXTRAVERSION = -dev13-tcp
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
@@ -305,6 +305,9 @@ endif
 # -DUSE_TLS
 #		compiles in tls support, requires -DUSE_TCP. Please use
 #		make TLS=1 instead. (tls support is highly experimental for now)
+# -DHAVE_RESOLV_RES
+#		support for changing some of the resolver parameters present
+#		 (_res structure in <resolv.h>)
 
 
 DEFS+= $(extra_defs) \
@@ -318,6 +321,7 @@ DEFS+= $(extra_defs) \
 	 -DUSE_MCAST \
 	 -DUSE_TCP \
 	 -DDISABLE_NAGLE \
+	 -DHAVE_RESOLV_RES \
 	 -DDBG_QM_MALLOC \
 	 #-DF_MALLOC \
 	 #-DDBG_F_MALLOC \

+ 26 - 1
NEWS

@@ -21,13 +21,38 @@ core:
  - tcp: - improved  performance (io event handling), using OS specific
            optimizations
         - 1024 connections limit removed (see tcp_max_connections)
+-  resolver: - timeouts, retries a.s.o can no be set from ser.cfg
+             (see below dns_* and man resolv.conf(6)).
+             The maximum time a dns request can take (before failing) is:
+              (dns_retr_time*dns_retr_no)*(search_list_domains)
+             If dns_try_ipv6 is yes, mutliply it again by 2.
+             The fastest possible dns config (max 1s):
+                dns_try_ipv6=no
+                dns_retr_time=1
+                dns_retr_no=1
+                dns_use_search_list=no
 new config variables:
+   dns_try_ipv6 = yes/no - if yes and a dns lookup fails, it will retry it
+      for ipv6 (AAAA record). Default: yes
+   dns_retr_time = time - time in s before retrying a dns request.
+      Default: system specific, depends also on the/etc/resolv.conf content
+      (usually 5s).
+   dns_retr_no = no. - number of dns retransmissions before giving up.
+      Default: see above (usually 4)
+   dns_server_no = no. - how many dns servers from the ones defined in 
+      /etc/resolv.conf will be used. Default: all of them.
+   dns_use_search_list= yes/no - if no, the search list in /etc/resolv.conf
+      will be ignored (=> fewer lookups => gives up faster). Default: yes.
+      HINT: even if you don't have a search list defined, setting this option
+      to "no" will still be "faster", because an empty search list is in 
+      fact search "" (so even if the search list is empty/missing there will
+      still be 2 dns queries, eg. foo+'.' and foo+""+'.')
    tcp_connection_lifetime = value (s) - how long the lifetime of a
       tcp connection will be exteneded after an IO event (accept, connect, 
       read, write). Default: 120 s.
    tcp_poll_method = poll|select|epoll_et|epoll-lt|kqueue|devpoll - poll
       method used (by default the best one for the current OS is selected)
-   tcp_max_connections = no - maximum number of tcp connections (if the number
+   tcp_max_connections = no. - maximum number of tcp connections (if the number
       is exceeded no new tcp connections will be accepted). Default: 2048.
 
 

+ 17 - 0
cfg.lex

@@ -54,6 +54,8 @@
  *  2004-11-30  added force_send_socket
  *  2005-07-08  added tcp_connection_lifetime, tcp_poll_method,
  *               tcp_max_connections (andrei)
+ *  2005-07-11  added dns_retr_{time,no}, dns_servers_no, dns_use_search_list,
+ *              dns_try_ipv6 (andrei)
  */
 
 
@@ -182,6 +184,11 @@ LISTEN		listen
 ALIAS		alias
 DNS		 dns
 REV_DNS	 rev_dns
+DNS_TRY_IPV6	dns_try_ipv6
+DNS_RETR_TIME	dns_retr_time
+DNS_RETR_NO		dns_retr_no
+DNS_SERVERS_NO	dns_servers_no
+DNS_USE_SEARCH	dns_use_search_list
 PORT	port
 STAT	statistics
 MAXBUFFER maxbuffer
@@ -356,6 +363,16 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
 <INITIAL>{REV_DNS}	{ count(); yylval.strval=yytext; return REV_DNS; }
+<INITIAL>{DNS_TRY_IPV6}	{ count(); yylval.strval=yytext;
+								return DNS_TRY_IPV6; }
+<INITIAL>{DNS_RETR_TIME}	{ count(); yylval.strval=yytext;
+								return DNS_RETR_TIME; }
+<INITIAL>{DNS_RETR_NO}	{ count(); yylval.strval=yytext;
+								return DNS_RETR_NO; }
+<INITIAL>{DNS_SERVERS_NO}	{ count(); yylval.strval=yytext;
+								return DNS_SERVERS_NO; }
+<INITIAL>{DNS_USE_SEARCH}	{ count(); yylval.strval=yytext;
+								return DNS_USE_SEARCH; }
 <INITIAL>{PORT}	{ count(); yylval.strval=yytext; return PORT; }
 <INITIAL>{STAT}	{ count(); yylval.strval=yytext; return STAT; }
 <INITIAL>{MAXBUFFER}	{ count(); yylval.strval=yytext; return MAXBUFFER; }

+ 17 - 0
cfg.y

@@ -60,6 +60,8 @@
  * 2004-11-30  added force_send_socket (andrei)
  * 2005-07-08  added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
  *              (andrei)
+ * 2005-07-11 added DNS_RETR_TIME, DNS_RETR_NO, DNS_SERVERS_NO, DNS_USE_SEARCH,
+ *             DNS_TRY_IPV6 (andrei)
  */
 
 
@@ -195,6 +197,11 @@ static struct socket_id* mk_listen_id(char*, int, int);
 %token ALIAS
 %token DNS
 %token REV_DNS
+%token DNS_TRY_IPV6
+%token DNS_RETR_TIME
+%token DNS_RETR_NO
+%token DNS_SERVERS_NO
+%token DNS_USE_SEARCH
 %token PORT
 %token STAT
 %token CHILDREN
@@ -402,6 +409,16 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
 		| DNS EQUAL error { yyerror("boolean value expected"); }
 		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
 		| REV_DNS EQUAL error { yyerror("boolean value expected"); }
+		| DNS_TRY_IPV6 EQUAL NUMBER   { dns_try_ipv6=$3; }
+		| DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
+		| DNS_RETR_TIME EQUAL NUMBER   { dns_retr_time=$3; }
+		| DNS_RETR_TIME error { yyerror("number expected"); }
+		| DNS_RETR_NO EQUAL NUMBER   { dns_retr_no=$3; }
+		| DNS_RETR_NO error { yyerror("number expected"); }
+		| DNS_SERVERS_NO EQUAL NUMBER   { dns_servers_no=$3; }
+		| DNS_SERVERS_NO error { yyerror("number expected"); }
+		| DNS_USE_SEARCH EQUAL NUMBER   { dns_search_list=$3; }
+		| DNS_USE_SEARCH error { yyerror("boolean value expected"); }
 		| PORT EQUAL NUMBER   { port_no=$3; }
 		| STAT EQUAL STRING {
 					#ifdef STATS

+ 6 - 0
globals.h

@@ -165,4 +165,10 @@ extern str default_global_port;
 extern int disable_core_dump;
 extern int open_files_limit;
 
+/* resolver */
+extern int dns_retr_time;
+extern int dns_retr_no;
+extern int dns_servers_no;
+extern int dns_search_list;
+
 #endif

+ 2 - 0
main.c

@@ -1449,6 +1449,8 @@ try_again:
 	
 	print_rl();
 	
+	/* init the resolver, before fixing the config */
+	resolv_init();
 	/* fix parameters */
 	if (port_no<=0) port_no=SIP_PORT;
 #ifdef USE_TLS

+ 43 - 0
resolve.c

@@ -29,6 +29,7 @@
  * -------
  *  2003-02-13  added proto to sip_resolvehost, for SRV lookups (andrei)
  *  2003-07-03  default port value set according to proto (andrei)
+ *  2005-07-11  added resolv_init (timeouts a.s.o) (andrei)
  */ 
 
 
@@ -49,6 +50,48 @@
 #define local_malloc pkg_malloc
 #define local_free   pkg_free
 
+int dns_try_ipv6=1; /* default on */
+/* declared in globals.h */
+int dns_retr_time=-1;
+int dns_retr_no=-1;
+int dns_servers_no=-1;
+int dns_search_list=-1;
+
+
+/* init. the resolver
+ * params: retr_time  - time before retransmitting (must be >0)
+ *         retr_no    - retransmissions number
+ *         servers_no - how many dns servers will be used
+ *                      (from the one listed in /etc/resolv.conf)
+ *         search     - if 0 the search list in /etc/resolv.conf will
+ *                      be ignored (HINT: even if you don't have a
+ *                      search list in resolv.conf, it's still better
+ *                      to set search to 0, because an empty seachlist
+ *                      means in fact search "" => it takes more time)
+ * If any of the parameters <0, the default (system specific) value
+ * will be used. See also resolv.conf(5).
+ * returns: 0 on success, -1 on error
+ */
+int resolv_init()
+{
+	res_init();
+#ifdef HAVE_RESOLV_RES
+	if (dns_retr_time>0)
+		_res.retrans=dns_retr_time;
+	if (dns_retr_no>0)
+		_res.retry=dns_retr_no;
+	if (dns_servers_no>=0)
+		_res.nscount=dns_servers_no;
+	if (dns_search_list==0)
+		_res.options&=~(RES_DEFNAMES|RES_DNSRCH);
+#else
+#warning "no resolv timeout support"
+	LOG(L_WARN, "WARNING: resolv_init: no resolv options support - resolv"
+			" options will be ignored\n");
+#endif
+	return 0;
+}
+
 
 
  /*  skips over a domain name in a dns message

+ 4 - 1
resolve.h

@@ -118,6 +118,7 @@ struct rdata* get_record(char* name, int type);
 void free_rdata_list(struct rdata* head);
 
 
+extern int dns_try_ipv6;
 
 
 #define rev_resolvehost(ip)\
@@ -330,7 +331,7 @@ static inline struct hostent* resolvehost(char* name)
 	/* ipv4 */
 	he=gethostbyname(name);
 #ifdef USE_IPV6
-	if(he==0){
+	if(he==0 && dns_try_ipv6){
 #ifndef DNS_IP_HACK
 skip_ipv4:
 #endif
@@ -356,4 +357,6 @@ skip_ipv4:
 
 
 
+int resolv_init();
+
 #endif