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 • Daniel-Constantin Mierla committed 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 2874
 		dns_hash_put(e);
2873 2875
 	}
2874 2876
 naptr_not_found:
2875
-	return no_naptr_srv_sip_resolvehost(name,port,proto);
2877
+	*proto = origproto;
2878
+	he = no_naptr_srv_sip_resolvehost(name,port,proto);
2879
+	/* fallback all the way down to A/AAAA */
2880
+	if (he==0) {
2881
+		he=dns_get_he(name,dns_flags);
2882
+	}
2883
+   return he;
2876 2884
 }
2877 2885
 #endif /* USE_NAPTR */
2878 2886
 
... ...
@@ -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 1558
 			if ((port)&&(*port==0)){
1572 1559
 				*port=(srv_proto_list[i].proto==PROTO_TLS)?SIPS_PORT:SIP_PORT; /* just in case we don't find another */
1573 1560
 			}
1561
+			if ((proto)&&(*proto==0)){
1562
+				*proto = PROTO_UDP;
1563
+			}
1574 1564
 			srv_name.s=tmp_srv;
1575 1565
 			srv_name.len=len;
1576 1566
 			#ifdef USE_DNS_CACHE
... ...
@@ -1611,9 +1601,9 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
1611 1601
 	char n_proto;
1612 1602
 	str srv_name;
1613 1603
 	naptr_bmp_t tried_bmp; /* tried bitmap */
1604
+	char origproto;
1614 1605
 
1615
-
1616
-
1606
+	origproto = *proto;
1617 1607
 	naptr_head=0;
1618 1608
 	he=0;
1619 1609
 	if (name->len >= MAX_DNS_NAME) {
... ...
@@ -1650,7 +1640,12 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
1650 1640
 #endif
1651 1641
 	}
1652 1642
 	/* fallback to srv lookup */
1643
+	*proto = origproto;
1653 1644
 	he=no_naptr_srv_sip_resolvehost(name,port,proto);
1645
+	/* fallback all the way down to A/AAAA */
1646
+	if (he==0) {
1647
+		he=dns_get_he(name,dns_flags);
1648
+	}
1654 1649
 end:
1655 1650
 	if (naptr_head)
1656 1651
 		free_rdata_list(naptr_head);