Browse code

- 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 authored on 12/08/2008 09:51:32
Showing 6 changed files
... ...
@@ -246,6 +246,7 @@ DNS_SRV_LB		dns_srv_lb|dns_srv_loadbalancing
246 246
 DNS_UDP_PREF	dns_udp_pref|dns_udp_preference
247 247
 DNS_TCP_PREF	dns_tcp_pref|dns_tcp_preference
248 248
 DNS_TLS_PREF	dns_tls_pref|dns_tls_preference
249
+DNS_SCTP_PREF	dns_sctp_pref|dns_sctp_preference
249 250
 DNS_RETR_TIME	dns_retr_time
250 251
 DNS_RETR_NO		dns_retr_no
251 252
 DNS_SERVERS_NO	dns_servers_no
... ...
@@ -512,6 +513,8 @@ EAT_ABLE	[\ \t\b\r]
512 512
 								return DNS_TCP_PREF; }
513 513
 <INITIAL>{DNS_TLS_PREF}	{ count(); yylval.strval=yytext;
514 514
 								return DNS_TLS_PREF; }
515
+<INITIAL>{DNS_SCTP_PREF}	{ count(); yylval.strval=yytext;
516
+								return DNS_SCTP_PREF; }
515 517
 <INITIAL>{DNS_RETR_TIME}	{ count(); yylval.strval=yytext;
516 518
 								return DNS_RETR_TIME; }
517 519
 <INITIAL>{DNS_RETR_NO}	{ count(); yylval.strval=yytext;
... ...
@@ -290,6 +290,7 @@ static struct socket_id* mk_listen_id(char*, int, int);
290 290
 %token DNS_UDP_PREF
291 291
 %token DNS_TCP_PREF
292 292
 %token DNS_TLS_PREF
293
+%token DNS_SCTP_PREF
293 294
 %token DNS_RETR_TIME
294 295
 %token DNS_RETR_NO
295 296
 %token DNS_SERVERS_NO
... ...
@@ -628,12 +629,15 @@ assign_stm:
628 628
 	| DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
629 629
 	| DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
630 630
 	| DNS_SRV_LB error { yyerror("boolean value expected"); }
631
-	| DNS_UDP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_udp_pref=$3); }
631
+	| DNS_UDP_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
632 632
 	| DNS_UDP_PREF error { yyerror("number expected"); }
633
-	| DNS_TCP_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3); }
633
+	| DNS_TCP_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
634 634
 	| DNS_TCP_PREF error { yyerror("number expected"); }
635
-	| DNS_TLS_PREF EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_tls_pref=$3); }
635
+	| DNS_TLS_PREF EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
636 636
 	| DNS_TLS_PREF error { yyerror("number expected"); }
