浏览代码

- sctp preference support in naptr queries (added a new ser.cfg option:
dns_sctp_pref, see doc/dns.txt for more details)

Andrei Pelinescu-Onciul 17 年之前
父节点
当前提交
7d11cc0cb0
共有 6 个文件被更改,包括 40 次插入21 次删除
  1. 3 0
      cfg.lex
  2. 7 3
      cfg.y
  3. 6 3
      cfg_core.c
  4. 1 0
      cfg_core.h
  5. 18 11
      doc/dns.txt
  6. 5 4
      resolve.c

+ 3 - 0
cfg.lex

@@ -246,6 +246,7 @@ DNS_SRV_LB		dns_srv_lb|dns_srv_loadbalancing
 DNS_UDP_PREF	dns_udp_pref|dns_udp_preference
 DNS_TCP_PREF	dns_tcp_pref|dns_tcp_preference
 DNS_TLS_PREF	dns_tls_pref|dns_tls_preference
+DNS_SCTP_PREF	dns_sctp_pref|dns_sctp_preference
 DNS_RETR_TIME	dns_retr_time
 DNS_RETR_NO		dns_retr_no
 DNS_SERVERS_NO	dns_servers_no
@@ -512,6 +513,8 @@ EAT_ABLE	[\ \t\b\r]
 								return DNS_TCP_PREF; }
 <INITIAL>{DNS_TLS_PREF}	{ count(); yylval.strval=yytext;
 								return DNS_TLS_PREF; }
+<INITIAL>{DNS_SCTP_PREF}	{ count(); yylval.strval=yytext;
+								return DNS_SCTP_PREF; }
 <INITIAL>{DNS_RETR_TIME}	{ count(); yylval.strval=yytext;
 								return DNS_RETR_TIME; }
 <INITIAL>{DNS_RETR_NO}	{ count(); yylval.strval=yytext;

+ 7 - 3
cfg.y

@@ -290,6 +290,7 @@ static struct socket_id* mk_listen_id(char*, int, int);
 %token DNS_UDP_PREF
 %token DNS_TCP_PREF
 %token DNS_TLS_PREF
+%token DNS_SCTP_PREF
 %token DNS_RETR_TIME
 %token DNS_RETR_NO
 %token DNS_SERVERS_NO
@@ -628,12 +629,15 @@ assign_stm:
 	| DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
 	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
 	| DNS_SRV_LB error { yyerror("boolean value expected"); }
-	| DNS_UDP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_udp_pref=$3); }
+	| DNS_UDP_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
 	| DNS_UDP_PREF error { yyerror("number expected"); }
-	| DNS_TCP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3); }
+	| DNS_TCP_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
 	| DNS_TCP_PREF error { yyerror("number expected"); }
-	| DNS_TLS_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tls_pref=$3); }
+	| DNS_TLS_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
 	| DNS_TLS_PREF error { yyerror("number expected"); }
+	| DNS_SCTP_PREF EQUAL NUMBER { 
+								IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
+	| DNS_SCTP_PREF error { yyerror("number expected"); }
 	| DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
 	| DNS_RETR_TIME error { yyerror("number expected"); }
 	| DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }

+ 6 - 3
cfg_core.c

