Browse code

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

- try all protocols, not only UDP

(cherry picked from commit b50888cf447ea3a3315e665c97f71a07bb687337)

√ėyvind Kolbu authored on 30/09/2013 09:15:13 • Daniel-Constantin Mierla committed on 02/10/2013 07:50:48
Showing 2 changed files
... ...
@@ -2857,8 +2857,10 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
2857 2857
 	naptr_bmp_t tried_bmp;
2858 2858
 	struct dns_hash_entry* e;
2859 2859
 	char n_proto;
2860
+	char origproto;
2860 2861
 	str srv_name;
2861 2862
 
2863
+	origproto=*proto;
2862 2864
 	he=0;
2863 2865
 	if (dns_hash==0){ /* not init => use normal, non-cached version */
2864 2866
 		LOG(L_WARN, "WARNING: dns_sip_resolvehost: called before dns cache"
... ...
@@ -2903,7 +2905,13 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
2903 2905
 		dns_hash_put(e);
2904 2906
 	}
2905 2907
 naptr_not_found:
2906
-	return no_naptr_srv_sip_resolvehost(name,port,proto);
2908
+	*proto = origproto;
2909
+	he = no_naptr_srv_sip_resolvehost(name,port,proto);
2910
+	/* fallback all the way down to A/AAAA */
2911
+	if (he==0) {
2912
+		he=dns_get_he(name,dns_flags);
2913
+	}
2914
+   return he;
2907 2915
 }
2908 2916
 #endif /* USE_NAPTR */
2909 2917
 
... ...
@@ -1519,20 +1519,7 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, unsigned short* port, ch
1519 1519
 			}
1520 1520
 			if (default_order){
1521 1521
 				for (i=0; i<list_len;i++) {
1522
-					switch ( srv_proto_list[i].proto) {
1523
-						case PROTO_UDP:
1524
-							srv_proto_list[i].proto_pref=4;
1525
-							break;
1526
-						case PROTO_TCP:
1527
-							srv_proto_list[i].proto_pref=3;
1528
-							break;
1529
-						case PROTO_TLS:
1530
-							srv_proto_list[i].proto_pref=2;
1531
-							break;
1532
-						case PROTO_SCTP:
1533
-							srv_proto_list[i].proto_pref=1;
1534
-							break;
1535
-					}
1522
+					srv_proto_list[i].proto_pref=proto_pref_score(i);;
1536 1523
 				}
1537 1524
 			}
1538 1525
 
... ...
@@ -1592,6 +1579,9 @@ struct hostent* no_naptr_srv_sip_resolvehost(str* name, unsigned short* port, ch
1592 1579
 			if ((port)&&(*port==0)){
1593 1580
 				*port=(srv_proto_list[i].proto==PROTO_TLS)?SIPS_PORT:SIP_PORT; /* just in case we don't find another */
1594 1581
 			}
1582
+			if ((proto)&&(*proto==0)){
1583
+				*proto = PROTO_UDP;
1584
+			}
1595 1585
 			srv_name.s=tmp_srv;
1596 1586
 			srv_name.len=len;
1597 1587
 			#ifdef USE_DNS_CACHE
... ...
@@ -1632,9 +1622,9 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
1632 1622
 	char n_proto;
1633 1623
 	str srv_name;
1634 1624
 	naptr_bmp_t tried_bmp; /* tried bitmap */
1625
+	char origproto;
1635 1626
 
1636
-
1637
-
1627
+	origproto = *proto;
1638 1628
 	naptr_head=0;
1639 1629
 	he=0;
1640 1630
 	if (name->len >= MAX_DNS_NAME) {
... ...
@@ -1673,7 +1663,12 @@ struct hostent* naptr_sip_resolvehost(str* name,  unsigned short* port,
1673 1663
 #endif
1674 1664
 	}
1675 1665
 	/* fallback to srv lookup */
1666
+	*proto = origproto;
1676 1667
 	he=no_naptr_srv_sip_resolvehost(name,port,proto);
1668
+	/* fallback all the way down to A/AAAA */
1669
+	if (he==0) {
1670
+		he=dns_get_he(name,dns_flags);
1671
+	}
1677 1672
 end:
1678 1673
 	if (naptr_head)
1679 1674
 		free_rdata_list(naptr_head);