637
+	| DNS_SCTP_PREF EQUAL NUMBER { 
638
+								IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
639
+	| DNS_SCTP_PREF error { yyerror("number expected"); }
637 640
 	| DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
638 641
 	| DNS_RETR_TIME error { yyerror("number expected"); }
639 642
 	| DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
... ...
@@ -60,9 +60,10 @@ struct cfg_group_core default_core_cfg = {
60 60
 	0,  /* dns_try_ipv6 -- off, if no ipv6 support */
61 61
 #endif
62 62
 	0,  /* dns_try_naptr -- off by default */
63
-	3,  /* udp transport preference (for naptr) */
64
-	2,  /* tcp transport preference (for naptr) */
65
-	1,  /* tls transport preference (for naptr) */
63
+	30,  /* udp transport preference (for naptr) */
64
+	20,  /* tcp transport preference (for naptr) */
65
+	10,  /* tls transport preference (for naptr) */
66
+	20,  /* sctp transport preference (for naptr) */
66 67
 	-1, /* dns_retr_time */
67 68
 	-1, /* dns_retr_no */
68 69
 	-1, /* dns_servers_no */
... ...
@@ -124,6 +125,8 @@ cfg_def_t core_cfg_def[] = {
124 124
 		"tcp protocol preference when doing NAPTR lookups"},
125 125
 	{"dns_tls_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
126 126
 		"tls protocol preference when doing NAPTR lookups"},
127
+	{"dns_sctp_pref",	CFG_VAR_INT,	0, 0, 0, reinit_naptr_proto_prefs,
128
+		"sctp protocol preference when doing NAPTR lookups"},
127 129
 	{"dns_retr_time",	CFG_VAR_INT,	0, 0, 0, resolv_reinit,
128 130
 		"time in s before retrying a dns request"},
129 131
 	{"dns_retr_no",		CFG_VAR_INT,	0, 0, 0, resolv_reinit,
... ...
@@ -60,6 +60,7 @@ struct cfg_group_core {
60 60
 	int dns_udp_pref;
61 61
 	int dns_tcp_pref;
62 62
 	int dns_tls_pref;
63
+	int dns_sctp_pref;
63 64
 	int dns_retr_time;
64 65
 	int dns_retr_no;
65 66
 	int dns_servers_no;
... ...
@@ -91,26 +91,33 @@ DNS Resolver Options
91 91
       Default: off
92 92
 
93 93
    dns_udp_pref = number - udp protocol preference when doing NAPTR lookups.
94
-      This option works together with dns_tcp_pref and dns_tls_pref. If all
95
-      this options have the same positive value and more NAPTR records are
96
-      available, ser will select the NAPTR record preferred by the remote side
97
-      (according to RFC2915). If the values are positive but different, ser
98
-      will select the NAPTR record whose protocol it prefers the most
99
-      (the protocol with the highest dns_<proto>_pref number). If there are 
100
-      several NAPTR records with the same preferred protocol, ser will select
101
-      among them based on their order and preference (see RFC2915).
94
+      This option works together with dns_tcp_pref, dns_tls_pref and 
95
+      dns_sctp_pref. If all this options have the same positive value and more
96
+      NAPTR records are available, ser will select the NAPTR record preferred
97
+      by the remote side (according to RFC2915). If the values are positive
98
+      but different, ser will select the NAPTR record whose protocol it
99
+      prefers the most (the protocol with the highest dns_<proto>_pref
100
+      number). If there are several NAPTR records with the same preferred
101
+      protocol, ser will select among them based on their order and preference
102
+      (see RFC2915).
102 103
       To completely disable selecting a specific protocol, use  a negative
103 104
       number. For example dns_tcp_pref=-1 will completely disable selection
104 105
       of tcp NAPTR records, even if this will result in the NAPTR lookup
105
-      failure.
106
-      Default: dns_udp_pref=3, dns_tcp_pref=2 and dns_tls_pref=1
106
+      failure. Note: if a protocol is disabled in ser (e.g. tls_disable=1)
107
+      the corresponding NAPTR records selection will be also disabled,
108
+      irrespective of the dns_<proto>_preference value.
109
+      Default: dns_udp_pref=30, dns_tcp_pref=20,  dns_tls_pref=10 and 
110
+      dns_sctp_pref=20.
107 111
       (prefer udp, but if no udp NAPTR record found or no SRV-resolvable 
108
-      udp NAPTR record found use tcp records and if this fails too use tls)
112
+      udp NAPTR record found use tcp or sctp records and if this fails too
113
+      use tls)
109 114
 
110 115
    dns_tcp_pref = number  (see dns_udp_pref above)
111 116
 
112 117
    dns_tls_pref = number (see dns_udp_pref above)
113 118
 
119
+   dns_sctp_pref = number (see dns_udp_pref above)
120
+
114 121
    dns_retr_time = time - time in s before retrying a dns request.
115 122
       Default: system specific, depends also on the/etc/resolv.conf content
116 123
       (usually 5 s).
... ...
@@ -42,7 +42,8 @@
42 42
  *              whether rest of the name is matched against search list
43 43
  *              or blindly accepted (better performance but exploitable)
44 44
  *  2008-01-31  resolver options use the configuration framework, and the
45
- *		resolver is reinitialized when the options change (Miklos)
45
+ *               resolver is reinitialized when the options change (Miklos)
46
+ *  2008-08-12  sctp preference support for NAPTR queries (andrei)
46 47
  */ 
47 48
 
48 49
 
... ...
@@ -73,7 +74,6 @@
73 73
 #define local_free   pkg_free
74 74
 
75 75
 #ifdef USE_NAPTR
76
-#define PROTO_LAST  PROTO_SCTP
77 76
 static int naptr_proto_pref[PROTO_LAST];
78 77
 #endif
79 78
 
... ...
@@ -81,13 +81,14 @@ static int naptr_proto_pref[PROTO_LAST];
81 81
 void init_naptr_proto_prefs()
82 82
 {
83 83
 	if ((PROTO_UDP >= PROTO_LAST) || (PROTO_TCP >= PROTO_LAST) ||
84
-		(PROTO_TLS >= PROTO_LAST)){
84
+		(PROTO_TLS >= PROTO_LAST) || (PROTO_SCTP>=PROTO_LAST)){
85 85
 		BUG("init_naptr_proto_prefs: array too small \n");
86 86
 		return;
87 87
 	}
88 88
 	naptr_proto_pref[PROTO_UDP]=cfg_get(core, core_cfg, dns_udp_pref);
89 89
 	naptr_proto_pref[PROTO_TCP]=cfg_get(core, core_cfg, dns_tcp_pref);
90 90
 	naptr_proto_pref[PROTO_TLS]=cfg_get(core, core_cfg, dns_tls_pref);
91
+	naptr_proto_pref[PROTO_SCTP]=cfg_get(core, core_cfg, dns_sctp_pref);
91 92
 }
92 93
 
93 94
 #endif /* USE_NAPTR */
... ...
@@ -839,7 +840,7 @@ char naptr_get_sip_proto(struct naptr_rdata* n)
839 839
 
840 840
 inline static int proto_pref_score(char proto)
841 841
 {
842
-	if ((proto>=PROTO_UDP) && (proto<= PROTO_TLS))
842
+	if ((proto>=PROTO_UDP) && (proto<= PROTO_LAST))
843 843
 		return naptr_proto_pref[(int)proto];
844 844
 	return 0;
845 845
 }