@@ -60,9 +60,10 @@ struct cfg_group_core default_core_cfg = {
 	0,  /* dns_try_ipv6 -- off, if no ipv6 support */
 #endif
 	0,  /* dns_try_naptr -- off by default */
-	3,  /* udp transport preference (for naptr) */
-	2,  /* tcp transport preference (for naptr) */
-	1,  /* tls transport preference (for naptr) */
+	30,  /* udp transport preference (for naptr) */
+	20,  /* tcp transport preference (for naptr) */
+	10,  /* tls transport preference (for naptr) */
+	20,  /* sctp transport preference (for naptr) */
 	-1, /* dns_retr_time */
 	-1, /* dns_retr_no */
 	-1, /* dns_servers_no */
@@ -124,6 +125,8 @@ cfg_def_t core_cfg_def[] = {
 		"tcp protocol preference when doing NAPTR lookups"},
 	{"dns_tls_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
 		"tls protocol preference when doing NAPTR lookups"},
+	{"dns_sctp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
+		"sctp protocol preference when doing NAPTR lookups"},
 	{"dns_retr_time",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
 		"time in s before retrying a dns request"},
 	{"dns_retr_no",		CFG_VAR_INT,	0, 0, 0, resolv_reinit,

+ 1 - 0
cfg_core.h

@@ -60,6 +60,7 @@ struct cfg_group_core {
 	int dns_udp_pref;
 	int dns_tcp_pref;
 	int dns_tls_pref;
+	int dns_sctp_pref;
 	int dns_retr_time;
 	int dns_retr_no;
 	int dns_servers_no;

+ 18 - 11
doc/dns.txt

@@ -91,26 +91,33 @@ DNS Resolver Options
       Default: off
 
    dns_udp_pref = number - udp protocol preference when doing NAPTR lookups.
-      This option works together with dns_tcp_pref and dns_tls_pref. If all
-      this options have the same positive value and more NAPTR records are
-      available, ser will select the NAPTR record preferred by the remote side
-      (according to RFC2915). If the values are positive but different, ser
-      will select the NAPTR record whose protocol it prefers the most
-      (the protocol with the highest dns_<proto>_pref number). If there are 
-      several NAPTR records with the same preferred protocol, ser will select
-      among them based on their order and preference (see RFC2915).
+      This option works together with dns_tcp_pref, dns_tls_pref and 
+      dns_sctp_pref. If all this options have the same positive value and more
+      NAPTR records are available, ser will select the NAPTR record preferred
+      by the remote side (according to RFC2915). If the values are positive
+      but different, ser will select the NAPTR record whose protocol it
+      prefers the most (the protocol with the highest dns_<proto>_pref
+      number). If there are several NAPTR records with the same preferred
+      protocol, ser will select among them based on their order and preference
+      (see RFC2915).
       To completely disable selecting a specific protocol, use  a negative
       number. For example dns_tcp_pref=-1 will completely disable selection
       of tcp NAPTR records, even if this will result in the NAPTR lookup
-      failure.
-      Default: dns_udp_pref=3, dns_tcp_pref=2 and dns_tls_pref=1
+      failure. Note: if a protocol is disabled in ser (e.g. tls_disable=1)
+      the corresponding NAPTR records selection will be also disabled,
+      irrespective of the dns_<proto>_preference value.
+      Default: dns_udp_pref=30, dns_tcp_pref=20,  dns_tls_pref=10 and 
+      dns_sctp_pref=20.
       (prefer udp, but if no udp NAPTR record found or no SRV-resolvable 
-      udp NAPTR record found use tcp records and if this fails too use tls)
+      udp NAPTR record found use tcp or sctp records and if this fails too
+      use tls)
 
    dns_tcp_pref = number  (see dns_udp_pref above)
 
    dns_tls_pref = number (see dns_udp_pref above)
 
+   dns_sctp_pref = number (see dns_udp_pref above)
+
    dns_retr_time = time - time in s before retrying a dns request.
       Default: system specific, depends also on the/etc/resolv.conf content
       (usually 5 s).

+ 5 - 4
resolve.c

@@ -42,7 +42,8 @@
  *              whether rest of the name is matched against search list
  *              or blindly accepted (better performance but exploitable)
  *  2008-01-31  resolver options use the configuration framework, and the
- *		resolver is reinitialized when the options change (Miklos)
+ *               resolver is reinitialized when the options change (Miklos)
+ *  2008-08-12  sctp preference support for NAPTR queries (andrei)
  */ 
 
 
@@ -73,7 +74,6 @@
 #define local_free   pkg_free
 
 #ifdef USE_NAPTR
-#define PROTO_LAST  PROTO_SCTP
 static int naptr_proto_pref[PROTO_LAST];
 #endif
 
@@ -81,13 +81,14 @@ static int naptr_proto_pref[PROTO_LAST];
 void init_naptr_proto_prefs()
 {
 	if ((PROTO_UDP >= PROTO_LAST) || (PROTO_TCP >= PROTO_LAST) ||
-		(PROTO_TLS >= PROTO_LAST)){
+		(PROTO_TLS >= PROTO_LAST) || (PROTO_SCTP>=PROTO_LAST)){
 		BUG("init_naptr_proto_prefs: array too small \n");
 		return;
 	}
 	naptr_proto_pref[PROTO_UDP]=cfg_get(core, core_cfg, dns_udp_pref);
 	naptr_proto_pref[PROTO_TCP]=cfg_get(core, core_cfg, dns_tcp_pref);
 	naptr_proto_pref[PROTO_TLS]=cfg_get(core, core_cfg, dns_tls_pref);
+	naptr_proto_pref[PROTO_SCTP]=cfg_get(core, core_cfg, dns_sctp_pref);
 }
 
 #endif /* USE_NAPTR */
@@ -839,7 +840,7 @@ char naptr_get_sip_proto(struct naptr_rdata* n)
 
 inline static int proto_pref_score(char proto)
 {
-	if ((proto>=PROTO_UDP) && (proto<= PROTO_TLS))
+	if ((proto>=PROTO_UDP) && (proto<= PROTO_LAST))
 		return naptr_proto_pref[(int)proto];
 	return 0;
 }