Browse code

core: resolve down to A/AAAA records when no naptr records

- try all protocols, not only UDP

√ėyvind Kolbu authored on 30/09/2013 09:15:13
Showing 2 changed files
... ...
@@ -2830,8 +2830,10 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
2830 2830
 	naptr_bmp_t tried_bmp;
2831 2831
 	struct dns_hash_entry* e;
2832 2832
 	char n_proto;
2833
+	char origproto;
2833 2834
 	str srv_name;
2834 2835
 
2836
+	origproto=*proto;
2835 2837
 	he=0;
2836 2838
 	if (dns_hash==0){ /* not init => use normal, non-cached version */
2837 2839
 		LOG(L_WARN, "WARNING: dns_sip_resolvehost: called before dns cache"
... ...
@@ -2872,7 +2874,13 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
2872 2872
 		dns_hash_put(e);
2873 2873
 	}
2874 2874
 naptr_not_found:
2875
-	return no_naptr_srv_sip_resolvehost(name,port,proto);
2875
+	*proto = origproto;
2876
+	he = no_naptr_srv_sip_resolvehost(name,port,proto);
2877
+	/* fallback all the way down to A/AAAA */
2878
+	if (he==0) {
2879
+		he=dns_get_he(name,dns_flags);
2880
+	}
2881
+   return he;
2876 2882
 }
2877 2883
 #endif /* USE_NAPTR */
2878 2884
 
... ...
@@ -1498,20 +1498,7 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, unsigned short* port, ch
1498 1498
 			}
1499 1499
 			if (default_order){
1500 1500
 				for (i=0; i<list_len;i++) {
1501
-					switch ( srv_proto_list[i].proto) {
1502
-						case PROTO_UDP:
1503
-							srv_proto_list[i].proto_pref=4;
1504
-							break;
1505
-						case PROTO_TCP:
1506
-							srv_proto_list[i].proto_pref=3;
1507
-							break;
1508
-						case PROTO_TLS:
1509
-							srv_proto_list[i].proto_pref=2;
1510
-							break;
1511
-						case PROTO_SCTP:
1512
-							srv_proto_list[i].proto_pref=1;
1513
-							break;
1514
-					}
1501
+					srv_proto_list[i].proto_pref=proto_pref_score(i);;
1515 1502
 				}
1516 1503
 			}
1517 1504
 
... ...
@@ -1571,6 +1558,9 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, unsigned short* port, ch
1571 1571
 			if ((port)&&(*port==0)){
1572 1572
 				*port=(srv_proto_list[i].proto==PROTO_TLS)?SIPS_PORT:SIP_PORT; /* just in case we don't find another */
1573 1573
 			}
1574
+			if ((proto)&&(*proto==0)){
1575
+				*proto = PROTO_UDP;
1576
+			}
1574 1577
 			srv_name.s=tmp_srv;
1575 1578
 			srv_name.len=len;
1576 1579
 			#ifdef USE_DNS_CACHE
... ...
@@ -1611,9 +1601,9 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
1611 1611
 	char n_proto;
1612 1612
 	str srv_name;
1613 1613
 	naptr_bmp_t tried_bmp; /* tried bitmap */
1614
+	char origproto;
1614 1615
 
1615
-
1616
-
1616
+	origproto = *proto;
1617 1617
 	naptr_head=0;
1618 1618
 	he=0;
1619 1619
 	if (name->len >= MAX_DNS_NAME) {
... ...
@@ -1650,7 +1640,12 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
1650 1650
 #endif
1651 1651
 	}
1652 1652
 	/* fallback to srv lookup */
1653
+	*proto = origproto;
1653 1654
 	he=no_naptr_srv_sip_resolvehost(name,port,proto);
1655
+	/* fallback all the way down to A/AAAA */
1656
+	if (he==0) {
1657
+		he=dns_get_he(name,dns_flags);
1658
+	}
1654 1659
 end:
1655 1660
 	if (naptr_head)
1656 1661
 		free_rdata_list(naptr_head);